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