]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSComparisonV2.C
Missing setter added
[u/mrichter/AliRoot.git] / ITS / AliITSComparisonV2.C
CommitLineData
c630aafd 1/****************************************************************************
5102bab6 2 * Very important, delicate and rather obscure macro. *
3 * *
4 * Creates list of "trackable" tracks, *
5 * calculates efficiency, resolutions etc. *
6 * The ESD tracks must be in an appropriate state (kITSin or kITSrefit) *
7 * *
c630aafd 8 * Origin: I.Belikov, CERN, Jouri.Belikov@cern.ch *
9 ****************************************************************************/
10
11#if !defined(__CINT__) || defined(__MAKECINT__)
4fa1e629 12 #include <TMath.h>
13 #include <TError.h>
ddae8318 14 #include <Riostream.h>
4fa1e629 15 #include <TH1F.h>
16 #include <TH2F.h>
17 #include <TTree.h>
18 #include <TParticle.h>
19 #include <TCanvas.h>
20 #include <TLine.h>
21 #include <TText.h>
22 #include <TBenchmark.h>
23 #include <TStyle.h>
8b462fd8 24 #include <TFile.h>
4fa1e629 25 #include <TROOT.h>
03248e6d 26
c630aafd 27 #include "AliStack.h"
4fa1e629 28 #include "AliHeader.h"
29 #include "AliTrackReference.h"
88cb7938 30 #include "AliRunLoader.h"
4fa1e629 31 #include "AliRun.h"
4514157e 32 #include "AliESDEvent.h"
4fa1e629 33
00a7cc50 34 #include "AliITSRecPoint.h"
4fa1e629 35 #include "AliITSLoader.h"
03248e6d 36#endif
37
4fa1e629 38Int_t GoodTracksITS(const Char_t *dir=".");
5102bab6 39
c630aafd 40extern AliRun *gAlice;
4fa1e629 41extern TBenchmark *gBenchmark;
42extern TROOT *gROOT;
c630aafd 43
4fa1e629 44static Int_t allgood=0;
45static Int_t allselected=0;
46static Int_t allfound=0;
47
48Int_t AliITSComparisonV2
7e9ae194 49(Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".") {
4fa1e629 50 gBenchmark->Start("AliITSComparisonV2");
51
52 ::Info("AliITSComparisonV2.C","Doing comparison...");
88cb7938 53
4fa1e629 54
55 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
56 if (!hp) hp=new TH1F("hp","PHI resolution",50,-20.,20.);
57 hp->SetFillColor(4);
58
59 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
60 if (!hl) hl=new TH1F("hl","LAMBDA resolution",50,-20,20);
61 hl->SetFillColor(4);
62
63 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
64 if (!hpt) hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
65 hpt->SetFillColor(2);
66
67 TH1F *hmpt=(TH1F*)gROOT->FindObject("hmpt");
68 if (!hmpt)
49d13e89 69 hmpt=new TH1F("hmpt","Transverse impact parameter",30,-777,777);
4fa1e629 70 hmpt->SetFillColor(6);
71
72 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
49d13e89 73 if (!hz) hz=new TH1F("hz","Longitudinal impact parameter",30,-777,777);
4fa1e629 74
75
76
77 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
78 if (!hgood) hgood=new TH1F("hgood","Good tracks",30,0.2,6.1);
79
80 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
81 if (!hfound) hfound=new TH1F("hfound","Found tracks",30,0.2,6.1);
82
83 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
84 if (!hfake) hfake=new TH1F("hfake","Fake tracks",30,0.2,6.1);
85
86 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
87 if (!hg) hg=new TH1F("hg","Efficiency for good tracks",30,0.2,6.1);
88 hg->SetLineColor(4); hg->SetLineWidth(2);
89
90 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
91 if (!hf) hf=new TH1F("hf","Efficiency for fake tracks",30,0.2,6.1);
92 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
93
94 TH1F *he=(TH1F*)gROOT->FindObject("he");
95 if (!he)
4514157e 96 he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,200.);
4fa1e629 97
98 TH2F *hep=(TH2F*)gROOT->FindObject("hep");
99 if (!hep) hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,400.);
100 hep->SetMarkerStyle(8);
101 hep->SetMarkerSize(0.4);
102
103
104 Char_t fname[100];
105 sprintf(fname,"%s/GoodTracksITS.root",dir);
106
107 TFile *refFile=TFile::Open(fname,"old");
108 if (!refFile || !refFile->IsOpen()) {
109 ::Info("AliITSComparisonV2.C","Marking good tracks (will take a while)...");
110 if (GoodTracksITS(dir)) {
111 ::Error("AliITSComparisonV2.C","Can't generate the reference file !");
112 return 1;
113 }
c630aafd 114 }
4fa1e629 115 refFile=TFile::Open(fname,"old");
116 if (!refFile || !refFile->IsOpen()) {
117 ::Error("AliITSComparisonV2.C","Can't open the reference file !");
118 return 1;
119 }
120
121 TTree *itsTree=(TTree*)refFile->Get("itsTree");
122 if (!itsTree) {
123 ::Error("AliITSComparisonV2.C","Can't get the reference tree !");
124 return 2;
c630aafd 125 }
4fa1e629 126 TBranch *branch=itsTree->GetBranch("ITS");
127 if (!branch) {
128 ::Error("AliITSComparisonV2.C","Can't get the ITS branch !");
129 return 3;
03248e6d 130 }
4fa1e629 131 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
132 branch->SetAddress(&refs);
133
03248e6d 134
4fa1e629 135 sprintf(fname,"%s/AliESDs.root",dir);
136 TFile *ef=TFile::Open(fname);
5102bab6 137 if ((!ef)||(!ef->IsOpen())) {
4fa1e629 138 sprintf(fname,"%s/AliESDits.root",dir);
139 ef=TFile::Open(fname);
140 if ((!ef)||(!ef->IsOpen())) {
141 ::Error("AliITSComparisonV2.C","Can't open AliESDits.root !");
142 return 4;
143 }
5102bab6 144 }
4514157e 145 AliESDEvent* event = new AliESDEvent();
8b462fd8 146 TTree* esdTree = (TTree*) ef->Get("esdTree");
147 if (!esdTree) {
148 ::Error("AliITSComparison.C", "no ESD tree found");
149 return 6;
150 }
4514157e 151 event->ReadFromTree(esdTree);
4fa1e629 152
153
154 //******* Loop over events *********
155 Int_t e=0;
8b462fd8 156 while (esdTree->GetEvent(e)) {
4fa1e629 157 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
158
4fa1e629 159 Int_t nentr=event->GetNumberOfTracks();
160 allfound+=nentr;
161
162 if (itsTree->GetEvent(e++)==0) {
163 cerr<<"No reconstructable tracks !\n";
164 continue;
18856a77 165 }
18856a77 166
4fa1e629 167 Int_t ngood=refs->GetEntriesFast();
168 allgood+=ngood;
03248e6d 169
4fa1e629 170 const Int_t MAX=15000;
171 Int_t notf[MAX], nnotf=0;
172 Int_t fake[MAX], nfake=0;
173 Int_t mult[MAX], numb[MAX], nmult=0;
174 Int_t k;
175 for (k=0; k<ngood; k++) {
176 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(k);
177 Int_t lab=ref->Label(), tlab=-1;
178 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
03248e6d 179
4fa1e629 180 if (ptg<ptcutl) continue;
181 if (ptg>ptcuth) continue;
03248e6d 182
4fa1e629 183 allselected++;
f2718ade 184
4fa1e629 185 hgood->Fill(ptg);
03248e6d 186
4fa1e629 187 AliESDtrack *esd=0;
188 Int_t cnt=0;
4fa1e629 189 for (Int_t i=0; i<nentr; i++) {
190 AliESDtrack *t=event->GetTrack(i);
191 UInt_t status=t->GetStatus();
f2718ade 192
4fa1e629 193 if ((status&AliESDtrack::kITSrefit)==0) continue;
194
4fa1e629 195 Int_t lbl=t->GetLabel();
196 if (lab==TMath::Abs(lbl)) {
197 if (cnt==0) {esd=t; tlab=lbl;}
198 cnt++;
199 }
200 }
201 if (cnt==0) {
202 notf[nnotf++]=lab;
203 continue;
204 } else if (cnt>1){
205 mult[nmult]=lab;
206 numb[nmult]=cnt; nmult++;
207 }
208
f2718ade 209 if (lab==tlab) hfound->Fill(ptg);
210 else {
211 fake[nfake++]=lab;
212 hfake->Fill(ptg);
213 }
f2718ade 214
49d13e89 215 Double_t alpha=esd->GetAlpha(),xv,par[5];
216 esd->GetExternalParameters(xv,par);
217 Float_t phi=TMath::ASin(par[2]) + alpha;
4fa1e629 218 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
219 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
220 Float_t lam=TMath::ATan(par[3]);
221 Float_t pt_1=TMath::Abs(par[4]);
03248e6d 222
4fa1e629 223 Float_t phig=TMath::ATan2(ref->Py(),ref->Px());
224 hp->Fill((phi - phig)*1000.);
03248e6d 225
4fa1e629 226 Float_t lamg=TMath::ATan2(ref->Pz(),ptg);
227 hl->Fill((lam - lamg)*1000.);
03248e6d 228
c84a5e9e 229 Float_t d,z; esd->GetImpactParameters(d,z);
230 hmpt->Fill(10000*d);
49d13e89 231 hz->Fill(10000*z);
03248e6d 232
4fa1e629 233 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
03248e6d 234
4fa1e629 235 Float_t mom=1./(pt_1*TMath::Cos(lam));
c84a5e9e 236 Float_t dedx=esd->GetITSsignal();
4fa1e629 237 hep->Fill(mom,dedx,1.);
f2718ade 238
4fa1e629 239 Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG !
f2718ade 240
4fa1e629 241 if (TMath::Abs(pdg)==211) //pions
242 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
03248e6d 243
4fa1e629 244 }
245
246 cout<<"\nList of Not found tracks :\n";
247 for (k=0; k<nnotf; k++){
248 cout<<notf[k]<<"\t";
249 if ((k%9)==8) cout<<"\n";
250 }
251 cout<<"\n\nList of fake tracks :\n";
252 for (k=0; k<nfake; k++){
253 cout<<fake[k]<<"\t";
254 if ((k%9)==8) cout<<"\n";
255 }
256 cout<<"\n\nList of multiple found tracks :\n";
257 for (k=0; k<nmult; k++) {
258 cout<<"id. "<<mult[k]
259 <<" found - "<<numb[k]<<"times\n";
260 }
261 cout<<endl;
262
263 cout<<"Number of found tracks : "<<nentr<<endl;
264 cout<<"Number of \"good\" tracks : "<<ngood<<endl;
f2718ade 265
4fa1e629 266 refs->Clear();
4fa1e629 267 } //***** End of the loop over events
268
8b462fd8 269 delete event;
4514157e 270 delete esdTree;
4fa1e629 271 ef->Close();
272
273 delete itsTree;
274 refFile->Close();
275
276 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
277 if (ng!=0) cout<<"\n\nIntegral efficiency is about "<<nf/ng*100.<<" %\n";
278 cout<<"Total number selected of \"good\" tracks ="<<allselected<<endl<<endl;
279 cout<<"Total number of found tracks ="<<allfound<<endl;
280 cout<<"Total number of \"good\" tracks ="<<allgood<<endl;
281 cout<<endl;
03248e6d 282
283 gStyle->SetOptStat(111110);
284 gStyle->SetOptFit(1);
285
286 TCanvas *c1=new TCanvas("c1","",0,0,700,850);
287
2d343a94 288 Int_t minc=33;
289
03248e6d 290 TPad *p1=new TPad("p1","",0,0.3,.5,.6); p1->Draw();
291 p1->cd(); p1->SetFillColor(42); p1->SetFrameFillColor(10);
2d343a94 292 hp->SetFillColor(4); hp->SetXTitle("(mrad)");
293 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus"); c1->cd();
03248e6d 294
295 TPad *p2=new TPad("p2","",0.5,.3,1,.6); p2->Draw();
296 p2->cd(); p2->SetFillColor(42); p2->SetFrameFillColor(10);
2d343a94 297 hl->SetXTitle("(mrad)");
298 if (hl->GetEntries()<minc) hl->Draw(); else hl->Fit("gaus"); c1->cd();
03248e6d 299
300 TPad *p3=new TPad("p3","",0,0,0.5,0.3); p3->Draw();
301 p3->cd(); p3->SetFillColor(42); p3->SetFrameFillColor(10);
2d343a94 302 hpt->SetXTitle("(%)");
303 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus"); c1->cd();
03248e6d 304
305 TPad *p4=new TPad("p4","",0.5,0,1,0.3); p4->Draw();
306 p4->cd(); p4->SetFillColor(42); p4->SetFrameFillColor(10);
2d343a94 307 hmpt->SetXTitle("(micron)");
308 if (hmpt->GetEntries()<minc) hmpt->Draw(); else hmpt->Fit("gaus");
309 hz->Draw("same"); c1->cd();
03248e6d 310
311
312 TPad *p5=new TPad("p5","",0,0.6,1,1); p5->Draw(); p5->cd();
313 p5->SetFillColor(41); p5->SetFrameFillColor(10);
314 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
315 hg->Divide(hfound,hgood,1,1.,"b");
316 hf->Divide(hfake,hgood,1,1.,"b");
317 hg->SetMaximum(1.4);
318 hg->SetYTitle("Tracking efficiency");
319 hg->SetXTitle("Pt (GeV/c)");
320 hg->Draw();
321
4fa1e629 322 TLine *line1 = new TLine(0.2,1.0,6.1,1.0); line1->SetLineStyle(4);
03248e6d 323 line1->Draw("same");
4fa1e629 324 TLine *line2 = new TLine(0.2,0.9,6.1,0.9); line2->SetLineStyle(4);
03248e6d 325 line2->Draw("same");
326
327 hf->SetFillColor(1);
328 hf->SetFillStyle(3013);
329 hf->SetLineColor(2);
330 hf->SetLineWidth(2);
331 hf->Draw("histsame");
332 TText *text = new TText(0.461176,0.248448,"Fake tracks");
333 text->SetTextSize(0.05);
334 text->Draw();
335 text = new TText(0.453919,1.11408,"Good tracks");
336 text->SetTextSize(0.05);
337 text->Draw();
338
c630aafd 339 TCanvas *c2=new TCanvas("c2","",320,32,530,590);
340 TPad *p6=new TPad("p6","",0.,0.,1.,.5); p6->Draw();
341 p6->cd(); p6->SetFillColor(42); p6->SetFrameFillColor(10);
342 he->SetFillColor(2); he->SetFillStyle(3005);
343 he->SetXTitle("Arbitrary Units");
2d343a94 344 if (he->GetEntries()<minc) he->Draw(); else he->Fit("gaus"); c2->cd();
c630aafd 345
346 TPad *p7=new TPad("p7","",0.,0.5,1.,1.); p7->Draw();
347 p7->cd(); p7->SetFillColor(42); p7->SetFrameFillColor(10);
348 hep->SetXTitle("p (Gev/c)"); hep->SetYTitle("dE/dX (Arb. Units)");
349 hep->Draw(); c1->cd();
2d343a94 350
351 TFile fc("AliITSComparisonV2.root","RECREATE");
352 c1->Write();
353 c2->Write();
354 fc.Close();
355
4fa1e629 356 gBenchmark->Stop("AliITSComparisonV2");
357 gBenchmark->Show("AliITSComparisonV2");
358
03248e6d 359 return 0;
360}
361
4fa1e629 362
363
364Int_t GoodTracksITS(const Char_t *dir) {
365 if (gAlice) {
366 delete gAlice->GetRunLoader();
367 delete gAlice;//if everything was OK here it is already NULL
368 gAlice = 0x0;
c630aafd 369 }
88cb7938 370
4fa1e629 371 Char_t fname[100];
372 sprintf(fname,"%s/galice.root",dir);
373
374 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
375 if (!rl) {
376 ::Error("GoodTracksITS","Can't start session !");
377 return 1;
c630aafd 378 }
4fa1e629 379
88cb7938 380 rl->LoadgAlice();
381 rl->LoadHeader();
4fa1e629 382 rl->LoadKinematics();
03248e6d 383
4fa1e629 384 AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
385 if (itsl == 0x0) {
386 ::Error("GoodTracksITS","Can not find the ITSLoader");
387 delete rl;
388 return 4;
389 }
c630aafd 390 itsl->LoadRecPoints();
4fa1e629 391
392
393 Int_t nev=rl->GetNumberOfEvents();
394 ::Info("GoodTracksITS","Number of events : %d\n",nev);
395
396 sprintf(fname,"%s/GoodTracksTPC.root",dir);
397 TFile *tpcFile=TFile::Open(fname);
398 if ((!tpcFile)||(!tpcFile->IsOpen())) {
399 ::Error("GoodTracksITS","Can't open the GoodTracksTPC.root !");
400 delete rl;
401 return 5;
03248e6d 402 }
4fa1e629 403 TClonesArray dum("AliTrackReference",1000), *tpcRefs=&dum;
404 TTree *tpcTree=(TTree*)tpcFile->Get("tpcTree");
405 if (!tpcTree) {
406 ::Error("GoodTracksITS","Can't get the TPC reference tree !");
407 delete rl;
408 return 6;
03248e6d 409 }
4fa1e629 410 TBranch *tpcBranch=tpcTree->GetBranch("TPC");
411 if (!tpcBranch) {
412 ::Error("GoodTracksITS","Can't get the TPC reference branch !");
413 delete rl;
414 return 7;
415 }
416 tpcBranch->SetAddress(&tpcRefs);
417
418 sprintf(fname,"%s/GoodTracksITS.root",dir);
419 TFile *itsFile=TFile::Open(fname,"recreate");
8c277781 420 TClonesArray dummy2("AliTrackReference",1000), *itsRefs=&dummy2;
4fa1e629 421 TTree itsTree("itsTree","Tree with info about the reconstructable ITS tracks");
422 itsTree.Branch("ITS",&itsRefs);
423
424 //******** Loop over generated events
425 for (Int_t e=0; e<nev; e++) {
426 Int_t k;
427
428 rl->GetEvent(e); itsFile->cd();
429
430 Int_t np = rl->GetHeader()->GetNtrack();
431 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
432
433 //******** Fill the "good" masks
434 Int_t *good=new Int_t[np]; for (k=0; k<np; k++) good[k]=0;
435
436 TTree *cTree=itsl->TreeR();
437 if (!cTree) {
438 ::Error("GoodTracksITS","Can't get the cluster tree !");
439 delete rl;
440 return 8;
03248e6d 441 }
00a7cc50 442 TBranch *branch=cTree->GetBranch("ITSRecPoints");
4fa1e629 443 if (!branch) {
444 ::Error("GoodTracksITS","Can't get the clusters branch !");
445 delete rl;
446 return 9;
447 }
00a7cc50 448 TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
4fa1e629 449 branch->SetAddress(&clusters);
450
451 Int_t entr=(Int_t)cTree->GetEntries();
452 for (k=0; k<entr; k++) {
453 cTree->GetEvent(k);
454 Int_t ncl=clusters->GetEntriesFast(); if (ncl==0) continue;
4fa1e629 455 while (ncl--) {
00a7cc50 456 AliITSRecPoint *pnt=(AliITSRecPoint*)clusters->UncheckedAt(ncl);
7e9ae194 457
458 Int_t lay=pnt->GetLayer();
459 if (lay<0 || lay>5) {
460 ::Error("GoodTracksITS","Wrong layer !");
461 delete rl;
462 return 10;
463 }
464
4fa1e629 465 Int_t l0=pnt->GetLabel(0);
466 if (l0>=np) {
467// cerr<<"Wrong label: "<<l0<<endl;
468 continue;
469 }
470 Int_t l1=pnt->GetLabel(1);
471 if (l1>=np) {
472// cerr<<"Wrong label: "<<l1<<endl;
473 continue;
474 }
475 Int_t l2=pnt->GetLabel(2);
476 if (l2>=np) {
477// cerr<<"Wrong label: "<<l2<<endl;
478 continue;
479 }
7e9ae194 480 Int_t mask=1<<lay;
4fa1e629 481 if (l0>=0) good[l0]|=mask;
482 if (l1>=0) good[l1]|=mask;
483 if (l2>=0) good[l2]|=mask;
484 }
485 clusters->Clear();
03248e6d 486 }
88cb7938 487
03248e6d 488
4fa1e629 489 //****** select tracks which are "good" enough
490 AliStack* stack = rl->Stack();
491
492 tpcTree->GetEvent(e);
493 Int_t nk=tpcRefs->GetEntriesFast();
494 Int_t nt=0;
495 for (k=0; k<nk; k++) {
496 AliTrackReference *tpcRef=(AliTrackReference *)tpcRefs->UncheckedAt(k);
497 Int_t lab=tpcRef->Label();
498 if (good[lab] != 0x3F) continue;
499 TParticle *p = (TParticle*)stack->Particle(lab);
500 if (p == 0x0) {
501 cerr<<"Can not get particle "<<lab<<endl;
502 continue;
503 }
504
8c277781 505 AliTrackReference *ref=new((*itsRefs)[nt]) AliTrackReference(*tpcRef);
506 ref->SetMomentum(p->Px(),p->Py(),p->Pz());
507 ref->SetPosition(p->Vx(),p->Vy(),p->Vz());
4fa1e629 508 nt++;
509 }
510 tpcRefs->Clear();
511
512 itsTree.Fill();
513 itsRefs->Clear();
03248e6d 514
4fa1e629 515 delete[] good;
03248e6d 516
4fa1e629 517 } //*** end of the loop over generated events
518
519 itsTree.Write();
520 itsFile->Close();
521
522 delete tpcTree;
523 tpcFile->Close();
524
525 delete rl;
526 return 0;
03248e6d 527}
528
529