Adding the trigger and vertex checking in both the QA and the actual analysis
[u/mrichter/AliRoot.git] / STEER / AliCascadeComparison.C
CommitLineData
ca28c5f5 1/****************************************************************************
2 * Very important, delicate and rather obscure macro. *
3 * *
4 * Creates list of "findable" cascades, *
5 * calculates efficiency, resolutions etc. *
6 * *
7 * Origin: Christian Kuhn, IReS, Strasbourg, christian.kuhn@ires.in2p3.fr *
8 ****************************************************************************/
9
566abf75 10#if !defined(__CINT__) || defined(__MAKECINT__)
4fa1e629 11 #include <TMath.h>
12 #include <TError.h>
ddae8318 13 #include <Riostream.h>
4fa1e629 14 #include <TH1F.h>
15 #include <TTree.h>
16 #include <TParticle.h>
17 #include <TCanvas.h>
18 #include <TLine.h>
19 #include <TText.h>
20 #include <TBenchmark.h>
21 #include <TStyle.h>
8b462fd8 22 #include <TFile.h>
4fa1e629 23 #include <TROOT.h>
24
25 #include "AliStack.h"
566abf75 26 #include "AliHeader.h"
4fa1e629 27 #include "AliTrackReference.h"
566abf75 28 #include "AliRunLoader.h"
ca28c5f5 29 #include "AliRun.h"
4514157e 30 #include "AliESDEvent.h"
8a643433 31 #include "AliESDcascade.h"
4fa1e629 32#else
8a643433 33 const Int_t kXiMinus = 3312;
34 const Int_t kXiPlusBar = -3312;
35 const Int_t kOmegaMinus = 3334;
36 const Int_t kOmegaPlusBar = -3334;
ca28c5f5 37#endif
38
4fa1e629 39Int_t GoodCascades(const Char_t *dir=".");
ca28c5f5 40
566abf75 41extern AliRun *gAlice;
4fa1e629 42extern TBenchmark *gBenchmark;
43extern TROOT *gROOT;
44
45static Int_t allgood=0;
46static Int_t allfound=0;
566abf75 47
4fa1e629 48Int_t AliCascadeComparison(Int_t code=3312, const Char_t *dir=".") {
ca28c5f5 49 //code= 3312; //kXiMinus
50 //code=-3312; //kXiPlusBar
51 //code= 3334; //kOmegaMinus
52 //code=-3334; //kOmegaPlusBar
4fa1e629 53 gBenchmark->Start("AliCascadeComparison");
5102bab6 54
4fa1e629 55 ::Info("AliCascadeComparison.C","Doing comparison...");
5102bab6 56
ca28c5f5 57 const Double_t cascadeWindow=0.05, cascadeWidth=0.015;
04b2a5f1 58 Double_t ptncut=0.12, ptpcut=0.33, kine0cut=0.003;
59 Double_t ptbcut=0.11, kinecut=0.002;
60 Double_t cascadeMass=1.32131;
ca28c5f5 61 switch (code) {
62 case kXiMinus:
04b2a5f1 63 break;
64 case kXiPlusBar:
65 ptncut=0.33; ptpcut=0.12;
66 break;
ca28c5f5 67 case kOmegaMinus:
04b2a5f1 68 cascadeMass=1.67245;
69 kine0cut=0.001;
70 ptbcut=0.22; kinecut=0.006;
71 break;
72 case kOmegaPlusBar:
73 cascadeMass=1.67245;
74 kine0cut=0.001;
75 ptncut=0.33; ptpcut=0.12;
76 ptbcut=0.22; kinecut=0.006;
77 break;
ca28c5f5 78 default: cerr<<"Invalid PDG code !\n"; return 1;
79 }
80
4fa1e629 81
82 TH1F *hp=(TH1F*)gROOT->FindObject("hp");
83 if (!hp) hp=new TH1F("hp","Angular Resolution",30,-30.,30.);
566abf75 84 hp->SetXTitle("(mrad)"); hp->SetFillColor(2);
4fa1e629 85
86 TH1F *hl=(TH1F*)gROOT->FindObject("hl");
87 if (!hl) hl=new TH1F("hl","Lambda Resolution",30,-30,30);
88 hl->SetXTitle("(mrad)"); hl->SetFillColor(1); hl->SetFillStyle(3013);
89
90 TH1F *hpt=(TH1F*)gROOT->FindObject("hpt");
91 if (!hpt) hpt=new TH1F("hpt","Relative Pt Resolution",30,-10.,10.);
566abf75 92 hpt->SetXTitle("(%)"); hpt->SetFillColor(2);
93
4fa1e629 94 TH1F *hx=(TH1F*)gROOT->FindObject("hx");
95 if (!hx) hx=new TH1F("hx","Position Resolution (X,Y)",30,-3.,3.);
566abf75 96 hx->SetXTitle("(mm)"); hx->SetFillColor(6);
4fa1e629 97
98 TH1F *hy=(TH1F*)gROOT->FindObject("hy");
99 if (!hy) hy=new TH1F("hy","Position Resolution (Y)",30,-3.,3.);
566abf75 100 hy->SetXTitle("(mm)"); hy->SetFillColor(1); hy->SetFillStyle(3013);
4fa1e629 101
102 TH1F *hz=(TH1F*)gROOT->FindObject("hz");
103 if (!hz) hz=new TH1F("hz","Position Resolution (Z)",30,-3.,3.);
566abf75 104 hz->SetXTitle("(mm)"); hz->SetFillColor(6);
105
4fa1e629 106
566abf75 107 Double_t pmin=0.2, pmax=4.2; Int_t nchan=20;
4fa1e629 108 TH1F *hgood=(TH1F*)gROOT->FindObject("hgood");
109 if (!hgood) hgood=new TH1F("hgood","Good Cascades",nchan,pmin,pmax);
110
111 TH1F *hfound=(TH1F*)gROOT->FindObject("hfound");
112 if (!hfound) hfound=new TH1F("hfound","Found Cascades",nchan,pmin,pmax);
113
114 TH1F *hfake=(TH1F*)gROOT->FindObject("hfake");
115 if (!hfake) hfake=new TH1F("hfake","Fake Cascades",nchan,pmin,pmax);
116
117 TH1F *hg=(TH1F*)gROOT->FindObject("hg");
118 if (!hg) hg=new TH1F("hg","Efficiency for Good Cascades",nchan,pmin,pmax);
566abf75 119 hg->SetLineColor(4); hg->SetLineWidth(2);
4fa1e629 120
121 TH1F *hf=(TH1F*)gROOT->FindObject("hf");
122 if (!hf) hf=new TH1F("hf","Probability of Fake Cascades",nchan,pmin,pmax);
566abf75 123 hf->SetFillColor(1); hf->SetFillStyle(3013); hf->SetLineWidth(2);
124
4fa1e629 125
566abf75 126 Double_t mmin=cascadeMass-cascadeWindow, mmax=cascadeMass+cascadeWindow;
4fa1e629 127 TH1F *cs=(TH1F*)gROOT->FindObject("cs");
128 if (!cs) cs=new TH1F("cs","Cascade Effective Mass",40, mmin, mmax);
129 cs->SetXTitle("(GeV)"); cs->SetLineColor(4); cs->SetLineWidth(4);
130
131 TH1F *csf=(TH1F*)gROOT->FindObject("csf");
132 if (!csf) csf=new TH1F("csf","Fake Cascade Effective Mass",40, mmin, mmax);
566abf75 133 csf->SetXTitle("(GeV)"); csf->SetFillColor(6);
134
ca28c5f5 135
4fa1e629 136 Char_t fname[100];
137 sprintf(fname,"%s/GoodCascades.root",dir);
138
139 TFile *refFile=TFile::Open(fname,"old");
140 if (!refFile || !refFile->IsOpen()) {
141 ::Info("AliCascadeComparison.C","Marking good cascades (will take a while)...");
142 if (GoodCascades(dir)) {
143 ::Error("AliCascadesComparison.C","Can't generate the reference file !");
144 return 1;
145 }
ca28c5f5 146 }
4fa1e629 147 refFile=TFile::Open(fname,"old");
148 if (!refFile || !refFile->IsOpen()) {
149 ::Error("AliCascadeComparison.C","Can't open the reference file !");
150 return 1;
151 }
152
153 TTree *csTree=(TTree*)refFile->Get("csTree");
154 if (!csTree) {
155 ::Error("AliCascadeComparison.C","Can't get the reference tree !");
156 return 2;
ca28c5f5 157 }
4fa1e629 158 TBranch *pbranch=csTree->GetBranch("positive");
159 if (!pbranch) {
160 ::Error("AliCascadeComparison.C","Can't get the positive daughter branch !");
161 return 3;
162 }
163 TClonesArray dummy("AliTrackReference",1000), *prefs=&dummy;
164 pbranch->SetAddress(&prefs);
165
166 TBranch *nbranch=csTree->GetBranch("negative");
167 if (!nbranch) {
168 ::Error("AliCascadeComparison.C","Can't get the negative daughter branch !");
169 return 4;
170 }
171 TClonesArray dumm("AliTrackReference",1000), *nrefs=&dumm;
172 nbranch->SetAddress(&nrefs);
173
174 TBranch *bbranch=csTree->GetBranch("bachelor");
175 if (!nbranch) {
176 ::Error("AliCascadeComparison.C","Can't get the bachelor branch !");
177 return 4;
178 }
179 TClonesArray dum("AliTrackReference",1000), *brefs=&dum;
180 bbranch->SetAddress(&brefs);
181
182
183
184 sprintf(fname,"%s/AliESDs.root",dir);
185 TFile *ef=TFile::Open(fname);
186 if ((!ef)||(!ef->IsOpen())) {
187 sprintf(fname,"%s/AliESDcascade.root",dir);
188 ef=TFile::Open(fname);
189 if ((!ef)||(!ef->IsOpen())) {
190 ::Error("AliCascadeComparison.C","Can't open AliESDcascade.root !");
191 return 5;
192 }
193 }
4514157e 194 AliESDEvent* event = new AliESDEvent();
8b462fd8 195 TTree* esdTree = (TTree*) ef->Get("esdTree");
196 if (!esdTree) {
197 ::Error("AliCascadeComparison.C", "no ESD tree found");
198 return 6;
199 }
4514157e 200 event->ReadFromTree(esdTree);
4fa1e629 201
ca28c5f5 202
4fa1e629 203 //******* Loop over events *********
204 Int_t e=0;
8b462fd8 205 while (esdTree->GetEvent(e)) {
4fa1e629 206 cout<<endl<<endl<<"********* Processing event number: "<<e<<"*******\n";
207
4fa1e629 208 Int_t nentr=event->GetNumberOfCascades();
209 allfound+=nentr;
210
211
212 if (csTree->GetEvent(e++)==0) {
213 cerr<<"No reconstructable cascades !\n";
214 continue;
215 }
216
217 Int_t ngood=prefs->GetEntriesFast(),ng=0;
218
219 Double_t pxg=0.,pyg=0.,pzg=0.,ptg=0.;
220 Int_t nlab=-1, plab=-1, blab=-1;
221 Int_t i;
222 for (i=0; i<nentr; i++) {
223 AliESDcascade *cascade=event->GetCascade(i);
224
225 Int_t nidx=TMath::Abs(cascade->GetNindex());
226 Int_t pidx=TMath::Abs(cascade->GetPindex());
227 Int_t bidx=TMath::Abs(cascade->GetBindex());
228
229 AliESDtrack *ntrack=event->GetTrack(nidx);
230 AliESDtrack *ptrack=event->GetTrack(pidx);
231 AliESDtrack *btrack=event->GetTrack(bidx);
232
233 nlab=TMath::Abs(ntrack->GetLabel());
234 plab=TMath::Abs(ptrack->GetLabel());
235 blab=TMath::Abs(btrack->GetLabel());
236
237 /** Kinematical cuts **/
238 Double_t pxn,pyn,pzn; cascade->GetNPxPyPz(pxn,pyn,pzn);
239 Double_t ptn=TMath::Sqrt(pxn*pxn + pyn*pyn);
240 if (ptn < ptncut) continue;
241 Double_t pxp,pyp,pzp; cascade->GetPPxPyPz(pxp,pyp,pzp);
242 Double_t ptp=TMath::Sqrt(pxp*pxp + pyp*pyp);
243 if (ptp < ptpcut) continue;
244 Double_t pxb,pyb,pzb; cascade->GetBPxPyPz(pxb,pyb,pzb);
245 Double_t ptb=TMath::Sqrt(pxb*pxb + pyb*pyb);
246 if (ptb < ptbcut) continue;
247 Double_t kine0;
248 Double_t kine=cascade->ChangeMassHypothesis(kine0,code);
249 if (TMath::Abs(kine0)>kine0cut) continue;
250 //if (TMath::Abs(kine)>kinecut) continue;
251
252 Double_t mass=cascade->GetEffMass();
253 cs->Fill(mass);
254 csf->Fill(mass);
255
256 AliTrackReference *nref=0, *pref=0, *bref=0;
257 Int_t j;
258 for (j=0; j<ngood; j++) {
259 bref=(AliTrackReference*)brefs->UncheckedAt(j);
260 nref=(AliTrackReference*)nrefs->UncheckedAt(j);
261 pref=(AliTrackReference*)prefs->UncheckedAt(j);
262 if (bref->Label() == blab)
263 if (nref->Label() == nlab)
264 if (pref->Label() == plab) break;
265 }
266
267 if (TMath::Abs(mass-cascadeMass)>cascadeWidth) continue;
268
269 Double_t px,py,pz; cascade->GetPxPyPz(px,py,pz);
270 Double_t pt=TMath::Sqrt(px*px+py*py);
271
272 if (j==ngood) {
273 hfake->Fill(pt);
274 cout<<"Fake cascade: ("<<nlab<<","<<plab<<","<<blab<<")\n";
275 continue;
276 }
277 csf->Fill(mass,-1);
278
279 pxg=bref->Px()+nref->Px()+pref->Px();
280 pyg=bref->Px()+nref->Py()+pref->Py();
281 pzg=nref->Pz()+pref->Pz();
282 ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
283 Double_t phig=TMath::ATan2(pyg,pxg), phi=TMath::ATan2(py,px);
284 Double_t lamg=TMath::ATan2(pzg,ptg), lam=TMath::ATan2(pz,pt);
285 hp->Fill((phi - phig)*1000.);
286 hl->Fill((lam - lamg)*1000.);
287 hpt->Fill((1/pt - 1/ptg)/(1/ptg)*100.);
288
289 Double_t x,y,z; cascade->GetXYZ(x,y,z);
290 hx->Fill((x-nref->X())*10);
291 hy->Fill((y-nref->Y())*10);
292 hz->Fill((z-nref->Z())*10);
293
294 hfound->Fill(ptg);
295 nref->SetLabel(-1);
296
297 }
298 for (i=0; i<ngood; i++) {
299 AliTrackReference *bref=(AliTrackReference*)brefs->UncheckedAt(i);
300 AliTrackReference *nref=(AliTrackReference*)nrefs->UncheckedAt(i);
301 AliTrackReference *pref=(AliTrackReference*)prefs->UncheckedAt(i);
18b4df7a 302 Int_t pdg=(Int_t)nref->GetLength(); //this is the cascade's PDG !
4fa1e629 303 if (code!=pdg) continue;
304 ng++;
305 pxg=bref->Px()+nref->Px()+pref->Px();
306 pyg=bref->Px()+nref->Py()+pref->Py();
307 ptg=TMath::Sqrt(pxg*pxg+pyg*pyg);
308 hgood->Fill(ptg);
309 nlab=nref->Label(); plab=pref->Label(); blab=bref->Label();
310 if (nlab < 0) continue;
311 cout<<"Cascade ("<<nlab<<','<<plab<<","<<blab<<") has not been found !\n";
312 }
313 allgood+=ng;
314
315 cout<<"Number of found cascades : "<<nentr<<endl;
316 cout<<"Number of \"good\" cascades : "<<ng<<endl;
317
318 brefs->Clear();
319 prefs->Clear();
320 nrefs->Clear();
4fa1e629 321
322 } //**** End of the loop over events
323
8b462fd8 324 delete event;
4514157e 325 delete esdTree;
4fa1e629 326 ef->Close();
ca28c5f5 327
4fa1e629 328 delete csTree;
329 refFile->Close();
330
8a643433 331 Stat_t ngg=hgood->GetEntries(), nf=hfound->GetEntries();
332 if (ngg!=0) cout<<"Integral efficiency is about "<<nf/ngg*100.<<" %\n";
4fa1e629 333 cout<<
334 "Total number of found cascades: "<<allfound<<" ("<<nf<<" in the peak)\n";
335 cout<<"Total number of \"good\" cascades: "<<allgood<<endl;
ca28c5f5 336
ca28c5f5 337
338 gStyle->SetOptStat(111110);
339 gStyle->SetOptFit(1);
340
4fa1e629 341 TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
342 if (!c1) {
343 c1=new TCanvas("c1","",0,0,580,610);
344 c1->Divide(2,2);
345 }
346
347 Int_t minc=33;
ca28c5f5 348
349 c1->cd(1);
350 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
4fa1e629 351 if (hp->GetEntries()<minc) hp->Draw(); else hp->Fit("gaus");
ca28c5f5 352 hl->Draw("same"); c1->cd();
353
354 c1->cd(2);
355 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
4fa1e629 356 if (hpt->GetEntries()<minc) hpt->Draw(); else hpt->Fit("gaus");
357 c1->cd();
ca28c5f5 358
359 c1->cd(3);
360 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
4fa1e629 361 if (hx->GetEntries()<minc) hx->Draw(); else hx->Fit("gaus");
ca28c5f5 362 hy->Draw("same"); c1->cd();
363
364 c1->cd(4);
365 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
4fa1e629 366 if (hz->GetEntries()<minc) hz->Draw(); else hz->Fit("gaus");
ca28c5f5 367
4fa1e629 368 c1->Update();
ca28c5f5 369
4fa1e629 370 TCanvas *c2=(TCanvas*)gROOT->FindObject("c2");
371 if (!c2) {
372 c2=new TCanvas("c2","",600,0,580,610);
373 c2->Divide(1,2);
374 }
ca28c5f5 375
376 c2->cd(1);
377 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
378 hfound->Sumw2(); hgood->Sumw2(); hfake->Sumw2();
379 hg->Divide(hfound,hgood,1,1.,"b");
380 hf->Divide(hfake,hgood,1,1.,"b");
381 hg->SetMaximum(1.4);
382 hg->SetYTitle("Cascade reconstruction efficiency");
383 hg->SetXTitle("Pt (GeV/c)");
384 hg->Draw();
385
386 TLine *line1 = new TLine(pmin,1.0,pmax,1.0); line1->SetLineStyle(4);
387 line1->Draw("same");
388 TLine *line2 = new TLine(pmin,0.9,pmax,0.9); line2->SetLineStyle(4);
389 line2->Draw("same");
390
391 hf->SetFillColor(1);
392 hf->SetFillStyle(3013);
393 hf->SetLineColor(2);
394 hf->SetLineWidth(2);
395 hf->Draw("histsame");
396 TText *text = new TText(0.461176,0.248448,"Fake cascades");
397 text->SetTextSize(0.05);
398 text->Draw();
399 text = new TText(0.453919,1.11408,"Good cascades");
400 text->SetTextSize(0.05);
401 text->Draw();
402
403
404 c2->cd(2);
405 gPad->SetFillColor(42); gPad->SetFrameFillColor(10);
4fa1e629 406 if (cs->GetEntries()<minc) cs->Draw();
407 else cs->Fit("gaus","","",cascadeMass-cascadeWidth,cascadeMass+cascadeWidth);
04b2a5f1 408 csf->Draw("same");
ca28c5f5 409 Double_t max=cs->GetMaximum();
410 TLine *line3 =
411 new TLine(cascadeMass-cascadeWidth,0.,cascadeMass-cascadeWidth,max);
412 line3->Draw("same");
413 TLine *line4 =
414 new TLine(cascadeMass+cascadeWidth,0.,cascadeMass+cascadeWidth,max);
415 line4->Draw("same");
416
4fa1e629 417 c2->Update();
ca28c5f5 418
4fa1e629 419 TFile fc("AliCascadeComparison.root","RECREATE");
420 c1->Write();
421 c2->Write();
422 fc.Close();
ca28c5f5 423
4fa1e629 424 gBenchmark->Stop("AliCascadeComparison");
425 gBenchmark->Show("AliCascadeComparison");
ca28c5f5 426
ca28c5f5 427
4fa1e629 428 return 0;
429}
ca28c5f5 430
4fa1e629 431
432Int_t GoodCascades(const Char_t *dir) {
5102bab6 433 if (gAlice) {
880d6abe 434 delete AliRunLoader::GetRunLoader();
5102bab6 435 delete gAlice;
436 gAlice=0;
437 }
4fa1e629 438
439 Char_t fname[100];
440 sprintf(fname,"%s/galice.root",dir);
441
442 AliRunLoader *rl = AliRunLoader::Open(fname,"COMPARISON");
5102bab6 443 if (!rl) {
4fa1e629 444 ::Error("GoodCascades","Can't start session !");
566abf75 445 return 1;
ca28c5f5 446 }
5102bab6 447
566abf75 448 rl->LoadgAlice();
449 rl->LoadHeader();
450 rl->LoadKinematics();
4fa1e629 451
452
453 Int_t nev=rl->GetNumberOfEvents();
454 ::Info("GoodCascades","Number of events : %d\n",nev);
455
456
457 sprintf(fname,"%s/GoodTracksITS.root",dir);
458 TFile *itsFile=TFile::Open(fname);
459 if ((!itsFile)||(!itsFile->IsOpen())) {
460 ::Error("GoodCAscades","Can't open the GoodTracksITS.root !");
461 delete rl;
462 return 5;
463 }
464 TClonesArray dm("AliTrackReference",1000), *itsRefs=&dm;
465 TTree *itsTree=(TTree*)itsFile->Get("itsTree");
466 if (!itsTree) {
467 ::Error("GoodCascades","Can't get the ITS reference tree !");
468 delete rl;
469 return 6;
470 }
471 TBranch *itsBranch=itsTree->GetBranch("ITS");
472 if (!itsBranch) {
473 ::Error("GoodCascades","Can't get the ITS reference branch !");
474 delete rl;
475 return 7;
476 }
477 itsBranch->SetAddress(&itsRefs);
478
479
480 sprintf(fname,"%s/GoodCascades.root",dir);
481 TFile *csFile=TFile::Open(fname,"recreate");
482 TClonesArray dummy("AliTrackReference",1000), *nrefs=&dummy;
483 TClonesArray dumm("AliTrackReference",1000), *prefs=&dumm;
484 TClonesArray dum("AliTrackReference",1000), *brefs=&dum;
485 TTree csTree("csTree","Tree with info about the reconstructable cascades");
486 csTree.Branch("negative",&nrefs);
487 csTree.Branch("positive",&prefs);
488 csTree.Branch("bachelor",&brefs);
489
490
491 // *** Get information about the cuts ***
492 Double_t r2min=0.9*0.9;
493 Double_t r2max=2.9*2.9;
494
495
496 //******** Loop over generated events
497 for (Int_t e=0; e<nev; e++) {
498 rl->GetEvent(e); csFile->cd();
499
500 Int_t np = rl->GetHeader()->GetNtrack();
501 cout<<"Event "<<e<<" Number of particles: "<<np<<endl;
502
503 itsTree->GetEvent(e);
504 Int_t nk=itsRefs->GetEntriesFast();
505
506 AliStack *stack=rl->Stack();
507
508 AliTrackReference *nref=0, *pref=0, *bref=0;
509
510 Int_t nc=0;
511 while (np--) {
512 //cerr<<np<<'\r';
513 TParticle *cp=stack->Particle(np);
514
515 // *** only these cascades are "good" ***
516 Int_t code=cp->GetPdgCode();
517 if (code!=kXiMinus) if (code!=kXiPlusBar)
518 if (code!=kOmegaMinus) if (code!=kOmegaPlusBar) continue;
519
520 // *** daughter tracks must be "good" ***
521 Int_t v0lab=cp->GetFirstDaughter(), blab=cp->GetLastDaughter();
522 if (v0lab==blab) continue;
523 if (v0lab<0) continue;
524 if (blab<0) continue;
525
526 TParticle *p0=stack->Particle(v0lab);
527 TParticle *bp=stack->Particle(blab);
528 Int_t i;
529 if ((p0->GetPdgCode()!=kLambda0) && (p0->GetPdgCode()!=kLambda0Bar)) {
530 TParticle *p=p0; p0=bp; bp=p;
531 i=v0lab; v0lab=blab; blab=i;
532 if ((p0->GetPdgCode()!=kLambda0)&&(p0->GetPdgCode()!=kLambda0Bar))
ca28c5f5 533 continue;
4fa1e629 534 }
ca28c5f5 535
4fa1e629 536 // ** is the bachelor "good" ? **
537 for (i=0; i<nk; i++) {
538 bref=(AliTrackReference*)itsRefs->UncheckedAt(i);
539 if (bref->Label()==blab) break;
540 }
541 if (i==nk) continue;
542
543 // ** is the V0 "good" ? **
544 Int_t plab=p0->GetFirstDaughter(), nlab=p0->GetLastDaughter();
545 if (nlab==plab) continue;
546 if (nlab<0) continue;
547 if (plab<0) continue;
548 if (stack->Particle(plab)->GetPDG()->Charge() < 0.) {
549 i=plab; plab=nlab; nlab=i;
550 }
551 for (i=0; i<nk; i++) {
552 nref=(AliTrackReference*)itsRefs->UncheckedAt(i);
553 if (nref->Label()==nlab) break;
554 }
555 if (i==nk) continue;
556 for (i=0; i<nk; i++) {
557 pref=(AliTrackReference*)itsRefs->UncheckedAt(i);
558 if (pref->Label()==plab) break;
559 }
560 if (i==nk) continue;
561
562
563 // *** fiducial volume ***
564 Double_t x=bp->Vx(), y=bp->Vy(), r2=x*x+y*y; //bachelor
565 if (r2<r2min) continue;
566 if (r2>r2max) continue;
567 TParticle *pp=stack->Particle(plab);
568 x=pp->Vx(); y=pp->Vy(); r2=x*x+y*y; //V0
569 if (r2<r2min) continue;
570 if (r2>r2max) continue;
571
572 Int_t pdg=cp->GetPdgCode();
573 nref->SetLength(pdg); //This will the cascade's PDG !
574
575 new((*nrefs)[nc]) AliTrackReference(*nref);
576 new((*prefs)[nc]) AliTrackReference(*pref);
577 new((*brefs)[nc]) AliTrackReference(*bref);
578
579 nc++;
ca28c5f5 580 }
4fa1e629 581 itsRefs->Clear();
ca28c5f5 582
4fa1e629 583 csTree.Fill();
584 nrefs->Clear(); prefs->Clear(); brefs->Clear();
ca28c5f5 585
4fa1e629 586 } //**** end of the loop over generated events
ca28c5f5 587
4fa1e629 588 csTree.Write();
589 csFile->Close();
ca28c5f5 590
4fa1e629 591 delete itsTree;
592 itsFile->Close();
593
594 delete rl;
595 return 0;
ca28c5f5 596}