2 #include <TDatabasePDG.h>
9 #include <AliExternalTrackParam.h>
10 #include <AliTPCcalibDB.h>
11 #include <AliTPCclusterMI.h>
12 #include <AliTPCCorrection.h>
13 #include <AliTrackerBase.h>
14 #include <AliTrackPointArray.h>
16 #include <AliTPCParam.h>
17 #include <AliTPCROC.h>
18 #include <TTreeStream.h>
19 #include <AliTPCReconstructor.h>
20 #include <AliTPCTransform.h>
21 #include <AliTPCseed.h>
22 #include <AliTPCtracker.h>
23 #include <AliTPCtrackerSector.h>
24 #include <AliRieman.h>
26 #include "AliToyMCTrack.h"
27 #include "AliToyMCEvent.h"
29 #include "AliToyMCReconstruction.h"
37 //____________________________________________________________________________________
38 AliToyMCReconstruction::AliToyMCReconstruction() : TObject()
42 , fCorrectionType(kNoCorrection)
44 , fUseMaterial(kFALSE)
45 , fIdealTracking(kFALSE)
48 , fCreateT0seed(kFALSE)
50 , fFillClusterRes(kFALSE)
57 , fkNSectorInner(18) // hard-coded to avoid loading the parameters before
58 , fInnerSectorArray(0x0)
59 , fkNSectorOuter(18) // hard-coded to avoid loading the parameters before
60 , fOuterSectorArray(0x0)
61 , fAllClusters("AliTPCclusterMI",10000)
62 , fMapTrackEvent(10000)
63 , fMapTrackTrackInEvent(10000)
69 fTPCParam=AliTPCcalibDB::Instance()->GetParameters();
73 //____________________________________________________________________________________
74 AliToyMCReconstruction::~AliToyMCReconstruction()
83 //____________________________________________________________________________________
84 void AliToyMCReconstruction::RunReco(const char* file, Int_t nmaxEv)
87 // Recostruction from associated clusters
90 ConnectInputFile(file, nmaxEv);
93 InitStreamer(".debug");
97 static AliExternalTrackParam resetParam;
99 AliExternalTrackParam t0seed;
100 AliExternalTrackParam seed;
101 AliExternalTrackParam track;
102 AliExternalTrackParam tOrig;
105 AliExternalTrackParam tOrigITS; // ideal track
106 AliExternalTrackParam tRealITS; // ITS track with realistic space point resolution
107 AliExternalTrackParam trackITS; // TPC refitted track
109 //between TPC inner wall and ITS
110 AliExternalTrackParam tOrigITS1;
111 AliExternalTrackParam tRealITS1;
112 AliExternalTrackParam trackITS1;
115 AliExternalTrackParam tOrigITS2;
116 AliExternalTrackParam tRealITS2;
117 AliExternalTrackParam trackITS2;
119 AliExternalTrackParam *dummy;
122 TClonesArray *arrClustRes=0x0;
123 if (fFillClusterRes){
124 arrClustRes=new TClonesArray("AliTPCclusterMI",160);
127 Int_t maxev=fTree->GetEntries();
128 if (nmaxEv>0&&nmaxEv<maxev) maxev=nmaxEv;
130 const Double_t lastLayerITS = 43.0; // same as in AliToyMCEventGenerator::MakeITSClusters (hard coded)
131 const Double_t iFCRadius = 83.5; //radius constants found in AliTPCCorrection.cxx
132 const Double_t betweeTPCITS = (lastLayerITS+iFCRadius)/2.; // its track propgated to inner TPC wall
134 const Double_t kMaxSnp = 0.85;
135 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
138 for (Int_t iev=0; iev<maxev; ++iev){
139 printf("============== Processing Event %6d =================\n",iev);
140 fTree->GetEvent(iev);
141 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks(); ++itr){
142 // printf(" > ====== Processing Track %6d ======== \n",itr);
143 const AliToyMCTrack *tr=fEvent->GetTrack(itr);
145 // ideal track propagated to ITS reference points
149 // propagate original track to ITS comparison points
150 AliTrackerBase::PropagateTrackTo(&tOrigITS, lastLayerITS,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
151 AliTrackerBase::PropagateTrackTo(&tOrigITS1,betweeTPCITS,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
152 AliTrackerBase::PropagateTrackTo(&tOrigITS2,iFCRadius, kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
154 // realistic ITS track propagated to reference points
155 tRealITS = resetParam;
156 tRealITS1 = resetParam;
157 tRealITS2 = resetParam;
158 dummy = GetTrackRefit(tr,kITS);
163 // propagate realistic track to ITS comparison points
164 AliTrackerBase::PropagateTrackTo(&tRealITS, lastLayerITS,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
165 AliTrackerBase::PropagateTrackTo(&tRealITS1,betweeTPCITS,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
166 AliTrackerBase::PropagateTrackTo(&tRealITS2,iFCRadius, kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
178 trackITS = resetParam;
179 trackITS1 = resetParam;
180 trackITS2 = resetParam;
182 Float_t z0=fEvent->GetZ();
183 Float_t t0=fEvent->GetT0();
185 Float_t vDrift=GetVDrift();
186 Float_t zLength=GetZLength(0);
188 // crate time0 seed, steered by fCreateT0seed
189 // printf("t0 seed\n");
192 dummy = GetSeedFromTrack(tr);
200 dummy = GetFittedTrackFromSeed(tr,&t0seed);
205 // crate real seed using the time 0 from the first seed
206 // set fCreateT0seed now to false to get the seed in z coordinates
207 fTime0 = t0seed.GetZ()-zLength/vDrift;
208 fCreateT0seed = kFALSE;
209 // printf("seed (%.2g)\n",fTime0);
210 dummy = GetSeedFromTrack(tr);
215 // create fitted track
217 // printf("track\n");
218 dummy = GetFittedTrackFromSeed(tr, &seed, arrClustRes);
223 // Copy original track and fitted track
224 // for extrapolation to ITS last layer
229 // propagate seed to 0
230 AliTrackerBase::PropagateTrackTo(&seed,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
236 // rotate fitted track to the frame of the original track and propagate to same reference
237 AliTrackerBase::PropagateTrackTo(&trackITS,lastLayerITS,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
238 trackITS.Rotate(tOrigITS.GetAlpha());
239 AliTrackerBase::PropagateTrackTo(&trackITS,lastLayerITS,kMass,1,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
241 // rotate fitted track to the frame of the original track and propagate to same reference
242 AliTrackerBase::PropagateTrackTo(&trackITS1,betweeTPCITS,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
243 trackITS1.Rotate(tOrigITS1.GetAlpha());
244 AliTrackerBase::PropagateTrackTo(&trackITS1,betweeTPCITS,kMass,1,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
246 // rotate fitted track to the frame of the original track and propagate to same reference
247 AliTrackerBase::PropagateTrackTo(&trackITS2,iFCRadius,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
248 trackITS2.Rotate(tOrigITS2.GetAlpha());
249 AliTrackerBase::PropagateTrackTo(&trackITS2,iFCRadius,kMass,1,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
253 Int_t ctype(fCorrectionType);
256 (*fStreamer) << "Tracks" <<
260 "fTime0=" << fTime0 <<
262 "clsType=" << fClusterType <<
263 "corrType=" << ctype <<
264 "seedRow=" << fSeedingRow <<
265 "seedDist=" << fSeedingDist <<
266 "vDrift=" << vDrift <<
267 "zLength=" << zLength <<
268 "t0seed.=" << &t0seed <<
271 "tOrig.=" << &tOrig <<
272 "track.=" << &track <<
274 "tOrigITS.=" << &tOrigITS <<
275 "tOrigITS1.=" << &tOrigITS1 <<
276 "tOrigITS2.=" << &tOrigITS2 <<
278 "tRealITS.=" << &tRealITS <<
279 "tRealITS1.=" << &tRealITS1 <<
280 "tRealITS2.=" << &tRealITS2 <<
282 "trackITS.=" << &trackITS <<
283 "trackITS1.=" << &trackITS1 <<
284 "trackITS2.=" << &trackITS2;
287 const Int_t nCl=arrClustRes->GetEntriesFast();
288 // fracktion of outliers from track extrapolation
289 // for 1, 1.5, 2, 2.5 and 3 sigma of the cluster resolution (~1mm)
290 Float_t fracY[5]={0.};
291 Float_t fracZ[5]={0.};
293 for (Int_t icl=0; icl<nCl; ++icl) {
294 AliTPCclusterMI *cl=static_cast<AliTPCclusterMI*>(arrClustRes->At(icl));
295 const Float_t sigmaY=TMath::Sqrt(cl->GetSigmaY2());
296 const Float_t sigmaZ=TMath::Sqrt(cl->GetSigmaZ2());
297 for (Int_t inSig=0; inSig<5; ++inSig) {
298 fracY[inSig] += cl->GetY()>(1+inSig*.5)*sigmaY;
299 fracZ[inSig] += cl->GetZ()>(1+inSig*.5)*sigmaZ;
304 for (Int_t inSig=0; inSig<5; ++inSig) {
310 (*fStreamer) << "Tracks" <<
311 "clustRes.=" << arrClustRes;
312 for (Int_t inSig=0; inSig<5; ++inSig) {
313 const char* fracYname=Form("clFracY%02d=", 10+inSig*5);
314 const char* fracZname=Form("clFracZ%02d=", 10+inSig*5);
315 (*fStreamer) << "Tracks" <<
316 fracYname << fracY[inSig] <<
317 fracZname << fracZ[inSig];
321 (*fStreamer) << "Tracks" <<
334 //____________________________________________________________________________________
335 void AliToyMCReconstruction::RunRecoAllClusters(const char* file, Int_t nmaxEv)
338 // Reconstruction for seed from associated clusters, but array of clusters:
339 // Step 1) Filling of cluster arrays
340 // Step 2) Seeding from clusters associated to tracks
341 // Step 3) Free track reconstruction using all clusters
345 if (!f.IsOpen() || f.IsZombie()) {
346 printf("ERROR: couldn't open the file '%s'\n", file);
350 fTree=(TTree*)f.Get("toyMCtree");
352 printf("ERROR: couldn't read the 'toyMCtree' from file '%s'\n", file);
357 fTree->SetBranchAddress("event",&fEvent);
359 // read spacecharge from the Userinfo ot the tree
362 TString debugName=file;
363 debugName.ReplaceAll(".root","");
364 debugName.Append(Form(".%1d.%1d_%1d_%1d_%03d_%02d",
365 fUseMaterial,fIdealTracking,fClusterType,
366 Int_t(fCorrectionType),fSeedingRow,fSeedingDist));
367 debugName.Append(".allClusters.debug.root");
369 gSystem->Exec(Form("test -f %s && rm %s", debugName.Data(), debugName.Data()));
370 if (!fStreamer) fStreamer=new TTreeSRedirector(debugName.Data());
374 static AliExternalTrackParam dummySeedT0;
375 static AliExternalTrackParam dummySeed;
376 static AliExternalTrackParam dummyTrack;
378 AliExternalTrackParam t0seed;
379 AliExternalTrackParam seed;
380 AliExternalTrackParam track;
381 AliExternalTrackParam tOrig;
383 AliExternalTrackParam *dummy;
385 Int_t maxev=fTree->GetEntries();
386 if (nmaxEv>0&&nmaxEv<maxev) maxev=nmaxEv;
388 // ===========================================================================================
389 // Loop 1: Fill AliTPCtrackerSector structure
390 // ===========================================================================================
391 FillSectorStructure(maxev);
393 // settings (TODO: find the correct settings)
394 AliTPCRecoParam *tpcRecoParam = new AliTPCRecoParam();
395 tpcRecoParam->SetDoKinks(kFALSE);
396 AliTPCcalibDB::Instance()->GetTransform()->SetCurrentRecoParam(tpcRecoParam);
397 //tpcRecoParam->Print();
399 // need AliTPCReconstructor for parameter settings in AliTPCtracker
400 AliTPCReconstructor *tpcRec = new AliTPCReconstructor();
401 tpcRec->SetRecoParam(tpcRecoParam);
404 // ===========================================================================================
405 // Loop 2: Seeding from clusters associated to tracks
406 // TODO: Implement tracking from given seed!
407 // ===========================================================================================
408 for (Int_t iev=0; iev<maxev; ++iev){
409 printf("============== Processing Event %6d =================\n",iev);
410 fTree->GetEvent(iev);
411 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks(); ++itr){
412 printf(" > ====== Processing Track %6d ======== \n",itr);
413 const AliToyMCTrack *tr=fEvent->GetTrack(itr);
418 t0seed = dummySeedT0;
422 Float_t z0=fEvent->GetZ();
423 Float_t t0=fEvent->GetT0();
425 Float_t vDrift=GetVDrift();
426 Float_t zLength=GetZLength(0);
430 // crate time0 seed, steered by fCreateT0seed
434 dummy = GetSeedFromTrack(tr);
440 // crate real seed using the time 0 from the first seed
441 // set fCreateT0seed now to false to get the seed in z coordinates
442 fTime0 = t0seed.GetZ()-zLength/vDrift;
443 fCreateT0seed = kFALSE;
444 printf("seed (%.2g)\n",fTime0);
445 dummy = GetSeedFromTrack(tr);
450 // create fitted track
453 dummy = GetFittedTrackFromSeedAllClusters(tr, &seed,nClus);
458 // propagate seed to 0
459 const Double_t kMaxSnp = 0.85;
460 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
461 AliTrackerBase::PropagateTrackTo(&seed,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,kFALSE);
466 Int_t ctype(fCorrectionType);
469 (*fStreamer) << "Tracks" <<
473 "fTime0=" << fTime0 <<
475 "clsType=" << fClusterType <<
476 "corrType=" << ctype <<
477 "seedRow=" << fSeedingRow <<
478 "seedDist=" << fSeedingDist <<
479 "vDrift=" << vDrift <<
480 "zLength=" << zLength <<
482 "t0seed.=" << &t0seed <<
484 "track.=" << &track <<
485 "tOrig.=" << &tOrig <<
505 //____________________________________________________________________________________
506 void AliToyMCReconstruction::RunRecoAllClustersStandardTracking(const char* file, Int_t nmaxEv)
509 // Reconstruction for seed from associated clusters, but array of clusters
510 // Step 1) Filling of cluster arrays
511 // Step 2) Use the standard tracking: AliTPCtracker::Clusters2Tracks();
515 if (!f.IsOpen() || f.IsZombie()) {
516 printf("ERROR: couldn't open the file '%s'\n", file);
520 fTree=(TTree*)f.Get("toyMCtree");
522 printf("ERROR: couldn't read the 'toyMCtree' from file '%s'\n", file);
527 fTree->SetBranchAddress("event",&fEvent);
529 // read spacecharge from the Userinfo ot the tree
532 TString debugName=file;
533 debugName.ReplaceAll(".root","");
534 debugName.Append(Form(".%1d.%1d_%1d_%1d_%03d_%02d",
535 fUseMaterial,fIdealTracking,fClusterType,
536 Int_t(fCorrectionType),fSeedingRow,fSeedingDist));
537 debugName.Append(".allClusters.debug.root");
539 gSystem->Exec(Form("test -f %s && rm %s", debugName.Data(), debugName.Data()));
540 if (!fStreamer) fStreamer=new TTreeSRedirector(debugName.Data());
544 AliExternalTrackParam t0seed;
545 AliExternalTrackParam seed;
546 AliExternalTrackParam track;
547 AliExternalTrackParam tOrig;
548 AliToyMCTrack tOrigToy;
550 AliExternalTrackParam *dummy;
551 AliTPCseed *seedBest;
553 AliTPCclusterMI *cluster;
555 Int_t maxev=fTree->GetEntries();
556 if (nmaxEv>0&&nmaxEv<maxev) maxev=nmaxEv;
559 // ===========================================================================================
560 // Loop 1: Fill AliTPCtrackerSector structure
561 // ===========================================================================================
562 FillSectorStructure(maxev);
564 // ===========================================================================================
565 // Loop 2: Use the TPC tracker for seeding (MakeSeeds3)
566 // TODO: - check tracking configuration
567 // - add clusters and original tracks to output (how?)
568 // ===========================================================================================
570 // settings (TODO: find the correct settings)
571 AliTPCRecoParam *tpcRecoParam = new AliTPCRecoParam();
572 tpcRecoParam->SetDoKinks(kFALSE);
573 AliTPCcalibDB::Instance()->GetTransform()->SetCurrentRecoParam(tpcRecoParam);
574 //tpcRecoParam->Print();
576 // need AliTPCReconstructor for parameter settings in AliTPCtracker
577 AliTPCReconstructor *tpcRec = new AliTPCReconstructor();
578 tpcRec->SetRecoParam(tpcRecoParam);
581 AliTPCtracker *tpcTracker = new AliTPCtracker(fTPCParam);
582 tpcTracker->SetDebug(10);
585 tpcTracker->SetTPCtrackerSectors(fInnerSectorArray,fOuterSectorArray);
586 tpcTracker->LoadInnerSectors();
587 tpcTracker->LoadOuterSectors();
590 static TObjArray arrTracks;
591 TObjArray * arr = &arrTracks;
592 TObjArray * seeds = new TObjArray;
596 // cuts[0]=0.0070; // cuts[0] - fP4 cut
597 // cuts[1] = 1.5; // cuts[1] - tan(phi) cut
598 // cuts[2] = 3.; // cuts[2] - zvertex cut
599 // cuts[3] = 3.; // cuts[3] - fP3 cut
602 Int_t lowerRow = fSeedingRow;
603 Int_t upperRow = fSeedingRow+2*fSeedingDist;
604 const AliTPCROC * roc = AliTPCROC::Instance();
605 const Int_t kNRowsInnerTPC = roc->GetNRows(0);
606 const Int_t kNRowsTPC = kNRowsInnerTPC + roc->GetNRows(36);
607 if(lowerRow < kNRowsInnerTPC){
608 Printf("Seeding row requested (%d) is lower than kNRowsInnerTPC --> use %d",lowerRow,kNRowsInnerTPC);
609 lowerRow = kNRowsInnerTPC;
610 upperRow = lowerRow + 20;
612 if(upperRow >= kNRowsTPC){
613 Printf("Seeding row requested (%d) is larger than kNRowsTPC --> use %d",upperRow,kNRowsTPC-1);
614 upperRow = kNRowsTPC-1;
615 lowerRow = upperRow-20;
619 for (Int_t sec=0;sec<fkNSectorOuter;sec++){
621 //tpcTracker->MakeSeeds3(arr, sec,upperRow,lowerRow,cuts,-1,1);
622 MakeSeeds(arr, sec,upperRow,lowerRow); // own function (based on TLinearFitter)
623 //tpcTracker->SumTracks(seeds,arr);
624 //tpcTracker->SignClusters(seeds,3.0,3.0);
628 Printf("After seeding we have %d tracks",seeds->GetEntriesFast());
631 tpcTracker->SetSeeds(seeds);
632 tpcTracker->PropagateForward();
633 Printf("After trackinging we have %d tracks",seeds->GetEntriesFast());
636 // Loop over all input tracks and connect to found seeds
637 for (Int_t iev=0; iev<maxev; ++iev){
638 printf("============== Fill Tracks: Processing Event %6d =================\n",iev);
639 fTree->GetEvent(iev);
640 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks(); ++itr){
641 printf(" > ====== Fill Tracks: Processing Track %6d ======== \n",itr);
642 const AliToyMCTrack *tr=fEvent->GetTrack(itr);
646 Float_t z0=fEvent->GetZ();
647 Float_t t0=fEvent->GetT0();
648 Float_t vDrift=GetVDrift();
649 Float_t zLength=GetZLength(0);
651 // find the corresponding seed (and track)
652 Int_t trackID = tr->GetUniqueID();
653 Int_t nClustersMC = tr->GetNumberOfSpacePoints(); // number of findable clusters (ideal)
655 nClustersMC = tr->GetNumberOfDistSpacePoints(); // number of findable clusters (distorted)
656 // Int_t idxSeed = 0; // index of best seed (best is with maximum number of clusters with correct ID)
657 Int_t nSeeds = 0; // number of seeds for MC track
658 Int_t nSeedClusters = 0; // number of clusters for best seed
659 Int_t nSeedClustersTmp = 0; // number of clusters for current seed
660 Int_t nSeedClustersID = 0; // number of clusters with correct ID for best seed
661 Int_t nSeedClustersIDTmp = 0; // number of clusters with correct ID for current seed
662 for(Int_t iSeeds = 0; iSeeds < seeds->GetEntriesFast(); ++iSeeds){
664 // set current seed and reset counters
665 seedTmp = (AliTPCseed*)(seeds->At(iSeeds));
666 nSeedClustersTmp = 0;
667 nSeedClustersIDTmp = 0;
669 if(!seedTmp) continue;
671 // loop over all rows
672 for(Int_t iRow = seedTmp->GetRow(); iRow < seedTmp->GetRow() + seedTmp->GetNumberOfClustersIndices(); iRow++ ){
674 // get cluster and increment counters
675 cluster = seedTmp->GetClusterFast(iRow);
678 if(cluster->GetLabel(0)==trackID){
679 nSeedClustersIDTmp++;
684 // if number of corresponding clusters > 0,
686 if(nSeedClustersTmp > 0){
690 // if number of corresponding clusters bigger than current nSeedClusters,
691 // take this seed as the best one
692 if(nSeedClustersIDTmp > nSeedClustersID){
695 nSeedClusters = nSeedClustersTmp; // number of correctly assigned clusters
696 nSeedClustersID = nSeedClustersIDTmp; // number of all clusters
701 // cluster to track association (commented out, when used standard tracking)
702 if (nSeeds>0&&nSeedClusters>0) {
703 t0seed = (AliExternalTrackParam)*seedBest;
704 // fTime0 = t0seed.GetZ()-zLength/vDrift;
705 // get the refitted track from the seed
706 // this will also set the fTime0 from the seed extrapolation
707 dummy=GetRefittedTrack(*seedBest);
710 //printf("seed (%.2g): %d seeds with %d clusters\n",fTime0,nSeeds,nSeedClusters);
712 // // cluster to track association for all good seeds
713 // // set fCreateT0seed to true to get the seed in time coordinates
714 // fCreateT0seed = kTRUE;
715 // dummy = ClusterToTrackAssociation(seedBest,trackID,nClus);
717 //// propagate track to 0
718 //const Double_t kMaxSnp = 0.85;
719 //const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
720 //AliTrackerBase::PropagateTrackTo(&track,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,kFALSE);
724 Int_t ctype(fCorrectionType);
727 (*fStreamer) << "Tracks" <<
731 "fTime0=" << fTime0 <<
733 "clsType=" << fClusterType <<
734 "corrType=" << ctype <<
735 "seedRow=" << fSeedingRow <<
736 "seedDist=" << fSeedingDist <<
737 "vDrift=" << vDrift <<
738 "zLength=" << zLength <<
739 "nClustersMC=" << nClustersMC <<
740 "nSeeds=" << nSeeds <<
741 "nSeedClusters=" << nSeedClusters <<
742 "nSeedClustersID=" << nSeedClustersID <<
743 "t0seed.=" << &t0seed <<
744 "track.=" << &track <<
745 "tOrig.=" << &tOrig <<
746 "tOrigToy.=" << &tOrigToy <<
765 //____________________________________________________________________________________
766 void AliToyMCReconstruction::RunFullTracking(const char* file, Int_t nmaxEv)
772 ConnectInputFile(file,nmaxEv);
775 InitStreamer(".fullTracking");
777 FillSectorStructureAC();
779 AliTPCReconstructor::SetStreamLevel(0);
785 if (lowerRow>upperRow){
792 // NOTE: the z position is set to GetTimeBin*vDrift
793 // therefore it is not possible to simply propagate
794 // the track using AliTrackerBase::Propagate, since a
795 // wrong B-Field will be assinged...
796 printf("Run Seeding in %3d - %3d\n",lowerRow,upperRow);
797 for (Int_t sec=0;sec<36;sec++){
798 printf(" in sector: %d\n",sec);
799 Int_t nAdded=MakeSeeds2(&seeds, sec,lowerRow,upperRow);
800 printf(" -> Added Seeds: %d\n",nAdded);
801 nAdded=MakeSeeds2(&seeds, sec,lowerRow-2,upperRow-2);
802 printf(" -> Added Seeds: %d\n",nAdded);
803 nAdded=MakeSeeds2(&seeds, sec,lowerRow-4,upperRow-4);
804 printf(" -> Added Seeds: %d\n",nAdded);
807 printf("Run Tracking in %3d - %3d\n",lowerRow,upperRow);
809 for (Int_t iseed=firstSeed; iseed<seeds.GetEntriesFast();++iseed) ClusterToTrackAssociation(*(AliTPCseed*)seeds.UncheckedAt(iseed));
810 //first seed is used to not run the tracking twice on a seed
811 firstSeed=seeds.GetEntriesFast();
812 // DumpTrackInfo(&seeds);
817 printf("Run Seeding in %3d - %3d\n",lowerRow,upperRow);
818 for (Int_t sec=0;sec<36;sec++){
819 printf(" in sector: %d\n",sec);
820 Int_t nAdded=MakeSeeds2(&seeds, sec,lowerRow,upperRow);
821 printf(" -> Added Seeds: %d\n",nAdded);
823 printf("Run Tracking in %3d - %3d\n",lowerRow,upperRow);
824 for (Int_t iseed=firstSeed; iseed<seeds.GetEntriesFast();++iseed) ClusterToTrackAssociation(*(AliTPCseed*)seeds.UncheckedAt(iseed));
825 firstSeed=seeds.GetEntriesFast();
827 //now seeding also at more central rows with shorter seeds
831 printf("Run Seeding in %3d - %3d\n",lowerRow,upperRow);
832 for (Int_t sec=0;sec<36;sec++){
833 printf(" in sector: %d\n",sec);
834 Int_t nAdded=MakeSeeds2(&seeds, sec,lowerRow,upperRow);
835 printf(" -> Added Seeds: %d\n",nAdded);
837 printf("Run Tracking in %3d - %3d\n",lowerRow,upperRow);
838 for (Int_t iseed=firstSeed; iseed<seeds.GetEntriesFast();++iseed) ClusterToTrackAssociation(*(AliTPCseed*)seeds.UncheckedAt(iseed));
839 firstSeed=seeds.GetEntriesFast();
842 Int_t startUpper=upperRow-10;
843 Int_t startLower=lowerRow-5;
844 for (Int_t sec=0;sec<36;sec++){
847 printf(" in sector: %d\n",sec);
849 printf("Run Seeding in %3d - %3d\n",lowerRow,upperRow);
850 Int_t nAdded=MakeSeeds2(&seeds, sec,lowerRow,upperRow);
851 printf(" -> Added Seeds: %d\n",nAdded);
852 for (Int_t iseed=firstSeed; iseed<seeds.GetEntriesFast();++iseed) ClusterToTrackAssociation(*(AliTPCseed*)seeds.UncheckedAt(iseed));
853 firstSeed=seeds.GetEntriesFast();
861 DumpTrackInfo(&seeds);
863 // TObjArray seedsCentral2;
867 // for (Int_t sec=0;sec<36;sec++){
868 // Int_t nAdded=MakeSeeds2(&seedsCentral2, sec,lowerRow,upperRow);
869 // printf(" -> Added Seeds: %d\n",nAdded);
870 // nAdded=MakeSeeds2(&seedsCentral2, sec,lowerRow-2,upperRow-2);
871 // printf(" -> Added Seeds: %d\n",nAdded);
872 // nAdded=MakeSeeds2(&seedsCentral2, sec,lowerRow-4,upperRow-4);
873 // printf(" -> Added Seeds: %d\n",nAdded);
875 // for (Int_t iseed=0; iseed<seedsCentral2.GetEntriesFast();++iseed) ClusterToTrackAssociation(*(AliTPCseed*)seedsCentral2.UncheckedAt(iseed));
876 // DumpTrackInfo(&seedsCentral2);
879 // (*fStreamer) << "clusters" <<
880 // "cl.=" << &fAllClusters << "\n";
885 //____________________________________________________________________________________
886 AliExternalTrackParam* AliToyMCReconstruction::GetSeedFromTrackIdeal(const AliToyMCTrack * const tr, EDet det )
889 // crate a seed from the track points of the respective detector
891 AliTrackPoint seedPoint[3];
896 npoints=tr->GetNumberOfITSPoints();
899 npoints=(fClusterType == 0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
902 npoints=tr->GetNumberOfTRDPoints();
906 if (npoints<3) return 0x0;
908 Int_t pos[3]={0,npoints/2,npoints-1};
909 const AliCluster *cl=0x0;
911 for (Int_t ipoint=0;ipoint<3;++ipoint){
912 Int_t cluster=pos[ipoint];
915 seedPoint[ipoint]=(*tr->GetITSPoint(cluster));
918 cl=tr->GetSpacePoint(cluster);
919 if (fClusterType == 1) cl=tr->GetDistortedSpacePoint(cluster);
920 AliTPCclusterMI::SetGlobalTrackPoint(*cl,seedPoint[ipoint]);
923 seedPoint[ipoint]=(*tr->GetTRDPoint(cluster));
928 AliExternalTrackParam *seed = AliTrackerBase::MakeSeed(seedPoint[0], seedPoint[1], seedPoint[2]);
929 seed->ResetCovariance(10);
934 //____________________________________________________________________________________
935 AliExternalTrackParam* AliToyMCReconstruction::GetSeedFromTrack(const AliToyMCTrack * const tr, Bool_t forceSeed)
938 // if we don't have a valid time0 informaion (fTime0) available yet
939 // assume we create a seed for the time0 estimate
942 // seed point informaion
943 AliTrackPoint seedPoint[3];
944 const AliTPCclusterMI *seedCluster[3]={0x0,0x0,0x0};
946 // number of clusters to loop over
947 const Int_t ncls=(fClusterType==0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
949 AliError(Form("Not enough points to create a seed: %d",ncls));
952 UChar_t nextSeedRow=fSeedingRow;
955 //assumes sorted clusters
957 // force the seed creation, using the first, middle and last cluster
958 Int_t npoints[3]={0,ncls/2,ncls-1};
959 for (Int_t icl=0;icl<3;++icl){
960 const AliTPCclusterMI *cl=tr->GetSpacePoint(npoints[icl]);
961 if (fClusterType==1) cl=tr->GetDistortedSpacePoint(npoints[icl]);
962 seedCluster[nseeds]=cl;
963 SetTrackPointFromCluster(cl, seedPoint[nseeds]);
967 // create seeds according to the reco settings
968 for (Int_t icl=0;icl<ncls;++icl) {
969 const AliTPCclusterMI *cl=tr->GetSpacePoint(icl);
970 if (fClusterType==1) cl=tr->GetDistortedSpacePoint(icl);
973 const UChar_t row=cl->GetRow() + 63*(cl->GetDetector()>35);
974 // skip clusters without proper pad row
975 if (row>200) continue;
978 // if we are in the last row and still miss a seed we use the last row
979 // even if the row spacing will not be equal
980 if (row>=nextSeedRow || icl==ncls-1){
981 seedCluster[nseeds]=cl;
982 SetTrackPointFromCluster(cl, seedPoint[nseeds]);
984 nextSeedRow+=fSeedingDist;
986 if (nseeds==3) break;
991 // check we really have 3 seeds
993 AliError(Form("Seeding failed for parameters %d, %d\n",fSeedingDist,fSeedingRow));
997 // determine preliminary theta
998 Float_t xyz1[3]={0,0,0};
999 Float_t xyz2[3]={0,0,0};
1000 seedPoint[0].GetXYZ(xyz1);
1001 seedPoint[2].GetXYZ(xyz2);
1002 Float_t prelDeltaR = TMath::Sqrt(xyz2[0]*xyz2[0]+xyz2[1]*xyz2[1]) - TMath::Sqrt(xyz1[0]*xyz1[0]+xyz1[1]*xyz1[1]) ;
1003 Float_t prelDeltaZ = ( seedCluster[0]->GetTimeBin() - seedCluster[2]->GetTimeBin() ) * GetVDrift();
1004 Float_t prelTheta = TMath::ATan(prelDeltaR/prelDeltaZ);
1005 if(prelTheta > TMath::Pi()/2) prelTheta = TMath::Pi() - prelTheta;
1007 // do cluster correction for fCorrectionType:
1008 // 0 - no correction
1012 // 4 - preliminary eta (needs fixing!!! Not yet in full code!!!)
1013 // assign the cluster abs time as z component to all seeds
1014 for (Int_t iseed=0; iseed<3; ++iseed) {
1015 Float_t xyz[3]={0,0,0};
1016 seedPoint[iseed].GetXYZ(xyz);
1017 const Float_t r=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
1019 const Int_t sector=seedCluster[iseed]->GetDetector();
1020 const Int_t sign=1-2*((sector/18)%2);
1022 Float_t zBeforeCorr = xyz[2];
1024 if ( (fClusterType == 1) && (fCorrectionType != kNoCorrection) ) {
1025 // the settings below are for the T0 seed
1026 // for known T0 the z position is already calculated in SetTrackPointFromCluster
1027 if ( fCreateT0seed ){
1028 if ( fCorrectionType == kTPCCenter ) xyz[2] = 125.*sign;
1029 //!!! TODO: is this the correct association?
1030 if ( fCorrectionType == kAverageEta ) xyz[2] = TMath::Tan(45./2.*TMath::DegToRad())*r*sign;
1031 if ( fCorrectionType == kPreliminaryEta ) xyz[2] = r/TMath::Tan(prelTheta)*sign;//(needs fixing!!! Not yet in full code!!!)
1034 if ( fCorrectionType == kIdeal ) xyz[2] = seedCluster[iseed]->GetZ();
1036 // Store xyz only here!!! To get the Delta z from the correction...
1037 zBeforeCorr = xyz[2];
1039 //!!! TODO: to be replaced with the proper correction
1040 fTPCCorrection->CorrectPoint(xyz, seedCluster[iseed]->GetDetector());
1043 // after the correction set the time bin as z-Position in case of a T0 seed
1044 if ( fCreateT0seed )
1045 xyz[2]=seedCluster[iseed]->GetTimeBin() + sign*( zBeforeCorr - xyz[2] )/GetVDrift();
1047 seedPoint[iseed].SetXYZ(xyz);
1050 const Double_t kMaxSnp = 0.85;
1051 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1053 AliExternalTrackParam *seed = AliTrackerBase::MakeSeed(seedPoint[0], seedPoint[1], seedPoint[2]);
1055 if (fCreateT0seed&&!fLongT0seed){
1056 // only propagate to vertex if we don't create a long seed
1057 // if fTime0 < 0 we assume that we create a seed for the T0 estimate
1058 AliTrackerBase::PropagateTrackTo(seed,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,kFALSE);
1059 if (TMath::Abs(seed->GetX())>3) {
1060 // printf("Could not propagate track to 0, %.2f, %.2f, %.2f\n",seed->GetX(),seed->GetAlpha(),seed->Pt());
1064 seed->ResetCovariance(10);
1069 //____________________________________________________________________________________
1070 AliExternalTrackParam* AliToyMCReconstruction::GetTrackRefit(const AliToyMCTrack * const tr, EDet det)
1073 // Get the ITS or TRD track refitted from the toy track
1074 // type: 0=ITS; 1=TRD
1077 AliExternalTrackParam *track=GetSeedFromTrackIdeal(tr,det);
1078 if (!track) return 0x0;
1080 const Double_t kMaxSnp = 0.85;
1081 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1086 npoints=tr->GetNumberOfITSPoints();
1089 npoints=(fClusterType == 0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
1092 npoints=tr->GetNumberOfTRDPoints();
1096 const AliCluster *cl=0x0;
1098 for (Int_t ipoint=0; ipoint<npoints; ++ipoint) {
1103 pIn=(*tr->GetITSPoint(ipoint));
1106 cl=tr->GetSpacePoint(ipoint);
1107 if (fClusterType == 1) cl=tr->GetDistortedSpacePoint(ipoint);
1108 AliTPCclusterMI::SetGlobalTrackPoint(*cl,pIn);
1111 pIn=(*tr->GetTRDPoint(ipoint));
1116 const Double_t angle=pIn.GetAngle();
1117 track->Rotate(angle);
1118 AliTrackPoint prot = pIn.Rotate(track->GetAlpha()); // rotate to the local frame - non distoted point
1120 if (!AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial)) {
1121 AliInfo(Form("Could not propagate track to x=%.2f (a=%.2f) for det %d",prot.GetX(),angle,det));
1125 Double_t pointPos[2]={0,0};
1126 Double_t pointCov[3]={0,0,0};
1127 pointPos[0]=prot.GetY();//local y
1128 pointPos[1]=prot.GetZ();//local z
1129 pointCov[0]=prot.GetCov()[3];//simay^2
1130 pointCov[1]=prot.GetCov()[4];//sigmayz
1131 pointCov[2]=prot.GetCov()[5];//sigmaz^2
1133 if (!track->Update(pointPos,pointCov)) {
1134 AliInfo(Form("no update: det: %d",det));
1144 //____________________________________________________________________________________
1145 void AliToyMCReconstruction::SetTrackPointFromCluster(const AliTPCclusterMI *cl, AliTrackPoint &p )
1148 // make AliTrackPoint out of AliTPCclusterMI
1152 Float_t xyz[3]={0.,0.,0.};
1153 // ClusterToSpacePoint(cl,xyz);
1154 // cl->GetGlobalCov(cov);
1155 //TODO: what to do with the covariance matrix???
1156 //TODO: the problem is that it is used in GetAngle in AliTrackPoint
1157 //TODO: which is used by AliTrackerBase::MakeSeed to get alpha correct ...
1158 //TODO: for the moment simply assign 1 permill squared
1159 // in AliTrackPoint the cov is xx, xy, xz, yy, yz, zz
1160 // Float_t cov[6]={xyz[0]*xyz[0]*1e-6,xyz[0]*xyz[1]*1e-6,xyz[0]*xyz[2]*1e-6,
1161 // xyz[1]*xyz[1]*1e-6,xyz[1]*xyz[2]*1e-6,xyz[2]*xyz[2]*1e-6};
1162 // cl->GetGlobalXYZ(xyz);
1163 // cl->GetGlobalCov(cov);
1164 // voluem ID to add later ....
1167 // AliTrackPoint *tp=const_cast<AliTPCclusterMI*>(cl)->MakePoint(p);
1170 // const_cast<AliTPCclusterMI*>(cl)->MakePoint(p);
1171 AliTPCclusterMI::SetGlobalTrackPoint(*cl,p);
1174 p.SetVolumeID(cl->GetDetector());
1177 if ( !fCreateT0seed && !fIdealTracking ) {
1179 const Int_t sector=cl->GetDetector();
1180 const Int_t sign=1-2*((sector/18)%2);
1181 const Float_t zT0=( GetZLength(sector) - (cl->GetTimeBin()-fTime0)*GetVDrift() )*sign;
1182 // printf(" z: %.2f %.2f\n",xyz[2],zT0);
1188 // p.Rotate(p.GetAngle()).Print();
1191 //____________________________________________________________________________________
1192 void AliToyMCReconstruction::ClusterToSpacePoint(const AliTPCclusterMI *cl, Float_t xyz[3])
1195 // convert the cluster to a space point in global coordinates
1198 xyz[0]=cl->GetRow();
1199 xyz[1]=cl->GetPad();
1200 xyz[2]=cl->GetTimeBin(); // this will not be correct at all
1201 Int_t i[3]={0,cl->GetDetector(),cl->GetRow()};
1202 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
1203 fTPCParam->Transform8to4(xyz,i);
1204 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
1205 fTPCParam->Transform4to3(xyz,i);
1206 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
1207 fTPCParam->Transform2to1(xyz,i);
1208 // printf("%.2f, %.2f, %.2f - %d, %d, %d\n",xyz[0],xyz[1],xyz[2],i[0],i[1],i[2]);
1211 //____________________________________________________________________________________
1212 AliExternalTrackParam* AliToyMCReconstruction::GetFittedTrackFromSeed(const AliToyMCTrack *tr, const AliExternalTrackParam *seed, TClonesArray *arrClustRes)
1219 arrClustRes->Clear();
1223 AliExternalTrackParam *track = new AliExternalTrackParam(*seed);
1225 Int_t ncls=(fClusterType == 0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
1227 const AliTPCROC * roc = AliTPCROC::Instance();
1229 const Double_t kRTPC0 = roc->GetPadRowRadii(0,0);
1230 const Double_t kRTPC1 = roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
1231 const Double_t kMaxSnp = 0.85;
1232 const Double_t kMaxR = 500.;
1233 const Double_t kMaxZ = 500.;
1235 // const Double_t kMaxZ0=220;
1236 // const Double_t kZcut=3;
1238 const Double_t refX = tr->GetX();
1240 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1242 // loop over all other points and add to the track
1243 for (Int_t ipoint=ncls-1; ipoint>=0; --ipoint){
1245 const AliTPCclusterMI *cl=tr->GetSpacePoint(ipoint);
1246 if (fClusterType == 1) cl=tr->GetDistortedSpacePoint(ipoint);
1247 const Int_t globalRow = cl->GetRow() +(cl->GetDetector() >35)*63;
1248 if ( fCreateT0seed ){
1249 if ( globalRow<fSeedingRow || globalRow>fSeedingRow+2*fSeedingDist ) continue;
1252 SetTrackPointFromCluster(cl, pIn);
1254 Float_t xyz[3]={0,0,0};
1256 Float_t zBeforeCorr = xyz[2];
1258 const Int_t sector=cl->GetDetector();
1259 const Int_t sign=1-2*((sector/18)%2);
1261 if (fCorrectionType != kNoCorrection){
1263 const Float_t r=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
1265 if ( fCreateT0seed ){
1266 if ( fCorrectionType == kTPCCenter ) xyz[2] = 125.*sign;
1267 //!!! TODO: is this the correct association?
1268 if ( fCorrectionType == kAverageEta ) xyz[2] = TMath::Tan(45./2.*TMath::DegToRad())*r*sign;
1269 if ( fCorrectionType == kIdeal ) xyz[2] = cl->GetZ();
1272 // Store xyz only here!!! To get the Delta z from the correction...
1273 zBeforeCorr = xyz[2];
1275 fTPCCorrection->CorrectPoint(xyz, cl->GetDetector());
1278 if ( fCreateT0seed )
1279 xyz[2]=cl->GetTimeBin() + sign*( zBeforeCorr - xyz[2] )/GetVDrift();
1280 // xyz[2]=cl->GetTimeBin();
1283 // rotate the cluster to the local detector frame
1284 track->Rotate(((cl->GetDetector()%18)*20+10)*TMath::DegToRad());
1285 AliTrackPoint prot = pIn.Rotate(track->GetAlpha()); // rotate to the local frame - non distoted point
1286 if (TMath::Abs(prot.GetX())<kRTPC0) continue;
1287 if (TMath::Abs(prot.GetX())>kRTPC1) continue;
1289 Bool_t res=AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
1293 if (TMath::Abs(track->GetZ())>kMaxZ) break;
1294 if (TMath::Abs(track->GetX())>kMaxR) break;
1295 // if (TMath::Abs(track->GetZ())<kZcut)continue;
1300 TClonesArray &arrDummy=*arrClustRes;
1301 AliTPCclusterMI *clRes = new(arrDummy[arrDummy.GetEntriesFast()]) AliTPCclusterMI(*cl);
1302 clRes->SetX(prot.GetX());
1303 clRes->SetY(track->GetY()-prot.GetY());
1304 clRes->SetZ(track->GetZ()-prot.GetZ());
1307 Double_t pointPos[2]={0,0};
1308 Double_t pointCov[3]={0,0,0};
1309 pointPos[0]=prot.GetY();//local y
1310 pointPos[1]=prot.GetZ();//local z
1311 pointCov[0]=prot.GetCov()[3];//simay^2
1312 pointCov[1]=prot.GetCov()[4];//sigmayz
1313 pointCov[2]=prot.GetCov()[5];//sigmaz^2
1315 if (!track->Update(pointPos,pointCov)) {printf("no update\n"); break;}
1318 AliTrackerBase::PropagateTrackTo2(track,refX,kMass,5.,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
1320 if (!fCreateT0seed){
1321 // rotate fittet track to the frame of the original track and propagate to same reference
1322 track->Rotate(tr->GetAlpha());
1324 AliTrackerBase::PropagateTrackTo2(track,refX,kMass,1.,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
1330 //____________________________________________________________________________________
1331 AliExternalTrackParam* AliToyMCReconstruction::GetFittedTrackFromSeedAllClusters(const AliToyMCTrack *tr, const AliExternalTrackParam *seed, Int_t &nClus)
1334 // Tracking for given seed on an array of clusters
1338 AliExternalTrackParam *track = new AliExternalTrackParam(*seed);
1340 const AliTPCROC * roc = AliTPCROC::Instance();
1342 const Double_t kRTPC0 = roc->GetPadRowRadii(0,0);
1343 const Double_t kRTPC1 = roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
1344 const Int_t kNRowsTPC = roc->GetNRows(0) + roc->GetNRows(36) - 1;
1345 const Int_t kIRowsTPC = roc->GetNRows(0) - 1;
1346 const Double_t kMaxSnp = 0.85;
1347 const Double_t kMaxR = 500.;
1348 const Double_t kMaxZ = 500.;
1349 const Double_t roady = 100.;
1350 const Double_t roadz = 100.;
1352 const Double_t refX = tr->GetX();
1354 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1357 UInt_t indexCur = 0;
1358 Double_t xCur, yCur, zCur = 0.;
1360 Float_t vDrift = GetVDrift();
1362 // first propagate seed to outermost row
1363 AliTrackerBase::PropagateTrackTo(track,kRTPC1,kMass,5,kFALSE,kMaxSnp);
1365 // Loop over rows and find the cluster candidates
1366 for( Int_t iRow = kNRowsTPC; iRow >= 0; --iRow ){
1368 // inner or outer sector
1369 Bool_t bInnerSector = kTRUE;
1370 if(iRow > kIRowsTPC) bInnerSector = kFALSE;
1372 // nearest track point/cluster (to be found)
1373 AliTrackPoint nearestPoint;
1374 AliTPCclusterMI *nearestCluster = NULL;
1379 // Propagate to center of pad row and extract parameters
1380 AliTrackerBase::PropagateTrackTo(track,roc->GetPadRowRadii(0,iRow),kMass,5,kFALSE,kMaxSnp);
1381 xCur = track->GetX();
1382 yCur = track->GetY();
1383 zCur = track->GetZ();
1384 if ( !fIdealTracking ) {
1385 zCur = zCur/vDrift + fTime0; // Look at time, not at z!
1387 secCur = GetSector(track);
1389 // Find the nearest cluster (TODO: correct road settings!)
1390 Printf("inner tracking here: x = %.2f, y = %.2f, z = %.2f (Row %d Sector %d)",xCur,yCur,zCur,iRow,secCur);
1391 nearestCluster = fInnerSectorArray[secCur%fkNSectorInner][iRow].FindNearest2(yCur,zCur,roady,roadz,indexCur);
1393 // Move to next row if now cluster found
1394 if(!nearestCluster) continue;
1395 //Printf("Nearest Clusters = %d (of %d) ",indexCur,fInnerSectorArray[secCur%fkNSectorInner][iRow].GetN());
1402 // Propagate to center of pad row and extract parameters
1403 AliTrackerBase::PropagateTrackTo(track,roc->GetPadRowRadii(36,iRow-kIRowsTPC-1),kMass,5,kFALSE,kMaxSnp);
1404 xCur = track->GetX();
1405 yCur = track->GetY();
1406 zCur = track->GetZ();
1407 if ( !fIdealTracking ) {
1408 zCur = zCur/vDrift + fTime0; // Look at time, not at z!
1410 secCur = GetSector(track);
1412 // Find the nearest cluster (TODO: correct road settings!)
1413 Printf("outer tracking here: x = %.2f, y = %.2f, z = %.2f (Row %d Sector %d)",xCur,yCur,zCur,iRow,secCur);
1414 nearestCluster = fOuterSectorArray[(secCur-fkNSectorInner*2)%fkNSectorOuter][iRow-kIRowsTPC-1].FindNearest2(yCur,zCur,roady,roadz,indexCur);
1416 // Move to next row if now cluster found
1417 if(!nearestCluster) continue;
1418 //Printf("Nearest Clusters = %d (of %d)",indexCur,fOuterSectorArray[(secCur-fkNSectorInner*2)%fkNSectorOuter][iRow-kIRowsTPC-1].GetN());
1422 // create track point from cluster
1423 SetTrackPointFromCluster(nearestCluster,nearestPoint);
1425 //Printf("Track point = %.2f %.2f %.2f",nearestPoint.GetX(),nearestPoint.GetY(),nearestPoint.GetZ());
1428 // TODO: also correction when looking for the next cluster?
1429 if (fCorrectionType != kNoCorrection){
1430 Float_t xyz[3]={0,0,0};
1431 nearestPoint.GetXYZ(xyz);
1432 fTPCCorrection->CorrectPoint(xyz, nearestCluster->GetDetector());
1433 nearestPoint.SetXYZ(xyz);
1436 // rotate the cluster to the local detector frame
1437 track->Rotate(((nearestCluster->GetDetector()%18)*20+10)*TMath::DegToRad());
1438 AliTrackPoint prot = nearestPoint.Rotate(track->GetAlpha()); // rotate to the local frame - non distoted point
1439 if (TMath::Abs(prot.GetX())<kRTPC0) continue;
1440 if (TMath::Abs(prot.GetX())>kRTPC1) continue;
1443 //Printf("Rotated Track point = %.2f %.2f %.2f",prot.GetX(),prot.GetY(),prot.GetZ());
1445 // update track with the nearest track point
1446 Bool_t res=AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
1450 if (TMath::Abs(track->GetZ())>kMaxZ) break;
1451 if (TMath::Abs(track->GetX())>kMaxR) break;
1452 //if (TMath::Abs(track->GetZ())<kZcut)continue;
1454 Double_t pointPos[2]={0,0};
1455 Double_t pointCov[3]={0,0,0};
1456 pointPos[0]=prot.GetY();//local y
1457 pointPos[1]=prot.GetZ();//local z
1458 pointCov[0]=prot.GetCov()[3];//simay^2
1459 pointCov[1]=prot.GetCov()[4];//sigmayz
1460 pointCov[2]=prot.GetCov()[5];//sigmaz^2
1462 if (!track->Update(pointPos,pointCov)) {printf("no update\n");}
1468 // propagation to refX
1469 AliTrackerBase::PropagateTrackTo(track,refX,kMass,5.,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
1471 // rotate fittet track to the frame of the original track and propagate to same reference
1472 track->Rotate(tr->GetAlpha());
1474 AliTrackerBase::PropagateTrackTo(track,refX,kMass,1.,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
1476 Printf("We have %d clusters in this track!",nClus);
1481 //____________________________________________________________________________________
1482 AliExternalTrackParam* AliToyMCReconstruction::ClusterToTrackAssociation(const AliTPCseed *seed, Int_t trackID, Int_t &nClus)
1485 // Cluster to track association for given seed on an array of clusters
1489 AliExternalTrackParam *track = new AliExternalTrackParam(*seed);
1491 const AliTPCROC * roc = AliTPCROC::Instance();
1493 const Double_t kRTPC0 = roc->GetPadRowRadii(0,0);
1494 const Double_t kRTPC1 = roc->GetPadRowRadii(36,roc->GetNRows(36)-1);
1495 const Int_t kNRowsTPC = roc->GetNRows(0) + roc->GetNRows(36) - 1;
1496 const Int_t kIRowsTPC = roc->GetNRows(0) - 1;
1497 const Double_t kMaxSnp = 0.85;
1498 const Double_t kMaxR = 500.;
1499 const Double_t kMaxZ = 500.;
1500 const Double_t roady = 0.1;
1501 const Double_t roadz = 0.01;
1503 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1505 Int_t secCur, secOld = -1;
1506 UInt_t indexCur = 0;
1507 Double_t xCur, yCur, zCur = 0.;
1509 // Float_t vDrift = GetVDrift();
1511 // first propagate seed to outermost row
1512 Bool_t res0=AliTrackerBase::PropagateTrackTo(track,kRTPC1,kMass,5,kFALSE,kMaxSnp);
1514 // Loop over rows and find the cluster candidates
1515 for( Int_t iRow = kNRowsTPC; iRow >= 0; --iRow ){
1517 // inner or outer sector
1518 Bool_t bInnerSector = kTRUE;
1519 if(iRow > kIRowsTPC) bInnerSector = kFALSE;
1521 // nearest track point/cluster (to be found)
1522 AliTrackPoint nearestPoint;
1523 AliTPCclusterMI *nearestCluster = NULL;
1528 // Propagate to center of pad row and extract parameters
1529 AliTrackerBase::PropagateTrackTo(track,roc->GetPadRowRadii(0,iRow),kMass,5,kFALSE,kMaxSnp);
1530 xCur = track->GetX();
1531 yCur = track->GetY();
1532 zCur = track->GetZ();
1533 secCur = GetSector(track);
1535 // Find the nearest cluster (TODO: correct road settings!)
1536 //Printf("inner tracking here: x = %.2f, y = %.2f, z = %.6f (Row %d Sector %d)",xCur,yCur,zCur,iRow,secCur);
1537 nearestCluster = fInnerSectorArray[secCur%fkNSectorInner][iRow].FindNearest2(yCur,zCur,roady,roadz,indexCur);
1539 // Look again at -y if nothing found here and the sector changed with respect to the last found cluster
1540 // Increase also the road in this case
1541 if(!nearestCluster && secCur != secOld && secOld > -1){
1542 //Printf("inner tracking here 2: x = %.2f, y = %.2f, z = %.6f (Row %d Sector %d)",xCur,-yCur,zCur,iRow,secCur);
1543 nearestCluster = fInnerSectorArray[secCur%fkNSectorInner][iRow].FindNearest2(-yCur,zCur,roady*100,roadz,indexCur);
1546 // Move to next row if now cluster found
1547 if(!nearestCluster) continue;
1548 //Printf("Nearest Clusters = %d (of %d) ",indexCur,fInnerSectorArray[secCur%fkNSectorInner][iRow].GetN());
1555 // Propagate to center of pad row and extract parameters
1556 AliTrackerBase::PropagateTrackTo(track,roc->GetPadRowRadii(36,iRow-kIRowsTPC-1),kMass,5,kFALSE,kMaxSnp);
1557 xCur = track->GetX();
1558 yCur = track->GetY();
1559 zCur = track->GetZ();
1560 secCur = GetSector(track);
1562 // Find the nearest cluster (TODO: correct road settings!)
1563 Printf("res0 = %d, outer tracking here: x = %.2f, y = %.2f, z = %.6f (Row %d Sector %d)",res0,xCur,yCur,zCur,iRow,secCur);
1564 nearestCluster = fOuterSectorArray[(secCur-fkNSectorInner*2)%fkNSectorOuter][iRow-kIRowsTPC-1].FindNearest2(yCur,zCur,roady,roadz,indexCur);
1566 // Look again at -y if nothing found here and the sector changed with respect to the last found cluster
1567 // Increase also the road in this case
1568 if(!nearestCluster && secCur != secOld && secOld > -1){
1569 Printf("outer tracking here 2: x = %.2f, y = %.2f, z = %.6f (Row %d Sector %d)",xCur,-yCur,zCur,iRow,secCur);
1570 nearestCluster = fOuterSectorArray[(secCur-fkNSectorInner*2)%fkNSectorOuter][iRow-kIRowsTPC-1].FindNearest2(-yCur,zCur,roady*100,roadz,indexCur);
1574 // Move to next row if now cluster found
1575 if(!nearestCluster) continue;
1576 Printf("Nearest Clusters = %d (of %d)",indexCur,fOuterSectorArray[(secCur-fkNSectorInner*2)%fkNSectorOuter][iRow-kIRowsTPC-1].GetN());
1580 // create track point from cluster
1581 SetTrackPointFromCluster(nearestCluster,nearestPoint);
1583 //Printf("Track point = %.2f %.2f %.2f",nearestPoint.GetX(),nearestPoint.GetY(),nearestPoint.GetZ());
1585 // rotate the cluster to the local detector frame
1586 track->Rotate(((nearestCluster->GetDetector()%18)*20+10)*TMath::DegToRad());
1587 AliTrackPoint prot = nearestPoint.Rotate(track->GetAlpha()); // rotate to the local frame - non distoted point
1588 if (TMath::Abs(prot.GetX())<kRTPC0) continue;
1589 if (TMath::Abs(prot.GetX())>kRTPC1) continue;
1592 //Printf("Rotated Track point = %.2f %.2f %.2f",prot.GetX(),prot.GetY(),prot.GetZ());
1594 // update track with the nearest track point
1595 Bool_t res=AliTrackerBase::PropagateTrackTo(track,prot.GetX(),kMass,5,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
1599 if (TMath::Abs(track->GetZ())>kMaxZ) break;
1600 if (TMath::Abs(track->GetX())>kMaxR) break;
1601 //if (TMath::Abs(track->GetZ())<kZcut)continue;
1603 Double_t pointPos[2]={0,0};
1604 Double_t pointCov[3]={0,0,0};
1605 pointPos[0]=prot.GetY();//local y
1606 pointPos[1]=prot.GetZ();//local z
1607 pointCov[0]=prot.GetCov()[3];//simay^2
1608 pointCov[1]=prot.GetCov()[4];//sigmayz
1609 pointCov[2]=prot.GetCov()[5];//sigmaz^2
1611 if (!track->Update(pointPos,pointCov)) {printf("no update\n");}
1614 //Printf("Cluster belongs to track = %d",nearestCluster->GetLabel(0));
1616 // only count as associate cluster if it belongs to correct track!
1617 if(nearestCluster->GetLabel(0) == trackID)
1621 Printf("We have %d clusters in this track!",nClus);
1626 //____________________________________________________________________________________
1627 void AliToyMCReconstruction::AssociateClusters(AliTPCseed &seed, Int_t firstRow, Int_t lastRow, Bool_t direction)
1630 // do cluster to track association from first to last row
1631 // direction 0: outwards; 1: inwards
1637 AliRieman rieman1(160);
1638 AliRieman rieman2(160);
1639 SetRieman(seed,rieman1);
1640 CopyRieman(rieman1,rieman2);
1642 Int_t sec=seed.GetSector();
1643 Int_t noLastPoint=0;
1644 //TODO: change to inward and outwar search?
1645 // -> better handling of non consecutive points
1651 //always from inside out
1652 if (firstRow>lastRow){
1658 for (Int_t row=firstRow; row<=lastRow && noLastPoint<3;++row) {
1659 Int_t iRow=TMath::Abs(row);
1660 const AliTPCclusterMI *cl=seed.GetClusterPointer(iRow);
1663 const Int_t secrow = iRow<63?iRow:iRow-63;
1665 AliTPCtrackerSector *arrSec=(iRow<63)?fInnerSectorArray:fOuterSectorArray;
1666 const AliTPCtrackerRow& kr = arrSec[sec%36][secrow];
1667 const Double_t maxy=arrSec[sec%36].GetMaxY(secrow);
1669 Double_t y=rieman1.GetYat(kr.GetX());
1670 Double_t z=rieman1.GetZat(kr.GetX());
1672 if (TMath::Abs(y)>maxy) {
1673 AliError("Tracking over sector boundaries not implemented, yet");
1677 AliTPCclusterMI *n=kr.FindNearest(y,z,roady,roadz);
1678 if (!n || n->IsUsed()) {
1682 // check for quality of the cluster
1684 rieman2.AddPoint(n->GetX(), n->GetY(), n->GetZ(),
1685 TMath::Sqrt(n->GetSigmaY2()), TMath::Sqrt(n->GetSigmaZ2()));
1687 // printf(" Riemann results: row=%d valid=%d, Chi2=%.2f (%.2f) %d (%d)",
1688 // iRow, rieman2.IsValid(), rieman2.GetChi2(), rieman1.GetChi2(), n->GetLabel(0),seed.GetLabel());
1689 Double_t limit=2*rieman1.GetChi2();
1690 if (fClusterType==0) limit=1000;
1691 if (rieman2.GetChi2()>limit) {
1692 CopyRieman(rieman1,rieman2);
1697 // printf(" +++ \n");
1701 rieman1.AddPoint(n->GetX(), n->GetY(), n->GetZ(),
1702 TMath::Sqrt(n->GetSigmaY2()), TMath::Sqrt(n->GetSigmaZ2()));
1705 seed.SetClusterPointer(iRow,n);
1706 // if (iRow<seed.GetSeed1()) seed.SetSeed1(iRow);
1707 // if (iRow>seed.GetSeed2()) seed.SetSeed2(iRow);
1713 //____________________________________________________________________________________
1714 void AliToyMCReconstruction::ClusterToTrackAssociation(AliTPCseed &seed)
1720 // printf("\n ============ \nnext Seed: %d\n",seed.GetLabel());
1721 //assume seed is within one sector
1722 Int_t iMiddle=(seed.GetSeed1()+seed.GetSeed2())/2;
1724 AssociateClusters(seed,iMiddle+1,158,kFALSE);
1726 AssociateClusters(seed,0,iMiddle,kTRUE);
1727 seed.SetIsSeeding(kFALSE);
1729 CookLabel(&seed,.6);
1733 //____________________________________________________________________________________
1734 void AliToyMCReconstruction::InitSpaceCharge()
1737 // Init the space charge map
1740 TString filename="$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps5_50kHz_precal.root";
1742 TList *l=fTree->GetUserInfo();
1743 for (Int_t i=0; i<l->GetEntries(); ++i) {
1744 TString s(l->At(i)->GetName());
1745 if (s.Contains("SC_")) {
1752 printf("Initialising the space charge map using the file: '%s'\n",filename.Data());
1753 TFile f(filename.Data());
1754 fTPCCorrection=(AliTPCCorrection*)f.Get("map");
1756 // fTPCCorrection = new AliTPCSpaceCharge3D();
1757 // fTPCCorrection->SetSCDataFileName("$ALICE_ROOT/TPC/Calib/maps/SC_NeCO2_eps10_50kHz.root");
1758 // fTPCCorrection->SetOmegaTauT1T2(0.325,1,1); // Ne CO2
1759 // // fTPCCorrection->SetOmegaTauT1T2(0.41,1,1.05); // Ar CO2
1760 // fTPCCorrection->InitSpaceCharge3DDistortion();
1764 //____________________________________________________________________________________
1765 Double_t AliToyMCReconstruction::GetVDrift() const
1770 return fTPCParam->GetDriftV();
1773 //____________________________________________________________________________________
1774 Double_t AliToyMCReconstruction::GetZLength(Int_t roc) const
1779 if (roc<0 || roc>71) return -1;
1780 return fTPCParam->GetZLength(roc);
1783 //____________________________________________________________________________________
1784 TTree* AliToyMCReconstruction::ConnectTrees (const char* files) {
1785 TString s=gSystem->GetFromPipe(Form("ls %s",files));
1788 TObjArray *arrFiles=s.Tokenize("\n");
1790 for (Int_t ifile=0; ifile<arrFiles->GetEntriesFast(); ++ifile){
1791 TString name(arrFiles->At(ifile)->GetName());
1793 TPRegexp reg(".*([0-9]_[0-9]_[0-9]_[0-9]{3}_[0-9]{2}).debug.root");
1794 TObjArray *arrMatch=0x0;
1795 arrMatch=reg.MatchS(name);
1797 if (arrMatch && arrMatch->At(1)) matchName=arrMatch->At(1)->GetName();
1798 else matchName=Form("%02d",ifile);
1802 TFile *f=TFile::Open(name.Data());
1804 TTree *t=(TTree*)f->Get("Tracks");
1810 t->SetName(matchName.Data());
1813 tFirst->AddFriend(Form("t%s=Tracks",matchName.Data()), name.Data());
1814 // tFirst->AddFriend(Form("t%d=Tracks",ifile), name.Data());
1818 if (tFirst->GetListOfFriends()) tFirst->GetListOfFriends()->Print();
1822 //____________________________________________________________________________________
1823 Int_t AliToyMCReconstruction::LoadOuterSectors() {
1824 //-----------------------------------------------------------------
1825 // This function fills outer TPC sectors with clusters.
1826 // Copy and paste from AliTPCtracker
1827 //-----------------------------------------------------------------
1828 Int_t nrows = fOuterSectorArray->GetNRows();
1830 for (Int_t sec = 0;sec<fkNSectorOuter;sec++)
1831 for (Int_t row = 0;row<nrows;row++){
1832 AliTPCtrackerRow* tpcrow = &(fOuterSectorArray[sec%fkNSectorOuter][row]);
1833 Int_t sec2 = sec+2*fkNSectorInner;
1835 Int_t ncl = tpcrow->GetN1();
1837 AliTPCclusterMI *c= (tpcrow->GetCluster1(ncl));
1838 index=(((sec2<<8)+row)<<16)+ncl;
1839 tpcrow->InsertCluster(c,index);
1842 ncl = tpcrow->GetN2();
1844 AliTPCclusterMI *c= (tpcrow->GetCluster2(ncl));
1845 index=((((sec2+fkNSectorOuter)<<8)+row)<<16)+ncl;
1846 tpcrow->InsertCluster(c,index);
1849 // write indexes for fast acces
1851 for (Int_t i=0;i<510;i++)
1852 tpcrow->SetFastCluster(i,-1);
1853 for (Int_t i=0;i<tpcrow->GetN();i++){
1854 Int_t zi = Int_t((*tpcrow)[i]->GetZ()+255.);
1855 tpcrow->SetFastCluster(zi,i); // write index
1858 for (Int_t i=0;i<510;i++){
1859 if (tpcrow->GetFastCluster(i)<0)
1860 tpcrow->SetFastCluster(i,last);
1862 last = tpcrow->GetFastCluster(i);
1869 //____________________________________________________________________________________
1870 Int_t AliToyMCReconstruction::LoadInnerSectors() {
1871 //-----------------------------------------------------------------
1872 // This function fills inner TPC sectors with clusters.
1873 // Copy and paste from AliTPCtracker
1874 //-----------------------------------------------------------------
1875 Int_t nrows = fInnerSectorArray->GetNRows();
1877 for (Int_t sec = 0;sec<fkNSectorInner;sec++)
1878 for (Int_t row = 0;row<nrows;row++){
1879 AliTPCtrackerRow* tpcrow = &(fInnerSectorArray[sec%fkNSectorInner][row]);
1882 Int_t ncl = tpcrow->GetN1();
1884 AliTPCclusterMI *c= (tpcrow->GetCluster1(ncl));
1885 index=(((sec<<8)+row)<<16)+ncl;
1886 tpcrow->InsertCluster(c,index);
1889 ncl = tpcrow->GetN2();
1891 AliTPCclusterMI *c= (tpcrow->GetCluster2(ncl));
1892 index=((((sec+fkNSectorInner)<<8)+row)<<16)+ncl;
1893 tpcrow->InsertCluster(c,index);
1896 // write indexes for fast acces
1898 for (Int_t i=0;i<510;i++)
1899 tpcrow->SetFastCluster(i,-1);
1900 for (Int_t i=0;i<tpcrow->GetN();i++){
1901 Int_t zi = Int_t((*tpcrow)[i]->GetZ()+255.);
1902 tpcrow->SetFastCluster(zi,i); // write index
1905 for (Int_t i=0;i<510;i++){
1906 if (tpcrow->GetFastCluster(i)<0)
1907 tpcrow->SetFastCluster(i,last);
1909 last = tpcrow->GetFastCluster(i);
1916 //____________________________________________________________________________________
1917 Int_t AliToyMCReconstruction::GetSector(AliExternalTrackParam *track) {
1918 //-----------------------------------------------------------------
1919 // This function returns the sector number for a given track
1920 //-----------------------------------------------------------------
1924 // get the sector number
1925 // rotate point to global system (track is already global!)
1928 //track->Local2GlobalPosition(xd,track->GetAlpha());
1930 // use TPCParams to get the sector number
1931 Float_t xyz[3] = {xd[0],xd[1],xd[2]};
1932 Int_t i[3] = {0,0,0};
1934 sector = fTPCParam->Transform0to1(xyz,i);
1940 //____________________________________________________________________________________
1941 void AliToyMCReconstruction::FillSectorStructure(Int_t maxev) {
1942 //-----------------------------------------------------------------
1943 // This function fills the sector structure of AliToyMCReconstruction
1944 //-----------------------------------------------------------------
1946 // cluster array of all sectors
1947 fInnerSectorArray = new AliTPCtrackerSector[fkNSectorInner];
1948 fOuterSectorArray = new AliTPCtrackerSector[fkNSectorOuter];
1950 for (Int_t i=0; i<fkNSectorInner; ++i) fInnerSectorArray[i].Setup(fTPCParam,0);
1951 for (Int_t i=0; i<fkNSectorOuter; ++i) fOuterSectorArray[i].Setup(fTPCParam,1);
1953 Int_t count[72][96] = { {0} , {0} };
1955 for (Int_t iev=0; iev<maxev; ++iev){
1956 printf("============== Fill Clusters: Processing Event %6d =================\n",iev);
1957 fTree->GetEvent(iev);
1958 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks(); ++itr){
1959 printf(" > ====== Fill Clusters: Processing Track %6d ======== \n",itr);
1960 const AliToyMCTrack *tr=fEvent->GetTrack(itr);
1962 // number of clusters to loop over
1963 const Int_t ncls=(fClusterType==0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
1965 for(Int_t icl=0; icl<ncls; ++icl){
1967 AliTPCclusterMI *cl=const_cast<AliTPCclusterMI *>(tr->GetSpacePoint(icl));
1968 if (fClusterType==1) cl=const_cast<AliTPCclusterMI *>(tr->GetDistortedSpacePoint(icl));
1971 Int_t sec = cl->GetDetector();
1972 Int_t row = cl->GetRow();
1974 // set Q of the cluster to 1, Q==0 does not work for the seeding
1977 // set cluster time to cluster Z (if not ideal tracking)
1978 if ( !fIdealTracking ) {
1979 // a 'valid' position in z is needed for the seeding procedure
1980 // cl->SetZ(cl->GetTimeBin()*GetVDrift());
1981 cl->SetZ(cl->GetTimeBin());
1983 //Printf("Fill clusters (sector %d row %d): %.2f %.2f %.2f %.2f",sec,row,cl->GetX(),cl->GetY(),cl->GetZ(),cl->GetTimeBin());
1985 // fill arrays for inner and outer sectors (A/C side handled internally)
1986 if (sec<fkNSectorInner*2){
1987 fInnerSectorArray[sec%fkNSectorInner].InsertCluster(cl, count[sec][row], fTPCParam);
1990 fOuterSectorArray[(sec-fkNSectorInner*2)%fkNSectorOuter].InsertCluster(cl, count[sec][row], fTPCParam);
1998 // fill the arrays completely
1999 // LoadOuterSectors();
2000 // LoadInnerSectors();
2002 // // check the arrays
2003 // for (Int_t i=0; i<fkNSectorInner; ++i){
2004 // for (Int_t j=0; j<fInnerSectorArray[i].GetNRows(); ++j){
2005 // if(fInnerSectorArray[i][j].GetN()>0){
2006 // Printf("Inner: Sector %d Row %d : %d",i,j,fInnerSectorArray[i][j].GetN());
2010 // for (Int_t i=0; i<fkNSectorInner; ++i){
2011 // for (Int_t j=0; j<fOuterSectorArray[i].GetNRows(); ++j){
2012 // if(fOuterSectorArray[i][j].GetN()>0){
2013 // Printf("Outer: Sector %d Row %d : %d",i,j,fOuterSectorArray[i][j].GetN());
2019 //____________________________________________________________________________________
2020 void AliToyMCReconstruction::FillSectorStructureAC() {
2021 //-----------------------------------------------------------------
2022 // This function fills the sector structure of AliToyMCReconstruction
2023 //-----------------------------------------------------------------
2026 my god is the AliTPCtrackerSector stuff complicated!!!
2027 Ok, so here we will not fill the fClusters1 and fClusters2 of AliTPCtrackerRow,
2028 using InsertCluster of AliTPCtrackerSector, but only the fClusters via InsertCluster
2029 of AliTPCtrackerRow itself which then will not be owner, but we create an array in
2030 here (fAllClusters) which owns all clusters ...
2034 // cluster array of all sectors
2035 fInnerSectorArray = new AliTPCtrackerSector[2*fkNSectorInner];
2036 fOuterSectorArray = new AliTPCtrackerSector[2*fkNSectorOuter];
2038 for (Int_t i=0; i<2*fkNSectorInner; ++i) {
2039 fInnerSectorArray[i].Setup(fTPCParam,0);
2042 for (Int_t i=0; i<2*fkNSectorOuter; ++i) {
2043 fOuterSectorArray[i].Setup(fTPCParam,1);
2046 Int_t count[72][96] = { {0} , {0} };
2048 for (Int_t iev=0; iev<fNmaxEvents; ++iev){
2049 printf("============== Fill Clusters: Processing Event %6d =================\n",iev);
2050 fTree->GetEvent(iev);
2051 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks(); ++itr){
2052 // printf(" > ====== Fill Clusters: Processing Track %6d ======== \n",itr);
2053 const AliToyMCTrack *tr=fEvent->GetTrack(itr);
2055 // number of clusters to loop over
2056 const Int_t ncls=(fClusterType==0)?tr->GetNumberOfSpacePoints():tr->GetNumberOfDistSpacePoints();
2058 // check if expansion of the cluster arrays is needed.
2059 if (fAllClusters.GetEntriesFast()+ncls>=fAllClusters.Capacity()) fAllClusters.Expand(2*fAllClusters.Capacity());
2060 for(Int_t icl=0; icl<ncls; ++icl){
2062 AliTPCclusterMI *cl=const_cast<AliTPCclusterMI *>(tr->GetSpacePoint(icl));
2063 if (fClusterType==1) cl=const_cast<AliTPCclusterMI *>(tr->GetDistortedSpacePoint(icl));
2066 // register copy to the cluster array
2067 cl = new(fAllClusters[fAllClusters.GetEntriesFast()]) AliTPCclusterMI(*cl);
2069 Int_t sec = cl->GetDetector();
2070 Int_t row = cl->GetRow();
2072 // set Q of the cluster to 1, Q==0 does not work for the seeding
2075 // set cluster time to cluster Z (if not ideal tracking)
2076 if ( !fIdealTracking ) {
2077 // a 'valid' position in z is needed for the seeding procedure
2079 if (((sec/18)%2)==1) sign=-1;
2080 cl->SetZ(cl->GetTimeBin()*GetVDrift());
2081 //mark cluster to be time*vDrift by setting the type to 1
2083 // cl->SetZ(cl->GetTimeBin());
2085 //Printf("Fill clusters (sector %d row %d): %.2f %.2f %.2f %.2f",sec,row,cl->GetX(),cl->GetY(),cl->GetZ(),cl->GetTimeBin());
2087 // fill arrays for inner and outer sectors (A/C side handled internally)
2088 if (sec<fkNSectorInner*2){
2089 fInnerSectorArray[sec][row].InsertCluster(cl, count[sec][row]);
2092 fOuterSectorArray[(sec-fkNSectorInner*2)][row].InsertCluster(cl, count[sec][row]);
2102 //____________________________________________________________________________________
2103 AliToyMCTrack *AliToyMCReconstruction::ConvertTPCSeedToToyMCTrack(const AliTPCseed &seed)
2110 AliToyMCTrack *tToy = new AliToyMCTrack(seed);
2112 for (Int_t icl=0; icl<159; ++icl){
2113 const AliTPCclusterMI *cl=seed.GetClusterFast(icl);
2115 if (fClusterType==0){
2116 tToy->AddSpacePoint(*cl);
2118 tToy->AddDistortedSpacePoint(*cl);
2125 //____________________________________________________________________________________
2126 AliExternalTrackParam* AliToyMCReconstruction::GetRefittedTrack(const AliTPCseed &seed)
2132 AliExternalTrackParam *track=0x0;
2134 const Float_t vDrift=GetVDrift();
2135 const Float_t zLength=GetZLength(0);
2136 const Double_t kMaxSnp = 0.85;
2137 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
2139 AliToyMCTrack *toyTrack = ConvertTPCSeedToToyMCTrack(seed);
2144 fCreateT0seed = kTRUE;
2145 AliExternalTrackParam *t0seed = GetSeedFromTrack(toyTrack,kTRUE);
2146 if (!t0seed) return 0x0;
2148 fTime0 = t0seed->GetZ()-zLength/vDrift;
2152 fCreateT0seed = kFALSE;
2153 AliExternalTrackParam *dummy = GetSeedFromTrack(toyTrack,kTRUE);
2154 track = GetFittedTrackFromSeed(toyTrack, dummy);
2156 // propagate seed to 0
2157 AliTrackerBase::PropagateTrackTo(track,0,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
2162 //____________________________________________________________________________________
2163 AliTPCclusterMI* AliToyMCReconstruction::FindMiddleCluster(const AliTPCclusterMI *clInner, const AliTPCclusterMI *clOuter,
2164 Double_t roady, Double_t roadz,
2171 const Int_t rocInner = clInner->GetDetector();
2172 const Int_t rocOuter = clOuter->GetDetector();
2174 if ( (rocInner%18) != (rocOuter%18) ){
2175 AliError("Currently only same Sector implemented");
2179 const Int_t innerDet=clInner->GetDetector();
2180 const Int_t outerDet=clOuter->GetDetector();
2181 const Int_t globalRowInner = clInner->GetRow() +(innerDet >35)*63;
2182 const Int_t globalRowOuter = clOuter->GetRow() +(outerDet >35)*63;
2184 AliTPCclusterMI *n=0x0;
2186 // allow flexibility of +- nRowsGrace Rows to find a middle cluster
2187 const Int_t nRowsGrace = 0;
2188 for (Int_t iter=0; iter<2*nRowsGrace+1; ++iter){
2189 Int_t iMiddle = (globalRowInner+globalRowOuter)/2;
2190 iMiddle+=((iter+1)/2)*(1-2*((iter+1)%2));
2192 Int_t localRow=iMiddle;
2193 Int_t roc = innerDet;
2199 AliTPCtrackerSector *arrRow=(iMiddle<63)?fInnerSectorArray:fOuterSectorArray;
2200 const AliTPCtrackerRow& krMiddle = arrRow[roc%36][localRow]; // middle
2201 // initial guess use simple linear interpolation
2202 Double_t y=(clInner->GetY()+clOuter->GetY())/2;
2203 Double_t z=(clInner->GetZ()+clOuter->GetZ())/2;
2204 if (seedFit.IsValid()) {
2205 // update values once the fit was performed
2206 y=seedFit.GetYat(krMiddle.GetX());
2207 z=seedFit.GetZat(krMiddle.GetX());
2210 n=krMiddle.FindNearest(y,z,roady,roadz);
2215 // printf(" Nearest cluster (%.2f, %.2f, %.2f) = m(%.2f, %.2f, %.2f : %d) i(%.2f, %.2f , %.2f : %d) o(%.2f, %.2f, %.2f : %d)\n",krMiddle.GetX(),y,z,
2216 // n->GetX(), n->GetY(),n->GetZ(),n->GetLabel(0),
2217 // clInner->GetX(), clInner->GetY(),clInner->GetZ(),clInner->GetLabel(0),
2218 // clOuter->GetX(), clOuter->GetY(),clOuter->GetZ(),clOuter->GetLabel(0)
2223 //____________________________________________________________________________________
2224 void AliToyMCReconstruction::AddMiddleClusters(AliTPCseed *seed,
2225 const AliTPCclusterMI *clInner, const AliTPCclusterMI *clOuter,
2226 Double_t roady, Double_t roadz,
2227 Int_t &nTotalClusters, AliRieman &seedFit)
2230 // Iteratively add the middle clusters
2233 // update rieman fit with every second point added
2234 AliTPCclusterMI *clMiddle=FindMiddleCluster(clInner,clOuter,roady,roadz,seedFit);
2236 // break iterative process
2237 if (!clMiddle || clMiddle->IsUsed()) return;
2239 const Int_t globalRowInner = clInner->GetRow() +(clInner->GetDetector() >35)*63;
2240 const Int_t globalRowMiddle = clMiddle->GetRow()+(clMiddle->GetDetector()>35)*63;
2241 const Int_t globalRowOuter = clOuter->GetRow() +(clOuter->GetDetector() >35)*63;
2243 seed->SetClusterPointer(globalRowMiddle,clMiddle);
2245 // printf(" > Total clusters: %d\n",nTotalClusters);
2246 seedFit.AddPoint(clMiddle->GetX(), clMiddle->GetY(), clMiddle->GetZ(),
2247 TMath::Sqrt(clMiddle->GetSigmaY2()), TMath::Sqrt(clMiddle->GetSigmaZ2()));
2249 if (seedFit.GetN()>3) {
2250 // printf(" call update: %d (%d)\n",seedFit.GetN(),nTotalClusters);
2251 // printf(" Riemann results: valid=%d, Chi2=%.2f, Chi2Y=%.2f, Chi2Z=%.2f -- %d\n",
2252 // seedFit.IsValid(), seedFit.GetChi2(), seedFit.GetChi2Y(), seedFit.GetChi2Z(), clMiddle->GetLabel(0));
2255 if ( seedFit.IsValid() && seedFit.GetChi2()>1000 ) return;
2257 // Add middle clusters towards outer radius
2258 if (globalRowMiddle+1<globalRowOuter) AddMiddleClusters(seed,clMiddle,clOuter,roady,roadz,nTotalClusters,seedFit);
2260 // Add middle clusters towards innter radius
2261 if (globalRowInner+1<globalRowMiddle) AddMiddleClusters(seed,clInner,clMiddle,roady,roadz,nTotalClusters,seedFit);
2266 //____________________________________________________________________________________
2267 Int_t AliToyMCReconstruction::MakeSeeds2(TObjArray * arr, Int_t sec, Int_t iRowInner, Int_t iRowOuter)
2270 // find seeds in a sector, requires iRowInner < iRowOuter
2271 // iRowXXX runs from 0-159, so over IROC and OROC
2275 AliError("This function requires the sector arrays filled for AC tracking");
2279 // swap rows in case they are in the wrong order
2280 if (iRowInner>iRowOuter) {
2281 Int_t tmp=iRowInner;
2282 iRowInner=iRowOuter;
2286 if (iRowOuter>158) iRowOuter=158;
2287 if (iRowInner<0) iRowInner=0;
2289 // Define the search roads:
2290 // timeRoadCombinatorics - the maximum time difference used for the
2291 // combinatorics. Since we don't have a 'z-Vertex' estimate this will
2292 // reduce the combinatorics significantly when iterating on one TF
2293 // use a little more than one full drift length of the TPC to allow for
2296 // timeRoad - the time difference allowed when associating the cluster
2297 // in the middle of the other two used for the initial search
2299 // padRoad - the local y difference allowed when associating the middle cluster
2301 // Double_t timeRoadCombinatorics = 270./vDrift;
2302 // Double_t timeRoad = 20./vDrift;
2303 Double_t timeRoadCombinatorics = 270.;
2304 Double_t timeRoad = 10.;
2305 Double_t padRoad = 5.;
2308 // fOuterSectorArray runs from 0-95, so from iRowXXX which runs from 0-159
2309 // the number of rows in the IROC has to be subtracted
2310 const Int_t innerRows=fInnerSectorArray->GetNRows();
2312 AliTPCtrackerSector *arrInnerRow=(iRowInner<63)?fInnerSectorArray:fOuterSectorArray;
2313 AliTPCtrackerSector *arrOuterRow=(iRowOuter<63)?fInnerSectorArray:fOuterSectorArray;
2315 const AliTPCtrackerRow& krInner = arrInnerRow[sec][iRowInner - (iRowInner>62)*innerRows]; // up
2316 const AliTPCtrackerRow& krOuter = arrOuterRow[sec][iRowOuter - (iRowOuter>62)*innerRows]; // down
2318 AliTPCseed *seed = new AliTPCseed;
2320 const Int_t nMaxClusters=iRowOuter-iRowInner+1;
2321 // Int_t nScannedClusters = 0;
2324 // loop over all points in the firstand last search row
2325 for (Int_t iOuter=0; iOuter < krOuter; iOuter++) {
2326 const AliTPCclusterMI *clOuter = krOuter[iOuter];
2327 if (clOuter->IsUsed()) continue;
2328 for (Int_t iInner=0; iInner < krInner; iInner++) {
2329 const AliTPCclusterMI *clInner = krInner[iInner];
2330 if (clInner->IsUsed()) continue;
2331 // printf("\n\n Check combination %d (%d), %d (%d) -- %d (%d) -- %d\n",iOuter, iInner, clOuter->GetLabel(0), clInner->GetLabel(0),iRowOuter,iRowInner,sec);
2332 // check maximum distance for combinatorics
2333 if (TMath::Abs(clOuter->GetZ()-clInner->GetZ())>timeRoadCombinatorics) continue;
2334 // printf(" Is inside one drift\n");
2336 // use rieman fit for seed description
2337 AliRieman seedFit(159);
2338 // add first two points
2339 seedFit.AddPoint(clInner->GetX(), clInner->GetY(), clInner->GetZ(),
2340 TMath::Sqrt(clInner->GetSigmaY2()), TMath::Sqrt(clInner->GetSigmaZ2()));
2341 seedFit.AddPoint(clOuter->GetX(), clOuter->GetY(), clOuter->GetZ(),
2342 TMath::Sqrt(clOuter->GetSigmaY2()), TMath::Sqrt(clOuter->GetSigmaZ2()));
2344 // Iteratively add all clusters in the respective middle
2345 Int_t nFoundClusters=2;
2346 AddMiddleClusters(seed,clInner,clOuter,padRoad,timeRoad,nFoundClusters,seedFit);
2347 // printf(" Clusters attached: %d\n",nFoundClusters);
2348 if (nFoundClusters>2) seedFit.Update();
2349 // printf(" Riemann results: valid=%d, Chi2=%.2f, Chi2Y=%.2f, Chi2Z=%.2f\n",
2350 // seedFit.IsValid(), seedFit.GetChi2(), seedFit.GetChi2Y(), seedFit.GetChi2Z());
2352 // check for minimum number of assigned clusters and a decent chi2
2353 if ( nFoundClusters<0.5*nMaxClusters || seedFit.GetChi2()>1000 ){
2357 // printf(" >>> Seed accepted\n");
2358 // add original outer clusters
2359 const Int_t globalRowInner = clInner->GetRow() +(clInner->GetDetector() >35)*63;
2360 const Int_t globalRowOuter = clOuter->GetRow() +(clOuter->GetDetector() >35)*63;
2362 seed->SetClusterPointer(globalRowInner,const_cast<AliTPCclusterMI*>(clInner));
2363 seed->SetClusterPointer(globalRowOuter,const_cast<AliTPCclusterMI*>(clOuter));
2365 // set parameters retrieved from AliRieman
2366 Double_t params[5]={0};
2367 Double_t covar[15]={0};
2368 const Double_t alpha=TMath::DegToRad()*(clInner->GetDetector()%18*20.+10.);
2369 const Double_t x=clInner->GetX();
2370 seedFit.GetExternalParameters(x,params,covar);
2372 seed->Set(x,alpha,params,covar);
2374 // set label of the seed. At least 60% of the clusters need the correct label
2376 // printf(" - Label: %d\n",seed->GetLabel());
2377 // mark clusters as being used
2378 MarkClustersUsed(seed);
2380 seed->SetSeed1(iRowInner);
2381 seed->SetSeed2(iRowOuter);
2382 seed->SetSector(sec);
2385 seed->SetUniqueID(arr->GetEntriesFast());
2386 seed->SetIsSeeding(kTRUE);
2389 seed=new AliTPCseed;
2394 //delete surplus seed
2400 //____________________________________________________________________________________
2401 void AliToyMCReconstruction::MakeSeeds(TObjArray * /*arr*/, Int_t sec, Int_t iRow1, Int_t iRow2)
2404 // Create seeds between i1 and i2 (stored in arr) with TLinearFitter
2406 // sec: sector number
2412 static TLinearFitter fitter(3,"pol2");
2414 // Get 3 padrows (iRow1,iMiddle=(iRow1+iRow2)/2,iRow2)
2415 Int_t iMiddle = (iRow1+iRow2)/2;
2416 const AliTPCtrackerRow& krd = fOuterSectorArray[sec][iRow2-fInnerSectorArray->GetNRows()]; // down
2417 const AliTPCtrackerRow& krm = fOuterSectorArray[sec][iMiddle-fInnerSectorArray->GetNRows()]; // middle
2418 const AliTPCtrackerRow& kru = fOuterSectorArray[sec][iRow1-fInnerSectorArray->GetNRows()]; // up
2420 // Loop over 3 cluster possibilities
2421 for (Int_t iu=0; iu < kru; iu++) {
2422 for (Int_t im=0; im < krm; im++) {
2423 for (Int_t id=0; id < krd; id++) {
2426 fitter.ClearPoints();
2428 // add all three points to fitter
2429 Double_t xy[2] = {kru[iu]->GetX(),kru[iu]->GetY()};
2430 Double_t z = kru[iu]->GetZ();
2431 fitter.AddPoint(xy,z);
2433 xy[0] = krm[im]->GetX();
2434 xy[1] = krm[im]->GetY();
2435 z = krm[im]->GetZ();
2436 fitter.AddPoint(xy,z);
2438 xy[0] = krd[id]->GetX();
2439 xy[1] = krd[id]->GetY();
2440 z = krd[id]->GetZ();
2441 fitter.AddPoint(xy,z);
2443 // Evaluate and get parameters
2446 // how to get the other clusters now?
2454 //____________________________________________________________________________________
2455 void AliToyMCReconstruction::InitStreamer(TString addName, Int_t level)
2458 // initilise the debug streamer and set the logging level
2459 // use a default naming convention
2465 if (addName.IsNull()) addName=".dummy";
2469 TString debugName=gSystem->BaseName(fInputFile->GetName());
2470 debugName.ReplaceAll(".root","");
2471 debugName.Append(Form(".%1d.%1d_%1d_%1d_%03d_%02d",
2472 fUseMaterial,fIdealTracking,fClusterType,
2473 Int_t(fCorrectionType),fSeedingRow,fSeedingDist));
2474 debugName.Append(addName);
2475 debugName.Append(".root");
2477 gSystem->Exec(Form("test -f %s && rm %s", debugName.Data(), debugName.Data()));
2478 fStreamer=new TTreeSRedirector(debugName.Data());
2479 fStreamer->SetUniqueID(level);
2484 //____________________________________________________________________________________
2485 void AliToyMCReconstruction::ConnectInputFile(const char* file, Int_t nmaxEv)
2488 // connect the tree and event pointer from the input file
2496 fInputFile=TFile::Open(file);
2497 if (!fInputFile || !fInputFile->IsOpen() || fInputFile->IsZombie()) {
2500 AliError(Form("ERROR: couldn't open the file '%s'\n", file));
2504 fTree=(TTree*)fInputFile->Get("toyMCtree");
2506 AliError(Form("ERROR: couldn't read the 'toyMCtree' from file '%s'\n", file));
2511 fTree->SetBranchAddress("event",&fEvent);
2515 fNmaxEvents=fTree->GetEntries();
2516 if (nmaxEv>-1) fNmaxEvents=TMath::Min(nmaxEv,fNmaxEvents);
2518 // setup space charge map from Userinfo of the tree
2521 // setup the track maps
2525 //____________________________________________________________________________________
2526 void AliToyMCReconstruction::Cleanup()
2529 // Cleanup input data
2532 if (fStreamer) delete fStreamer;
2546 //____________________________________________________________________________________
2547 void AliToyMCReconstruction::SetupTrackMaps()
2553 fMapTrackEvent.Delete();
2554 fMapTrackTrackInEvent.Delete();
2557 AliError("Tree not connected");
2561 Int_t nmaxEv=fTree->GetEntries();
2562 if (fNmaxEvents>-1) nmaxEv=fNmaxEvents;
2564 for (Int_t iev=0; iev<nmaxEv; ++iev) {
2565 fTree->GetEvent(iev);
2566 if (!fEvent) continue;
2568 const Int_t ntracks=fEvent->GetNumberOfTracks();
2569 if (fMapTrackEvent.GetSize()+ntracks>=fMapTrackEvent.Capacity()) fMapTrackEvent.Expand(2*fMapTrackEvent.Capacity());
2570 if (fMapTrackTrackInEvent.GetSize()+ntracks>=fMapTrackTrackInEvent.Capacity()) fMapTrackTrackInEvent.Expand(2*fMapTrackTrackInEvent.Capacity());
2572 for (Int_t itrack=0; itrack<ntracks; ++itrack){
2573 Int_t label=fEvent->GetTrack(itrack)->GetUniqueID();
2575 fMapTrackEvent.Add(label,iev);
2576 fMapTrackTrackInEvent.Add(label,itrack);
2582 //____________________________________________________________________________________
2583 void AliToyMCReconstruction::CookLabel(AliTPCseed *seed, Double_t fraction, Int_t info[5])
2589 Int_t labels[159]={0};
2590 // Long64_t posMaxLabel=-1;
2591 Int_t nMaxLabel=0; // clusters from maximum label
2592 Int_t nMaxLabel2=0; // clusters from second maximum
2594 Int_t maxLabel=-1; // label with most clusters
2595 Int_t maxLabel2=-1; // label with second most clusters
2597 TExMap labelMap(159);
2599 for (Int_t icl=0; icl<159; ++icl) {
2600 const AliTPCclusterMI *cl=seed->GetClusterPointer(icl);
2604 const Int_t clLabel=cl->GetLabel(0);
2605 // a not assinged value returns 0, so we need to add 1 and subtract it afterwards
2606 Long64_t labelPos=labelMap.GetValue(clLabel);
2610 labelMap.Add(clLabel,labelPos);
2615 const Int_t nCurrentLabel=++labels[labelPos];
2616 if (nCurrentLabel>nMaxLabel) {
2617 nMaxLabel2=nMaxLabel;
2618 nMaxLabel=nCurrentLabel;
2619 // posMaxLabel=labelPos;
2625 if (Double_t(nMaxLabel)/nclusters<fraction) maxLabel=-maxLabel;
2627 seed->SetLabel(maxLabel);
2639 //____________________________________________________________________________________
2640 void AliToyMCReconstruction::DumpSeedInfo(TObjArray *arr)
2644 if (!fStreamer || !fTree) return;
2645 // swap rows in case they are in the wrong order
2646 AliInfo(Form("Number of Seeds: %d (out of %d tracks)",arr->GetEntriesFast(),fMapTrackEvent.GetSize()));
2648 //loop over all events and tracks and try to associate the seed to the track
2649 for (Int_t iseed=0; iseed<arr->GetEntriesFast(); ++iseed){
2650 AliTPCseed *seed = static_cast<AliTPCseed*>(arr->UncheckedAt(iseed));
2652 // get original track
2653 Int_t seedLabel=seed->GetLabel();
2654 Int_t iev=fMapTrackEvent.GetValue(TMath::Abs(seedLabel));
2655 Int_t itr=fMapTrackTrackInEvent.GetValue(TMath::Abs(seedLabel));
2657 fTree->GetEvent(iev);
2658 const AliToyMCTrack *toyTrack = fEvent->GetTrack(itr);
2660 DumpSeedInfo(toyTrack,seed);
2664 //____________________________________________________________________________________
2665 void AliToyMCReconstruction::DumpTrackInfo(TObjArray *arr)
2669 if (!fStreamer || !fTree) return;
2670 // swap rows in case they are in the wrong order
2671 AliInfo(Form("Number of Seeds: %d (out of %d tracks)",arr->GetEntriesFast(),fMapTrackEvent.GetSize()));
2673 //loop over all events and tracks and try to associate the seed to the track
2674 AliTPCseed dummySeed;
2675 for (Int_t iev=0; iev<fNmaxEvents; ++iev) {
2676 fTree->GetEvent(iev);
2677 const Int_t ntracks=fEvent->GetNumberOfTracks();
2678 for (Int_t itr=0; itr<ntracks; ++itr) {
2679 const AliToyMCTrack *toyTrack = fEvent->GetTrack(itr);
2681 Bool_t foundSeed=kFALSE;
2682 for (Int_t iseed=0; iseed<arr->GetEntriesFast(); ++iseed) {
2683 AliTPCseed *seed = static_cast<AliTPCseed*>(arr->UncheckedAt(iseed));
2684 const UInt_t tmpLabel=TMath::Abs(seed->GetLabel());
2685 if (toyTrack->GetUniqueID()!=tmpLabel) continue;
2687 // dump all seeds with the correct label
2688 DumpSeedInfo(toyTrack,seed);
2692 if (!foundSeed) DumpSeedInfo(toyTrack,&dummySeed);
2698 //____________________________________________________________________________________
2699 void AliToyMCReconstruction::DumpSeedInfo(const AliToyMCTrack *toyTrack, AliTPCseed *seed)
2705 const Double_t kMaxSnp = 0.85;
2706 const Double_t kMass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
2707 Float_t vDrift=GetVDrift();
2708 Float_t zLength=GetZLength(0);
2710 AliExternalTrackParam tOrig(*toyTrack);
2711 AliExternalTrackParam tOrigITS(*toyTrack);
2713 // propagate original track to ITS last layer
2714 // Double_t lastLayerITS = 43.0; // same as in AliToyMCEventGenerator::MakeITSClusters (hard coded)
2715 const Double_t iFCRadius = 83.5; //radius constants found in AliTPCCorrection.cxx
2716 Double_t lastLayerITS = iFCRadius; // its track propgated to inner TPC wall
2717 AliTrackerBase::PropagateTrackTo(&tOrigITS,lastLayerITS,kMass,1,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
2719 AliExternalTrackParam dummyParam;
2720 Bool_t isDummy=kFALSE;
2721 //create refitted track, this will also set the fTime0
2722 AliExternalTrackParam *track=GetRefittedTrack(*seed);
2727 AliTrackerBase::PropagateTrackTo(track,0,kMass,5.,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
2728 track->Rotate(tOrig.GetAlpha());
2729 AliTrackerBase::PropagateTrackTo(track,0,kMass,1.,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
2731 // rotate fitted track to the frame of the original track and propagate to same reference
2732 AliExternalTrackParam trackITS(*track);
2733 AliTrackerBase::PropagateTrackTo(&trackITS,lastLayerITS,kMass,5,kTRUE,kMaxSnp,0,kFALSE,fUseMaterial);
2734 trackITS.Rotate(tOrigITS.GetAlpha());
2735 AliTrackerBase::PropagateTrackTo(&trackITS,lastLayerITS,kMass,1,kFALSE,kMaxSnp,0,kFALSE,fUseMaterial);
2737 Int_t seedSec=seed->GetSector();
2738 Int_t seedID =seed->GetUniqueID();
2740 //count findable and found clusters in the seed
2742 Int_t iRowInner=seed->GetSeed1();
2743 Int_t iRowOuter=seed->GetSeed2();
2745 Int_t nClustersSeedMax=iRowOuter-iRowInner+1;
2746 Int_t nClustersFindable=0;
2747 Int_t nClustersSeed=0;
2749 Int_t ncls=(fClusterType==0)?toyTrack->GetNumberOfSpacePoints():toyTrack->GetNumberOfDistSpacePoints();
2751 Int_t rowInner=iRowInner-(iRowInner>62)*63;
2752 Int_t rowOuter=iRowOuter-(iRowOuter>62)*63;
2754 //findable in the current seed sector
2757 Int_t nCrossedROCs=0;
2764 for (Int_t icl=0; icl<ncls; ++icl) {
2765 const AliTPCclusterMI *cl=(fClusterType==0)?toyTrack->GetSpacePoint(icl):toyTrack->GetDistortedSpacePoint(icl);
2766 const Int_t roc=cl->GetDetector();
2767 const Int_t row=cl->GetRow();
2768 const Int_t rowGlobal=row+(roc>35)*63;
2770 AliTPCclusterMI *seedCl = seed->GetClusterPointer(rowGlobal);
2772 AliTPCclusterMI *clc=const_cast<AliTPCclusterMI*>(cl);
2773 if (seedCl->GetDetector()==roc&&seedCl->IsUsed()) clc->Use();
2774 clc->SetLabel(seedID,1);
2778 // if (row1<0) row1=rowGlobal;
2780 if ( (roc%36) != (lastROC%36)) {
2782 if (nclROC>nMaxClROC) {
2795 if ( (roc%36)!=(seedSec%36) ) continue;
2796 // if ( (row<rowInner) || (row>rowOuter) ) continue;
2797 ++nClustersFindable;
2801 if (nclROC>nMaxClROC) {
2810 Int_t nClustersInTrack=0;
2812 for (Int_t icl=0; icl<159; ++icl) {
2813 const AliTPCclusterMI *cl=seed->GetClusterPointer(icl);
2816 const Int_t row=cl->GetRow();
2817 const Int_t rowGlobal=row+(cl->GetDetector()>35)*63;
2818 if (rowGlobal>lastRow) lastRow=rowGlobal;
2819 if (rowGlobal<firstRow) firstRow=rowGlobal;
2820 if ( (row<rowInner) || (row>rowOuter) ) continue;
2824 Float_t z0=fEvent->GetZ();
2825 Float_t t0=fEvent->GetT0();
2827 Int_t ctype(fCorrectionType);
2830 CookLabel(seed,.6,info);
2831 Int_t seedLabel=seed->GetLabel();
2833 Int_t labelOrig=toyTrack->GetUniqueID();
2835 AliToyMCTrack *tr2 = const_cast<AliToyMCTrack*>(toyTrack);
2837 (*fStreamer) << "Seeds" <<
2839 // "iseed=" << iseed <<
2843 "vDrift=" << vDrift <<
2844 "zLength=" << zLength <<
2845 "fTime0=" << fTime0 <<
2846 "clsType=" << fClusterType <<
2847 "corrType=" << ctype <<
2849 "tOrig.=" << &tOrig <<
2850 "tOrigITS.=" << &tOrigITS <<
2852 "to.nclFindable=" << nClustersFindable <<
2853 "to.nclTot=" << ncls <<
2854 "to.label=" << labelOrig <<
2855 "to.nCrossedROCs="<< nCrossedROCs <<
2856 "to.rocMax=" << rocMaxCl <<
2857 "to.rocMaxNcl=" << nMaxClROC <<
2858 "to.row1Max=" << row1Maxcl <<
2859 "to.row2Max=" << row2Maxcl <<
2861 "track.=" << track <<
2862 "trackITS.=" << &trackITS <<
2864 "s.RowInner=" << iRowInner <<
2865 "s.RowOuter=" << iRowOuter <<
2866 "s.nclMax=" << nClustersSeedMax <<
2867 "s.ncl=" << nClustersSeed <<
2868 "s.ID=" << seedID <<
2870 "tr.firstClRow=" << firstRow <<
2871 "tr.lastClRow=" << lastRow <<
2872 "tr.ncl=" << nClustersInTrack <<
2873 "tr.label=" << seedLabel <<
2875 "tr.LabelNcl=" << info[0] <<
2876 "tr.Label2Ncl=" << info[1] <<
2877 "tr.Label2=" << info[2] <<
2878 "tr.nclTot=" << info[3] <<
2879 "tr.Nlabels=" << info[4] <<
2881 "tr.Sec=" << seedSec <<
2884 "toyTrack.=" << tr2 <<
2887 if (!isDummy) delete track;
2890 //____________________________________________________________________________________
2891 void AliToyMCReconstruction::MarkClustersUsed(AliTPCseed *seed)
2897 for (Int_t icl=0; icl<159; ++icl) {
2898 AliTPCclusterMI *cl=seed->GetClusterPointer(icl);
2903 //____________________________________________________________________________________
2904 void AliToyMCReconstruction::ResetClustersZtoTime(AliTPCseed *seed)
2910 for (Int_t icl=0; icl<159; ++icl) {
2911 AliTPCclusterMI *cl=seed->GetClusterPointer(icl);
2912 if (cl) cl->SetZ(cl->GetTimeBin());
2916 //____________________________________________________________________________________
2917 void AliToyMCReconstruction::DumpTracksToTree(const char* file)
2922 ConnectInputFile(file);
2928 TString debugName=fInputFile->GetName();
2929 debugName.ReplaceAll(".root",".AllTracks.root");
2931 gSystem->Exec(Form("test -f %s && rm %s", debugName.Data(), debugName.Data()));
2932 fStreamer=new TTreeSRedirector(debugName.Data());
2934 for (Int_t iev=0;iev<fNmaxEvents;++iev){
2935 fTree->GetEvent(iev);
2936 for (Int_t itr=0; itr<fEvent->GetNumberOfTracks();++itr){
2937 AliToyMCTrack *toyTrack=const_cast<AliToyMCTrack*>(fEvent->GetTrack(itr));
2938 Int_t trackID=toyTrack->GetUniqueID();
2940 (*fStreamer) << "Tracks" <<
2943 "trackID=" << trackID <<
2944 "track.=" << toyTrack <<
2953 //____________________________________________________________________________________
2954 void AliToyMCReconstruction::SetRieman(const AliTPCseed &seed, AliRieman &rieman)
2961 for (Int_t icl=0; icl<159; ++icl) {
2962 const AliTPCclusterMI *cl=seed.GetClusterPointer(icl);
2964 rieman.AddPoint(cl->GetX(), cl->GetY(), cl->GetZ(),
2965 TMath::Sqrt(cl->GetSigmaY2()), TMath::Sqrt(cl->GetSigmaZ2()));
2970 //____________________________________________________________________________________
2971 void AliToyMCReconstruction::CopyRieman(const AliRieman &from, AliRieman &to)
2977 if (to.GetCapacity()<from.GetCapacity()) return;
2980 for (Int_t i=0;i<from.GetN();++i) to.AddPoint(from.GetX()[i],from.GetY()[i],from.GetZ()[i],from.GetSy()[i],from.GetSz()[i]);