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