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