use same binning for TH and THnSparse (M. Vajzer)
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
CommitLineData
e4f2f73d 1/**************************************************************************
972ef65e 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**************************************************************************/
e4f2f73d 15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Track finder //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
e4f2f73d 28#include <TBranch.h>
bb56afff 29#include <TDirectory.h>
e4f2f73d 30#include <TLinearFitter.h>
e4f2f73d 31#include <TTree.h>
32#include <TClonesArray.h>
e4f2f73d 33#include <TTreeStream.h>
eb2b4f91 34#include <TGeoMatrix.h>
35#include <TGeoManager.h>
e4f2f73d 36
37#include "AliLog.h"
fac58f00 38#include "AliMathBase.h"
e4f2f73d 39#include "AliESDEvent.h"
bb56afff 40#include "AliGeomManager.h"
e4f2f73d 41#include "AliRieman.h"
42#include "AliTrackPointArray.h"
43
e4f2f73d 44#include "AliTRDgeometry.h"
45#include "AliTRDpadPlane.h"
e4f2f73d 46#include "AliTRDcalibDB.h"
e4f2f73d 47#include "AliTRDReconstructor.h"
48#include "AliTRDCalibraFillHisto.h"
e4f2f73d 49#include "AliTRDrecoParam.h"
bb56afff 50
51#include "AliTRDcluster.h"
828c6f80 52#include "AliTRDdigitsParam.h"
e4f2f73d 53#include "AliTRDseedV1.h"
0906e73e 54#include "AliTRDtrackV1.h"
bb56afff 55#include "AliTRDtrackerV1.h"
56#include "AliTRDtrackerDebug.h"
57#include "AliTRDtrackingChamber.h"
58#include "AliTRDchamberTimeBin.h"
59
e4f2f73d 60ClassImp(AliTRDtrackerV1)
903326c1 61ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
eb38ed55 63
2f4384e6 64AliTRDtrackerV1::ETRDtrackerV1BetheBloch AliTRDtrackerV1::fgBB = AliTRDtrackerV1::kGeant;
d76231c8 65Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
6e39bde4 66 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
41702fec 67 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
68 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
e165b64b 69};
70const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
71 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
952051c5 72// Number of Time Bins/chamber should be also stored independently by the traker
73// (also in AliTRDReconstructor) in oder to be able to run HLT. Fix TODO
2985ffcb 74Int_t AliTRDtrackerV1::fgNTimeBins = 0;
4d6aee34 75AliRieman* AliTRDtrackerV1::fgRieman = NULL;
76TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
77TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
e4f2f73d 78
79//____________________________________________________________________
33ab3872 80AliTRDtrackerV1::AliTRDtrackerV1(const AliTRDReconstructor *rec)
41702fec 81 :AliTracker()
4d6aee34 82 ,fkReconstructor(NULL)
9e85cb05 83 ,fkRecoParam(NULL)
4d6aee34 84 ,fGeom(NULL)
85 ,fClusters(NULL)
86 ,fTracklets(NULL)
87 ,fTracks(NULL)
b1135f96 88 ,fTracksESD(NULL)
41702fec 89 ,fSieveSeeding(0)
9dcc64cc 90 ,fEventInFile(-1)
e4f2f73d 91{
41702fec 92 //
93 // Default constructor.
94 //
eb2b4f91 95
96 SetReconstructor(rec); // initialize reconstructor
97
98 // initialize geometry
99 if(!AliGeomManager::GetGeometry()){
100 AliFatal("Could not get geometry.");
101 }
102 fGeom = new AliTRDgeometry();
103 fGeom->CreateClusterMatrixArray();
4d6aee34 104 TGeoHMatrix *matrix = NULL;
eb2b4f91 105 Double_t loc[] = {0., 0., 0.};
106 Double_t glb[] = {0., 0., 0.};
107 for(Int_t ily=kNPlanes; ily--;){
e165b64b 108 Int_t ism = 0;
109 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
110 if(!matrix){
111 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
112 fR[ily] = fgkX0[ily];
eb2b4f91 113 continue;
114 }
115 matrix->LocalToMaster(loc, glb);
116 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
117 }
118
eb2b4f91 119 // initialize cluster containers
053767a4 120 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
3a039a31 121
eb2b4f91 122 // initialize arrays
123 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
124 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
125 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
b1135f96 126 fTracksESD = new TClonesArray("AliESDtrack", 2*kMaxTracksStack);
ddfbc51a 127 fTracksESD->SetOwner();
eb38ed55 128}
129
e4f2f73d 130//____________________________________________________________________
131AliTRDtrackerV1::~AliTRDtrackerV1()
132{
41702fec 133 //
134 // Destructor
135 //
136
4d6aee34 137 if(fgRieman) delete fgRieman; fgRieman = NULL;
138 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
139 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
d611c74f 140 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
b1135f96 141 if(fTracksESD){ fTracksESD->Delete(); delete fTracksESD; }
41702fec 142 if(fTracks) {fTracks->Delete(); delete fTracks;}
143 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
48f8adf3 144 if(fClusters) {
145 fClusters->Delete(); delete fClusters;
146 }
41702fec 147 if(fGeom) delete fGeom;
e4f2f73d 148}
149
150//____________________________________________________________________
151Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
152{
41702fec 153 //
154 // Steering stand alone tracking for full TRD detector
155 //
156 // Parameters :
157 // esd : The ESD event. On output it contains
158 // the ESD tracks found in TRD.
159 //
160 // Output :
161 // Number of tracks found in the TRD detector.
162 //
163 // Detailed description
164 // 1. Launch individual SM trackers.
165 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
166 //
167
9e85cb05 168 if(!fkRecoParam){
3a039a31 169 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
41702fec 170 return 0;
171 }
172
173 //AliInfo("Start Track Finder ...");
174 Int_t ntracks = 0;
053767a4 175 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
41702fec 176 // for(int ism=1; ism<2; ism++){
177 //AliInfo(Form("Processing supermodule %i ...", ism));
178 ntracks += Clusters2TracksSM(ism, esd);
179 }
980d5a2a 180 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
41702fec 181 return ntracks;
e4f2f73d 182}
183
0906e73e 184
185//_____________________________________________________________________________
eb38ed55 186Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
0906e73e 187{
41702fec 188 //AliInfo(Form("Asking for tracklet %d", index));
189
84eab75a 190 // reset position of the point before using it
191 p.SetXYZ(0., 0., 0.);
2f7514a6 192 AliTRDseedV1 *tracklet = GetTracklet(index);
193 if (!tracklet) return kFALSE;
84eab75a 194
41702fec 195 // get detector for this tracklet
e165b64b 196 Int_t det = tracklet->GetDetector();
197 Int_t sec = fGeom->GetSector(det);
198 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
199 sinA = TMath::Sin(alpha),
200 cosA = TMath::Cos(alpha);
41702fec 201 Double_t local[3];
e165b64b 202 local[0] = tracklet->GetX();
203 local[1] = tracklet->GetY();
204 local[2] = tracklet->GetZ();
41702fec 205 Double_t global[3];
e165b64b 206 fGeom->RotateBack(det, local, global);
207
208 Double_t cov2D[3]; Float_t cov[6];
209 tracklet->GetCovAt(local[0], cov2D);
210 cov[0] = cov2D[0]*sinA*sinA;
211 cov[1] =-cov2D[0]*sinA*cosA;
212 cov[2] =-cov2D[1]*sinA;
213 cov[3] = cov2D[0]*cosA*cosA;
214 cov[4] = cov2D[1]*cosA;
215 cov[5] = cov2D[2];
216 // store the global position of the tracklet and its covariance matrix in the track point
217 p.SetXYZ(global[0],global[1],global[2], cov);
41702fec 218
219 // setting volume id
e165b64b 220 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
221 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
41702fec 222 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
223 p.SetVolumeID(volid);
224
225 return kTRUE;
0906e73e 226}
227
eb38ed55 228//____________________________________________________________________
229TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
230{
41702fec 231 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
232 return fgTiltedRieman;
eb38ed55 233}
0906e73e 234
eb38ed55 235//____________________________________________________________________
236TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
237{
41702fec 238 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
239 return fgTiltedRiemanConstrained;
eb38ed55 240}
41702fec 241
eb38ed55 242//____________________________________________________________________
243AliRieman* AliTRDtrackerV1::GetRiemanFitter()
244{
fac58f00 245 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
41702fec 246 return fgRieman;
eb38ed55 247}
41702fec 248
0906e73e 249//_____________________________________________________________________________
250Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
251{
2a3191bb 252// Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
253// a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
254// covariance, PID, etc.) are than used to update the corresponding ESD track.
255// Each track seed is first propagated to the geometrical limit of the TRD detector.
256// Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
257// constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
258// Otherwise the ESD track is left unchanged.
259//
260// The following steps are performed:
261// 1. Selection of tracks based on the variance in the y-z plane.
262// 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
263// 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
264// the following status bits:
265// - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
266// - AliESDtrack::kTRDStop - if the tracks fails propagation
267// - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
268// 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
269// 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
270//
271
e3d45279 272 if(!fClusters || !fClusters->GetEntriesFast()){
273 AliInfo("No TRD clusters");
274 return 0;
275 }
2a3191bb 276 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
e3d45279 277 if (!calibra) AliInfo("Could not get Calibra instance");
c6f7c6cb 278 if (!fgNTimeBins) fgNTimeBins = fkReconstructor->GetNTimeBins();
828c6f80 279
eb2b4f91 280 // Define scalers
4b5b4c5b 281 const Int_t nSeeders(2);
282 Int_t nFound[nSeeders] = {0}, // number of tracks found
283 nBacked = 0, // number of tracks backed up for refit
284 nSeeds = 0, // total number of ESD seeds
285 nTRDseeds = 0, // number of seeds in the TRD acceptance
286 nSeeder[nSeeders]= {0}, // number of ITS/TPC potential seeds
287 nGoodSeeds[nSeeders]= {0}; // number of ITS/TPC found seeds
41702fec 288 Float_t foundMin = 20.0;
4b5b4c5b 289 const Char_t *seeder[] = {"ITS", "TPC"};
290 Float_t *quality[nSeeders] = {0};
291 Int_t *index[nSeeders] = {0},
292 *idxESD[nSeeders] = {0}; // esd index of track
9dcc64cc 293 fEventInFile = event->GetEventNumberInFile();
eb2b4f91 294 nSeeds = event->GetNumberOfTracks();
295 // Sort tracks according to quality
296 // (covariance in the yz plane)
297 if(nSeeds){
4b5b4c5b 298 // first check TPC seeds
299 quality[1] = new Float_t[nSeeds]; memset(quality[1], 0, nSeeds*sizeof(Float_t));
300 idxESD[1] = new Int_t[nSeeds];
301 for (Int_t iSeed(nSeeds); iSeed--;) {
302 AliESDtrack *seed = event->GetTrack(iSeed);
303 if(!(seed->GetStatus()&AliESDtrack::kTPCout)) continue;
304 Double_t covariance[15];
305 seed->GetExternalCovariance(covariance);
306 idxESD[1][nSeeder[1]] = iSeed;
307 quality[1][nSeeder[1]] = covariance[0] + covariance[2];
308 nSeeder[1]++;
309 }
310 index[1] = new Int_t[4*nSeeder[1]];
311 TMath::Sort(nSeeder[1], quality[1], index[1], kFALSE);
312 // second check rest of tracks for ITS seeds
313 quality[0] = new Float_t[nSeeds]; memset(quality[0], 0, nSeeds*sizeof(Float_t));
314 idxESD[0] = new Int_t[nSeeds];
315 for (Int_t iSeed(nSeeds); iSeed--;) {
d611c74f 316 AliESDtrack *seed = event->GetTrack(iSeed);
4b5b4c5b 317 if((seed->GetStatus()&AliESDtrack::kTPCout)) continue;
d611c74f 318 Double_t covariance[15];
319 seed->GetExternalCovariance(covariance);
4b5b4c5b 320 idxESD[0][nSeeder[0]] = iSeed;
321 quality[0][nSeeder[0]] = covariance[0] + covariance[2];
322 nSeeder[0]++;
d611c74f 323 }
4b5b4c5b 324 index[0] = new Int_t[4*nSeeder[0]];
325 TMath::Sort(nSeeder[0], quality[0], index[0], kFALSE);
41702fec 326 }
4b5b4c5b 327
eb2b4f91 328 // Propagate all seeds
41702fec 329 Int_t expectedClr;
330 AliTRDtrackV1 track;
4b5b4c5b 331 for(Int_t iSeeder(nSeeders); iSeeder--;){
332 for (Int_t iSeed = 0; iSeed < nSeeder[iSeeder]; iSeed++) {
333 Int_t currentIndexESD = idxESD[iSeeder][index[iSeeder][iSeed]];
334 // Get the seeds in sorted sequence
335 AliESDtrack *seed = event->GetTrack(currentIndexESD);
336 Float_t p4 = seed->GetC(seed->GetBz());
eb2b4f91 337
4b5b4c5b 338 // Check the seed status
339 ULong_t status(seed->GetStatus()); Bool_t kTPC(kTRUE);
340 if ((status & AliESDtrack::kTRDout) != 0) continue;
341 if (status & AliESDtrack::kTPCout){
342 AliDebug(2, Form("Found TPC seed @ idx[%4d] Sxy=%f[cm].", currentIndexESD, TMath::Sqrt(quality[iSeeder][index[iSeeder][iSeed]])));
343 // set steering parameters for TPC
344 //fkRecoParam->SetTrackParam(kTPC);
345 } else {
346 if (status & AliESDtrack::kITSout){
347 // rotate
348 Float_t globalToTracking = AliTRDgeometry::GetAlpha()*(Int_t(seed->GetAlpha()/AliTRDgeometry::GetAlpha()) + (seed->GetAlpha()>0. ? 0.5 : -0.5));
349 AliDebug(2, Form("Found ITS seed @ idx[%4d] Sxy=%f[cm] alpha=%7.2f[deg] g2T=%7.2f[deg]", currentIndexESD, TMath::Sqrt(quality[iSeeder][index[iSeeder][iSeed]]), seed->GetAlpha()*TMath::RadToDeg(), globalToTracking*TMath::RadToDeg()));
350 if(!seed->Rotate(globalToTracking)){
351 AliDebug(1, Form("ITS seed @ idx[%4d] failed rotation of alpha=%7.2f[deg] g2T=%7.2f[deg].", currentIndexESD, seed->GetAlpha()*TMath::RadToDeg(), globalToTracking*TMath::RadToDeg()));
352 continue;
353 }
354 kTPC=kFALSE;
355 // set steering parameters for ITS
356 //fkRecoParam->SetTrackParam(kITS);
357 } else {
358 AliDebug(1, Form("Bad seed[%4d] ITSin[%c] ITSout[%c] TPCin[%c] TPCout[%c].", currentIndexESD,
359 (status&AliESDtrack::kITSin)?'y':'n', (status&AliESDtrack::kITSout)?'y':'n', (status&AliESDtrack::kTPCin)?'y':'n', (status&AliESDtrack::kTPCout)?'y':'n'));
360 continue;
361 }
362 }
363
364 // Propagate to the entrance in the TRD mother volume
365 track.~AliTRDtrackV1();
366 new(&track) AliTRDtrackV1(*seed);
367 if(AliTRDgeometry::GetXtrdBeg() > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), AliTRDReconstructor::GetMaxStep())){
368 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
369 continue;
370 }
371 if(!AdjustSector(&track)){
372 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
373 continue;
374 }
375 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
376 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
377 continue;
378 }
379 AliDebug(2, Form("Propagate %s seed[%4d] ESDidx[%4d].", seeder[iSeeder], iSeed, currentIndexESD));
380 nGoodSeeds[iSeeder]++;
381 // store track status at TRD entrance
382 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
383
384 // prepare track and do propagation in the TRD
385 track.SetReconstructor(fkReconstructor);
386 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
387 track.SetPrimary(status & AliESDtrack::kTPCin);
388 track.SetNonTPCseeded(!kTPC);
389 expectedClr = FollowBackProlongation(track);
41702fec 390 // save calibration object
4b5b4c5b 391 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0) {
224f357f 392 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
393 calibTrack->SetOwner();
394 seed->AddCalibObject(calibTrack);
395 }
4b5b4c5b 396 // printf("track idx[%4d] nCl[%3d] TrkIn[%p]\n", index[iSeed], expectedClr, (void*)track.GetTrackIn());
41702fec 397
4b5b4c5b 398 // check if track entered the TRD fiducial volume
399 if(!track.GetTrackIn()){
400 AliDebug(2, Form("TRD missed by %s seed[%4d] ESDidx[%4d].", seeder[iSeeder], iSeed, currentIndexESD));
401 continue;
402 }
403 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
404 nTRDseeds++;
41702fec 405
4b5b4c5b 406 // check if track was stopped in the TRD
407 if(expectedClr==-999){
408 AliDebug(1, Form("Track @ idx[%4d] failed prolongation due to track error [%d]", currentIndexESD, track.GetStatusTRD()));
409 continue;
410 } else if(expectedClr==0){
411 AliDebug(1, Form("Track @ idx[%4d] failed prolongation due to layer error [%d %d %d %d %d %d]", currentIndexESD,
412 track.GetStatusTRD(0), track.GetStatusTRD(1), track.GetStatusTRD(2), track.GetStatusTRD(3), track.GetStatusTRD(4), track.GetStatusTRD(5)));
413 continue;
414 } else {
ef6f0bda 415 AliDebug(2, Form("Track @ idx[%4d] #cl[%3d] expect[%+3d]", currentIndexESD, track.GetNumberOfClusters(), expectedClr));
4b5b4c5b 416 nFound[kTPC]++;
417 // compute PID
418 track.CookPID();
419 //compute MC label
420 track.CookLabel(1. - AliTRDReconstructor::GetLabelFraction());
421 // update calibration references using this track
422 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
423 //update ESD track
424 seed->UpdateTrackParams(&track, expectedClr>0?AliESDtrack::kTRDout:AliESDtrack::kTRDStop);
425 seed->SetTRDBudget(track.GetBudget(0));
426 track.UpdateESDtrack(seed);
427 if(expectedClr<0) continue;
428 }
429
430 // Make backup for back propagation
431 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) || (track.Pt() > 0.8)) {
432 Int_t foundClr = track.GetNumberOfClusters();
433 if (foundClr >= foundMin) {
434 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
435
436 // Sign only gold tracks
437 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
438 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
439 }
440 Bool_t isGold = kFALSE;
441
442 // Full gold track
443 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
444 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
b453ef55 445 nBacked++;
41702fec 446 isGold = kTRUE;
447 }
4b5b4c5b 448
449 // Almost gold track
450 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
451 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
452 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
453 nBacked++;
454 isGold = kTRUE;
455 }
456
457 if ((!isGold) && (track.GetBackupTrack())) {
458 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
459 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
460 nBacked++;
461 isGold = kTRUE;
462 }
463 }
41702fec 464 }
41702fec 465 }
4b5b4c5b 466
467 // Propagation to the TOF
468 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
469 Int_t sm = track.GetSector();
470 // default value in case we have problems with the geometry.
471 Double_t xtof = 371.;
472 //Calculate radial position of the beginning of the TOF
473 //mother volume. In order to avoid mixing of the TRD
474 //and TOF modules some hard values are needed. This are:
475 //1. The path to the TOF module.
476 //2. The width of the TOF (29.05 cm)
477 //(with the help of Annalisa de Caro Mar-17-2009)
478 if(gGeoManager){
479 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
480 TGeoHMatrix *m = NULL;
481 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
482
483 if((m=gGeoManager->GetCurrentMatrix())){
484 m->LocalToMaster(loc, glob);
485 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
486 }
eb2b4f91 487 }
4b5b4c5b 488 if(xtof > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, xtof, AliTRDReconstructor::GetMaxStep())){
489 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
490 continue;
491 }
492 if(!AdjustSector(&track)){
493 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
494 continue;
495 }
496 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
497 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
498 continue;
499 }
500 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
501 // TODO obsolete - delete
502 seed->SetTRDQuality(track.StatusForTOF());
41702fec 503 }
504 }
4b5b4c5b 505 if(index[iSeeder]) delete [] index[iSeeder];
506 if(idxESD[iSeeder]) delete [] idxESD[iSeeder];
507 if(quality[iSeeder]) delete [] quality[iSeeder];
41702fec 508 }
41702fec 509
4b5b4c5b 510 AliInfo(Form("Number of seeds: ITSout[%4d] TPCout[%4d] TRDin[%4d]", nGoodSeeds[0], nGoodSeeds[1], nTRDseeds));
511 AliInfo(Form("Number of tracks: TRDout[%4d = %4d + %4d] TRDbackup[%4d]", nFound[0]+nFound[1], nFound[0], nFound[1], nBacked));
d4cf71ca 512
d611c74f 513 // run stand alone tracking
4d6aee34 514 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
41702fec 515
516 return 0;
0906e73e 517}
518
519
520//____________________________________________________________________
521Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
522{
41702fec 523 //
524 // Refits tracks within the TRD. The ESD event is expected to contain seeds
525 // at the outer part of the TRD.
526 // The tracks are propagated to the innermost time bin
527 // of the TRD and the ESD event is updated
528 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
529 //
530
531 Int_t nseed = 0; // contor for loaded seeds
532 Int_t found = 0; // contor for updated TRD tracks
533
534
e3d45279 535 if(!fClusters || !fClusters->GetEntriesFast()){
536 AliInfo("No TRD clusters");
537 return 0;
538 }
41702fec 539 AliTRDtrackV1 track;
540 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
541 AliESDtrack *seed = event->GetTrack(itrack);
050875b0 542 ULong_t status = seed->GetStatus();
ef6f0bda 543 // reject tracks which did not entered TRD from bellow (also produced by the TRD stand alone tracker)
544 if(!(status & AliESDtrack::kTRDin)) continue;
545 // reject TRD tracks with no clusters. This condition is softer than previously used
546 // !(status & AliESDtrack::kTRDout)
547 // since it allows also tracks stopped
548 if(!seed->GetTRDncls()) continue;
549 // check back-up quality
050875b0 550 new(&track) AliTRDtrackV1(*seed);
41702fec 551 if (track.GetX() < 270.0) {
552 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
553 continue;
554 }
ef6f0bda 555 nseed++;
41702fec 556
557 track.ResetCovariance(50.0);
558
559 // do the propagation and processing
560 Bool_t kUPDATE = kFALSE;
ef6f0bda 561 Double_t xToGo = 250.;//(status & AliESDtrack::kTPCout)?250.0:.1;
41702fec 562 if(FollowProlongation(track)){
e3cf3d02 563 // Update the friend track
2d73d21c 564 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
4d6aee34 565 TObject *o = NULL; Int_t ic = 0;
566 AliTRDtrackV1 *calibTrack = NULL;
e3cf3d02 567 while((o = seed->GetCalibObject(ic++))){
568 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
a310e49b 569 calibTrack->SetTrackOut(&track);
e3cf3d02 570 }
41702fec 571 }
a310e49b 572
573 // Prolongate to TPC
426bee9a 574 if (PropagateToX(track, xToGo, AliTRDReconstructor::GetMaxStep())) { // -with update
a310e49b 575 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
576 found++;
577 kUPDATE = kTRUE;
578 }
e3cf3d02 579 }
41702fec 580
581 // Prolongate to TPC without update
582 if(!kUPDATE) {
583 AliTRDtrackV1 tt(*seed);
426bee9a 584 if (PropagateToX(tt, xToGo, AliTRDReconstructor::GetMaxStep())) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
41702fec 585 }
586 }
980d5a2a 587 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
588 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
41702fec 589
590 return 0;
0906e73e 591}
592
0906e73e 593//____________________________________________________________________
594Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
595{
41702fec 596 // Extrapolates the TRD track in the TPC direction.
597 //
598 // Parameters
599 // t : the TRD track which has to be extrapolated
600 //
601 // Output
602 // number of clusters attached to the track
603 //
604 // Detailed description
605 //
606 // Starting from current radial position of track <t> this function
607 // extrapolates the track through the 6 TRD layers. The following steps
608 // are being performed for each plane:
609 // 1. prepare track:
610 // a. get plane limits in the local x direction
611 // b. check crossing sectors
612 // c. check track inclination
613 // 2. search tracklet in the tracker list (see GetTracklet() for details)
614 // 3. evaluate material budget using the geo manager
615 // 4. propagate and update track using the tracklet information.
616 //
617 // Debug level 2
618 //
619
620 Int_t nClustersExpected = 0;
e3cf3d02 621 for (Int_t iplane = kNPlanes; iplane--;) {
17896e82 622 Int_t index(-1);
41702fec 623 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
17896e82 624 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
41702fec 625 if(!tracklet) continue;
980d5a2a 626 if(!tracklet->IsOK()){
627 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
628 continue;
629 }
e3cf3d02 630 Double_t x = tracklet->GetX();//GetX0();
41702fec 631 // reject tracklets which are not considered for inward refit
4b5b4c5b 632 if(x > t.GetX()+AliTRDReconstructor::GetMaxStep()){
633 AliDebug(2, Form("Reject x[%7.3f] > track[%7.3f]", x, t.GetX()+AliTRDReconstructor::GetMaxStep()));
634 continue;
635 }
41702fec 636 // append tracklet to track
637 t.SetTracklet(tracklet, index);
638
952051c5 639 if (x < (t.GetX()-AliTRDReconstructor::GetMaxStep()) && !PropagateToX(t, x+AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) break;
41702fec 640 if (!AdjustSector(&t)) break;
641
642 // Start global position
643 Double_t xyz0[3];
644 t.GetXYZ(xyz0);
645
646 // End global position
647 Double_t alpha = t.GetAlpha(), y, z;
648 if (!t.GetProlongation(x,y,z)) break;
649 Double_t xyz1[3];
650 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
651 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
652 xyz1[2] = z;
653
51a23065 654 Double_t length = TMath::Sqrt(
655 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
656 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
657 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
658 );
659 if(length>0.){
660 // Get material budget
661 Double_t param[7];
662 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
663 Double_t xrho= param[0]*param[4];
664 Double_t xx0 = param[1]; // Get mean propagation parameters
665
666 // Propagate and update
667 t.PropagateTo(x, xx0, xrho);
668 if (!AdjustSector(&t)) break;
669 }
e3cf3d02 670
b72f4eaf 671 Double_t cov[3]; tracklet->GetCovAt(x, cov);
672 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
673 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
ef867f55 674 if (chi2 < 1e+10 && ((AliExternalTrackParam&)t).Update(p, cov)){
675 // Register info to track
676 t.SetNumberOfClusters();
677 t.UpdateChi2(chi2);
41702fec 678 nClustersExpected += tracklet->GetN();
679 }
680 }
681
9e85cb05 682 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
41702fec 683 Int_t index;
51a23065 684 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
41702fec 685 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
686 if(!tracklet) continue;
687 t.SetTracklet(tracklet, index);
688 }
689
a2fbb6ec 690 if(fkReconstructor->IsDebugStreaming()){
691 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
692 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
693 AliTRDtrackV1 track(t);
694 track.SetOwner();
695 cstreamer << "FollowProlongation"
696 << "EventNumber=" << eventNumber
697 << "ncl=" << nClustersExpected
698 << "track.=" << &track
699 << "\n";
700 }
41702fec 701 }
41702fec 702 return nClustersExpected;
0906e73e 703
704}
705
706//_____________________________________________________________________________
707Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
708{
afa21247 709// Extrapolates/Build the TRD track in the TOF direction.
710//
711// Parameters
712// t : the TRD track which has to be extrapolated
713//
714// Output
715// number of clusters attached to the track
716//
717// Starting from current radial position of track <t> this function
718// extrapolates the track through the 6 TRD layers. The following steps
719// are being performed for each plane:
720// 1. Propagate track to the entrance of the next chamber:
721// - get chamber limits in the radial direction
722// - check crossing sectors
723// - check track inclination
724// - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
725// 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
726// Kalman filter is needed and tracklets are already linked to the track this step is skipped.
727// 3. Fit tracklet using the information from the Kalman filter.
728// 4. Propagate and update track at reference radial position of the tracklet.
729// 5. Register tracklet with the tracker and track; update pulls monitoring.
730//
731// Observation
2a3191bb 732// 1. During the propagation a bit map is filled detailing the status of the track in each TRD chamber. The following errors are being registered for each tracklet:
733// - AliTRDtrackV1::kProlongation : track prolongation failed
734// - AliTRDtrackV1::kPropagation : track prolongation failed
735// - AliTRDtrackV1::kAdjustSector : failed during sector crossing
736// - AliTRDtrackV1::kSnp : too large bending
737// - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
738// - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
739// - AliTRDtrackV1::kUnknown : anything which is not covered before
afa21247 740// 2. By default the status of the track before first TRD update is saved.
741//
742// Debug level 2
743//
744// Author
745// Alexandru Bercuci <A.Bercuci@gsi.de>
746//
41702fec 747
eb2b4f91 748 Int_t n = 0;
749 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
4d6aee34 750 AliTRDtrackingChamber *chamber = NULL;
41702fec 751
9e85cb05 752 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
7c3eecb8 753 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
754
36574ea4 755 Bool_t kStoreIn(kTRUE), // toggel store track params. at TRD entry
68f9b6bd 756 kStandAlone(kFALSE), // toggle tracker awarness of stand alone seeding
757 kUseTRD(fkRecoParam->IsOverPtThreshold(t.Pt()));// use TRD measurment to update Kalman
758
759 Int_t startLayer(0);
4d6aee34 760 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
68f9b6bd 761 // Special case for stand alone tracking
762 // - store all tracklets found by seeding
763 // - start propagation from first tracklet found
181d2c97 764 AliTRDseedV1 *tracklets[kNPlanes];
765 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
68f9b6bd 766 for(Int_t ip(kNPlanes); ip--;){
767 if(!(tracklets[ip] = t.GetTracklet(ip))) continue;
181d2c97 768 t.UnsetTracklet(ip);
68f9b6bd 769 if(tracklets[ip]->IsOK()) startLayer=ip;
770 kStandAlone = kTRUE;
0b559d95 771 kUseTRD = kTRUE;
181d2c97 772 }
68f9b6bd 773 AliDebug(4, Form("SA[%c] Start[%d]\n"
774 " [0]idx[%d] traklet[%p]\n"
775 " [1]idx[%d] traklet[%p]\n"
776 " [2]idx[%d] traklet[%p]\n"
777 " [3]idx[%d] traklet[%p]\n"
778 " [4]idx[%d] traklet[%p]\n"
779 " [5]idx[%d] traklet[%p]"
780 , kStandAlone?'y':'n', startLayer
781 , t.GetTrackletIndex(0), (void*)tracklets[0]
782 , t.GetTrackletIndex(1), (void*)tracklets[1]
783 , t.GetTrackletIndex(2), (void*)tracklets[2]
784 , t.GetTrackletIndex(3), (void*)tracklets[3]
785 , t.GetTrackletIndex(4), (void*)tracklets[4]
786 , t.GetTrackletIndex(5), (void*)tracklets[5]));
e3cf3d02 787
053767a4 788 // Loop through the TRD layers
4d6aee34 789 TGeoHMatrix *matrix = NULL;
3e860707 790 Double_t x(0.), y(0.), z(0.);
68f9b6bd 791 for (Int_t ily=startLayer, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
1bd708e3 792 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
793
eb2b4f91 794 // rough estimate of the entry point
795 if (!t.GetProlongation(fR[ily], y, z)){
4b5b4c5b 796 n= n?-n:-999;
34b5e42d 797 t.SetErrStat(AliTRDtrackV1::kProlongation);
1bd708e3 798 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
eb2b4f91 799 break;
800 }
41702fec 801
eb2b4f91 802 // find sector / stack / detector
803 sm = t.GetSector();
804 // TODO cross check with y value !
805 stk = fGeom->GetStack(z, ily);
806 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
4d6aee34 807 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
eb2b4f91 808
809 // check if supermodule/chamber is installed
810 if( !fGeom->GetSMstatus(sm) ||
811 stk<0. ||
812 fGeom->IsHole(ily, stk, sm) ||
813 !matrix ){
1bd708e3 814 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
eb2b4f91 815 // propagate to the default radial position
952051c5 816 if(fR[ily] > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, fR[ily], AliTRDReconstructor::GetMaxStep())){
4b5b4c5b 817 n= n?-n:-999;
34b5e42d 818 t.SetErrStat(AliTRDtrackV1::kPropagation);
1bd708e3 819 AliDebug(4, "Failed Propagation [Missing Geometry]");
41702fec 820 break;
821 }
eb2b4f91 822 if(!AdjustSector(&t)){
4b5b4c5b 823 n= n?-n:-999;
34b5e42d 824 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 825 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
eb2b4f91 826 break;
827 }
952051c5 828 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
4b5b4c5b 829 n= n?-n:-999;
34b5e42d 830 t.SetErrStat(AliTRDtrackV1::kSnp);
1bd708e3 831 AliDebug(4, "Failed Max Snp [Missing Geometry]");
eb2b4f91 832 break;
833 }
34b5e42d 834 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
41702fec 835 continue;
836 }
e3cf3d02 837
eb2b4f91 838 // retrieve rotation matrix for the current chamber
839 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
840 Double_t glb[] = {0., 0., 0.};
841 matrix->LocalToMaster(loc, glb);
4b5b4c5b 842 AliDebug(3, Form("Propagate to D%3d[%02d_%d_%d] x_anode[%7.2f] (%f %f)", det, sm, stk, ily, glb[0]+driftLength, glb[1], glb[2]));
eb2b4f91 843
844 // Propagate to the radial distance of the current layer
952051c5 845 x = glb[0] - AliTRDReconstructor::GetMaxStep();
846 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())){
4b5b4c5b 847 n= n?-n:-999;
34b5e42d 848 t.SetErrStat(AliTRDtrackV1::kPropagation);
4b5b4c5b 849 AliDebug(4, Form("Failed Propagation to x[%7.2f]", x));
eb2b4f91 850 break;
851 }
852 if(!AdjustSector(&t)){
4b5b4c5b 853 n= n?-n:-999;
34b5e42d 854 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 855 AliDebug(4, "Failed Adjust Sector Start");
eb2b4f91 856 break;
857 }
952051c5 858 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
4b5b4c5b 859 n= n?-n:-999;
34b5e42d 860 t.SetErrStat(AliTRDtrackV1::kSnp);
952051c5 861 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
eb2b4f91 862 break;
863 }
4d6aee34 864 Bool_t doRecalculate = kFALSE;
eb2b4f91 865 if(sm != t.GetSector()){
4b5b4c5b 866 AliDebug(3, Form("Track crossed sectors %2d -> %2d", sm, t.GetSector()));
eb2b4f91 867 sm = t.GetSector();
4d6aee34 868 doRecalculate = kTRUE;
eb2b4f91 869 }
870 if(stk != fGeom->GetStack(z, ily)){
4b5b4c5b 871 AliDebug(3, Form("Track crossed stacks %d -> %d in sec[%02d]", stk, fGeom->GetStack(z, ily), sm));
eb2b4f91 872 stk = fGeom->GetStack(z, ily);
4d6aee34 873 doRecalculate = kTRUE;
eb2b4f91 874 }
4d6aee34 875 if(doRecalculate){
eb2b4f91 876 det = AliTRDgeometry::GetDetector(ily, stk, sm);
877 if(!(matrix = fGeom->GetClusterMatrix(det))){
34b5e42d 878 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
1bd708e3 879 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
eb2b4f91 880 continue;
881 }
882 matrix->LocalToMaster(loc, glb);
952051c5 883 x = glb[0] - AliTRDReconstructor::GetMaxStep();
eb2b4f91 884 }
885
886 // check if track is well inside fiducial volume
952051c5 887 if (!t.GetProlongation(x+AliTRDReconstructor::GetMaxStep(), y, z)) {
4b5b4c5b 888 n= n?-n:-999;
34b5e42d 889 t.SetErrStat(AliTRDtrackV1::kProlongation);
952051c5 890 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+AliTRDReconstructor::GetMaxStep(), y, z));
eb2b4f91 891 break;
892 }
893 if(fGeom->IsOnBoundary(det, y, z, .5)){
34b5e42d 894 t.SetErrStat(AliTRDtrackV1::kBoundary, ily);
1bd708e3 895 AliDebug(4, "Failed Track on Boundary");
eb2b4f91 896 continue;
897 }
4b5b4c5b 898 // mark track as entering the FIDUCIAL volume of TRD
899 if(kStoreIn){
900 t.SetTrackIn();
901 kStoreIn = kFALSE;
902 }
b1957d3c 903
eb2b4f91 904 ptrTracklet = tracklets[ily];
905 if(!ptrTracklet){ // BUILD TRACKLET
1bd708e3 906 AliDebug(3, Form("Building tracklet det[%d]", det));
eb2b4f91 907 // check data in supermodule
908 if(!fTrSec[sm].GetNChambers()){
34b5e42d 909 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
4b5b4c5b 910 AliDebug(4, Form("Failed NoClusters in sec[%02d]", sm));
eb2b4f91 911 continue;
912 }
913 if(fTrSec[sm].GetX(ily) < 1.){
34b5e42d 914 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
4b5b4c5b 915 AliDebug(4, Form("Failed NoX in sec[%02d]", sm));
eb2b4f91 916 continue;
917 }
918
919 // check data in chamber
920 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
34b5e42d 921 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
4b5b4c5b 922 AliDebug(4, Form("Failed No Data for D%03d[%02d_%d_%d]", AliTRDgeometry::GetDetector(ily, stk, sm), sm, stk, ily));
eb2b4f91 923 continue;
924 }
9e85cb05 925 if(chamber->GetNClusters() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
34b5e42d 926 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
4b5b4c5b 927 AliDebug(4, Form("Failed Not Enough Clusters[%2d] for D%03d[%02d_%d_%d]", chamber->GetNClusters(), AliTRDgeometry::GetDetector(ily, stk, sm), sm, stk, ily));
eb2b4f91 928 continue;
929 }
930 // build tracklet
4d8f1bd9 931 tracklet.~AliTRDseedV1();
eb2b4f91 932 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
4d6aee34 933 ptrTracklet->SetReconstructor(fkReconstructor);
eb2b4f91 934 ptrTracklet->SetKink(t.IsKink());
2eb10c34 935 ptrTracklet->SetPrimary(t.IsPrimary());
eb2b4f91 936 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
937 ptrTracklet->SetX0(glb[0]+driftLength);
4d8f1bd9 938 if(!ptrTracklet->Init(&t)){
4b5b4c5b 939 n= n?-n:-999;
34b5e42d 940 t.SetErrStat(AliTRDtrackV1::kTrackletInit);
1bd708e3 941 AliDebug(4, "Failed Tracklet Init");
eb2b4f91 942 break;
943 }
803dc399 944 // Select attachment base on track to B field sign not only track charge which is buggy
945 // mark kFALSE same sign tracks and kTRUE opposite sign tracks
946 // A.Bercuci 3.11.2011
947 Float_t prod(t.GetBz()*t.Charge());
948 if(!ptrTracklet->AttachClusters(chamber, kTRUE, prod<0.?kTRUE:kFALSE, fEventInFile)){
34b5e42d 949 t.SetErrStat(AliTRDtrackV1::kNoAttach, ily);
7c3eecb8 950 if(debugLevel>3){
951 AliTRDseedV1 trackletCp(*ptrTracklet);
952 UChar_t status(t.GetStatusTRD(ily));
9dcc64cc 953 (*cstreamer) << "FollowBackProlongation4"
7c3eecb8 954 <<"status=" << status
955 <<"tracklet.=" << &trackletCp
956 << "\n";
957 }
1bd708e3 958 AliDebug(4, "Failed Attach Clusters");
eb2b4f91 959 continue;
960 }
4b5b4c5b 961 Int_t nClTracklet(ptrTracklet->GetN());
962 AliDebug(3, Form("Number of Clusters in Tracklet: %2d", nClTracklet));
963 if(nClTracklet < Int_t(fgNTimeBins*fkRecoParam->GetFindableClusters())){
34b5e42d 964 t.SetErrStat(AliTRDtrackV1::kNoClustersTracklet, ily);
7c3eecb8 965 if(debugLevel>3){
966 AliTRDseedV1 trackletCp(*ptrTracklet);
967 UChar_t status(t.GetStatusTRD(ily));
9dcc64cc 968 (*cstreamer) << "FollowBackProlongation4"
7c3eecb8 969 <<"status=" << status
970 <<"tracklet.=" << &trackletCp
971 << "\n";
972 }
4b5b4c5b 973 AliDebug(4, Form("Attached clusters %2d<%2d (%4.1f%% of TB[%2d])", nClTracklet, Int_t(fgNTimeBins*fkRecoParam->GetFindableClusters()), 1.e2*fkRecoParam->GetFindableClusters(), fgNTimeBins));
eb2b4f91 974 continue;
975 }
976 ptrTracklet->UpdateUsed();
4b5b4c5b 977 // protect against reattaching clusters
978 if(Float_t(ptrTracklet->GetNUsed())/nClTracklet > .5/*fkRecoParam->GetUsedClustersLimit()*/){
979 t.SetErrStat(AliTRDtrackV1::kNoClustersTracklet, ily);
980 AliDebug(4, Form("Used clusters %2d[%4.1f%%] exceed limit [%4.1f%%]", nClTracklet, Float_t(ptrTracklet->GetNUsed())/nClTracklet, 1.e2*.5/*fkRecoParam->GetUsedClustersLimit()*/));
981 continue;
982 }
0217fcd0 983 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
eb2b4f91 984 // propagate track to the radial position of the tracklet
68f9b6bd 985
2eb10c34 986 // fit tracklet
987 // tilt correction options
988 // 0 : no correction
989 // 2 : pseudo tilt correction
9dcc64cc 990 if(!ptrTracklet->FitRobust(t.Charge()>0?kTRUE:kFALSE)){
34b5e42d 991 t.SetErrStat(AliTRDtrackV1::kNoFit, ily);
1bd708e3 992 AliDebug(4, "Failed Tracklet Fit");
eb2b4f91 993 continue;
994 }
995 x = ptrTracklet->GetX(); //GetX0();
952051c5 996 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())) {
4b5b4c5b 997 n= n?-n:-999;
34b5e42d 998 t.SetErrStat(AliTRDtrackV1::kPropagation);
1bd708e3 999 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
eb2b4f91 1000 break;
1001 }
1002 if(!AdjustSector(&t)) {
4b5b4c5b 1003 n= n?-n:-999;
34b5e42d 1004 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 1005 AliDebug(4, "Failed Adjust Sector");
eb2b4f91 1006 break;
41702fec 1007 }
952051c5 1008 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
4b5b4c5b 1009 n= n?-n:-999;
34b5e42d 1010 t.SetErrStat(AliTRDtrackV1::kSnp);
952051c5 1011 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
eb2b4f91 1012 break;
1013 }
4b5b4c5b 1014 // update parameters of track in.
1015 if(!ily) t.SetTrackIn();
b72f4eaf 1016 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1017 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1018 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
6e39bde4 1019 // update Kalman with the TRD measurement
b72f4eaf 1020 if(chi2>1e+10){ // TODO
34b5e42d 1021 t.SetErrStat(AliTRDtrackV1::kChi2, ily);
7c3eecb8 1022 if(debugLevel > 2){
1023 UChar_t status(t.GetStatusTRD());
1024 AliTRDseedV1 trackletCp(*ptrTracklet);
1025 AliTRDtrackV1 trackCp(t);
1026 trackCp.SetOwner();
9dcc64cc 1027 (*cstreamer) << "FollowBackProlongation3"
7c3eecb8 1028 << "status=" << status
1029 << "tracklet.=" << &trackletCp
1030 << "track.=" << &trackCp
1031 << "\n";
1032 }
1bd708e3 1033 AliDebug(4, Form("Failed Chi2[%f]", chi2));
eb2b4f91 1034 continue;
1035 }
ef867f55 1036 if(kUseTRD){
1037 if(!((AliExternalTrackParam&)t).Update(p, cov)) {
4b5b4c5b 1038 n= n?-n:-999;
34b5e42d 1039 t.SetErrStat(AliTRDtrackV1::kUpdate);
ef867f55 1040 if(debugLevel > 2){
1041 UChar_t status(t.GetStatusTRD());
1042 AliTRDseedV1 trackletCp(*ptrTracklet);
1043 AliTRDtrackV1 trackCp(t);
1044 trackCp.SetOwner();
9dcc64cc 1045 (*cstreamer) << "FollowBackProlongation3"
ef867f55 1046 << "status=" << status
1047 << "tracklet.=" << &trackletCp
1048 << "track.=" << &trackCp
1049 << "\n";
1050 }
1051 AliDebug(4, Form("Failed Track Update @ y[%7.2f] z[%7.2f] s2y[%f] s2z[%f] covyz[%f]", p[0], p[1], cov[0], cov[2], cov[1]));
1052 break;
7c3eecb8 1053 }
eb2b4f91 1054 }
68f9b6bd 1055 if(!kStandAlone) ptrTracklet->UseClusters();
b72f4eaf 1056 // fill residuals ?!
1057 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
1058
eb2b4f91 1059
4d8f1bd9 1060 // register tracklet with the tracker and track
803dc399 1061 // Save inside the tracklet the track parameters BEFORE track update.
1062 // Commented out their overwriting AFTER track update
1063 // A.Bercuci 3.11.2011
1064 //ptrTracklet->Update(&t);
eb2b4f91 1065 ptrTracklet = SetTracklet(ptrTracklet);
17896e82 1066 Int_t index(fTracklets->GetEntriesFast()-1);
1067 t.SetTracklet(ptrTracklet, index);
ef867f55 1068 // Register info to track
1069 t.SetNumberOfClusters();
1070 t.UpdateChi2(chi2);
1071
eb2b4f91 1072 n += ptrTracklet->GetN();
17896e82 1073 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
eb2b4f91 1074
41702fec 1075 // Reset material budget if 2 consecutive gold
eb2b4f91 1076// if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
41702fec 1077
1078 // Make backup of the track until is gold
b453ef55 1079 Int_t failed(0);
68f9b6bd 1080 if(!kStandAlone && (failed = t.MakeBackupTrack())) AliDebug(2, Form("Failed backup on cut[%d]", failed));
9e85cb05 1081
053767a4 1082 } // end layers loop
eb2b4f91 1083 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
1084 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
41702fec 1085
9dcc64cc 1086 if(n && debugLevel > 1){
1087 //Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
eb2b4f91 1088 AliTRDtrackV1 track(t);
1089 track.SetOwner();
9dcc64cc 1090 (*cstreamer) << "FollowBackProlongation2"
1091 << "EventNumber=" << fEventInFile
eb2b4f91 1092 << "track.=" << &track
41702fec 1093 << "\n";
1094 }
1095
eb2b4f91 1096 return n;
0906e73e 1097}
1098
eb38ed55 1099//_________________________________________________________________________
4d6aee34 1100Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
41702fec 1101 //
1102 // Fits a Riemann-circle to the given points without tilting pad correction.
1103 // The fit is performed using an instance of the class AliRieman (equations
1104 // and transformations see documentation of this class)
1105 // Afterwards all the tracklets are Updated
1106 //
1107 // Parameters: - Array of tracklets (AliTRDseedV1)
1108 // - Storage for the chi2 values (beginning with direction z)
1109 // - Seeding configuration
1110 // Output: - The curvature
1111 //
1112 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1113 fitter->Reset();
1114 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1115 Int_t *ppl = &allplanes[0];
1116 Int_t maxLayers = 6;
1117 if(planes){
1118 maxLayers = 4;
1119 ppl = planes;
1120 }
1121 for(Int_t il = 0; il < maxLayers; il++){
1122 if(!tracklets[ppl[il]].IsOK()) continue;
e3cf3d02 1123 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
41702fec 1124 }
1125 fitter->Update();
1126 // Set the reference position of the fit and calculate the chi2 values
1127 memset(chi2, 0, sizeof(Double_t) * 2);
1128 for(Int_t il = 0; il < maxLayers; il++){
1129 // Reference positions
1130 tracklets[ppl[il]].Init(fitter);
1131
1132 // chi2
1133 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1134 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1135 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1136 }
1137 return fitter->GetC();
eb38ed55 1138}
1139
1140//_________________________________________________________________________
1141void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1142{
41702fec 1143 //
1144 // Performs a Riemann helix fit using the seedclusters as spacepoints
1145 // Afterwards the chi2 values are calculated and the seeds are updated
1146 //
1147 // Parameters: - The four seedclusters
1148 // - The tracklet array (AliTRDseedV1)
1149 // - The seeding configuration
1150 // - Chi2 array
1151 //
1152 // debug level 2
1153 //
1154 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1155 fitter->Reset();
a3743898 1156 for(Int_t i = 0; i < 4; i++){
a3743898 1157 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1158 }
41702fec 1159 fitter->Update();
1160
1161
1162 // Update the seed and calculated the chi2 value
1163 chi2[0] = 0; chi2[1] = 0;
1164 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1165 // chi2
1166 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1167 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1168 }
eb38ed55 1169}
1170
1171
1172//_________________________________________________________________________
1173Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1174{
41702fec 1175 //
1176 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1177 // assumed that the vertex position is set to 0.
1178 // This method is very usefull for high-pt particles
1179 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1180 // x0, y0: Center of the circle
1181 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1182 // zc: center of the pad row
1183 // Equation which has to be fitted (after transformation):
1184 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1185 // Transformation:
1186 // t = 1/(x^2 + y^2)
1187 // u = 2 * x * t
1188 // v = 2 * x * tan(phiT) * t
1189 // Parameters in the equation:
1190 // a = -1/y0, b = x0/y0, e = dz/dx
1191 //
1192 // The Curvature is calculated by the following equation:
1193 // - curv = a/Sqrt(b^2 + 1) = 1/R
1194 // Parameters: - the 6 tracklets
1195 // - the Vertex constraint
1196 // Output: - the Chi2 value of the track
1197 //
1198 // debug level 5
1199 //
1200
1201 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1202 fitter->StoreData(kTRUE);
1203 fitter->ClearPoints();
4d6aee34 1204 AliTRDcluster *cl = NULL;
41702fec 1205
1206 Float_t x, y, z, w, t, error, tilt;
1207 Double_t uvt[2];
1208 Int_t nPoints = 0;
053767a4 1209 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1210 if(!tracklets[ilr].IsOK()) continue;
8d2bec9e 1211 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
053767a4 1212 if(!tracklets[ilr].IsUsable(itb)) continue;
e7542a7e 1213 if(!(cl = tracklets[ilr].GetClusters(itb))) continue;
1742f24c 1214 if(!cl->IsInChamber()) continue;
41702fec 1215 x = cl->GetX();
1216 y = cl->GetY();
1217 z = cl->GetZ();
053767a4 1218 tilt = tracklets[ilr].GetTilt();
41702fec 1219 // Transformation
1220 t = 1./(x * x + y * y);
1221 uvt[0] = 2. * x * t;
1222 uvt[1] = 2. * x * t * tilt ;
1223 w = 2. * (y + tilt * (z - zVertex)) * t;
78b7d24c 1224 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
41702fec 1225 fitter->AddPoint(uvt, w, error);
1226 nPoints++;
1227 }
1228 }
e17f4785 1229 fitter->Eval();
41702fec 1230
1231 // Calculate curvature
1232 Double_t a = fitter->GetParameter(0);
1233 Double_t b = fitter->GetParameter(1);
1234 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1235
ce42378b 1236 Float_t chi2track = 0.0;
1237 if (nPoints > 0) {
1238 chi2track = fitter->GetChisquare()/Double_t(nPoints);
1239 }
41702fec 1240 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
68f9b6bd 1241 tracklets[ip].SetC(curvature, 1);
1242
1243 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRiemanConstraint: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
41702fec 1244
a2fbb6ec 1245/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
41702fec 1246 //Linear Model on z-direction
1247 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1248 Double_t slope = fitter->GetParameter(2);
1249 Double_t zref = slope * xref;
1250 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1251 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1252 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
4d6aee34 1253 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
41702fec 1254 treeStreamer << "FitTiltedRiemanConstraint"
1255 << "EventNumber=" << eventNumber
1256 << "CandidateNumber=" << candidateNumber
1257 << "Curvature=" << curvature
1258 << "Chi2Track=" << chi2track
1259 << "Chi2Z=" << chi2Z
1260 << "zref=" << zref
1261 << "\n";
3a039a31 1262 }*/
41702fec 1263 return chi2track;
eb38ed55 1264}
1265
1266//_________________________________________________________________________
1267Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1268{
41702fec 1269 //
1270 // Performs a Riemann fit taking tilting pad correction into account
1271 // The equation of a Riemann circle, where the y position is substituted by the
1272 // measured y-position taking pad tilting into account, has to be transformed
1273 // into a 4-dimensional hyperplane equation
1274 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1275 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1276 // zc: center of the pad row
1277 // zt: z-position of the track
1278 // The z-position of the track is assumed to be linear dependent on the x-position
1279 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1280 // Transformation: u = 2 * x * t
1281 // v = 2 * tan(phiT) * t
1282 // w = 2 * tan(phiT) * (x - xref) * t
1283 // t = 1 / (x^2 + ymeas^2)
1284 // Parameters: a = -1/y0
1285 // b = x0/y0
1286 // c = (R^2 -x0^2 - y0^2)/y0
1287 // d = offset
1288 // e = dz/dx
1289 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1290 // results from the simple riemann fit. Afterwards the fit is redone.
1291 // The curvature is calculated according to the formula:
1292 // curv = a/(1 + b^2 + c*a) = 1/R
1293 //
1294 // Paramters: - Array of tracklets (connected to the track candidate)
1295 // - Flag selecting the error definition
1296 // Output: - Chi2 values of the track (in Parameter list)
1297 //
1298 TLinearFitter *fitter = GetTiltedRiemanFitter();
1299 fitter->StoreData(kTRUE);
1300 fitter->ClearPoints();
1301 AliTRDLeastSquare zfitter;
4d6aee34 1302 AliTRDcluster *cl = NULL;
41702fec 1303
1304 Double_t xref = CalculateReferenceX(tracklets);
6e39bde4 1305 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1306 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1307 memset(sumPolY, 0, sizeof(Double_t) * 5);
1308 memset(sumPolZ, 0, sizeof(Double_t) * 3);
41702fec 1309 Int_t nPoints = 0;
1310 // Containers for Least-square fitter
1311 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1312 if(!tracklets[ipl].IsOK()) continue;
ed15ef4f 1313 tilt = tracklets[ipl].GetTilt();
8d2bec9e 1314 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1315 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1742f24c 1316 if(!cl->IsInChamber()) continue;
c79857d5 1317 if (!tracklets[ipl].IsUsable(itb)) continue;
41702fec 1318 x = cl->GetX();
1319 y = cl->GetY();
1320 z = cl->GetZ();
41702fec 1321 dx = x - xref;
1322 // Transformation
1323 t = 1./(x*x + y*y);
1324 uvt[0] = 2. * x * t;
1325 uvt[1] = t;
1326 uvt[2] = 2. * tilt * t;
1327 uvt[3] = 2. * tilt * dx * t;
1328 w = 2. * (y + tilt*z) * t;
1329 // error definition changes for the different calls
1330 we = 2. * t;
78b7d24c 1331 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
41702fec 1332 fitter->AddPoint(uvt, w, we);
1333 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
6e39bde4 1334 // adding points for covariance matrix estimation
1335 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1336 erry *= erry;
1337 errz = 1./cl->GetSigmaZ2();
1338 for(Int_t ipol = 0; ipol < 5; ipol++){
1339 sumPolY[ipol] += erry;
1340 erry *= x;
1341 if(ipol < 3){
1342 sumPolZ[ipol] += errz;
1343 errz *= x;
1344 }
1345 }
41702fec 1346 nPoints++;
1347 }
1348 }
c08b1cc7 1349 if (fitter->Eval()) return 1.e10;
41702fec 1350 zfitter.Eval();
1351
1352 Double_t offset = fitter->GetParameter(3);
1353 Double_t slope = fitter->GetParameter(4);
1354
1355 // Linear fitter - not possible to make boundaries
1356 // Do not accept non possible z and dzdx combinations
1357 Bool_t acceptablez = kTRUE;
1358 Double_t zref = 0.0;
1359 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1360 if(!tracklets[iLayer].IsOK()) continue;
1361 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1362 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
41702fec 1363 acceptablez = kFALSE;
1364 }
1365 if (!acceptablez) {
1366 Double_t dzmf = zfitter.GetFunctionParameter(1);
1367 Double_t zmf = zfitter.GetFunctionValue(&xref);
1368 fgTiltedRieman->FixParameter(3, zmf);
1369 fgTiltedRieman->FixParameter(4, dzmf);
e17f4785 1370 fitter->Eval();
41702fec 1371 fitter->ReleaseParameter(3);
1372 fitter->ReleaseParameter(4);
1373 offset = fitter->GetParameter(3);
1374 slope = fitter->GetParameter(4);
1375 }
1376
1377 // Calculate Curvarture
1378 Double_t a = fitter->GetParameter(0);
1379 Double_t b = fitter->GetParameter(1);
1380 Double_t c = fitter->GetParameter(2);
1381 Double_t curvature = 1.0 + b*b - c*a;
68f9b6bd 1382 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
41702fec 1383
1384 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1385
6e39bde4 1386 // Prepare error calculation
1387 TMatrixD covarPolY(3,3);
1388 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1389 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1390 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1391 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1392 covarPolY.Invert();
1393 TMatrixD covarPolZ(2,2);
1394 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1395 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1396 covarPolZ.Invert();
1397
41702fec 1398 // Update the tracklets
6e39bde4 1399 Double_t x1, dy, dz;
1400 Double_t cov[15];
1401 memset(cov, 0, sizeof(Double_t) * 15);
41702fec 1402 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1403
1404 x = tracklets[iLayer].GetX0();
6e39bde4 1405 x1 = x - xref;
41702fec 1406 y = 0;
1407 z = 0;
1408 dy = 0;
1409 dz = 0;
6e39bde4 1410 memset(cov, 0, sizeof(Double_t) * 3);
1411 TMatrixD transform(3,3);
1412 transform(0,0) = 1;
1413 transform(0,1) = x;
1414 transform(0,2) = x*x;
1415 transform(1,1) = 1;
1416 transform(1,2) = x;
1417 transform(2,2) = 1;
1418 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1419 covariance *= transform.T();
1420 TMatrixD transformZ(2,2);
1421 transformZ(0,0) = transformZ(1,1) = 1;
1422 transformZ(0,1) = x;
1423 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1424 covarZ *= transformZ.T();
41702fec 1425 // y: R^2 = (x - x0)^2 + (y - y0)^2
1426 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1427 // R = Sqrt() = 1/Curvature
1428 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1429 Double_t res = (x * a + b); // = (x - x0)/y0
1430 res *= res;
1431 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1432 if (res >= 0) {
1433 res = TMath::Sqrt(res);
1434 y = (1.0 - res) / a;
1435 }
6e39bde4 1436 cov[0] = covariance(0,0);
1437 cov[2] = covarZ(0,0);
1438 cov[1] = 0.;
41702fec 1439
1440 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1441 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1442 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1443 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1444 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1445 Double_t x0 = -b / a;
1446 if (-c * a + b * b + 1 > 0) {
1447 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
6e39bde4 1448 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1449 if (a < 0) yderiv *= -1.0;
1450 dy = yderiv;
41702fec 1451 }
1452 }
1453 z = offset + slope * (x - xref);
1454 dz = slope;
1455 tracklets[iLayer].SetYref(0, y);
1456 tracklets[iLayer].SetYref(1, dy);
1457 tracklets[iLayer].SetZref(0, z);
1458 tracklets[iLayer].SetZref(1, dz);
1459 tracklets[iLayer].SetC(curvature);
6e39bde4 1460 tracklets[iLayer].SetCovRef(cov);
41702fec 1461 tracklets[iLayer].SetChi2(chi2track);
1462 }
68f9b6bd 1463 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRieman: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
41702fec 1464
a2fbb6ec 1465/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1466 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 1467 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1468 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1469 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1470 cstreamer << "FitTiltedRieman0"
1471 << "EventNumber=" << eventNumber
1472 << "CandidateNumber=" << candidateNumber
1473 << "xref=" << xref
1474 << "Chi2Z=" << chi2z
1475 << "\n";
3a039a31 1476 }*/
41702fec 1477 return chi2track;
eb38ed55 1478}
1479
3b57a3f7 1480
9e333711 1481//____________________________________________________________________
6e4d4425 1482Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
9e333711 1483{
4d6aee34 1484 //
1485 // Fit track with a staight line
1486 // Fills an AliTrackPoint array with np points
1487 // Function should be used to refit tracks when no magnetic field was on
1488 //
9e333711 1489 AliTRDLeastSquare yfitter, zfitter;
4d6aee34 1490 AliTRDcluster *cl = NULL;
9e333711 1491
4d6aee34 1492 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
9e333711 1493 if(!tracklets){
1494 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1495 if(!(tracklet = track->GetTracklet(ipl))) continue;
1496 if(!tracklet->IsOK()) continue;
1497 new(&work[ipl]) AliTRDseedV1(*tracklet);
1498 }
1499 tracklets = &work[0];
1500 }
1501
1502 Double_t xref = CalculateReferenceX(tracklets);
1503 Double_t x, y, z, dx, ye, yr, tilt;
1504 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1505 if(!tracklets[ipl].IsOK()) continue;
1506 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1507 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1508 if (!tracklets[ipl].IsUsable(itb)) continue;
1509 x = cl->GetX();
1510 z = cl->GetZ();
1511 dx = x - xref;
1512 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1513 }
1514 }
1515 zfitter.Eval();
1516 Double_t z0 = zfitter.GetFunctionParameter(0);
1517 Double_t dzdx = zfitter.GetFunctionParameter(1);
1518 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1519 if(!tracklets[ipl].IsOK()) continue;
1520 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1521 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1522 if (!tracklets[ipl].IsUsable(itb)) continue;
1523 x = cl->GetX();
1524 y = cl->GetY();
1525 z = cl->GetZ();
1526 tilt = tracklets[ipl].GetTilt();
1527 dx = x - xref;
1528 yr = y + tilt*(z - z0 - dzdx*dx);
1529 // error definition changes for the different calls
1530 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1531 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1532 yfitter.AddPoint(&dx, yr, ye);
1533 }
1534 }
1535 yfitter.Eval();
1536 Double_t y0 = yfitter.GetFunctionParameter(0);
1537 Double_t dydx = yfitter.GetFunctionParameter(1);
1538 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1539
1540 //update track points array
1541 if(np && points){
1542 Float_t xyz[3];
1543 for(int ip=0; ip<np; ip++){
1544 points[ip].GetXYZ(xyz);
1545 xyz[1] = y0 + dydx * (xyz[0] - xref);
1546 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1547 points[ip].SetXYZ(xyz);
1548 }
1549 }
1550 return chi2;
1551}
1552
1553
3b57a3f7 1554//_________________________________________________________________________
6e4d4425 1555Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
3b57a3f7 1556{
0fa1a8ee 1557//
1558// Performs a Riemann fit taking tilting pad correction into account
1559//
1560// Paramters: - Array of tracklets (connected to the track candidate)
1561// - Flag selecting the error definition
1562// Output: - Chi2 values of the track (in Parameter list)
1563//
1564// The equations which has to be solved simultaneously are:
1565// BEGIN_LATEX
1566// R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1567// y^{*} = y - tg(h)(z - z_{t})
1568// z_{t} = z_{0}+dzdx*(x-x_{r})
1569// END_LATEX
1570// with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1571// R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1572// track in the x-z plane. Using the following transformations
1573// BEGIN_LATEX
1574// t = 1 / (x^{2} + y^{2})
1575// u = 2 * x * t
1576// v = 2 * tan(h) * t
1577// w = 2 * tan(h) * (x - x_{r}) * t
1578// END_LATEX
1579// One gets the following linear equation
1580// BEGIN_LATEX
1581// a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1582// END_LATEX
1583// where the coefficients have the following meaning
1584// BEGIN_LATEX
1585// a = -1/y_{0}
1586// b = x_{0}/y_{0}
1587// c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1588// d = z_{0}
1589// e = dz/dx
1590// END_LATEX
1591// The error calculation for the free term is thus
1592// BEGIN_LATEX
1593// #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1594// END_LATEX
1595//
1596// From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1597// to the formula:
1598// BEGIN_LATEX
1599// C = 1/R = a/(1 + b^{2} + c*a)
1600// END_LATEX
1601//
1602// Authors
1603// M.Ivanov <M.Ivanov@gsi.de>
1604// A.Bercuci <A.Bercuci@gsi.de>
1605// M.Fasel <M.Fasel@gsi.de>
1606
41702fec 1607 TLinearFitter *fitter = GetTiltedRiemanFitter();
1608 fitter->StoreData(kTRUE);
1609 fitter->ClearPoints();
1610 AliTRDLeastSquare zfitter;
4d6aee34 1611 AliTRDcluster *cl = NULL;
3b57a3f7 1612
4d6aee34 1613 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
3b57a3f7 1614 if(!tracklets){
1615 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1616 if(!(tracklet = track->GetTracklet(ipl))) continue;
1617 if(!tracklet->IsOK()) continue;
1618 new(&work[ipl]) AliTRDseedV1(*tracklet);
1619 }
1620 tracklets = &work[0];
1621 }
1622
41702fec 1623 Double_t xref = CalculateReferenceX(tracklets);
68f9b6bd 1624 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:\nx0[(0)%6.2f (1)%6.2f (2)%6.2f (3)%6.2f (4)%6.2f (5)%6.2f] xref[%6.2f]", tracklets[0].GetX0(), tracklets[1].GetX0(), tracklets[2].GetX0(), tracklets[3].GetX0(), tracklets[4].GetX0(), tracklets[5].GetX0(), xref);
41702fec 1625 Double_t x, y, z, t, tilt, dx, w, we;
1626 Double_t uvt[4];
1627 Int_t nPoints = 0;
1628 // Containers for Least-square fitter
1629 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1630 if(!tracklets[ipl].IsOK()) continue;
8d2bec9e 1631 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1632 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
352cef8f 1633 //if (!tracklets[ipl].IsUsable(itb)) continue;
41702fec 1634 x = cl->GetX();
1635 y = cl->GetY();
1636 z = cl->GetZ();
1637 tilt = tracklets[ipl].GetTilt();
1638 dx = x - xref;
1639 // Transformation
1640 t = 1./(x*x + y*y);
1641 uvt[0] = 2. * x * t;
1642 uvt[1] = t;
1643 uvt[2] = 2. * tilt * t;
1644 uvt[3] = 2. * tilt * dx * t;
1645 w = 2. * (y + tilt*z) * t;
1646 // error definition changes for the different calls
1647 we = 2. * t;
f29f13a6 1648 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
41702fec 1649 fitter->AddPoint(uvt, w, we);
1650 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1651 nPoints++;
1652 }
1653 }
aec26713 1654 if(fitter->Eval()) return 1.E10;
1655
41702fec 1656 Double_t z0 = fitter->GetParameter(3);
1657 Double_t dzdx = fitter->GetParameter(4);
3b57a3f7 1658
1659
1660 // Linear fitter - not possible to make boundaries
1661 // Do not accept non possible z and dzdx combinations
1662 Bool_t accept = kTRUE;
1663 Double_t zref = 0.0;
1664 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1665 if(!tracklets[iLayer].IsOK()) continue;
1666 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1667 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
3b57a3f7 1668 accept = kFALSE;
1669 }
1670 if (!accept) {
41702fec 1671 zfitter.Eval();
3b57a3f7 1672 Double_t dzmf = zfitter.GetFunctionParameter(1);
1673 Double_t zmf = zfitter.GetFunctionValue(&xref);
1674 fitter->FixParameter(3, zmf);
1675 fitter->FixParameter(4, dzmf);
e17f4785 1676 fitter->Eval();
3b57a3f7 1677 fitter->ReleaseParameter(3);
1678 fitter->ReleaseParameter(4);
1679 z0 = fitter->GetParameter(3); // = zmf ?
1680 dzdx = fitter->GetParameter(4); // = dzmf ?
1681 }
1682
1683 // Calculate Curvature
1684 Double_t a = fitter->GetParameter(0);
1685 Double_t b = fitter->GetParameter(1);
1686 Double_t c = fitter->GetParameter(2);
1687 Double_t y0 = 1. / a;
1688 Double_t x0 = -b * y0;
a015e406 1689 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1690 if(tmp<=0.) return 1.E10;
4d6aee34 1691 Double_t radius = TMath::Sqrt(tmp);
1692 Double_t curvature = 1.0 + b*b - c*a;
1693 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
3b57a3f7 1694
1695 // Calculate chi2 of the fit
1696 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
68f9b6bd 1697 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:x0[%6.2f] y0[%6.2f] R[%6.2f] chi2[%f]\n", x0, y0, radius, chi2);
3b57a3f7 1698
1699 // Update the tracklets
1700 if(!track){
1701 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1702 x = tracklets[ip].GetX0();
4d6aee34 1703 tmp = radius*radius-(x-x0)*(x-x0);
a015e406 1704 if(tmp <= 0.) continue;
1705 tmp = TMath::Sqrt(tmp);
3b57a3f7 1706
1707 // y: R^2 = (x - x0)^2 + (y - y0)^2
1708 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1709 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1710 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1711 tracklets[ip].SetYref(1, (x - x0) / tmp);
1712 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1713 tracklets[ip].SetZref(1, dzdx);
4d6aee34 1714 tracklets[ip].SetC(curvature);
3b57a3f7 1715 tracklets[ip].SetChi2(chi2);
1716 }
1717 }
3b57a3f7 1718 //update track points array
1719 if(np && points){
1720 Float_t xyz[3];
1721 for(int ip=0; ip<np; ip++){
1722 points[ip].GetXYZ(xyz);
4d6aee34 1723 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
3b57a3f7 1724 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1725 points[ip].SetXYZ(xyz);
1726 }
1727 }
1728
3b57a3f7 1729 return chi2;
1730}
1731
1732
1bf51039 1733//____________________________________________________________________
e17f4785 1734Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1bf51039 1735{
1736// Kalman filter implementation for the TRD.
1737// It returns the positions of the fit in the array "points"
1738//
1739// Author : A.Bercuci@gsi.de
1740
3cfaffa4 1741 // printf("Start track @ x[%f]\n", track->GetX());
1bf51039 1742
1743 //prepare marker points along the track
1744 Int_t ip = np ? 0 : 1;
1745 while(ip<np){
1746 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1747 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1748 ip++;
1749 }
1750 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1751
1752
d8069611 1753 AliTRDseedV1 tracklet;
1754 AliTRDseedV1 *ptrTracklet = NULL;
1bf51039 1755
1756 //Loop through the TRD planes
1757 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1758 // GET TRACKLET OR BUILT IT
1759 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1760 if(tracklets){
e17f4785 1761 if(!(ptrTracklet = &tracklets[iplane])) continue;
1bf51039 1762 }else{
1763 if(!(ptrTracklet = track->GetTracklet(iplane))){
4d6aee34 1764 /*AliTRDtrackerV1 *tracker = NULL;
a2fbb6ec 1765 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1bf51039 1766 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1767 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1768 continue;
1769 }
1770 }
1771 if(!ptrTracklet->IsOK()) continue;
1772
1773 Double_t x = ptrTracklet->GetX0();
1774
1775 while(ip < np){
1776 //don't do anything if next marker is after next update point.
952051c5 1777 if((up?-1:1) * (points[ip].GetX() - x) - AliTRDReconstructor::GetMaxStep() < 0) break;
1778 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1779
1780 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1781 track->GetXYZ(xyz);
1782 track->Global2LocalPosition(xyz, track->GetAlpha());
1783 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1784 ip++;
1785 }
3cfaffa4 1786 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1bf51039 1787
3cfaffa4 1788 // Propagate closer to the next update point
952051c5 1789 if(((up?-1:1) * (x - track->GetX()) + AliTRDReconstructor::GetMaxStep() < 0) && !PropagateToX(*track, x + (up?-1:1)*AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1790
1791 if(!AdjustSector(track)) return -1;
952051c5 1792 if(TMath::Abs(track->GetSnp()) > AliTRDReconstructor::GetMaxSnp()) return -1;
1bf51039 1793
1794 //load tracklet to the tracker and the track
1795/* Int_t index;
1796 if((index = FindTracklet(ptrTracklet)) < 0){
1797 ptrTracklet = SetTracklet(&tracklet);
1798 index = fTracklets->GetEntriesFast()-1;
1799 }
1800 track->SetTracklet(ptrTracklet, index);*/
1801
1802
1803 // register tracklet to track with tracklet creation !!
1804 // PropagateBack : loaded tracklet to the tracker and update index
1805 // RefitInward : update index
1806 // MakeTrack : loaded tracklet to the tracker and update index
1807 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1808
1809
1810 //Calculate the mean material budget along the path inside the chamber
1811 Double_t xyz0[3]; track->GetXYZ(xyz0);
1812 Double_t alpha = track->GetAlpha();
1813 Double_t xyz1[3], y, z;
1814 if(!track->GetProlongation(x, y, z)) return -1;
1815 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1816 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1817 xyz1[2] = z;
fbe11be7 1818 if(TMath::Abs(xyz0[0] - xyz1[0]) < 1e-3 && TMath::Abs(xyz0[1] - xyz1[1]) < 1e-3) continue; // check wheter we are at the same global x position
1bf51039 1819 Double_t param[7];
3cfaffa4 1820 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1bf51039 1821 Double_t xrho = param[0]*param[4]; // density*length
1822 Double_t xx0 = param[1]; // radiation length
1823
1824 //Propagate the track
1825 track->PropagateTo(x, xx0, xrho);
1826 if (!AdjustSector(track)) break;
1827
1828 //Update track
b72f4eaf 1829 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1830 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1831 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
ef867f55 1832 if(chi2<1e+10) ((AliExternalTrackParam*)track)->Update(p, cov);
1bf51039 1833 if(!up) continue;
1834
1835 //Reset material budget if 2 consecutive gold
1836 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1837 } // end planes loop
1838
1839 // extrapolation
1840 while(ip < np){
952051c5 1841 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1842
1843 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1844 track->GetXYZ(xyz);
1845 track->Global2LocalPosition(xyz, track->GetAlpha());
1846 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1847 ip++;
1848 }
1849
1850 return track->GetChi2();
1851}
3b57a3f7 1852
eb38ed55 1853//_________________________________________________________________________
d8069611 1854Float_t AliTRDtrackerV1::CalculateChi2Z(const AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
eb38ed55 1855{
41702fec 1856 //
1857 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1858 // A linear dependence on the x-value serves as a model.
1859 // The parameters are related to the tilted Riemann fit.
1860 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1861 // - the offset for the reference x
1862 // - the slope
1863 // - the reference x position
1864 // Output: - The Chi2 value of the track in z-Direction
1865 //
1866 Float_t chi2Z = 0, nLayers = 0;
053767a4 1867 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
41702fec 1868 if(!tracklets[iLayer].IsOK()) continue;
1869 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1870 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
41702fec 1871 nLayers++;
1872 }
1873 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1874 return chi2Z;
eb38ed55 1875}
1876
bccda319 1877//_____________________________________________________________________________
1878Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1879{
41702fec 1880 //
1881 // Starting from current X-position of track <t> this function
1882 // extrapolates the track up to radial position <xToGo>.
1883 // Returns 1 if track reaches the plane, and 0 otherwise
1884 //
bccda319 1885
41702fec 1886 // Current track X-position
15a2657d 1887 Double_t xpos = t.GetX()/*,
1888 mass = t.GetMass()*/;
bccda319 1889
41702fec 1890 // Direction: inward or outward
1891 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
bccda319 1892
952051c5 1893 while (((xToGo - xpos) * dir) > AliTRDReconstructor::GetEpsilon()) {
2f4384e6 1894// printf("to go %f\n", (xToGo - xpos) * dir);
41702fec 1895 Double_t xyz0[3];
1896 Double_t xyz1[3];
1897 Double_t param[7];
1898 Double_t x;
1899 Double_t y;
1900 Double_t z;
bccda319 1901
41702fec 1902 // The next step size
1903 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
bccda319 1904
41702fec 1905 // Get the global position of the starting point
1906 t.GetXYZ(xyz0);
bccda319 1907
41702fec 1908 // X-position after next step
1909 x = xpos + step;
bccda319 1910
41702fec 1911 // Get local Y and Z at the X-position of the next step
3352b455 1912 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
bccda319 1913
41702fec 1914 // The global position of the end point of this prolongation step
1915 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1916 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1917 xyz1[2] = z;
bccda319 1918
41702fec 1919 // Calculate the mean material budget between start and
1920 // end point of this prolongation step
83dea92e 1921 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
2f4384e6 1922
41702fec 1923 // Propagate the track to the X-position after the next step
9c87a076 1924 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
bccda319 1925
15a2657d 1926/* // Correct for mean material budget
2f4384e6 1927 Double_t dEdx(0.),
1928 bg(t.GetP()/mass);
1929 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3){
1930 const char *pn[] = {"rho", "x/X0", "<A>", "<Z>", "L", "<Z/A>", "Nb"};
1931 printf("D-AliTRDtrackerV1::PropagateTo(): x[%6.2f] bg[%6.2f]\n", xpos, bg);
1932 printf(" param :: %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e]\n"
1933 , pn[0], param[0]
1934 , pn[1], param[1]
1935 , pn[2], param[2]
1936 , pn[3], param[3]
1937 , pn[4], param[4]
1938 , pn[5], param[5]
1939 , pn[6], param[6]);
1940 }
1941 switch(fgBB){
1942 case kSolid:
1943 dEdx = AliExternalTrackParam::BetheBlochSolid(bg);
1944 break;
1945 case kGas:
1946 dEdx = AliExternalTrackParam::BetheBlochGas(bg);
1947 break;
1948 case kGeant:
1949 { // mean exitation energy (GeV)
1950 Double_t mee = ((param[3] < 13.) ? (12. * param[3] + 7.) : (9.76 * param[3] + 58.8 * TMath::Power(param[3],-0.19))) * 1.e-9;
1951 Double_t mZA = param[5]>1.e-5?param[5]:(param[3]/param[2]);
1952 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3) printf("D-AliTRDtrackerV1::PropagateTo(): Mee[%e] <Z/A>[%e]\n", mee, mZA);
1953 // protect against failed calculation of rho in MeanMaterialBudget()
1954 dEdx = AliExternalTrackParam::BetheBlochGeant(bg, param[0]>1.e-6?param[0]:2.33, 0.2, 3., mee, mZA);
1955 }
1956 break;
1957 }
1958 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=2) printf("D-AliTRDtrackerV1::PropagateTo(): dEdx(bg=%e, m=%e)= %e[GeV/cm]\n", bg, mass, dEdx);
1959 if (!t.CorrectForMeanMaterialdEdx(param[1], dir*param[0]*param[4], mass, dEdx)) return 0;
15a2657d 1960*/
41702fec 1961 // Rotate the track if necessary
e7542a7e 1962 if(!AdjustSector(&t)) return 0;
bccda319 1963
41702fec 1964 // New track X-position
1965 xpos = t.GetX();
bccda319 1966
41702fec 1967 }
bccda319 1968
41702fec 1969 return 1;
bccda319 1970
1971}
1972
eb38ed55 1973//_____________________________________________________________________________
e7542a7e 1974Bool_t AliTRDtrackerV1::ReadClusters(TTree *clusterTree)
eb38ed55 1975{
41702fec 1976 //
1977 // Reads AliTRDclusters from the file.
1978 // The names of the cluster tree and branches
1979 // should match the ones used in AliTRDclusterizer::WriteClusters()
1980 //
1981
1982 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1983 TObjArray *clusterArray = new TObjArray(nsize+1000);
1984
1985 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1986 if (!branch) {
1987 AliError("Can't get the branch !");
e7542a7e 1988 return kFALSE;
41702fec 1989 }
1990 branch->SetAddress(&clusterArray);
1991
1992 if(!fClusters){
9e85cb05 1993 Float_t nclusters = fkRecoParam->GetNClusters();
4d6aee34 1994 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
e7542a7e 1995 fClusters = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1996 fClusters->SetOwner(kTRUE);
41702fec 1997 }
1998
1999 // Loop through all entries in the tree
2000 Int_t nEntries = (Int_t) clusterTree->GetEntries();
2001 Int_t nbytes = 0;
2002 Int_t ncl = 0;
4d6aee34 2003 AliTRDcluster *c = NULL;
41702fec 2004 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
2005 // Import the tree
2006 nbytes += clusterTree->GetEvent(iEntry);
2007
2008 // Get the number of points in the detector
2009 Int_t nCluster = clusterArray->GetEntriesFast();
2010 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
2011 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
41702fec 2012 new((*fClusters)[ncl++]) AliTRDcluster(*c);
2013 delete (clusterArray->RemoveAt(iCluster));
2014 }
41702fec 2015 }
2016 delete clusterArray;
2017
e7542a7e 2018 return kTRUE;
eb38ed55 2019}
2020
2021//_____________________________________________________________________________
2022Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
2023{
41702fec 2024 //
66f6bfd9 2025 // Fills clusters into TRD tracking sectors
41702fec 2026 //
41702fec 2027
9e85cb05 2028 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
2029
4d6aee34 2030 if(!fkReconstructor->IsWritingClusters()){
48f8adf3 2031 fClusters = AliTRDReconstructor::GetClusters();
2032 } else {
e7542a7e 2033 if(!ReadClusters(cTree)) {
66f6bfd9 2034 AliError("Problem with reading the clusters !");
2035 return 1;
2036 }
2037 }
2038 SetClustersOwner();
2039
48f8adf3 2040 if(!fClusters || !fClusters->GetEntriesFast()){
66f6bfd9 2041 AliInfo("No TRD clusters");
41702fec 2042 return 1;
2043 }
66f6bfd9 2044
2045 //Int_t nin =
2046 BuildTrackingContainers();
2047
2048 //Int_t ncl = fClusters->GetEntriesFast();
2049 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
2050
2051 return 0;
2052}
2053
2054//_____________________________________________________________________________
4d6aee34 2055Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
66f6bfd9 2056{
2057 //
2058 // Fills clusters into TRD tracking sectors
2059 // Function for use in the HLT
2060
2061 if(!clusters || !clusters->GetEntriesFast()){
2062 AliInfo("No TRD clusters");
41702fec 2063 return 1;
2064 }
2065
66f6bfd9 2066 fClusters = clusters;
2067 SetClustersOwner();
2068
9e85cb05 2069 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
66f6bfd9 2070 BuildTrackingContainers();
2071
2072 //Int_t ncl = fClusters->GetEntriesFast();
2073 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
2074
2075 return 0;
2076}
2077
2078
2079//____________________________________________________________________
2080Int_t AliTRDtrackerV1::BuildTrackingContainers()
2081{
2082// Building tracking containers for clusters
2083
c79857d5 2084 Int_t nin(0), ncl(fClusters->GetEntriesFast());
2085 while (ncl--) {
2086 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(ncl);
41702fec 2087 if(c->IsInChamber()) nin++;
4226b195 2088 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
41702fec 2089 Int_t detector = c->GetDetector();
2090 Int_t sector = fGeom->GetSector(detector);
053767a4 2091 Int_t stack = fGeom->GetStack(detector);
2092 Int_t layer = fGeom->GetLayer(detector);
41702fec 2093
0b559d95 2094 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, ncl);
41702fec 2095 }
b0a48c4d 2096
053767a4 2097 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
41702fec 2098 if(!fTrSec[isector].GetNChambers()) continue;
c79857d5 2099 fTrSec[isector].Init(fkReconstructor);
41702fec 2100 }
66f6bfd9 2101
2102 return nin;
eb38ed55 2103}
2104
2105
66f6bfd9 2106
0906e73e 2107//____________________________________________________________________
172b6f82 2108void AliTRDtrackerV1::UnloadClusters()
0906e73e 2109{
d4cf71ca 2110//
2111// Clears the arrays of clusters and tracks. Resets sectors and timebins
2112// If option "force" is also set the containers are also deleted. This is useful
2113// in case of HLT
2114
2115 if(fTracks){
2116 fTracks->Delete();
4d6aee34 2117 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
d4cf71ca 2118 }
2119 if(fTracklets){
2120 fTracklets->Delete();
4d6aee34 2121 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
d4cf71ca 2122 }
48f8adf3 2123 if(fClusters){
2124 if(IsClustersOwner()) fClusters->Delete();
2125
2126 // save clusters array in the reconstructor for further use.
4d6aee34 2127 if(!fkReconstructor->IsWritingClusters()){
48f8adf3 2128 AliTRDReconstructor::SetClusters(fClusters);
2129 SetClustersOwner(kFALSE);
4d6aee34 2130 } else AliTRDReconstructor::SetClusters(NULL);
48f8adf3 2131 }
0906e73e 2132
053767a4 2133 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
0906e73e 2134
41702fec 2135 // Increment the Event Number
2136 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
eb38ed55 2137}
0906e73e 2138
fac58f00 2139// //____________________________________________________________________
2140// void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2141// {
2142// const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2143// if(!track) return;
2144//
4d6aee34 2145// AliTRDseedV1 *tracklet = NULL;
fac58f00 2146// for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2147// if(!(tracklet = track->GetTracklet(ily))) continue;
4d6aee34 2148// AliTRDcluster *c = NULL;
8d2bec9e 2149// for(Int_t ic=AliTRDseed::kNclusters; ic--;){
fac58f00 2150// if(!(c=tracklet->GetClusters(ic))) continue;
2151// c->Use();
2152// }
2153// }
2154// }
2155//
b1957d3c 2156
eb38ed55 2157//_____________________________________________________________________________
4d6aee34 2158Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
eb38ed55 2159{
41702fec 2160 //
2161 // Rotates the track when necessary
2162 //
2163
2164 Double_t alpha = AliTRDgeometry::GetAlpha();
2165 Double_t y = track->GetY();
2166 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
3cfaffa4 2167
41702fec 2168 if (y > ymax) {
2169 if (!track->Rotate( alpha)) {
2170 return kFALSE;
2171 }
2172 }
2173 else if (y < -ymax) {
2174 if (!track->Rotate(-alpha)) {
2175 return kFALSE;
2176 }
2177 }
2178
2179 return kTRUE;
0906e73e 2180
2181}
2182
eb38ed55 2183
0906e73e 2184//____________________________________________________________________
33ab3872 2185AliTRDseedV1* AliTRDtrackerV1::GetTracklet(const AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
0906e73e 2186{
41702fec 2187 // Find tracklet for TRD track <track>
2188 // Parameters
2189 // - track
2190 // - sector
2191 // - plane
2192 // - index
2193 // Output
2194 // tracklet
2195 // index
2196 // Detailed description
2197 //
2198 idx = track->GetTrackletIndex(p);
17896e82 2199 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
41702fec 2200
2201 return tracklet;
0906e73e 2202}
2203
2204//____________________________________________________________________
4d6aee34 2205AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
0906e73e 2206{
41702fec 2207 // Add this tracklet to the list of tracklets stored in the tracker
2208 //
2209 // Parameters
2210 // - tracklet : pointer to the tracklet to be added to the list
2211 //
2212 // Output
2213 // - the index of the new tracklet in the tracker tracklets list
2214 //
2215 // Detailed description
2216 // Build the tracklets list if it is not yet created (late initialization)
2217 // and adds the new tracklet to the list.
2218 //
2219 if(!fTracklets){
053767a4 2220 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
41702fec 2221 fTracklets->SetOwner(kTRUE);
2222 }
2223 Int_t nentries = fTracklets->GetEntriesFast();
2224 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
972ef65e 2225}
2226
d20df6fc 2227//____________________________________________________________________
4d6aee34 2228AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
d20df6fc 2229{
2230 // Add this track to the list of tracks stored in the tracker
2231 //
2232 // Parameters
2233 // - track : pointer to the track to be added to the list
2234 //
2235 // Output
2236 // - the pointer added
2237 //
2238 // Detailed description
2239 // Build the tracks list if it is not yet created (late initialization)
2240 // and adds the new track to the list.
2241 //
2242 if(!fTracks){
053767a4 2243 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
d20df6fc 2244 fTracks->SetOwner(kTRUE);
2245 }
2246 Int_t nentries = fTracks->GetEntriesFast();
2247 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2248}
2249
2250
0906e73e 2251
e4f2f73d 2252//____________________________________________________________________
eb38ed55 2253Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
e4f2f73d 2254{
41702fec 2255 //
2256 // Steer tracking for one SM.
2257 //
2258 // Parameters :
2259 // sector : Array of (SM) propagation layers containing clusters
2260 // esd : The current ESD event. On output it contains the also
2261 // the ESD (TRD) tracks found in this SM.
2262 //
2263 // Output :
2264 // Number of tracks found in this TRD supermodule.
2265 //
2266 // Detailed description
2267 //
2268 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2269 // 2. Launch stack tracking.
2270 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2271 // 3. Pack results in the ESD event.
2272 //
2273
41702fec 2274 Int_t nTracks = 0;
2275 Int_t nChambers = 0;
4d6aee34 2276 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
053767a4 2277 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
41702fec 2278 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2279 nChambers = 0;
053767a4 2280 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2281 if(!(chamber = stack[ilayer])) continue;
9e85cb05 2282 if(chamber->GetNClusters() < fgNTimeBins * fkRecoParam->GetFindableClusters()) continue;
41702fec 2283 nChambers++;
053767a4 2284 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
41702fec 2285 }
2286 if(nChambers < 4) continue;
2287 //AliInfo(Form("Doing stack %d", istack));
b1135f96 2288 nTracks += Clusters2TracksStack(stack, fTracksESD);
41702fec 2289 }
050875b0 2290 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2291
352cef8f 2292 for(int itrack=0; itrack<nTracks; itrack++){
2293 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2294 Int_t id = esd->AddTrack(esdTrack);
2295
2296 // set ESD id to stand alone TRD tracks
9e85cb05 2297 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
352cef8f 2298 esdTrack=esd->GetTrack(id);
2299 TObject *o(NULL); Int_t ic(0);
2300 AliTRDtrackV1 *calibTrack(NULL);
2301 while((o = esdTrack->GetCalibObject(ic++))){
2302 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2303 calibTrack->SetESDid(esdTrack->GetID());
2304 break;
2305 }
2306 }
2307 }
41702fec 2308
2309 // Reset Track and Candidate Number
2310 AliTRDtrackerDebug::SetCandidateNumber(0);
2311 AliTRDtrackerDebug::SetTrackNumber(0);
b1135f96 2312
2313 // delete ESD tracks in the array
2314 fTracksESD->Delete();
41702fec 2315 return nTracks;
e4f2f73d 2316}
2317
2318//____________________________________________________________________
4d6aee34 2319Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
e4f2f73d 2320{
41702fec 2321 //
2322 // Make tracks in one TRD stack.
2323 //
2324 // Parameters :
2325 // layer : Array of stack propagation layers containing clusters
2326 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2327 // On exit the tracks found in this stack are appended.
2328 //
2329 // Output :
2330 // Number of tracks found in this stack.
2331 //
2332 // Detailed description
2333 //
2334 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2335 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2336 // See AliTRDtrackerV1::MakeSeeds() for more details.
2337 // 3. Arrange track candidates in decreasing order of their quality
2338 // 4. Classify tracks in 5 categories according to:
2339 // a) number of layers crossed
2340 // b) track quality
2341 // 5. Sign clusters by tracks in decreasing order of track quality
2342 // 6. Build AliTRDtrack out of seeding tracklets
2343 // 7. Cook MC label
2344 // 8. Build ESD track and register it to the output list
2345 //
2346
4d6aee34 2347 AliTRDtrackingChamber *chamber = NULL;
2348 AliTRDtrackingChamber **ci = NULL;
41702fec 2349 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2350 Int_t pars[4]; // MakeSeeds parameters
2351
2352 //Double_t alpha = AliTRDgeometry::GetAlpha();
2353 //Double_t shift = .5 * alpha;
2354 Int_t configs[kNConfigs];
2355
fac58f00 2356 // Purge used clusters from the containers
2357 ci = &stack[0];
2358 for(Int_t ic = kNPlanes; ic--; ci++){
2359 if(!(*ci)) continue;
2360 (*ci)->Update();
2361 }
2362
41702fec 2363 // Build initial seeding configurations
2364 Double_t quality = BuildSeedingConfigs(stack, configs);
9e85cb05 2365 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
41702fec 2366 AliInfo(Form("Plane config %d %d %d Quality %f"
2367 , configs[0], configs[1], configs[2], quality));
2368 }
d931f2aa 2369
41702fec 2370
2371 // Initialize contors
2372 Int_t ntracks, // number of TRD track candidates
2373 ntracks1, // number of registered TRD tracks/iter
2374 ntracks2 = 0; // number of all registered TRD tracks in stack
2375 fSieveSeeding = 0;
d931f2aa 2376
2377 // Get stack index
fac58f00 2378 Int_t ic = 0; ci = &stack[0];
2379 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2380 if(!(*ci)) return ntracks2;
2381 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
d931f2aa 2382
41702fec 2383 do{
2384 // Loop over seeding configurations
2385 ntracks = 0; ntracks1 = 0;
0b559d95 2386 for (Int_t iconf = 0; iconf<fkRecoParam->GetNumberOfSeedConfigs(); iconf++) {
41702fec 2387 pars[0] = configs[iconf];
2388 pars[1] = ntracks;
d931f2aa 2389 pars[2] = istack;
41702fec 2390 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
6e39bde4 2391 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
41702fec 2392 if(ntracks == kMaxTracksStack) break;
2393 }
980d5a2a 2394 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
41702fec 2395 if(!ntracks) break;
2396
2397 // Sort the seeds according to their quality
41f024fb 2398 Int_t sort[kMaxTracksStack+1];
41702fec 2399 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
68f9b6bd 2400 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 2){
2401 AliDebug(3, "Track candidates classification:");
2402 for (Int_t it(0); it < ntracks; it++) {
2403 Int_t jt(sort[it]);
2404 printf(" %2d idx[%d] Quality[%e]\n", it, jt, fTrackQuality[jt]);
2405 }
2406 }
41702fec 2407
2408 // Initialize number of tracks so far and logic switches
2409 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2410 Bool_t signedTrack[kMaxTracksStack];
2411 Bool_t fakeTrack[kMaxTracksStack];
2412 for (Int_t i=0; i<ntracks; i++){
2413 signedTrack[i] = kFALSE;
2414 fakeTrack[i] = kFALSE;
2415 }
2416 //AliInfo("Selecting track candidates ...");
2417
2418 // Sieve clusters in decreasing order of track quality
68f9b6bd 2419 Int_t jSieve(0), rejectedCandidates(0);
41702fec 2420 do{
41702fec 2421 // Check track candidates
68f9b6bd 2422 rejectedCandidates=0;
41702fec 2423 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
804bb02e 2424 Int_t trackIndex = sort[itrack];
2425 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
41702fec 2426
804bb02e 2427 // Calculate track parameters from tracklets seeds
804bb02e 2428 Int_t ncl = 0;
2429 Int_t nused = 0;
2430 Int_t nlayers = 0;
2431 Int_t findable = 0;
2432 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2433 Int_t jseed = kNPlanes*trackIndex+jLayer;
68f9b6bd 2434 sseed[jseed].UpdateUsed();
804bb02e 2435 if(!sseed[jseed].IsOK()) continue;
68f9b6bd 2436 // check if primary candidate
f29f13a6 2437 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
68f9b6bd 2438 ncl += sseed[jseed].GetN();
804bb02e 2439 nused += sseed[jseed].GetNUsed();
2440 nlayers++;
804bb02e 2441 }
2442
f29f13a6 2443 // Filter duplicated tracks
2444 if (nused > 30){
68f9b6bd 2445 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
f29f13a6 2446 fakeTrack[trackIndex] = kTRUE;
2447 continue;
2448 }
5ef88e00 2449 if (ncl>0 && Float_t(nused)/ncl >= .25){
68f9b6bd 2450 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d] used/ncl[%f]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused, Float_t(nused)/ncl));
f29f13a6 2451 fakeTrack[trackIndex] = kTRUE;
2452 continue;
2453 }
41702fec 2454
68f9b6bd 2455 AliDebug(4, Form("Candidate[%d] Quality[%e] Tracklets[%d] Findable[%d] Ncl[%d] Nused[%d]", trackIndex, fTrackQuality[trackIndex], nlayers, findable, ncl, nused));
2456
f29f13a6 2457 // Classify tracks
2458 Bool_t skip = kFALSE;
2459 switch(jSieve){
68f9b6bd 2460 case 0: // select 6 tracklets primary tracks, good quality
2461 if(nlayers > findable || nlayers < kNPlanes) {skip = kTRUE; break;}
f29f13a6 2462 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2463 break;
2464
68f9b6bd 2465 case 1: // select shorter primary tracks, good quality
e7542a7e 2466 //if(findable<4){skip = kTRUE; break;}
f29f13a6 2467 if(nlayers < findable){skip = kTRUE; break;}
2468 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2469 break;
2470
68f9b6bd 2471 case 2: // select 6 tracklets secondary tracks
2472 if(nlayers < kNPlanes) { skip = kTRUE; break;}
f29f13a6 2473 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2474 break;
2475
68f9b6bd 2476 case 3: // select shorter tracks, good quality
2477 if (nlayers<4){skip = kTRUE; break;}
f29f13a6 2478 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2479 break;
2480
68f9b6bd 2481 case 4: // select anything with at least 4 tracklets
2482 if (nlayers<4){skip = kTRUE; break;}
f29f13a6 2483 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2484 break;
2485 }
2486 if(skip){
68f9b6bd 2487 rejectedCandidates++;
5ef88e00 2488 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
f29f13a6 2489 continue;
5ef88e00 2490 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2491
f29f13a6 2492 signedTrack[trackIndex] = kTRUE;
2493
68f9b6bd 2494 AliTRDseedV1 *lseed =&sseed[trackIndex*kNPlanes];
2495 AliTRDtrackV1 *track = MakeTrack(lseed);
2496 if(!track){
2497 AliDebug(1, "Track building failed.");
2498 continue;
2499 } else {
2500 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 1){
2501 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2502 AliDebug(2, Form("Track pt=%7.2fGeV/c SM[%2d] Done.", track->Pt(), fGeom->GetSector(chamber->GetDetector())));
2503 }
2504 }
f29f13a6 2505
9e85cb05 2506 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
eb2b4f91 2507 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
f29f13a6 2508
f29f13a6 2509 AliTRDseedV1 *dseed[6];
b82b4de1 2510 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
f29f13a6 2511
2512 //Int_t eventNrInFile = esd->GetEventNumberInFile();
f29f13a6 2513 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2514 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2515 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
a2fbb6ec 2516 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
f29f13a6 2517 cstreamer << "Clusters2TracksStack"
68f9b6bd 2518 << "EventNumber=" << eventNumber
2519 << "TrackNumber=" << trackNumber
2520 << "CandidateNumber=" << candidateNumber
2521 << "Iter=" << fSieveSeeding
2522 << "Like=" << fTrackQuality[trackIndex]
2523 << "S0.=" << dseed[0]
2524 << "S1.=" << dseed[1]
2525 << "S2.=" << dseed[2]
2526 << "S3.=" << dseed[3]
2527 << "S4.=" << dseed[4]
2528 << "S5.=" << dseed[5]
2529 << "Ncl=" << ncl
2530 << "NLayers=" << nlayers
2531 << "Findable=" << findable
2532 << "NUsed=" << nused
f29f13a6 2533 << "\n";
2534 }
d877f55f 2535
68f9b6bd 2536
f29f13a6 2537 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2538 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2539 esdTrack->SetLabel(track->GetLabel());
2540 track->UpdateESDtrack(esdTrack);
2541 // write ESD-friends if neccessary
9e85cb05 2542 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
f29f13a6 2543 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2544 calibTrack->SetOwner();
2545 esdTrack->AddCalibObject(calibTrack);
2546 }
2547 ntracks1++;
2548 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
41702fec 2549 }
2550
2551 jSieve++;
68f9b6bd 2552 } while(jSieve<5 && rejectedCandidates); // end track candidates sieve
41702fec 2553 if(!ntracks1) break;
2554
2555 // increment counters
2556 ntracks2 += ntracks1;
4302c900 2557
4d6aee34 2558 if(fkReconstructor->IsHLT()) break;
41702fec 2559 fSieveSeeding++;
2560
2561 // Rebuild plane configurations and indices taking only unused clusters into account
2562 quality = BuildSeedingConfigs(stack, configs);
4d6aee34 2563 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
41702fec 2564
2565 for(Int_t ip = 0; ip < kNPlanes; ip++){
2566 if(!(chamber = stack[ip])) continue;
c79857d5 2567 chamber->Build(fGeom);//Indices(fSieveSeeding);
41702fec 2568 }
2569
9e85cb05 2570 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
41702fec 2571 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2572 }
2573 } while(fSieveSeeding<10); // end stack clusters sieve
2574
2575
2576
2577 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2578
2579 return ntracks2;
e4f2f73d 2580}
2581
2582//___________________________________________________________________
eb38ed55 2583Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
e4f2f73d 2584{
41702fec 2585 //
2586 // Assign probabilities to chambers according to their
2587 // capability of producing seeds.
2588 //
2589 // Parameters :
2590 //
2591 // layers : Array of stack propagation layers for all 6 chambers in one stack
2592 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2593 // for details) in the decreasing order of their seeding probabilities.
2594 //
2595 // Output :
2596 //
2597 // Return top configuration quality
2598 //
2599 // Detailed description:
2600 //
2601 // To each chamber seeding configuration (see GetSeedingConfig() for
2602 // the list of all configurations) one defines 2 quality factors:
2603 // - an apriori topological quality (see GetSeedingConfig() for details) and
2604 // - a data quality based on the uniformity of the distribution of
2605 // clusters over the x range (time bins population). See CookChamberQA() for details.
2606 // The overall chamber quality is given by the product of this 2 contributions.
2607 //
2608
eb2b4f91 2609 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
4d6aee34 2610 AliTRDtrackingChamber *chamber = NULL;
41702fec 2611 for(int iplane=0; iplane<kNPlanes; iplane++){
2612 if(!(chamber = stack[iplane])) continue;
2613 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2614 }
2615
eb2b4f91 2616 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2617 Int_t planes[] = {0, 0, 0, 0};
41702fec 2618 for(int iconf=0; iconf<kNConfigs; iconf++){
2619 GetSeedingConfig(iconf, planes);
2620 tconfig[iconf] = fgTopologicQA[iconf];
2621 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2622 }
2623
2624 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
0b559d95 2625 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
41702fec 2626 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2627 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2628
2629 return tconfig[configs[0]];
e4f2f73d 2630}
2631
2632//____________________________________________________________________
e17f4785 2633Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
e4f2f73d 2634{
afa21247 2635//
2a3191bb 2636// Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2637// either missed by TPC prolongation or conversions inside the TRD volume.
2638// For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
afa21247 2639//
2640// Parameters :
2641// layers : Array of stack propagation layers containing clusters
2642// sseed : Array of empty tracklet seeds. On exit they are filled.
2643// ipar : Control parameters:
2644// ipar[0] -> seeding chambers configuration
2645// ipar[1] -> stack index
2646// ipar[2] -> number of track candidates found so far
2647//
2648// Output :
2649// Number of tracks candidates found.
2650//
2651// The following steps are performed:
2652// 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2653// radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2654// is described in AliTRDtrackerV1::Clusters2TracksStack().
2655// 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2656// - for each seeding cluster in the lower seeding layer find
2657// - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2658// is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2659// - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2660// reco params
2661// - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2662// seeding clusters.
2663// The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2664// and AliTRDchamberTimeBin::GetClusters().
2665// 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2666// performed at this level
2667// 4. Initialize seeding tracklets in the seeding chambers.
2668// 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2669// 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2670// AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2671// 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2672// 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2673// approximation of the track.
2674// 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2675// checked against the Riemann fit:
2676// - position resolution in y
2677// - angular resolution in the bending plane
2678// - likelihood of the number of clusters attached to the tracklet
2679// 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2680// - Initialization of extrapolation tracklets with the fit parameters
2681// - Attach clusters to extrapolated tracklets
2682// - Helix fit of tracklets
2683// 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2684// See AliTRDtrackerV1::ImproveSeedQuality() for details.
2685// 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2686// 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2687// 14. Cooking labels for tracklets. Should be done only for MC
2688// 15. Register seeds.
2689//
2690// Authors:
2691// Marian Ivanov <M.Ivanov@gsi.de>
2692// Alexandru Bercuci <A.Bercuci@gsi.de>
2693// Markus Fasel <M.Fasel@gsi.de>
41702fec 2694
4d6aee34 2695 AliTRDtrackingChamber *chamber = NULL;
2696 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
e17f4785 2697 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
41702fec 2698 Int_t ncl, mcl; // working variable for looping over clusters
2699 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2700 // chi2 storage
2701 // chi2[0] = tracklet chi2 on the Z direction
2702 // chi2[1] = tracklet chi2 on the R direction
2703 Double_t chi2[4];
2704
afa21247 2705 // this should be data member of AliTRDtrack TODO
41702fec 2706 Double_t seedQuality[kMaxTracksStack];
2707
2708 // unpack control parameters
2709 Int_t config = ipar[0];
2710 Int_t ntracks = ipar[1];
d931f2aa 2711 Int_t istack = ipar[2];
41702fec 2712 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
afa21247 2713 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
be24510a 2714
2715
41702fec 2716 // Init chambers geometry
41702fec 2717 Double_t hL[kNPlanes]; // Tilting angle
2718 Float_t padlength[kNPlanes]; // pad lenghts
dd8059a8 2719 Float_t padwidth[kNPlanes]; // pad widths
4d6aee34 2720 AliTRDpadPlane *pp = NULL;
41702fec 2721 for(int iplane=0; iplane<kNPlanes; iplane++){
2722 pp = fGeom->GetPadPlane(iplane, istack);
bb79ccd5 2723 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
41702fec 2724 padlength[iplane] = pp->GetLengthIPad();
dd8059a8 2725 padwidth[iplane] = pp->GetWidthIPad();
41702fec 2726 }
2727
eb2b4f91 2728 // Init anode wire position for chambers
e165b64b 2729 Double_t x0[kNPlanes], // anode wire position
eb2b4f91 2730 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
4d6aee34 2731 TGeoHMatrix *matrix = NULL;
eb2b4f91 2732 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2733 Double_t glb[] = {0., 0., 0.};
2734 AliTRDtrackingChamber **cIter = &stack[0];
a3743898 2735 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
eb2b4f91 2736 if(!(*cIter)) continue;
e165b64b 2737 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
e165b64b 2738 x0[iLayer] = fgkX0[iLayer];
e7542a7e 2739 continue;
e165b64b 2740 }
eb2b4f91 2741 matrix->LocalToMaster(loc, glb);
2742 x0[iLayer] = glb[0];
2743 }
2744
980d5a2a 2745 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
41702fec 2746
d931f2aa 2747 // Build seeding layers
d611c74f 2748 ResetSeedTB();
41702fec 2749 Int_t nlayers = 0;
41702fec 2750 for(int isl=0; isl<kNSeedPlanes; isl++){
2751 if(!(chamber = stack[planes[isl]])) continue;
4d6aee34 2752 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
41702fec 2753 nlayers++;
41702fec 2754 }
eb2b4f91 2755 if(nlayers < kNSeedPlanes) return ntracks;
41702fec 2756
2757
2758 // Start finding seeds
2759 Double_t cond0[4], cond1[4], cond2[4];
2760 Int_t icl = 0;
d611c74f 2761 while((c[3] = (*fSeedTB[3])[icl++])){
41702fec 2762 if(!c[3]) continue;
d611c74f 2763 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2764 fSeedTB[0]->GetClusters(cond0, index, ncl);
41702fec 2765 //printf("Found c[3] candidates 0 %d\n", ncl);
2766 Int_t jcl = 0;
2767 while(jcl<ncl) {
d611c74f 2768 c[0] = (*fSeedTB[0])[index[jcl++]];
41702fec 2769 if(!c[0]) continue;
2770 Double_t dx = c[3]->GetX() - c[0]->GetX();
afa21247 2771 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2772 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2773 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
d611c74f 2774 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
41702fec 2775 //printf("Found c[0] candidates 1 %d\n", mcl);
2776
2777 Int_t kcl = 0;
2778 while(kcl<mcl) {
d611c74f 2779 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2780 if(!c[1]) continue;
afa21247 2781 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
d611c74f 2782 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2783 //printf("Found c[1] candidate 2 %p\n", c[2]);
2784 if(!c[2]) continue;
980d5a2a 2785
2786 AliDebug(3, Form("Seeding clusters\n 0[%6.3f %6.3f %6.3f]\n 1[%6.3f %6.3f %6.3f]\n 2[%6.3f %6.3f %6.3f]\n 3[%6.3f %6.3f %6.3f].",
2787 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2788 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2789 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2790 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
d611c74f 2791
804bb02e 2792 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
41702fec 2793
d611c74f 2794 FitRieman(c, chi2);
2795
d931f2aa 2796 AliTRDseedV1 *tseed = &cseed[0];
bb2db46c 2797 cIter = &stack[0];
2798 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2799 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
eb2b4f91 2800 tseed->SetDetector(det);
43d6ad34 2801 tseed->SetTilt(hL[iLayer]);
2802 tseed->SetPadLength(padlength[iLayer]);
dd8059a8 2803 tseed->SetPadWidth(padwidth[iLayer]);
4d6aee34 2804 tseed->SetReconstructor(fkReconstructor);
eb2b4f91 2805 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
d611c74f 2806 tseed->Init(GetRiemanFitter());
f29f13a6 2807 tseed->SetStandAlone(kTRUE);
d611c74f 2808 }
2809
2810 Bool_t isFake = kFALSE;
9e85cb05 2811 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
d611c74f 2812 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2813 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2814 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2815
2816 Double_t xpos[4];
2817 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2818 Float_t yref[4];
2819 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2820 Int_t ll = c[3]->GetLabel(0);
2821 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2822 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2823 AliRieman *rim = GetRiemanFitter();
a2fbb6ec 2824 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2825 cs0 << "MakeSeeds0"
2826 <<"EventNumber=" << eventNumber
2827 <<"CandidateNumber=" << candidateNumber
2828 <<"isFake=" << isFake
2829 <<"config=" << config
2830 <<"label=" << ll
2831 <<"chi2z=" << chi2[0]
2832 <<"chi2y=" << chi2[1]
2833 <<"Y2exp=" << cond2[0]
2834 <<"Z2exp=" << cond2[1]
2835 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2836 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2837 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2838 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2839 <<"yref0=" << yref[0]
2840 <<"yref1=" << yref[1]
2841 <<"yref2=" << yref[2]
2842 <<"yref3=" << yref[3]
2843 <<"c0.=" << c[0]
2844 <<"c1.=" << c[1]
2845 <<"c2.=" << c[2]
2846 <<"c3.=" << c[3]
2847 <<"Seed0.=" << &cseed[planes[0]]
2848 <<"Seed1.=" << &cseed[planes[1]]
2849 <<"Seed2.=" << &cseed[planes[2]]
2850 <<"Seed3.=" << &cseed[planes[3]]
2851 <<"RiemanFitter.=" << rim
2852 <<"\n";
2853 }
9e85cb05 2854 if(chi2[0] > fkRecoParam->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
980d5a2a 2855 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
d611c74f 2856 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2857 continue;
2858 }
9e85cb05 2859 if(chi2[1] > fkRecoParam->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
980d5a2a 2860 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
d611c74f 2861 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2862 continue;
2863 }
2864 //AliInfo("Passed chi2 filter.");
2865
2866 // try attaching clusters to tracklets
6e39bde4 2867 Int_t mlayers = 0;
980d5a2a 2868 AliTRDcluster *cl = NULL;
be24510a 2869 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
d611c74f 2870 Int_t jLayer = planes[iLayer];
980d5a2a 2871 Int_t nNotInChamber = 0;
f29f13a6 2872 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
980d5a2a 2873 if(/*fkReconstructor->IsHLT()*/kFALSE){
2874 cseed[jLayer].UpdateUsed();
2875 if(!cseed[jLayer].IsOK()) continue;
2876 }else{
2877 cseed[jLayer].Fit();
2878 cseed[jLayer].UpdateUsed();
2879 cseed[jLayer].ResetClusterIter();
2880 while((cl = cseed[jLayer].NextCluster())){
2881 if(!cl->IsInChamber()) nNotInChamber++;
2882 }
2883 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2884 if(cseed[jLayer].GetN() - (cseed[jLayer].GetNUsed() + nNotInChamber) < 5) continue; // checking for Cluster which are not in chamber is a much stronger restriction on real data
2885 }
d611c74f 2886 mlayers++;
2887 }
be24510a 2888
2889 if(mlayers < kNSeedPlanes){
980d5a2a 2890 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
be24510a 2891 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2892 continue;
2893 }
2894
2895 // temporary exit door for the HLT
4d6aee34 2896 if(fkReconstructor->IsHLT()){
be24510a 2897 // attach clusters to extrapolation chambers
2898 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2899 Int_t jLayer = planesExt[iLayer];
2900 if(!(chamber = stack[jLayer])) continue;
980d5a2a 2901 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
5f1ae1e7 2902 cseed[jLayer].Fit();
be24510a 2903 }
0b559d95 2904 //FitTiltedRiemanConstraint(&cseed[0], GetZ());
4302c900 2905 fTrackQuality[ntracks] = 1.; // dummy value
2906 ntracks++;
218ba867 2907 if(ntracks == kMaxTracksStack) return ntracks;
4302c900 2908 cseed += 6;
2909 continue;
2910 }
2911
be24510a 2912
f29f13a6 2913 // Update Seeds and calculate Likelihood
d611c74f 2914 // fit tracklets and cook likelihood
68f9b6bd 2915 Double_t chi2Vals[4];
2916 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
f29f13a6 2917 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2918 Int_t jLayer = planes[iLayer];
2eb10c34 2919 cseed[jLayer].Fit(1);
f29f13a6 2920 }
91834b8d 2921 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
d611c74f 2922
9e85cb05 2923 if (TMath::Log(1.E-9 + like) < fkRecoParam->GetTrackLikelihood()){
980d5a2a 2924 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
d611c74f 2925 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2926 continue;
2927 }
2928 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2929
2930 // book preliminary results
2931 seedQuality[ntracks] = like;
2932 fSeedLayer[ntracks] = config;/*sLayer;*/
2933
2934 // attach clusters to the extrapolation seeds
980d5a2a 2935 Int_t elayers(0);
be24510a 2936 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2937 Int_t jLayer = planesExt[iLayer];
d611c74f 2938 if(!(chamber = stack[jLayer])) continue;
d611c74f 2939
2940 // fit extrapolated seed
2941 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2942 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2943 AliTRDseedV1 pseed = cseed[jLayer];
f29f13a6 2944 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2eb10c34 2945 pseed.Fit(1);
d611c74f 2946 cseed[jLayer] = pseed;
68f9b6bd 2947 chi2Vals[0] = FitTiltedRieman(cseed, kTRUE);
2eb10c34 2948 cseed[jLayer].Fit(1);
980d5a2a 2949 elayers++;
d611c74f 2950 }
2951
2952 // AliInfo("Extrapolation done.");
2953 // Debug Stream containing all the 6 tracklets
9e85cb05 2954 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
a2fbb6ec 2955 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2956 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2957 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2958 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2959 cstreamer << "MakeSeeds1"
2960 << "EventNumber=" << eventNumber
2961 << "CandidateNumber=" << candidateNumber
2962 << "S0.=" << &cseed[0]
2963 << "S1.=" << &cseed[1]
2964 << "S2.=" << &cseed[2]
2965 << "S3.=" << &cseed[3]
2966 << "S4.=" << &cseed[4]
2967 << "S5.=" << &cseed[5]
2968 << "FitterT.=" << tiltedRieman
2969 << "\n";
2970 }
2971
9e85cb05 2972 if(fkRecoParam->HasImproveTracklets()){
68f9b6bd 2973 if(!ImproveSeedQuality(stack, cseed, chi2Vals[0])){
980d5a2a 2974 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
68f9b6bd 2975 AliDebug(3, "ImproveSeedQuality() failed.");
980d5a2a 2976 }
d611c74f 2977 }
d611c74f 2978
68f9b6bd 2979 // do track fitting with vertex constraint
2980 if(fkRecoParam->IsVertexConstrained()) chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ());
2981 else chi2Vals[1] = -1.;
2982 chi2Vals[2] = GetChi2Z(&cseed[0]);
2983 chi2Vals[3] = GetChi2Phi(&cseed[0]);
2984
2985 // calculate track quality
2986 fTrackQuality[ntracks] = CalculateTrackLikelihood(&chi2Vals[0]);
fac58f00 2987
9e85cb05 2988 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
a2fbb6ec 2989 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2990 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2991 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2992 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2993 TLinearFitter *fitterT = GetTiltedRiemanFitter();
91834b8d 2994 Int_t ncls = 0;
2995 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2996 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2997 }
d611c74f 2998 cstreamer << "MakeSeeds2"
2999 << "EventNumber=" << eventNumber
3000 << "CandidateNumber=" << candidateNumber
3001 << "Chi2TR=" << chi2Vals[0]
3002 << "Chi2TC=" << chi2Vals[1]
3003 << "Nlayers=" << mlayers
91834b8d 3004 << "NClusters=" << ncls
d611c74f 3005 << "Like=" << like
3006 << "S0.=" << &cseed[0]
3007 << "S1.=" << &cseed[1]
3008 << "S2.=" << &cseed[2]
3009 << "S3.=" << &cseed[3]
3010 << "S4.=" << &cseed[4]
3011 << "S5.=" << &cseed[5]
d611c74f 3012 << "FitterT.=" << fitterT
3013 << "FitterTC.=" << fitterTC
3014 << "\n";
3015 }
68f9b6bd 3016 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")){
3017 Double_t pt[]={0., 0.};
3018 for(Int_t il(0); il<kNPlanes; il++){
3019 if(!cseed[il].IsOK()) continue;
3020 pt[0] = GetBz()*kB2C/cseed[il].GetC();
3021 pt[1] = GetBz()*kB2C/cseed[il].GetC(1);
3022 break;
3023 }
3024 AliDebug(2, Form("Candidate[%2d] pt[%7.3f %7.3f] Q[%e]\n"
3025 " [0] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3026 " [1] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3027 " [2] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3028 " [3] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3029 " [4] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3030 " [5] x[%6.2f] n[%2d] nu[%d] OK[%c]"
3031 , ntracks, pt[0], pt[1], fTrackQuality[ntracks]
3032 ,cseed[0].GetX(), cseed[0].GetN(), cseed[0].GetNUsed(), cseed[0].IsOK()?'y':'n'
3033 ,cseed[1].GetX(), cseed[1].GetN(), cseed[1].GetNUsed(), cseed[1].IsOK()?'y':'n'
3034 ,cseed[2].GetX(), cseed[2].GetN(), cseed[2].GetNUsed(), cseed[2].IsOK()?'y':'n'
3035 ,cseed[3].GetX(), cseed[3].GetN(), cseed[3].GetNUsed(), cseed[3].IsOK()?'y':'n'
3036 ,cseed[4].GetX(), cseed[4].GetN(), cseed[4].GetNUsed(), cseed[4].IsOK()?'y':'n'
3037 ,cseed[5].GetX(), cseed[5].GetN(), cseed[5].GetNUsed(), cseed[5].IsOK()?'y':'n'));
3038 }
d611c74f 3039 ntracks++;
3040 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
3041 if(ntracks == kMaxTracksStack){
3042 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
3043 return ntracks;
3044 }
3045 cseed += 6;
41702fec 3046 }
3047 }
3048 }
41702fec 3049
3050 return ntracks;
e4f2f73d 3051}
3052
3053//_____________________________________________________________________________
68f9b6bd 3054AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const tracklet)
e4f2f73d 3055{
afa21247 3056//
3057// Build a TRD track out of tracklet candidates
3058//
3059// Parameters :
3060// seeds : array of tracklets
3061// params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
3062// [0] - radial position of the track at reference point
3063// [1] - y position of the fit at [0]
3064// [2] - z position of the fit at [0]
3065// [3] - snp of the first tracklet
3066// [4] - tgl of the first tracklet
3067// [5] - curvature of the Riemann fit - 1/pt
3068// [6] - sector rotation angle
3069//
3070// Output :
3071// The TRD track.
3072//
3073// Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
3074// (diagonal with constant variance terms TODO - correct parameterization)
3075//
3076// In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
3077// offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
3078// for details). Do also MC label calculation and PID if propagation successfully.
41702fec 3079
0b559d95 3080 if(fkReconstructor->IsHLT()) FitTiltedRiemanConstraint(tracklet, 0);
41702fec 3081 Double_t alpha = AliTRDgeometry::GetAlpha();
3082 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
41702fec 3083
68f9b6bd 3084 // find first good tracklet
3085 Int_t idx(0); while(idx<kNPlanes && !tracklet[idx].IsOK()) idx++;
3086 if(idx>2){ AliDebug(1, Form("Found suspect track start @ layer idx[%d]\n"
3087 " %c[0] x0[%f] n[%d] nu[%d] OK[%c]\n"
3088 " %c[1] x0[%f] n[%d] nu[%d] OK[%c]\n"
3089 " %c[2] x0[%f] n[%d] nu[%d] OK[%c]\n"
3090 " %c[3] x0[%f] n[%d] nu[%d] OK[%c]\n"
3091 " %c[4] x0[%f] n[%d] nu[%d] OK[%c]\n"
3092 " %c[5] x0[%f] n[%d] nu[%d] OK[%c]"
3093 ,idx
3094 ,idx==0?'*':' ', tracklet[0].GetX0(), tracklet[0].GetN(), tracklet[0].GetNUsed(), tracklet[0].IsOK()?'y':'n'
3095 ,idx==1?'*':' ', tracklet[1].GetX0(), tracklet[1].GetN(), tracklet[1].GetNUsed(), tr