]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUTrackerGlo.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUTrackerGlo.cxx
CommitLineData
32d38de2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17 TO CHECK
18 GetBz usage
19
20 */
21
22//-------------------------------------------------------------------------
23// Implementation of the ITS Upgrade tracker mother class.
24//-------------------------------------------------------------------------
25#include <TTree.h>
26#include <Riostream.h>
27#include <TMath.h>
76390254 28#include <TFile.h>
32d38de2 29
30#include "AliITSUTrackerGlo.h"
31#include "AliESDEvent.h"
32#include "AliESDtrack.h"
33#include "AliITSURecoDet.h"
34#include "AliITSURecoSens.h"
35#include "AliITSUReconstructor.h"
36#include "AliITSReconstructor.h"
37#include "AliITSUSeed.h"
38#include "AliITSUAux.h"
c61e50c3 39#include "AliITSUClusterPix.h"
cb50e082 40#include "AliITSUGeomTGeo.h"
bdb92766 41#include "AliCodeTimer.h"
9cdcba2c 42#include "AliRefArray.h"
32d38de2 43using namespace AliITSUAux;
44using namespace TMath;
45
c8d1f258 46//----------------- tmp stuff -----------------
c8d1f258 47
32d38de2 48ClassImp(AliITSUTrackerGlo)
e2d2481c 49
50const Double_t AliITSUTrackerGlo::fgkToler = 1e-6;// tolerance for layer on-surface check
51
52
32d38de2 53//_________________________________________________________________________
54AliITSUTrackerGlo::AliITSUTrackerGlo(AliITSUReconstructor* rec)
55: fReconstructor(rec)
56 ,fITS(0)
0091e9f0 57 ,fCurrESDtrack(0)
0ddbf657 58 ,fCurrESDtrMClb(kDummyLabel)
32d38de2 59 ,fCurrMass(kPionMass)
0ddbf657 60 ,fCountProlongationTrials(0)
61 ,fCountITSin(0)
62 ,fCountITSout(0)
63 ,fCountITSrefit(0)
716ccba7 64 ,fHypStore(100)
6cd80116 65 ,fLayerMaxCandidates(1000)
66 ,fLayerCandidates(0)
38997c3c 67 ,fNBranchesAdded(0)
68 ,fNCandidatesAdded(0)
716ccba7 69 ,fCurrHyp(0)
6cd80116 70 ,fWorkHyp(0)
c61e50c3 71 ,fSeedsPool("AliITSUSeed",0)
b8b59e05 72 ,fFreeSeedsID(0)
9cdcba2c 73 ,fESDIndex(0)
b8b59e05 74 ,fNFreeSeeds(0)
75 ,fLastSeedID(0)
6cd80116 76 ,fNLrActive(0)
42c3d4bd 77 ,fDefTrackConds(0)
78 ,fCurrTrackCond(0)
c03e4f8a 79 ,fCurrActLrID(-1)
80 ,fCurrLayer(0)
c51c3124 81 ,fTrackPhase(-1)
53870004 82#ifdef _FILL_CONTROL_HISTOS_
83 ,fCHistoArr(0)
84#endif
32d38de2 85{
86 // Default constructor
87 if (rec) Init(rec);
88}
89
90//_________________________________________________________________________
91AliITSUTrackerGlo::~AliITSUTrackerGlo()
92{
93 // Default destructor
94 //
9cdcba2c 95 delete[] fLayerCandidates;
96 if (fWorkHyp) fWorkHyp->SetTPCSeed(0); // this hypothesis does not own the seed
97 delete fWorkHyp;
32d38de2 98 //
76390254 99#ifdef _FILL_CONTROL_HISTOS_
53870004 100 if (fCHistoArr) {
76390254 101 TFile* ctrOut = TFile::Open("itsuControlHistos.root","recreate");
102 ctrOut->cd();
103 AliInfo("Storing control histos");
53870004 104 fCHistoArr->Print();
105 // ctrOut->WriteObject(fCHistoArr,"controlH","kSingleKey");
106 fCHistoArr->Write();
76390254 107 ctrOut->Close();
108 delete ctrOut;
53870004 109 fCHistoArr = 0;
76390254 110 }
111#endif
112 //
32d38de2 113}
114
115//_________________________________________________________________________
116void AliITSUTrackerGlo::Init(AliITSUReconstructor* rec)
117{
118 // init with external reconstructor
c61e50c3 119 //
3d4dc3e2 120 fITS = rec->GetITSInterface();
6cd80116 121 fNLrActive = fITS->GetNLayersActive();
6cd80116 122 fWorkHyp = new AliITSUTrackHyp(fNLrActive);
c61e50c3 123 //
6cd80116 124 if (fLayerMaxCandidates<1) fLayerMaxCandidates = 1000;
125 fLayerCandidates = new AliITSUSeed*[fLayerMaxCandidates];
c61e50c3 126 fSeedsPool.ExpandCreateFast(1000); // RS TOCHECK
b8b59e05 127 fFreeSeedsID.Set(1000);
9cdcba2c 128 fESDIndex.Set(1000);
129
c61e50c3 130 //
32d38de2 131}
132
42c3d4bd 133//_________________________________________________________________________
134void AliITSUTrackerGlo::CreateDefaultTrackCond()
135{
136 // creates default tracking conditions to be used when recoparam does not provide them
6cd80116 137
42c3d4bd 138 AliITSUTrackCond* cond = new AliITSUTrackCond();
139 //
6cd80116 140 cond->SetNLayers(fNLrActive);
141 cond->AddNewCondition(fNLrActive);
42c3d4bd 142 cond->AddGroupPattern( 0xffff ); // require all layers hit
ee54014a 143 cond->Init();
42c3d4bd 144 //
145 fDefTrackConds.AddLast(cond);
146 //
147 AliInfo("Created conditions: ");
148 for (int i=0;i<fDefTrackConds.GetEntriesFast();i++) fDefTrackConds[i]->Print();
149 //
150}
151
152
32d38de2 153//_________________________________________________________________________
154Int_t AliITSUTrackerGlo::Clusters2Tracks(AliESDEvent *esdEv)
155{
156 //
bdb92766 157 AliCodeTimerAuto("",0);
76390254 158 SetTrackingPhase(kClus2Tracks);
159 //
160#ifdef _FILL_CONTROL_HISTOS_
53870004 161 if (!fCHistoArr) BookControlHistos();
76390254 162#endif
c03e4f8a 163 static int evID = 0;
9cdcba2c 164 static TArrayF esdTrPt(fESDIndex.GetSize());
bdb92766 165 //
42c3d4bd 166 TObjArray *trackConds = 0;
32d38de2 167 //
0ddbf657 168 fCountProlongationTrials = 0;
169 fCountITSin = 0;
170 fCountITSout = 0;
171 fCountITSrefit = 0;
172 //
b8b59e05 173 ResetSeedsPool();
716ccba7 174 int nTrESD = esdEv->GetNumberOfTracks();
c51c3124 175 AliInfo(Form("Will try to find prolongations for %d tracks",nTrESD));
42c3d4bd 176 int nTrackCond = AliITSUReconstructor::GetRecoParam()->GetNTrackingConditions();
177 if (nTrackCond<1) {
178 if (!fDefTrackConds.GetEntriesFast()) {
179 AliInfo("No tracking conditions found in recoparams, creating default one requesting all layers hit");
180 CreateDefaultTrackCond();
181 }
182 trackConds = &fDefTrackConds;
183 nTrackCond = trackConds->GetEntriesFast();
184 }
185 else trackConds = AliITSUReconstructor::GetRecoParam()->GetTrackingConditions();
186 //
15b02d69 187 static Bool_t first = kTRUE;
188 if (first) {
189 AliITSUReconstructor::GetRecoParam()->Print();
190 first = kFALSE;
191 }
192 fHypStore.Delete();
193 if (fHypStore.GetSize()<nTrESD) fHypStore.Expand(nTrESD+100);
194 //
195 fITS->ProcessClusters();
196 //
bdb92766 197#ifdef _FILL_CONTROL_HISTOS_
53870004 198 FlagSplitClusters(); // tmp RS
bdb92766 199#endif
200 //
201 // the tracks will be reconstructed in decreasing pt order, sort them
9cdcba2c 202 if (fESDIndex.GetSize()<nTrESD) {
203 fESDIndex.Set(nTrESD+200);
bdb92766 204 esdTrPt.Set(nTrESD+200);
205 }
9cdcba2c 206 int* esdTrackIndex = fESDIndex.GetArray();
bdb92766 207 float* trPt = esdTrPt.GetArray();
208 for (int itr=nTrESD;itr--;) trPt[itr] = esdEv->GetTrack(itr)->Pt();
209 Sort(nTrESD,trPt,esdTrackIndex,kTRUE);
53870004 210 //
42c3d4bd 211 for (int icnd=0;icnd<nTrackCond;icnd++) {
212 fCurrTrackCond = (AliITSUTrackCond*)trackConds->UncheckedAt(icnd);
ee54014a 213 if (!fCurrTrackCond->IsInitDone()) fCurrTrackCond->Init();
42c3d4bd 214 // select ESD tracks to propagate
215 for (int itr=0;itr<nTrESD;itr++) {
bdb92766 216 int trID = esdTrackIndex[itr];
217 fCurrESDtrack = esdEv->GetTrack(trID);
0ddbf657 218 fCurrESDtrMClb = fCurrESDtrack->GetLabel();
219 //
220 if (!NeedToProlong(fCurrESDtrack)) continue; // are we interested in this track?
c03e4f8a 221 /*
9cdcba2c 222 // if specific tracks should be checked, create a global array int wtc[] = {evITS*10000+trID, ...};
c03e4f8a 223 Bool_t dbg = kFALSE;
224 int nwtc = sizeof(wtc)/sizeof(int);
225
226 for (int k=0;k<nwtc;k++) {
bdb92766 227 if (wtc[k]==evID*10000+trID) {
c03e4f8a 228 dbg = kTRUE;
229 printf("\n\n\n\n\n\n\n");
230 printf("At esdTr: %d MC: %d\n",wtc[k],fCurrESDtrMClb);
231 printf("\n\n\n\n\n\n\n");
232 break;
233 }
234 }
235 AliLog::SetClassDebugLevel("AliITSUTrackerGlo",dbg ? 10:0);
236 */
237
70cb7fe4 238 AliDebug(1,Form("Processing track %d(esd%d) | M=%.3f Pt=%.3f | MCLabel: %d",itr,trID,fCurrESDtrack->GetMass(kTRUE),fCurrESDtrack->Pt(),fCurrESDtrMClb));//RS
bdb92766 239 FindTrack(fCurrESDtrack, trID);
42c3d4bd 240 }
241 //
38997c3c 242 if (AliDebugLevelClass()>+2) {
15b02d69 243 AliInfo(Form("SeedsPool: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
244 fHypStore.Print();
245 }
42c3d4bd 246 FinalizeHypotheses();
c03e4f8a 247 //
248 //AliLog::SetClassDebugLevel("AliITSUTrackerGlo",0); // in case wtc array was defined, uncomment this
42c3d4bd 249 }
716ccba7 250 //
0ddbf657 251 AliInfo(Form("%d ITSin for %d tried TPC seeds out of %d ESD tracks\n",fCountITSin,fCountProlongationTrials,nTrESD));
c03e4f8a 252 evID++;
32d38de2 253 return 0;
254}
255
256//_________________________________________________________________________
c51c3124 257Int_t AliITSUTrackerGlo::PropagateBack(AliESDEvent *esdEv)
32d38de2 258{
259 //
c51c3124 260 // Do outward fits in ITS
bdb92766 261 AliCodeTimerAuto("",0);
c51c3124 262 //
e7d83d38 263 SetTrackingPhase(kPropBack);
c51c3124 264 int nTrESD = esdEv->GetNumberOfTracks();
15b02d69 265 AliDebug(1,Form("Will propagate back %d tracks",nTrESD));
c51c3124 266 //
267 double bz0 = GetBz();
268 Double_t xyzTrk[3],xyzVtx[3]={GetX(),GetY(),GetZ()};
9cdcba2c 269 AliITSUTrackHyp dummyTr;
c51c3124 270 const double kWatchStep=10.; // for larger steps watch arc vs segment difference
271 Double_t times[AliPID::kSPECIES];
272 //
c51c3124 273 for (int itr=0;itr<nTrESD;itr++) {
0ddbf657 274 fCurrESDtrack = esdEv->GetTrack(itr);
275 fCurrESDtrMClb = fCurrESDtrack->GetLabel();
c51c3124 276 // Start time integral and add distance from current position to vertex
0ddbf657 277 if (fCurrESDtrack->IsOn(AliESDtrack::kITSout)) continue; // already done
c51c3124 278 //
0ddbf657 279 fCurrESDtrack->GetXYZ(xyzTrk);
c51c3124 280 Double_t dst = 0.; // set initial track lenght, tof
281 {
282 double dxs = xyzTrk[0] - xyzVtx[0];
283 double dys = xyzTrk[1] - xyzVtx[1];
284 double dzs = xyzTrk[2] - xyzVtx[2];
285 // RS: for large segment steps d use approximation of cicrular arc s by
286 // s = 2R*asin(d/2R) = d/p asin(p) \approx d/p (p + 1/6 p^3) = d (1+1/6 p^2)
287 // where R is the track radius, p = d/2R = 2C*d (C is the abs curvature)
288 // Hence s^2/d^2 = (1+1/6 p^2)^2
289 dst = dxs*dxs + dys*dys;
290 if (dst > kWatchStep*kWatchStep) { // correct circular part for arc/segment factor
0ddbf657 291 double crv = Abs(fCurrESDtrack->GetC(bz0));
c51c3124 292 double fcarc = 1.+crv*crv*dst/6.;
293 dst *= fcarc*fcarc;
294 }
295 dst += dzs*dzs;
296 dst = Sqrt(dst);
297 }
298 //
0ddbf657 299 fCurrESDtrack->SetStatus(AliESDtrack::kTIME);
c51c3124 300 //
0ddbf657 301 if (!fCurrESDtrack->IsOn(AliESDtrack::kITSin)) { // case of tracks w/o ITS prolongation: just set the time integration
302 dummyTr.AliExternalTrackParam::operator=(*fCurrESDtrack);
c51c3124 303 dummyTr.StartTimeIntegral();
e2d2481c 304 dummyTr.AddTimeStep(dst);
c51c3124 305 dummyTr.GetIntegratedTimes(times);
0ddbf657 306 fCurrESDtrack->SetIntegratedTimes(times);
307 fCurrESDtrack->SetIntegratedLength(dummyTr.GetIntegratedLength());
c51c3124 308 continue;
309 }
310 //
9cdcba2c 311 fCurrHyp = GetTrackHyp(itr);
70cb7fe4 312 fCurrMass = fCurrHyp->GetMass();
9cdcba2c 313 fCurrHyp->StartTimeIntegral();
314 fCurrHyp->AddTimeStep(dst);
9cdcba2c 315 fCurrHyp->ResetCovariance(10000);
316 double chi2 = RefitTrack(fCurrHyp,fITS->GetRMax());
317 if (chi2>0) { // propagate to exit from the ITS/TPC screen
70cb7fe4 318 int ndf = fCurrHyp->GetWinner()->GetNLayersHit()*2-5;
319 if (ndf>0) chi2 /= ndf;
9cdcba2c 320 fCurrHyp->SetChi2(chi2);
321 UpdateESDTrack(fCurrHyp,AliESDtrack::kITSout);
0ddbf657 322 fCountITSout++;
68a0f687 323 }
e7d83d38 324 else {
0ddbf657 325 AliDebug(2,Form("Refit Failed for track %d | ESDtrack#%d (MClb:%d)",itr,fCurrESDtrack->GetID(),fCurrESDtrMClb));
9cdcba2c 326 //fCurrHyp->AliExternalTrackParam::Print();
327 //fCurrHyp->GetWinner()->Print();
e7d83d38 328 }
c51c3124 329 //
330 }
32d38de2 331 //
0ddbf657 332 AliInfo(Form("%d ITSout in %d ITSin tracks for %d tried TPC seeds out of %d ESD tracks\n",
333 fCountITSout,fCountITSin,fCountProlongationTrials,nTrESD));
334 //
32d38de2 335 return 0;
336}
337
338//_________________________________________________________________________
e7d83d38 339Int_t AliITSUTrackerGlo::RefitInward(AliESDEvent *esdEv)
32d38de2 340{
341 //
e7d83d38 342 // refit the tracks inward, using current cov.matrix
bdb92766 343 AliCodeTimerAuto("",0);
e7d83d38 344 //
345 SetTrackingPhase(kRefitInw);
346 Int_t nTrESD = esdEv->GetNumberOfTracks();
b515ad7e 347 // AliLog::SetClassDebugLevel("AliITSUTrackerGlo",10);
348
15b02d69 349 AliDebug(1,Form("Will refit inward %d tracks",nTrESD));
e7d83d38 350 //
351 for (int itr=0;itr<nTrESD;itr++) {
0ddbf657 352 fCurrESDtrack = esdEv->GetTrack(itr);
353 fCurrESDtrMClb = fCurrESDtrack->GetLabel();
e7d83d38 354 // Start time integral and add distance from current position to vertex
0ddbf657 355 UInt_t trStat = fCurrESDtrack->GetStatus();
e7d83d38 356 if ( !(trStat & AliESDtrack::kITSout) ) continue;
357 if ( trStat & AliESDtrack::kITSrefit ) continue; // already done
358 if ( (trStat & AliESDtrack::kTPCout) && !(trStat & AliESDtrack::kTPCrefit) ) continue;
359 //
9cdcba2c 360 fCurrHyp = GetTrackHyp(itr);
361 fCurrHyp->AliExternalTrackParam::operator=(*fCurrESDtrack); // fetch current ESDtrack kinematics
70cb7fe4 362 fCurrMass = fCurrHyp->GetMass();
363 //
9cdcba2c 364 double chi2 = RefitTrack(fCurrHyp,fITS->GetRMin());
70cb7fe4 365 if (chi2>0) { // propagate up to inside radius of the beam pipe
9cdcba2c 366 fCurrHyp->SetChi2(chi2);
367 UpdateESDTrack(fCurrHyp,AliESDtrack::kITSrefit);
0ddbf657 368 fCountITSrefit++;
e7d83d38 369 }
370 else {
0ddbf657 371 AliDebug(2,Form("Refit Failed for track %d |ESDtrack#%d (MClb:%d)",itr,fCurrESDtrack->GetID(),fCurrESDtrMClb));
e7d83d38 372 }
373 }
32d38de2 374 //
0ddbf657 375 AliInfo(Form("%d ITSrefit in %d ITSout in %d ITSin tracks for %d tried TPC seeds out of %d ESD tracks\n",
376 fCountITSrefit,fCountITSout,fCountITSin,fCountProlongationTrials,nTrESD));
377 //
b515ad7e 378 // AliLog::SetClassDebugLevel("AliITSUTrackerGlo",0);
32d38de2 379 return 0;
380}
381
382//_________________________________________________________________________
383Int_t AliITSUTrackerGlo::LoadClusters(TTree * treeRP)
384{
385 // read from tree (if pointer provided) or directly from the ITS reco interface
386 //
387 return fReconstructor->LoadClusters(treeRP);
388}
389
390//_________________________________________________________________________
391void AliITSUTrackerGlo::UnloadClusters()
392{
393 //
394 // To be implemented
395 //
396
397 Info("UnloadClusters","To be implemented");
398}
399//_________________________________________________________________________
400AliCluster * AliITSUTrackerGlo::GetCluster(Int_t /*index*/) const
401{
402 //
403 // To be implemented
404 //
405
406 Info("GetCluster","To be implemented");
407 return 0x0;
408}
409
410//_________________________________________________________________________
411Bool_t AliITSUTrackerGlo::NeedToProlong(AliESDtrack* esdTr)
412{
413 // do we need to match this track to ITS?
414 //
415 static double bz = GetBz();
416 if (!esdTr->IsOn(AliESDtrack::kTPCin) ||
417 esdTr->IsOn(AliESDtrack::kTPCout) ||
418 esdTr->IsOn(AliESDtrack::kITSin) ||
419 esdTr->GetKinkIndex(0)>0) return kFALSE;
420 //
c61e50c3 421 if (esdTr->Pt()<AliITSUReconstructor::GetRecoParam()->GetMinPtForProlongation()) return kFALSE;
32d38de2 422 //
423 float dtz[2];
424 esdTr->GetDZ(GetX(),GetY(),GetZ(),bz,dtz);
425 // if track is not V0 candidata but has large offset wrt IP, reject it. RS TOCHECK
c61e50c3 426 if ( !(esdTr->GetV0Index(0)>0 && dtz[0]>AliITSUReconstructor::GetRecoParam()->GetMaxDforV0dghtrForProlongation())
427 && (Abs(dtz[0])>AliITSUReconstructor::GetRecoParam()->GetMaxDForProlongation() ||
428 Abs(dtz[1])>AliITSUReconstructor::GetRecoParam()->GetMaxDZForProlongation())) return kFALSE;
32d38de2 429 //
cb50e082 430 // if (esdTr->Pt()<3) return kFALSE;//RS
32d38de2 431 return kTRUE;
432}
433
434//_________________________________________________________________________
716ccba7 435void AliITSUTrackerGlo::FindTrack(AliESDtrack* esdTr, Int_t esdID)
32d38de2 436{
437 // find prolongaion candidates finding for single seed
438 //
3e4e3c23 439 AliITSUSeed seedUC; // copy of the seed from the upper layer
440 AliITSUSeed seedT; // transient seed between the seedUC and new prolongation hypothesis
441 //
6cd80116 442 AliITSUTrackHyp* hypTr = InitHypothesis(esdTr,esdID); // initialize prolongations hypotheses tree
9cdcba2c 443 if (!hypTr || hypTr->GetSkip()) return;
444 //
6cd80116 445 fCurrHyp = fWorkHyp;
446 fCurrHyp->InitFrom(hypTr);
32d38de2 447 //
173b3073 448 AliITSURecoSens *hitSens[AliITSURecoSens::kNNeighbors+1];
f8832015 449 //
c61e50c3 450 TObjArray clArr; // container for transfer of clusters matching to seed
32d38de2 451 //
6cd80116 452 for (int ila=fNLrActive;ila--;) {
c03e4f8a 453 fCurrActLrID = ila;
454 fCurrLayer = fITS->GetLayerActive(ila);
455 Bool_t noClSharing = fCurrTrackCond->GetClSharing(ila)==0;
32d38de2 456 int ilaUp = ila+1; // prolong seeds from layer above
3e4e3c23 457 //
458 // for the outermost layer the seed is created from the ESD track
6cd80116 459 int nSeedsUp = (ilaUp==fNLrActive) ? 1 : fCurrHyp->GetNSeeds(ilaUp);
38997c3c 460 int maxNBranches = fCurrTrackCond->GetMaxBranches(ila);
461 int maxNCandidates = fCurrTrackCond->GetMaxCandidates(ila);
3e4e3c23 462 //
32d38de2 463 for (int isd=0;isd<nSeedsUp;isd++) {
3e4e3c23 464 AliITSUSeed* seedU;
6cd80116 465 if (ilaUp==fNLrActive) {
3e4e3c23 466 seedU = 0;
70cb7fe4 467 seedUC.InitFromSeed(fCurrHyp->GetTPCSeed()); // init with TPC seed from ref.R
3e4e3c23 468 }
469 else {
470 seedU = fCurrHyp->GetSeed(ilaUp,isd); // seed on prev.active layer to prolong
c03e4f8a 471 if (seedU->IsKilled()) continue;
3e4e3c23 472 seedUC = *seedU; // its copy will be prolonged
b8b59e05 473 seedUC.SetParent(seedU);
3e4e3c23 474 }
943e1898 475 seedUC.ResetFMatrix(); // reset the matrix for propagation to next layer
32d38de2 476 // go till next active layer
0ddbf657 477 AliDebug(2,Form("working on Lr:%d Seed:%d of %d for esdID=%d (MClb:%d) | pT=%.3f",ila,isd,nSeedsUp,esdID,fCurrESDtrMClb,seedUC.Pt()));
70cb7fe4 478 if (!TransportToLayer(&seedUC, fITS->GetLrIDActive(ilaUp), fITS->GetLrIDActive(ila)) ) { // external seed already prolonged
32d38de2 479 //
0ddbf657 480 AliDebug(2,Form("Transport failed | esdID=%d (MClb:%d)",esdID,fCurrESDtrMClb));
32d38de2 481 // Check if the seed satisfies to track definition
b8b59e05 482 if (NeedToKill(&seedUC,kTransportFailed) && seedU) KillSeed(seedU,kTRUE);
32d38de2 483 continue; // RS TODO: decide what to do with tracks stopped on higher layers w/o killing
484 }
f8832015 485 if (!GetRoadWidth(&seedUC, ila)) { // failed to find road width on the layer
b8b59e05 486 if (NeedToKill(&seedUC,kRWCheckFailed) && seedU) KillSeed(seedU,kTRUE);
32d38de2 487 continue;
488 }
5785a9d8 489 /*
490 //RS toremove
491 int mcquest = -1;
c03e4f8a 492 if (!seedUC.ContainsFake() && AliDebugLevelClass()>2) {
5785a9d8 493 mcquest = fCurrESDtrMClb;
494 seedUC.Print("etp");
495 printf("FSParams: "); for (int ip=0;ip<kNTrImpData;ip++) printf("%+e ",fTrImpData[ip]); printf("\n");
496 }
497 //
c03e4f8a 498 int nsens = fCurrLayer->FindSensors(&fTrImpData[kTrPhi0], hitSens, mcquest); // find detectors which may be hit by the track
5785a9d8 499 */
c03e4f8a 500 int nsens = fCurrLayer->FindSensors(&fTrImpData[kTrPhi0], hitSens); // find detectors which may be hit by the track
0ddbf657 501 AliDebug(2,Form("Will check %d sensors on lr:%d | esdID=%d (MClb:%d)",nsens,ila,esdID,fCurrESDtrMClb));
32d38de2 502 //
38997c3c 503 seedUC.SetLr(ila);
504 //
943e1898 505 double bz = GetBz();
32d38de2 506 for (int isn=nsens;isn--;) {
c61e50c3 507 AliITSURecoSens* sens = hitSens[isn];
38997c3c 508 int ncl = sens->GetNClusters();
509 if (!ncl) continue;
510 seedT = seedUC;
f8832015 511 //
c03e4f8a 512 // We need to propagate the seed to sensor on fCurrLayer staying in the frame of the sensor from prev.layer,
943e1898 513 // since the transport matrix should be defined in this frame.
514 double xs; // X in the TF of current seed, corresponding to intersection with sensor plane
53870004 515 if (!seedT.GetTrackingXAtXAlpha(sens->GetXTF(),sens->GetPhiTF(),bz, xs)) {
516 if (AliDebugLevelClass()>2) {
517 printf("Failed on GetTrackingXAtXAlpha: X=%.4f alp=%.3f\n",sens->GetXTF(),sens->GetPhiTF());
518 seedT.Print("etp");
519 }
520 continue;
521 }
522 if (xs<seedT.GetX()) {
523 if (!PropagateSeed(&seedT,xs,fCurrMass)) continue;
524 }
525 else { // some low precision tracks may hit the sensor plane outside of the layer radius
526 if (AliDebugLevelClass()>2) {
527 if (!seedT.ContainsFake()) {
528 printf("WRONG PROP on L%d, sens%d of %d: %.4f > %.4f\n",ila,isn,nsens,xs,seedT.GetX());
529 sens->Print();
530 seedT.Print("etp");
531 }
532 }
533 if (!seedT.PropagateParamOnlyTo(xs,bz)) continue;
534 }
8b16dbae 535 // if (!seedT.PropagateToX(xs,bz)) continue;
716ccba7 536 // if (!seedT.Rotate(sens->GetPhiTF())) continue;
537 if (!seedT.RotateToAlpha(sens->GetPhiTF())) continue;
943e1898 538 //
f8832015 539 int clID0 = sens->GetFirstClusterId();
cb50e082 540 for (int icl=ncl;icl--;) { // don't change the order, clusters are sorted
c03e4f8a 541 //AliLog::SetClassDebugLevel("AliITSUTrackerGlo",10);
542 int clID = clID0 + icl;
543 if (noClSharing && fCurrLayer->GetCluster(clID)->IsClusterUsed()) continue;
f8832015 544 int res = CheckCluster(&seedT,ila,clID0+icl);
c03e4f8a 545 //AliLog::SetClassDebugLevel("AliITSUTrackerGlo", 0);
f8832015 546 //
547 if (res==kStopSearchOnSensor) break; // stop looking on this sensor
548 if (res==kClusterNotMatching) continue; // cluster does not match
549 // cluster is matching and it was added to the hypotheses tree
c61e50c3 550 }
32d38de2 551 }
38997c3c 552 // cluster search is done. Do we need to have a version of this seed skipping current layer
553 if (!NeedToKill(&seedUC,kMissingCluster)) {
b2d3bc3a 554 AliITSUSeed* seedSkp = NewSeedFromPool(&seedUC);
ee54014a 555 double penalty = -fCurrTrackCond->GetMissPenalty(ila);
716ccba7 556 // to do: make penalty to account for probability to miss the cluster for good reason
557 seedSkp->SetChi2Cl(penalty);
c03e4f8a 558 AddSeedBranch(seedSkp);
559 // AddProlongationHypothesis(seedSkp,ila);
716ccba7 560 }
38997c3c 561 // transfer the new branches of the seed to the hypothesis container
562 if (fNBranchesAdded) ValidateAllowedBranches(maxNBranches);
563 //
32d38de2 564 }
38997c3c 565 if (fNCandidatesAdded) ValidateAllowedCandidates(ila,maxNCandidates);
566 // ((TObjArray*)fCurrHyp->GetLayerSeeds(ila))->Sort();
567 if (AliDebugLevelClass()>2) { //RS
15b02d69 568 printf(">>> All hypotheses on lr %d: \n",ila);
569 for (int ih=0;ih<fCurrHyp->GetNSeeds(ila);ih++) {printf(" #%3d ",ih); fCurrHyp->GetSeed(ila,ih)->Print();}
570 }
571 //
572 /*
716ccba7 573 for (int ih=0;ih<fCurrHyp->GetNSeeds(ila);ih++) {
716ccba7 574 if (ila!=0) continue;
575 double vecL[5] = {0};
576 double matL[15] = {0};
577 AliITSUSeed* sp = fCurrHyp->GetSeed(ila,ih);
578 while(sp->GetParent()) {
579 sp->Smooth(vecL,matL);
6cd80116 580 if (sp->GetLayerID()>=fNLrActive-1) break;
716ccba7 581 sp = (AliITSUSeed*)sp->GetParent();
582 }
583 */
32d38de2 584 }
585 //
6cd80116 586 SaveReducedHypothesesTree(hypTr);
587 if (AliDebugLevelClass()>1) {
588 printf("\nSaved hypotheses for esdTrack %d (MCLab:%d)\n",esdID,fCurrESDtrMClb);
589 hypTr->Print("l");
590 }
591 fCurrHyp = 0;
716ccba7 592 //
32d38de2 593}
594
595//_________________________________________________________________________
6cd80116 596AliITSUTrackHyp* AliITSUTrackerGlo::InitHypothesis(AliESDtrack *esdTr, Int_t esdID)
32d38de2 597{
c61e50c3 598 // init prolongaion candidates finding for single seed
6cd80116 599 AliITSUTrackHyp* hyp = GetTrackHyp(esdID);
600 if (hyp) return hyp;
716ccba7 601 //
0ddbf657 602 fCountProlongationTrials++;
603 //
32d38de2 604 fCurrMass = esdTr->GetMass();
605 if (fCurrMass<kPionMass*0.9) fCurrMass = kPionMass; // don't trust to mu, e identification from TPCin
c61e50c3 606 //
6cd80116 607 hyp = new AliITSUTrackHyp(fNLrActive);
608 hyp->SetESDTrack(esdTr);
609 hyp->SetUniqueID(esdID);
610 hyp->SetMass(fCurrMass);
9cdcba2c 611 hyp->SetTPCSeed( new AliExternalTrackParam(*esdTr) );
6cd80116 612 SetTrackHyp(hyp,esdID);
9cdcba2c 613
70cb7fe4 614 if (!TransportToLayer(hyp->GetTPCSeed(),fITS->GetNLayers(), fITS->GetLrIDActive(fNLrActive-1), fITS->GetRITSTPCRef())) hyp->SetSkip(); // propagate to outer R of ITS
3e4e3c23 615 //
6cd80116 616 return hyp;
32d38de2 617 // TO DO
618}
619
620//_________________________________________________________________________
70cb7fe4 621Bool_t AliITSUTrackerGlo::TransportToLayer(AliITSUSeed* seed, Int_t lFrom, Int_t lTo, Double_t rLim)
32d38de2 622{
70cb7fe4 623 // transport seed from layerFrom to the entrance (along the direction of the track) of layerTo or to rLim (if>0), wathever is closer
32d38de2 624 //
8b16dbae 625 //
626 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
627 //
32d38de2 628 int dir = lTo > lFrom ? 1:-1;
629 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
630 Bool_t checkFirst = kTRUE;
70cb7fe4 631 Bool_t limReached = kFALSE;
32d38de2 632 while(lFrom!=lTo) {
32d38de2 633 if (lrFr) {
70cb7fe4 634 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
e2d2481c 635 checkFirst = kFALSE;
32d38de2 636 }
637 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
638 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
639 //
640 // go the entrance of the layer, assuming no materials in between
8b16dbae 641 double xToGo = lrTo->GetR(-dir);
70cb7fe4 642 if (rLim>0) {
643 if (dir>0) {
644 if (rLim<xToGo) {xToGo = rLim; limReached = kTRUE;}
645 }
646 else {
647 if (rLim>xToGo) {xToGo = rLim; limReached = kTRUE;}
648 }
649 }
0ddbf657 650 // double xts = xToGo;
b2d3bc3a 651 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) {
0ddbf657 652 //printf("FailHere1: %f %f %d\n",xts,xToGo,dir);
653 //seed->Print("etp");
70cb7fe4 654 //
b2d3bc3a 655 return kFALSE;
656 }
b515ad7e 657 AliDebug(2,Form("go in dir=%d to R=%.4f(X:%.4f)",dir,lrTo->GetR(-dir), xToGo));
b2d3bc3a 658 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) {
0ddbf657 659 //printf("FailHere2: %f %f %d\n",xts,xToGo,dir);
660 //seed->Print("etp");
b2d3bc3a 661 return kFALSE;
662 }
32d38de2 663 lrFr = lrTo;
70cb7fe4 664 if (limReached) break;
32d38de2 665 }
666 return kTRUE;
667 //
668}
669
3e4e3c23 670//_________________________________________________________________________
70cb7fe4 671Bool_t AliITSUTrackerGlo::TransportToLayer(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t rLim)
3e4e3c23 672{
70cb7fe4 673 // transport track from layerFrom to the entrance of layerTo or to rLim (if>0), wathever is closer
3e4e3c23 674 //
8b16dbae 675 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
676 //
3e4e3c23 677 int dir = lTo > lFrom ? 1:-1;
678 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
679 Bool_t checkFirst = kTRUE;
70cb7fe4 680 Bool_t limReached = kFALSE;
3e4e3c23 681 while(lFrom!=lTo) {
3e4e3c23 682 if (lrFr) {
e2d2481c 683 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
684 checkFirst = kFALSE;
3e4e3c23 685 }
686 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
687 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
688 //
0ddbf657 689 // go the entrance of the layer, assuming no materials in between
690 double xToGo = lrTo->GetR(-dir);
70cb7fe4 691 if (rLim>0) {
692 if (dir>0) {
693 if (rLim<xToGo) {xToGo = rLim; limReached = kTRUE;}
694 }
695 else {
696 if (rLim>xToGo) {xToGo = rLim; limReached = kTRUE;}
697 }
698 }
0ddbf657 699 // double xts = xToGo;
700 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) {
701 // printf("FailHere1: %f %f %d\n",xts,xToGo,dir);
702 // seed->Print("etp");
703 return kFALSE;
704 }
b515ad7e 705 AliDebug(2,Form("go in dir=%d to R=%.4f(X:%.4f)",dir,lrTo->GetR(-dir), xToGo));
706 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) {
707 //printf("FailHere2: %f %f %d\n",xts,xToGo,dir);
708 //seed->Print("etp");
709 return kFALSE;
710 }
711 lrFr = lrTo;
70cb7fe4 712 if (limReached) break;
b515ad7e 713 }
714 return kTRUE;
715 //
716}
717
718//_________________________________________________________________________
719Bool_t AliITSUTrackerGlo::TransportToLayerX(AliExternalTrackParam* seed, Int_t lFrom, Int_t lTo, Double_t xStop)
720{
721 // transport track from layerFrom to the entrance of layerTo but do not pass control parameter X
722 //
723 if (lTo==lFrom) AliFatal(Form("was called with lFrom=%d lTo=%d",lFrom,lTo));
724 //
725 int dir = lTo > lFrom ? 1:-1;
726 AliITSURecoLayer* lrFr = fITS->GetLayer(lFrom); // this can be 0 when extrapolation from TPC to ITS is requested
727 Bool_t checkFirst = kTRUE;
728 while(lFrom!=lTo) {
729 if (lrFr) {
730 if (!GoToExitFromLayer(seed,lrFr,dir,checkFirst)) return kFALSE; // go till the end of current layer
731 checkFirst = kFALSE;
732 }
733 AliITSURecoLayer* lrTo = fITS->GetLayer( (lFrom+=dir) );
734 if (!lrTo) AliFatal(Form("Layer %d does not exist",lFrom));
735 //
736 // go the entrance of the layer, assuming no materials in between
737 double xToGo = lrTo->GetR(-dir); // R of the entrance to layer
738 //
739 // double xts = xToGo;
740 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) {
741 // printf("FailHere1: %f %f %d\n",xts,xToGo,dir);
742 // seed->Print("etp");
743 return kFALSE;
744 }
745 if ( (dir>0&&xToGo>xStop) || (dir<0&&xToGo<xStop) ) xToGo = xStop;
746 //
747 AliDebug(2,Form("go in dir=%d to R=%.4f(X:%.4f)",dir,lrTo->GetR(-dir), xToGo));
0ddbf657 748 if (!PropagateSeed(seed,xToGo,fCurrMass,100, kFALSE )) {
749 //printf("FailHere2: %f %f %d\n",xts,xToGo,dir);
750 //seed->Print("etp");
751 return kFALSE;
752 }
3e4e3c23 753 lrFr = lrTo;
754 }
755 return kTRUE;
756 //
757}
758
e2d2481c 759//_________________________________________________________________________
760Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
761{
762 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
763 // If check is requested, do this only provided the track has not exited the layer already
764 double xToGo = lr->GetR(dir);
765 if (check) { // do we need to track till the surface of the current layer ?
766 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
15b02d69 767 AliDebug(3,Form(" dir:%d Cur: %e Tgt: %e",dir,Sqrt(curR2),xToGo));
0ddbf657 768 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // on the surface or outside of the layer
769 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // on the surface or outside of the layer
e2d2481c 770 }
771 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
772 // go via layer to its boundary, applying material correction.
773 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
e7d83d38 774 //
e2d2481c 775 return kTRUE;
776 //
777}
778
779//_________________________________________________________________________
780Bool_t AliITSUTrackerGlo::GoToExitFromLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
781{
782 // go to the exit from lr in direction dir, applying material corrections in steps specific for this layer
783 // If check is requested, do this only provided the track has not exited the layer already
784 double xToGo = lr->GetR(dir);
785 if (check) { // do we need to track till the surface of the current layer ?
786 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
0ddbf657 787 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // on the surface or outside of the layer
788 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // on the surface or outside of the layer
e2d2481c 789 }
b515ad7e 790 AliDebug(2,Form(" dir=%d : from R=%.4f -> R=%.4f",dir,Sqrt(seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY()), xToGo));
e2d2481c 791 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
792 // go via layer to its boundary, applying material correction.
793 if (!PropagateSeed(seed,xToGo,fCurrMass, lr->GetMaxStep())) return kFALSE;
e7d83d38 794 //
e2d2481c 795 return kTRUE;
796 //
797}
798
799
800//_________________________________________________________________________
801Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliITSUSeed* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
802{
803 // go to the entrance of lr in direction dir, w/o applying material corrections.
804 // If check is requested, do this only provided the track did not reach the layer already
805 double xToGo = lr->GetR(-dir);
806 if (check) { // do we need to track till the surface of the current layer ?
807 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
0ddbf657 808 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // already passed
809 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // already passed
e2d2481c 810 }
811 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
812 // go via layer to its boundary, applying material correction.
813 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
814 return kTRUE;
815 //
816}
817
818//_________________________________________________________________________
819Bool_t AliITSUTrackerGlo::GoToEntranceToLayer(AliExternalTrackParam* seed, AliITSURecoLayer* lr, Int_t dir, Bool_t check)
820{
821 // go to the entrance of lr in direction dir, w/o applying material corrections.
822 // If check is requested, do this only provided the track did not reach the layer already
823 double xToGo = lr->GetR(-dir);
824 if (check) { // do we need to track till the surface of the current layer ?
825 double curR2 = seed->GetX()*seed->GetX() + seed->GetY()*seed->GetY(); // current radius
0ddbf657 826 if (dir>0) { if (curR2-xToGo*xToGo>-fgkToler) return kTRUE; } // already passed
827 else if (dir<0) { if (xToGo*xToGo-curR2>-fgkToler) return kTRUE; } // already passed
e2d2481c 828 }
829 if (!seed->GetXatLabR(xToGo,xToGo,GetBz(),dir)) return kFALSE;
830 // go via layer to its boundary, applying material correction.
831 if (!PropagateSeed(seed,xToGo,fCurrMass, 100, kFALSE)) return kFALSE;
832 return kTRUE;
833 //
834}
835
32d38de2 836//_________________________________________________________________________
c61e50c3 837Bool_t AliITSUTrackerGlo::GetRoadWidth(AliITSUSeed* seed, int ilrA)
32d38de2 838{
839 // calculate road width in terms of phi and z for the track which MUST be on the external radius of the layer
840 // as well as some aux info
841 double bz = GetBz();
842 AliITSURecoLayer* lrA = fITS->GetLayerActive(ilrA);
c61e50c3 843 seed->GetXYZ(&fTrImpData[kTrXIn]); // lab position at the entrance from above
53870004 844 static AliExternalTrackParam sc; // seed copy for manipulations
943e1898 845 sc = *seed;
32d38de2 846 //
c61e50c3 847 fTrImpData[kTrPhiIn] = ATan2(fTrImpData[kTrYIn],fTrImpData[kTrXIn]);
943e1898 848 if (!sc.Rotate(fTrImpData[kTrPhiIn])) return kFALSE; // go to the frame of the entry point into the layer
c61e50c3 849 double dr = lrA->GetDR(); // approximate X dist at the inner radius
943e1898 850 if (!sc.GetXYZAt(sc.GetX()-dr, bz, fTrImpData + kTrXOut)) {
32d38de2 851 // special case: track does not reach inner radius, might be tangential
943e1898 852 double r = sc.GetD(0,0,bz);
32d38de2 853 double x;
bdb92766 854 if (!sc.GetXatLabR(r,x,bz,-1)) return kFALSE;
943e1898 855 dr = Abs(sc.GetX() - x);
bdb92766 856 if (!sc.GetXYZAt(x, bz, fTrImpData + kTrXOut)) return kFALSE;
32d38de2 857 }
858 //
c61e50c3 859 fTrImpData[kTrPhiOut] = ATan2(fTrImpData[kTrYOut],fTrImpData[kTrXOut]);
943e1898 860 double sgy = sc.GetSigmaY2() + dr*dr*sc.GetSigmaSnp2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(ilrA);
861 double sgz = sc.GetSigmaZ2() + dr*dr*sc.GetSigmaTgl2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(ilrA);
ee54014a 862 sgy = Sqrt(sgy)*fCurrTrackCond->GetNSigmaRoadY(ilrA);
863 sgz = Sqrt(sgz)*fCurrTrackCond->GetNSigmaRoadZ(ilrA);
5785a9d8 864 double dphi0 = 0.5*Abs(fTrImpData[kTrPhiOut]-fTrImpData[kTrPhiIn]);
865 double phi0 = 0.5*(fTrImpData[kTrPhiOut]+fTrImpData[kTrPhiIn]);
866 if ( dphi0>(0.5*Pi()) ) {
867 // special case of angles around pi
868 dphi0 = Abs(phi0);
869 phi0 += Pi();
870 }
871
872 fTrImpData[kTrPhi0] = phi0;
173b3073 873 fTrImpData[kTrZ0] = 0.5*(fTrImpData[kTrZOut]+fTrImpData[kTrZIn]);
5785a9d8 874 fTrImpData[kTrDPhi] = dphi0 + sgy/lrA->GetR();
173b3073 875 fTrImpData[kTrDZ] = 0.5*Abs(fTrImpData[kTrZOut]-fTrImpData[kTrZIn]) + sgz;
32d38de2 876 //
877 return kTRUE;
878}
879
b8b59e05 880//________________________________________
881void AliITSUTrackerGlo::ResetSeedsPool()
882{
883 // mark all seeds in the pool as unused
0ddbf657 884 AliDebug(-1,Form("CurrentSize: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
b8b59e05 885 fNFreeSeeds = 0;
886 fSeedsPool.Clear(); // seeds don't allocate memory
887}
888
889
890//________________________________________
891void AliITSUTrackerGlo::MarkSeedFree(AliITSUSeed *sd)
32d38de2 892{
b8b59e05 893 // account that this seed is "deleted"
894 int id = sd->GetPoolID();
895 if (id<0) {
896 AliError(Form("Freeing of seed %p NOT from the pool is requested",sd));
897 return;
898 }
899 // AliInfo(Form("%d %p",id, seed));
900 fSeedsPool.RemoveAt(id);
901 if (fFreeSeedsID.GetSize()<=fNFreeSeeds) fFreeSeedsID.Set( 2*fNFreeSeeds + 100 );
902 fFreeSeedsID.GetArray()[fNFreeSeeds++] = id;
32d38de2 903}
f8832015 904
905//_________________________________________________________________________
906Int_t AliITSUTrackerGlo::CheckCluster(AliITSUSeed* track, Int_t lr, Int_t clID)
907{
908 // Check if the cluster (in tracking frame!) is matching to track.
909 // The track must be already propagated to sensor tracking frame.
910 // Returns: kStopSearchOnSensor if the search on given sensor should be stopped,
911 // kClusterMatching if the cluster is matching
912 // kClusterMatching otherwise
913 //
f8832015 914 const double kTolerX = 5e-4;
c03e4f8a 915 // AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
916 AliCluster *cl = fCurrLayer->GetCluster(clID);
f8832015 917 //
c8d1f258 918 Bool_t goodCl = kFALSE;
0ddbf657 919 int currLabel = Abs(fCurrESDtrMClb);
716ccba7 920 //
8b16dbae 921 if (cl->GetLabel(0)>=0) {
922 for (int i=0;i<3;i++) if (cl->GetLabel(i)>=0 && cl->GetLabel(i)==currLabel) {goodCl = kTRUE; break;}
923 }
53870004 924 Bool_t goodSeed = !track->ContainsFake();
c8d1f258 925 //
f8832015 926 if (TMath::Abs(cl->GetX())>kTolerX) { // if due to the misalingment X is large, propagate track only
c8d1f258 927 if (!track->PropagateParamOnlyTo(track->GetX()+cl->GetX(),GetBz())) {
53870004 928 if (goodCl&&goodSeed && AliDebugLevelClass()>2 ) {
929 AliDebug(2,Form("Lost good cl on L:%d failed propagation. |ESDtrack#%d (MClb:%d)",lr,fCurrESDtrack->GetID(),fCurrESDtrMClb));
930 track->Print("etp");
15b02d69 931 cl->Print();
932 }
c8d1f258 933 return kStopSearchOnSensor; // propagation failed, seedT is intact
934 }
f8832015 935 }
3dd9c283 936 double dy = cl->GetY()-track->GetY();
c8d1f258 937 double dz = cl->GetZ()-track->GetZ();
0091e9f0 938 //
76390254 939#ifdef _FILL_CONTROL_HISTOS_
bdb92766 940 int hcOffs = (1+fTrackPhase)*kHistosPhase + lr;
76390254 941 double htrPt=-1;
cb50e082 942 if (goodCl && (((AliITSUClusterPix*)cl)->GetNPix()>1 || !((AliITSUClusterPix*)cl)->IsSplit()) && goodSeed && fCHistoArr /* && track->GetChi2Penalty()<1e-5*/) {
76390254 943 htrPt = track->Pt();
53870004 944 ((TH2*)fCHistoArr->At(kHResY+hcOffs))->Fill(htrPt,dy);
945 ((TH2*)fCHistoArr->At(kHResZ+hcOffs))->Fill(htrPt,dz);
76390254 946 double errY = track->GetSigmaY2();
947 double errZ = track->GetSigmaZ2();
53870004 948 if (errY>0) ((TH2*)fCHistoArr->At(kHResYP+hcOffs))->Fill(htrPt,dy/Sqrt(errY));
949 if (errZ>0) ((TH2*)fCHistoArr->At(kHResZP+hcOffs))->Fill(htrPt,dz/Sqrt(errZ));
76390254 950 }
951#endif
952 //
f8832015 953 double dy2 = dy*dy;
954 double tol2 = (track->GetSigmaY2() + AliITSUReconstructor::GetRecoParam()->GetSigmaY2(lr))*
ee54014a 955 fCurrTrackCond->GetNSigmaRoadY(lr)*fCurrTrackCond->GetNSigmaRoadY(lr); // RS TOOPTIMIZE
f8832015 956 if (dy2>tol2) { // the clusters are sorted in Z(col) then in Y(row).
53870004 957 if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
958 AliDebug(2,Form("Lost good cl: dy2=%e > tol2=%e |ESDtrack#%d (MClb:%d)",dy2,tol2,fCurrESDtrack->GetID(),fCurrESDtrMClb));
959 track->Print("etp");
15b02d69 960 cl->Print();
53870004 961 PrintSeedClusters(track);
15b02d69 962 }
cb50e082 963 // clusters are sorted in increasing Y and the loop goes from last (highers Y) to 1st.
964 // if the track has too large y for this cluster (dy<0) it will be so for all other clusters of the sensor
965 if (dy<0) return kStopSearchOnSensor; // No chance that other cluster of this sensor will match (all Y's will be even larger)
f8832015 966 else return kClusterNotMatching; // Other clusters may match
967 }
c8d1f258 968 double dz2 = dz*dz;
f8832015 969 tol2 = (track->GetSigmaZ2() + AliITSUReconstructor::GetRecoParam()->GetSigmaZ2(lr))*
ee54014a 970 fCurrTrackCond->GetNSigmaRoadZ(lr)*fCurrTrackCond->GetNSigmaRoadZ(lr); // RS TOOPTIMIZE
c8d1f258 971 if (dz2>tol2) {
53870004 972 if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
973 AliDebug(2,Form("Lost good cl on L:%d : dz2=%e > tol2=%e |ESDtrack#%d (MClb:%d)",lr,dz2,tol2,fCurrESDtrack->GetID(),fCurrESDtrMClb));
974 track->Print("etp");
15b02d69 975 cl->Print();
53870004 976 PrintSeedClusters(track);
15b02d69 977 }
c8d1f258 978 return kClusterNotMatching; // Other clusters may match
979 }
f8832015 980 //
981 // check chi2
982 Double_t p[2]={cl->GetY(), cl->GetZ()};
983 Double_t cov[3]={cl->GetSigmaY2(), cl->GetSigmaYZ(), cl->GetSigmaZ2()};
984 double chi2 = track->GetPredictedChi2(p,cov);
76390254 985 //
986#ifdef _FILL_CONTROL_HISTOS_
987 if (htrPt>0) {
53870004 988 ((TH2*)fCHistoArr->At(kHChi2Cl+hcOffs))->Fill(htrPt,chi2);
76390254 989 }
990#endif
991 //
ee54014a 992 if (chi2>fCurrTrackCond->GetMaxTr2ClChi2(lr)) {
53870004 993 if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
994 AliDebug(2,Form("Lost good cl on L:%d : Chi2=%e > Chi2Max=%e |dy: %+.3e dz: %+.3e |ESDtrack#%d (MClb:%d)\n",
ee54014a 995 lr,chi2,fCurrTrackCond->GetMaxTr2ClChi2(lr),dy,dz,fCurrESDtrack->GetID(),fCurrESDtrMClb));
3dd9c283 996 track->Print("etp");
997 cl->Print("");
53870004 998 PrintSeedClusters(track);
3dd9c283 999 }
c8d1f258 1000 return kClusterNotMatching;
1001 }
f8832015 1002 //
1003 track = NewSeedFromPool(track); // input track will be reused, use its clone for updates
943e1898 1004 if (!track->Update()) {
53870004 1005 if (goodCl&&goodSeed && AliDebugLevelClass()>2) {
1006 AliDebug(2,Form("Lost good cluster on L:%d : failed to update",lr));
38997c3c 1007 track->Print("etp");
1008 cl->Print("");
53870004 1009 PrintSeedClusters(track);
38997c3c 1010 }
b8b59e05 1011 MarkSeedFree(track);
c8d1f258 1012 return kClusterNotMatching;
1013 }
f8832015 1014 track->SetChi2Cl(chi2);
1015 track->SetLrClusterID(lr,clID);
c03e4f8a 1016 // cl->IncreaseClusterUsage(); // do this only for winners
f8832015 1017 //
716ccba7 1018 track->SetFake(!goodCl);
1019 //
0ddbf657 1020 AliDebug(2,Form("AddCl(%d) Cl%d lr:%d: dY:%+8.4f dZ:%+8.4f (MC: %5d %5d %5d) |Chi2=%f(%c)| ",
716ccba7 1021 goodCl,clID,lr,dy,dz2,cl->GetLabel(0),cl->GetLabel(1),cl->GetLabel(2), chi2, track->IsFake() ? '-':'+'));
c8d1f258 1022 //
38997c3c 1023 AddSeedBranch(track);
c03e4f8a 1024#ifdef _FILL_CONTROL_HISTOS_
1025 if (htrPt>0) {
1026 ((TH2*)fCHistoArr->At(kHChi2Nrm+hcOffs))->Fill(htrPt,track->GetChi2GloNrm());
1027 }
1028#endif
f8832015 1029 //
1030 return kClusterMatching;
1031}
c8d1f258 1032
1033//_________________________________________________________________________
1034Bool_t AliITSUTrackerGlo::NeedToKill(AliITSUSeed *seed, Int_t flag)
1035{
1036 // check if the seed should not be discarded
1037 const UShort_t kMask = 0xffff;
1038 if (flag==kMissingCluster) {
1039 int lastChecked = seed->GetLayerID();
1040 UShort_t patt = seed->GetHitsPattern();
c03e4f8a 1041 if (lastChecked) patt |= ~(kMask<<lastChecked); // not all layers were checked, complete unchecked ones by potential hits
42c3d4bd 1042 Bool_t seedOK = fCurrTrackCond->CheckPattern(patt);
c8d1f258 1043 return !seedOK;
1044 }
1045 return kTRUE;
1046}
44785f3e 1047
1048//______________________________________________________________________________
1049Bool_t AliITSUTrackerGlo::PropagateSeed(AliITSUSeed *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
1050{
1051 // propagate seed to given x applying material correction if requested
1052 const Double_t kEpsilon = 1e-5;
1053 Double_t xpos = seed->GetX();
1054 Int_t dir = (xpos<xToGo) ? 1:-1;
1055 Double_t xyz0[3],xyz1[3],param[7];
1056 //
8b16dbae 1057 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
f497470c 1058 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
44785f3e 1059 while ( (xToGo-xpos)*dir > kEpsilon){
1060 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
1061 Double_t x = xpos+step;
1062 Double_t bz=GetBz(); // getting the local Bz
0ddbf657 1063 if (!seed->PropagateToX(x,bz)) return kFALSE;
8b16dbae 1064 double ds = 0;
1065 if (matCorr || updTime) {
44785f3e 1066 xyz0[0]=xyz1[0]; // global pos at the beginning of step
1067 xyz0[1]=xyz1[1];
1068 xyz0[2]=xyz1[2];
1069 seed->GetXYZ(xyz1); // // global pos at the end of step
8b16dbae 1070 if (matCorr) {
1071 MeanMaterialBudget(xyz0,xyz1,param);
1072 Double_t xrho=param[0]*param[4], xx0=param[1];
1073 if (dir>0) xrho = -xrho; // outward should be negative
b2d3bc3a 1074 if (!seed->ApplyMaterialCorrection(xx0,xrho,mass,kFALSE)) {AliInfo("Fail2"); seed->Print("etp"); return kFALSE;}
8b16dbae 1075 ds = param[4];
1076 }
1077 else { // matCorr is not requested but time integral is
1078 double d0 = xyz1[0]-xyz0[0];
1079 double d1 = xyz1[1]-xyz0[1];
1080 double d2 = xyz1[2]-xyz0[2];
1081 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
1082 }
44785f3e 1083 }
8b16dbae 1084 if (updTime) seed->AddTimeStep(ds);
44785f3e 1085 xpos = seed->GetX();
1086 }
1087 return kTRUE;
1088}
716ccba7 1089
3e4e3c23 1090//______________________________________________________________________________
1091Bool_t AliITSUTrackerGlo::PropagateSeed(AliExternalTrackParam *seed, Double_t xToGo, Double_t mass, Double_t maxStep, Bool_t matCorr)
1092{
1093 // propagate seed to given x applying material correction if requested
1094 const Double_t kEpsilon = 1e-5;
1095 Double_t xpos = seed->GetX();
1096 Int_t dir = (xpos<xToGo) ? 1:-1;
1097 Double_t xyz0[3],xyz1[3],param[7];
1098 //
b515ad7e 1099 if (AliDebugLevelClass()>1) {
1100 AliDebug(2,Form("Before Propagate to X=%f with M=%.3f MaxStep=%.4f MatCorr=%d",xToGo,mass,maxStep,matCorr));
1101 seed->AliExternalTrackParam::Print();
1102 }
3e4e3c23 1103 Bool_t updTime = dir>0 && seed->IsStartedTimeIntegral();
1104 if (matCorr || updTime) seed->GetXYZ(xyz1); //starting global position
1105 while ( (xToGo-xpos)*dir > kEpsilon){
1106 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
1107 Double_t x = xpos+step;
1108 Double_t bz=GetBz(); // getting the local Bz
1109 if (!seed->PropagateTo(x,bz)) return kFALSE;
1110 double ds = 0;
1111 if (matCorr || updTime) {
1112 xyz0[0]=xyz1[0]; // global pos at the beginning of step
1113 xyz0[1]=xyz1[1];
1114 xyz0[2]=xyz1[2];
1115 seed->GetXYZ(xyz1); // // global pos at the end of step
1116 //
1117 if (matCorr) {
1118 MeanMaterialBudget(xyz0,xyz1,param);
1119 Double_t xrho=param[0]*param[4], xx0=param[1];
1120 if (dir>0) xrho = -xrho; // outward should be negative
1121 if (!seed->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
1122 ds = param[4];
1123 }
1124 else { // matCorr is not requested but time integral is
1125 double d0 = xyz1[0]-xyz0[0];
1126 double d1 = xyz1[1]-xyz0[1];
1127 double d2 = xyz1[2]-xyz0[2];
1128 ds = TMath::Sqrt(d0*d0+d1*d1+d2*d2);
1129 }
1130 }
1131 if (updTime) seed->AddTimeStep(ds);
1132 //
1133 xpos = seed->GetX();
1134 }
b515ad7e 1135 if (AliDebugLevelClass()>1) {
1136 AliDebug(2,Form("After Propagate to X=%f",xToGo));
1137 seed->AliExternalTrackParam::Print();
1138 }
3e4e3c23 1139 return kTRUE;
1140}
1141
9cdcba2c 1142//______________________________________________________________________________
1143Bool_t AliITSUTrackerGlo::FinalizeHypothesis(AliITSUTrackHyp* hyp)
1144{
1145 // finalize single TPC track hypothesis
1146 if (!hyp || hyp->GetESDTrack()->IsOn(AliESDtrack::kITSin)) return kFALSE;
1147 AliITSUSeed* winner = 0;
1148 fCurrHyp = hyp;
70cb7fe4 1149 fCurrMass = hyp->GetMass();
9cdcba2c 1150 if (!(winner=hyp->DefineWinner())) return kFALSE;
1151 FlagSeedClusters(winner,kTRUE);
1152 CookMCLabel(hyp);
1153 //
1154#ifdef _FILL_CONTROL_HISTOS_
1155 if (fCHistoArr) {
1156 TH2* hchimt = 0;
1157 TH2* hchiSA = 0;
1158 int lb = Abs(hyp->GetESDTrack()->GetTPCLabel());
1159 if ( hyp->GetITSLabel()==lb ) {
1160 hchimt = (TH2*)fCHistoArr->At(kHChiMatchCorr);
1161 hchiSA = (TH2*)fCHistoArr->At(kHChiITSSACorr);
1162 }
1163 else if ( Abs(hyp->GetITSLabel()) == lb ) hchimt = (TH2*)fCHistoArr->At(kHChiMatchFake);
1164 else if ( hyp->GetITSLabel()>=0 ) hchimt = (TH2*)fCHistoArr->At(kHChiMatchCorrMiss);
1165 else hchimt = (TH2*)fCHistoArr->At(kHChiMatchFakeMiss);
1166 if (!hchiSA) hchiSA = (TH2*)fCHistoArr->At(kHChiITSSAFake);
70cb7fe4 1167 // printf("MTStatus: ITS:%+5d TPC:%+5d chimt:%e chi2SA:%e-> %s\n",hyp->GetITSLabel(),lb,winner->GetChi2ITSTPC(),winner->GetChi2ITSSA(),hchimt->GetName());
9cdcba2c 1168 if (hchimt) hchimt->Fill(hyp->GetTPCSeed()->Pt(),winner->GetChi2ITSTPC());
1169 if (hchiSA) hchiSA->Fill(hyp->GetTPCSeed()->Pt(),winner->GetChi2ITSSA());
1170 }
1171#endif
1172 //
1173 UpdateESDTrack(hyp,AliESDtrack::kITSin);
1174 return kTRUE;
1175}
1176
3e4e3c23 1177//______________________________________________________________________________
1178void AliITSUTrackerGlo::FinalizeHypotheses()
1179{
1180 // select winner for each hypothesis, remove cl. sharing conflicts
9cdcba2c 1181 AliCodeTimerAuto("",0);
15b02d69 1182 AliDebug(2,"TODO");
3e4e3c23 1183 //
1184 int nh = fHypStore.GetEntriesFast();
1185 for (int ih=0;ih<nh;ih++) {
9cdcba2c 1186 if (FinalizeHypothesis( GetTrackHyp(ih) )) fCountITSin++;
3e4e3c23 1187 }
c03e4f8a 1188 //
9cdcba2c 1189 AliITSUSeed* winner = 0;
1190
bdb92766 1191#ifdef _FILL_CONTROL_HISTOS_
1192 // if requested, collect cluster sharing statistics
1193 TH2* hShare = 0;
1194 if (fCHistoArr && (hShare=(TH2*)fCHistoArr->At(kHClShare))) {
1195 for (int ih=0;ih<nh;ih++) {
9cdcba2c 1196 AliITSUTrackHyp* hyp = GetTrackHyp(ih);
bdb92766 1197 if (!hyp || !(winner=hyp->GetWinner())) continue;
1198 int lrID = 0;
1199 double pt = hyp->Pt();
1200 do {
1201 int clID = winner->GetLrCluster(lrID);
1202 if (clID<0) continue;
1203 AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
1204 if (!cl->IsClusterShared()) continue;
1205 hShare->Fill(pt,winner->IsFake() ? lrID+fNLrActive : lrID);
1206 } while ((winner=(AliITSUSeed*)winner->GetParent()));
1207 }
1208 }
1209#endif
1210
9cdcba2c 1211 AliRefArray** refArr = new AliRefArray*[fNLrActive];
1212 for (int ilr=0;ilr<fNLrActive;ilr++) refArr[ilr] = new AliRefArray(1000);
1213 for (int ih=0;ih<nh;ih++) {
1214 AliITSUTrackHyp* hyp = GetTrackHyp(ih);
1215 if (!hyp || !(winner=hyp->GetWinner())) continue;
1216 int lrID = 0;
1217 do {
1218 int clID = winner->GetLrCluster(lrID);
1219 if (clID<0) continue;
1220 AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
1221 if (!cl->IsClusterShared()) continue;
1222 refArr[lrID]->AddReference(clID,ih);
1223 } while ((winner=(AliITSUSeed*)winner->GetParent()));
1224 }
70cb7fe4 1225 /*
9cdcba2c 1226 UInt_t refs[100];
1227 for (int ilr=0;ilr<fNLrActive;ilr++) {
1228 int ncl = fITS->GetLayerActive(ilr)->GetNClusters();
1229 printf("\nClusterSharingDump: Lr %d (%d cl)\n",ilr,ncl);
1230 int cnt = 0;
1231 for (int icl=0;icl<ncl;icl++) {
1232 if (!refArr[ilr]->HasReference(icl)) continue;
1233 int nref = refArr[ilr]->GetReferences(icl,refs,100);
70cb7fe4 1234 // printf("--- cl%3d(#%d): NShare=%4d\n",cnt++,icl,nref);
9cdcba2c 1235 for (int ir=0;ir<nref;ir++) {
1236 AliITSUTrackHyp* hyp = GetTrackHyp(refs[ir]);
1237 winner = hyp->GetWinner();
1238 AliESDtrack* esdTr = hyp->GetESDTrack();
1239 printf("#%4d Pt:%.3f Chi:%6.2f Ncl:%d MCits%+5d MCtpc:%+5d ESD:%4d |",
1240 refs[ir],winner->Pt(),winner->GetChi2GloNrm(),winner->GetNLayersHit(),
1241 hyp->GetITSLabel(),esdTr->GetTPCLabel(),esdTr->GetID());
1242 int prevL=-1;
1243 do {
1244 int lrs;
1245 int clID = winner->GetLrCluster(lrs);
1246 if (clID<0) continue;
1247 while( lrs>++prevL ) printf("%4s ","----");
1248 printf("%4d (%5.1f)",clID,winner->GetChi2Cl());
1249 } while ((winner=(AliITSUSeed*)winner->GetParent()));
1250 printf("|\n");
1251 }
1252 }
1253 }
70cb7fe4 1254 */
9cdcba2c 1255 delete[] refArr;
1256
3e4e3c23 1257}
c51c3124 1258
1259//______________________________________________________________________________
68a0f687 1260void AliITSUTrackerGlo::UpdateESDTrack(AliITSUTrackHyp* hyp,Int_t flag)
c51c3124 1261{
1262 // update ESD track with current best hypothesis
1263 AliESDtrack* esdTr = hyp->GetESDTrack();
1264 if (!esdTr) return;
1265 AliITSUSeed* win = hyp->GetWinner();
1266 if (!win) return;
70cb7fe4 1267 double chiSav;
1268 //
68a0f687 1269 switch (flag) {
1270 case AliESDtrack::kITSin:
1271 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
1272 // TODO: set cluster info
1273 break;
1274 //
1275 case AliESDtrack::kITSout:
70cb7fe4 1276 // here the stored chi2 will correspond to backward ITS-SA fit
68a0f687 1277 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
1278 // TODO: avoid setting friend
1279 break;
1280 //
1281 case AliESDtrack::kITSrefit:
70cb7fe4 1282
1283 // at the moment fill as a chi2 the TPC-ITS matching chi2
1284 chiSav = hyp->GetChi2();
1285 hyp->SetChi2(win->GetChi2ITSTPC());
68a0f687 1286 esdTr->UpdateTrackParams(hyp,flag); // update kinematics
70cb7fe4 1287 hyp->SetChi2(chiSav);
68a0f687 1288 // TODO: avoid setting cluster info
1289 break;
1290 default:
1291 AliFatal(Form("Unknown flag %d",flag));
1292 }
c51c3124 1293 //
bdb92766 1294 esdTr->SetITSLabel(hyp->GetITSLabel());
c51c3124 1295 // transfer module indices
1296 // TODO
1297}
1298
1299//______________________________________________________________________________
9cdcba2c 1300Double_t AliITSUTrackerGlo::RefitTrack(AliExternalTrackParam* trc, Double_t rDest, Int_t stopCond)
c51c3124 1301{
9cdcba2c 1302 // refit track till radius rDest. The cluster,mass info is taken from fCurrHyp (and its winner seed)
1303 // if stopCond<0 : propagate till last cluster then stop
1304 // if stopCond==0: propagate till last cluster then try to go till limiting rDest, don't mind if fail
1305 // if stopCond>0 : rDest must be reached
8b16dbae 1306 //
c51c3124 1307 double rCurr = Sqrt(trc->GetX()*trc->GetX() + trc->GetY()*trc->GetY());
1308 int dir,lrStart,lrStop;
1309 //
8b16dbae 1310 dir = rCurr<rDest ? 1 : -1;
1311 lrStart = fITS->FindFirstLayerID(rCurr,dir);
70cb7fe4 1312 lrStop = fITS->FindLastLayerID(rDest,dir); // lr id before which we have to stop
1313 //
15b02d69 1314 if (AliDebugLevelClass()>2) {
1315 printf("Refit %d: Lr:%d (%f) -> Lr:%d (%f)\n",dir,lrStart,rCurr, lrStop,rDest);
9cdcba2c 1316 printf("Before refit: "); trc->Print();
15b02d69 1317 }
8b16dbae 1318 if (lrStop<0 || lrStart<0) AliFatal(Form("Failed to find start(%d) or last(%d) layers. Track from %.3f to %.3f",lrStart,lrStop,rCurr,rDest));
1319 //
9cdcba2c 1320 Int_t clInfo[2*AliITSUAux::kMaxLayers];
1321 Int_t nCl = fCurrHyp->FetchClusterInfo(clInfo);
1322 fCurrMass = fCurrHyp->GetMass();
1323 AliExternalTrackParam tmpTr(*trc);
1324 double chi2 = 0;
68a0f687 1325 int iclLr[2],nclLr,clCount=0;
c51c3124 1326 //
70cb7fe4 1327 int lrStop1 = lrStop+1;
1328 for (int ilr=lrStart;ilr!=lrStop1;ilr+=dir) {
c51c3124 1329 AliITSURecoLayer* lr = fITS->GetLayer(ilr);
1330 if ( dir*(rCurr-lr->GetR(dir))>0) continue; // this layer is already passed
8b16dbae 1331 int ilrA2,ilrA = lr->GetActiveID();
1332 // passive layer or active w/o hits will be traversed on the way to next cluster
9cdcba2c 1333 if (!lr->IsActive() || clInfo[ilrA2=(ilrA<<1)]<0) continue;
8b16dbae 1334 //
8b16dbae 1335 // select the order in which possible 2 clusters (in case of the overlap) will be traversed and fitted
1336 nclLr=0;
1337 if (dir>0) { // clusters are stored in increasing radius order
9cdcba2c 1338 iclLr[nclLr++]=clInfo[ilrA2++];
1339 if (clInfo[ilrA2]>=0) iclLr[nclLr++]=clInfo[ilrA2];
8b16dbae 1340 }
1341 else {
9cdcba2c 1342 if ( clInfo[ilrA2+1]>=0 ) iclLr[nclLr++]=clInfo[ilrA2+1];
1343 iclLr[nclLr++]=clInfo[ilrA2];
8b16dbae 1344 }
1345 //
b515ad7e 1346 Bool_t transportedToLayer = kFALSE;
8b16dbae 1347 for (int icl=0;icl<nclLr;icl++) {
1348 AliITSUClusterPix* clus = (AliITSUClusterPix*)lr->GetCluster(iclLr[icl]);
1349 AliITSURecoSens* sens = lr->GetSensorFromID(clus->GetVolumeId());
e7d83d38 1350 if (!tmpTr.Rotate(sens->GetPhiTF())) {
9cdcba2c 1351 AliESDtrack* trESD = fCurrHyp->GetESDTrack();
1352 AliDebug(2,Form("Failed on rotate to %f | ESDtrack#%d (MClb:%d)",sens->GetPhiTF(),trESD->GetID(),trESD->GetTPCLabel()));
1353 return -1;
e7d83d38 1354 }
b515ad7e 1355 //
1356 double xClus = sens->GetXTF()+clus->GetX();
1357 if (!transportedToLayer) {
1358 if (ilr!=lrStart && !TransportToLayerX(&tmpTr,lrStart,ilr,xClus)) {
9cdcba2c 1359 AliESDtrack* trESD = fCurrHyp->GetESDTrack();
1360 AliDebug(2,Form("Failed to transport %d -> %d | ESDtrack#%d (MClb:%d)\n",lrStart,ilr,trESD->GetID(),trESD->GetTPCLabel()));
1361 return -1; // go to the entrance to the layer
b515ad7e 1362 }
1363 lrStart = ilr;
1364 transportedToLayer = kTRUE;
1365 }
1366 //
1367 if (AliDebugLevelClass()>1) {
1368 AliDebug(2,Form("Propagate to cl:%d on lr %d Need to go %.4f -> %.4f",icl,ilrA,tmpTr.GetX(),xClus));
b515ad7e 1369 }
1370 //
1371 if (!PropagateSeed(&tmpTr,xClus,fCurrMass)) {
9cdcba2c 1372 AliESDtrack* trESD = fCurrHyp->GetESDTrack();
1373 AliDebug(2,Form("Failed on propagate to %f (dir=%d) | ESDtrack#%d (MClb:%d)",xClus,dir,trESD->GetID(),trESD->GetTPCLabel()));
1374 return -1;
e7d83d38 1375 }
76390254 1376 //
9cdcba2c 1377 Double_t p[2]={clus->GetY(), clus->GetZ()};
1378 Double_t cov[3]={clus->GetSigmaY2(), clus->GetSigmaYZ(), clus->GetSigmaZ2()};
1379 double chi2cl = tmpTr.GetPredictedChi2(p,cov);
1380 chi2 += chi2cl;
1381 //
76390254 1382#ifdef _FILL_CONTROL_HISTOS_
bdb92766 1383 int hcOffs = (1+fTrackPhase)*kHistosPhase + ilrA;
76390254 1384 double htrPt=-1;
9cdcba2c 1385 if (fCHistoArr && fTrackPhase>kClus2Tracks && trc->GetLabel()>=0/* && trc->Charge()>0*/) {
76390254 1386 htrPt = tmpTr.Pt();
9cdcba2c 1387 double dy = p[0]-tmpTr.GetY();
1388 double dz = p[1]-tmpTr.GetZ();
53870004 1389 ((TH2*)fCHistoArr->At(kHResY+hcOffs))->Fill(htrPt,dy);
1390 ((TH2*)fCHistoArr->At(kHResZ+hcOffs))->Fill(htrPt,dz);
76390254 1391 double errY = tmpTr.GetSigmaY2();
1392 double errZ = tmpTr.GetSigmaZ2();
53870004 1393 if (errY>0) ((TH2*)fCHistoArr->At(kHResYP+hcOffs))->Fill(htrPt,dy/Sqrt(errY));
1394 if (errZ>0) ((TH2*)fCHistoArr->At(kHResZP+hcOffs))->Fill(htrPt,dz/Sqrt(errZ));
9cdcba2c 1395 ((TH2*)fCHistoArr->At(kHChi2Cl+hcOffs))->Fill(htrPt,chi2cl);
76390254 1396 }
1397#endif
9cdcba2c 1398 //
1399 if ( !tmpTr.Update(p,cov) ) {
1400 AliESDtrack* trESD = fCurrHyp->GetESDTrack();
1401 AliDebug(2,Form("Failed on Update | ESDtrack#%d (MClb:%d)",trESD->GetID(),trESD->GetTPCLabel()));
1402 return -1;
e7d83d38 1403 }
b515ad7e 1404 if (AliDebugLevelClass()>1) {
9cdcba2c 1405 printf("AfterRefit: "); tmpTr.Print();
1406 }
1407 if (++clCount==nCl && stopCond<0) {
1408 *trc = tmpTr;
1409 return chi2; // it was requested to not propagate after last update
b515ad7e 1410 }
8b16dbae 1411 }
c51c3124 1412 //
1413 }
8b16dbae 1414 // All clusters were succesfully fitted. Even if the track does not reach rDest, this is enough to validate it.
1415 // Still, try to go as close as possible to rDest.
1416 //
70cb7fe4 1417 if (lrStart!=lrStop) {
e7d83d38 1418 if (!TransportToLayer(&tmpTr,lrStart,lrStop)) {
9cdcba2c 1419 AliDebug(-1,Form("Failed on TransportToLayer %d->%d | ESDtrack#%d (MClb:%d), X=%f",lrStart,lrStop,fCurrESDtrack->GetID(),fCurrESDtrMClb,tmpTr.GetX()));
1420 if (stopCond>0) return -chi2; // rDest was obligatory
e7d83d38 1421 }
1422 if (!GoToExitFromLayer(&tmpTr,fITS->GetLayer(lrStop),dir)) {
9cdcba2c 1423 AliDebug(-1,Form("Failed on GoToExitFromLayer %d | ESDtrack#%d (MClb:%d), X=%f",lrStop,fCurrESDtrack->GetID(),fCurrESDtrMClb,tmpTr.GetX()));
1424 if (stopCond>0) return -chi2; // rDest was obligatory
9cdcba2c 1425 }
70cb7fe4 1426 }
1427 // go to the destination radius. Note that here we don't select direction to avoid precision problems
1428 if (!tmpTr.GetXatLabR(rDest,rDest,GetBz(),0) || !PropagateSeed(&tmpTr,rDest,fCurrMass, 100, kFALSE)) {
1429 if (stopCond>0) return -chi2; // rDest was obligatory
1430 }
9cdcba2c 1431 *trc=tmpTr;
15b02d69 1432 if (AliDebugLevelClass()>2) {
9cdcba2c 1433 printf("After refit (now at lr %d): ",lrStop); trc->Print();
15b02d69 1434 }
9cdcba2c 1435 return chi2;
c51c3124 1436}
dd2117a2 1437
1438//__________________________________________________________________
1439void AliITSUTrackerGlo::CookMCLabel(AliITSUTrackHyp* hyp)
1440{
1441 // build MC label
1442 //
1443 const int kMaxLbPerCl = 3;
1444 int lbID[kMaxLayers*6],lbStat[kMaxLayers*6];
1445 Int_t lr,nLab=0,nCl=0;
1446 AliITSUSeed *seed = hyp->GetWinner();
1447 while(seed) {
1448 int clID = seed->GetLrCluster(lr);
1449 if (clID>=0) {
1450 AliCluster *cl = fITS->GetLayerActive(lr)->GetCluster(clID);
1451 nCl++;
1452 for (int imc=0;imc<kMaxLbPerCl;imc++) { // labels within single cluster
1453 int trLb = cl->GetLabel(imc);
704d9398 1454 if (trLb<0) break;
dd2117a2 1455 // search this mc track in already accounted ones
1456 int iLab;
1457 for (iLab=0;iLab<nLab;iLab++) if (lbID[iLab]==trLb) break;
1458 if (iLab<nLab) lbStat[iLab]++;
1459 else {
1460 lbID[nLab] = trLb;
1461 lbStat[nLab++] = 1;
1462 }
1463 } // loop over given cluster's labels
1464 }
1465 seed = (AliITSUSeed*)seed->GetParent();
1466 } // loop over clusters
1467 //
5785a9d8 1468 AliESDtrack* esdTr = hyp->GetESDTrack();
1469 int tpcLab = esdTr ? Abs(esdTr->GetTPCLabel()) : -kDummyLabel;
41343470 1470 if (nCl && nLab) {
dd2117a2 1471 int maxLab=0,nTPCok=0;
dd2117a2 1472 for (int ilb=nLab;ilb--;) {
1473 int st = lbStat[ilb];
1474 if (lbStat[maxLab]<st) maxLab=ilb;
1475 if (tpcLab==lbID[ilb]) nTPCok += st;
1476 }
1477 hyp->SetFakeRatio(1.-float(nTPCok)/nCl);
1478 hyp->SetLabel( nTPCok==nCl ? tpcLab : -tpcLab);
bdb92766 1479 hyp->SetITSLabel( lbStat[maxLab]==nCl ? lbID[maxLab] : -lbID[maxLab]); // winner label
dd2117a2 1480 return;
1481 }
1482 //
1483 hyp->SetFakeRatio(-1.);
5785a9d8 1484 hyp->SetLabel( -tpcLab );
dd2117a2 1485 hyp->SetITSLabel( kDummyLabel );
1486}
38997c3c 1487
1488//__________________________________________________________________
1489Bool_t AliITSUTrackerGlo::AddSeedBranch(AliITSUSeed* seed)
1490{
1491 // add new prolongation branch for the seed to temporary array. The seeds are sorted according to Compare f-n
6cd80116 1492 if (fNCandidatesAdded+fNBranchesAdded>=fLayerMaxCandidates ) {
1493 AliInfo(Form("Number of candidates at layer %d for current seed reached %d, increasing buffer",fCurrActLrID,fLayerMaxCandidates));
1494 fLayerMaxCandidates = 2*(fLayerMaxCandidates+1);
1495 AliITSUSeed** tmpArr = fLayerCandidates;
1496 fLayerCandidates = new AliITSUSeed*[fLayerMaxCandidates];
1497 memcpy(fLayerCandidates,tmpArr,(fNCandidatesAdded+fNBranchesAdded)*sizeof(AliITSUSeed*));
1498 delete tmpArr; // delete only array, not objects
38997c3c 1499 }
1500 AliITSUSeed** branches = &fLayerCandidates[fNCandidatesAdded]; // note: fNCandidatesAdded is incremented after adding all branches of current seed
1501 int slot=fNBranchesAdded++;
1502 for (int slotF=slot;slotF--;) { // slotF is always slot-1
1503 AliITSUSeed* si = branches[slotF];
1504 if (si->Compare(seed)<0) break; // found the last seed with better quality
1505 // otherwise, shift the worse seed to the next slot
1506 branches[slot] = si;
1507 slot = slotF; // slot should be slotF+1
1508 }
1509 // if needed, move worse seeds
1510 branches[slot] = seed;
1511 return kTRUE;
1512 //
1513}
1514
1515//__________________________________________________________________
1516void AliITSUTrackerGlo::ValidateAllowedBranches(Int_t acceptMax)
1517{
1518 // keep allowed number of branches for current seed and disable extras
70cb7fe4 1519 AliCodeTimerAuto("",0);
38997c3c 1520 int nb = Min(fNBranchesAdded,acceptMax);
1521 // if (nb<fNBranchesAdded) printf("ValidateAllowedBranches: %d of %d (%d) on lr %d\n",nb,fNBranchesAdded,fNCandidatesAdded,ilr);
1522 // disable unused branches
1523 AliITSUSeed** branches = &fLayerCandidates[fNCandidatesAdded];
c03e4f8a 1524#ifdef _FILL_CONTROL_HISTOS_
1525 int bestID = -1;
1526 for (int ib=0;ib<fNBranchesAdded;ib++) {
1527 AliITSUSeed* sd = branches[ib];
1528 if (!sd->ContainsFake() && (bestID<0 || sd->Compare(branches[bestID])<0) ) bestID = ib;
1529 }
1530 if (bestID>=0) {
bdb92766 1531 TH2* hb = (TH2*)fCHistoArr->At(kHBestInBranch + (1+fTrackPhase)*kHistosPhase + fCurrActLrID);
c03e4f8a 1532 if (hb) hb->Fill(branches[bestID]->Pt(), bestID);
1533 }
1534#endif
bdb92766 1535 //
38997c3c 1536 for (int ib=nb;ib<fNBranchesAdded;ib++) {
bdb92766 1537 //
1538#ifdef _FILL_CONTROL_HISTOS_
1539 if (AliDebugLevelClass()>-2 && !branches[ib]->ContainsFake() /*&& branches[ib]->GetNLayersHit()*/
1540 && (bestID<0 || branches[ib]->Compare(branches[bestID])<0 ) ) {
38997c3c 1541 printf("Suppress good branch as %d of %d |",ib,fNBranchesAdded); branches[ib]->Print();
bdb92766 1542 // printf("Survivors : \n");
1543 // for (int j=0;j<nb;j++) branches[j]->Print();
38997c3c 1544 }
bdb92766 1545#endif
38997c3c 1546 MarkSeedFree(branches[ib]);
1547 }
1548 fNCandidatesAdded += nb; // update total candidates counter
1549 fNBranchesAdded = 0; // reset branches counter
1550 //
1551}
1552
1553//__________________________________________________________________
1554void AliITSUTrackerGlo::ValidateAllowedCandidates(Int_t ilr, Int_t acceptMax)
1555{
1556 // transfer allowed number of branches to hypothesis container
1557 //
9cdcba2c 1558 AliCodeTimerAuto("",0);
38997c3c 1559 // sort candidates in increasing order of chi2
6cd80116 1560 static int lastSize = 0;
1561 static int *index = 0;
1562 static float *chi2 = 0;
1563 if (fLayerMaxCandidates>lastSize) {
1564 lastSize = fLayerMaxCandidates;
1565 delete[] index;
1566 delete[] chi2;
1567 index = new int[lastSize];
1568 chi2 = new float[lastSize];
1569 }
38997c3c 1570 for (int i=fNCandidatesAdded;i--;) chi2[i] = fLayerCandidates[i]->GetChi2GloNrm();
1571 Sort(fNCandidatesAdded,chi2,index,kFALSE);
1572 //
c03e4f8a 1573#ifdef _FILL_CONTROL_HISTOS_
1574 int bestID = -1;
1575 for (int ib=0;ib<fNCandidatesAdded;ib++) {
1576 AliITSUSeed* sd = fLayerCandidates[index[ib]];
1577 if (!sd->ContainsFake() && (bestID<0 || sd->Compare(fLayerCandidates[index[bestID]])<0) ) bestID = ib;
1578 }
1579 if (bestID>=0) {
bdb92766 1580 TH2* hb = (TH2*)fCHistoArr->At(kHBestInCand + (1+fTrackPhase)*kHistosPhase + fCurrActLrID);
c03e4f8a 1581 if (hb) hb->Fill(fLayerCandidates[index[bestID]]->Pt(), bestID);
1582 }
1583#endif
1584 //
9cdcba2c 1585 int nacc=0,nb=0;
1586 if (ilr>0) { // just take 1st acceptMax candidates
1587 nb = Min(fNCandidatesAdded,acceptMax);
1588 for (int ib=0;ib<nb;ib++) AddProlongationHypothesis(fLayerCandidates[index[ib]],ilr);
1589 }
1590 else { // for innermost layer test ITS SA backward chi2 and matching to TPC
1591 AliITSUSeed* wn0 = fCurrHyp->GetWinner(); // in principle, should be NULL
1592 for (nb=0;nb<fNCandidatesAdded;nb++) {
1593 AliITSUSeed* sd = fLayerCandidates[index[nb]];
1594 fCurrHyp->SetWinner(sd);
1595 if (!CheckBackwardMatching(sd)) MarkSeedFree(sd); // discard bad backward tracks
1596 else {
1597 AddProlongationHypothesis(sd,ilr);
1598 if (++nacc==acceptMax) {nb++; break;} // the rest will be discarded
1599 }
1600 }
1601 fCurrHyp->SetWinner(wn0); // restore original winner (NULL?)
1602 }
38997c3c 1603 //
38997c3c 1604 // disable unused candidates
1605 for (int ib=nb;ib<fNCandidatesAdded;ib++) {
bdb92766 1606 //
1607#ifdef _FILL_CONTROL_HISTOS_
1608 if (AliDebugLevelClass()>-2 && !fLayerCandidates[index[ib]]->ContainsFake() /*&& fLayerCandidates[index[ib]]->GetNLayersHit()*/
1609 && (bestID<0 || fLayerCandidates[index[ib]]->Compare(fLayerCandidates[index[bestID]])<0 ) ) {
38997c3c 1610 printf("Suppress good candidate as %d of %d |",index[ib],fNCandidatesAdded); fLayerCandidates[index[ib]]->Print();
1611 }
bdb92766 1612#endif
38997c3c 1613 MarkSeedFree(fLayerCandidates[index[ib]]);
1614 }
1615 fNCandidatesAdded = 0; // reset candidates counter
1616 //
1617}
1618
9cdcba2c 1619//__________________________________________________________________
1620Bool_t AliITSUTrackerGlo::CheckBackwardMatching(AliITSUSeed* seed)
1621{
1622 // check seed backward propagation chi2 and matching to TPC
1623 double bz0 = GetBz();
70cb7fe4 1624 double rDest = fITS->GetRITSTPCRef(); // reference radius for comparison
9cdcba2c 1625 static AliExternalTrackParam trback;
1626 trback = *seed;
1627 trback.ResetCovariance(10000);
1628 int ndf = seed->GetNLayersHit()*2-5;
1629 double chi2sa = RefitTrack(&trback,rDest,1);
1630 if (chi2sa<0) return kFALSE;
1631 if (ndf>0) chi2sa /= ndf;
1632 if (chi2sa>fCurrTrackCond->GetMaxITSSAChi2()) return kFALSE;
1633 //
1634 // relate to TPC track at outer layer
1635 AliExternalTrackParam* tpcSeed = fCurrHyp->GetTPCSeed();
1636 if (!trback.Rotate(tpcSeed->GetAlpha()) || !trback.PropagateParamOnlyTo(tpcSeed->GetX(),bz0)) {
1637 if (AliDebugLevelClass()>+1 && !seed->ContainsFake()) {
1638 AliInfo(Form("Failed to propagate seed to TPC track @ X:%.3f Alpha:%.3f",tpcSeed->GetX(),tpcSeed->GetAlpha()));
1639 seed->Print("etp");
1640 trback.Print();
1641 }
1642 return kFALSE;
1643 }
1644 double chi2Match = trback.GetPredictedChi2(tpcSeed)/5;
1645 if (chi2Match>fCurrTrackCond->GetMaxITSTPCMatchChi2()) return kFALSE;
1646 //
1647 seed->SetChi2ITSSA(chi2sa);
1648 seed->SetChi2ITSTPC(chi2Match);
1649 return kTRUE;
1650}
1651
6cd80116 1652//__________________________________________________________________
1653void AliITSUTrackerGlo::SaveReducedHypothesesTree(AliITSUTrackHyp* dest)
1654{
1655 // remove those hypothesis seeds which dont lead to candidates at final layer
1656 //
1657 // 1st, flag the seeds to save
1658 int lr0 = 0;
1659 for (int isd=0;isd<fCurrHyp->GetNSeeds(lr0);isd++) {
1660 AliITSUSeed* seed = fCurrHyp->RemoveSeed(lr0,isd);
1661 if (!seed) continue;
1662 seed->FlagTree(AliITSUSeed::kSave);
1663 dest->AddSeed(seed,lr0);
1664 }
1665 for (int ilr=1;ilr<fNLrActive;ilr++) {
1666 int nsd = fCurrHyp->GetNSeeds(ilr);
1667 for (int isd=0;isd<nsd;isd++) {
1668 AliITSUSeed* seed = fCurrHyp->RemoveSeed(ilr,isd);
1669 if (!seed) continue; // already discarded or saved
1670 if (seed->IsSaved()) dest->AddSeed(seed,ilr);
1671 else MarkSeedFree(seed);
1672 }
1673 }
1674 //
1675 // AliInfo(Form("SeedsPool: %d, BookedUpTo: %d, free: %d",fSeedsPool.GetSize(),fSeedsPool.GetEntriesFast(),fNFreeSeeds));
1676}
1677
53870004 1678//__________________________________________________________________
1679void AliITSUTrackerGlo::FlagSplitClusters()
1680{
1681 // set special bit on split clusters using MC info
6cd80116 1682 for (int ilr=fNLrActive;ilr--;) {
53870004 1683 int nsplit=0;
1684 AliITSURecoLayer* lr = fITS->GetLayerActive(ilr);
1685 for (int isn=lr->GetNSensors();isn--;) {
1686 AliITSURecoSens* sens = lr->GetSensor(isn);
1687 int nCl = sens->GetNClusters();
1688 if (!nCl) continue;
1689 int cl0 = sens->GetFirstClusterId();
1690 for (int icl=nCl;icl--;) {
1691 AliITSUClusterPix *cl = (AliITSUClusterPix*)lr->GetCluster(cl0+icl);
1692 for (int icl1=icl;icl1--;) {
1693 AliITSUClusterPix *cl1 = (AliITSUClusterPix*)lr->GetCluster(cl0+icl1);
1694 if (cl->HasCommonTrack(cl1)) {
1695 if (!cl->IsSplit()) nsplit++;
1696 if (!cl1->IsSplit()) nsplit++;
1697 cl->SetSplit();
1698 cl1->SetSplit();
1699 }
1700 }
1701 }
1702 }
1703 AliInfo(Form("%4d out of %4d clusters are split",nsplit,lr->GetNClusters()));
1704 }
1705 //
1706}
1707
1708//__________________________________________________________________
1709Bool_t AliITSUTrackerGlo::ContainsSplitCluster(const AliITSUSeed* seed, Int_t maxSize)
1710{
1711 // check if the seed contains split cluster with size < maxSize
1712 int lrID,clID;
1713 if ( (clID=seed->GetLrCluster(lrID))>=0 ) {
1714 AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
1715 if (cl->IsSplit() && cl->GetNPix()<maxSize ) return kTRUE;
1716 }
1717 return seed->GetParent() ? ContainsSplitCluster((AliITSUSeed*)seed->GetParent(),maxSize) : kFALSE;
1718 //
1719}
1720
1721//__________________________________________________________________
1722void AliITSUTrackerGlo::PrintSeedClusters(const AliITSUSeed* seed, Option_t* option)
1723{
1724 // print seeds clusters
1725 int lrID,clID;
1726 if ( (clID=seed->GetLrCluster(lrID))>=0 ) {
1727 AliITSUClusterPix* cl = (AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID);
1728 cl->Print(option);
1729 }
1730 if (seed->GetParent()) PrintSeedClusters((AliITSUSeed*)seed->GetParent(), option);
1731 //
1732}
1733
c03e4f8a 1734//__________________________________________________________________
1735void AliITSUTrackerGlo::FlagSeedClusters(const AliITSUSeed* seed, Bool_t flg)
1736{
1737 // mark used clusters
1738 int lrID,clID;
1739 while (seed) {
bdb92766 1740 if ( (clID=seed->GetLrCluster(lrID))>=0 ) ((AliITSUClusterPix*)fITS->GetLayerActive(lrID)->GetCluster(clID))->ModClUsage(flg);
c03e4f8a 1741 seed = (AliITSUSeed*)seed->GetParent();
1742 }
1743 //
1744}
1745
1746
1747
53870004 1748#ifdef _FILL_CONTROL_HISTOS_
1749//__________________________________________________________________
1750void AliITSUTrackerGlo::BookControlHistos()
1751{
1752 // book special control histos
bdb92766 1753 if (fCHistoArr) return;
1754 const int kNResDef=7;
1755 const double kResDef[kNResDef]={0.05,0.05,0.3, 0.05,1,0.5,1.5};
1756 fCHistoArr = new TObjArray();
1757 fCHistoArr->SetOwner(kTRUE);
1758 const double ptMax=10;
1759 const double plMax=10;
1760 const double chiMax=100;
1761 const int nptbins=50;
1762 const int nresbins=400;
1763 const int nplbins=50;
1764 const int nchbins=200;
1765 const int maxBr = 15;
1766 const int maxCand = 200;
1767 TString ttl;
1768 for (int stp=0;stp<kNTrackingPhases;stp++) {
1769 for (int ilr=0;ilr<fNLrActive;ilr++) {
1770 int hoffs = (1+stp)*kHistosPhase + ilr;
1771 double mxdf = ilr>=kNResDef ? kResDef[kNResDef-1] : kResDef[ilr];
1772 ttl = Form("S%d_residY%d",stp,ilr);
1773 TH2F* hdy = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nresbins,-mxdf,mxdf);
1774 fCHistoArr->AddAtAndExpand(hdy,hoffs + kHResY);
1775 hdy->SetDirectory(0);
1776 //
1777 ttl = Form("S%d_residYPull%d",stp,ilr);
1778 TH2F* hdyp = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nplbins,-plMax,plMax);
1779 fCHistoArr->AddAtAndExpand(hdyp,hoffs + kHResYP);
1780 hdyp->SetDirectory(0);
1781 //
1782 ttl = Form("S%d_residZ%d",stp,ilr);
1783 TH2F* hdz = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nresbins,-mxdf,mxdf);
1784 fCHistoArr->AddAtAndExpand(hdz,hoffs + kHResZ);
1785 hdz->SetDirectory(0);
1786 //
1787 ttl = Form("S%d_residZPull%d",stp,ilr);
1788 TH2F* hdzp = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax,nplbins,-plMax,plMax);
1789 hdzp->SetDirectory(0);
1790 fCHistoArr->AddAtAndExpand(hdzp,hoffs + kHResZP);
1791 //
1792 ttl = Form("S%d_chi2Cl%d",stp,ilr);
1793 TH2F* hchi = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1794 hchi->SetDirectory(0);
1795 fCHistoArr->AddAtAndExpand(hchi,hoffs + kHChi2Cl);
1796 //
1797 ttl = Form("S%d_chi2Nrm%d",stp,ilr);
1798 TH2F* hchiN = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1799 hchiN->SetDirectory(0);
1800 fCHistoArr->AddAtAndExpand(hchiN,hoffs + kHChi2Nrm);
1801 //
1802 if (stp==0) { // these histos make sense only for clusters2tracks stage
1803 ttl = Form("S%d_bestInBranch%d",stp,ilr);
1804 TH2* hnbr = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, maxBr,-0.5,maxBr-0.5);
1805 hnbr->SetDirectory(0);
1806 fCHistoArr->AddAtAndExpand(hnbr,hoffs + kHBestInBranch);
c03e4f8a 1807 //
bdb92766 1808 ttl = Form("S%d_bestInCands%d",stp,ilr);
1809 TH2* hncn = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, maxCand,-0.5,maxCand-0.5);
1810 hncn->SetDirectory(0);
1811 fCHistoArr->AddAtAndExpand(hncn,hoffs + kHBestInCand);
c03e4f8a 1812 //
53870004 1813 }
1814 }
1815 }
bdb92766 1816 // custom histos
1817 ttl = Form("ClSharing");
1818 TH2* hclShare = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, 2*fNLrActive,0,2*fNLrActive);
1819 hclShare->SetDirectory(0);
1820 fCHistoArr->AddAtAndExpand(hclShare,kHClShare);
53870004 1821 //
9cdcba2c 1822 TH2* hchiMatch = 0;
1823 ttl = Form("Chi2MatchCorr");
1824 hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1825 hchiMatch->SetDirectory(0);
1826 fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchCorr);
1827 //
1828 ttl = Form("Chi2MatchFake");
1829 hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1830 hchiMatch->SetDirectory(0);
1831 fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchFake);
1832 //
1833 ttl = Form("Chi2MatchCorrMiss");
1834 hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1835 hchiMatch->SetDirectory(0);
1836 fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchCorrMiss);
1837 //
1838 ttl = Form("Chi2MatchFakeMiss");
1839 hchiMatch = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins,0.,chiMax);
1840 hchiMatch->SetDirectory(0);
1841 fCHistoArr->AddAtAndExpand(hchiMatch,kHChiMatchFakeMiss);
1842 //
1843 TH2* hchiSA = 0;
1844 ttl = Form("Chi2ITSSACorr");
1845 hchiSA = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins/2,0.,chiMax/2);
1846 hchiSA->SetDirectory(0);
1847 fCHistoArr->AddAtAndExpand(hchiSA,kHChiITSSACorr);
1848 //
1849 ttl = Form("Chi2ITSSAFake");
1850 hchiSA = new TH2F(ttl.Data(),ttl.Data(),nptbins,0,ptMax, nchbins/2,0.,chiMax/2);
1851 hchiSA->SetDirectory(0);
1852 fCHistoArr->AddAtAndExpand(hchiSA,kHChiITSSAFake);
1853 //
1854
53870004 1855}
1856#endif