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