ROOT logo
Int_t TOFquickanal(Int_t eventNumber = 0)
{
  /////////////////////////////////////////////////////////////////////////
  //   This macro is a small example of a ROOT macro
  //   illustrating how to read the output of GALICE
  //   and fill some histograms concerning the TOF Hit Tree.
  //
  //     Root > .L TOFquickanal.C   //this loads the macro in memory
  //     Root > TOFquickanal();     //by default process first event
  //     Root > TOFquickanal(2);    //process third event
  //End_Html
  //
  // Author: F. Pierella , Bologna University 12-04-2001
  // Updated to the new I/O by: A. De Caro, C. Zampolli
  /////////////////////////////////////////////////////////////////////////
  
  // Dynamically link some shared libs
  if (gClassTable->GetID("AliRun") < 0) {
    gROOT->LoadMacro("loadlibs.C");
    loadlibs();
  }

  Int_t rc = 0;
  
  AliRunLoader *rl =AliRunLoader::Open("galice.root",AliConfig::GetDefaultEventFolderName(),"update");
  if (!rl) 
    {
      cerr << "Can't load RunLoader from file!\n";
      rc = 1;
      return rc;
    }

  rl->LoadgAlice();
  gAlice=rl->GetAliRun();

  if (!gAlice)
    {
      cerr << "<TOFquickanal> AliRun object not found on file \n";
      rc = 2;
      return rc;
    }

  // Get the pointer to the TOF detector
  AliLoader *tofl = rl->GetLoader("TOFLoader");
  AliTOF * tof = (AliTOF*) gAlice->GetDetector("TOF");
  if (tof == 0x0 || tofl == 0x0) {
    cerr << "<TOFquickanal> Can not find TOF or TOFLoader\n";
    rc = 3;
    return rc;
  }

  //=======> Create histograms
  //---> Time of Flight for Primary Particles (ns)
  TH1F *htofprim = new TH1F("htofprim","Time of Flight for Primary Particles",100,0.,100.);
  //--->Time of Flight for Secondary Particles (ns)
  TH1F *htofsec  = new TH1F("htofsec","Time of Flight for Secondary Particles",100,0.,100.);
  
  //---> r (radius) coordinate of production in the ALICE frame for secondary particles that produce at 
  //     least one TOF-hit (cm) - cylindrical coordinate system assumed, primary plus secondary-
  TH1F *hradius = new TH1F("hradius","r (radius) coordinate at the production vertex for secondary particles with at least one TOF-Hit",50,0.,500.);
  
  //---> Momentum of primary particles that produce (at least) one TOF-hit when the hit
  //     is produced (Gev/c)
  TH1F *htofmom  = new TH1F("htofmom","Momentum of primary particles when the Hit is produced",50,0.,5.);
  
  //---> Momentum of primary particles that produce (at least) one TOF-hit at the production vertex
  //     (Gev/c)
  TH1F *hprodmom  = new TH1F("hprodmom","Momentum of primary particles (with at least one TOF hit) at the production ",50,0.,5.); 
  
  //---> Theta of production for primary particles that produce (at least) one TOF-hit (deg)
  TH1F *hprodthe  = new TH1F("hprodthe","Theta of primary particles (with at least one TOF hit) at the production ",90,0.,180.);
  
  //---> Phi of production for primary particles that produce (at least) one TOF-hit (deg)
  TH1F *hprodphi  = new TH1F("hprodphi","Phi of primary particles (with at least one TOF hit) at the production ",180,-180.,180.);
  
  //---> z Coordinate of the TOF Hit (z beam axis) - primary plus secondary - (cm)
  TH1F *hzcoor = new TH1F("hzcoor","z Coordinate of the TOF Hit",800,-400.,400.);
  
  //---> Incidence Angle of the particle on the pad (or strip) (deg)  - primary plus secondary - 
  TH1F *hincangle = new TH1F("hincangle","Incidence Angle of the particle on the strip",90,0.,180.);
  
  printf ("Processing event %d \n", eventNumber);
  rl->GetEvent(eventNumber);
  
  // Get pointers to Alice detectors and Hits containers
  tofl->LoadHits();
  TTree *TH = tofl->TreeH();
  tof->SetTreeAddress();
  if (!TH) {
    cout << "<TOFquickanal> No hit tree found" << endl;
    rc = 4;
    return rc;
  }
  
  // Import the Kine Tree for the event eventNumber in the file  
  rl->LoadHeader();
  rl->LoadKinematics();
  //AliStack * stack = rl->Stack();
  
  Int_t ntracks = TH->GetEntries();
  cout<<" ntracks = "<<ntracks<<endl;
  
  AliTOFhitT0 *tofHit;
  
  // Start loop on tracks in the hits containers
  for (Int_t track=0; track<ntracks;track++) {
    
    tof->ResetHits();
    TH->GetEvent(track);
    
    for(tofHit=(AliTOFhitT0*)tof->FirstHit(track); tofHit; tofHit=(AliTOFhitT0*)tof->NextHit()) {
      
      Float_t toflight = tofHit->GetTof();
      toflight        *= 1.E+09;  // conversion from s to ns
      Double_t tofmom  = tofHit->GetMom();
      
      Int_t ipart = tofHit->Track();
      TParticle *particle = gAlice->Particle(ipart);
      if (particle->GetFirstMother() < 0) {
	htofprim->Fill(toflight);
	htofmom->Fill(tofmom); 
      } else {
	htofsec->Fill(toflight); 
      }
      
      Double_t zcoor = tofHit->Z();
      hzcoor->Fill(zcoor);
      
      Double_t incangle = tofHit->GetIncA();
      hincangle->Fill(incangle);
      
      Double_t xcoor  = particle->Vx();
      Double_t ycoor  = particle->Vy();
      Double_t radius = TMath::Sqrt(xcoor*xcoor+ycoor*ycoor);
      if (particle->GetFirstMother() >= 0) hradius->Fill(radius);
      
      Double_t prodmom = particle->P();        
      if (prodmom!=0.) {
	Double_t dummy = (particle->Pz())/prodmom;
	Double_t prodthe = TMath::ACos(dummy);
	prodthe *= 57.29578; // conversion from rad to deg
	if (particle->GetFirstMother() < 0) hprodthe->Fill(prodthe);
      } // theta at production vertex
      
      if (particle->GetFirstMother() < 0) {         
	hprodmom->Fill(prodmom);
	Double_t dummypx = particle->Px();
	Double_t dummypy = particle->Py();
	Double_t prodphi = TMath::ATan2(dummypy,dummypx);
	prodphi *= 57.29578; // conversion from rad to deg
	hprodphi->Fill(prodphi);
      } // phi at production vertex
    } // close loop on TOF-hits
  } // close loop on tracks in the hits containers
  
  //Create  canvas, set the view range, show histograms
  TCanvas *c1 = new TCanvas("c1","Alice TOF hits quick analysis",400,10,600,700);
  c1->cd();
  hprodmom->Draw();
  
  TCanvas *c2 = new TCanvas("c2","Alice TOF hits quick analysis",400,10,600,700);
  c2->cd();
  hprodthe->Draw();
  
  TCanvas *c3 = new TCanvas("c3","Alice TOF hits quick analysis",400,10,600,700);
  c3->cd();
  hprodphi->Draw();
  
  TCanvas *c4 = new TCanvas("c4","Alice TOF hits quick analysis",400,10,600,700);
  c4->cd();
  hzcoor->Draw();
  
  TCanvas *c5 = new TCanvas("c5","Alice TOF hits quick analysis",400,10,600,700);
  c5->cd();
  hradius->Draw();
  
  TCanvas *c6 = new TCanvas("c6","Alice TOF hits quick analysis",400,10,600,700);
  c6->cd();
  htofprim->Draw();
  
  TCanvas *c7 = new TCanvas("c7","Alice TOF hits quick analysis",400,10,600,700);
  c7->cd();
  htofsec->Draw();
  
  
  TCanvas *c8 = new TCanvas("c8","Alice TOF hits quick analysis",400,10,600,700);
  c8->cd();
  htofmom->Draw();
  
  TCanvas *c9 = new TCanvas("c9","Alice TOF hits quick analysis",400,10,600,700);
  c9->cd();
  hincangle->Draw();
  
  //tofl->UnloadHits();
  //rl->UnloadHeader();
  //rl->UnloadgAlice();
  //rl->UnloadKinematics();

  return rc;

}
 TOFquickanal.C:1
 TOFquickanal.C:2
 TOFquickanal.C:3
 TOFquickanal.C:4
 TOFquickanal.C:5
 TOFquickanal.C:6
 TOFquickanal.C:7
 TOFquickanal.C:8
 TOFquickanal.C:9
 TOFquickanal.C:10
 TOFquickanal.C:11
 TOFquickanal.C:12
 TOFquickanal.C:13
 TOFquickanal.C:14
 TOFquickanal.C:15
 TOFquickanal.C:16
 TOFquickanal.C:17
 TOFquickanal.C:18
 TOFquickanal.C:19
 TOFquickanal.C:20
 TOFquickanal.C:21
 TOFquickanal.C:22
 TOFquickanal.C:23
 TOFquickanal.C:24
 TOFquickanal.C:25
 TOFquickanal.C:26
 TOFquickanal.C:27
 TOFquickanal.C:28
 TOFquickanal.C:29
 TOFquickanal.C:30
 TOFquickanal.C:31
 TOFquickanal.C:32
 TOFquickanal.C:33
 TOFquickanal.C:34
 TOFquickanal.C:35
 TOFquickanal.C:36
 TOFquickanal.C:37
 TOFquickanal.C:38
 TOFquickanal.C:39
 TOFquickanal.C:40
 TOFquickanal.C:41
 TOFquickanal.C:42
 TOFquickanal.C:43
 TOFquickanal.C:44
 TOFquickanal.C:45
 TOFquickanal.C:46
 TOFquickanal.C:47
 TOFquickanal.C:48
 TOFquickanal.C:49
 TOFquickanal.C:50
 TOFquickanal.C:51
 TOFquickanal.C:52
 TOFquickanal.C:53
 TOFquickanal.C:54
 TOFquickanal.C:55
 TOFquickanal.C:56
 TOFquickanal.C:57
 TOFquickanal.C:58
 TOFquickanal.C:59
 TOFquickanal.C:60
 TOFquickanal.C:61
 TOFquickanal.C:62
 TOFquickanal.C:63
 TOFquickanal.C:64
 TOFquickanal.C:65
 TOFquickanal.C:66
 TOFquickanal.C:67
 TOFquickanal.C:68
 TOFquickanal.C:69
 TOFquickanal.C:70
 TOFquickanal.C:71
 TOFquickanal.C:72
 TOFquickanal.C:73
 TOFquickanal.C:74
 TOFquickanal.C:75
 TOFquickanal.C:76
 TOFquickanal.C:77
 TOFquickanal.C:78
 TOFquickanal.C:79
 TOFquickanal.C:80
 TOFquickanal.C:81
 TOFquickanal.C:82
 TOFquickanal.C:83
 TOFquickanal.C:84
 TOFquickanal.C:85
 TOFquickanal.C:86
 TOFquickanal.C:87
 TOFquickanal.C:88
 TOFquickanal.C:89
 TOFquickanal.C:90
 TOFquickanal.C:91
 TOFquickanal.C:92
 TOFquickanal.C:93
 TOFquickanal.C:94
 TOFquickanal.C:95
 TOFquickanal.C:96
 TOFquickanal.C:97
 TOFquickanal.C:98
 TOFquickanal.C:99
 TOFquickanal.C:100
 TOFquickanal.C:101
 TOFquickanal.C:102
 TOFquickanal.C:103
 TOFquickanal.C:104
 TOFquickanal.C:105
 TOFquickanal.C:106
 TOFquickanal.C:107
 TOFquickanal.C:108
 TOFquickanal.C:109
 TOFquickanal.C:110
 TOFquickanal.C:111
 TOFquickanal.C:112
 TOFquickanal.C:113
 TOFquickanal.C:114
 TOFquickanal.C:115
 TOFquickanal.C:116
 TOFquickanal.C:117
 TOFquickanal.C:118
 TOFquickanal.C:119
 TOFquickanal.C:120
 TOFquickanal.C:121
 TOFquickanal.C:122
 TOFquickanal.C:123
 TOFquickanal.C:124
 TOFquickanal.C:125
 TOFquickanal.C:126
 TOFquickanal.C:127
 TOFquickanal.C:128
 TOFquickanal.C:129
 TOFquickanal.C:130
 TOFquickanal.C:131
 TOFquickanal.C:132
 TOFquickanal.C:133
 TOFquickanal.C:134
 TOFquickanal.C:135
 TOFquickanal.C:136
 TOFquickanal.C:137
 TOFquickanal.C:138
 TOFquickanal.C:139
 TOFquickanal.C:140
 TOFquickanal.C:141
 TOFquickanal.C:142
 TOFquickanal.C:143
 TOFquickanal.C:144
 TOFquickanal.C:145
 TOFquickanal.C:146
 TOFquickanal.C:147
 TOFquickanal.C:148
 TOFquickanal.C:149
 TOFquickanal.C:150
 TOFquickanal.C:151
 TOFquickanal.C:152
 TOFquickanal.C:153
 TOFquickanal.C:154
 TOFquickanal.C:155
 TOFquickanal.C:156
 TOFquickanal.C:157
 TOFquickanal.C:158
 TOFquickanal.C:159
 TOFquickanal.C:160
 TOFquickanal.C:161
 TOFquickanal.C:162
 TOFquickanal.C:163
 TOFquickanal.C:164
 TOFquickanal.C:165
 TOFquickanal.C:166
 TOFquickanal.C:167
 TOFquickanal.C:168
 TOFquickanal.C:169
 TOFquickanal.C:170
 TOFquickanal.C:171
 TOFquickanal.C:172
 TOFquickanal.C:173
 TOFquickanal.C:174
 TOFquickanal.C:175
 TOFquickanal.C:176
 TOFquickanal.C:177
 TOFquickanal.C:178
 TOFquickanal.C:179
 TOFquickanal.C:180
 TOFquickanal.C:181
 TOFquickanal.C:182
 TOFquickanal.C:183
 TOFquickanal.C:184
 TOFquickanal.C:185
 TOFquickanal.C:186
 TOFquickanal.C:187
 TOFquickanal.C:188
 TOFquickanal.C:189
 TOFquickanal.C:190
 TOFquickanal.C:191
 TOFquickanal.C:192
 TOFquickanal.C:193
 TOFquickanal.C:194
 TOFquickanal.C:195
 TOFquickanal.C:196
 TOFquickanal.C:197
 TOFquickanal.C:198
 TOFquickanal.C:199
 TOFquickanal.C:200
 TOFquickanal.C:201
 TOFquickanal.C:202
 TOFquickanal.C:203
 TOFquickanal.C:204
 TOFquickanal.C:205
 TOFquickanal.C:206