1 /****************************************************************************
2 * Very important, delicate and rather obscure macro. *
4 * Creates list of "findable" V0s, *
5 * calculates efficiency, resolutions etc. *
7 * To get the list of the "findable" V0s, you should first get the list *
8 * of "findable" tracks, which can be done by running *
9 * TPC/AliTPCComparison.C and ITS/AliITSComparisonV2.C macros. *
11 * Origin: I.Belikov, IReS, Strasbourg, Jouri.Belikov@cern.ch *
12 ****************************************************************************/
14 #if !defined(__CINT__) || defined(__MAKECINT__)
17 #include <Riostream.h>
20 #include <TParticle.h>
25 #include <TBenchmark.h>
31 #include "AliHeader.h"
32 #include "AliTrackReference.h"
33 #include "AliRunLoader.h"
35 #include "AliESDEvent.h"
39 Int_t GoodV0s(const Char_t *dir=".");
41 extern AliRun *gAlice;
42 extern TBenchmark *gBenchmark;
45 static Int_t allgood=0;
46 static Int_t allfound=0;
48 Int_t AliV0Comparison(Int_t code=310, const Char_t *dir=".") {
49 //Lambda=3122, LambdaBar=-3122
50 gBenchmark->Start("AliV0Comparison");
52 ::Info("AliV0Comparison.C","Doing comparison...");
55 const Double_t V0window=0.05;
56 Double_t ptncut=0.13, ptpcut=0.13, kinecut=0.03;
57 Double_t V0mass=0.497672, V0width=0.020;
62 V0mass=1.115683; V0width=0.015; ptpcut=0.50; kinecut=0.002;
65 V0mass=1.115683; V0width=0.015; ptncut=0.50; kinecut=0.002;
67 default: cerr<<"Invalid PDG code !\n"; return 1;
70 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
71 if (!hp) hp=new TH1F("hp","PHI Resolution",30,-30.,30.);
72 hp->SetXTitle("(mrad)"); hp->SetFillColor(2);
74 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
75 if (!hl) hl=new TH1F("hl","LAMBDA Resolution",30,-30,30);
76 hl->SetXTitle("(mrad)"); hl->SetFillColor(1); hl->SetFillStyle(3013);
78 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
79 if (!hpt) hpt=new TH1F("hpt","Relative Pt Resolution",30,-10.,10.);
80 hpt->SetXTitle("(%)"); hpt->SetFillColor(2);
82 TH1F *hx=(TH1F*)gROOT->FindObject("hx");
83 if (!hx) hx=new TH1F("hx","Position Resolution (X)",30,-3.,3.);
84 hx->SetXTitle("(mm)"); hx->SetFillColor(6);
86 TH1F *hy=(TH1F*)gROOT->FindObject("hy");
87 if (!hy) hy=new TH1F("hy","Position Resolution (Y)",30,-3.,3.);
88 hy->SetXTitle("(mm)"); hy->SetFillColor(1); hy->SetFillStyle(3013);
90 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
91 if (!hz) hz=new TH1F("hz","Position Resolution (Z)",30,-3.,3.);
92 hz->SetXTitle("(mm)"); hz->SetFillColor(6);
95 Double_t pmin=0.2, pmax=4.2; Int_t nchan=20;
96 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
97 if (!hgood) hgood=new TH1F("hgood","Good Vertices",nchan,pmin,pmax);
99 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
100 if (!hfound) hfound=new TH1F("hfound","Found Vertices",nchan,pmin,pmax);
102 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
103 if (!hfake) hfake=new TH1F("hfake","Fake Vertices",nchan,pmin,pmax);
105 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
106 if (!hg) hg=new TH1F("hg","Efficiency for Good Vertices",nchan,pmin,pmax);
107 hg->SetLineColor(4); hg->SetLineWidth(2);
109 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
110 if (!hf) hf=new TH1F("hf","Probability of Fake Vertices",nchan,pmin,pmax);
111 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
114 Double_t mmin=V0mass-V0window, mmax=V0mass+V0window;
115 TH1F *v0s=(TH1F*)gROOT->FindObject("v0s");
116 if (!v0s) v0s=new TH1F("v0s","V0s Effective Mass",40, mmin, mmax);
117 v0s->SetXTitle("(GeV)"); v0s->SetLineColor(4); v0s->SetLineWidth(4);
119 TH1F *v0sf=(TH1F*)gROOT->FindObject("v0sf");
120 if (!v0sf) v0sf=new TH1F("v0sf","Fake V0s Effective Mass",40, mmin, mmax);
121 v0sf->SetXTitle("(GeV)"); v0sf->SetFillColor(6);
125 sprintf(fname,"%s/GoodV0s.root",dir);
127 TFile *refFile=TFile::Open(fname,"old");
128 if (!refFile || !refFile->IsOpen()) {
129 ::Info("AliV0Comparison.C","Marking good V0s (will take a while)...");
131 ::Error("AliV0Comparison.C","Can't generate the reference file !");
135 refFile=TFile::Open(fname,"old");
136 if (!refFile || !refFile->IsOpen()) {
137 ::Error("AliV0Comparison.C","Can't open the reference file !");
141 TTree *v0Tree=(TTree*)refFile->Get("v0Tree");
143 ::Error("AliV0Comparison.C","Can't get the reference tree !");
146 TBranch *pbranch=v0Tree->GetBranch("positive");
148 ::Error("AliV0Comparison.C","Can't get the positive daughter branch !");
151 TClonesArray dummy("AliTrackReference",1000), *prefs=&dummy;
152 pbranch->SetAddress(&prefs);
154 TBranch *nbranch=v0Tree->GetBranch("negative");
156 ::Error("AliV0Comparison.C","Can't get the negative daughter branch !");
159 TClonesArray dumm("AliTrackReference",1000), *nrefs=&dumm;
160 nbranch->SetAddress(&nrefs);
163 sprintf(fname,"%s/AliESDs.root",dir);
164 TFile *ef=TFile::Open(fname);
165 if ((!ef)||(!ef->IsOpen())) {
166 sprintf(fname,"%s/AliESDv0.root",dir);
167 ef=TFile::Open(fname);
168 if ((!ef)||(!ef->IsOpen())) {
169 ::Error("AliV0Comparison.C","Can't open AliESDv0.root !");
173 AliESDEvent* event = new AliESDEvent();
174 TTree* esdTree = (TTree*) ef->Get("esdTree");
176 ::Error("AliV0Comparison.C", "no ESD tree found");
179 event->ReadFromTree(esdTree);
182 //******* Loop over events *********
184 while (esdTree->GetEvent(e)) {
185 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
187 Int_t nentr=event->GetNumberOfV0s();
190 if (v0Tree->GetEvent(e++)==0) {
191 cerr<<"No reconstructable V0s !\n";
195 Int_t ngood=prefs->GetEntriesFast(),ng=0;
197 Double_t pxg=0.,pyg=0.,pzg=0.,ptg=0.;
198 Int_t nlab=-1, plab=-1;
200 for (i=0; i<nentr; i++) {
201 AliESDv0 *vertex=event->GetV0(i);
203 if (vertex->GetOnFlyStatus()) continue;
205 Int_t nidx=TMath::Abs(vertex->GetNindex());
206 Int_t pidx=TMath::Abs(vertex->GetPindex());
208 AliESDtrack *ntrack=event->GetTrack(nidx);
209 AliESDtrack *ptrack=event->GetTrack(pidx);
211 nlab=TMath::Abs(ntrack->GetLabel());
212 plab=TMath::Abs(ptrack->GetLabel());
214 /** Kinematical cuts **/
215 Double_t pxn,pyn,pzn; vertex->GetNPxPyPz(pxn,pyn,pzn);
216 Double_t ptn=TMath::Sqrt(pxn*pxn + pyn*pyn);
217 if (ptn < ptncut) continue;
218 Double_t pxp,pyp,pzp; vertex->GetPPxPyPz(pxp,pyp,pzp);
219 Double_t ptp=TMath::Sqrt(pxp*pxp + pyp*pyp);
220 if (ptp < ptpcut) continue;
221 Double_t kine=vertex->ChangeMassHypothesis(code);
222 //if (TMath::Abs(kine)>kinecut) continue;
224 Double_t mass=vertex->GetEffMass();
228 AliTrackReference *nref=0, *pref=0;
230 for (j=0; j<ngood; j++) {
231 nref=(AliTrackReference*)nrefs->UncheckedAt(j);
232 pref=(AliTrackReference*)prefs->UncheckedAt(j);
233 if (nref->Label() == nlab)
234 if (pref->Label() == plab) break;
237 if (TMath::Abs(mass-V0mass)>V0width) continue;
239 Double_t px,py,pz; vertex->GetPxPyPz(px,py,pz);
240 Double_t pt=TMath::Sqrt(px*px+py*py);
244 cout<<"Fake vertex: ("<<nlab<<","<<plab<<")\n";
249 pxg=nref->Px()+pref->Px(); pyg=nref->Py()+pref->Py();
250 pzg=nref->Pz()+pref->Pz();
251 ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
252 Double_t phig=TMath::ATan2(pyg,pxg), phi=TMath::ATan2(py,px);
253 Double_t lamg=TMath::ATan2(pzg,ptg), lam=TMath::ATan2(pz,pt);
254 hp->Fill((phi - phig)*1000.);
255 hl->Fill((lam - lamg)*1000.);
256 hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
258 Double_t x,y,z; vertex->GetXYZ(x,y,z);
259 hx->Fill((x - nref->X())*10);
260 hy->Fill((y - nref->Y())*10);
261 hz->Fill((z - nref->Z())*10);
267 for (i=0; i<ngood; i++) {
268 AliTrackReference *nref=(AliTrackReference*)nrefs->UncheckedAt(i);
269 AliTrackReference *pref=(AliTrackReference*)prefs->UncheckedAt(i);
270 Int_t pdg=(Int_t)nref->GetLength();//this is the mother's PDG !
271 if (code!=pdg) continue;
273 pxg=nref->Px()+pref->Px(); pyg=nref->Py()+pref->Py();
274 ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
276 nlab=nref->Label(); plab=pref->Label();
277 if (nlab < 0) continue;
278 cout<<"Vertex ("<<nlab<<','<<plab<<") has not been found !\n";
282 cout<<"Number of found V0s : "<<nentr<<endl;
283 cout<<"Number of \"good\" V0s : "<<ng<<endl;
288 } //**** End of the loop over events
297 Stat_t ng=hgood->GetEntries(), nf=hfound->GetEntries();
298 if (ng!=0) cout<<"Integral efficiency is about "<<nf/ng*100.<<" %\n";
299 cout<<"Total number of found V0s: "<<allfound<<" ("<<nf<<" in the peak)\n";
300 cout<<"Total number of \"good\" V0s: "<<allgood<<endl;
302 gStyle->SetOptStat(111110);
303 gStyle->SetOptFit(1);
305 TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
307 c1=new TCanvas("c1","",0,0,580,610);
314 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
315 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus");
316 hl->Draw("same"); c1->cd();
319 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
320 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus");
324 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
325 if (hx->GetEntries()<minc) hx->Draw(); else hx->Fit("gaus");
326 hy->Draw("same"); c1->cd();
329 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
330 if (hz->GetEntries()<minc) hz->Draw(); else hz->Fit("gaus");
334 TCanvas *c2=(TCanvas*)gROOT->FindObject("c2");
336 c2=new TCanvas("c2","",600,0,580,610);
341 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
342 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
343 hg->Divide(hfound,hgood,1,1.,"b");
344 hf->Divide(hfake,hgood,1,1.,"b");
346 hg->SetYTitle("V0 reconstruction efficiency");
347 hg->SetXTitle("Pt (GeV/c)");
350 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
352 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
356 hf->SetFillStyle(3013);
359 hf->Draw("histsame");
360 TText *text = new TText(0.461176,0.248448,"Fake vertices");
361 text->SetTextSize(0.05);
363 text = new TText(0.453919,1.11408,"Good vertices");
364 text->SetTextSize(0.05);
369 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
370 if (v0s->GetEntries()<minc) v0s->Draw();
371 else v0s->Fit("gaus","","",V0mass-V0width,V0mass+V0width);
373 Double_t max=v0s->GetMaximum();
374 TLine *line3 = new TLine(V0mass-V0width,0.,V0mass-V0width,max);
376 TLine *line4 = new TLine(V0mass+V0width,0.,V0mass+V0width,max);
381 TFile fc("AliV0Comparison.root","RECREATE");
386 gBenchmark->Stop("AliV0Comparison");
387 gBenchmark->Show("AliV0Comparison");
393 Int_t GoodV0s(const Char_t *dir) {
395 delete gAlice->GetRunLoader();
396 delete gAlice;//if everything was OK here it is already NULL
401 sprintf(fname,"%s/galice.root",dir);
403 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
405 ::Error("GoodTracksITS","Can't start session !");
411 rl->LoadKinematics();
414 Int_t nev=rl->GetNumberOfEvents();
415 ::Info("GoodV0s","Number of events : %d\n",nev);
417 sprintf(fname,"%s/GoodTracksITS.root",dir);
418 TFile *itsFile=TFile::Open(fname);
419 if ((!itsFile)||(!itsFile->IsOpen())) {
420 ::Error("GoodV0s","Can't open the GoodTracksITS.root !");
424 TClonesArray dum("AliTrackReference",1000), *itsRefs=&dum;
425 TTree *itsTree=(TTree*)itsFile->Get("itsTree");
427 ::Error("GoodV0s","Can't get the ITS reference tree !");
431 TBranch *itsBranch=itsTree->GetBranch("ITS");
433 ::Error("GoodV0s","Can't get the ITS reference branch !");
437 itsBranch->SetAddress(&itsRefs);
440 sprintf(fname,"%s/GoodV0s.root",dir);
441 TFile *v0File=TFile::Open(fname,"recreate");
442 TClonesArray dummy("AliTrackReference",1000), *nrefs=&dummy;
443 TClonesArray dumm("AliTrackReference",1000), *prefs=&dumm;
444 TTree v0Tree("v0Tree","Tree with info about the reconstructable V0s");
445 v0Tree.Branch("negative",&nrefs);
446 v0Tree.Branch("positive",&prefs);
449 /*** Some information about the cuts ***/
450 Double_t r2min=0.9*0.9;
451 Double_t r2max=2.9*2.9;
455 //******** Loop over generated events
456 for (Int_t e=0; e<nev; e++) {
457 rl->GetEvent(e); v0File->cd();
459 Int_t np = rl->GetHeader()->GetNtrack();
460 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
462 itsTree->GetEvent(e);
463 Int_t nk=itsRefs->GetEntriesFast();
465 AliStack *stack=rl->Stack();
467 AliTrackReference *nref=0, *pref=0;
472 TParticle *p0=stack->Particle(np);
474 /*** only these V0s are "good" ***/
475 Int_t code=p0->GetPdgCode();
478 if (code!=kLambda0Bar) continue;
480 /*** daughter tracks should be "good" ***/
481 Int_t plab=p0->GetFirstDaughter(), nlab=p0->GetLastDaughter();
482 if (nlab==plab) continue;
483 if (nlab<0) continue;
484 if (plab<0) continue;
486 TParticle * part = stack->Particle(plab);
488 TParticlePDG * partPDG = part->GetPDG();
489 if (partPDG && partPDG->Charge() < 0.) {
490 i=plab; plab=nlab; nlab=i;
494 for (i=0; i<nk; i++) {
495 nref=(AliTrackReference*)itsRefs->UncheckedAt(i);
496 if (nref->Label()==nlab) break;
499 for (i=0; i<nk; i++) {
500 pref=(AliTrackReference*)itsRefs->UncheckedAt(i);
501 if (pref->Label()==plab) break;
505 /*** fiducial volume ***/
506 TParticle *p=stack->Particle(nlab);
507 Double_t x=p->Vx(), y=p->Vy(), z=p->Vz(), r2=x*x+y*y;
508 if (r2<r2min) continue;
509 if (r2>r2max) continue;
511 Int_t pdg=p0->GetPdgCode();
512 nref->SetLength(pdg); //This will the V0's PDG !
514 new((*nrefs)[nv]) AliTrackReference(*nref);
515 new((*prefs)[nv]) AliTrackReference(*pref);
522 nrefs->Clear(); prefs->Clear();
524 } //**** end of the loop over generated events