1 /****************************************************************************
2 * Very important, delicate and rather obscure macro. *
3 * ("a la" AliTPCComparison.C) *
5 * Creates list of "trackable" tracks, *
6 * calculates efficiency, resolutions etc. *
7 * (To get the list of the "trackable" tracks one should *
8 * first run the AliTPCComparison.C macro) *
10 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
11 ****************************************************************************/
13 #if !defined(__CINT__) || defined(__MAKECINT__)
16 #include <Riostream.h>
20 #include <TParticle.h>
24 #include <TBenchmark.h>
29 #include "AliHeader.h"
30 #include "AliTrackReference.h"
31 #include "AliRunLoader.h"
33 #include "AliESDEvent.h"
34 #include "AliESDtrack.h"
37 Int_t GoodTracksTRD(const Char_t *dir=".");
39 extern AliRun *gAlice;
40 extern TBenchmark *gBenchmark;
43 static Int_t allgood=0;
44 static Int_t allselected=0;
45 static Int_t allfound=0;
47 Int_t AliTRDComparisonV2
48 (Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".") {
49 gBenchmark->Start("AliTRDComparisonV2");
51 ::Info("AliTRDComparisonV2.C","Doing comparison...");
54 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
56 hp=new TH1F("hp","PHI resolution",50,-70.,70.);
58 hp->SetXTitle("(mrad)");
60 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
62 hl=new TH1F("hl","LAMBDA resolution",50,-70,70);
64 hl->SetXTitle("(mrad)");
66 TH1F *hc=(TH1F*)gROOT->FindObject("hc");
68 hc=new TH1F("hc","Number of the assigned clusters",25,110,135);
71 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
73 hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
75 hpt->SetXTitle("(%)");
77 TH1F *hmpt=(TH1F*)gROOT->FindObject("hmpt");
79 hmpt=new TH1F("hmpt","Y and Z resolution",30,-30,30);
80 hmpt->SetFillColor(6);
81 hmpt->SetXTitle("(mm)");
83 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
84 if (!hz) hz=new TH1F("hz","Z resolution",30,-30,30);
88 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
89 if (!hgood) hgood=new TH1F("hgood","Good tracks",30,0.2,6.1);
91 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
92 if (!hfound) hfound=new TH1F("hfound","Found tracks",30,0.2,6.1);
94 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
95 if (!hfake) hfake=new TH1F("hfake","Fake tracks",30,0.2,6.1);
97 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
98 if (!hg) hg=new TH1F("hg","Efficiency for good tracks",30,0.2,6.1);
99 hg->SetLineColor(4); hg->SetLineWidth(2);
101 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
102 if (!hf) hf=new TH1F("hf","Efficiency for fake tracks",30,0.2,6.1);
103 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
105 TH1F *he=(TH1F*)gROOT->FindObject("he");
107 he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,1000.);
109 TH2F *hep=(TH2F*)gROOT->FindObject("hep");
110 if (!hep) hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,2000.);
111 hep->SetMarkerStyle(8);
112 hep->SetMarkerSize(0.4);
116 sprintf(fname,"%s/GoodTracksTRD.root",dir);
118 TFile *refFile=TFile::Open(fname,"old");
119 if (!refFile || !refFile->IsOpen()) {
120 ::Info("AliTRDComparisonV2.C","Marking good tracks (will take a while)...");
121 if (GoodTracksTRD(dir)) {
122 ::Error("AliTRDComparisonV2.C","Can't generate the reference file !");
126 refFile=TFile::Open(fname,"old");
127 if (!refFile || !refFile->IsOpen()) {
128 ::Error("AliTRDComparisonV2.C","Can't open the reference file !");
132 TTree *trdTree=(TTree*)refFile->Get("trdTree");
134 ::Error("AliTRDComparisonV2.C","Can't get the reference tree !");
137 TBranch *branch=trdTree->GetBranch("TRD");
139 ::Error("AliTRDComparisonV2.C","Can't get the TRD branch !");
142 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
143 branch->SetAddress(&refs);
146 sprintf(fname,"%s/AliESDs.root",dir);
147 TFile *ef=TFile::Open(fname);
148 if ((!ef)||(!ef->IsOpen())) {
149 sprintf(fname,"%s/AliESDtrd.root",dir);
150 ef=TFile::Open(fname);
151 if ((!ef)||(!ef->IsOpen())) {
152 ::Error("AliTRDComparisonV2.C","Can't open AliESDtrd.root !");
156 AliESDEvent* event = new AliESDEvent();
157 TTree* esdTree = (TTree*) ef->Get("esdTree");
159 ::Error("AliTRDComparisonV2.C", "no ESD tree found");
162 event->ReadFromTree(esdTree);
165 //******* Loop over events *********
167 while (esdTree->GetEvent(e)) {
168 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
170 Int_t nentr=event->GetNumberOfTracks();
173 if (trdTree->GetEvent(e++)==0) {
174 cerr<<"No reconstructable tracks !\n";
178 Int_t ngood=refs->GetEntriesFast();
181 const Int_t MAX=15000;
182 Int_t notf[MAX], nnotf=0;
183 Int_t fake[MAX], nfake=0;
184 Int_t mult[MAX], numb[MAX], nmult=0;
186 for (k=0; k<ngood; k++) {
187 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(k);
188 Int_t lab=ref->Label(), tlab=-1;
189 Float_t ptg=ref->Pt();
191 if (ptg<ptcutl) continue;
192 if (ptg>ptcuth) continue;
200 for (Int_t i=0; i<nentr; i++) {
201 AliESDtrack *t=event->GetTrack(i);
202 UInt_t status=t->GetStatus();
204 if ((status&AliESDtrack::kTRDout)==0) continue;
206 Int_t lbl=t->GetTRDLabel();
207 if (lab==TMath::Abs(lbl)) {
208 if (cnt==0) {esd=t; tlab=lbl;}
217 numb[nmult]=cnt; nmult++;
220 if (lab==tlab) hfound->Fill(ptg);
226 AliExternalTrackParam out(*esd->GetOuterParam());
228 Double_t bz=event->GetMagneticField();
229 Double_t xg = ref->LocalX();
230 out.PropagateTo(xg,bz);
232 Float_t phi=TMath::ASin(out.GetSnp()) + out.GetAlpha();
233 if (phi < 0) phi+=2*TMath::Pi();
234 if (phi >=2*TMath::Pi()) phi-=2*TMath::Pi();
235 Float_t phig=ref->Phi();
236 hp->Fill((phi - phig)*1000.);
238 Float_t lam=TMath::ATan(out.GetTgl());
239 Float_t lamg=TMath::ATan2(ref->Pz(),ptg);
240 hl->Fill((lam - lamg)*1000.);
242 hc->Fill(esd->GetTRDclusters(0));
244 Float_t pt_1=out.OneOverPt();
245 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
247 Float_t y=out.GetY();
248 Float_t yg=ref->LocalY();
249 hmpt->Fill(10*(y - yg));
251 Float_t z=out.GetZ();
253 hz->Fill(10*(z - zg));
255 Float_t mom=1./(pt_1*TMath::Cos(lam));
256 Float_t dedx=esd->GetTRDsignal();
257 hep->Fill(mom,dedx,1.);
259 Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG !
261 if (TMath::Abs(pdg)==211) //pions
262 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
266 cout<<"\nList of Not found tracks :\n";
267 for (k=0; k<nnotf; k++){
269 if ((k%9)==8) cout<<"\n";
271 cout<<"\n\nList of fake tracks :\n";
272 for (k=0; k<nfake; k++){
274 if ((k%9)==8) cout<<"\n";
276 cout<<"\n\nList of multiple found tracks :\n";
277 for (k=0; k<nmult; k++) {
278 cout<<"id. "<<mult[k]
279 <<" found - "<<numb[k]<<"times\n";
283 cout<<"Number of found tracks : "<<nentr<<endl;
284 cout<<"Number of \"good\" tracks : "<<ngood<<endl;
287 } //***** End of the loop over events
296 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
297 if (ng!=0) cout<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
298 cout<<"Total number selected of \"good\" tracks ="<<allselected<<endl<<endl;
299 cout<<"Total number of found tracks ="<<allfound<<endl;
300 cout<<"Total number of \"good\" tracks ="<<allgood<<endl;
303 gStyle->SetOptStat(111110);
304 gStyle->SetOptFit(1);
306 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
310 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
311 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
312 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus"); c1->cd();
314 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
315 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
316 if (hl->GetEntries()<minc) hl->Draw(); else hl->Fit("gaus"); c1->cd();
318 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
319 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
320 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus"); c1->cd();
322 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
323 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
324 if (hmpt->GetEntries()<minc) hmpt->Draw(); else hmpt->Fit("gaus");
325 hz->Draw("same"); c1->cd();
328 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
329 p5->SetFillColor(41); p5->SetFrameFillColor(10);
330 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
331 hg->Divide(hfound,hgood,1,1.,"b");
332 hf->Divide(hfake,hgood,1,1.,"b");
334 hg->SetYTitle("Tracking efficiency");
335 hg->SetXTitle("Pt (GeV/c)");
338 TLine *line1 = new TLine(0.2,1.0,6.1,1.0); line1->SetLineStyle(4);
340 TLine *line2 = new TLine(0.2,0.9,6.1,0.9); line2->SetLineStyle(4);
344 hf->SetFillStyle(3013);
347 hf->Draw("histsame");
348 TText *text = new TText(0.461176,0.248448,"Fake tracks");
349 text->SetTextSize(0.05);
351 text = new TText(0.453919,1.11408,"Good tracks");
352 text->SetTextSize(0.05);
355 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
356 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
357 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
358 he->SetFillColor(2); he->SetFillStyle(3005);
359 he->SetXTitle("Arbitrary Units");
360 if (he->GetEntries()<minc) he->Draw(); else he->Fit("gaus"); c2->cd();
362 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
363 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
364 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
365 hep->Draw(); c1->cd();
367 TFile fc("AliTRDComparisonV2.root","RECREATE");
372 gBenchmark->Stop("AliTRDComparisonV2");
373 gBenchmark->Show("AliTRDComparisonV2");
380 Int_t GoodTracksTRD(const Char_t *dir) {
382 delete gAlice->GetRunLoader();
383 delete gAlice;//if everything was OK here it is already NULL
388 sprintf(fname,"%s/galice.root",dir);
390 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
392 ::Error("GoodTracksTRD","Can't start session !");
400 Int_t nev=rl->GetNumberOfEvents();
401 ::Info("GoodTracksTRD","Number of events : %d\n",nev);
403 sprintf(fname,"%s/GoodTracksTPC.root",dir);
404 TFile *tpcFile=TFile::Open(fname);
405 if ((!tpcFile)||(!tpcFile->IsOpen())) {
406 ::Error("GoodTracksTRD","Can't open the GoodTracksTPC.root !");
410 TClonesArray dum("AliTrackReference",1000), *tpcRefs=&dum;
411 TTree *tpcTree=(TTree*)tpcFile->Get("tpcTree");
413 ::Error("GoodTracksTRD","Can't get the TPC reference tree !");
417 TBranch *tpcBranch=tpcTree->GetBranch("TPC");
419 ::Error("GoodTracksTRD","Can't get the TPC reference branch !");
423 tpcBranch->SetAddress(&tpcRefs);
425 sprintf(fname,"%s/GoodTracksTRD.root",dir);
426 TFile *trdFile=TFile::Open(fname,"recreate");
427 TClonesArray dummy2("AliTrackReference",1000), *trdRefs=&dummy2;
428 TTree trdTree("trdTree","Info about the reconstructable TRD tracks");
429 trdTree.Branch("TRD",&trdRefs);
431 //******** Loop over generated events
432 for (Int_t e=0; e<nev; e++) {
435 rl->GetEvent(e); trdFile->cd();
437 Int_t np = rl->GetHeader()->GetNtrack();
438 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
441 TTree *TR=rl->TreeTR();
442 TBranch *branch=TR->GetBranch("TrackReferences");
444 ::Error("GoodTracksTRD","No TRD track references !");
448 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
449 branch->SetAddress(&refs);
450 Int_t nr=TR->GetEntries();
452 //Preselect the "good" track candidates (TRD info only)
454 for (Int_t r=0; r<nr; r++) {
457 Int_t n=refs->GetEntriesFast();
461 AliTrackReference *ref0=(AliTrackReference *)refs->UncheckedAt(0);
462 if (ref0->LocalX() > 300.) continue;
464 AliTrackReference *refn=0x0;
465 for (Int_t iref=n-1; iref>=0; --iref) {
466 refn = (AliTrackReference *)refs->UncheckedAt(iref);
467 if (refn->LocalX() > 363. &&
468 refn->DetectorId() == AliTrackReference::kTRD) break;
472 if (TMath::Abs(ref0->Alpha() - refn->Alpha()) > 1e-5) continue;
474 new((*trdRefs)[nt++]) AliTrackReference(*refn);
477 //Check if the candidates are "good" from the TPC point of view
478 tpcTree->GetEvent(e);
479 Int_t ntpc=tpcRefs->GetEntriesFast();
480 for (Int_t t=0; t<nt; t++) {
481 AliTrackReference *ref=(AliTrackReference *)trdRefs->UncheckedAt(t);
482 Int_t lab=ref->Label();
483 for (k=0; k<ntpc; k++) {
485 *tpcRef=(AliTrackReference *)tpcRefs->UncheckedAt(k);
486 if (tpcRef->Label()==lab) {
487 ref->SetLength(tpcRef->GetLength());
491 if (k==ntpc) delete trdRefs->RemoveAt(t);
499 } //*** end of the loop over generated events