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