1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //----------------------------------------------------------------------------
17 // Implementation of the D0toKpi reconstruction and analysis class
18 // Note: the two decay tracks are labelled: 0 (positive track)
20 // An example of usage can be found in the macro AliD0toKpiTest.C
21 // Origin: A. Dainese andrea.dainese@pd.infn.it
22 //----------------------------------------------------------------------------
28 #include <TParticle.h>
31 #include "AliRunLoader.h"
32 #include "AliITStrackV2.h"
33 #include "AliITSVertexerTracks.h"
34 #include "AliESDVertex.h"
35 #include "AliV0vertexer.h"
36 #include "AliV0vertex.h"
37 #include "AliD0toKpi.h"
38 #include "AliD0toKpiAnalysis.h"
50 ClassImp(AliD0toKpiAnalysis)
52 //----------------------------------------------------------------------------
53 AliD0toKpiAnalysis::AliD0toKpiAnalysis() {
54 // Default constructor
63 fVertexOnTheFly = kFALSE;
67 //----------------------------------------------------------------------------
68 AliD0toKpiAnalysis::~AliD0toKpiAnalysis() {}
69 //----------------------------------------------------------------------------
70 void AliD0toKpiAnalysis::ApplySelection(const Char_t *inName,const Char_t *outName) const {
71 // select candidates that pass fD0Cuts and write them to a new file
73 TFile *inFile = TFile::Open(inName);
75 TTree *treeD0in=(TTree*)inFile->Get("TreeD0");
76 AliD0toKpiAnalysis *inAnalysis = (AliD0toKpiAnalysis*)inFile->Get("D0toKpiAnalysis");
77 printf("+++\n+++ I N P U T S T A T U S:\n+++\n");
78 inAnalysis->PrintStatus();
82 treeD0in->SetBranchAddress("D0toKpi",&d);
83 Int_t entries = (Int_t)treeD0in->GetEntries();
85 printf("+++\n+++ Number of D0 in input tree: %d\n+++\n",entries);
87 TTree *treeD0out = new TTree("TreeD0","Tree with selected D0 candidates");
88 treeD0out->Branch("D0toKpi","AliD0toKpi",&d,200000,0);
91 Int_t okD0=0,okD0bar=0;
94 for(Int_t i=0; i<entries; i++) {
95 // get event from tree
96 treeD0in->GetEvent(i);
98 if(fSim && fOnlySignal && !d->IsSignal()) continue;
100 // check if candidate passes selection (as D0 or D0bar)
101 if(d->Select(fD0Cuts,okD0,okD0bar)) {
108 AliD0toKpiAnalysis *outAnalysis = (AliD0toKpiAnalysis*)inAnalysis->Clone("D0toKpiAnalysis");
109 outAnalysis->SetD0Cuts(fD0Cuts);
110 printf("------------------------------------------\n");
111 printf("+++\n+++ O U T P U T S T A T U S:\n+++\n");
112 outAnalysis->PrintStatus();
114 printf("+++\n+++ Number of D0 in output tree: %d\n+++\n",nSel);
116 TFile* outFile = new TFile(outName,"recreate");
118 outAnalysis->Write();
123 //----------------------------------------------------------------------------
124 Double_t AliD0toKpiAnalysis::CalculateTOFmass(Double_t mom,Double_t length,
125 Double_t time) const {
126 // calculated the mass from momentum, track length from vertex to TOF
127 // and time measured by the TOF
128 if(length==0.) return -1000.;
129 Double_t a = time*time/length/length;
131 a = TMath::Sqrt(a-1.);
133 a = -TMath::Sqrt(1.-a);
138 //----------------------------------------------------------------------------
139 void AliD0toKpiAnalysis::FindCandidates(Int_t evFirst,Int_t evLast,
140 const Char_t *outName) {
141 // Find D0 candidates and calculate parameters
144 printf("AliD0toKpiAnalysis::FindCandidates(): Set B!\n");
148 TString trkName("AliITStracksV2.root");
149 if(gSystem->AccessPathName(trkName.Data(),kFileExists)) {
150 printf("AliD0toKpiAnalysis::FindCandidates(): No tracks file found!\n");
154 TString outName1=outName;
155 TString outName2("nTotEvents.dat");
158 Int_t nTotEv=0,nD0rec=0,nD0rec1ev=0;
160 Double_t v2[3],mom[6],d0[2];
161 Double_t alphaP,alphaN,ptP,ptN,phiP,phiN;
162 Int_t iTrkP,iTrkN,trkEntries;
163 Int_t nTrksP=0,nTrksN=0;
165 Int_t okD0=0,okD0bar=0;
166 Char_t trkTreeName[100],vtxName[100];
167 AliITStrackV2 *postrack = 0;
168 AliITStrackV2 *negtrack = 0;
170 // create the AliITSVertexerTracks object
171 // (it will be used only if fVertexOnTheFly=kTrue)
172 AliITSVertexerTracks *vertexer1 = new AliITSVertexerTracks;
173 vertexer1->SetMinTracks(2);
178 // define the cuts for vertexing
179 Double_t vtxcuts[]={50., // max. allowed chi2
180 0.0, // min. allowed negative daughter's impact param
181 0.0, // min. allowed positive daughter's impact param
182 1.0, // max. allowed DCA between the daughter tracks
183 -1.0, // min. allowed cosine of pointing angle
184 0.0, // min. radius of the fiducial volume
185 2.9};// max. radius of the fiducial volume
187 // create the AliV0vertexer object
188 AliV0vertexer *vertexer2 = new AliV0vertexer(vtxcuts);
190 // create tree for reconstructed D0s
191 AliD0toKpi *ioD0toKpi=0;
192 TTree *treeD0 = new TTree("TreeD0","Tree with D0 candidates");
193 treeD0->Branch("D0toKpi","AliD0toKpi",&ioD0toKpi,200000,0);
195 // open file with tracks
196 TFile *trkFile = TFile::Open(trkName.Data());
198 // loop on events in file
199 for(ev=evFirst; ev<=evLast; ev++) {
200 printf(" --- Looking for D0->Kpi in event %d ---\n",ev);
202 // retrieve primary vertex from file
203 sprintf(vtxName,"VertexTracks_%d",ev);
204 AliESDVertex *vertex1stored = (AliESDVertex*)trkFile->Get(vtxName);
205 vertex1stored->GetXYZ(fV1);
206 delete vertex1stored;
208 // retrieve tracks from file
209 sprintf(trkTreeName,"TreeT_ITS_%d",ev);
210 TTree *trkTree=(TTree*)trkFile->Get(trkTreeName);
212 printf("AliD0toKpiAnalysis::FindCandidates():\n tracks tree not found for evet %d\n",ev);
215 trkEntries = (Int_t)trkTree->GetEntries();
216 printf(" Number of tracks: %d\n",trkEntries);
218 // count the total number of events
221 // call function which applies sigle-track selection and
222 // separetes positives and negatives
223 TObjArray trksP(trkEntries/2);
224 Int_t *trkEntryP = new Int_t[trkEntries];
225 TObjArray trksN(trkEntries/2);
226 Int_t *trkEntryN = new Int_t[trkEntries];
227 SelectTracks(*trkTree,trksP,trkEntryP,nTrksP,trksN,trkEntryN,nTrksN);
231 // loop on positive tracks
232 for(iTrkP=0; iTrkP<nTrksP; iTrkP++) {
233 if(iTrkP%10==0) printf(" Processing positive track number %d of %d\n",iTrkP,nTrksP);
235 // get track from track array
236 postrack = (AliITStrackV2*)trksP.At(iTrkP);
237 trkNum[0] = trkEntryP[iTrkP];
239 // loop on negative tracks
240 for(iTrkN=0; iTrkN<nTrksN; iTrkN++) {
241 // get track from tracks array
242 negtrack = (AliITStrackV2*)trksN.At(iTrkN);
243 trkNum[1] = trkEntryN[iTrkN];
245 AliITStrackV2 nt(*negtrack), pt(*postrack), *pnt=&nt, *ppt=&pt;
248 // ----------- DCA MINIMIZATION ------------------
250 // find the DCA and propagate the tracks to the DCA
251 dca = vertexer2->PropagateToDCA(pnt,ppt);
253 // define the AliV0vertex object
254 AliV0vertex *vertex2 = new AliV0vertex(*pnt,*ppt);
256 // get position of the secondary vertex
257 vertex2->GetXYZ(v2[0],v2[1],v2[2]);
261 // momenta of the tracks at the vertex
262 ptP = 1./TMath::Abs(ppt->Get1Pt());
263 alphaP = ppt->GetAlpha();
264 phiP = alphaP+TMath::ASin(ppt->GetSnp());
265 mom[0] = ptP*TMath::Cos(phiP);
266 mom[1] = ptP*TMath::Sin(phiP);
267 mom[2] = ptP*ppt->GetTgl();
269 ptN = 1./TMath::Abs(pnt->Get1Pt());
270 alphaN = pnt->GetAlpha();
271 phiN = alphaN+TMath::ASin(pnt->GetSnp());
272 mom[3] = ptN*TMath::Cos(phiN);
273 mom[4] = ptN*TMath::Sin(phiN);
274 mom[5] = ptN*pnt->GetTgl();
277 // no vertexing if DeltaMass > fMassCut
278 if(fVertexOnTheFly) {
280 if(SelectInvMass(mom)) {
281 // primary vertex from *other* tracks in event
282 vertexer1->SetVtxStart(fV1[0],fV1[1]);
283 skipped[0] = trkEntryP[iTrkP];
284 skipped[1] = trkEntryN[iTrkN];
285 vertexer1->SetSkipTracks(2,skipped);
286 AliESDVertex *vertex1onfly =
287 (AliESDVertex*)vertexer1->VertexOnTheFly(*trkTree);
288 if(vertex1onfly->GetNContributors()>0) goodVtx1 = kTRUE;
289 vertex1onfly->GetXYZ(fV1);
290 //vertex1onfly->PrintStatus();
295 // impact parameters of the tracks w.r.t. the primary vertex
296 d0[0] = 10000.*ppt->GetD(fV1[0],fV1[1]);
297 d0[1] = -10000.*pnt->GetD(fV1[0],fV1[1]);
299 // create the object AliD0toKpi
300 AliD0toKpi theD0(ev,trkNum,fV1,v2,dca,mom,d0);
303 if(goodVtx1 && theD0.Select(fD0Cuts,okD0,okD0bar)) {
309 nD0rec++; nD0rec1ev++;
314 } // loop on negative tracks
316 } // loop on positive tracks
324 printf(" Number of D0 candidates: %d\n",nD0rec1ev);
325 } // loop on events in file
328 printf("\n+++\n+++ Total number of events: %d\n+++\n",nTotEv);
329 printf("\n+++\n+++ Total number of D0 candidates: %d\n+++\n",nD0rec);
336 // create a copy of this class to be written to output file
337 AliD0toKpiAnalysis *copy = (AliD0toKpiAnalysis*)this->Clone("D0toKpiAnalysis");
340 // add PDG codes to decay tracks in found candidates (in simulation mode)
341 // and store tree in the output file
343 TFile *outroot = new TFile(outName1.Data(),"recreate");
349 printf(" Now adding information from simulation (PDG codes) ...\n");
350 TTree *treeD0sim = new TTree("TreeD0","Tree with D0 candidates");
351 MakeTracksRefFile(evFirst,evLast);
352 SimulationInfo(treeD0,treeD0sim);
354 TFile *outroot = new TFile(outName1.Data(),"recreate");
361 // write to a file the total number of events
362 FILE *outdat = fopen(outName2.Data(),"w");
363 fprintf(outdat,"%d\n",nTotEv);
368 //----------------------------------------------------------------------------
369 void AliD0toKpiAnalysis::FindCandidatesESD(Int_t evFirst,Int_t evLast,
370 const Char_t *outName) {
371 // Find D0 candidates and calculate parameters
374 printf("AliD0toKpiAnalysis::FindCandidatesESD(): Set B!\n");
378 TString esdName("AliESDs.root");
379 if(gSystem->AccessPathName(esdName.Data(),kFileExists)) {
380 printf("AliD0toKpiAnalysis::FindCandidatesESD(): No ESDs file found!\n");
384 TString outName1=outName;
385 TString outName2("nTotEvents.dat");
387 Int_t nTotEv=0,nD0rec=0,nD0rec1ev=0;
389 Double_t v2[3],mom[6],d0[2];
390 Double_t alphaP,alphaN,ptP,ptN,phiP,phiN;
391 Int_t iTrkP,iTrkN,trkEntries;
392 Int_t nTrksP=0,nTrksN=0;
395 Int_t okD0=0,okD0bar=0;
396 AliITStrackV2 *postrack = 0;
397 AliITStrackV2 *negtrack = 0;
399 // create the AliITSVertexerTracks object
400 // (it will be used only if fVertexOnTheFly=kTrue)
401 AliITSVertexerTracks *vertexer1 = new AliITSVertexerTracks;
402 vertexer1->SetMinTracks(2);
407 // define the cuts for vertexing
408 Double_t vtxcuts[]={50., // max. allowed chi2
409 0.0, // min. allowed negative daughter's impact param
410 0.0, // min. allowed positive daughter's impact param
411 1.0, // max. allowed DCA between the daughter tracks
412 -1.0, // min. allowed cosine of pointing angle
413 0.0, // min. radius of the fiducial volume
414 2.9};// max. radius of the fiducial volume
416 // create the AliV0vertexer object
417 AliV0vertexer *vertexer2 = new AliV0vertexer(vtxcuts);
419 // create tree for reconstructed D0s
420 AliD0toKpi *ioD0toKpi=0;
421 TTree *treeD0 = new TTree("TreeD0","Tree with D0 candidates");
422 treeD0->Branch("D0toKpi","AliD0toKpi",&ioD0toKpi,200000,0);
424 // open file with tracks
425 TFile *esdFile = TFile::Open(esdName.Data());
426 AliESD* event = new AliESD;
427 TTree* tree = (TTree*) esdFile->Get("esdTree");
429 Error("FindCandidatesESD", "no ESD tree found");
432 tree->SetBranchAddress("ESD", &event);
434 // loop on events in file
435 for (Int_t iEvent = evFirst; iEvent < tree->GetEntries(); iEvent++) {
436 if (iEvent > evLast) break;
437 tree->GetEvent(iEvent);
438 Int_t ev = (Int_t)event->GetEventNumber();
439 printf("--- Finding D0 -> Kpi in event %d\n",ev);
441 // retrieve primary vertex from file
442 //sprintf(vtxName,"Vertex_%d",ev);
443 //AliESDVertex *vertex1stored = (AliESDVertex*)trkFile->Get(vtxName);
444 //vertex1stored->GetXYZ(fV1);
445 //delete vertex1stored;
446 event->GetVertex()->GetXYZ(fV1);
448 trkEntries = event->GetNumberOfTracks();
449 printf(" Number of tracks: %d\n",trkEntries);
451 // count the total number of events
454 // call function which applies sigle-track selection and
455 // separetes positives and negatives
456 TObjArray trksP(trkEntries/2);
457 Int_t *trkEntryP = new Int_t[trkEntries];
458 TObjArray trksN(trkEntries/2);
459 Int_t *trkEntryN = new Int_t[trkEntries];
460 TTree *trkTree = new TTree();
461 if(fVertexOnTheFly) {
462 SelectTracksESDvtx(*event,trkTree,trksP,trkEntryP,nTrksP,
463 trksN,trkEntryN,nTrksN);
465 SelectTracksESD(*event,trksP,trkEntryP,nTrksP,
466 trksN,trkEntryN,nTrksN);
469 AliDebugClass(1,Form(" pos. tracks: %d neg .tracks: %d",nTrksP,nTrksN));
473 // loop on positive tracks
474 for(iTrkP=0; iTrkP<nTrksP; iTrkP++) {
475 if(iTrkP%10==0) AliDebugClass(1,Form(" Processing positive track number %d of %d",iTrkP,nTrksP));
477 // get track from track array
478 postrack = (AliITStrackV2*)trksP.UncheckedAt(iTrkP);
479 trkNum[0] = trkEntryP[iTrkP];
481 // loop on negative tracks
482 for(iTrkN=0; iTrkN<nTrksN; iTrkN++) {
484 // get track from tracks array
485 negtrack = (AliITStrackV2*)trksN.UncheckedAt(iTrkN);
486 trkNum[1] = trkEntryN[iTrkN];
488 AliITStrackV2 nt(*negtrack), pt(*postrack), *pnt=&nt, *ppt=&pt;
491 // ----------- DCA MINIMIZATION ------------------
493 // find the DCA and propagate the tracks to the DCA
494 dca = vertexer2->PropagateToDCA(pnt,ppt);
496 // define the AliV0vertex object
497 AliV0vertex *vertex2 = new AliV0vertex(*pnt,*ppt);
499 // get position of the secondary vertex
500 vertex2->GetXYZ(v2[0],v2[1],v2[2]);
504 // momenta of the tracks at the vertex
505 ptP = 1./TMath::Abs(ppt->Get1Pt());
506 alphaP = ppt->GetAlpha();
507 phiP = alphaP+TMath::ASin(ppt->GetSnp());
508 mom[0] = ptP*TMath::Cos(phiP);
509 mom[1] = ptP*TMath::Sin(phiP);
510 mom[2] = ptP*ppt->GetTgl();
512 ptN = 1./TMath::Abs(pnt->Get1Pt());
513 alphaN = pnt->GetAlpha();
514 phiN = alphaN+TMath::ASin(pnt->GetSnp());
515 mom[3] = ptN*TMath::Cos(phiN);
516 mom[4] = ptN*TMath::Sin(phiN);
517 mom[5] = ptN*pnt->GetTgl();
520 // no vertexing if DeltaMass > fMassCut
521 if(fVertexOnTheFly) {
523 if(SelectInvMass(mom)) {
524 // primary vertex from *other* tracks in event
525 vertexer1->SetVtxStart(fV1[0],fV1[1]);
526 skipped[0] = trkEntryP[iTrkP];
527 skipped[1] = trkEntryN[iTrkN];
528 vertexer1->SetSkipTracks(2,skipped);
529 AliESDVertex *vertex1onfly =
530 (AliESDVertex*)vertexer1->VertexOnTheFly(*trkTree);
531 if(vertex1onfly->GetNContributors()>0) goodVtx1 = kTRUE;
532 vertex1onfly->GetXYZ(fV1);
533 //vertex1onfly->PrintStatus();
538 // impact parameters of the tracks w.r.t. the primary vertex
539 d0[0] = 10000.*ppt->GetD(fV1[0],fV1[1]);
540 d0[1] = -10000.*pnt->GetD(fV1[0],fV1[1]);
542 // create the object AliD0toKpi
543 AliD0toKpi theD0(ev,trkNum,fV1,v2,dca,mom,d0);
546 if(goodVtx1 && theD0.Select(fD0Cuts,okD0,okD0bar)) {
548 // get PID info from ESD
549 AliESDtrack *t0 = (AliESDtrack*)event->GetTrack(trkNum[0]);
551 t0->GetESDpid(esdpid0);
552 if(t0->GetStatus()&AliESDtrack::kTOFpid) {
553 tofmass[0] = CalculateTOFmass(t0->GetP(),
554 t0->GetIntegratedLength(),
559 AliESDtrack *t1 = (AliESDtrack*)event->GetTrack(trkNum[1]);
561 t1->GetESDpid(esdpid1);
562 if(t1->GetStatus()&AliESDtrack::kTOFpid) {
563 tofmass[1] = CalculateTOFmass(t1->GetP(),
564 t1->GetIntegratedLength(),
570 theD0.SetPIDresponse(esdpid0,esdpid1);
571 theD0.SetTOFmasses(tofmass);
577 nD0rec++; nD0rec1ev++;
582 } // loop on negative tracks
584 } // loop on positive tracks
593 printf(" Number of D0 candidates: %d\n",nD0rec1ev);
594 } // loop on events in file
597 printf("\n+++\n+++ Total number of events: %d\n+++\n",nTotEv);
598 printf("\n+++\n+++ Total number of D0 candidates: %d\n+++\n",nD0rec);
605 // create a copy of this class to be written to output file
606 AliD0toKpiAnalysis *copy = (AliD0toKpiAnalysis*)this->Clone("D0toKpiAnalysis");
608 // add PDG codes to decay tracks in found candidates (in simulation mode)
609 // and store tree in the output file
611 TFile *outroot = new TFile(outName1.Data(),"recreate");
617 printf(" Now adding information from simulation (PDG codes) ...\n");
618 TTree *treeD0sim = new TTree("TreeD0","Tree with D0 candidates");
619 MakeTracksRefFileESD();
620 SimulationInfo(treeD0,treeD0sim);
622 TFile *outroot = new TFile(outName1.Data(),"recreate");
629 // write to a file the total number of events
630 FILE *outdat = fopen(outName2.Data(),"w");
631 fprintf(outdat,"%d\n",nTotEv);
636 //-----------------------------------------------------------------------------
637 void AliD0toKpiAnalysis::PrintStatus() const {
638 // Print parameters being used
640 printf(" fBz = %f T\n",fBz);
641 printf("Preselections:\n");
642 printf(" fPtCut = %f GeV\n",fPtCut);
643 printf(" fd0Cut = %f micron\n",fd0Cut);
644 printf(" fMassCut = %f GeV\n",fMassCut);
645 if(fVertexOnTheFly) printf("Primary vertex on the fly\n");
647 printf("Simulation mode\n");
648 if(fOnlySignal) printf(" Only signal goes to file\n");
650 printf("Cuts on candidates:\n");
651 printf(" |M-MD0| [GeV] < %f\n",fD0Cuts[0]);
652 printf(" dca [micron] < %f\n",fD0Cuts[1]);
653 printf(" cosThetaStar < %f\n",fD0Cuts[2]);
654 printf(" pTK [GeV] > %f\n",fD0Cuts[3]);
655 printf(" pTpi [GeV] > %f\n",fD0Cuts[4]);
656 printf(" |d0K| [micron] < %f\n",fD0Cuts[5]);
657 printf(" |d0pi| [micron] < %f\n",fD0Cuts[6]);
658 printf(" d0d0 [micron^2] < %f\n",fD0Cuts[7]);
659 printf(" cosThetaPoint > %f\n",fD0Cuts[8]);
663 //-----------------------------------------------------------------------------
664 Bool_t AliD0toKpiAnalysis::SelectInvMass(const Double_t p[6]) const {
665 // Apply preselection in the invariant mass of the pair
667 Double_t mD0 = 1.8645;
668 Double_t mPi = 0.13957;
669 Double_t mKa = 0.49368;
672 Double_t mom2[2],momTot2;
674 mom2[0] = p[0]*p[0] + p[1]*p[1] + p[2]*p[2];
675 mom2[1] = p[3]*p[3] + p[4]*p[4] + p[5]*p[5];
677 momTot2 = (p[0]+p[3])*(p[0]+p[3])+
678 (p[1]+p[4])*(p[1]+p[4])+
679 (p[2]+p[5])*(p[2]+p[5]);
682 energy[1] = TMath::Sqrt(mKa*mKa+mom2[1]);
683 energy[0] = TMath::Sqrt(mPi*mPi+mom2[0]);
685 Double_t minvD0 = TMath::Sqrt((energy[0]+energy[1])*(energy[0]+energy[1])-momTot2);
688 energy[0] = TMath::Sqrt(mKa*mKa+mom2[0]);
689 energy[1] = TMath::Sqrt(mPi*mPi+mom2[1]);
691 Double_t minvD0bar = TMath::Sqrt((energy[0]+energy[1])*(energy[0]+energy[1])-momTot2);
693 if(TMath::Abs(minvD0-mD0) < fMassCut) return kTRUE;
694 if(TMath::Abs(minvD0bar-mD0) < fMassCut) return kTRUE;
697 //-----------------------------------------------------------------------------
698 void AliD0toKpiAnalysis::SelectTracks(TTree &trkTree,
699 TObjArray &trksP,Int_t *trkEntryP,Int_t &nTrksP,
700 TObjArray &trksN,Int_t *trkEntryN,Int_t &nTrksN) const {
701 // Create two TObjArrays with positive and negative tracks and
702 // apply single-track preselection
706 Int_t entr = (Int_t)trkTree.GetEntries();
708 // trasfer tracks from tree to arrays
709 for(Int_t i=0; i<entr; i++) {
711 AliITStrackV2 *track = new AliITStrackV2;
712 trkTree.SetBranchAddress("tracks",&track);
716 // single track selection
717 if(!SingleTrkCuts(*track)) { delete track; continue; }
719 if(track->Get1Pt()>0.) { // negative track
720 trksN.AddLast(track);
721 trkEntryN[nTrksN] = i;
723 } else { // positive track
724 trksP.AddLast(track);
725 trkEntryP[nTrksP] = i;
733 //-----------------------------------------------------------------------------
734 void AliD0toKpiAnalysis::SelectTracksESD(AliESD &event,
735 TObjArray &trksP,Int_t *trkEntryP,Int_t &nTrksP,
736 TObjArray &trksN,Int_t *trkEntryN,Int_t &nTrksN) const {
737 // Create two TObjArrays with positive and negative tracks and
738 // apply single-track preselection
742 Int_t entr = event.GetNumberOfTracks();
744 // transfer ITS tracks from ESD to arrays and to a tree
745 for(Int_t i=0; i<entr; i++) {
747 AliESDtrack *esdtrack = (AliESDtrack*)event.GetTrack(i);
748 UInt_t status = esdtrack->GetStatus();
750 if(!(status&AliESDtrack::kITSrefit)) continue;
752 AliITStrackV2 *itstrack = new AliITStrackV2(*esdtrack);
754 // single track selection
755 if(!SingleTrkCuts(*itstrack))
756 { delete itstrack; continue; }
758 if(itstrack->Get1Pt()>0.) { // negative track
759 trksN.AddLast(itstrack);
760 trkEntryN[nTrksN] = i;
762 } else { // positive track
763 trksP.AddLast(itstrack);
764 trkEntryP[nTrksP] = i;
768 } // loop on ESD tracks
772 //-----------------------------------------------------------------------------
773 void AliD0toKpiAnalysis::SelectTracksESDvtx(AliESD &event,TTree *trkTree,
774 TObjArray &trksP,Int_t *trkEntryP,Int_t &nTrksP,
775 TObjArray &trksN,Int_t *trkEntryN,Int_t &nTrksN) const {
776 // Create two TObjArrays with positive and negative tracks and
777 // apply single-track preselection
781 Int_t entr = event.GetNumberOfTracks();
783 AliITStrackV2 *itstrackfortree = 0;
784 trkTree->Branch("tracks","AliITStrackV2",&itstrackfortree,entr,0);
787 // transfer ITS tracks from ESD to arrays and to a tree
788 for(Int_t i=0; i<entr; i++) {
790 AliESDtrack *esdtrack = (AliESDtrack*)event.GetTrack(i);
791 UInt_t status = esdtrack->GetStatus();
793 if(!(status&AliESDtrack::kITSrefit)) continue;
795 AliITStrackV2 *itstrack = new AliITStrackV2(*esdtrack);
797 // store track in the tree to be used for primary vertex finding
798 itstrackfortree = new AliITStrackV2(*esdtrack);
802 // single track selection
803 if(!SingleTrkCuts(*itstrack))
804 { delete itstrack; continue; }
806 if(itstrack->Get1Pt()>0.) { // negative track
807 trksN.AddLast(itstrack);
808 trkEntryN[nTrksN] = i;
810 } else { // positive track
811 trksP.AddLast(itstrack);
812 trkEntryP[nTrksP] = i;
816 } // loop on esd tracks
818 delete itstrackfortree;
822 //-----------------------------------------------------------------------------
823 void AliD0toKpiAnalysis::SetD0Cuts(Double_t cut0,Double_t cut1,
824 Double_t cut2,Double_t cut3,Double_t cut4,
825 Double_t cut5,Double_t cut6,
826 Double_t cut7,Double_t cut8) {
827 // Set the cuts for D0 selection
840 //-----------------------------------------------------------------------------
841 void AliD0toKpiAnalysis::SetD0Cuts(const Double_t cuts[9]) {
842 // Set the cuts for D0 selection
844 for(Int_t i=0; i<9; i++) fD0Cuts[i] = cuts[i];
848 //-----------------------------------------------------------------------------
849 Bool_t AliD0toKpiAnalysis::SingleTrkCuts(const AliITStrackV2& trk) const {
850 // Check if track passes some kinematical cuts
852 if(TMath::Abs(1./trk.Get1Pt()) < fPtCut)
854 if(TMath::Abs(10000.*trk.GetD(fV1[0],fV1[1])) < fd0Cut)
859 //----------------------------------------------------------------------------
860 void AliD0toKpiAnalysis::MakeTracksRefFile(Int_t evFirst,Int_t evLast)
862 // Create a file with simulation info for the reconstructed tracks
864 TFile *out = TFile::Open("ITStracksRefFile.root","recreate");
865 TFile *trk = TFile::Open("AliITStracksV2.root");
866 AliRunLoader *rl = AliRunLoader::Open("galice.root");
869 rl->LoadKinematics();
876 for(Int_t ev=evFirst; ev<=evLast; ev++){
878 AliStack *stack = rl->Stack();
884 sprintf(tname,"TreeT_ITS_%d",ev);
886 TTree *tracktree=(TTree*)trk->Get(tname);
887 if(!tracktree) continue;
888 AliITStrackV2 *track = new AliITStrackV2;
889 tracktree->SetBranchAddress("tracks",&track);
890 Int_t nentr=(Int_t)tracktree->GetEntries();
892 // Tree for true track parameters
894 sprintf(ttname,"Tree_Ref_%d",ev);
895 TTree *reftree = new TTree(ttname,"Tree with true track params");
896 reftree->Branch("rectracks",&reftrk,"lab/I:pdg:mumlab:mumpdg:Vx/F:Vy:Vz:Px:Py:Pz");
898 for(Int_t i=0; i<nentr; i++) {
899 tracktree->GetEvent(i);
900 label = TMath::Abs(track->GetLabel());
902 part = (TParticle*)stack->Particle(label);
904 reftrk.pdg = part->GetPdgCode();
905 reftrk.mumlab = part->GetFirstMother();
906 if(part->GetFirstMother()>=0) {
907 mumpart = (TParticle*)stack->Particle(part->GetFirstMother());
908 reftrk.mumpdg = mumpart->GetPdgCode();
912 reftrk.Vx = part->Vx();
913 reftrk.Vy = part->Vy();
914 reftrk.Vz = part->Vz();
915 reftrk.Px = part->Px();
916 reftrk.Py = part->Py();
917 reftrk.Pz = part->Pz();
936 //----------------------------------------------------------------------------
937 void AliD0toKpiAnalysis::MakeTracksRefFileESD() const {
938 // Create a file with simulation info for the reconstructed tracks
940 TFile *outFile = TFile::Open("ITStracksRefFile.root","recreate");
941 TFile *esdFile = TFile::Open("AliESDs.root");
942 AliRunLoader *rl = AliRunLoader::Open("galice.root");
945 rl->LoadKinematics();
953 TIter next(esdFile->GetListOfKeys());
954 // loop on events in file
955 while ((key=(TKey*)next())!=0) {
956 AliESD *event=(AliESD*)key->ReadObj();
957 Int_t ev = (Int_t)event->GetEventNumber();
960 AliStack *stack = rl->Stack();
962 Int_t nentr=(Int_t)event->GetNumberOfTracks();
964 // Tree for true track parameters
966 sprintf(ttname,"Tree_Ref_%d",ev);
967 TTree *reftree = new TTree(ttname,"Tree with true track params");
968 reftree->Branch("rectracks",&reftrk,"lab/I:pdg:mumlab:mumpdg:Vx/F:Vy:Vz:Px:Py:Pz");
970 for(Int_t i=0; i<nentr; i++) {
971 AliESDtrack *esdtrack = (AliESDtrack*)event->GetTrack(i);
972 label = TMath::Abs(esdtrack->GetLabel());
974 part = (TParticle*)stack->Particle(label);
976 reftrk.pdg = part->GetPdgCode();
977 reftrk.mumlab = part->GetFirstMother();
978 if(part->GetFirstMother()>=0) {
979 mumpart = (TParticle*)stack->Particle(part->GetFirstMother());
980 reftrk.mumpdg = mumpart->GetPdgCode();
984 reftrk.Vx = part->Vx();
985 reftrk.Vy = part->Vy();
986 reftrk.Vz = part->Vz();
987 reftrk.Px = part->Px();
988 reftrk.Py = part->Py();
989 reftrk.Pz = part->Pz();
1008 //-----------------------------------------------------------------------------
1009 void AliD0toKpiAnalysis::SimulationInfo(TTree *treeD0in,TTree *treeD0out) const {
1010 // add pdg codes to candidate decay tracks (for sim)
1012 TString refFileName("ITStracksRefFile.root");
1013 if(fSim && gSystem->AccessPathName(refFileName.Data(),kFileExists)) {
1014 printf("AliD0toKpiAnalysis::SimulationInfo: no reference file found!\n");
1017 TFile *refFile = TFile::Open(refFileName.Data());
1019 Char_t refTreeName[100];
1021 Int_t pdg[2],mumpdg[2],mumlab[2];
1024 // read-in reference tree for event 0 (the only event for Pb-Pb)
1025 sprintf(refTreeName,"Tree_Ref_%d",0);
1026 TTree *refTree0 = (TTree*)refFile->Get(refTreeName);
1027 refTree0->SetBranchAddress("rectracks",&reftrk);
1029 AliD0toKpi *theD0 = 0;
1030 treeD0in->SetBranchAddress("D0toKpi",&theD0);
1031 treeD0out->Branch("D0toKpi","AliD0toKpi",&theD0,200000,0);
1033 Int_t entries = (Int_t)treeD0in->GetEntries();
1035 for(Int_t i=0; i<entries; i++) {
1036 if(i%100==0) printf(" done %d candidates of %d\n",i,entries);
1038 treeD0in->GetEvent(i);
1039 event = theD0->EventNo();
1041 if(event==0) { // always true for Pb-Pb (avoid to read-in tree every time)
1042 refTree0->GetEvent(theD0->GetTrkNum(0));
1043 pdg[0] = reftrk.pdg;
1044 mumpdg[0] = reftrk.mumpdg;
1045 mumlab[0] = reftrk.mumlab;
1046 refTree0->GetEvent(theD0->GetTrkNum(1));
1047 pdg[1] = reftrk.pdg;
1048 mumpdg[1] = reftrk.mumpdg;
1049 mumlab[1] = reftrk.mumlab;
1051 sprintf(refTreeName,"Tree_Ref_%d",event);
1052 TTree *refTree = (TTree*)refFile->Get(refTreeName);
1053 refTree->SetBranchAddress("rectracks",&reftrk);
1054 refTree->GetEvent(theD0->GetTrkNum(0));
1055 pdg[0] = reftrk.pdg;
1056 mumpdg[0] = reftrk.mumpdg;
1057 mumlab[0] = reftrk.mumlab;
1058 refTree->GetEvent(theD0->GetTrkNum(1));
1059 pdg[1] = reftrk.pdg;
1060 mumpdg[1] = reftrk.mumpdg;
1061 mumlab[1] = reftrk.mumlab;
1065 theD0->SetPdgCodes(pdg);
1066 theD0->SetMumPdgCodes(mumpdg);
1068 if(TMath::Abs(mumpdg[0])==421 && TMath::Abs(mumpdg[1])==421
1069 && mumlab[0]==mumlab[1]) theD0->SetSignal();
1071 if(!fOnlySignal || theD0->IsSignal()) treeD0out->Fill();