1 #if !defined(__CINT__) || defined(__MAKECINT__)
9 #include "TBenchmark.h"
10 #include "TStopwatch.h"
11 #include "TParticle.h"
14 #include "AliTPCtrack.h"
15 #include "AliSimDigits.h"
16 #include "AliTPCParam.h"
17 #include "TParticle.h"
19 #include "AliDetector.h"
20 #include "AliTrackReference.h"
34 #include "AliTPCComparisonMI.h"
35 #include "AliTPCParamSR.h"
36 #include "AliTracker.h"
37 #include "AliComplexCluster.h"
44 Bool_t ImportgAlice(TFile *file);
45 TFile* OpenAliceFile(char *fn, Bool_t importgAlice = kFALSE, char *mode = "read");
47 AliTPCParam * GetTPCParam(){
48 AliTPCParamSR * par = new AliTPCParamSR;
55 ////////////////////////////////////////////////////////////////////////
56 Bool_t ImportgAlice(TFile *file) {
57 // read in gAlice object from the file
58 gAlice = (AliRun*)file->Get("gAlice");
59 if (!gAlice) return kFALSE;
62 ////////////////////////////////////////////////////////////////////////
63 TFile* OpenAliceFile(char *fn, Bool_t importgAlice, char *mode) {
64 TFile *file = TFile::Open(fn,mode);
65 if (!file->IsOpen()) {
66 cerr<<"OpenAliceFile: cannot open file "<<fn<<" in mode "
70 if (!importgAlice) return file;
71 if (ImportgAlice(file)) return file;
74 ////////////////////////////////////////////////////////////////////////
76 //_____________________________________________________________________________
77 Float_t TPCBetheBloch(Float_t bg)
80 // Bethe-Bloch energy loss formula
82 const Double_t kp1=0.76176e-1;
83 const Double_t kp2=10.632;
84 const Double_t kp3=0.13279e-4;
85 const Double_t kp4=1.8631;
86 const Double_t kp5=1.9479;
88 Double_t dbg = (Double_t) bg;
90 Double_t beta = dbg/TMath::Sqrt(1.+dbg*dbg);
92 Double_t aa = TMath::Power(beta,kp4);
93 Double_t bb = TMath::Power(1./dbg,kp5);
95 bb=TMath::Log(kp3+bb);
97 return ((Float_t)((kp2-aa-bb)*kp1/aa));
104 ////////////////////////////////////////////////////////////////////////
105 AliTPCGenInfo::AliTPCGenInfo()
110 AliTPCGenInfo::~AliTPCGenInfo()
112 if (fReferences) delete fReferences;
115 ////////////////////////////////////////////////////////////////////////
117 ////////////////////////////////////////////////////////////////////////
119 // End of implementation of the class AliTPCGenInfo
121 ////////////////////////////////////////////////////////////////////////
125 ////////////////////////////////////////////////////////////////////////
130 ////////////////////////////////////////////////////////////////////////
131 digitRow & digitRow::operator=(const digitRow &digOld)
133 for (Int_t i = 0; i<kgRowBytes; i++) fDig[i] = digOld.fDig[i];
136 ////////////////////////////////////////////////////////////////////////
137 void digitRow::SetRow(Int_t row)
139 if (row >= 8*kgRowBytes) {
140 cerr<<"digitRow::SetRow: index "<<row<<" out of bounds."<<endl;
148 ////////////////////////////////////////////////////////////////////////
149 Bool_t digitRow::TestRow(Int_t row)
152 // return kTRUE if row is on
156 return TESTBIT(fDig[iC],iB);
158 ////////////////////////////////////////////////////////////////////////
159 Int_t digitRow::RowsOn(Int_t upto)
162 // returns number of rows with a digit
163 // count only rows less equal row number upto
166 for (Int_t i = 0; i<kgRowBytes; i++) {
167 for (Int_t j = 0; j < 8; j++) {
168 if (i*8+j > upto) return total;
169 if (TESTBIT(fDig[i],j)) total++;
174 ////////////////////////////////////////////////////////////////////////
175 void digitRow::Reset()
178 // resets all rows to zero
180 for (Int_t i = 0; i<kgRowBytes; i++) {
184 ////////////////////////////////////////////////////////////////////////
185 Int_t digitRow::Last()
188 // returns the last row number with a digit
189 // returns -1 if now digits
191 for (Int_t i = kgRowBytes-1; i>=0; i--) {
192 for (Int_t j = 7; j >= 0; j--) {
193 if TESTBIT(fDig[i],j) return i*8+j;
198 ////////////////////////////////////////////////////////////////////////
199 Int_t digitRow::First()
202 // returns the first row number with a digit
203 // returns -1 if now digits
205 for (Int_t i = 0; i<kgRowBytes; i++) {
206 for (Int_t j = 0; j < 8; j++) {
207 if (TESTBIT(fDig[i],j)) return i*8+j;
213 ////////////////////////////////////////////////////////////////////////
215 // end of implementation of a class digitRow
217 ////////////////////////////////////////////////////////////////////////
219 ////////////////////////////////////////////////////////////////////////
220 TPCFindGenTracks::TPCFindGenTracks()
222 fMCInfo = new AliTPCGenInfo;
223 fMCInfo->fReferences = new TClonesArray("AliTrackReference");
227 ////////////////////////////////////////////////////////////////////////
228 TPCFindGenTracks::TPCFindGenTracks(char * fnGalice, char* fnRes,
229 Int_t nEvents, Int_t firstEvent)
232 fFirstEventNr = firstEvent;
233 fEventNr = firstEvent;
237 fLoader = AliRunLoader::Open(fnGalice);
239 delete gAlice->GetRunLoader();
243 if (fLoader->LoadgAlice()){
244 cerr<<"Error occured while l"<<endl;
246 Int_t nall = fLoader->GetNumberOfEvents();
248 cerr<<"no events available"<<endl;
252 if (firstEvent+nEvents>nall) {
253 fEventNr = nall-firstEvent;
254 cerr<<"restricted number of events availaible"<<endl;
258 ////////////////////////////////////////////////////////////////////////
259 void TPCFindGenTracks::Reset()
264 fFnRes = "genTracks.root";
266 fContainerDigitRow = 0;
269 fReferenceIndex0 = 0;
270 fReferenceIndex1 = 0;
278 ////////////////////////////////////////////////////////////////////////
279 TPCFindGenTracks::~TPCFindGenTracks()
285 Int_t TPCFindGenTracks::SetIO()
289 CreateTreeGenTracks();
290 if (!fTreeGenTracks) return 1;
291 AliTracker::SetFieldFactor();
292 fParamTPC = GetTPCParam();
297 ////////////////////////////////////////////////////////////////////////
298 Int_t TPCFindGenTracks::SetIO(Int_t eventNr)
303 gAlice->GetEvent(eventNr);
304 fLoader->SetEventNumber(eventNr);
306 fLoader->LoadHeader();
307 fLoader->LoadKinematics();
308 fStack = fLoader->Stack();
310 fLoader->LoadTrackRefs();
311 fTreeTR = fLoader->TreeTR();
313 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
315 fTreeD = tpcl->TreeD();
320 ////////////////////////////////////////////////////////////////////////
321 Int_t TPCFindGenTracks::Exec(Int_t nEvents, Int_t firstEventNr)
324 fFirstEventNr = firstEventNr;
328 ////////////////////////////////////////////////////////////////////////
329 Int_t TPCFindGenTracks::Exec()
333 Int_t status =SetIO();
334 if (status>0) return status;
337 for (fEventNr = fFirstEventNr; fEventNr < fFirstEventNr+fNEvents;
340 fNParticles = fStack->GetNtrack();
341 fContainerDigitRow = new digitRow[fNParticles];
343 fReferences = new AliTrackReference[fgMaxTR];
344 fReferenceIndex0 = new Int_t[fNParticles];
345 fReferenceIndex1 = new Int_t[fNParticles];
347 for (Int_t i = 0; i<fNParticles; i++) {
348 fReferenceIndex0[i] = -1;
349 fReferenceIndex1[i] = -1;
352 cout<<"Start to process event "<<fEventNr<<endl;
353 cout<<"\tfNParticles = "<<fNParticles<<endl;
354 if (fDebug>2) cout<<"\tStart loop over TreeD"<<endl;
355 if (TreeDLoop()>0) return 1;
356 if (fDebug>2) cout<<"\tStart loop over TreeTR"<<endl;
357 if (TreeTRLoop()>0) return 1;
358 if (fDebug>2) cout<<"\tStart loop over TreeK"<<endl;
359 if (TreeKLoop()>0) return 1;
360 if (fDebug>2) cout<<"\tEnd loop over TreeK"<<endl;
362 delete [] fContainerDigitRow;
363 delete [] fReferences;
364 delete [] fReferenceIndex0;
365 delete [] fReferenceIndex1;
370 cerr<<"Exec finished"<<endl;
377 ////////////////////////////////////////////////////////////////////////
378 void TPCFindGenTracks::CreateTreeGenTracks()
380 fFileGenTracks = TFile::Open(fFnRes,"RECREATE");
381 if (!fFileGenTracks) {
382 cerr<<"Error in CreateTreeGenTracks: cannot open file "<<fFnRes<<endl;
385 fTreeGenTracks = new TTree("genTracksTree","genTracksTree");
389 fMCInfo = new AliTPCGenInfo;
390 fMCInfo->fReferences = new TClonesArray("AliTrackReference");
392 fTreeGenTracks->Branch("MC","AliTPCGenInfo",&fMCInfo);
394 fTreeGenTracks->Branch("fEventNr",&fEventNr,"fEventNr/I");
396 fTreeGenTracks->AutoSave();
398 ////////////////////////////////////////////////////////////////////////
399 void TPCFindGenTracks::CloseOutputFile()
401 if (!fFileGenTracks) {
402 cerr<<"File "<<fFnRes<<" not found as an open file."<<endl;
405 fFileGenTracks->cd();
406 fTreeGenTracks->Write();
407 delete fTreeGenTracks;
408 fFileGenTracks->Close();
409 delete fFileGenTracks;
413 ////////////////////////////////////////////////////////////////////////
414 Int_t TPCFindGenTracks::TreeKLoop()
417 // open the file with treeK
418 // loop over all entries there and save information about some tracks
421 AliStack * stack = fStack;
422 if (!stack) {cerr<<"Stack was not found!\n"; return 1;}
425 cout<<"There are "<<fNParticles<<" primary and secondary particles in event "
430 TParticlePDG *ppdg = 0;
433 // not all generators give primary vertex position. Take the vertex
434 // of the particle 0 as primary vertex.
435 TDatabasePDG pdg; //get pdg table
437 //thank you very much root for this
438 TBranch * br = fTreeGenTracks->GetBranch("MC");
440 TParticle *particle = stack->ParticleFromTreeK(0);
441 fVPrim[0] = particle->Vx();
442 fVPrim[1] = particle->Vy();
443 fVPrim[2] = particle->Vz();
444 for (Int_t iParticle = 0; iParticle < fNParticles; iParticle++) {
446 // load only particles with TR
447 if (fReferenceIndex0[iParticle]<0) continue;
448 //////////////////////////////////////////////////////////////////////
449 fMCInfo->fLabel = iParticle;
451 fMCInfo->fRow = (fContainerDigitRow[iParticle]);
452 fMCInfo->fRowsWithDigits = fMCInfo->fRow.RowsOn();
453 if (fMCInfo->fRowsWithDigits<10) continue;
454 fMCInfo->fRowsWithDigitsInn = fMCInfo->fRow.RowsOn(63); // 63 = number of inner rows
455 fMCInfo->fRowsTrackLength = fMCInfo->fRow.Last() - fMCInfo->fRow.First();
456 fMCInfo->fDigitsInSeed = 0;
457 if (fMCInfo->fRow.TestRow(seedRow11) && fMCInfo->fRow.TestRow(seedRow12))
458 fMCInfo->fDigitsInSeed = 1;
459 if (fMCInfo->fRow.TestRow(seedRow21) && fMCInfo->fRow.TestRow(seedRow22))
460 fMCInfo->fDigitsInSeed += 10;
464 fMCInfo->fParticle = *(stack->Particle(iParticle));
465 if (fMCInfo->fParticle.GetLastDaughter()>0&&fMCInfo->fParticle.GetLastDaughter()<fNParticles){
466 TParticle * dparticle0 = 0;
467 if (fMCInfo->fParticle.GetDaughter(0)>0) dparticle0 = stack->Particle(fMCInfo->fParticle.GetDaughter(0));
468 TParticle * dparticle1 = 0;
469 if (fMCInfo->fParticle.GetDaughter(1)>0) dparticle1 = stack->Particle(fMCInfo->fParticle.GetDaughter(1));
470 if ((dparticle1)&&(dparticle1->P()>0.15)) {
471 fMCInfo->fDecayCoord[0] = dparticle1->Vx();
472 fMCInfo->fDecayCoord[1] = dparticle1->Vy();
473 fMCInfo->fDecayCoord[2] = dparticle1->Vz();
476 fMCInfo->fDecayCoord[0]=1000000;
478 fMCInfo->fDecayCoord[0]=1000000;
479 fMCInfo->fParticle = *(stack->ParticleFromTreeK(iParticle));
483 fMCInfo->fLabel = iParticle;
484 fMCInfo->fVDist[0] = fMCInfo->fParticle.Vx()-fVPrim[0];
485 fMCInfo->fVDist[1] = fMCInfo->fParticle.Vy()-fVPrim[1];
486 fMCInfo->fVDist[2] = fMCInfo->fParticle.Vz()-fVPrim[2];
487 fMCInfo->fVDist[3] = TMath::Sqrt(fMCInfo->fVDist[0]*fMCInfo->fVDist[0]+
488 fMCInfo->fVDist[1]*fMCInfo->fVDist[1]+fMCInfo->fVDist[2]*fMCInfo->fVDist[2]);
491 Int_t index = fReferenceIndex0[iParticle];
492 AliTrackReference ref = fReferences[index];
493 // if (ref.GetTrack()!=iParticle)
494 // printf("problem2\n");
495 fMCInfo->fTrackRef = ref;
498 if (fMCInfo->fReferences !=0) delete fMCInfo->fReferences;
499 fMCInfo->fReferences =
500 new TClonesArray("AliTrackReference");
501 fMCInfo->fReferences->ExpandCreateFast(fReferenceIndex1[iParticle]-fReferenceIndex0[iParticle]+1);
503 for (Int_t i = fReferenceIndex0[iParticle];i<=fReferenceIndex1[iParticle];i++){
504 AliTrackReference ref = fReferences[i];
505 AliTrackReference *ref2 = (AliTrackReference*) fMCInfo->fReferences->At(rfindex);
506 if (ref.GetTrack()!=iParticle)
507 printf("problem5\n");
513 ipdg = fMCInfo->fParticle.GetPdgCode();
514 ppdg = pdg.GetParticle(ipdg);
515 // calculate primary ionization per cm
517 Float_t mass = ppdg->Mass();
518 Float_t p = TMath::Sqrt(fMCInfo->fTrackRef.Px()*fMCInfo->fTrackRef.Px()+
519 fMCInfo->fTrackRef.Py()*fMCInfo->fTrackRef.Py()+
520 fMCInfo->fTrackRef.Pz()*fMCInfo->fTrackRef.Pz());
522 // Float_t betagama = fMCInfo->fParticle.P()/mass;
523 Float_t betagama = p /mass;
524 fMCInfo->fPrim = TPCBetheBloch(betagama);
526 //////////////////////////////////////////////////////////////////////
527 br->SetAddress(&fMCInfo);
528 fTreeGenTracks->Fill();
531 fTreeGenTracks->AutoSave();
533 if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
541 ////////////////////////////////////////////////////////////////////////
542 Int_t TPCFindGenTracks::TreeDLoop()
545 // open the file with treeD
546 // loop over all entries there and save information about some tracks
549 Int_t nInnerSector = fParamTPC->GetNInnerSector();
551 // Int_t zero=fParamTPC->GetZeroSup();
552 Int_t zero=fParamTPC->GetZeroSup()+6;
555 //char treeDName[100];
556 //sprintf(treeDName,"TreeD_75x40_100x60_150x60_%d",fEventNr);
557 //TTree *treeD=(TTree*)fFileTreeD->Get(treeDName);
560 AliSimDigits digitsAddress, *digits=&digitsAddress;
561 fTreeD->GetBranch("Segment")->SetAddress(&digits);
563 Int_t sectorsByRows=(Int_t)fTreeD->GetEntries();
564 if (fDebug > 1) cout<<"\tsectorsByRows = "<<sectorsByRows<<endl;
565 for (Int_t i=0; i<sectorsByRows; i++) {
566 // for (Int_t i=5720; i<sectorsByRows; i++) {
567 if (!fTreeD->GetEvent(i)) continue;
569 fParamTPC->AdjustSectorRow(digits->GetID(),sec,row);
570 if (fDebug > 1) cout<<sec<<' '<<row<<" \r";
571 // cerr<<sec<<' '<<row<<endl;
573 // here I expect that upper sectors follow lower sectors
574 if (sec > nInnerSector) rowShift = fParamTPC->GetNRowLow();
576 //digits->ExpandTrackBuffer();
577 //Int_t *tracks = digits->GetTracks();
580 Int_t iRow=digits->CurrentRow();
581 Int_t iColumn=digits->CurrentColumn();
582 Short_t digitValue = digits->CurrentDigit();
583 // cout<<"Inner loop: sector, iRow, iColumn "
584 // <<sec<<" "<<iRow<<" "<<iColumn<<endl;
585 if (digitValue >= zero) {
587 for (Int_t j = 0; j<3; j++) {
588 label = digits->GetTrackID(iRow,iColumn,j);
589 //label = digits->GetTrackIDFast(iRow,iColumn,j);
591 if (label >= fNParticles) { //don't label from bakground event
594 if (label >= 0 && label <= fNParticles) {
595 // if (label >= 0 && label <= fDebug) {
597 cout<<"Inner loop: sector, iRow, iColumn, label, value, row "
599 <<iRow<<" "<<iColumn<<" "<<label<<" "<<digitValue
602 fContainerDigitRow[label].SetRow(row+rowShift);
606 } while (digits->Next());
609 if (fDebug > 2) cerr<<"end of TreeDLoop"<<endl;
615 ////////////////////////////////////////////////////////////////////////
616 Int_t TPCFindGenTracks::TreeTRLoop()
619 // loop over TrackReferences and store the first one for each track
622 TTree * treeTR = fTreeTR;
624 cerr<<"TreeTR not found"<<endl;
627 Int_t nPrimaries = (Int_t) treeTR->GetEntries();
628 if (fDebug > 1) cout<<"There are "<<nPrimaries<<" entries in TreeTR"<<endl;
631 TBranch *TPCBranchTR = treeTR->GetBranch("TPC");
633 cerr<<"TPC branch in TR not found"<<endl;
636 TClonesArray* TPCArrayTR = new TClonesArray("AliTrackReference");
637 TPCBranchTR->SetAddress(&TPCArrayTR);
642 for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++) {
643 TPCBranchTR->GetEntry(iPrimPart);
644 for (Int_t iTrackRef = 0; iTrackRef < TPCArrayTR->GetEntriesFast(); iTrackRef++) {
645 AliTrackReference *trackRef = (AliTrackReference*)TPCArrayTR->At(iTrackRef);
647 if (trackRef->Pt() < fgPtCut) continue;
648 Int_t label = trackRef->GetTrack();
649 if (label<0 || label > fNParticles) {
652 if (index>=fgMaxTR) continue; //restricted size of buffer for TR
653 fReferences[index] = *trackRef;
654 fReferenceIndex1[label] = index; // the last ref with given label
655 if (fReferenceIndex0[label]==-1) fReferenceIndex0[label] = index; //the first index with label
663 ////////////////////////////////////////////////////////////////////////
664 Float_t TPCFindGenTracks::TR2LocalX(AliTrackReference *trackRef,
665 AliTPCParam *paramTPC) {
667 Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
669 paramTPC->Transform0to1(x,index);
670 paramTPC->Transform1to2(x,index);
673 ////////////////////////////////////////////////////////////////////////
678 ////////////////////////////////////////////////////////////////////////
684 ////////////////////////////////////////////////////////////////////////
685 TPCCmpTr::TPCCmpTr(char* fnGenTracks,
688 Int_t nEvents, Int_t firstEvent)
691 fFnGenTracks = fnGenTracks;
693 fFirstEventNr = firstEvent;
694 fEventNr = firstEvent;
698 fLoader = AliRunLoader::Open(fnGalice);
700 delete gAlice->GetRunLoader();
704 if (fLoader->LoadgAlice()){
705 cerr<<"Error occured while l"<<endl;
707 Int_t nall = fLoader->GetNumberOfEvents();
709 cerr<<"no events available"<<endl;
713 if (firstEvent+nEvents>nall) {
714 fEventNr = nall-firstEvent;
715 cerr<<"restricted number of events availaible"<<endl;
719 //////////////////////////////////////////////////////////////
720 Int_t TPCCmpTr::SetIO()
725 if (!fTreeCmp) return 1;
726 AliTracker::SetFieldFactor();
727 fParamTPC = GetTPCParam();
729 if (!ConnectGenTree()) {
730 cerr<<"Cannot connect tree with generated tracks"<<endl;
736 //////////////////////////////////////////////////////////////
738 Int_t TPCCmpTr::SetIO(Int_t eventNr)
743 gAlice->GetEvent(eventNr);
744 fLoader->SetEventNumber(eventNr);
746 AliTPCLoader * tpcl = (AliTPCLoader*)fLoader->GetLoader("TPCLoader");
748 fTreeRecTracks = tpcl->TreeT();
755 ////////////////////////////////////////////////////////////////////////
756 void TPCCmpTr::Reset()
761 fFnCmp = "cmpTracks.root";
773 ////////////////////////////////////////////////////////////////////////
774 TPCCmpTr::~TPCCmpTr()
778 ////////////////////////////////////////////////////////////////////////
779 Int_t TPCCmpTr::Exec(Int_t nEvents, Int_t firstEventNr)
782 fFirstEventNr = firstEventNr;
786 ////////////////////////////////////////////////////////////////////////
787 Int_t TPCCmpTr::Exec()
795 fNextTreeGenEntryToRead = 0;
796 cerr<<"fFirstEventNr, fNEvents: "<<fFirstEventNr<<" "<<fNEvents<<endl;
797 for (Int_t eventNr = fFirstEventNr; eventNr < fFirstEventNr+fNEvents;
800 fNParticles = gAlice->GetEvent(fEventNr);
802 fIndexRecTracks = new Int_t[fNParticles*4]; //write at maximum 4 tracks corresponding to particle
803 fFakeRecTracks = new Int_t[fNParticles];
804 fMultiRecTracks = new Int_t[fNParticles];
805 for (Int_t i = 0; i<fNParticles; i++) {
806 fIndexRecTracks[4*i] = -1;
807 fIndexRecTracks[4*i+1] = -1;
808 fIndexRecTracks[4*i+2] = -1;
809 fIndexRecTracks[4*i+3] = -1;
811 fFakeRecTracks[i] = 0;
812 fMultiRecTracks[i] = 0;
815 cout<<"Start to process event "<<fEventNr<<endl;
816 cout<<"\tfNParticles = "<<fNParticles<<endl;
817 if (fDebug>2) cout<<"\tStart loop over TreeT"<<endl;
818 if (TreeTLoop(eventNr)>0) return 1;
820 if (fDebug>2) cout<<"\tStart loop over tree genTracks"<<endl;
821 if (TreeGenLoop(eventNr)>0) return 1;
822 if (fDebug>2) cout<<"\tEnd loop over tree genTracks"<<endl;
824 delete fTreeRecTracks;
825 delete [] fIndexRecTracks;
826 delete [] fFakeRecTracks;
827 delete [] fMultiRecTracks;
832 cerr<<"Exec finished"<<endl;
839 ////////////////////////////////////////////////////////////////////////
840 Bool_t TPCCmpTr::ConnectGenTree()
843 // connect all branches from the genTracksTree
844 // use the same variables as for the new cmp tree, it may work
846 fFileGenTracks = TFile::Open(fFnGenTracks,"READ");
847 if (!fFileGenTracks) {
848 cerr<<"Error in ConnectGenTree: cannot open file "<<fFnGenTracks<<endl;
851 fTreeGenTracks = (TTree*)fFileGenTracks->Get("genTracksTree");
852 if (!fTreeGenTracks) {
853 cerr<<"Error in ConnectGenTree: cannot find genTracksTree in the file "
854 <<fFnGenTracks<<endl;
858 fMCInfo = new AliTPCGenInfo;
859 fMCInfo->fReferences = new TClonesArray("AliTrackReference");
860 fTreeGenTracks->SetBranchAddress("MC",&fMCInfo);
863 //fTreeGenTracks->SetBranchAddress("fEventNr",&fEventNr);
867 cout<<"Number of gen. tracks with TR: "<<fTreeGenTracks->GetEntries()<<endl;
873 ////////////////////////////////////////////////////////////////////////
874 void TPCCmpTr::CreateTreeCmp()
876 fFileCmp = TFile::Open(fFnCmp,"RECREATE");
878 cerr<<"Error in CreateTreeCmp: cannot open file "<<fFnCmp<<endl;
883 fTreeCmp = new TTree("TPCcmpTracks","TPCcmpTracks");
885 fMCInfo = new AliTPCGenInfo;
886 fMCInfo->fReferences = new TClonesArray("AliTrackReference");
887 fRecInfo = new AliTPCRecInfo;
889 fTPCTrack = new AliTPCtrack;
891 fTreeCmp->Branch("MC","AliTPCGenInfo",&fMCInfo);
892 fTreeCmp->Branch("RC","AliTPCRecInfo",&fRecInfo);
893 fTreeCmp->Branch("fEventNr",&fEventNr,"fEventNr/I");
894 fTreeCmp->Branch("fTPCTrack","AliTPCtrack",&fTPCTrack);
896 fTreeCmp->AutoSave();
899 ////////////////////////////////////////////////////////////////////////
900 void TPCCmpTr::CloseOutputFile()
903 cerr<<"File "<<fFnCmp<<" not found as an open file."<<endl;
914 ////////////////////////////////////////////////////////////////////////
916 TVector3 TPCCmpTr::TR2Local(AliTrackReference *trackRef,
917 AliTPCParam *paramTPC) {
919 Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
921 paramTPC->Transform0to1(x,index);
922 paramTPC->Transform1to2(x,index);
925 ////////////////////////////////////////////////////////////////////////
927 Int_t TPCCmpTr::TreeTLoop(Int_t eventNr)
930 // loop over all TPC reconstructed tracks and store info in memory
934 if (!fTreeRecTracks) {
935 cerr<<"Can't get a tree with TPC rec. tracks "<<endl;
938 //fTreePoints=(TTree*)fFileRecTracks->Get("trackDebug");
940 Int_t nEntries = (Int_t) fTreeRecTracks->GetEntries();
941 if (fDebug > 2) cout<<"Event, rec. tracks: "<<eventNr<<" "
943 TBranch * br= fTreeRecTracks->GetBranch("tracks");
944 br->SetAddress(&fTPCTrack);
946 if (fTreePoints) brp = fTreePoints->GetBranch("debug");
953 fTrackPoints->Delete();
957 fTracks = new TObjArray(nEntries);
959 fTrackPoints = new TObjArray(nEntries);
961 else fTrackPoints = 0;
964 //load tracks to the memory
965 for (Int_t i=0; i<nEntries;i++){
966 AliTPCtrack * track = new AliTPCtrack;
967 br->SetAddress(&track);
969 fTracks->AddAt(track,i);
972 //load track points to the memory
973 if (brp) for (Int_t i=0; i<nEntries;i++){
974 TClonesArray * arr = new TClonesArray("AliTPCTrackPoint2");
975 brp->SetAddress(&arr);
978 for (Int_t j=0;j<arr->GetEntriesFast();j++){
979 AliTPCTrackPoint2 * point = (AliTPCTrackPoint2*)arr->UncheckedAt(j);
980 if (point && point->fID>=0){
981 fTrackPoints->AddAt(arr,point->fID);
989 for (Int_t iEntry=0; iEntry<nEntries;iEntry++){
990 //br->GetEntry(iEntry);
991 fTPCTrack = (AliTPCtrack*)fTracks->UncheckedAt(iEntry);
993 Int_t label = fTPCTrack->GetLabel();
994 Int_t absLabel = abs(label);
995 if (absLabel < fNParticles) {
996 // fIndexRecTracks[absLabel] = iEntry;
997 if (label < 0) fFakeRecTracks[absLabel]++;
999 if (fMultiRecTracks[absLabel]>0){
1000 if (fMultiRecTracks[absLabel]<4)
1001 fIndexRecTracks[absLabel*4+fMultiRecTracks[absLabel]] = iEntry;
1004 fIndexRecTracks[absLabel*4] = iEntry;
1005 fMultiRecTracks[absLabel]++;
1009 if (fDebug > 2) cerr<<"end of TreeTLoop"<<endl;
1013 ////////////////////////////////////////////////////////////////////////
1014 Int_t TPCCmpTr::TreeGenLoop(Int_t eventNr)
1017 // loop over all entries for a given event, find corresponding
1018 // rec. track and store in the fTreeCmp
1021 Int_t entry = fNextTreeGenEntryToRead;
1022 Double_t nParticlesTR = fTreeGenTracks->GetEntriesFast();
1023 cerr<<"fNParticles, nParticlesTR, fNextTreeGenEntryToRead: "<<fNParticles<<" "
1024 <<nParticlesTR<<" "<<fNextTreeGenEntryToRead<<endl;
1025 TBranch * branch = fTreeCmp->GetBranch("RC");
1026 while (entry < nParticlesTR) {
1027 fTreeGenTracks->GetEntry(entry);
1029 if (fEventNr < eventNr) continue;
1030 if (fEventNr > eventNr) break;
1031 fNextTreeGenEntryToRead = entry-1;
1032 if (fDebug > 2 && fMCInfo->fLabel < 10) {
1033 cerr<<"Fill track with a label "<<fMCInfo->fLabel<<endl;
1039 if (fIndexRecTracks[fMCInfo->fLabel*4] >= 0) {
1040 fTPCTrack= (AliTPCtrack*)fTracks->UncheckedAt(fIndexRecTracks[fMCInfo->fLabel*4]);
1042 // if (nBytes > 0) {
1045 TVector3 local = TR2Local(&(fMCInfo->fTrackRef),fParamTPC);
1046 local.GetXYZ(fRecInfo->fTRLocalCoord);
1048 // find nearest track if multifound
1049 if (fIndexRecTracks[fMCInfo->fLabel*4]+1){
1050 Float_t dz = TMath::Abs(local.Z()-fTPCTrack->GetZ());
1051 for (Int_t i=1;i<4;i++){
1052 if (fIndexRecTracks[fMCInfo->fLabel*4+i]>=0){
1053 AliTPCtrack * track = (AliTPCtrack*)fTracks->UncheckedAt(fIndexRecTracks[fMCInfo->fLabel*4+i]);
1054 if (TMath::Abs(local.Z()-track->GetZ())<dz)
1061 Int_t id = fTPCTrack->GetUniqueID();
1062 if (fTrackPoints->UncheckedAt(id)){
1063 fRecInfo->fTP = (TClonesArray*)fTrackPoints->UncheckedAt(id);
1064 // fTrackPoints->AddAt(0,id); //not owner anymore
1067 fRecInfo->fTPCTrack =*fTPCTrack;
1068 fRecInfo->fReconstructed = 1;
1069 fRecInfo->fFake = fFakeRecTracks[fMCInfo->fLabel];
1070 fRecInfo->fMultiple = fMultiRecTracks[fMCInfo->fLabel];
1071 fRecInfo->fdEdx = fTPCTrack->GetdEdx();
1073 fRecInfo->fTPCTrack.PropagateTo(local.X());
1076 Double_t localX = local.X();
1077 fTPCTrack->GetExternalParameters(localX,par);
1078 fRecInfo->fRecPhi=TMath::ASin(par[2]) + fTPCTrack->GetAlpha();
1079 if (fRecInfo->fRecPhi<0) fRecInfo->fRecPhi+=2*kPI;
1080 if (fRecInfo->fRecPhi>=2*kPI) fRecInfo->fRecPhi-=2*kPI;
1081 // fRecInfo->fRecPhi = (fRecInfo->fRecPhi)*kRaddeg;
1082 fRecInfo->fLambda = TMath::ATan(par[3]);
1083 fRecInfo->fRecPt_1 = TMath::Abs(par[4]);
1088 branch->SetAddress(&fRecInfo); // set all pointers
1092 fTreeCmp->AutoSave();
1096 fTrackPoints->Delete();
1097 delete fTrackPoints;
1100 if (fDebug > 2) cerr<<"end of TreeKLoop"<<endl;
1104 ////////////////////////////////////////////////////////////////////////