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