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