]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSComparisonV2.C
Macro for SDD dE/dx calibration (from Leonardo and Riccardo)
[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"
56042d60 33 #include "AliESDtrack.h"
4fa1e629 34
00a7cc50 35 #include "AliITSRecPoint.h"
4fa1e629 36 #include "AliITSLoader.h"
03248e6d 37#endif
38
4fa1e629 39Int_t GoodTracksITS(const Char_t *dir=".");
5102bab6 40
c630aafd 41extern AliRun *gAlice;
4fa1e629 42extern TBenchmark *gBenchmark;
43extern TROOT *gROOT;
c630aafd 44
4fa1e629 45static Int_t allgood=0;
46static Int_t allselected=0;
47static Int_t allfound=0;
48
49Int_t AliITSComparisonV2
7e9ae194 50(Float_t ptcutl=0.2, Float_t ptcuth=10., const Char_t *dir=".") {
4fa1e629 51 gBenchmark->Start("AliITSComparisonV2");
52
53 ::Info("AliITSComparisonV2.C","Doing comparison...");
88cb7938 54
4fa1e629 55
56 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
57 if (!hp) hp=new TH1F("hp","PHI resolution",50,-20.,20.);
58 hp->SetFillColor(4);
59
60 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
61 if (!hl) hl=new TH1F("hl","LAMBDA resolution",50,-20,20);
62 hl->SetFillColor(4);
63
64 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
65 if (!hpt) hpt=new TH1F("hpt","Relative Pt resolution",30,-10.,10.);
66 hpt->SetFillColor(2);
67
68 TH1F *hmpt=(TH1F*)gROOT->FindObject("hmpt");
69 if (!hmpt)
49d13e89 70 hmpt=new TH1F("hmpt","Transverse impact parameter",30,-777,777);
4fa1e629 71 hmpt->SetFillColor(6);
72
73 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
49d13e89 74 if (!hz) hz=new TH1F("hz","Longitudinal impact parameter",30,-777,777);
4fa1e629 75
76
77
78 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
79 if (!hgood) hgood=new TH1F("hgood","Good tracks",30,0.2,6.1);
80
81 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
82 if (!hfound) hfound=new TH1F("hfound","Found tracks",30,0.2,6.1);
83
84 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
85 if (!hfake) hfake=new TH1F("hfake","Fake tracks",30,0.2,6.1);
86
87 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
88 if (!hg) hg=new TH1F("hg","Efficiency for good tracks",30,0.2,6.1);
89 hg->SetLineColor(4); hg->SetLineWidth(2);
90
91 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
92 if (!hf) hf=new TH1F("hf","Efficiency for fake tracks",30,0.2,6.1);
93 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
94
95 TH1F *he=(TH1F*)gROOT->FindObject("he");
96 if (!he)
4514157e 97 he =new TH1F("he","dE/dX for pions with 0.4<p<0.5 GeV/c",50,0.,200.);
4fa1e629 98
99 TH2F *hep=(TH2F*)gROOT->FindObject("hep");
100 if (!hep) hep=new TH2F("hep","dE/dX vs momentum",50,0.,2.,50,0.,400.);
101 hep->SetMarkerStyle(8);
102 hep->SetMarkerSize(0.4);
103
104
105 Char_t fname[100];
106 sprintf(fname,"%s/GoodTracksITS.root",dir);
107
108 TFile *refFile=TFile::Open(fname,"old");
109 if (!refFile || !refFile->IsOpen()) {
110 ::Info("AliITSComparisonV2.C","Marking good tracks (will take a while)...");
111 if (GoodTracksITS(dir)) {
112 ::Error("AliITSComparisonV2.C","Can't generate the reference file !");
113 return 1;
114 }
c630aafd 115 }
4fa1e629 116 refFile=TFile::Open(fname,"old");
117 if (!refFile || !refFile->IsOpen()) {
118 ::Error("AliITSComparisonV2.C","Can't open the reference file !");
119 return 1;
120 }
121
122 TTree *itsTree=(TTree*)refFile->Get("itsTree");
123 if (!itsTree) {
124 ::Error("AliITSComparisonV2.C","Can't get the reference tree !");
125 return 2;
c630aafd 126 }
4fa1e629 127 TBranch *branch=itsTree->GetBranch("ITS");
128 if (!branch) {
129 ::Error("AliITSComparisonV2.C","Can't get the ITS branch !");
130 return 3;
03248e6d 131 }
4fa1e629 132 TClonesArray dummy("AliTrackReference",1000), *refs=&dummy;
133 branch->SetAddress(&refs);
134
03248e6d 135
4fa1e629 136 sprintf(fname,"%s/AliESDs.root",dir);
137 TFile *ef=TFile::Open(fname);
5102bab6 138 if ((!ef)||(!ef->IsOpen())) {
4fa1e629 139 sprintf(fname,"%s/AliESDits.root",dir);
140 ef=TFile::Open(fname);
141 if ((!ef)||(!ef->IsOpen())) {
142 ::Error("AliITSComparisonV2.C","Can't open AliESDits.root !");
143 return 4;
144 }
5102bab6 145 }
4514157e 146 AliESDEvent* event = new AliESDEvent();
8b462fd8 147 TTree* esdTree = (TTree*) ef->Get("esdTree");
148 if (!esdTree) {
149 ::Error("AliITSComparison.C", "no ESD tree found");
150 return 6;
151 }
4514157e 152 event->ReadFromTree(esdTree);
4fa1e629 153
154
155 //******* Loop over events *********
156 Int_t e=0;
8b462fd8 157 while (esdTree->GetEvent(e)) {
4fa1e629 158 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
159
4fa1e629 160 Int_t nentr=event->GetNumberOfTracks();
161 allfound+=nentr;
162
163 if (itsTree->GetEvent(e++)==0) {
164 cerr<<"No reconstructable tracks !\n";
165 continue;
18856a77 166 }
18856a77 167
4fa1e629 168 Int_t ngood=refs->GetEntriesFast();
169 allgood+=ngood;
03248e6d 170
4fa1e629 171 const Int_t MAX=15000;
172 Int_t notf[MAX], nnotf=0;
173 Int_t fake[MAX], nfake=0;
174 Int_t mult[MAX], numb[MAX], nmult=0;
175 Int_t k;
176 for (k=0; k<ngood; k++) {
177 AliTrackReference *ref=(AliTrackReference*)refs->UncheckedAt(k);
178 Int_t lab=ref->Label(), tlab=-1;
179 Float_t ptg=TMath::Sqrt(ref->Px()*ref->Px() + ref->Py()*ref->Py());
03248e6d 180
4fa1e629 181 if (ptg<ptcutl) continue;
182 if (ptg>ptcuth) continue;
03248e6d 183
4fa1e629 184 allselected++;
f2718ade 185
4fa1e629 186 hgood->Fill(ptg);
03248e6d 187
4fa1e629 188 AliESDtrack *esd=0;
189 Int_t cnt=0;
4fa1e629 190 for (Int_t i=0; i<nentr; i++) {
191 AliESDtrack *t=event->GetTrack(i);
192 UInt_t status=t->GetStatus();
f2718ade 193
4fa1e629 194 if ((status&AliESDtrack::kITSrefit)==0) continue;
195
4fa1e629 196 Int_t lbl=t->GetLabel();
197 if (lab==TMath::Abs(lbl)) {
198 if (cnt==0) {esd=t; tlab=lbl;}
199 cnt++;
200 }
201 }
202 if (cnt==0) {
203 notf[nnotf++]=lab;
204 continue;
205 } else if (cnt>1){
206 mult[nmult]=lab;
207 numb[nmult]=cnt; nmult++;
208 }
209
f2718ade 210 if (lab==tlab) hfound->Fill(ptg);
211 else {
212 fake[nfake++]=lab;
213 hfake->Fill(ptg);
214 }
f2718ade 215
49d13e89 216 Double_t alpha=esd->GetAlpha(),xv,par[5];
217 esd->GetExternalParameters(xv,par);
218 Float_t phi=TMath::ASin(par[2]) + alpha;
4fa1e629 219 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
220 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
221 Float_t lam=TMath::ATan(par[3]);
222 Float_t pt_1=TMath::Abs(par[4]);
03248e6d 223
4fa1e629 224 Float_t phig=TMath::ATan2(ref->Py(),ref->Px());
225 hp->Fill((phi - phig)*1000.);
03248e6d 226
4fa1e629 227 Float_t lamg=TMath::ATan2(ref->Pz(),ptg);
228 hl->Fill((lam - lamg)*1000.);
03248e6d 229
c84a5e9e 230 Float_t d,z; esd->GetImpactParameters(d,z);
231 hmpt->Fill(10000*d);
49d13e89 232 hz->Fill(10000*z);
03248e6d 233
4fa1e629 234 hpt->Fill((pt_1 - 1/ptg)/(1/ptg)*100.);
03248e6d 235
4fa1e629 236 Float_t mom=1./(pt_1*TMath::Cos(lam));
c84a5e9e 237 Float_t dedx=esd->GetITSsignal();
4fa1e629 238 hep->Fill(mom,dedx,1.);
f2718ade 239
4fa1e629 240 Int_t pdg=(Int_t)ref->GetLength(); //this is particle's PDG !
f2718ade 241
4fa1e629 242 if (TMath::Abs(pdg)==211) //pions
243 if (mom>0.4 && mom<0.5) he->Fill(dedx,1.);
03248e6d 244
4fa1e629 245 }
246
247 cout<<"\nList of Not found tracks :\n";
248 for (k=0; k<nnotf; k++){
249 cout<<notf[k]<<"\t";
250 if ((k%9)==8) cout<<"\n";
251 }
252 cout<<"\n\nList of fake tracks :\n";
253 for (k=0; k<nfake; k++){
254 cout<<fake[k]<<"\t";
255 if ((k%9)==8) cout<<"\n";
256 }
257 cout<<"\n\nList of multiple found tracks :\n";
258 for (k=0; k<nmult; k++) {
259 cout<<"id. "<<mult[k]
260 <<" found - "<<numb[k]<<"times\n";
261 }
262 cout<<endl;
263
264 cout<<"Number of found tracks : "<<nentr<<endl;
265 cout<<"Number of \"good\" tracks : "<<ngood<<endl;
f2718ade 266
4fa1e629 267 refs->Clear();
4fa1e629 268 } //***** End of the loop over events
269
8b462fd8 270 delete event;
4514157e 271 delete esdTree;
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) {
33c3c91a 367 delete AliRunLoader::Instance();
4fa1e629 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
4fa1e629 385 AliITSLoader* itsl = (AliITSLoader*)rl->GetLoader("ITSLoader");
386 if (itsl == 0x0) {
387 ::Error("GoodTracksITS","Can not find the ITSLoader");
388 delete rl;
389 return 4;
390 }
c630aafd 391 itsl->LoadRecPoints();
4fa1e629 392
393
394 Int_t nev=rl->GetNumberOfEvents();
395 ::Info("GoodTracksITS","Number of events : %d\n",nev);
396
397 sprintf(fname,"%s/GoodTracksTPC.root",dir);
398 TFile *tpcFile=TFile::Open(fname);
399 if ((!tpcFile)||(!tpcFile->IsOpen())) {
400 ::Error("GoodTracksITS","Can't open the GoodTracksTPC.root !");
401 delete rl;
402 return 5;
03248e6d 403 }
4fa1e629 404 TClonesArray dum("AliTrackReference",1000), *tpcRefs=&dum;
405 TTree *tpcTree=(TTree*)tpcFile->Get("tpcTree");
406 if (!tpcTree) {
407 ::Error("GoodTracksITS","Can't get the TPC reference tree !");
408 delete rl;
409 return 6;
03248e6d 410 }
4fa1e629 411 TBranch *tpcBranch=tpcTree->GetBranch("TPC");
412 if (!tpcBranch) {
413 ::Error("GoodTracksITS","Can't get the TPC reference branch !");
414 delete rl;
415 return 7;
416 }
417 tpcBranch->SetAddress(&tpcRefs);
418
419 sprintf(fname,"%s/GoodTracksITS.root",dir);
420 TFile *itsFile=TFile::Open(fname,"recreate");
8c277781 421 TClonesArray dummy2("AliTrackReference",1000), *itsRefs=&dummy2;
4fa1e629 422 TTree itsTree("itsTree","Tree with info about the reconstructable ITS tracks");
423 itsTree.Branch("ITS",&itsRefs);
424
425 //******** Loop over generated events
426 for (Int_t e=0; e<nev; e++) {
427 Int_t k;
428
429 rl->GetEvent(e); itsFile->cd();
430
431 Int_t np = rl->GetHeader()->GetNtrack();
432 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
433
434 //******** Fill the "good" masks
435 Int_t *good=new Int_t[np]; for (k=0; k<np; k++) good[k]=0;
436
437 TTree *cTree=itsl->TreeR();
438 if (!cTree) {
439 ::Error("GoodTracksITS","Can't get the cluster tree !");
440 delete rl;
441 return 8;
03248e6d 442 }
00a7cc50 443 TBranch *branch=cTree->GetBranch("ITSRecPoints");
4fa1e629 444 if (!branch) {
445 ::Error("GoodTracksITS","Can't get the clusters branch !");
446 delete rl;
447 return 9;
448 }
00a7cc50 449 TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
4fa1e629 450 branch->SetAddress(&clusters);
451
452 Int_t entr=(Int_t)cTree->GetEntries();
453 for (k=0; k<entr; k++) {
454 cTree->GetEvent(k);
455 Int_t ncl=clusters->GetEntriesFast(); if (ncl==0) continue;
4fa1e629 456 while (ncl--) {
00a7cc50 457 AliITSRecPoint *pnt=(AliITSRecPoint*)clusters->UncheckedAt(ncl);
7e9ae194 458
459 Int_t lay=pnt->GetLayer();
460 if (lay<0 || lay>5) {
461 ::Error("GoodTracksITS","Wrong layer !");
462 delete rl;
463 return 10;
464 }
465
4fa1e629 466 Int_t l0=pnt->GetLabel(0);
467 if (l0>=np) {
468// cerr<<"Wrong label: "<<l0<<endl;
469 continue;
470 }
471 Int_t l1=pnt->GetLabel(1);
472 if (l1>=np) {
473// cerr<<"Wrong label: "<<l1<<endl;
474 continue;
475 }
476 Int_t l2=pnt->GetLabel(2);
477 if (l2>=np) {
478// cerr<<"Wrong label: "<<l2<<endl;
479 continue;
480 }
7e9ae194 481 Int_t mask=1<<lay;
4fa1e629 482 if (l0>=0) good[l0]|=mask;
483 if (l1>=0) good[l1]|=mask;
484 if (l2>=0) good[l2]|=mask;
485 }
486 clusters->Clear();
03248e6d 487 }
88cb7938 488
03248e6d 489
4fa1e629 490 //****** select tracks which are "good" enough
491 AliStack* stack = rl->Stack();
492
493 tpcTree->GetEvent(e);
494 Int_t nk=tpcRefs->GetEntriesFast();
495 Int_t nt=0;
496 for (k=0; k<nk; k++) {
497 AliTrackReference *tpcRef=(AliTrackReference *)tpcRefs->UncheckedAt(k);
498 Int_t lab=tpcRef->Label();
499 if (good[lab] != 0x3F) continue;
500 TParticle *p = (TParticle*)stack->Particle(lab);
501 if (p == 0x0) {
502 cerr<<"Can not get particle "<<lab<<endl;
503 continue;
504 }
505
8c277781 506 AliTrackReference *ref=new((*itsRefs)[nt]) AliTrackReference(*tpcRef);
507 ref->SetMomentum(p->Px(),p->Py(),p->Pz());
508 ref->SetPosition(p->Vx(),p->Vy(),p->Vz());
4fa1e629 509 nt++;
510 }
511 tpcRefs->Clear();
512
513 itsTree.Fill();
514 itsRefs->Clear();
03248e6d 515
4fa1e629 516 delete[] good;
03248e6d 517
4fa1e629 518 } //*** end of the loop over generated events
519
520 itsTree.Write();
521 itsFile->Close();
522
523 delete tpcTree;
524 tpcFile->Close();
525
526 delete rl;
527 return 0;
03248e6d 528}
529
530