1 /****************************************************************************
2 * This macro estimates efficiency of matching with the TOF. *
3 * TOF "Good" tracks are those originating from the primary vertex, *
4 * being "good" in the ITS and having at least one digit in the TOF. *
5 * (To get the list of "good" tracks one should first run *
6 * AliTPCComparison.C and AliITSComparisonV2.C macros) *
7 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
8 ****************************************************************************/
10 #if !defined(__CINT__) || defined(__MAKECINT__)
13 #include <Riostream.h>
16 #include <TParticle.h>
20 #include <TBenchmark.h>
26 #include "AliHeader.h"
27 #include "AliTrackReference.h"
28 #include "AliRunLoader.h"
32 #include "AliTOFdigit.h"
33 #include "AliLoader.h"
35 #include "TClonesArray.h"
38 Int_t GoodTracksTOF(const Char_t *dir=".");
40 extern AliRun *gAlice;
41 extern TBenchmark *gBenchmark;
44 static Int_t allgood=0;
45 static Int_t allmatched=0;
46 static Int_t allmismatched=0;
48 Int_t AliTOFComparison(const Char_t *dir=".") {
49 gBenchmark->Start("AliTOFComparison");
51 ::Info("AliTOFComparison.C","Doing comparison...");
57 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
58 if (!hgood) hgood=new TH1F("hgood","Good tracks",30,pmin,pmax);
60 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
61 if (!hfound) hfound=new TH1F("hfound","Matched tracks",30,pmin,pmax);
63 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
64 if (!hfake) hfake=new TH1F("hfake","Mismatched tracks",30,pmin,pmax);
66 TH1F *hgp=(TH1F*)gROOT->FindObject("hgp");
67 if (!hgp) hgp=new TH1F("hgp","",30,pmin,pmax);
68 hgp->SetLineColor(4); hgp->SetLineWidth(2);
70 TH1F *hfp=(TH1F*)gROOT->FindObject("hfp");
71 if (!hfp) hfp=new TH1F("hfp","Probability of mismatching",30,pmin,pmax);
72 hfp->SetFillColor(1); hfp->SetFillStyle(3013); hfp->SetLineWidth(2);
74 TH1F *hgoo=(TH1F*)gROOT->FindObject("hgoo");
75 if (!hgoo) hgoo=new TH1F("hgoo","Good tracks",30,-1,1);
77 TH1F *hfoun=(TH1F*)gROOT->FindObject("hfoun");
78 if (!hfoun) hfoun=new TH1F("hfoun","Matched tracks",30,-1,1);
80 TH1F *hfak=(TH1F*)gROOT->FindObject("hfak");
81 if (!hfak) hfak=new TH1F("hfak","Mismatched tracks",30,-1,1);
83 TH1F *hgl=(TH1F*)gROOT->FindObject("hgl");
84 if (!hgl) hgl=new TH1F("hgl","",30,-1,1);
85 hgl->SetLineColor(4); hgl->SetLineWidth(2);
87 TH1F *hfl=(TH1F*)gROOT->FindObject("hfl");
88 if (!hfl) hfl=new TH1F("hfl","Probability of mismatching",30,-1,1);
89 hfl->SetFillColor(1); hfl->SetFillStyle(3013); hfl->SetLineWidth(2);
94 sprintf(fname,"%s/GoodTracksTOF.root",dir);
96 TFile *refFile=TFile::Open(fname,"old");
97 if (!refFile || !refFile->IsOpen()) {
98 ::Info("AliTOFComparison.C","Marking good tracks (will take a while)...");
99 if (GoodTracksTOF(dir)) {
100 ::Error("AliTOFComparison.C","Can't generate the reference file !");
104 refFile=TFile::Open(fname,"old");
105 if (!refFile || !refFile->IsOpen()) {
106 ::Error("AliTOFComparison.C","Can't open the reference file !");
110 TTree *tofTree=(TTree*)refFile->Get("tofTree");
112 ::Error("AliTOFComparison.C","Can't get the reference tree !");
115 TBranch *branch=tofTree->GetBranch("TOF");
117 ::Error("AliTOFComparison.C","Can't get the TOF branch !");
120 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
121 branch->SetAddress(&refs);
125 delete gAlice->GetRunLoader();
126 delete gAlice;//if everything was OK here it is already NULL
129 sprintf(fname,"%s/galice.root",dir);
130 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
132 cerr<<"Can not open session"<<endl;
135 AliLoader* tofl = rl->GetLoader("TOFLoader");
137 cerr<<"Can not get the TOF loader"<<endl;
140 tofl->LoadDigits("read");
143 sprintf(fname,"%s/AliESDs.root",dir);
144 TFile *ef=TFile::Open(fname);
145 if ((!ef)||(!ef->IsOpen())) {
146 ::Error("AliTOFComparison.C","Can't open AliESDs.root !");
151 TIter next(ef->GetListOfKeys());
155 //******* Loop over events *********
157 while ((key=(TKey*)next())!=0) {
158 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
160 rl->GetEvent(e); ef->cd();
162 TTree *digTree=tofl->TreeD();
164 cerr<<"Can't get the TOF cluster tree !\n";
167 TBranch *branch=digTree->GetBranch("TOF");
169 cerr<<"Can't get the branch with the TOF digits !\n";
172 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
173 branch->SetAddress(&digits);
175 digTree->GetEvent(0);
176 Int_t nd=digits->GetEntriesFast();
177 cerr<<"Number of the TOF digits: "<<nd<<endl;
181 AliESD *event=(AliESD*)key->ReadObj();
182 Int_t ntrk=event->GetNumberOfTracks();
183 cerr<<"Number of ESD tracks : "<<ntrk<<endl;
186 if (tofTree->GetEvent(e++)==0) {
187 cerr<<"No reconstructable tracks !\n";
191 Int_t ngood=refs->GetEntriesFast();
195 for (Int_t i=0; i<ngood; i++) {
196 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(i);
197 Int_t lab=ref->Label();
198 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
200 Double_t tgl=ref->Pz()/ptg; //tan(lambda)
202 if (ptg>pmin) { hgood->Fill(ptg); hgoo->Fill(tgl); }
206 for (j=0; j<ntrk; j++) {
207 AliESDtrack *tt=event->GetTrack(j);
208 if (lab!=TMath::Abs(tt->GetLabel())) continue;
210 //if ((tt->GetStatus()&AliESDtrack::kTOFpid) == 0) continue;
211 if (tt->GetTOFsignal() < 0) continue;
212 UInt_t idx=tt->GetTOFcluster();
213 if ((Int_t)idx>=nd) {
214 cerr<<"Wrong digit index ! "<<idx<<endl;
217 AliTOFdigit *dig=(AliTOFdigit*)digits->UncheckedAt(idx);
218 Int_t *label=dig->GetTracks();
223 if (ptg>pmin) { hfake->Fill(ptg); hfak->Fill(tgl); }
226 if (ptg>pmin) { hfound->Fill(ptg); hfoun->Fill(tgl); }
231 cerr<<"Not matched: "<<lab<<" ";
233 cerr<<(t->GetStatus()&AliESDtrack::kITSout)<<' '
234 <<(t->GetStatus()&AliESDtrack::kTPCout)<<' '
235 <<(t->GetStatus()&AliESDtrack::kTRDout)<<' '
236 <<(t->GetStatus()&AliESDtrack::kTIME);
237 } else cerr<<"No ESD track !";
241 cout<<"Number of good tracks: "<<ngood<<endl;
242 cout<<"Number of matched tracks: "<<matched<<endl;
243 cout<<"Number of mismatched tracks: "<<mismatched<<endl;
245 allgood+=ngood; allmatched+=matched; allmismatched+=mismatched;
249 } //***** End of the loop over events
256 if (allgood!=0) cerr<<"\n\nEfficiency: "<<Float_t(allmatched)/allgood<<endl;
257 cout<<"Total number of good tracks: "<<allgood<<endl;
258 cout<<"Total number of matched tracks: "<<allmatched<<endl;
259 cout<<"Total number of mismatched tracks: "<<allmismatched<<endl;
261 TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
263 c1=new TCanvas("c1","",0,0,600,900);
266 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
267 hgp->Divide(hfound,hgood,1,1.,"b");
268 hfp->Divide(hfake,hgood,1,1.,"b");
269 hgp->SetMaximum(1.4);
270 hgp->SetYTitle("Matching efficiency");
271 hgp->SetXTitle("Pt (GeV/c)");
273 hfoun->Sumw2(); hgoo->Sumw2(); hfak->Sumw2();
274 hgl->Divide(hfoun,hgoo,1,1.,"b");
275 hfl->Divide(hfak,hgoo,1,1.,"b");
276 hgl->SetMaximum(1.4);
277 hgl->SetYTitle("Matching efficiency");
278 hgl->SetXTitle("Tan(lambda)");
283 hfp->Draw("histsame");
284 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
286 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
292 hfl->Draw("histsame");
293 TLine *line3 = new TLine(-1,1.0,1,1.0); line3->SetLineStyle(4);
295 TLine *line4 = new TLine(-1,0.9,1,0.9); line4->SetLineStyle(4);
300 TFile fc("AliTOFComparison.root","RECREATE");
304 gBenchmark->Stop("AliTOFComparison");
305 gBenchmark->Show("AliTOFComparison");
311 Int_t GoodTracksTOF(const Char_t *dir) {
313 delete gAlice->GetRunLoader();
314 delete gAlice;//if everything was OK here it is already NULL
319 sprintf(fname,"%s/galice.root",dir);
321 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
323 ::Error("GoodTracksTOF","Can't start session !");
329 rl->LoadKinematics();
332 AliLoader* tofl = rl->GetLoader("TOFLoader");
334 ::Error("GoodTracksTOF","Can not get the TOF loader !");
338 tofl->LoadDigits("read");
340 Int_t nev=rl->GetNumberOfEvents();
341 ::Info("GoodTracksTOF","Number of events : %d\n",nev);
343 sprintf(fname,"%s/GoodTracksITS.root",dir);
344 TFile *itsFile=TFile::Open(fname);
345 if ((!itsFile)||(!itsFile->IsOpen())) {
346 ::Error("GoodTracksTOF","Can't open the GoodTracksITS.root !");
350 TClonesArray dum("AliTrackReference",1000), *itsRefs=&dum;
351 TTree *itsTree=(TTree*)itsFile->Get("itsTree");
353 ::Error("GoodTracksTOF","Can't get the ITS reference tree !");
357 TBranch *itsBranch=itsTree->GetBranch("ITS");
359 ::Error("GoodTracksTOF","Can't get the ITS reference branch !");
363 itsBranch->SetAddress(&itsRefs);
366 sprintf(fname,"%s/GoodTracksTOF.root",dir);
367 TFile *tofFile=TFile::Open(fname,"recreate");
368 TClonesArray dummy("AliTrackReference",1000), *tofRefs=&dummy;
369 TTree tofTree("tofTree","Tree with info about the reconstructable TOF tracks");
370 tofTree.Branch("TOF",&tofRefs);
373 //******** Loop over generated events
374 for (Int_t e=0; e<nev; e++) {
376 rl->GetEvent(e); tofFile->cd();
378 Int_t np = rl->GetHeader()->GetNtrack();
379 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
381 //******** Fill the "good" masks
382 Int_t *good=new Int_t[np]; Int_t k; for (k=0; k<np; k++) good[k]=0;
384 TTree *dTree=tofl->TreeD();
386 ::Error("GoodTracksTOF","Can't get the TOF cluster tree !");
390 TBranch *branch=dTree->GetBranch("TOF");
392 ::Error("GoodTracksTOF","Can't get the branch with the TOF digits !");
395 TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
396 branch->SetAddress(&digits);
399 Int_t nd=digits->GetEntriesFast();
401 for (Int_t i=0; i<nd; i++) {
402 AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
403 Int_t l0=d->GetTrack(0);
404 if (l0>=np) {cerr<<"Wrong label: "<<l0<<endl; continue;}
405 Int_t l1=d->GetTrack(1);
406 if (l1>=np) {cerr<<"Wrong label: "<<l1<<endl; continue;}
407 Int_t l2=d->GetTrack(2);
408 if (l2>=np) {cerr<<"Wrong label: "<<l2<<endl; continue;}
409 if (l0>=0) good[l0]++;
410 if (l1>=0) good[l1]++;
411 if (l2>=0) good[l2]++;
416 //****** select tracks which are "good" enough
417 AliStack* stack = rl->Stack();
419 itsTree->GetEvent(e);
420 Int_t nk=itsRefs->GetEntriesFast();
423 for (k=0; k<nk; k++) {
424 AliTrackReference *itsRef=(AliTrackReference *)itsRefs->UncheckedAt(k);
425 Int_t lab=itsRef->Label();
426 if (good[lab] == 0) continue;
427 TParticle *p = (TParticle*)stack->Particle(lab);
429 cerr<<"Can not get particle "<<lab<<endl;
433 if (TMath::Abs(p->Vx())>0.1) continue;
434 if (TMath::Abs(p->Vy())>0.1) continue;
435 //if (TMath::Abs(p->Vz())>0.1) continue;
437 new((*tofRefs)[nt]) AliTrackReference(*itsRef);
447 } //*** end of the loop over generated events