1 /****************************************************************************
2 * Very important, delicate and rather obscure macro. *
4 * Creates list of "trackable" tracks, *
5 * calculates efficiency, resolutions etc. *
6 * The ESD tracks must be in an appropriate state (kITSin or kITSrefit) *
8 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
9 ****************************************************************************/
11 #if !defined(__CINT__) || defined(__MAKECINT__)
14 #include <Riostream.h>
18 #include <TParticle.h>
22 #include <TBenchmark.h>
28 #include "AliHeader.h"
29 #include "AliTrackReference.h"
30 #include "AliRunLoader.h"
35 #include "AliITSgeom.h"
36 #include "AliITStrackV2.h"
37 #include "AliITSclusterV2.h"
38 #include "AliITSLoader.h"
41 Int_t GoodTracksITS(const Char_t *dir=".");
43 extern AliRun *gAlice;
44 extern TBenchmark *gBenchmark;
47 static Int_t allgood=0;
48 static Int_t allselected=0;
49 static Int_t allfound=0;
51 Int_t AliITSComparisonV2
52 (Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".", Float_t ratio=0.0) {
53 gBenchmark->Start("AliITSComparisonV2");
55 ::Info("AliITSComparisonV2.C","Doing comparison...");
58 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
59 if (!hp) hp=new TH1F("hp","PHI resolution",50,-20.,20.);
62 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
63 if (!hl) hl=new TH1F("hl","LAMBDA resolution",50,-20,20);
66 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
67 if (!hpt) hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
70 TH1F *hmpt=(TH1F*)gROOT->FindObject("hmpt");
72 hmpt=new TH1F("hmpt","Transverse impact parameter",30,-300,300);
73 hmpt->SetFillColor(6);
75 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
76 if (!hz) hz=new TH1F("hz","Longitudinal impact parameter",30,-300,300);
80 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
81 if (!hgood) hgood=new TH1F("hgood","Good tracks",30,0.2,6.1);
83 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
84 if (!hfound) hfound=new TH1F("hfound","Found tracks",30,0.2,6.1);
86 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
87 if (!hfake) hfake=new TH1F("hfake","Fake tracks",30,0.2,6.1);
89 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
90 if (!hg) hg=new TH1F("hg","Efficiency for good tracks",30,0.2,6.1);
91 hg->SetLineColor(4); hg->SetLineWidth(2);
93 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
94 if (!hf) hf=new TH1F("hf","Efficiency for fake tracks",30,0.2,6.1);
95 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
97 TH1F *he=(TH1F*)gROOT->FindObject("he");
99 he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,100.);
101 TH2F *hep=(TH2F*)gROOT->FindObject("hep");
102 if (!hep) hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,400.);
103 hep->SetMarkerStyle(8);
104 hep->SetMarkerSize(0.4);
108 sprintf(fname,"%s/GoodTracksITS.root",dir);
110 TFile *refFile=TFile::Open(fname,"old");
111 if (!refFile || !refFile->IsOpen()) {
112 ::Info("AliITSComparisonV2.C","Marking good tracks (will take a while)...");
113 if (GoodTracksITS(dir)) {
114 ::Error("AliITSComparisonV2.C","Can't generate the reference file !");
118 refFile=TFile::Open(fname,"old");
119 if (!refFile || !refFile->IsOpen()) {
120 ::Error("AliITSComparisonV2.C","Can't open the reference file !");
124 TTree *itsTree=(TTree*)refFile->Get("itsTree");
126 ::Error("AliITSComparisonV2.C","Can't get the reference tree !");
129 TBranch *branch=itsTree->GetBranch("ITS");
131 ::Error("AliITSComparisonV2.C","Can't get the ITS branch !");
134 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
135 branch->SetAddress(&refs);
138 sprintf(fname,"%s/AliESDs.root",dir);
139 TFile *ef=TFile::Open(fname);
140 if ((!ef)||(!ef->IsOpen())) {
141 sprintf(fname,"%s/AliESDits.root",dir);
142 ef=TFile::Open(fname);
143 if ((!ef)||(!ef->IsOpen())) {
144 ::Error("AliITSComparisonV2.C","Can't open AliESDits.root !");
149 TIter next(ef->GetListOfKeys());
153 //******* Loop over events *********
155 while ((key=(TKey*)next())!=0) {
156 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
158 AliESD *event=(AliESD*)key->ReadObj();
160 Float_t field=event->GetMagneticField();
161 AliKalmanTrack::SetConvConst(1000/0.299792458/field);
163 Int_t nentr=event->GetNumberOfTracks();
166 if (itsTree->GetEvent(e++)==0) {
167 cerr<<"No reconstructable tracks !\n";
171 Int_t ngood=refs->GetEntriesFast();
174 const Int_t MAX=15000;
175 Int_t notf[MAX], nnotf=0;
176 Int_t fake[MAX], nfake=0;
177 Int_t mult[MAX], numb[MAX], nmult=0;
179 for (k=0; k<ngood; k++) {
180 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(k);
181 Int_t lab=ref->Label(), tlab=-1;
182 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
184 if (ptg<ptcutl) continue;
185 if (ptg>ptcuth) continue;
194 for (Int_t i=0; i<nentr; i++) {
195 AliESDtrack *t=event->GetTrack(i);
196 UInt_t status=t->GetStatus();
197 UInt_t flags=AliESDtrack::kTPCin|AliESDtrack::kITSin;
199 if ((status&AliESDtrack::kITSrefit)==0) continue;
201 if ((status&flags)==status) pipe=1;
203 Int_t lbl=t->GetLabel();
204 if (lab==TMath::Abs(lbl)) {
205 if (cnt==0) {esd=t; tlab=lbl;}
214 numb[nmult]=cnt; nmult++;
217 if (esd->GetITSFakeRatio()<ratio) tlab = TMath::Abs(tlab);
219 if (lab==tlab) hfound->Fill(ptg);
225 AliITStrackV2 track(*esd);
227 track.PropagateTo(3.,0.0028,65.19);
228 track.PropagateToVertex(); // This is not "exactly" the vertex
231 Double_t xv,par[5]; track.GetExternalParameters(xv,par);
232 Float_t phi=TMath::ASin(par[2]) + track.GetAlpha();
233 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
234 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
235 Float_t lam=TMath::ATan(par[3]);
236 Float_t pt_1=TMath::Abs(par[4]);
238 Float_t phig=TMath::ATan2(ref->Py(),ref->Px());
239 hp->Fill((phi - phig)*1000.);
241 Float_t lamg=TMath::ATan2(ref->Pz(),ptg);
242 hl->Fill((lam - lamg)*1000.);
244 Double_t d=10000*track.GetD(ref->X(),ref->Y());
247 Double_t z=10000*(track.GetZ()-ref->Z());
250 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
252 Float_t mom=1./(pt_1*TMath::Cos(lam));
253 Float_t dedx=track.GetdEdx();
254 hep->Fill(mom,dedx,1.);
256 Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG !
258 if (TMath::Abs(pdg)==211) //pions
259 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
263 cout<<"\nList of Not found tracks :\n";
264 for (k=0; k<nnotf; k++){
266 if ((k%9)==8) cout<<"\n";
268 cout<<"\n\nList of fake tracks :\n";
269 for (k=0; k<nfake; k++){
271 if ((k%9)==8) cout<<"\n";
273 cout<<"\n\nList of multiple found tracks :\n";
274 for (k=0; k<nmult; k++) {
275 cout<<"id. "<<mult[k]
276 <<" found - "<<numb[k]<<"times\n";
280 cout<<"Number of found tracks : "<<nentr<<endl;
281 cout<<"Number of \"good\" tracks : "<<ngood<<endl;
285 } //***** End of the loop over events
292 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
293 if (ng!=0) cout<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
294 cout<<"Total number selected of \"good\" tracks ="<<allselected<<endl<<endl;
295 cout<<"Total number of found tracks ="<<allfound<<endl;
296 cout<<"Total number of \"good\" tracks ="<<allgood<<endl;
299 gStyle->SetOptStat(111110);
300 gStyle->SetOptFit(1);
302 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
306 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
307 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
308 hp->SetFillColor(4); hp->SetXTitle("(mrad)");
309 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus"); c1->cd();
311 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
312 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
313 hl->SetXTitle("(mrad)");
314 if (hl->GetEntries()<minc) hl->Draw(); else hl->Fit("gaus"); c1->cd();
316 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
317 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
318 hpt->SetXTitle("(%)");
319 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus"); c1->cd();
321 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
322 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
323 hmpt->SetXTitle("(micron)");
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("AliITSComparisonV2.root","RECREATE");
372 gBenchmark->Stop("AliITSComparisonV2");
373 gBenchmark->Show("AliITSComparisonV2");
380 Int_t GoodTracksITS(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("GoodTracksITS","Can't start session !");
398 rl->LoadKinematics();
400 AliITS *ITS=(AliITS*)rl->GetAliRun()->GetDetector("ITS");
402 ::Error("GoodTracksITS","Can't get the ITS !");
406 AliITSgeom *geom=ITS->GetITSgeom();
408 ::Error("GoodTracksITS","Can't get the ITS geometry !");
413 AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
415 ::Error("GoodTracksITS","Can not find the ITSLoader");
419 itsl->LoadRecPoints();
422 Int_t nev=rl->GetNumberOfEvents();
423 ::Info("GoodTracksITS","Number of events : %d\n",nev);
425 sprintf(fname,"%s/GoodTracksTPC.root",dir);
426 TFile *tpcFile=TFile::Open(fname);
427 if ((!tpcFile)||(!tpcFile->IsOpen())) {
428 ::Error("GoodTracksITS","Can't open the GoodTracksTPC.root !");
432 TClonesArray dum("AliTrackReference",1000), *tpcRefs=&dum;
433 TTree *tpcTree=(TTree*)tpcFile->Get("tpcTree");
435 ::Error("GoodTracksITS","Can't get the TPC reference tree !");
439 TBranch *tpcBranch=tpcTree->GetBranch("TPC");
441 ::Error("GoodTracksITS","Can't get the TPC reference branch !");
445 tpcBranch->SetAddress(&tpcRefs);
447 sprintf(fname,"%s/GoodTracksITS.root",dir);
448 TFile *itsFile=TFile::Open(fname,"recreate");
449 TClonesArray dummy("AliTrackReference",1000), *itsRefs=&dummy;
450 TTree itsTree("itsTree","Tree with info about the reconstructable ITS tracks");
451 itsTree.Branch("ITS",&itsRefs);
453 //******** Loop over generated events
454 for (Int_t e=0; e<nev; e++) {
457 rl->GetEvent(e); itsFile->cd();
459 Int_t np = rl->GetHeader()->GetNtrack();
460 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
462 //******** Fill the "good" masks
463 Int_t *good=new Int_t[np]; for (k=0; k<np; k++) good[k]=0;
465 TTree *cTree=itsl->TreeR();
467 ::Error("GoodTracksITS","Can't get the cluster tree !");
471 TBranch *branch=cTree->GetBranch("Clusters");
473 ::Error("GoodTracksITS","Can't get the clusters branch !");
477 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
478 branch->SetAddress(&clusters);
480 Int_t entr=(Int_t)cTree->GetEntries();
481 for (k=0; k<entr; k++) {
483 Int_t ncl=clusters->GetEntriesFast(); if (ncl==0) continue;
484 Int_t lay,lad,det; geom->GetModuleId(k,lay,lad,det);
485 if (lay<1 || lay>6) {
486 ::Error("GoodTracksITS","Wrong layer !");
491 AliITSclusterV2 *pnt=(AliITSclusterV2*)clusters->UncheckedAt(ncl);
492 Int_t l0=pnt->GetLabel(0);
494 // cerr<<"Wrong label: "<<l0<<endl;
497 Int_t l1=pnt->GetLabel(1);
499 // cerr<<"Wrong label: "<<l1<<endl;
502 Int_t l2=pnt->GetLabel(2);
504 // cerr<<"Wrong label: "<<l2<<endl;
507 Int_t mask=1<<(lay-1);
508 if (l0>=0) good[l0]|=mask;
509 if (l1>=0) good[l1]|=mask;
510 if (l2>=0) good[l2]|=mask;
516 //****** select tracks which are "good" enough
517 AliStack* stack = rl->Stack();
519 tpcTree->GetEvent(e);
520 Int_t nk=tpcRefs->GetEntriesFast();
522 for (k=0; k<nk; k++) {
523 AliTrackReference *tpcRef=(AliTrackReference *)tpcRefs->UncheckedAt(k);
524 Int_t lab=tpcRef->Label();
525 if (good[lab] != 0x3F) continue;
526 TParticle *p = (TParticle*)stack->Particle(lab);
528 cerr<<"Can not get particle "<<lab<<endl;
532 AliTrackReference *ref=new((*itsRefs)[nt]) AliTrackReference(*tpcRef);
533 ref->SetMomentum(p->Px(),p->Py(),p->Pz());
534 ref->SetPosition(p->Vx(),p->Vy(),p->Vz());
544 } //*** end of the loop over generated events