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