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 "AliTOFcluster.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->LoadRecPoints("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 !");
150 AliESD* event = new AliESD;
151 TTree* esdTree = (TTree*) ef->Get("esdTree");
153 ::Error("AliTOFComparison.C", "no ESD tree found");
156 esdTree->SetBranchAddress("ESD", &event);
160 //******* Loop over events *********
162 while (esdTree->GetEvent(e)) {
163 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
167 TTree *clsTree=tofl->TreeR();
169 cerr<<"Can't get the TOF cluster tree !\n";
172 TBranch *branch=clsTree->GetBranch("TOF");
174 cerr<<"Can't get the branch with the TOF digits !\n";
177 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
178 branch->SetAddress(&clusters);
180 clsTree->GetEvent(0);
181 Int_t nd=clusters->GetEntriesFast();
182 cerr<<"Number of the TOF clusters: "<<nd<<endl;
186 Int_t ntrk=event->GetNumberOfTracks();
187 cerr<<"Number of ESD tracks : "<<ntrk<<endl;
190 if (tofTree->GetEvent(e++)==0) {
191 cerr<<"No reconstructable tracks !\n";
195 Int_t ngood=refs->GetEntriesFast();
199 for (Int_t i=0; i<ngood; i++) {
200 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(i);
201 Int_t lab=ref->Label();
202 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
204 Double_t tgl=ref->Pz()/ptg; //tan(lambda)
206 if (ptg>pmin) { hgood->Fill(ptg); hgoo->Fill(tgl); }
210 for (j=0; j<ntrk; j++) {
211 AliESDtrack *tt=event->GetTrack(j);
212 if (lab!=TMath::Abs(tt->GetLabel())) continue;
214 //if ((tt->GetStatus()&AliESDtrack::kTOFpid) == 0) continue;
215 if (tt->GetTOFsignal() < 0) continue;
216 UInt_t idx=tt->GetTOFcluster();
217 if ((Int_t)idx>=nd) {
218 cerr<<"Wrong cluster index ! "<<idx<<endl;
221 AliTOFcluster *cls=(AliTOFcluster*)clusters->UncheckedAt(idx);
222 if (cls->GetLabel(0)!=lab)
223 if (cls->GetLabel(1)!=lab)
224 if (cls->GetLabel(2)!=lab) {
226 if (ptg>pmin) { hfake->Fill(ptg); hfak->Fill(tgl); }
229 if (ptg>pmin) { hfound->Fill(ptg); hfoun->Fill(tgl); }
234 cerr<<"Not matched: "<<lab<<" ";
236 cerr<<(t->GetStatus()&AliESDtrack::kITSout)<<' '
237 <<(t->GetStatus()&AliESDtrack::kTPCout)<<' '
238 <<(t->GetStatus()&AliESDtrack::kTRDout)<<' '
239 <<(t->GetStatus()&AliESDtrack::kTIME);
240 } else cerr<<"No ESD track !";
244 cout<<"Number of good tracks: "<<ngood<<endl;
245 cout<<"Number of matched tracks: "<<matched<<endl;
246 cout<<"Number of mismatched tracks: "<<mismatched<<endl;
248 allgood+=ngood; allmatched+=matched; allmismatched+=mismatched;
251 } //***** End of the loop over events
259 if (allgood!=0) cerr<<"\n\nEfficiency: "<<Float_t(allmatched)/allgood<<endl;
260 cout<<"Total number of good tracks: "<<allgood<<endl;
261 cout<<"Total number of matched tracks: "<<allmatched<<endl;
262 cout<<"Total number of mismatched tracks: "<<allmismatched<<endl;
264 TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
266 c1=new TCanvas("c1","",0,0,600,900);
269 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
270 hgp->Divide(hfound,hgood,1,1.,"b");
271 hfp->Divide(hfake,hgood,1,1.,"b");
272 hgp->SetMaximum(1.4);
273 hgp->SetYTitle("Matching efficiency");
274 hgp->SetXTitle("Pt (GeV/c)");
276 hfoun->Sumw2(); hgoo->Sumw2(); hfak->Sumw2();
277 hgl->Divide(hfoun,hgoo,1,1.,"b");
278 hfl->Divide(hfak,hgoo,1,1.,"b");
279 hgl->SetMaximum(1.4);
280 hgl->SetYTitle("Matching efficiency");
281 hgl->SetXTitle("Tan(lambda)");
286 hfp->Draw("histsame");
287 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
289 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
295 hfl->Draw("histsame");
296 TLine *line3 = new TLine(-1,1.0,1,1.0); line3->SetLineStyle(4);
298 TLine *line4 = new TLine(-1,0.9,1,0.9); line4->SetLineStyle(4);
303 TFile fc("AliTOFComparison.root","RECREATE");
307 gBenchmark->Stop("AliTOFComparison");
308 gBenchmark->Show("AliTOFComparison");
314 Int_t GoodTracksTOF(const Char_t *dir) {
316 delete gAlice->GetRunLoader();
317 delete gAlice;//if everything was OK here it is already NULL
322 sprintf(fname,"%s/galice.root",dir);
324 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
326 ::Error("GoodTracksTOF","Can't start session !");
332 rl->LoadKinematics();
335 AliLoader* tofl = rl->GetLoader("TOFLoader");
337 ::Error("GoodTracksTOF","Can not get the TOF loader !");
341 tofl->LoadRecPoints("read");
343 Int_t nev=rl->GetNumberOfEvents();
344 ::Info("GoodTracksTOF","Number of events : %d\n",nev);
346 sprintf(fname,"%s/GoodTracksITS.root",dir);
347 TFile *itsFile=TFile::Open(fname);
348 if ((!itsFile)||(!itsFile->IsOpen())) {
349 ::Error("GoodTracksTOF","Can't open the GoodTracksITS.root !");
353 TClonesArray dum("AliTrackReference",1000), *itsRefs=&dum;
354 TTree *itsTree=(TTree*)itsFile->Get("itsTree");
356 ::Error("GoodTracksTOF","Can't get the ITS reference tree !");
360 TBranch *itsBranch=itsTree->GetBranch("ITS");
362 ::Error("GoodTracksTOF","Can't get the ITS reference branch !");
366 itsBranch->SetAddress(&itsRefs);
369 sprintf(fname,"%s/GoodTracksTOF.root",dir);
370 TFile *tofFile=TFile::Open(fname,"recreate");
371 TClonesArray dummy("AliTrackReference",1000), *tofRefs=&dummy;
372 TTree tofTree("tofTree","Tree with info about the reconstructable TOF tracks");
373 tofTree.Branch("TOF",&tofRefs);
376 //******** Loop over generated events
377 for (Int_t e=0; e<nev; e++) {
379 rl->GetEvent(e); tofFile->cd();
381 Int_t np = rl->GetHeader()->GetNtrack();
382 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
384 //******** Fill the "good" masks
385 Int_t *good=new Int_t[np]; Int_t k; for (k=0; k<np; k++) good[k]=0;
387 TTree *cTree=tofl->TreeR();
389 ::Error("GoodTracksTOF","Can't get the TOF cluster tree !");
393 TBranch *branch=cTree->GetBranch("TOF");
395 ::Error("GoodTracksTOF","Can't get the branch with the TOF digits !");
398 TClonesArray dummy("AliTOFcluster",10000), *clusters=&dummy;
399 branch->SetAddress(&clusters);
402 Int_t nd=clusters->GetEntriesFast();
404 for (Int_t i=0; i<nd; i++) {
405 AliTOFcluster *c=(AliTOFcluster*)clusters->UncheckedAt(i);
406 Int_t l0=c->GetLabel(0);
407 if (l0>=np) {cerr<<"Wrong label: "<<l0<<endl; continue;}
408 Int_t l1=c->GetLabel(1);
409 if (l1>=np) {cerr<<"Wrong label: "<<l1<<endl; continue;}
410 Int_t l2=c->GetLabel(2);
411 if (l2>=np) {cerr<<"Wrong label: "<<l2<<endl; continue;}
412 if (l0>=0) good[l0]++;
413 if (l1>=0) good[l1]++;
414 if (l2>=0) good[l2]++;
419 //****** select tracks which are "good" enough
420 AliStack* stack = rl->Stack();
422 itsTree->GetEvent(e);
423 Int_t nk=itsRefs->GetEntriesFast();
426 for (k=0; k<nk; k++) {
427 AliTrackReference *itsRef=(AliTrackReference *)itsRefs->UncheckedAt(k);
428 Int_t lab=itsRef->Label();
429 if (good[lab] == 0) continue;
430 TParticle *p = (TParticle*)stack->Particle(lab);
432 cerr<<"Can not get particle "<<lab<<endl;
436 if (TMath::Abs(p->Vx())>0.1) continue;
437 if (TMath::Abs(p->Vy())>0.1) continue;
438 //if (TMath::Abs(p->Vz())>0.1) continue;
440 new((*tofRefs)[nt]) AliTrackReference(*itsRef);
450 } //*** end of the loop over generated events