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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////
20 Origin: marian.ivanov@cern.ch
22 Generate complex MC information - used for Comparison later on
25 gSystem->Load("libPWG1.so")
26 AliGenInfoMaker *t = new AliGenInfoMaker("galice.root","genTracks.root",0,0)
31 #if !defined(__CINT__) || defined(__MAKECINT__)
42 #include "TStopwatch.h"
43 #include "TParticle.h"
46 #include "TGeometry.h"
47 #include "TPolyLine3D.h"
52 #include "AliSimDigits.h"
53 #include "AliTPCParam.h"
55 #include "AliTPCLoader.h"
56 #include "AliDetector.h"
57 #include "AliTrackReference.h"
58 #include "AliTPCParamSR.h"
59 #include "AliTracker.h"
62 #include "AliTrackPointArray.h"
65 #include "AliMCInfo.h"
66 #include "AliGenV0Info.h"
67 #include "AliGenKinkInfo.h"
68 #include "AliGenInfoMaker.h"
72 ClassImp(AliGenInfoMaker)
80 ////////////////////////////////////////////////////////////////////////
81 AliGenInfoMaker::AliGenInfoMaker():
82 fDebug(0), //! debug flag
83 fEventNr(0), //! current event number
84 fLabel(0), //! track label
85 fNEvents(0), //! number of events to process
86 fFirstEventNr(0), //! first event to process
87 fNParticles(0), //! number of particles in TreeK
88 fTreeGenTracks(0), //! output tree with generated tracks
89 fTreeKinks(0), //! output tree with Kinks
90 fTreeV0(0), //! output tree with V0
91 fTreeHitLines(0), //! tree with hit lines
92 fFileGenTracks(0), //! output file with stored fTreeGenTracks
93 fLoader(0), //! pointer to the run loader
94 fTreeD(0), //! current tree with digits
95 fTreeTR(0), //! current tree with TR
96 fStack(0), //! current stack
97 fGenInfo(0), //! array with pointers to gen info
98 fNInfos(0), //! number of tracks with infos
99 fParamTPC(0), //! AliTPCParam
107 ////////////////////////////////////////////////////////////////////////
108 AliGenInfoMaker::AliGenInfoMaker(const char * fnGalice, const char* fnRes,
109 Int_t nEvents, Int_t firstEvent):
110 fDebug(0), //! debug flag
111 fEventNr(0), //! current event number
112 fLabel(0), //! track label
113 fNEvents(0), //! number of events to process
114 fFirstEventNr(0), //! first event to process
115 fNParticles(0), //! number of particles in TreeK
116 fTreeGenTracks(0), //! output tree with generated tracks
117 fTreeKinks(0), //! output tree with Kinks
118 fTreeV0(0), //! output tree with V0
119 fTreeHitLines(0), //! tree with hit lines
120 fFileGenTracks(0), //! output file with stored fTreeGenTracks
121 fLoader(0), //! pointer to the run loader
122 fTreeD(0), //! current tree with digits
123 fTreeTR(0), //! current tree with TR
124 fStack(0), //! current stack
125 fGenInfo(0), //! array with pointers to gen info
126 fNInfos(0), //! number of tracks with infos
127 fParamTPC(0), //! AliTPCParam
137 fFirstEventNr = firstEvent;
138 fEventNr = firstEvent;
140 sprintf(fFnRes,"%s",fnRes);
142 fLoader = AliRunLoader::Open(fnGalice);
144 delete gAlice->GetRunLoader();
148 if (fLoader->LoadgAlice()){
149 cerr<<"Error occured while l"<<endl;
151 Int_t nall = fLoader->GetNumberOfEvents();
159 cerr<<"no events available"<<endl;
163 if (firstEvent+nEvents>nall) {
164 fEventNr = nall-firstEvent;
165 cerr<<"restricted number of events availaible"<<endl;
167 AliMagF * magf = gAlice->Field();
168 AliTracker::SetFieldMap(magf,0);
172 AliMCInfo * AliGenInfoMaker::MakeInfo(UInt_t i)
176 if (fGenInfo[i]) return fGenInfo[i];
177 fGenInfo[i] = new AliMCInfo;
185 ////////////////////////////////////////////////////////////////////////
186 AliGenInfoMaker::~AliGenInfoMaker()
190 fLoader->UnloadgAlice();
196 Int_t AliGenInfoMaker::SetIO()
200 CreateTreeGenTracks();
201 if (!fTreeGenTracks) return 1;
202 // AliTracker::SetFieldFactor();
204 fParamTPC = GetTPCParam();
209 ////////////////////////////////////////////////////////////////////////
210 Int_t AliGenInfoMaker::SetIO(Int_t eventNr)
215 fLoader->SetEventNumber(eventNr);
217 fLoader->LoadHeader();
218 fLoader->LoadKinematics();
219 fStack = fLoader->Stack();
221 fLoader->LoadTrackRefs();
223 fTreeTR = fLoader->TreeTR();
225 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
227 fTreeD = tpcl->TreeD();
231 Int_t AliGenInfoMaker::CloseIOEvent()
233 fLoader->UnloadHeader();
234 fLoader->UnloadKinematics();
235 fLoader->UnloadTrackRefs();
236 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
237 tpcl->UnloadDigits();
241 Int_t AliGenInfoMaker::CloseIO()
243 fLoader->UnloadgAlice();
249 ////////////////////////////////////////////////////////////////////////
250 Int_t AliGenInfoMaker::Exec(Int_t nEvents, Int_t firstEventNr)
253 fFirstEventNr = firstEventNr;
257 ////////////////////////////////////////////////////////////////////////
258 Int_t AliGenInfoMaker::Exec()
262 Int_t status =SetIO();
263 if (status>0) return status;
266 for (fEventNr = fFirstEventNr; fEventNr < fFirstEventNr+fNEvents;
269 fNParticles = fStack->GetNtrack();
271 fGenInfo = new AliMCInfo*[fNParticles];
272 for (UInt_t i = 0; i<fNParticles; i++) {
276 cout<<"Start to process event "<<fEventNr<<endl;
277 cout<<"\tfNParticles = "<<fNParticles<<endl;
278 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeTR"<<endl;
279 if (TreeTRLoop()>0) return 1;
281 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeD"<<endl;
282 if (TreeDLoop()>0) return 1;
284 if (fDebug>2) cout<<"\n\n\n\tStart loop over TreeK"<<endl;
285 if (TreeKLoop()>0) return 1;
286 if (fDebug>2) cout<<"\tEnd loop over TreeK"<<endl;
288 if (BuildKinkInfo()>0) return 1;
289 if (BuildV0Info()>0) return 1;
290 //if (BuildHitLines()>0) return 1;
291 if (fDebug>2) cout<<"\tEnd loop over TreeK"<<endl;
293 for (UInt_t i = 0; i<fNParticles; i++) {
294 if (fGenInfo[i]) delete fGenInfo[i];
303 cerr<<"Exec finished"<<endl;
310 ////////////////////////////////////////////////////////////////////////
311 void AliGenInfoMaker::CreateTreeGenTracks()
313 fFileGenTracks = TFile::Open(fFnRes,"RECREATE");
314 if (!fFileGenTracks) {
315 cerr<<"Error in CreateTreeGenTracks: cannot open file "<<fFnRes<<endl;
318 fTreeGenTracks = new TTree("genTracksTree","genTracksTree");
319 AliMCInfo * info = new AliMCInfo;
320 fTreeGenTracks->Branch("MC","AliMCInfo",&info);
323 AliGenKinkInfo *kinkinfo = new AliGenKinkInfo;
324 fTreeKinks = new TTree("genKinksTree","genKinksTree");
325 fTreeKinks->Branch("MC","AliGenKinkInfo",&kinkinfo);
328 AliGenV0Info *v0info = new AliGenV0Info;
329 fTreeV0 = new TTree("genV0Tree","genV0Tree");
330 fTreeV0->Branch("MC","AliGenV0Info",&v0info);
334 AliTrackPointArray * points0 = new AliTrackPointArray;
335 AliTrackPointArray * points1 = new AliTrackPointArray;
336 AliTrackPointArray * points2 = new AliTrackPointArray;
337 fTreeHitLines = new TTree("HitLines","HitLines");
338 fTreeHitLines->Branch("TPC.","AliTrackPointArray",&points0,32000,10);
339 fTreeHitLines->Branch("TRD.","AliTrackPointArray",&points1,32000,10);
340 fTreeHitLines->Branch("ITS.","AliTrackPointArray",&points2,32000,10);
342 fTreeHitLines->Branch("Label",&label,"label/I");
344 fTreeGenTracks->AutoSave();
345 fTreeKinks->AutoSave();
347 fTreeHitLines->AutoSave();
349 ////////////////////////////////////////////////////////////////////////
350 void AliGenInfoMaker::CloseOutputFile()
352 if (!fFileGenTracks) {
353 cerr<<"File "<<fFnRes<<" not found as an open file."<<endl;
356 fFileGenTracks->cd();
357 fTreeGenTracks->Write();
358 delete fTreeGenTracks;
364 fFileGenTracks->Close();
365 delete fFileGenTracks;
369 ////////////////////////////////////////////////////////////////////////
370 Int_t AliGenInfoMaker::TreeKLoop()
373 // open the file with treeK
374 // loop over all entries there and save information about some tracks
377 AliStack * stack = fStack;
378 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
381 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
385 TParticlePDG *ppdg = 0;
386 // not all generators give primary vertex position. Take the vertex
387 // of the particle 0 as primary vertex.
388 TDatabasePDG pdg; //get pdg table
389 //thank you very much root for this
390 TBranch * br = fTreeGenTracks->GetBranch("MC");
391 TParticle *particle = stack->ParticleFromTreeK(0);
392 fVPrim[0] = particle->Vx();
393 fVPrim[1] = particle->Vy();
394 fVPrim[2] = particle->Vz();
395 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
396 // load only particles with TR
397 AliMCInfo * info = GetInfo(iParticle);
399 //////////////////////////////////////////////////////////////////////
400 info->fLabel = iParticle;
402 info->fParticle = *(stack->Particle(iParticle));
403 info->fVDist[0] = info->fParticle.Vx()-fVPrim[0];
404 info->fVDist[1] = info->fParticle.Vy()-fVPrim[1];
405 info->fVDist[2] = info->fParticle.Vz()-fVPrim[2];
406 info->fVDist[3] = TMath::Sqrt(info->fVDist[0]*info->fVDist[0]+
407 info->fVDist[1]*info->fVDist[1]+info->fVDist[2]*info->fVDist[2]);
410 ipdg = info->fParticle.GetPdgCode();
412 ppdg = pdg.GetParticle(ipdg);
413 info->fEventNr = fEventNr;
415 //////////////////////////////////////////////////////////////////////
416 br->SetAddress(&info);
417 fTreeGenTracks->Fill();
419 fTreeGenTracks->AutoSave();
420 if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
425 ////////////////////////////////////////////////////////////////////////////////////
426 Int_t AliGenInfoMaker::BuildKinkInfo()
429 // Build tree with Kink Information
431 AliStack * stack = fStack;
432 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
435 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
439 //TParticlePDG *ppdg = 0;
440 // not all generators give primary vertex position. Take the vertex
441 // of the particle 0 as primary vertex.
442 TDatabasePDG pdg; //get pdg table
443 //thank you very much root for this
444 TBranch * br = fTreeKinks->GetBranch("MC");
446 AliGenKinkInfo * kinkinfo = new AliGenKinkInfo;
448 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
449 // load only particles with TR
450 AliMCInfo * info = GetInfo(iParticle);
452 if (info->fCharge==0) continue;
453 if (info->fTRdecay.P()<0.13) continue; //momenta cut
454 if (info->fTRdecay.R()>500) continue; //R cut - decay outside barrel
455 TParticle & particle = info->fParticle;
456 Int_t first = particle.GetDaughter(0);
457 if (first ==0) continue;
459 Int_t last = particle.GetDaughter(1);
460 if (last ==0) last=first;
461 AliMCInfo * info2 = 0;
462 AliMCInfo * dinfo = 0;
464 for (Int_t id2=first;id2<=last;id2++){
465 info2 = GetInfo(id2);
466 if (!info2) continue;
467 TParticle &p2 = info2->fParticle;
468 Double_t r = TMath::Sqrt(p2.Vx()*p2.Vx()+p2.Vy()*p2.Vy());
469 if ( TMath::Abs(info->fTRdecay.R()-r)>0.01) continue;
470 if (!(p2.GetPDG())) continue;
473 kinkinfo->SetInfoMother(*info);
474 kinkinfo->SetInfoDaughter(*dinfo);
475 if (kinkinfo->GetMinus().GetParticle().GetPDG()==0 || kinkinfo->GetPlus().GetParticle().GetPDG()==0) continue;
477 br->SetAddress(&kinkinfo);
482 kinkinfo->fMCm = (*info);
483 kinkinfo->GetPlus() = (*dinfo);
485 br->SetAddress(&kinkinfo);
490 fTreeGenTracks->AutoSave();
491 if (fDebug > 2) cerr<<"end of Kink Loop"<<endl;
496 ////////////////////////////////////////////////////////////////////////////////////
497 Int_t AliGenInfoMaker::BuildV0Info()
500 // Build tree with V0 Information
502 AliStack * stack = fStack;
503 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
506 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
510 //TParticlePDG *ppdg = 0;
511 // not all generators give primary vertex position. Take the vertex
512 // of the particle 0 as primary vertex.
513 TDatabasePDG pdg; //get pdg table
514 //thank you very much root for this
515 TBranch * br = fTreeV0->GetBranch("MC");
517 AliGenV0Info * v0info = new AliGenV0Info;
520 for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
521 // load only particles with TR
522 AliMCInfo * info = GetInfo(iParticle);
524 if (info->fCharge==0) continue;
527 TParticle & particle = info->fParticle;
528 Int_t mother = particle.GetMother(0);
529 if (mother <=0) continue;
531 TParticle * motherparticle = stack->Particle(mother);
532 if (!motherparticle) continue;
534 Int_t last = motherparticle->GetDaughter(1);
535 if (last==(int)iParticle) continue;
536 AliMCInfo * info2 = info;
537 AliMCInfo * dinfo = GetInfo(last);
538 if (!dinfo) continue;
539 if (!dinfo->fParticle.GetPDG()) continue;
540 if (!info2->fParticle.GetPDG()) continue;
542 v0info->SetInfoP(*info);
543 v0info->SetInfoM(*dinfo);
544 v0info->SetMother(*motherparticle);
545 v0info->Update(fVPrim);
546 br->SetAddress(&v0info);
551 if (fDebug > 2) cerr<<"end of V0 Loop"<<endl;
558 ////////////////////////////////////////////////////////////////////////
559 Int_t AliGenInfoMaker::BuildHitLines()
563 // open the file with treeK
564 // loop over all entries there and save information about some tracks
567 AliStack * stack = fStack;
568 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
571 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
575 // // TParticlePDG *ppdg = 0;
576 // // not all generators give primary vertex position. Take the vertex
577 // // of the particle 0 as primary vertex.
578 // TDatabasePDG pdg; //get pdg table
579 // //thank you very much root for this
580 // AliTrackPointArray *tpcp = new AliTrackPointArray;
581 // AliTrackPointArray *trdp = new AliTrackPointArray;
582 // AliTrackPointArray *itsp = new AliTrackPointArray;
585 // TBranch * brtpc = fTreeHitLines->GetBranch("TPC.");
586 // TBranch * brtrd = fTreeHitLines->GetBranch("TRD.");
587 // TBranch * brits = fTreeHitLines->GetBranch("ITS.");
588 // TBranch * brlabel = fTreeHitLines->GetBranch("Label");
589 // brlabel->SetAddress(&label);
590 // brtpc->SetAddress(&tpcp);
591 // brtrd->SetAddress(&trdp);
592 // brits->SetAddress(&itsp);
594 // AliDetector *dtpc = gAlice->GetDetector("TPC");
595 // AliDetector *dtrd = gAlice->GetDetector("TRD");
596 // AliDetector *dits = gAlice->GetDetector("ITS");
598 // for (UInt_t iParticle = 0; iParticle < fNParticles; iParticle++) {
599 // // load only particles with TR
600 // AliMCInfo * info = GetInfo(iParticle);
601 // if (!info) continue;
602 // Int_t primpart = info->fPrimPart;
603 // ipdg = info->fParticle.GetPdgCode();
604 // label = iParticle;
606 // gAlice->ResetHits();
610 // tpcp->fLabel1 = ipdg;
611 // trdp->fLabel1 = ipdg;
612 // itsp->fLabel1 = ipdg;
613 // if (dtpc->TreeH()->GetEvent(primpart)){
614 // dtpc->LoadPoints(primpart);
615 // tpcp->Reset(dtpc,iParticle);
617 // if (dtrd->TreeH()->GetEvent(primpart)){
618 // dtrd->LoadPoints(primpart);
619 // trdp->Reset(dtrd,iParticle);
621 // if (dits->TreeH()->GetEvent(primpart)){
622 // dits->LoadPoints(primpart);
623 // itsp->Reset(dits,iParticle);
626 // fTreeHitLines->Fill();
627 // dtpc->ResetPoints();
628 // dtrd->ResetPoints();
629 // dits->ResetPoints();
634 // fTreeHitLines->AutoSave();
635 // if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
640 ////////////////////////////////////////////////////////////////////////
641 Int_t AliGenInfoMaker::TreeDLoop()
644 // open the file with treeD
645 // loop over all entries there and save information about some tracks
648 Int_t nInnerSector = fParamTPC->GetNInnerSector();
650 Int_t zero=fParamTPC->GetZeroSup()+6;
653 AliSimDigits digitsAddress, *digits=&digitsAddress;
654 fTreeD->GetBranch("Segment")->SetAddress(&digits);
656 Int_t sectorsByRows=(Int_t)fTreeD->GetEntries();
657 if (fDebug > 1) cout<<"\tsectorsByRows = "<<sectorsByRows<<endl;
658 for (Int_t i=0; i<sectorsByRows; i++) {
659 if (!fTreeD->GetEvent(i)) continue;
661 fParamTPC->AdjustSectorRow(digits->GetID(),sec,row);
662 if (fDebug > 1) cout<<sec<<' '<<row<<" \r";
663 // here I expect that upper sectors follow lower sectors
664 if (sec > nInnerSector) rowShift = fParamTPC->GetNRowLow();
666 digits->ExpandTrackBuffer();
669 Int_t iRow=digits->CurrentRow();
670 Int_t iColumn=digits->CurrentColumn();
671 Short_t digitValue = digits->CurrentDigit();
672 if (digitValue >= zero) {
674 for (Int_t j = 0; j<3; j++) {
675 // label = digits->GetTrackID(iRow,iColumn,j);
676 label = digits->GetTrackIDFast(iRow,iColumn,j)-2;
677 if (label >= (Int_t)fNParticles) { //don't label from bakground event
680 if (label >= 0 && label <= (Int_t)fNParticles) {
682 cout<<"Inner loop: sector, iRow, iColumn, label, value, row "
684 <<iRow<<" "<<iColumn<<" "<<label<<" "<<digitValue
687 AliMCInfo * info = GetInfo(label);
689 info->fTPCRow.SetRow(row+rowShift);
694 } while (digits->Next());
697 if (fDebug > 2) cerr<<"end of TreeDLoop"<<endl;
702 ////////////////////////////////////////////////////////////////////////
703 Int_t AliGenInfoMaker::TreeTRLoop()
706 // loop over TrackReferences and store the first one for each track
708 TTree * treeTR = fTreeTR;
709 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
710 if (fDebug > 1) cout<<"There are "<<nPrimaries<<" entries in TreeTR"<<endl;
713 //track references for TPC
714 TClonesArray* tpcArrayTR = new TClonesArray("AliTrackReference");
715 TClonesArray* itsArrayTR = new TClonesArray("AliTrackReference");
716 TClonesArray* trdArrayTR = new TClonesArray("AliTrackReference");
717 TClonesArray* tofArrayTR = new TClonesArray("AliTrackReference");
718 TClonesArray* runArrayTR = new TClonesArray("AliTrackReference");
720 if (treeTR->GetBranch("TPC")) treeTR->GetBranch("TPC")->SetAddress(&tpcArrayTR);
721 if (treeTR->GetBranch("ITS")) treeTR->GetBranch("ITS")->SetAddress(&itsArrayTR);
722 if (treeTR->GetBranch("TRD")) treeTR->GetBranch("TRD")->SetAddress(&trdArrayTR);
723 if (treeTR->GetBranch("TOF")) treeTR->GetBranch("TOF")->SetAddress(&tofArrayTR);
724 if (treeTR->GetBranch("AliRun")) treeTR->GetBranch("AliRun")->SetAddress(&runArrayTR);
728 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
729 treeTR->GetEntry(iPrimPart);
731 // Loop over TPC references
733 for (Int_t iTrackRef = 0; iTrackRef < tpcArrayTR->GetEntriesFast(); iTrackRef++) {
734 AliTrackReference *trackRef = (AliTrackReference*)tpcArrayTR->At(iTrackRef);
736 if (trackRef->TestBit(BIT(2))){
738 if (trackRef->P()<fTPCPtCut) continue;
739 Int_t label = trackRef->GetTrack();
740 AliMCInfo * info = GetInfo(label);
741 if (!info) info = MakeInfo(label);
742 info->fTRdecay = *trackRef;
745 if (trackRef->P()<fTPCPtCut) continue;
746 Int_t label = trackRef->GetTrack();
747 AliMCInfo * info = GetInfo(label);
748 if (!info) info = MakeInfo(label);
750 info->fPrimPart = iPrimPart;
751 TClonesArray & arr = *(info->fTPCReferences);
752 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
755 // Loop over ITS references
757 for (Int_t iTrackRef = 0; iTrackRef < itsArrayTR->GetEntriesFast(); iTrackRef++) {
758 AliTrackReference *trackRef = (AliTrackReference*)itsArrayTR->At(iTrackRef);
761 if (trackRef->P()<fTPCPtCut) continue;
762 Int_t label = trackRef->GetTrack();
763 AliMCInfo * info = GetInfo(label);
764 if ( (!info) && trackRef->Pt()<fITSPtCut) continue;
765 if (!info) info = MakeInfo(label);
767 info->fPrimPart = iPrimPart;
768 TClonesArray & arr = *(info->fITSReferences);
769 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
772 // Loop over TRD references
774 for (Int_t iTrackRef = 0; iTrackRef < trdArrayTR->GetEntriesFast(); iTrackRef++) {
775 AliTrackReference *trackRef = (AliTrackReference*)trdArrayTR->At(iTrackRef);
777 if (trackRef->P()<fTRDPtCut) continue;
778 Int_t label = trackRef->GetTrack();
779 AliMCInfo * info = GetInfo(label);
780 if ( (!info) && trackRef->Pt()<fTRDPtCut) continue;
781 if (!info) info = MakeInfo(label);
783 info->fPrimPart = iPrimPart;
784 TClonesArray & arr = *(info->fTRDReferences);
785 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
788 // Loop over TOF references
790 for (Int_t iTrackRef = 0; iTrackRef < tofArrayTR->GetEntriesFast(); iTrackRef++) {
791 AliTrackReference *trackRef = (AliTrackReference*)tofArrayTR->At(iTrackRef);
792 Int_t label = trackRef->GetTrack();
793 AliMCInfo * info = GetInfo(label);
795 if (trackRef->Pt()<fTPCPtCut) continue;
796 if ( (!info) && trackRef->Pt()<fTOFPtCut) continue;
798 if (!info) info = MakeInfo(label);
800 info->fPrimPart = iPrimPart;
801 TClonesArray & arr = *(info->fTOFReferences);
802 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
806 // get dacay position
808 for (Int_t iTrackRef = 0; iTrackRef < runArrayTR->GetEntriesFast(); iTrackRef++) {
809 AliTrackReference *trackRef = (AliTrackReference*)runArrayTR->At(iTrackRef);
811 Int_t label = trackRef->GetTrack();
812 AliMCInfo * info = GetInfo(label);
814 if (!trackRef->TestBit(BIT(2))) continue; //if not decay
815 // if (TMath::Abs(trackRef.X());
816 info->fTRdecay = *trackRef;
820 tpcArrayTR->Delete();
822 trdArrayTR->Delete();
824 tofArrayTR->Delete();
826 itsArrayTR->Delete();
828 runArrayTR->Delete();
831 return TreeTRLoopNew();
838 ////////////////////////////////////////////////////////////////////////
839 Int_t AliGenInfoMaker::TreeTRLoopNew()
842 // loop over TrackReferences and store the first one for each track
844 TTree * treeTR = fTreeTR;
845 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
846 if (fDebug > 1) cout<<"There are "<<nPrimaries<<" entries in TreeTR"<<endl;
850 TClonesArray* runArrayTR = new TClonesArray("AliTrackReference");
852 if (treeTR->GetBranch("TrackReferences")) treeTR->GetBranch("TrackReferences")->SetAddress(&runArrayTR);
856 for (Int_t ipart = 0; ipart<fStack->GetNtrack(); ipart++) {
857 TParticle * part = fStack->Particle(ipart);
859 if (part->Pt()<fITSPtCut) continue;
860 if (part->R()>250.) continue;
861 if (TMath::Abs(part->Vz())>250.) continue;
862 if (TMath::Abs(part->Pz()/part->Pt())>2.5) continue;
868 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
869 treeTR->GetEntry(iPrimPart);
871 // gettrack references
873 for (Int_t iTrackRef = 0; iTrackRef < runArrayTR->GetEntriesFast(); iTrackRef++) {
874 AliTrackReference *trackRef = (AliTrackReference*)runArrayTR->At(iTrackRef);
876 Int_t label = trackRef->GetTrack();
880 if (trackRef->DetectorId()== AliTrackReference::kTPC){
882 Int_t label = trackRef->GetTrack();
883 AliMCInfo * info = GetInfo(label);
884 if (!info && trackRef->Pt()<fTPCPtCut) continue;
885 if (!info) info = MakeInfo(label);
887 info->fPrimPart = iPrimPart;
888 TClonesArray & arr = *(info->fTPCReferences);
889 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
894 if (trackRef->DetectorId()== AliTrackReference::kITS){
896 Int_t label = trackRef->GetTrack();
897 AliMCInfo * info = GetInfo(label);
898 if (!info && trackRef->Pt()<fITSPtCut) continue;
899 if (!info) info = MakeInfo(label);
901 info->fPrimPart = iPrimPart;
902 TClonesArray & arr = *(info->fITSReferences);
903 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
908 if (trackRef->DetectorId()== AliTrackReference::kTRD){
910 Int_t label = trackRef->GetTrack();
911 AliMCInfo * info = GetInfo(label);
912 if (!info&&trackRef->P()<fTRDPtCut) continue;
913 if (!info) info = MakeInfo(label);
915 info->fPrimPart = iPrimPart;
916 TClonesArray & arr = *(info->fTRDReferences);
917 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
922 if (trackRef->DetectorId()== AliTrackReference::kTOF){
924 Int_t label = trackRef->GetTrack();
925 AliMCInfo * info = GetInfo(label);
926 if (!info&&trackRef->P()<fTOFPtCut) continue;
927 if (!info) info = MakeInfo(label);
929 info->fPrimPart = iPrimPart;
930 TClonesArray & arr = *(info->fTOFReferences);
931 new (arr[arr.GetEntriesFast()]) AliTrackReference(*trackRef);
936 if (trackRef->DetectorId()== AliTrackReference::kDisappeared){
938 AliMCInfo * info = GetInfo(label);
940 //if (!trackRef->TestBit(BIT(2))) continue; //if not decay
941 info->fTRdecay = *trackRef;
951 ////////////////////////////////////////////////////////////////////////
952 Float_t AliGenInfoMaker::TR2LocalX(AliTrackReference *trackRef,
953 AliTPCParam *paramTPC) const {
955 Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
957 paramTPC->Transform0to1(x,index);
958 paramTPC->Transform1to2(x,index);
961 ////////////////////////////////////////////////////////////////////////
965 AliTPCParam * AliGenInfoMaker::GetTPCParam(){
966 AliTPCParamSR * par = new AliTPCParamSR;