1 /****************************************************************************
2 * Legacy comparison macro, adapted to the upgraded ITS. *
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 * Before running, load the ITSU libraries: *
9 * gSystem->Load("libITSUpgradeBase");gSystem->Load("libITSUpgradeRec"); *
11 * Origin: I.Belikov, IPHC, Iouri.Belikov@iphc.cnrs.fr *
12 ****************************************************************************/
14 #if !defined(__CINT__) || defined(__MAKECINT__)
17 #include <Riostream.h>
21 #include <TParticle.h>
25 #include <TBenchmark.h>
31 #include "AliHeader.h"
32 #include "AliTrackReference.h"
33 #include "AliRunLoader.h"
35 #include "AliESDEvent.h"
36 #include "AliESDtrack.h"
38 #include "UPGRADE/AliITSUClusterPix.h"
39 #include "UPGRADE/AliITSULoader.h"
42 Int_t GoodTracksITS(const Char_t *dir=".");
44 extern AliRun *gAlice;
45 extern TBenchmark *gBenchmark;
48 static Int_t allgood=0;
49 static Int_t allselected=0;
50 static Int_t allfound=0;
52 Int_t AliITSUComparison
53 (Float_t ptcutl=0., Float_t ptcuth=2., const Char_t *dir=".") {
54 gBenchmark->Start("AliITSUComparison");
56 ::Info("AliITSUComparison.C","Doing comparison...");
59 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
60 if (!hp) hp=new TH1F("hp","PHI resolution",50,-20.,20.);
63 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
64 if (!hl) hl=new TH1F("hl","LAMBDA resolution",50,-20,20);
67 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
68 if (!hpt) hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
71 TH1F *hmpt=(TH1F*)gROOT->FindObject("hmpt");
73 hmpt=new TH1F("hmpt","Transverse impact parameter",30,-777,777);
74 hmpt->SetFillColor(6);
76 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
77 if (!hz) hz=new TH1F("hz","Longitudinal impact parameter",30,-777,777);
81 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
82 if (!hgood) hgood=new TH1F("hgood","Good tracks",nb,ptcutl,ptcuth);
84 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
85 if (!hfound) hfound=new TH1F("hfound","Found tracks",nb,ptcutl,ptcuth);
87 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
88 if (!hfake) hfake=new TH1F("hfake","Fake tracks",nb,ptcutl,ptcuth);
90 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
91 if (!hg) hg=new TH1F("hg","Efficiency for good tracks",nb,ptcutl,ptcuth);
92 hg->SetLineColor(4); hg->SetLineWidth(2);
94 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
95 if (!hf) hf=new TH1F("hf","Efficiency for fake tracks",nb,ptcutl,ptcuth);
96 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
99 TH1F *he=(TH1F*)gROOT->FindObject("he");
101 he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,200.);
103 TH2F *hep=(TH2F*)gROOT->FindObject("hep");
104 if (!hep) hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,400.);
105 hep->SetMarkerStyle(8);
106 hep->SetMarkerSize(0.4);
110 sprintf(fname,"%s/GoodTracksITS.root",dir);
112 TFile *refFile=TFile::Open(fname,"old");
113 if (!refFile || !refFile->IsOpen()) {
114 ::Info("AliITSUComparison.C","Marking good tracks (will take a while)...");
115 if (GoodTracksITS(dir)) {
116 ::Error("AliITSUComparison.C","Can't generate the reference file !");
120 refFile=TFile::Open(fname,"old");
121 if (!refFile || !refFile->IsOpen()) {
122 ::Error("AliITSUComparison.C","Can't open the reference file !");
126 TTree *itsTree=(TTree*)refFile->Get("itsTree");
128 ::Error("AliITSUComparison.C","Can't get the reference tree !");
131 TBranch *branch=itsTree->GetBranch("ITS");
133 ::Error("AliITSUComparison.C","Can't get the ITS branch !");
136 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
137 branch->SetAddress(&refs);
140 sprintf(fname,"%s/AliESDs.root",dir);
141 TFile *ef=TFile::Open(fname);
142 if ((!ef)||(!ef->IsOpen())) {
143 sprintf(fname,"%s/AliESDits.root",dir);
144 ef=TFile::Open(fname);
145 if ((!ef)||(!ef->IsOpen())) {
146 ::Error("AliITSUComparison.C","Can't open AliESDits.root !");
150 AliESDEvent* event = new AliESDEvent();
151 TTree* esdTree = (TTree*) ef->Get("esdTree");
153 ::Error("AliITSComparison.C", "no ESD tree found");
156 event->ReadFromTree(esdTree);
159 //******* Loop over events *********
161 while (esdTree->GetEvent(e)) {
162 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
164 Int_t nentr=event->GetNumberOfTracks();
167 if (itsTree->GetEvent(e++)==0) {
168 cerr<<"No reconstructable tracks !\n";
172 Int_t ngood=refs->GetEntriesFast();
175 const Int_t MAX=15000;
176 Int_t notf[MAX], nnotf=0;
177 Int_t fake[MAX], nfake=0;
178 Int_t mult[MAX], numb[MAX], nmult=0;
180 for (k=0; k<ngood; k++) {
181 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(k);
182 Int_t lab=ref->Label(), tlab=-1;
183 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
185 if (ptg<ptcutl) continue;
186 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();
198 if ((status&AliESDtrack::kITSrefit)==0) continue;
200 Int_t lbl=t->GetLabel();
201 if (lab==TMath::Abs(lbl)) {
202 if (cnt==0) {esd=t; tlab=lbl;}
203 if (lbl> 0) {esd=t; tlab=lbl;}
212 numb[nmult]=cnt; nmult++;
215 if (lab==tlab) hfound->Fill(ptg);
221 Double_t alpha=esd->GetAlpha(),xv,par[5];
222 esd->GetExternalParameters(xv,par);
223 Float_t phi=TMath::ASin(par[2]) + alpha;
224 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
225 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
226 Float_t lam=TMath::ATan(par[3]);
227 Float_t pt_1=TMath::Abs(par[4]);
229 Float_t phig=TMath::ATan2(ref->Py(),ref->Px());
230 hp->Fill((phi - phig)*1000.);
232 Float_t lamg=TMath::ATan2(ref->Pz(),ptg);
233 hl->Fill((lam - lamg)*1000.);
235 Float_t d,z; esd->GetImpactParameters(d,z);
239 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
241 Float_t mom=(TMath::Abs(pt_1)>1e-5) ? 1./(pt_1*TMath::Cos(lam)) : 1e+5;
242 Float_t dedx=esd->GetITSsignal();
243 hep->Fill(mom,dedx,1.);
245 Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG !
247 if (TMath::Abs(pdg)==211) //pions
248 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
252 cout<<"\nList of Not found tracks :\n";
253 for (k=0; k<nnotf; k++){
255 if ((k%9)==8) cout<<"\n";
257 cout<<"\n\nList of fake tracks :\n";
258 for (k=0; k<nfake; k++){
260 if ((k%9)==8) cout<<"\n";
262 cout<<"\n\nList of multiple found tracks :\n";
263 for (k=0; k<nmult; k++) {
264 cout<<"id. "<<mult[k]
265 <<" found - "<<numb[k]<<"times\n";
269 cout<<"Number of found tracks : "<<nentr<<endl;
270 cout<<"Number of \"good\" tracks : "<<ngood<<endl;
273 } //***** End of the loop over events
282 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
283 if (ng!=0) cout<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
284 cout<<"Total number selected of \"good\" tracks ="<<allselected<<endl<<endl;
285 cout<<"Total number of found tracks ="<<allfound<<endl;
286 cout<<"Total number of \"good\" tracks ="<<allgood<<endl;
289 gStyle->SetOptStat(111110);
290 gStyle->SetOptFit(1);
292 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
296 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
297 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
298 hp->SetFillColor(4); hp->SetXTitle("(mrad)");
299 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus"); c1->cd();
301 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
302 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
303 hl->SetXTitle("(mrad)");
304 if (hl->GetEntries()<minc) hl->Draw(); else hl->Fit("gaus"); c1->cd();
306 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
307 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
308 hpt->SetXTitle("(%)");
309 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus"); c1->cd();
311 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
312 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
313 hmpt->SetXTitle("(micron)");
314 if (hmpt->GetEntries()<minc) hmpt->Draw(); else hmpt->Fit("gaus");
315 hz->Draw("same"); c1->cd();
318 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
319 p5->SetFillColor(41); p5->SetFrameFillColor(10);
320 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
321 hg->Divide(hfound,hgood,1,1.,"b");
322 hf->Divide(hfake,hgood,1,1.,"b");
324 hg->SetYTitle("Tracking efficiency");
325 hg->SetXTitle("Pt (GeV/c)");
328 TLine *line1 = new TLine(ptcutl,1.0,ptcuth,1.0); line1->SetLineStyle(4);
330 TLine *line2 = new TLine(ptcutl,0.9,ptcuth,0.9); line2->SetLineStyle(4);
334 hf->SetFillStyle(3013);
337 hf->Draw("histsame");
338 TText *text = new TText(0.461176,0.248448,"Fake tracks");
339 text->SetTextSize(0.05);
341 text = new TText(0.453919,1.11408,"Good tracks");
342 text->SetTextSize(0.05);
345 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
346 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
347 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
348 he->SetFillColor(2); he->SetFillStyle(3005);
349 he->SetXTitle("Arbitrary Units");
350 if (he->GetEntries()<minc) he->Draw(); else he->Fit("gaus"); c2->cd();
352 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
353 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
354 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
355 hep->Draw(); c1->cd();
357 TFile fc("AliITSUComparison.root","RECREATE");
362 gBenchmark->Stop("AliITSUComparison");
363 gBenchmark->Show("AliITSUComparison");
370 Int_t GoodTracksITS(const Char_t *dir) {
372 delete AliRunLoader::Instance();
373 delete gAlice;//if everything was OK here it is already NULL
378 sprintf(fname,"%s/galice.root",dir);
380 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
382 ::Error("GoodTracksITS","Can't start session !");
388 rl->LoadKinematics();
390 AliITSULoader* itsl = (AliITSULoader*)rl->GetLoader("ITSLoader");
392 ::Error("GoodTracksITS","Can not find the ITSLoader");
396 itsl->LoadRecPoints();
399 Int_t nev=rl->GetNumberOfEvents();
400 ::Info("GoodTracksITS","Number of events : %d\n",nev);
402 sprintf(fname,"%s/GoodTracksTPC.root",dir);
403 TFile *tpcFile=TFile::Open(fname);
404 if ((!tpcFile)||(!tpcFile->IsOpen())) {
405 ::Error("GoodTracksITS","Can't open the GoodTracksTPC.root !");
409 TClonesArray dum("AliTrackReference",1000), *tpcRefs=&dum;
410 TTree *tpcTree=(TTree*)tpcFile->Get("tpcTree");
412 ::Error("GoodTracksITS","Can't get the TPC reference tree !");
416 TBranch *tpcBranch=tpcTree->GetBranch("TPC");
418 ::Error("GoodTracksITS","Can't get the TPC reference branch !");
422 tpcBranch->SetAddress(&tpcRefs);
424 sprintf(fname,"%s/GoodTracksITS.root",dir);
425 TFile *itsFile=TFile::Open(fname,"recreate");
426 TClonesArray dummy2("AliTrackReference",1000), *itsRefs=&dummy2;
427 TTree itsTree("itsTree","Tree with info about the reconstructable ITS tracks");
428 itsTree.Branch("ITS",&itsRefs);
430 //******** Loop over generated events
431 for (Int_t e=0; e<nev; e++) {
434 rl->GetEvent(e); itsFile->cd();
436 Int_t np = rl->GetHeader()->GetNtrack();
437 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
439 //******** Fill the "good" masks
440 Int_t *good=new Int_t[np]; for (k=0; k<np; k++) good[k]=0;
442 TTree *cTree=itsl->TreeR();
444 ::Error("GoodTracksITS","Can't get the cluster tree !");
449 const Int_t nLayers=7;
450 TBranch *branch[nLayers];
451 TClonesArray clusters[nLayers];
452 for (Int_t layer=0; layer<nLayers; layer++) {
454 new(clusters+layer) TClonesArray("AliITSUClusterPix",1000);
456 sprintf(bname,"ITSRecPoints%d\0",layer);
457 branch[layer]=cTree->GetBranch(bname);
458 if (!branch[layer]) {
459 ::Error("GoodTracksITS","Can't get the clusters branch !");
463 branch[layer]->SetAddress(&ptr);
466 Int_t entr=(Int_t)cTree->GetEntries();
467 for (k=0; k<entr; k++) {
469 for (Int_t lay=0; lay<nLayers; lay++) {
470 Int_t ncl=clusters[lay].GetEntriesFast(); if (ncl==0) continue;
472 AliITSUClusterPix *pnt=
473 (AliITSUClusterPix*)clusters[lay].UncheckedAt(ncl);
474 Int_t l0=pnt->GetLabel(0);
476 // cerr<<"Wrong label: "<<l0<<endl;
479 Int_t l1=pnt->GetLabel(1);
481 // cerr<<"Wrong label: "<<l1<<endl;
484 Int_t l2=pnt->GetLabel(2);
486 // cerr<<"Wrong label: "<<l2<<endl;
490 if (l0>=0) good[l0]|=mask;
491 if (l1>=0) good[l1]|=mask;
492 if (l2>=0) good[l2]|=mask;
494 clusters[lay].Clear();
500 //****** select tracks which are "good" enough
501 AliStack* stack = rl->Stack();
503 tpcTree->GetEvent(e);
504 Int_t nk=tpcRefs->GetEntriesFast();
506 for (k=0; k<nk; k++) {
507 AliTrackReference *tpcRef=(AliTrackReference *)tpcRefs->UncheckedAt(k);
508 Int_t lab=tpcRef->Label();
509 if (good[lab] != 0x7F) continue;
510 TParticle *p = (TParticle*)stack->Particle(lab);
512 cerr<<"Can not get particle "<<lab<<endl;
516 AliTrackReference *ref=new((*itsRefs)[nt]) AliTrackReference(*tpcRef);
517 ref->SetMomentum(p->Px(),p->Py(),p->Pz());
518 ref->SetPosition(p->Vx(),p->Vy(),p->Vz());
528 } //*** end of the loop over generated events