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