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