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