]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrackerV1.cxx
Remove class AliPtMothFromPtDaugh, which introduced unwanted dependency on libSTEER
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
CommitLineData
e4f2f73d 1/**************************************************************************
972ef65e 2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
e4f2f73d 15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Track finder //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
e4f2f73d 28#include <TBranch.h>
bb56afff 29#include <TDirectory.h>
e4f2f73d 30#include <TLinearFitter.h>
e4f2f73d 31#include <TTree.h>
32#include <TClonesArray.h>
e4f2f73d 33#include <TTreeStream.h>
eb2b4f91 34#include <TGeoMatrix.h>
35#include <TGeoManager.h>
e4f2f73d 36
37#include "AliLog.h"
fac58f00 38#include "AliMathBase.h"
e4f2f73d 39#include "AliESDEvent.h"
bb56afff 40#include "AliGeomManager.h"
e4f2f73d 41#include "AliRieman.h"
42#include "AliTrackPointArray.h"
43
e4f2f73d 44#include "AliTRDgeometry.h"
45#include "AliTRDpadPlane.h"
e4f2f73d 46#include "AliTRDcalibDB.h"
e4f2f73d 47#include "AliTRDReconstructor.h"
48#include "AliTRDCalibraFillHisto.h"
e4f2f73d 49#include "AliTRDrecoParam.h"
bb56afff 50
51#include "AliTRDcluster.h"
828c6f80 52#include "AliTRDdigitsParam.h"
e4f2f73d 53#include "AliTRDseedV1.h"
0906e73e 54#include "AliTRDtrackV1.h"
bb56afff 55#include "AliTRDtrackerV1.h"
56#include "AliTRDtrackerDebug.h"
57#include "AliTRDtrackingChamber.h"
58#include "AliTRDchamberTimeBin.h"
59
e4f2f73d 60ClassImp(AliTRDtrackerV1)
903326c1 61ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
eb38ed55 63
eb38ed55 64const Float_t AliTRDtrackerV1::fgkMinClustersInTrack = 0.5; //
65const Float_t AliTRDtrackerV1::fgkLabelFraction = 0.8; //
66const Double_t AliTRDtrackerV1::fgkMaxChi2 = 12.0; //
67const Double_t AliTRDtrackerV1::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
68const Double_t AliTRDtrackerV1::fgkMaxStep = 2.0; // Maximal step size in propagation
d76231c8 69Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
6e39bde4 70 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
41702fec 71 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
72 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
e165b64b 73};
74const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
75 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
2985ffcb 76Int_t AliTRDtrackerV1::fgNTimeBins = 0;
4d6aee34 77AliRieman* AliTRDtrackerV1::fgRieman = NULL;
78TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
79TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
e4f2f73d 80
81//____________________________________________________________________
3a039a31 82AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
41702fec 83 :AliTracker()
4d6aee34 84 ,fkReconstructor(NULL)
9e85cb05 85 ,fkRecoParam(NULL)
4d6aee34 86 ,fGeom(NULL)
87 ,fClusters(NULL)
88 ,fTracklets(NULL)
89 ,fTracks(NULL)
b1135f96 90 ,fTracksESD(NULL)
41702fec 91 ,fSieveSeeding(0)
e4f2f73d 92{
41702fec 93 //
94 // Default constructor.
95 //
eb2b4f91 96
97 SetReconstructor(rec); // initialize reconstructor
98
99 // initialize geometry
100 if(!AliGeomManager::GetGeometry()){
101 AliFatal("Could not get geometry.");
102 }
103 fGeom = new AliTRDgeometry();
104 fGeom->CreateClusterMatrixArray();
4d6aee34 105 TGeoHMatrix *matrix = NULL;
eb2b4f91 106 Double_t loc[] = {0., 0., 0.};
107 Double_t glb[] = {0., 0., 0.};
108 for(Int_t ily=kNPlanes; ily--;){
e165b64b 109 Int_t ism = 0;
110 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
111 if(!matrix){
112 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
113 fR[ily] = fgkX0[ily];
eb2b4f91 114 continue;
115 }
116 matrix->LocalToMaster(loc, glb);
117 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
118 }
119
eb2b4f91 120 // initialize cluster containers
053767a4 121 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
3a039a31 122
eb2b4f91 123 // initialize arrays
124 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
125 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
126 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
b1135f96 127 fTracksESD = new TClonesArray("AliESDtrack", 2*kMaxTracksStack);
128 fTracksESD->SetOwner();
eb38ed55 129}
130
e4f2f73d 131//____________________________________________________________________
132AliTRDtrackerV1::~AliTRDtrackerV1()
133{
41702fec 134 //
135 // Destructor
136 //
137
4d6aee34 138 if(fgRieman) delete fgRieman; fgRieman = NULL;
139 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
140 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
d611c74f 141 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
b1135f96 142 if(fTracksESD){ fTracksESD->Delete(); delete fTracksESD; }
41702fec 143 if(fTracks) {fTracks->Delete(); delete fTracks;}
144 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
48f8adf3 145 if(fClusters) {
146 fClusters->Delete(); delete fClusters;
147 }
41702fec 148 if(fGeom) delete fGeom;
e4f2f73d 149}
150
151//____________________________________________________________________
152Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
153{
41702fec 154 //
155 // Steering stand alone tracking for full TRD detector
156 //
157 // Parameters :
158 // esd : The ESD event. On output it contains
159 // the ESD tracks found in TRD.
160 //
161 // Output :
162 // Number of tracks found in the TRD detector.
163 //
164 // Detailed description
165 // 1. Launch individual SM trackers.
166 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
167 //
168
9e85cb05 169 if(!fkRecoParam){
3a039a31 170 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
41702fec 171 return 0;
172 }
173
174 //AliInfo("Start Track Finder ...");
175 Int_t ntracks = 0;
053767a4 176 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
41702fec 177 // for(int ism=1; ism<2; ism++){
178 //AliInfo(Form("Processing supermodule %i ...", ism));
179 ntracks += Clusters2TracksSM(ism, esd);
180 }
980d5a2a 181 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
41702fec 182 return ntracks;
e4f2f73d 183}
184
0906e73e 185
186//_____________________________________________________________________________
eb38ed55 187Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
0906e73e 188{
41702fec 189 //AliInfo(Form("Asking for tracklet %d", index));
190
84eab75a 191 // reset position of the point before using it
192 p.SetXYZ(0., 0., 0.);
2f7514a6 193 AliTRDseedV1 *tracklet = GetTracklet(index);
194 if (!tracklet) return kFALSE;
84eab75a 195
41702fec 196 // get detector for this tracklet
e165b64b 197 Int_t det = tracklet->GetDetector();
198 Int_t sec = fGeom->GetSector(det);
199 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
200 sinA = TMath::Sin(alpha),
201 cosA = TMath::Cos(alpha);
41702fec 202 Double_t local[3];
e165b64b 203 local[0] = tracklet->GetX();
204 local[1] = tracklet->GetY();
205 local[2] = tracklet->GetZ();
41702fec 206 Double_t global[3];
e165b64b 207 fGeom->RotateBack(det, local, global);
208
209 Double_t cov2D[3]; Float_t cov[6];
210 tracklet->GetCovAt(local[0], cov2D);
211 cov[0] = cov2D[0]*sinA*sinA;
212 cov[1] =-cov2D[0]*sinA*cosA;
213 cov[2] =-cov2D[1]*sinA;
214 cov[3] = cov2D[0]*cosA*cosA;
215 cov[4] = cov2D[1]*cosA;
216 cov[5] = cov2D[2];
217 // store the global position of the tracklet and its covariance matrix in the track point
218 p.SetXYZ(global[0],global[1],global[2], cov);
41702fec 219
220 // setting volume id
e165b64b 221 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
222 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
41702fec 223 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
224 p.SetVolumeID(volid);
225
226 return kTRUE;
0906e73e 227}
228
eb38ed55 229//____________________________________________________________________
230TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
231{
41702fec 232 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
233 return fgTiltedRieman;
eb38ed55 234}
0906e73e 235
eb38ed55 236//____________________________________________________________________
237TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
238{
41702fec 239 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
240 return fgTiltedRiemanConstrained;
eb38ed55 241}
41702fec 242
eb38ed55 243//____________________________________________________________________
244AliRieman* AliTRDtrackerV1::GetRiemanFitter()
245{
fac58f00 246 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
41702fec 247 return fgRieman;
eb38ed55 248}
41702fec 249
0906e73e 250//_____________________________________________________________________________
251Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
252{
2a3191bb 253// Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
254// a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
255// covariance, PID, etc.) are than used to update the corresponding ESD track.
256// Each track seed is first propagated to the geometrical limit of the TRD detector.
257// Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
258// constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
259// Otherwise the ESD track is left unchanged.
260//
261// The following steps are performed:
262// 1. Selection of tracks based on the variance in the y-z plane.
263// 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
264// 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
265// the following status bits:
266// - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
267// - AliESDtrack::kTRDStop - if the tracks fails propagation
268// - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
269// 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
270// 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
271//
272
e3d45279 273 if(!fClusters || !fClusters->GetEntriesFast()){
274 AliInfo("No TRD clusters");
275 return 0;
276 }
2a3191bb 277 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
e3d45279 278 if (!calibra) AliInfo("Could not get Calibra instance");
c6f7c6cb 279 if (!fgNTimeBins) fgNTimeBins = fkReconstructor->GetNTimeBins();
828c6f80 280
eb2b4f91 281 // Define scalers
282 Int_t nFound = 0, // number of tracks found
b453ef55 283 nBacked = 0, // number of tracks backed up for refit
eb2b4f91 284 nSeeds = 0, // total number of ESD seeds
285 nTRDseeds= 0, // number of seeds in the TRD acceptance
286 nTPCseeds= 0; // number of TPC seeds
41702fec 287 Float_t foundMin = 20.0;
288
4d6aee34 289 Float_t *quality = NULL;
290 Int_t *index = NULL;
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];
296 index = new Int_t[nSeeds];
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
41702fec 321 new(&track) AliTRDtrackV1(*seed);
eb2b4f91 322 if(AliTRDgeometry::GetXtrdBeg() > (fgkMaxStep + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), fgkMaxStep)){
323 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
324 continue;
325 }
326 if(!AdjustSector(&track)){
327 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
328 continue;
329 }
330 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp) {
331 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
332 continue;
333 }
334
335 nTPCseeds++;
e4d4864b 336
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)));
343 expectedClr = FollowBackProlongation(track);
344 // check if track entered the TRD fiducial volume
345 if(track.GetTrackLow()){
346 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
347 nTRDseeds++;
348 }
349 // check if track was stopped in the TRD
350 if (expectedClr<0){
351 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
352 continue;
353 }
ae3fbe1f 354
355 if(expectedClr){
eb2b4f91 356 nFound++;
41702fec 357 // computes PID for track
358 track.CookPID();
359 // update calibration references using this track
360 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
361 // save calibration object
9e85cb05 362 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 &&
363fkRecoParam->IsOverPtThreshold(track.Pt())){
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
27fbeba8 373 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
e3cf3d02 374
41702fec 375 // Make backup for back propagation
41702fec 376 Int_t foundClr = track.GetNumberOfClusters();
377 if (foundClr >= foundMin) {
41702fec 378 track.CookLabel(1. - fgkLabelFraction);
f29f13a6 379 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
41702fec 380
381 // Sign only gold tracks
382 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
f29f13a6 383 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
41702fec 384 }
385 Bool_t isGold = kFALSE;
386
387 // Full gold track
388 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
389 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
b453ef55 390 nBacked++;
41702fec 391 isGold = kTRUE;
392 }
393
394 // Almost gold track
395 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
396 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
397 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
b453ef55 398 nBacked++;
41702fec 399 isGold = kTRUE;
400 }
401
402 if ((!isGold) && (track.GetBackupTrack())) {
403 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
404 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
b453ef55 405 nBacked++;
41702fec 406 isGold = kTRUE;
407 }
408 }
41702fec 409 }
410 }
411
eb2b4f91 412 // Propagation to the TOF
413 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
414 Int_t sm = track.GetSector();
415 // default value in case we have problems with the geometry.
416 Double_t xtof = 371.;
417 //Calculate radial position of the beginning of the TOF
418 //mother volume. In order to avoid mixing of the TRD
419 //and TOF modules some hard values are needed. This are:
420 //1. The path to the TOF module.
421 //2. The width of the TOF (29.05 cm)
422 //(with the help of Annalisa de Caro Mar-17-2009)
423 if(gGeoManager){
424 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
4d6aee34 425 TGeoHMatrix *m = NULL;
eb2b4f91 426 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
427
428 if((m=gGeoManager->GetCurrentMatrix())){
429 m->LocalToMaster(loc, glob);
430 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
431 }
41702fec 432 }
672b48bd 433 if(xtof > (fgkMaxStep + track.GetX()) && !PropagateToX(track, xtof, fgkMaxStep)){
434 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
435 continue;
436 }
437 if(!AdjustSector(&track)){
438 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
439 continue;
440 }
441 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp){
442 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
443 continue;
444 }
050875b0 445 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
eb2b4f91 446 // TODO obsolete - delete
447 seed->SetTRDQuality(track.StatusForTOF());
41702fec 448 }
41702fec 449 seed->SetTRDBudget(track.GetBudget(0));
450 }
d611c74f 451 if(index) delete [] index;
452 if(quality) delete [] quality;
41702fec 453
d4cf71ca 454 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
b453ef55 455 AliInfo(Form("Number of tracks: TRDout[%d] TRDbackup[%d]", nFound, nBacked));
d4cf71ca 456
d611c74f 457 // run stand alone tracking
4d6aee34 458 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
41702fec 459
460 return 0;
0906e73e 461}
462
463
464//____________________________________________________________________
465Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
466{
41702fec 467 //
468 // Refits tracks within the TRD. The ESD event is expected to contain seeds
469 // at the outer part of the TRD.
470 // The tracks are propagated to the innermost time bin
471 // of the TRD and the ESD event is updated
472 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
473 //
474
475 Int_t nseed = 0; // contor for loaded seeds
476 Int_t found = 0; // contor for updated TRD tracks
477
478
e3d45279 479 if(!fClusters || !fClusters->GetEntriesFast()){
480 AliInfo("No TRD clusters");
481 return 0;
482 }
41702fec 483 AliTRDtrackV1 track;
484 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
485 AliESDtrack *seed = event->GetTrack(itrack);
050875b0 486 ULong_t status = seed->GetStatus();
41702fec 487
050875b0 488 new(&track) AliTRDtrackV1(*seed);
41702fec 489 if (track.GetX() < 270.0) {
490 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
491 continue;
492 }
493
e3cf3d02 494 // reject tracks which failed propagation in the TRD or
495 // are produced by the TRD stand alone tracker
e3cf3d02 496 if(!(status & AliESDtrack::kTRDout)) continue;
497 if(!(status & AliESDtrack::kTRDin)) continue;
41702fec 498 nseed++;
499
500 track.ResetCovariance(50.0);
501
502 // do the propagation and processing
503 Bool_t kUPDATE = kFALSE;
504 Double_t xTPC = 250.0;
505 if(FollowProlongation(track)){
506 // Prolongate to TPC
507 if (PropagateToX(track, xTPC, fgkMaxStep)) { // -with update
e3cf3d02 508 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
509 found++;
510 kUPDATE = kTRUE;
511 }
512
513 // Update the friend track
9e85cb05 514 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 && fkRecoParam->IsOverPtThreshold(track.Pt())){
4d6aee34 515 TObject *o = NULL; Int_t ic = 0;
516 AliTRDtrackV1 *calibTrack = NULL;
e3cf3d02 517 while((o = seed->GetCalibObject(ic++))){
518 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
519 calibTrack->SetTrackHigh(track.GetTrackHigh());
520 }
41702fec 521 }
e3cf3d02 522 }
41702fec 523
524 // Prolongate to TPC without update
525 if(!kUPDATE) {
526 AliTRDtrackV1 tt(*seed);
e3cf3d02 527 if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
41702fec 528 }
529 }
980d5a2a 530 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
531 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
41702fec 532
533 return 0;
0906e73e 534}
535
0906e73e 536//____________________________________________________________________
537Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
538{
41702fec 539 // Extrapolates the TRD track in the TPC direction.
540 //
541 // Parameters
542 // t : the TRD track which has to be extrapolated
543 //
544 // Output
545 // number of clusters attached to the track
546 //
547 // Detailed description
548 //
549 // Starting from current radial position of track <t> this function
550 // extrapolates the track through the 6 TRD layers. The following steps
551 // are being performed for each plane:
552 // 1. prepare track:
553 // a. get plane limits in the local x direction
554 // b. check crossing sectors
555 // c. check track inclination
556 // 2. search tracklet in the tracker list (see GetTracklet() for details)
557 // 3. evaluate material budget using the geo manager
558 // 4. propagate and update track using the tracklet information.
559 //
560 // Debug level 2
561 //
562
e3cf3d02 563 Bool_t kStoreIn = kTRUE;
41702fec 564 Int_t nClustersExpected = 0;
e3cf3d02 565 for (Int_t iplane = kNPlanes; iplane--;) {
17896e82 566 Int_t index(-1);
41702fec 567 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
17896e82 568 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
41702fec 569 if(!tracklet) continue;
980d5a2a 570 if(!tracklet->IsOK()){
571 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
572 continue;
573 }
e3cf3d02 574 Double_t x = tracklet->GetX();//GetX0();
41702fec 575 // reject tracklets which are not considered for inward refit
576 if(x > t.GetX()+fgkMaxStep) continue;
577
578 // append tracklet to track
579 t.SetTracklet(tracklet, index);
580
581 if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
582 if (!AdjustSector(&t)) break;
583
584 // Start global position
585 Double_t xyz0[3];
586 t.GetXYZ(xyz0);
587
588 // End global position
589 Double_t alpha = t.GetAlpha(), y, z;
590 if (!t.GetProlongation(x,y,z)) break;
591 Double_t xyz1[3];
592 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
593 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
594 xyz1[2] = z;
595
51a23065 596 Double_t length = TMath::Sqrt(
597 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
598 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
599 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
600 );
601 if(length>0.){
602 // Get material budget
603 Double_t param[7];
604 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
605 Double_t xrho= param[0]*param[4];
606 Double_t xx0 = param[1]; // Get mean propagation parameters
607
608 // Propagate and update
609 t.PropagateTo(x, xx0, xrho);
610 if (!AdjustSector(&t)) break;
611 }
e3cf3d02 612 if(kStoreIn){
613 t.SetTrackHigh();
614 kStoreIn = kFALSE;
615 }
616
b72f4eaf 617 Double_t cov[3]; tracklet->GetCovAt(x, cov);
618 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
619 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
620 if (chi2 < 1e+10 && t.Update(p, cov, chi2)){
41702fec 621 nClustersExpected += tracklet->GetN();
622 }
623 }
624
9e85cb05 625 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
41702fec 626 Int_t index;
51a23065 627 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
41702fec 628 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
629 if(!tracklet) continue;
630 t.SetTracklet(tracklet, index);
631 }
632
a2fbb6ec 633 if(fkReconstructor->IsDebugStreaming()){
634 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
635 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
636 AliTRDtrackV1 track(t);
637 track.SetOwner();
638 cstreamer << "FollowProlongation"
639 << "EventNumber=" << eventNumber
640 << "ncl=" << nClustersExpected
641 << "track.=" << &track
642 << "\n";
643 }
41702fec 644 }
41702fec 645 return nClustersExpected;
0906e73e 646
647}
648
649//_____________________________________________________________________________
650Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
651{
afa21247 652// Extrapolates/Build the TRD track in the TOF direction.
653//
654// Parameters
655// t : the TRD track which has to be extrapolated
656//
657// Output
658// number of clusters attached to the track
659//
660// Starting from current radial position of track <t> this function
661// extrapolates the track through the 6 TRD layers. The following steps
662// are being performed for each plane:
663// 1. Propagate track to the entrance of the next chamber:
664// - get chamber limits in the radial direction
665// - check crossing sectors
666// - check track inclination
667// - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
668// 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
669// Kalman filter is needed and tracklets are already linked to the track this step is skipped.
670// 3. Fit tracklet using the information from the Kalman filter.
671// 4. Propagate and update track at reference radial position of the tracklet.
672// 5. Register tracklet with the tracker and track; update pulls monitoring.
673//
674// Observation
2a3191bb 675// 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:
676// - AliTRDtrackV1::kProlongation : track prolongation failed
677// - AliTRDtrackV1::kPropagation : track prolongation failed
678// - AliTRDtrackV1::kAdjustSector : failed during sector crossing
679// - AliTRDtrackV1::kSnp : too large bending
680// - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
681// - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
682// - AliTRDtrackV1::kUnknown : anything which is not covered before
afa21247 683// 2. By default the status of the track before first TRD update is saved.
684//
685// Debug level 2
686//
687// Author
688// Alexandru Bercuci <A.Bercuci@gsi.de>
689//
41702fec 690
eb2b4f91 691 Int_t n = 0;
692 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
4d6aee34 693 AliTRDtrackingChamber *chamber = NULL;
41702fec 694
9e85cb05 695 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
7c3eecb8 696 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
697
4d6aee34 698 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
181d2c97 699 // in case of stand alone tracking we store all the pointers to the tracklets in a temporary array
700 AliTRDseedV1 *tracklets[kNPlanes];
701 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
702 for(Int_t ip = 0; ip < kNPlanes; ip++){
703 tracklets[ip] = t.GetTracklet(ip);
704 t.UnsetTracklet(ip);
705 }
b06a50a5 706 Bool_t kStoreIn(kTRUE), //
707 kPropagateIn(kTRUE),//
9e85cb05 708 kUseTRD(fkRecoParam->IsOverPtThreshold(t.Pt()));// use TRD measurment to update Kalman
e3cf3d02 709
053767a4 710 // Loop through the TRD layers
4d6aee34 711 TGeoHMatrix *matrix = NULL;
eb2b4f91 712 Double_t x, y, z;
713 for (Int_t ily=0, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
1bd708e3 714 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
715
eb2b4f91 716 // rough estimate of the entry point
717 if (!t.GetProlongation(fR[ily], y, z)){
718 n=-1;
719 t.SetStatus(AliTRDtrackV1::kProlongation);
1bd708e3 720 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
eb2b4f91 721 break;
722 }
41702fec 723
eb2b4f91 724 // find sector / stack / detector
725 sm = t.GetSector();
726 // TODO cross check with y value !
727 stk = fGeom->GetStack(z, ily);
728 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
4d6aee34 729 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
1bd708e3 730 AliDebug(3, Form("Propagate to det[%3d]", det));
eb2b4f91 731
732 // check if supermodule/chamber is installed
733 if( !fGeom->GetSMstatus(sm) ||
734 stk<0. ||
735 fGeom->IsHole(ily, stk, sm) ||
736 !matrix ){
1bd708e3 737 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
eb2b4f91 738 // propagate to the default radial position
739 if(fR[ily] > (fgkMaxStep + t.GetX()) && !PropagateToX(t, fR[ily], fgkMaxStep)){
740 n=-1;
741 t.SetStatus(AliTRDtrackV1::kPropagation);
1bd708e3 742 AliDebug(4, "Failed Propagation [Missing Geometry]");
41702fec 743 break;
744 }
eb2b4f91 745 if(!AdjustSector(&t)){
746 n=-1;
747 t.SetStatus(AliTRDtrackV1::kAdjustSector);
1bd708e3 748 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
eb2b4f91 749 break;
750 }
751 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp){
752 n=-1;
753 t.SetStatus(AliTRDtrackV1::kSnp);
1bd708e3 754 AliDebug(4, "Failed Max Snp [Missing Geometry]");
eb2b4f91 755 break;
756 }
757 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
41702fec 758 continue;
759 }
e3cf3d02 760
eb2b4f91 761 // retrieve rotation matrix for the current chamber
762 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
763 Double_t glb[] = {0., 0., 0.};
764 matrix->LocalToMaster(loc, glb);
765
766 // Propagate to the radial distance of the current layer
767 x = glb[0] - fgkMaxStep;
768 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)){
769 n=-1;
770 t.SetStatus(AliTRDtrackV1::kPropagation);
1bd708e3 771 AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
eb2b4f91 772 break;
773 }
774 if(!AdjustSector(&t)){
775 n=-1;
776 t.SetStatus(AliTRDtrackV1::kAdjustSector);
1bd708e3 777 AliDebug(4, "Failed Adjust Sector Start");
eb2b4f91 778 break;
779 }
780 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
781 n=-1;
782 t.SetStatus(AliTRDtrackV1::kSnp);
1bd708e3 783 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
eb2b4f91 784 break;
785 }
4d6aee34 786 Bool_t doRecalculate = kFALSE;
eb2b4f91 787 if(sm != t.GetSector()){
788 sm = t.GetSector();
4d6aee34 789 doRecalculate = kTRUE;
eb2b4f91 790 }
791 if(stk != fGeom->GetStack(z, ily)){
792 stk = fGeom->GetStack(z, ily);
4d6aee34 793 doRecalculate = kTRUE;
eb2b4f91 794 }
4d6aee34 795 if(doRecalculate){
eb2b4f91 796 det = AliTRDgeometry::GetDetector(ily, stk, sm);
797 if(!(matrix = fGeom->GetClusterMatrix(det))){
798 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
1bd708e3 799 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
eb2b4f91 800 continue;
801 }
802 matrix->LocalToMaster(loc, glb);
803 x = glb[0] - fgkMaxStep;
804 }
805
806 // check if track is well inside fiducial volume
807 if (!t.GetProlongation(x+fgkMaxStep, y, z)) {
808 n=-1;
809 t.SetStatus(AliTRDtrackV1::kProlongation);
1bd708e3 810 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+fgkMaxStep, y, z));
eb2b4f91 811 break;
812 }
813 if(fGeom->IsOnBoundary(det, y, z, .5)){
814 t.SetStatus(AliTRDtrackV1::kBoundary, ily);
1bd708e3 815 AliDebug(4, "Failed Track on Boundary");
eb2b4f91 816 continue;
817 }
818 // mark track as entering the FIDUCIAL volume of TRD
e3cf3d02 819 if(kStoreIn){
820 t.SetTrackLow();
821 kStoreIn = kFALSE;
822 }
b1957d3c 823
eb2b4f91 824 ptrTracklet = tracklets[ily];
825 if(!ptrTracklet){ // BUILD TRACKLET
1bd708e3 826 AliDebug(3, Form("Building tracklet det[%d]", det));
eb2b4f91 827 // check data in supermodule
828 if(!fTrSec[sm].GetNChambers()){
829 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
1bd708e3 830 AliDebug(4, "Failed NoClusters");
eb2b4f91 831 continue;
832 }
833 if(fTrSec[sm].GetX(ily) < 1.){
834 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
1bd708e3 835 AliDebug(4, "Failed NoX");
eb2b4f91 836 continue;
837 }
838
839 // check data in chamber
840 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
841 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
1bd708e3 842 AliDebug(4, "Failed No Detector");
eb2b4f91 843 continue;
844 }
9e85cb05 845 if(chamber->GetNClusters() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
eb2b4f91 846 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
1bd708e3 847 AliDebug(4, "Failed Not Enough Clusters in Detector");
eb2b4f91 848 continue;
849 }
850 // build tracklet
851 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
4d6aee34 852 ptrTracklet->SetReconstructor(fkReconstructor);
eb2b4f91 853 ptrTracklet->SetKink(t.IsKink());
854 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
855 ptrTracklet->SetX0(glb[0]+driftLength);
856 if(!tracklet.Init(&t)){
857 n=-1;
858 t.SetStatus(AliTRDtrackV1::kTrackletInit);
1bd708e3 859 AliDebug(4, "Failed Tracklet Init");
eb2b4f91 860 break;
861 }
862 if(!tracklet.AttachClusters(chamber, kTRUE)){
863 t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
7c3eecb8 864 if(debugLevel>3){
865 AliTRDseedV1 trackletCp(*ptrTracklet);
866 UChar_t status(t.GetStatusTRD(ily));
867 (*cstreamer) << "FollowBackProlongation2"
868 <<"status=" << status
869 <<"tracklet.=" << &trackletCp
870 << "\n";
871 }
1bd708e3 872 AliDebug(4, "Failed Attach Clusters");
eb2b4f91 873 continue;
874 }
1bd708e3 875 AliDebug(3, Form("Number of Clusters in Tracklet: %d", tracklet.GetN()));
9e85cb05 876 if(tracklet.GetN() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
eb2b4f91 877 t.SetStatus(AliTRDtrackV1::kNoClustersTracklet, ily);
7c3eecb8 878 if(debugLevel>3){
879 AliTRDseedV1 trackletCp(*ptrTracklet);
880 UChar_t status(t.GetStatusTRD(ily));
881 (*cstreamer) << "FollowBackProlongation2"
882 <<"status=" << status
883 <<"tracklet.=" << &trackletCp
884 << "\n";
885 }
1bd708e3 886 AliDebug(4, "Failed N Clusters Attached");
eb2b4f91 887 continue;
888 }
889 ptrTracklet->UpdateUsed();
0217fcd0 890 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
eb2b4f91 891 // propagate track to the radial position of the tracklet
892 ptrTracklet->UseClusters(); // TODO ? do we need this here ?
893 // fit tracklet no tilt correction
894 if(!ptrTracklet->Fit(kFALSE)){
895 t.SetStatus(AliTRDtrackV1::kNoFit, ily);
1bd708e3 896 AliDebug(4, "Failed Tracklet Fit");
eb2b4f91 897 continue;
898 }
899 x = ptrTracklet->GetX(); //GetX0();
900 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)) {
901 n=-1;
902 t.SetStatus(AliTRDtrackV1::kPropagation);
1bd708e3 903 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
eb2b4f91 904 break;
905 }
906 if(!AdjustSector(&t)) {
907 n=-1;
908 t.SetStatus(AliTRDtrackV1::kAdjustSector);
1bd708e3 909 AliDebug(4, "Failed Adjust Sector");
eb2b4f91 910 break;
41702fec 911 }
eb2b4f91 912 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
913 n=-1;
914 t.SetStatus(AliTRDtrackV1::kSnp);
1bd708e3 915 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
eb2b4f91 916 break;
917 }
81a6494d 918 if(kPropagateIn){
919 t.SetTrackLow();
920 kPropagateIn = kFALSE;
921 }
b72f4eaf 922 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
923 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
924 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
6e39bde4 925 // update Kalman with the TRD measurement
b72f4eaf 926 if(chi2>1e+10){ // TODO
eb2b4f91 927 t.SetStatus(AliTRDtrackV1::kChi2, ily);
7c3eecb8 928 if(debugLevel > 2){
929 UChar_t status(t.GetStatusTRD());
930 AliTRDseedV1 trackletCp(*ptrTracklet);
931 AliTRDtrackV1 trackCp(t);
932 trackCp.SetOwner();
933 (*cstreamer) << "FollowBackProlongation1"
934 << "status=" << status
935 << "tracklet.=" << &trackletCp
936 << "track.=" << &trackCp
937 << "\n";
938 }
1bd708e3 939 AliDebug(4, Form("Failed Chi2[%f]", chi2));
eb2b4f91 940 continue;
941 }
b06a50a5 942 if(!t.Update(p, cov, chi2, kUseTRD)) {
eb2b4f91 943 n=-1;
944 t.SetStatus(AliTRDtrackV1::kUpdate);
7c3eecb8 945 if(debugLevel > 2){
946 UChar_t status(t.GetStatusTRD());
947 AliTRDseedV1 trackletCp(*ptrTracklet);
948 AliTRDtrackV1 trackCp(t);
949 trackCp.SetOwner();
950 (*cstreamer) << "FollowBackProlongation1"
951 << "status=" << status
952 << "tracklet.=" << &trackletCp
953 << "track.=" << &trackCp
954 << "\n";
955 }
1bd708e3 956 AliDebug(4, Form("Failed Track Update @ y[%7.2f] z[%7.2f] s2y[%f] s2z[%f] covyz[%f]", p[0], p[1], cov[0], cov[2], cov[1]));
eb2b4f91 957 break;
958 }
b72f4eaf 959 // fill residuals ?!
960 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
961
eb2b4f91 962
963 // load tracklet to the tracker
16cca13f 964 ptrTracklet->Update(&t);
eb2b4f91 965 ptrTracklet = SetTracklet(ptrTracklet);
17896e82 966 Int_t index(fTracklets->GetEntriesFast()-1);
967 t.SetTracklet(ptrTracklet, index);
eb2b4f91 968 n += ptrTracklet->GetN();
17896e82 969 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
eb2b4f91 970
41702fec 971 // Reset material budget if 2 consecutive gold
eb2b4f91 972// if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
41702fec 973
974 // Make backup of the track until is gold
b453ef55 975 Int_t failed(0);
976 if((failed = t.MakeBackupTrack())) AliDebug(2, Form("Failed backup on cut[%d]", failed));
9e85cb05 977
053767a4 978 } // end layers loop
eb2b4f91 979 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
980 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
41702fec 981
7c3eecb8 982 if(debugLevel > 1){
41702fec 983 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
eb2b4f91 984 AliTRDtrackV1 track(t);
985 track.SetOwner();
7c3eecb8 986 (*cstreamer) << "FollowBackProlongation0"
eb2b4f91 987 << "EventNumber=" << eventNumber
988 << "ncl=" << n
989 << "track.=" << &track
41702fec 990 << "\n";
991 }
992
eb2b4f91 993 return n;
0906e73e 994}
995
eb38ed55 996//_________________________________________________________________________
4d6aee34 997Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
41702fec 998 //
999 // Fits a Riemann-circle to the given points without tilting pad correction.
1000 // The fit is performed using an instance of the class AliRieman (equations
1001 // and transformations see documentation of this class)
1002 // Afterwards all the tracklets are Updated
1003 //
1004 // Parameters: - Array of tracklets (AliTRDseedV1)
1005 // - Storage for the chi2 values (beginning with direction z)
1006 // - Seeding configuration
1007 // Output: - The curvature
1008 //
1009 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1010 fitter->Reset();
1011 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1012 Int_t *ppl = &allplanes[0];
1013 Int_t maxLayers = 6;
1014 if(planes){
1015 maxLayers = 4;
1016 ppl = planes;
1017 }
1018 for(Int_t il = 0; il < maxLayers; il++){
1019 if(!tracklets[ppl[il]].IsOK()) continue;
e3cf3d02 1020 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
41702fec 1021 }
1022 fitter->Update();
1023 // Set the reference position of the fit and calculate the chi2 values
1024 memset(chi2, 0, sizeof(Double_t) * 2);
1025 for(Int_t il = 0; il < maxLayers; il++){
1026 // Reference positions
1027 tracklets[ppl[il]].Init(fitter);
1028
1029 // chi2
1030 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1031 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1032 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1033 }
1034 return fitter->GetC();
eb38ed55 1035}
1036
1037//_________________________________________________________________________
1038void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1039{
41702fec 1040 //
1041 // Performs a Riemann helix fit using the seedclusters as spacepoints
1042 // Afterwards the chi2 values are calculated and the seeds are updated
1043 //
1044 // Parameters: - The four seedclusters
1045 // - The tracklet array (AliTRDseedV1)
1046 // - The seeding configuration
1047 // - Chi2 array
1048 //
1049 // debug level 2
1050 //
1051 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1052 fitter->Reset();
a3743898 1053 for(Int_t i = 0; i < 4; i++){
a3743898 1054 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1055 }
41702fec 1056 fitter->Update();
1057
1058
1059 // Update the seed and calculated the chi2 value
1060 chi2[0] = 0; chi2[1] = 0;
1061 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1062 // chi2
1063 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1064 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1065 }
eb38ed55 1066}
1067
1068
1069//_________________________________________________________________________
1070Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1071{
41702fec 1072 //
1073 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1074 // assumed that the vertex position is set to 0.
1075 // This method is very usefull for high-pt particles
1076 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1077 // x0, y0: Center of the circle
1078 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1079 // zc: center of the pad row
1080 // Equation which has to be fitted (after transformation):
1081 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1082 // Transformation:
1083 // t = 1/(x^2 + y^2)
1084 // u = 2 * x * t
1085 // v = 2 * x * tan(phiT) * t
1086 // Parameters in the equation:
1087 // a = -1/y0, b = x0/y0, e = dz/dx
1088 //
1089 // The Curvature is calculated by the following equation:
1090 // - curv = a/Sqrt(b^2 + 1) = 1/R
1091 // Parameters: - the 6 tracklets
1092 // - the Vertex constraint
1093 // Output: - the Chi2 value of the track
1094 //
1095 // debug level 5
1096 //
1097
1098 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1099 fitter->StoreData(kTRUE);
1100 fitter->ClearPoints();
4d6aee34 1101 AliTRDcluster *cl = NULL;
41702fec 1102
1103 Float_t x, y, z, w, t, error, tilt;
1104 Double_t uvt[2];
1105 Int_t nPoints = 0;
053767a4 1106 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1107 if(!tracklets[ilr].IsOK()) continue;
8d2bec9e 1108 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
053767a4 1109 if(!tracklets[ilr].IsUsable(itb)) continue;
1110 cl = tracklets[ilr].GetClusters(itb);
1742f24c 1111 if(!cl->IsInChamber()) continue;
41702fec 1112 x = cl->GetX();
1113 y = cl->GetY();
1114 z = cl->GetZ();
053767a4 1115 tilt = tracklets[ilr].GetTilt();
41702fec 1116 // Transformation
1117 t = 1./(x * x + y * y);
1118 uvt[0] = 2. * x * t;
1119 uvt[1] = 2. * x * t * tilt ;
1120 w = 2. * (y + tilt * (z - zVertex)) * t;
78b7d24c 1121 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
41702fec 1122 fitter->AddPoint(uvt, w, error);
1123 nPoints++;
1124 }
1125 }
e17f4785 1126 fitter->Eval();
41702fec 1127
1128 // Calculate curvature
1129 Double_t a = fitter->GetParameter(0);
1130 Double_t b = fitter->GetParameter(1);
1131 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1132
1133 Float_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1134 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
e3cf3d02 1135 tracklets[ip].SetC(curvature);
41702fec 1136
a2fbb6ec 1137/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
41702fec 1138 //Linear Model on z-direction
1139 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1140 Double_t slope = fitter->GetParameter(2);
1141 Double_t zref = slope * xref;
1142 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1143 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1144 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
4d6aee34 1145 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
41702fec 1146 treeStreamer << "FitTiltedRiemanConstraint"
1147 << "EventNumber=" << eventNumber
1148 << "CandidateNumber=" << candidateNumber
1149 << "Curvature=" << curvature
1150 << "Chi2Track=" << chi2track
1151 << "Chi2Z=" << chi2Z
1152 << "zref=" << zref
1153 << "\n";
3a039a31 1154 }*/
41702fec 1155 return chi2track;
eb38ed55 1156}
1157
1158//_________________________________________________________________________
1159Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1160{
41702fec 1161 //
1162 // Performs a Riemann fit taking tilting pad correction into account
1163 // The equation of a Riemann circle, where the y position is substituted by the
1164 // measured y-position taking pad tilting into account, has to be transformed
1165 // into a 4-dimensional hyperplane equation
1166 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1167 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1168 // zc: center of the pad row
1169 // zt: z-position of the track
1170 // The z-position of the track is assumed to be linear dependent on the x-position
1171 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1172 // Transformation: u = 2 * x * t
1173 // v = 2 * tan(phiT) * t
1174 // w = 2 * tan(phiT) * (x - xref) * t
1175 // t = 1 / (x^2 + ymeas^2)
1176 // Parameters: a = -1/y0
1177 // b = x0/y0
1178 // c = (R^2 -x0^2 - y0^2)/y0
1179 // d = offset
1180 // e = dz/dx
1181 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1182 // results from the simple riemann fit. Afterwards the fit is redone.
1183 // The curvature is calculated according to the formula:
1184 // curv = a/(1 + b^2 + c*a) = 1/R
1185 //
1186 // Paramters: - Array of tracklets (connected to the track candidate)
1187 // - Flag selecting the error definition
1188 // Output: - Chi2 values of the track (in Parameter list)
1189 //
1190 TLinearFitter *fitter = GetTiltedRiemanFitter();
1191 fitter->StoreData(kTRUE);
1192 fitter->ClearPoints();
1193 AliTRDLeastSquare zfitter;
4d6aee34 1194 AliTRDcluster *cl = NULL;
41702fec 1195
1196 Double_t xref = CalculateReferenceX(tracklets);
6e39bde4 1197 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1198 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1199 memset(sumPolY, 0, sizeof(Double_t) * 5);
1200 memset(sumPolZ, 0, sizeof(Double_t) * 3);
41702fec 1201 Int_t nPoints = 0;
1202 // Containers for Least-square fitter
1203 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1204 if(!tracklets[ipl].IsOK()) continue;
ed15ef4f 1205 tilt = tracklets[ipl].GetTilt();
8d2bec9e 1206 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1207 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1742f24c 1208 if(!cl->IsInChamber()) continue;
41702fec 1209 if (!tracklets[ipl].IsUsable(itb)) continue;
1210 x = cl->GetX();
1211 y = cl->GetY();
1212 z = cl->GetZ();
41702fec 1213 dx = x - xref;
1214 // Transformation
1215 t = 1./(x*x + y*y);
1216 uvt[0] = 2. * x * t;
1217 uvt[1] = t;
1218 uvt[2] = 2. * tilt * t;
1219 uvt[3] = 2. * tilt * dx * t;
1220 w = 2. * (y + tilt*z) * t;
1221 // error definition changes for the different calls
1222 we = 2. * t;
78b7d24c 1223 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
41702fec 1224 fitter->AddPoint(uvt, w, we);
1225 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
6e39bde4 1226 // adding points for covariance matrix estimation
1227 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1228 erry *= erry;
1229 errz = 1./cl->GetSigmaZ2();
1230 for(Int_t ipol = 0; ipol < 5; ipol++){
1231 sumPolY[ipol] += erry;
1232 erry *= x;
1233 if(ipol < 3){
1234 sumPolZ[ipol] += errz;
1235 errz *= x;
1236 }
1237 }
41702fec 1238 nPoints++;
1239 }
1240 }
e17f4785 1241 fitter->Eval();
41702fec 1242 zfitter.Eval();
1243
1244 Double_t offset = fitter->GetParameter(3);
1245 Double_t slope = fitter->GetParameter(4);
1246
1247 // Linear fitter - not possible to make boundaries
1248 // Do not accept non possible z and dzdx combinations
1249 Bool_t acceptablez = kTRUE;
1250 Double_t zref = 0.0;
1251 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1252 if(!tracklets[iLayer].IsOK()) continue;
1253 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1254 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
41702fec 1255 acceptablez = kFALSE;
1256 }
1257 if (!acceptablez) {
1258 Double_t dzmf = zfitter.GetFunctionParameter(1);
1259 Double_t zmf = zfitter.GetFunctionValue(&xref);
1260 fgTiltedRieman->FixParameter(3, zmf);
1261 fgTiltedRieman->FixParameter(4, dzmf);
e17f4785 1262 fitter->Eval();
41702fec 1263 fitter->ReleaseParameter(3);
1264 fitter->ReleaseParameter(4);
1265 offset = fitter->GetParameter(3);
1266 slope = fitter->GetParameter(4);
1267 }
1268
1269 // Calculate Curvarture
1270 Double_t a = fitter->GetParameter(0);
1271 Double_t b = fitter->GetParameter(1);
1272 Double_t c = fitter->GetParameter(2);
1273 Double_t curvature = 1.0 + b*b - c*a;
1274 if (curvature > 0.0)
1275 curvature = a / TMath::Sqrt(curvature);
1276
1277 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1278
6e39bde4 1279 // Prepare error calculation
1280 TMatrixD covarPolY(3,3);
1281 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1282 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1283 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1284 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1285 covarPolY.Invert();
1286 TMatrixD covarPolZ(2,2);
1287 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1288 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1289 covarPolZ.Invert();
1290
41702fec 1291 // Update the tracklets
6e39bde4 1292 Double_t x1, dy, dz;
1293 Double_t cov[15];
1294 memset(cov, 0, sizeof(Double_t) * 15);
41702fec 1295 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1296
1297 x = tracklets[iLayer].GetX0();
6e39bde4 1298 x1 = x - xref;
41702fec 1299 y = 0;
1300 z = 0;
1301 dy = 0;
1302 dz = 0;
6e39bde4 1303 memset(cov, 0, sizeof(Double_t) * 3);
1304 TMatrixD transform(3,3);
1305 transform(0,0) = 1;
1306 transform(0,1) = x;
1307 transform(0,2) = x*x;
1308 transform(1,1) = 1;
1309 transform(1,2) = x;
1310 transform(2,2) = 1;
1311 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1312 covariance *= transform.T();
1313 TMatrixD transformZ(2,2);
1314 transformZ(0,0) = transformZ(1,1) = 1;
1315 transformZ(0,1) = x;
1316 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1317 covarZ *= transformZ.T();
41702fec 1318 // y: R^2 = (x - x0)^2 + (y - y0)^2
1319 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1320 // R = Sqrt() = 1/Curvature
1321 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1322 Double_t res = (x * a + b); // = (x - x0)/y0
1323 res *= res;
1324 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1325 if (res >= 0) {
1326 res = TMath::Sqrt(res);
1327 y = (1.0 - res) / a;
1328 }
6e39bde4 1329 cov[0] = covariance(0,0);
1330 cov[2] = covarZ(0,0);
1331 cov[1] = 0.;
41702fec 1332
1333 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1334 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1335 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1336 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1337 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1338 Double_t x0 = -b / a;
1339 if (-c * a + b * b + 1 > 0) {
1340 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
6e39bde4 1341 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1342 if (a < 0) yderiv *= -1.0;
1343 dy = yderiv;
41702fec 1344 }
1345 }
1346 z = offset + slope * (x - xref);
1347 dz = slope;
1348 tracklets[iLayer].SetYref(0, y);
1349 tracklets[iLayer].SetYref(1, dy);
1350 tracklets[iLayer].SetZref(0, z);
1351 tracklets[iLayer].SetZref(1, dz);
1352 tracklets[iLayer].SetC(curvature);
6e39bde4 1353 tracklets[iLayer].SetCovRef(cov);
41702fec 1354 tracklets[iLayer].SetChi2(chi2track);
1355 }
1356
a2fbb6ec 1357/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1358 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 1359 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1360 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1361 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1362 cstreamer << "FitTiltedRieman0"
1363 << "EventNumber=" << eventNumber
1364 << "CandidateNumber=" << candidateNumber
1365 << "xref=" << xref
1366 << "Chi2Z=" << chi2z
1367 << "\n";
3a039a31 1368 }*/
41702fec 1369 return chi2track;
eb38ed55 1370}
1371
3b57a3f7 1372
9e333711 1373//____________________________________________________________________
6e4d4425 1374Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
9e333711 1375{
4d6aee34 1376 //
1377 // Fit track with a staight line
1378 // Fills an AliTrackPoint array with np points
1379 // Function should be used to refit tracks when no magnetic field was on
1380 //
9e333711 1381 AliTRDLeastSquare yfitter, zfitter;
4d6aee34 1382 AliTRDcluster *cl = NULL;
9e333711 1383
4d6aee34 1384 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
9e333711 1385 if(!tracklets){
1386 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1387 if(!(tracklet = track->GetTracklet(ipl))) continue;
1388 if(!tracklet->IsOK()) continue;
1389 new(&work[ipl]) AliTRDseedV1(*tracklet);
1390 }
1391 tracklets = &work[0];
1392 }
1393
1394 Double_t xref = CalculateReferenceX(tracklets);
1395 Double_t x, y, z, dx, ye, yr, tilt;
1396 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1397 if(!tracklets[ipl].IsOK()) continue;
1398 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1399 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1400 if (!tracklets[ipl].IsUsable(itb)) continue;
1401 x = cl->GetX();
1402 z = cl->GetZ();
1403 dx = x - xref;
1404 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1405 }
1406 }
1407 zfitter.Eval();
1408 Double_t z0 = zfitter.GetFunctionParameter(0);
1409 Double_t dzdx = zfitter.GetFunctionParameter(1);
1410 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1411 if(!tracklets[ipl].IsOK()) continue;
1412 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1413 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1414 if (!tracklets[ipl].IsUsable(itb)) continue;
1415 x = cl->GetX();
1416 y = cl->GetY();
1417 z = cl->GetZ();
1418 tilt = tracklets[ipl].GetTilt();
1419 dx = x - xref;
1420 yr = y + tilt*(z - z0 - dzdx*dx);
1421 // error definition changes for the different calls
1422 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1423 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1424 yfitter.AddPoint(&dx, yr, ye);
1425 }
1426 }
1427 yfitter.Eval();
1428 Double_t y0 = yfitter.GetFunctionParameter(0);
1429 Double_t dydx = yfitter.GetFunctionParameter(1);
1430 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1431
1432 //update track points array
1433 if(np && points){
1434 Float_t xyz[3];
1435 for(int ip=0; ip<np; ip++){
1436 points[ip].GetXYZ(xyz);
1437 xyz[1] = y0 + dydx * (xyz[0] - xref);
1438 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1439 points[ip].SetXYZ(xyz);
1440 }
1441 }
1442 return chi2;
1443}
1444
1445
3b57a3f7 1446//_________________________________________________________________________
6e4d4425 1447Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
3b57a3f7 1448{
0fa1a8ee 1449//
1450// Performs a Riemann fit taking tilting pad correction into account
1451//
1452// Paramters: - Array of tracklets (connected to the track candidate)
1453// - Flag selecting the error definition
1454// Output: - Chi2 values of the track (in Parameter list)
1455//
1456// The equations which has to be solved simultaneously are:
1457// BEGIN_LATEX
1458// R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1459// y^{*} = y - tg(h)(z - z_{t})
1460// z_{t} = z_{0}+dzdx*(x-x_{r})
1461// END_LATEX
1462// with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1463// R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1464// track in the x-z plane. Using the following transformations
1465// BEGIN_LATEX
1466// t = 1 / (x^{2} + y^{2})
1467// u = 2 * x * t
1468// v = 2 * tan(h) * t
1469// w = 2 * tan(h) * (x - x_{r}) * t
1470// END_LATEX
1471// One gets the following linear equation
1472// BEGIN_LATEX
1473// a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1474// END_LATEX
1475// where the coefficients have the following meaning
1476// BEGIN_LATEX
1477// a = -1/y_{0}
1478// b = x_{0}/y_{0}
1479// c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1480// d = z_{0}
1481// e = dz/dx
1482// END_LATEX
1483// The error calculation for the free term is thus
1484// BEGIN_LATEX
1485// #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1486// END_LATEX
1487//
1488// From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1489// to the formula:
1490// BEGIN_LATEX
1491// C = 1/R = a/(1 + b^{2} + c*a)
1492// END_LATEX
1493//
1494// Authors
1495// M.Ivanov <M.Ivanov@gsi.de>
1496// A.Bercuci <A.Bercuci@gsi.de>
1497// M.Fasel <M.Fasel@gsi.de>
1498
41702fec 1499 TLinearFitter *fitter = GetTiltedRiemanFitter();
1500 fitter->StoreData(kTRUE);
1501 fitter->ClearPoints();
1502 AliTRDLeastSquare zfitter;
4d6aee34 1503 AliTRDcluster *cl = NULL;
3b57a3f7 1504
4d6aee34 1505 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
3b57a3f7 1506 if(!tracklets){
1507 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1508 if(!(tracklet = track->GetTracklet(ipl))) continue;
1509 if(!tracklet->IsOK()) continue;
1510 new(&work[ipl]) AliTRDseedV1(*tracklet);
1511 }
1512 tracklets = &work[0];
1513 }
1514
41702fec 1515 Double_t xref = CalculateReferenceX(tracklets);
352cef8f 1516 AliDebugGeneral("AliTRDtrackerV1::FitRiemanTilt()", 4,
1517 Form("\nx0[(0)%6.2f (1)%6.2f (2)%6.2f (3)%6.2f (4)%6.2f (5)%6.2f] xref[%6.2f]", tracklets[0].GetX0(), tracklets[1].GetX0(), tracklets[2].GetX0(), tracklets[3].GetX0(), tracklets[4].GetX0(), tracklets[5].GetX0(), xref));
41702fec 1518 Double_t x, y, z, t, tilt, dx, w, we;
1519 Double_t uvt[4];
1520 Int_t nPoints = 0;
1521 // Containers for Least-square fitter
1522 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1523 if(!tracklets[ipl].IsOK()) continue;
8d2bec9e 1524 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1525 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
352cef8f 1526 //if (!tracklets[ipl].IsUsable(itb)) continue;
41702fec 1527 x = cl->GetX();
1528 y = cl->GetY();
1529 z = cl->GetZ();
1530 tilt = tracklets[ipl].GetTilt();
1531 dx = x - xref;
1532 // Transformation
1533 t = 1./(x*x + y*y);
1534 uvt[0] = 2. * x * t;
1535 uvt[1] = t;
1536 uvt[2] = 2. * tilt * t;
1537 uvt[3] = 2. * tilt * dx * t;
1538 w = 2. * (y + tilt*z) * t;
1539 // error definition changes for the different calls
1540 we = 2. * t;
f29f13a6 1541 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
41702fec 1542 fitter->AddPoint(uvt, w, we);
1543 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1544 nPoints++;
1545 }
1546 }
aec26713 1547 if(fitter->Eval()) return 1.E10;
1548
41702fec 1549 Double_t z0 = fitter->GetParameter(3);
1550 Double_t dzdx = fitter->GetParameter(4);
3b57a3f7 1551
1552
1553 // Linear fitter - not possible to make boundaries
1554 // Do not accept non possible z and dzdx combinations
1555 Bool_t accept = kTRUE;
1556 Double_t zref = 0.0;
1557 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1558 if(!tracklets[iLayer].IsOK()) continue;
1559 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1560 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
3b57a3f7 1561 accept = kFALSE;
1562 }
1563 if (!accept) {
41702fec 1564 zfitter.Eval();
3b57a3f7 1565 Double_t dzmf = zfitter.GetFunctionParameter(1);
1566 Double_t zmf = zfitter.GetFunctionValue(&xref);
1567 fitter->FixParameter(3, zmf);
1568 fitter->FixParameter(4, dzmf);
e17f4785 1569 fitter->Eval();
3b57a3f7 1570 fitter->ReleaseParameter(3);
1571 fitter->ReleaseParameter(4);
1572 z0 = fitter->GetParameter(3); // = zmf ?
1573 dzdx = fitter->GetParameter(4); // = dzmf ?
1574 }
1575
1576 // Calculate Curvature
1577 Double_t a = fitter->GetParameter(0);
1578 Double_t b = fitter->GetParameter(1);
1579 Double_t c = fitter->GetParameter(2);
1580 Double_t y0 = 1. / a;
1581 Double_t x0 = -b * y0;
a015e406 1582 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1583 if(tmp<=0.) return 1.E10;
4d6aee34 1584 Double_t radius = TMath::Sqrt(tmp);
1585 Double_t curvature = 1.0 + b*b - c*a;
1586 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
3b57a3f7 1587
1588 // Calculate chi2 of the fit
1589 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
352cef8f 1590 AliDebugGeneral("AliTRDtrackerV1::FitRiemanTilt()", 4,
1591 Form("x0[%6.2f] y0[%6.2f] R[%6.2f] chi2[%f]\n", x0, y0, radius, chi2));
3b57a3f7 1592
1593 // Update the tracklets
1594 if(!track){
1595 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1596 x = tracklets[ip].GetX0();
4d6aee34 1597 tmp = radius*radius-(x-x0)*(x-x0);
a015e406 1598 if(tmp <= 0.) continue;
1599 tmp = TMath::Sqrt(tmp);
3b57a3f7 1600
1601 // y: R^2 = (x - x0)^2 + (y - y0)^2
1602 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1603 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1604 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1605 tracklets[ip].SetYref(1, (x - x0) / tmp);
1606 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1607 tracklets[ip].SetZref(1, dzdx);
4d6aee34 1608 tracklets[ip].SetC(curvature);
3b57a3f7 1609 tracklets[ip].SetChi2(chi2);
1610 }
1611 }
3b57a3f7 1612 //update track points array
1613 if(np && points){
1614 Float_t xyz[3];
1615 for(int ip=0; ip<np; ip++){
1616 points[ip].GetXYZ(xyz);
4d6aee34 1617 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 1618 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1619 points[ip].SetXYZ(xyz);
1620 }
1621 }
1622
3b57a3f7 1623 return chi2;
1624}
1625
1626
1bf51039 1627//____________________________________________________________________
e17f4785 1628Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1bf51039 1629{
1630// Kalman filter implementation for the TRD.
1631// It returns the positions of the fit in the array "points"
1632//
1633// Author : A.Bercuci@gsi.de
1634
3cfaffa4 1635 // printf("Start track @ x[%f]\n", track->GetX());
1bf51039 1636
1637 //prepare marker points along the track
1638 Int_t ip = np ? 0 : 1;
1639 while(ip<np){
1640 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1641 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1642 ip++;
1643 }
1644 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1645
1646
4d6aee34 1647 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
1bf51039 1648
1649 //Loop through the TRD planes
1650 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1651 // GET TRACKLET OR BUILT IT
1652 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1653 if(tracklets){
e17f4785 1654 if(!(ptrTracklet = &tracklets[iplane])) continue;
1bf51039 1655 }else{
1656 if(!(ptrTracklet = track->GetTracklet(iplane))){
4d6aee34 1657 /*AliTRDtrackerV1 *tracker = NULL;
a2fbb6ec 1658 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1bf51039 1659 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1660 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1661 continue;
1662 }
1663 }
1664 if(!ptrTracklet->IsOK()) continue;
1665
1666 Double_t x = ptrTracklet->GetX0();
1667
1668 while(ip < np){
1669 //don't do anything if next marker is after next update point.
1670 if((up?-1:1) * (points[ip].GetX() - x) - fgkMaxStep < 0) break;
1bf51039 1671 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1672
1673 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1674 track->GetXYZ(xyz);
1675 track->Global2LocalPosition(xyz, track->GetAlpha());
1676 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1677 ip++;
1678 }
3cfaffa4 1679 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1bf51039 1680
3cfaffa4 1681 // Propagate closer to the next update point
1bf51039 1682 if(((up?-1:1) * (x - track->GetX()) + fgkMaxStep < 0) && !PropagateToX(*track, x + (up?-1:1)*fgkMaxStep, fgkMaxStep)) return -1.;
1683
1684 if(!AdjustSector(track)) return -1;
1685 if(TMath::Abs(track->GetSnp()) > fgkMaxSnp) return -1;
1686
1687 //load tracklet to the tracker and the track
1688/* Int_t index;
1689 if((index = FindTracklet(ptrTracklet)) < 0){
1690 ptrTracklet = SetTracklet(&tracklet);
1691 index = fTracklets->GetEntriesFast()-1;
1692 }
1693 track->SetTracklet(ptrTracklet, index);*/
1694
1695
1696 // register tracklet to track with tracklet creation !!
1697 // PropagateBack : loaded tracklet to the tracker and update index
1698 // RefitInward : update index
1699 // MakeTrack : loaded tracklet to the tracker and update index
1700 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1701
1702
1703 //Calculate the mean material budget along the path inside the chamber
1704 Double_t xyz0[3]; track->GetXYZ(xyz0);
1705 Double_t alpha = track->GetAlpha();
1706 Double_t xyz1[3], y, z;
1707 if(!track->GetProlongation(x, y, z)) return -1;
1708 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1709 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1710 xyz1[2] = z;
fbe11be7 1711 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 1712 Double_t param[7];
3cfaffa4 1713 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1bf51039 1714 Double_t xrho = param[0]*param[4]; // density*length
1715 Double_t xx0 = param[1]; // radiation length
1716
1717 //Propagate the track
1718 track->PropagateTo(x, xx0, xrho);
1719 if (!AdjustSector(track)) break;
1720
1721 //Update track
b72f4eaf 1722 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1723 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1724 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
1725 if(chi2<1e+10) track->Update(p, cov, chi2);
1bf51039 1726 if(!up) continue;
1727
1728 //Reset material budget if 2 consecutive gold
1729 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1730 } // end planes loop
1731
1732 // extrapolation
1733 while(ip < np){
1734 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1735
1736 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1737 track->GetXYZ(xyz);
1738 track->Global2LocalPosition(xyz, track->GetAlpha());
1739 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1740 ip++;
1741 }
1742
1743 return track->GetChi2();
1744}
3b57a3f7 1745
eb38ed55 1746//_________________________________________________________________________
bb56afff 1747Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
eb38ed55 1748{
41702fec 1749 //
1750 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1751 // A linear dependence on the x-value serves as a model.
1752 // The parameters are related to the tilted Riemann fit.
1753 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1754 // - the offset for the reference x
1755 // - the slope
1756 // - the reference x position
1757 // Output: - The Chi2 value of the track in z-Direction
1758 //
1759 Float_t chi2Z = 0, nLayers = 0;
053767a4 1760 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
41702fec 1761 if(!tracklets[iLayer].IsOK()) continue;
1762 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1763 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
41702fec 1764 nLayers++;
1765 }
1766 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1767 return chi2Z;
eb38ed55 1768}
1769
bccda319 1770//_____________________________________________________________________________
1771Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1772{
41702fec 1773 //
1774 // Starting from current X-position of track <t> this function
1775 // extrapolates the track up to radial position <xToGo>.
1776 // Returns 1 if track reaches the plane, and 0 otherwise
1777 //
bccda319 1778
41702fec 1779 const Double_t kEpsilon = 0.00001;
bccda319 1780
41702fec 1781 // Current track X-position
1782 Double_t xpos = t.GetX();
bccda319 1783
41702fec 1784 // Direction: inward or outward
1785 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
bccda319 1786
41702fec 1787 while (((xToGo - xpos) * dir) > kEpsilon) {
bccda319 1788
41702fec 1789 Double_t xyz0[3];
1790 Double_t xyz1[3];
1791 Double_t param[7];
1792 Double_t x;
1793 Double_t y;
1794 Double_t z;
bccda319 1795
41702fec 1796 // The next step size
1797 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
bccda319 1798
41702fec 1799 // Get the global position of the starting point
1800 t.GetXYZ(xyz0);
bccda319 1801
41702fec 1802 // X-position after next step
1803 x = xpos + step;
bccda319 1804
41702fec 1805 // Get local Y and Z at the X-position of the next step
3352b455 1806 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
bccda319 1807
41702fec 1808 // The global position of the end point of this prolongation step
1809 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1810 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1811 xyz1[2] = z;
bccda319 1812
41702fec 1813 // Calculate the mean material budget between start and
1814 // end point of this prolongation step
83dea92e 1815 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
bccda319 1816
41702fec 1817 // Propagate the track to the X-position after the next step
9c87a076 1818 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
bccda319 1819
41702fec 1820 // Rotate the track if necessary
1821 AdjustSector(&t);
bccda319 1822
41702fec 1823 // New track X-position
1824 xpos = t.GetX();
bccda319 1825
41702fec 1826 }
bccda319 1827
41702fec 1828 return 1;
bccda319 1829
1830}
1831
eb38ed55 1832
1833//_____________________________________________________________________________
1834Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) const
1835{
41702fec 1836 //
1837 // Reads AliTRDclusters from the file.
1838 // The names of the cluster tree and branches
1839 // should match the ones used in AliTRDclusterizer::WriteClusters()
1840 //
1841
1842 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1843 TObjArray *clusterArray = new TObjArray(nsize+1000);
1844
1845 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1846 if (!branch) {
1847 AliError("Can't get the branch !");
1848 return 1;
1849 }
1850 branch->SetAddress(&clusterArray);
1851
1852 if(!fClusters){
9e85cb05 1853 Float_t nclusters = fkRecoParam->GetNClusters();
4d6aee34 1854 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
8ae98148 1855 array = new TClonesArray("AliTRDcluster", Int_t(nclusters));
41702fec 1856 array->SetOwner(kTRUE);
1857 }
1858
1859 // Loop through all entries in the tree
1860 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1861 Int_t nbytes = 0;
1862 Int_t ncl = 0;
4d6aee34 1863 AliTRDcluster *c = NULL;
41702fec 1864 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1865 // Import the tree
1866 nbytes += clusterTree->GetEvent(iEntry);
1867
1868 // Get the number of points in the detector
1869 Int_t nCluster = clusterArray->GetEntriesFast();
1870 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1871 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
41702fec 1872 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1873 delete (clusterArray->RemoveAt(iCluster));
1874 }
1875
1876 }
1877 delete clusterArray;
1878
1879 return 0;
eb38ed55 1880}
1881
1882//_____________________________________________________________________________
1883Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1884{
41702fec 1885 //
66f6bfd9 1886 // Fills clusters into TRD tracking sectors
41702fec 1887 //
41702fec 1888
9e85cb05 1889 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
1890
4d6aee34 1891 if(!fkReconstructor->IsWritingClusters()){
48f8adf3 1892 fClusters = AliTRDReconstructor::GetClusters();
1893 } else {
66f6bfd9 1894 if (ReadClusters(fClusters, cTree)) {
1895 AliError("Problem with reading the clusters !");
1896 return 1;
1897 }
1898 }
1899 SetClustersOwner();
1900
48f8adf3 1901 if(!fClusters || !fClusters->GetEntriesFast()){
66f6bfd9 1902 AliInfo("No TRD clusters");
41702fec 1903 return 1;
1904 }
66f6bfd9 1905
1906 //Int_t nin =
1907 BuildTrackingContainers();
1908
1909 //Int_t ncl = fClusters->GetEntriesFast();
1910 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1911
1912 return 0;
1913}
1914
1915//_____________________________________________________________________________
4d6aee34 1916Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
66f6bfd9 1917{
1918 //
1919 // Fills clusters into TRD tracking sectors
1920 // Function for use in the HLT
1921
1922 if(!clusters || !clusters->GetEntriesFast()){
1923 AliInfo("No TRD clusters");
41702fec 1924 return 1;
1925 }
1926
66f6bfd9 1927 fClusters = clusters;
1928 SetClustersOwner();
1929
9e85cb05 1930 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
66f6bfd9 1931 BuildTrackingContainers();
1932
1933 //Int_t ncl = fClusters->GetEntriesFast();
1934 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1935
1936 return 0;
1937}
1938
1939
1940//____________________________________________________________________
1941Int_t AliTRDtrackerV1::BuildTrackingContainers()
1942{
1943// Building tracking containers for clusters
1944
1945 Int_t nin =0, icl = fClusters->GetEntriesFast();
41702fec 1946 while (icl--) {
1947 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
1948 if(c->IsInChamber()) nin++;
4226b195 1949 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
41702fec 1950 Int_t detector = c->GetDetector();
1951 Int_t sector = fGeom->GetSector(detector);
053767a4 1952 Int_t stack = fGeom->GetStack(detector);
1953 Int_t layer = fGeom->GetLayer(detector);
41702fec 1954
053767a4 1955 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, icl);
41702fec 1956 }
b0a48c4d 1957
1958 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
053767a4 1959 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
41702fec 1960 if(!fTrSec[isector].GetNChambers()) continue;
4d6aee34 1961 fTrSec[isector].Init(fkReconstructor, cal);
41702fec 1962 }
66f6bfd9 1963
1964 return nin;
eb38ed55 1965}
1966
1967
66f6bfd9 1968
0906e73e 1969//____________________________________________________________________
172b6f82 1970void AliTRDtrackerV1::UnloadClusters()
0906e73e 1971{
d4cf71ca 1972//
1973// Clears the arrays of clusters and tracks. Resets sectors and timebins
1974// If option "force" is also set the containers are also deleted. This is useful
1975// in case of HLT
1976
1977 if(fTracks){
1978 fTracks->Delete();
4d6aee34 1979 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
d4cf71ca 1980 }
1981 if(fTracklets){
1982 fTracklets->Delete();
4d6aee34 1983 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
d4cf71ca 1984 }
48f8adf3 1985 if(fClusters){
1986 if(IsClustersOwner()) fClusters->Delete();
1987
1988 // save clusters array in the reconstructor for further use.
4d6aee34 1989 if(!fkReconstructor->IsWritingClusters()){
48f8adf3 1990 AliTRDReconstructor::SetClusters(fClusters);
1991 SetClustersOwner(kFALSE);
4d6aee34 1992 } else AliTRDReconstructor::SetClusters(NULL);
48f8adf3 1993 }
0906e73e 1994
053767a4 1995 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
0906e73e 1996
41702fec 1997 // Increment the Event Number
1998 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
eb38ed55 1999}
0906e73e 2000
fac58f00 2001// //____________________________________________________________________
2002// void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2003// {
2004// const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2005// if(!track) return;
2006//
4d6aee34 2007// AliTRDseedV1 *tracklet = NULL;
fac58f00 2008// for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2009// if(!(tracklet = track->GetTracklet(ily))) continue;
4d6aee34 2010// AliTRDcluster *c = NULL;
8d2bec9e 2011// for(Int_t ic=AliTRDseed::kNclusters; ic--;){
fac58f00 2012// if(!(c=tracklet->GetClusters(ic))) continue;
2013// c->Use();
2014// }
2015// }
2016// }
2017//
b1957d3c 2018
eb38ed55 2019//_____________________________________________________________________________
4d6aee34 2020Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
eb38ed55 2021{
41702fec 2022 //
2023 // Rotates the track when necessary
2024 //
2025
2026 Double_t alpha = AliTRDgeometry::GetAlpha();
2027 Double_t y = track->GetY();
2028 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
3cfaffa4 2029
41702fec 2030 if (y > ymax) {
2031 if (!track->Rotate( alpha)) {
2032 return kFALSE;
2033 }
2034 }
2035 else if (y < -ymax) {
2036 if (!track->Rotate(-alpha)) {
2037 return kFALSE;
2038 }
2039 }
2040
2041 return kTRUE;
0906e73e 2042
2043}
2044
eb38ed55 2045
0906e73e 2046//____________________________________________________________________
4d6aee34 2047AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
0906e73e 2048{
41702fec 2049 // Find tracklet for TRD track <track>
2050 // Parameters
2051 // - track
2052 // - sector
2053 // - plane
2054 // - index
2055 // Output
2056 // tracklet
2057 // index
2058 // Detailed description
2059 //
2060 idx = track->GetTrackletIndex(p);
17896e82 2061 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
41702fec 2062
2063 return tracklet;
0906e73e 2064}
2065
2066//____________________________________________________________________
4d6aee34 2067AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
0906e73e 2068{
41702fec 2069 // Add this tracklet to the list of tracklets stored in the tracker
2070 //
2071 // Parameters
2072 // - tracklet : pointer to the tracklet to be added to the list
2073 //
2074 // Output
2075 // - the index of the new tracklet in the tracker tracklets list
2076 //
2077 // Detailed description
2078 // Build the tracklets list if it is not yet created (late initialization)
2079 // and adds the new tracklet to the list.
2080 //
2081 if(!fTracklets){
053767a4 2082 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
41702fec 2083 fTracklets->SetOwner(kTRUE);
2084 }
2085 Int_t nentries = fTracklets->GetEntriesFast();
2086 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
972ef65e 2087}
2088
d20df6fc 2089//____________________________________________________________________
4d6aee34 2090AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
d20df6fc 2091{
2092 // Add this track to the list of tracks stored in the tracker
2093 //
2094 // Parameters
2095 // - track : pointer to the track to be added to the list
2096 //
2097 // Output
2098 // - the pointer added
2099 //
2100 // Detailed description
2101 // Build the tracks list if it is not yet created (late initialization)
2102 // and adds the new track to the list.
2103 //
2104 if(!fTracks){
053767a4 2105 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
d20df6fc 2106 fTracks->SetOwner(kTRUE);
2107 }
2108 Int_t nentries = fTracks->GetEntriesFast();
2109 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2110}
2111
2112
0906e73e 2113
e4f2f73d 2114//____________________________________________________________________
eb38ed55 2115Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
e4f2f73d 2116{
41702fec 2117 //
2118 // Steer tracking for one SM.
2119 //
2120 // Parameters :
2121 // sector : Array of (SM) propagation layers containing clusters
2122 // esd : The current ESD event. On output it contains the also
2123 // the ESD (TRD) tracks found in this SM.
2124 //
2125 // Output :
2126 // Number of tracks found in this TRD supermodule.
2127 //
2128 // Detailed description
2129 //
2130 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2131 // 2. Launch stack tracking.
2132 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2133 // 3. Pack results in the ESD event.
2134 //
2135
41702fec 2136 Int_t nTracks = 0;
2137 Int_t nChambers = 0;
4d6aee34 2138 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
053767a4 2139 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
41702fec 2140 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2141 nChambers = 0;
053767a4 2142 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2143 if(!(chamber = stack[ilayer])) continue;
9e85cb05 2144 if(chamber->GetNClusters() < fgNTimeBins * fkRecoParam->GetFindableClusters()) continue;
41702fec 2145 nChambers++;
053767a4 2146 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
41702fec 2147 }
2148 if(nChambers < 4) continue;
2149 //AliInfo(Form("Doing stack %d", istack));
b1135f96 2150 nTracks += Clusters2TracksStack(stack, fTracksESD);
41702fec 2151 }
050875b0 2152 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2153
352cef8f 2154 for(int itrack=0; itrack<nTracks; itrack++){
2155 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2156 Int_t id = esd->AddTrack(esdTrack);
2157
2158 // set ESD id to stand alone TRD tracks
9e85cb05 2159 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
352cef8f 2160 esdTrack=esd->GetTrack(id);
2161 TObject *o(NULL); Int_t ic(0);
2162 AliTRDtrackV1 *calibTrack(NULL);
2163 while((o = esdTrack->GetCalibObject(ic++))){
2164 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2165 calibTrack->SetESDid(esdTrack->GetID());
2166 break;
2167 }
2168 }
2169 }
41702fec 2170
2171 // Reset Track and Candidate Number
2172 AliTRDtrackerDebug::SetCandidateNumber(0);
2173 AliTRDtrackerDebug::SetTrackNumber(0);
b1135f96 2174
2175 // delete ESD tracks in the array
2176 fTracksESD->Delete();
41702fec 2177 return nTracks;
e4f2f73d 2178}
2179
2180//____________________________________________________________________
4d6aee34 2181Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
e4f2f73d 2182{
41702fec 2183 //
2184 // Make tracks in one TRD stack.
2185 //
2186 // Parameters :
2187 // layer : Array of stack propagation layers containing clusters
2188 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2189 // On exit the tracks found in this stack are appended.
2190 //
2191 // Output :
2192 // Number of tracks found in this stack.
2193 //
2194 // Detailed description
2195 //
2196 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2197 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2198 // See AliTRDtrackerV1::MakeSeeds() for more details.
2199 // 3. Arrange track candidates in decreasing order of their quality
2200 // 4. Classify tracks in 5 categories according to:
2201 // a) number of layers crossed
2202 // b) track quality
2203 // 5. Sign clusters by tracks in decreasing order of track quality
2204 // 6. Build AliTRDtrack out of seeding tracklets
2205 // 7. Cook MC label
2206 // 8. Build ESD track and register it to the output list
2207 //
2208
b0a48c4d 2209 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
4d6aee34 2210 AliTRDtrackingChamber *chamber = NULL;
2211 AliTRDtrackingChamber **ci = NULL;
41702fec 2212 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2213 Int_t pars[4]; // MakeSeeds parameters
2214
2215 //Double_t alpha = AliTRDgeometry::GetAlpha();
2216 //Double_t shift = .5 * alpha;
2217 Int_t configs[kNConfigs];
2218
fac58f00 2219 // Purge used clusters from the containers
2220 ci = &stack[0];
2221 for(Int_t ic = kNPlanes; ic--; ci++){
2222 if(!(*ci)) continue;
2223 (*ci)->Update();
2224 }
2225
41702fec 2226 // Build initial seeding configurations
2227 Double_t quality = BuildSeedingConfigs(stack, configs);
9e85cb05 2228 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
41702fec 2229 AliInfo(Form("Plane config %d %d %d Quality %f"
2230 , configs[0], configs[1], configs[2], quality));
2231 }
d931f2aa 2232
41702fec 2233
2234 // Initialize contors
2235 Int_t ntracks, // number of TRD track candidates
2236 ntracks1, // number of registered TRD tracks/iter
2237 ntracks2 = 0; // number of all registered TRD tracks in stack
2238 fSieveSeeding = 0;
d931f2aa 2239
2240 // Get stack index
fac58f00 2241 Int_t ic = 0; ci = &stack[0];
2242 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2243 if(!(*ci)) return ntracks2;
2244 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
d931f2aa 2245
41702fec 2246 do{
2247 // Loop over seeding configurations
2248 ntracks = 0; ntracks1 = 0;
2249 for (Int_t iconf = 0; iconf<3; iconf++) {
2250 pars[0] = configs[iconf];
2251 pars[1] = ntracks;
d931f2aa 2252 pars[2] = istack;
41702fec 2253 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
6e39bde4 2254 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
41702fec 2255 if(ntracks == kMaxTracksStack) break;
2256 }
980d5a2a 2257 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
41702fec 2258
2259 if(!ntracks) break;
2260
2261 // Sort the seeds according to their quality
2262 Int_t sort[kMaxTracksStack];
2263 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
2264
2265 // Initialize number of tracks so far and logic switches
2266 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2267 Bool_t signedTrack[kMaxTracksStack];
2268 Bool_t fakeTrack[kMaxTracksStack];
2269 for (Int_t i=0; i<ntracks; i++){
2270 signedTrack[i] = kFALSE;
2271 fakeTrack[i] = kFALSE;
2272 }
2273 //AliInfo("Selecting track candidates ...");
2274
2275 // Sieve clusters in decreasing order of track quality
2276 Double_t trackParams[7];
4d6aee34 2277 // AliTRDseedV1 *lseed = NULL;
41702fec 2278 Int_t jSieve = 0, candidates;
2279 do{
2280 //AliInfo(Form("\t\tITER = %i ", jSieve));
2281
2282 // Check track candidates
2283 candidates = 0;
2284 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
804bb02e 2285 Int_t trackIndex = sort[itrack];
2286 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
41702fec 2287
2288
804bb02e 2289 // Calculate track parameters from tracklets seeds
804bb02e 2290 Int_t ncl = 0;
2291 Int_t nused = 0;
2292 Int_t nlayers = 0;
2293 Int_t findable = 0;
2294 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2295 Int_t jseed = kNPlanes*trackIndex+jLayer;
2296 if(!sseed[jseed].IsOK()) continue;
f29f13a6 2297 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
eede7907 2298 // TODO here we get a sig fault which should never happen !
804bb02e 2299 sseed[jseed].UpdateUsed();
2300 ncl += sseed[jseed].GetN2();
2301 nused += sseed[jseed].GetNUsed();
2302 nlayers++;
804bb02e 2303 }
2304
f29f13a6 2305 // Filter duplicated tracks
2306 if (nused > 30){
2307 //printf("Skip %d nused %d\n", trackIndex, nused);
2308 fakeTrack[trackIndex] = kTRUE;
2309 continue;
2310 }
5ef88e00 2311 if (ncl>0 && Float_t(nused)/ncl >= .25){
f29f13a6 2312 //printf("Skip %d nused/ncl >= .25\n", trackIndex);
2313 fakeTrack[trackIndex] = kTRUE;
2314 continue;
2315 }
41702fec 2316
f29f13a6 2317 // Classify tracks
2318 Bool_t skip = kFALSE;
2319 switch(jSieve){
2320 case 0:
2321 if(nlayers < 6) {skip = kTRUE; break;}
2322 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2323 break;
2324
2325 case 1:
2326 if(nlayers < findable){skip = kTRUE; break;}
2327 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2328 break;
2329
2330 case 2:
2331 if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
2332 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2333 break;
2334
2335 case 3:
2336 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2337 break;
2338
2339 case 4:
2340 if (nlayers == 3){skip = kTRUE; break;}
2341 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2342 break;
2343 }
2344 if(skip){
2345 candidates++;
5ef88e00 2346 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
f29f13a6 2347 continue;
5ef88e00 2348 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2349
f29f13a6 2350 signedTrack[trackIndex] = kTRUE;
2351
2352 // Build track parameters
2353 AliTRDseedV1 *lseed =&sseed[trackIndex*6];
2354 /* Int_t idx = 0;
2355 while(idx<3 && !lseed->IsOK()) {
2356 idx++;
2357 lseed++;
2358 }*/
2359 Double_t x = lseed->GetX0();// - 3.5;
2360 trackParams[0] = x; //NEW AB
2361 trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);
2362 trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x);
2363 trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
2364 trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
2365 trackParams[5] = lseed->GetC();
2366 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2367 trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift; // Supermodule*/
2368
9e85cb05 2369 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
eb2b4f91 2370 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
f29f13a6 2371
f29f13a6 2372 AliTRDseedV1 *dseed[6];
b82b4de1 2373 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
f29f13a6 2374
2375 //Int_t eventNrInFile = esd->GetEventNumberInFile();
f29f13a6 2376 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2377 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2378 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
a2fbb6ec 2379 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
f29f13a6 2380 cstreamer << "Clusters2TracksStack"
2381 << "EventNumber=" << eventNumber
2382 << "TrackNumber=" << trackNumber
2383 << "CandidateNumber=" << candidateNumber
2384 << "Iter=" << fSieveSeeding
2385 << "Like=" << fTrackQuality[trackIndex]
2386 << "S0.=" << dseed[0]
2387 << "S1.=" << dseed[1]
2388 << "S2.=" << dseed[2]
2389 << "S3.=" << dseed[3]
2390 << "S4.=" << dseed[4]
2391 << "S5.=" << dseed[5]
2392 << "p0=" << trackParams[0]
2393 << "p1=" << trackParams[1]
2394 << "p2=" << trackParams[2]
2395 << "p3=" << trackParams[3]
2396 << "p4=" << trackParams[4]
2397 << "p5=" << trackParams[5]
2398 << "p6=" << trackParams[6]
f29f13a6 2399 << "Ncl=" << ncl
2400 << "NLayers=" << nlayers
2401 << "Findable=" << findable
2402 << "NUsed=" << nused
2403 << "\n";
2404 }
d877f55f 2405
f29f13a6 2406 AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
2407 if(!track){
980d5a2a 2408 AliDebug(1, "Track building failed.");
f29f13a6 2409 continue;
d877f55f 2410 }
41702fec 2411
f29f13a6 2412 //AliInfo("End of MakeTrack()");
2413 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2414 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2415 esdTrack->SetLabel(track->GetLabel());
2416 track->UpdateESDtrack(esdTrack);
2417 // write ESD-friends if neccessary
9e85cb05 2418 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
f29f13a6 2419 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2420 calibTrack->SetOwner();
2421 esdTrack->AddCalibObject(calibTrack);
2422 }
2423 ntracks1++;
2424 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
41702fec 2425 }
2426
2427 jSieve++;
2428 } while(jSieve<5 && candidates); // end track candidates sieve
2429 if(!ntracks1) break;
2430
2431 // increment counters
2432 ntracks2 += ntracks1;
4302c900 2433
4d6aee34 2434 if(fkReconstructor->IsHLT()) break;
41702fec 2435 fSieveSeeding++;
2436
2437 // Rebuild plane configurations and indices taking only unused clusters into account
2438 quality = BuildSeedingConfigs(stack, configs);
4d6aee34 2439 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
41702fec 2440
2441 for(Int_t ip = 0; ip < kNPlanes; ip++){
2442 if(!(chamber = stack[ip])) continue;
b0a48c4d 2443 chamber->Build(fGeom, cal);//Indices(fSieveSeeding);
41702fec 2444 }
2445
9e85cb05 2446 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
41702fec 2447 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2448 }
2449 } while(fSieveSeeding<10); // end stack clusters sieve
2450
2451
2452
2453 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2454
2455 return ntracks2;
e4f2f73d 2456}
2457
2458//___________________________________________________________________
eb38ed55 2459Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
e4f2f73d 2460{
41702fec 2461 //
2462 // Assign probabilities to chambers according to their
2463 // capability of producing seeds.
2464 //
2465 // Parameters :
2466 //
2467 // layers : Array of stack propagation layers for all 6 chambers in one stack
2468 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2469 // for details) in the decreasing order of their seeding probabilities.
2470 //
2471 // Output :
2472 //
2473 // Return top configuration quality
2474 //
2475 // Detailed description:
2476 //
2477 // To each chamber seeding configuration (see GetSeedingConfig() for
2478 // the list of all configurations) one defines 2 quality factors:
2479 // - an apriori topological quality (see GetSeedingConfig() for details) and
2480 // - a data quality based on the uniformity of the distribution of
2481 // clusters over the x range (time bins population). See CookChamberQA() for details.
2482 // The overall chamber quality is given by the product of this 2 contributions.
2483 //
2484
eb2b4f91 2485 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
4d6aee34 2486 AliTRDtrackingChamber *chamber = NULL;
41702fec 2487 for(int iplane=0; iplane<kNPlanes; iplane++){
2488 if(!(chamber = stack[iplane])) continue;
2489 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2490 }
2491
eb2b4f91 2492 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2493 Int_t planes[] = {0, 0, 0, 0};
41702fec 2494 for(int iconf=0; iconf<kNConfigs; iconf++){
2495 GetSeedingConfig(iconf, planes);
2496 tconfig[iconf] = fgTopologicQA[iconf];
2497 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2498 }
2499
2500 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2501 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2502 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2503 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2504
2505 return tconfig[configs[0]];
e4f2f73d 2506}
2507
2508//____________________________________________________________________
e17f4785 2509Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
e4f2f73d 2510{
afa21247 2511//
2a3191bb 2512// Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2513// either missed by TPC prolongation or conversions inside the TRD volume.
2514// For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
afa21247 2515//
2516// Parameters :
2517// layers : Array of stack propagation layers containing clusters
2518// sseed : Array of empty tracklet seeds. On exit they are filled.
2519// ipar : Control parameters:
2520// ipar[0] -> seeding chambers configuration
2521// ipar[1] -> stack index
2522// ipar[2] -> number of track candidates found so far
2523//
2524// Output :
2525// Number of tracks candidates found.
2526//
2527// The following steps are performed:
2528// 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2529// radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2530// is described in AliTRDtrackerV1::Clusters2TracksStack().
2531// 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2532// - for each seeding cluster in the lower seeding layer find
2533// - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2534// is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2535// - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2536// reco params
2537// - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2538// seeding clusters.
2539// The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2540// and AliTRDchamberTimeBin::GetClusters().
2541// 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2542// performed at this level
2543// 4. Initialize seeding tracklets in the seeding chambers.
2544// 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2545// 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2546// AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2547// 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2548// 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2549// approximation of the track.
2550// 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2551// checked against the Riemann fit:
2552// - position resolution in y
2553// - angular resolution in the bending plane
2554// - likelihood of the number of clusters attached to the tracklet
2555// 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2556// - Initialization of extrapolation tracklets with the fit parameters
2557// - Attach clusters to extrapolated tracklets
2558// - Helix fit of tracklets
2559// 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2560// See AliTRDtrackerV1::ImproveSeedQuality() for details.
2561// 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2562// 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2563// 14. Cooking labels for tracklets. Should be done only for MC
2564// 15. Register seeds.
2565//
2566// Authors:
2567// Marian Ivanov <M.Ivanov@gsi.de>
2568// Alexandru Bercuci <A.Bercuci@gsi.de>
2569// Markus Fasel <M.Fasel@gsi.de>
41702fec 2570
4d6aee34 2571 AliTRDtrackingChamber *chamber = NULL;
2572 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
e17f4785 2573 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
41702fec 2574 Int_t ncl, mcl; // working variable for looping over clusters
2575 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2576 // chi2 storage
2577 // chi2[0] = tracklet chi2 on the Z direction
2578 // chi2[1] = tracklet chi2 on the R direction
2579 Double_t chi2[4];
2580
afa21247 2581 // this should be data member of AliTRDtrack TODO
41702fec 2582 Double_t seedQuality[kMaxTracksStack];
2583
2584 // unpack control parameters
2585 Int_t config = ipar[0];
2586 Int_t ntracks = ipar[1];
d931f2aa 2587 Int_t istack = ipar[2];
41702fec 2588 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
afa21247 2589 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
be24510a 2590
2591
41702fec 2592 // Init chambers geometry
41702fec 2593 Double_t hL[kNPlanes]; // Tilting angle
2594 Float_t padlength[kNPlanes]; // pad lenghts
dd8059a8 2595 Float_t padwidth[kNPlanes]; // pad widths
4d6aee34 2596 AliTRDpadPlane *pp = NULL;
41702fec 2597 for(int iplane=0; iplane<kNPlanes; iplane++){
2598 pp = fGeom->GetPadPlane(iplane, istack);
bb79ccd5 2599 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
41702fec 2600 padlength[iplane] = pp->GetLengthIPad();
dd8059a8 2601 padwidth[iplane] = pp->GetWidthIPad();
41702fec 2602 }
2603
eb2b4f91 2604 // Init anode wire position for chambers
e165b64b 2605 Double_t x0[kNPlanes], // anode wire position
eb2b4f91 2606 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
4d6aee34 2607 TGeoHMatrix *matrix = NULL;
eb2b4f91 2608 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2609 Double_t glb[] = {0., 0., 0.};
2610 AliTRDtrackingChamber **cIter = &stack[0];
a3743898 2611 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
eb2b4f91 2612 if(!(*cIter)) continue;
e165b64b 2613 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
2614 continue;
2615 x0[iLayer] = fgkX0[iLayer];
2616 }
eb2b4f91 2617 matrix->LocalToMaster(loc, glb);
2618 x0[iLayer] = glb[0];
2619 }
2620
980d5a2a 2621 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
41702fec 2622
d931f2aa 2623 // Build seeding layers
d611c74f 2624 ResetSeedTB();
41702fec 2625 Int_t nlayers = 0;
41702fec 2626 for(int isl=0; isl<kNSeedPlanes; isl++){
2627 if(!(chamber = stack[planes[isl]])) continue;
4d6aee34 2628 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
41702fec 2629 nlayers++;
41702fec 2630 }
eb2b4f91 2631 if(nlayers < kNSeedPlanes) return ntracks;
41702fec 2632
2633
2634 // Start finding seeds
2635 Double_t cond0[4], cond1[4], cond2[4];
2636 Int_t icl = 0;
d611c74f 2637 while((c[3] = (*fSeedTB[3])[icl++])){
41702fec 2638 if(!c[3]) continue;
d611c74f 2639 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2640 fSeedTB[0]->GetClusters(cond0, index, ncl);
41702fec 2641 //printf("Found c[3] candidates 0 %d\n", ncl);
2642 Int_t jcl = 0;
2643 while(jcl<ncl) {
d611c74f 2644 c[0] = (*fSeedTB[0])[index[jcl++]];
41702fec 2645 if(!c[0]) continue;
2646 Double_t dx = c[3]->GetX() - c[0]->GetX();
afa21247 2647 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2648 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2649 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
d611c74f 2650 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
41702fec 2651 //printf("Found c[0] candidates 1 %d\n", mcl);
2652
2653 Int_t kcl = 0;
2654 while(kcl<mcl) {
d611c74f 2655 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2656 if(!c[1]) continue;
afa21247 2657 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
d611c74f 2658 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2659 //printf("Found c[1] candidate 2 %p\n", c[2]);
2660 if(!c[2]) continue;
980d5a2a 2661
2662 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].",
2663 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2664 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2665 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2666 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
d611c74f 2667
804bb02e 2668 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
41702fec 2669
d611c74f 2670 FitRieman(c, chi2);
2671
d931f2aa 2672 AliTRDseedV1 *tseed = &cseed[0];
bb2db46c 2673 cIter = &stack[0];
2674 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2675 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
eb2b4f91 2676 tseed->SetDetector(det);
43d6ad34 2677 tseed->SetTilt(hL[iLayer]);
2678 tseed->SetPadLength(padlength[iLayer]);
dd8059a8 2679 tseed->SetPadWidth(padwidth[iLayer]);
4d6aee34 2680 tseed->SetReconstructor(fkReconstructor);
eb2b4f91 2681 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
d611c74f 2682 tseed->Init(GetRiemanFitter());
f29f13a6 2683 tseed->SetStandAlone(kTRUE);
d611c74f 2684 }
2685
2686 Bool_t isFake = kFALSE;
9e85cb05 2687 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
d611c74f 2688 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2689 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2690 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2691
2692 Double_t xpos[4];
2693 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2694 Float_t yref[4];
2695 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2696 Int_t ll = c[3]->GetLabel(0);
2697 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2698 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2699 AliRieman *rim = GetRiemanFitter();
a2fbb6ec 2700 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2701 cs0 << "MakeSeeds0"
2702 <<"EventNumber=" << eventNumber
2703 <<"CandidateNumber=" << candidateNumber
2704 <<"isFake=" << isFake
2705 <<"config=" << config
2706 <<"label=" << ll
2707 <<"chi2z=" << chi2[0]
2708 <<"chi2y=" << chi2[1]
2709 <<"Y2exp=" << cond2[0]
2710 <<"Z2exp=" << cond2[1]
2711 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2712 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2713 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2714 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2715 <<"yref0=" << yref[0]
2716 <<"yref1=" << yref[1]
2717 <<"yref2=" << yref[2]
2718 <<"yref3=" << yref[3]
2719 <<"c0.=" << c[0]
2720 <<"c1.=" << c[1]
2721 <<"c2.=" << c[2]
2722 <<"c3.=" << c[3]
2723 <<"Seed0.=" << &cseed[planes[0]]
2724 <<"Seed1.=" << &cseed[planes[1]]
2725 <<"Seed2.=" << &cseed[planes[2]]
2726 <<"Seed3.=" << &cseed[planes[3]]
2727 <<"RiemanFitter.=" << rim
2728 <<"\n";
2729 }
9e85cb05 2730 if(chi2[0] > fkRecoParam->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
980d5a2a 2731 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
d611c74f 2732 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2733 continue;
2734 }
9e85cb05 2735 if(chi2[1] > fkRecoParam->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
980d5a2a 2736 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
d611c74f 2737 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2738 continue;
2739 }
2740 //AliInfo("Passed chi2 filter.");
2741
2742 // try attaching clusters to tracklets
6e39bde4 2743 Int_t mlayers = 0;
980d5a2a 2744 AliTRDcluster *cl = NULL;
be24510a 2745 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
d611c74f 2746 Int_t jLayer = planes[iLayer];
980d5a2a 2747 Int_t nNotInChamber = 0;
f29f13a6 2748 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
980d5a2a 2749 if(/*fkReconstructor->IsHLT()*/kFALSE){
2750 cseed[jLayer].UpdateUsed();
2751 if(!cseed[jLayer].IsOK()) continue;
2752 }else{
2753 cseed[jLayer].Fit();
2754 cseed[jLayer].UpdateUsed();
2755 cseed[jLayer].ResetClusterIter();
2756 while((cl = cseed[jLayer].NextCluster())){
2757 if(!cl->IsInChamber()) nNotInChamber++;
2758 }
2759 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2760 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
2761 }
d611c74f 2762 mlayers++;
2763 }
be24510a 2764
2765 if(mlayers < kNSeedPlanes){
980d5a2a 2766 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
be24510a 2767 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2768 continue;
2769 }
2770
2771 // temporary exit door for the HLT
4d6aee34 2772 if(fkReconstructor->IsHLT()){
be24510a 2773 // attach clusters to extrapolation chambers
2774 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2775 Int_t jLayer = planesExt[iLayer];
2776 if(!(chamber = stack[jLayer])) continue;
980d5a2a 2777 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
5f1ae1e7 2778 cseed[jLayer].Fit();
be24510a 2779 }
4302c900 2780 fTrackQuality[ntracks] = 1.; // dummy value
2781 ntracks++;
218ba867 2782 if(ntracks == kMaxTracksStack) return ntracks;
4302c900 2783 cseed += 6;
2784 continue;
2785 }
2786
be24510a 2787
f29f13a6 2788 // Update Seeds and calculate Likelihood
d611c74f 2789 // fit tracklets and cook likelihood
f29f13a6 2790 FitTiltedRieman(&cseed[0], kTRUE);
2791 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2792 Int_t jLayer = planes[iLayer];
2793 cseed[jLayer].Fit(kTRUE);
2794 }
91834b8d 2795 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
d611c74f 2796
9e85cb05 2797 if (TMath::Log(1.E-9 + like) < fkRecoParam->GetTrackLikelihood()){
980d5a2a 2798 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
d611c74f 2799 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2800 continue;
2801 }
2802 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2803
2804 // book preliminary results
2805 seedQuality[ntracks] = like;
2806 fSeedLayer[ntracks] = config;/*sLayer;*/
2807
2808 // attach clusters to the extrapolation seeds
980d5a2a 2809 Int_t elayers(0);
be24510a 2810 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2811 Int_t jLayer = planesExt[iLayer];
d611c74f 2812 if(!(chamber = stack[jLayer])) continue;
d611c74f 2813
2814 // fit extrapolated seed
2815 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2816 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2817 AliTRDseedV1 pseed = cseed[jLayer];
f29f13a6 2818 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2819 pseed.Fit(kTRUE);
d611c74f 2820 cseed[jLayer] = pseed;
d611c74f 2821 FitTiltedRieman(cseed, kTRUE);
f29f13a6 2822 cseed[jLayer].Fit(kTRUE);
980d5a2a 2823 elayers++;
d611c74f 2824 }
2825
2826 // AliInfo("Extrapolation done.");
2827 // Debug Stream containing all the 6 tracklets
9e85cb05 2828 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
a2fbb6ec 2829 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2830 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2831 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2832 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2833 cstreamer << "MakeSeeds1"
2834 << "EventNumber=" << eventNumber
2835 << "CandidateNumber=" << candidateNumber
2836 << "S0.=" << &cseed[0]
2837 << "S1.=" << &cseed[1]
2838 << "S2.=" << &cseed[2]
2839 << "S3.=" << &cseed[3]
2840 << "S4.=" << &cseed[4]
2841 << "S5.=" << &cseed[5]
2842 << "FitterT.=" << tiltedRieman
2843 << "\n";
2844 }
2845
9e85cb05 2846 if(fkRecoParam->HasImproveTracklets()){
980d5a2a 2847 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
2848 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer] = cseed[jLayer];
2849
2850 if(ImproveSeedQuality(stack, cseed) < mlayers+elayers){
2851 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2852 AliDebug(3, "Filter on improve seeds.");
2853 } else {
2854 // store results
2855 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer] = bseed[jLayer];
2856 }
d611c74f 2857 }
2858 //AliInfo("Improve seed quality done.");
2859
2860 // fit full track and cook likelihoods
2861 // Double_t curv = FitRieman(&cseed[0], chi2);
2862 // Double_t chi2ZF = chi2[0] / TMath::Max((mlayers - 3.), 1.);
2863 // Double_t chi2RF = chi2[1] / TMath::Max((mlayers - 3.), 1.);
2864
2865 // do the final track fitting (Once with vertex constraint and once without vertex constraint)
2866 Double_t chi2Vals[3];
6e39bde4 2867 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
9e85cb05 2868 if(fkRecoParam->IsVertexConstrained())
d611c74f 2869 chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ()); // Do Vertex Constrained fit if desired
2870 else
2871 chi2Vals[1] = 1.;
2872 chi2Vals[2] = GetChi2Z(&cseed[0]) / TMath::Max((mlayers - 3.), 1.);
2873 // Chi2 definitions in testing stage
2874 //chi2Vals[2] = GetChi2ZTest(&cseed[0]);
2875 fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
2876 //AliInfo("Hyperplane fit done\n");
fac58f00 2877
9e85cb05 2878 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
a2fbb6ec 2879 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2880 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2881 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2882 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2883 TLinearFitter *fitterT = GetTiltedRiemanFitter();
91834b8d 2884 Int_t ncls = 0;
2885 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2886 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2887 }
d611c74f 2888 cstreamer << "MakeSeeds2"
2889 << "EventNumber=" << eventNumber
2890 << "CandidateNumber=" << candidateNumber
2891 << "Chi2TR=" << chi2Vals[0]
2892 << "Chi2TC=" << chi2Vals[1]
2893 << "Nlayers=" << mlayers
91834b8d 2894 << "NClusters=" << ncls
d611c74f 2895 << "Like=" << like
2896 << "S0.=" << &cseed[0]
2897 << "S1.=" << &cseed[1]
2898 << "S2.=" << &cseed[2]
2899 << "S3.=" << &cseed[3]
2900 << "S4.=" << &cseed[4]
2901 << "S5.=" << &cseed[5]
d611c74f 2902 << "FitterT.=" << fitterT
2903 << "FitterTC.=" << fitterTC
2904 << "\n";
2905 }
2906
2907 ntracks++;
2908 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2909 if(ntracks == kMaxTracksStack){
2910 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2911 return ntracks;
2912 }
2913 cseed += 6;
41702fec 2914 }
2915 }
2916 }
41702fec 2917
2918 return ntracks;
e4f2f73d 2919}
2920
2921//_____________________________________________________________________________
e17f4785 2922AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const seeds, Double_t *params)
e4f2f73d 2923{
afa21247 2924//
2925// Build a TRD track out of tracklet candidates
2926//
2927// Parameters :
2928// seeds : array of tracklets
2929// params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
2930// [0] - radial position of the track at reference point
2931// [1] - y position of the fit at [0]
2932// [2] - z position of the fit at [0]
2933// [3] - snp of the first tracklet
2934// [4] - tgl of the first tracklet
2935// [5] - curvature of the Riemann fit - 1/pt
2936// [6] - sector rotation angle
2937//
2938// Output :
2939// The TRD track.
2940//
2941// Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
2942// (diagonal with constant variance terms TODO - correct parameterization)
2943//
2944// In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
2945// offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
2946// for details). Do also MC label calculation and PID if propagation successfully.
41702fec 2947
afa21247 2948
41702fec 2949 Double_t alpha = AliTRDgeometry::GetAlpha();
2950 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
2951 Double_t c[15];
2952
afa21247 2953 c[ 0] = 0.2; // s^2_y
2954 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
2955 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
2956 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
2957 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[5]*params[5]*0.01; // s^2_1/pt
41702fec 2958
d20df6fc 2959 AliTRDtrackV1 track(seeds, &params[1], c, params[0], params[6]*alpha+shift);
2960 track.PropagateTo(params[0]-5.0);
4d6aee34 2961 AliTRDseedV1 *ptrTracklet = NULL;
9887cc9f 2962
2963 // skip Kalman filter for HLT
5f1ae1e7 2964 if(/*fkReconstructor->IsHLT()*/kFALSE){
9887cc9f 2965 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
2966 track.UnsetTracklet(jLayer);
e17f4785 2967 ptrTracklet = &seeds[jLayer];
9887cc9f 2968 if(!ptrTracklet->IsOK()) continue;
5f1ae1e7 2969 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
9887cc9f 2970 ptrTracklet = SetTracklet(ptrTracklet);
f29f13a6 2971 ptrTracklet->UseClusters();
91834b8d 2972 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
2973 }
d78d7df0 2974 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
799e38d7 2975 ptrTrack->CookPID();
5f1ae1e7 2976 ptrTrack->CookLabel(.9);
4d6aee34 2977 ptrTrack->SetReconstructor(fkReconstructor);
d78d7df0 2978 return ptrTrack;
91834b8d 2979 }
393fda1c 2980
b1135f96 2981 // prevent the error message in AliTracker::MeanMaterialBudget: "start point out of geometry"
2982 if(TMath::Abs(track.GetX()) + TMath::Abs(track.GetY()) + TMath::Abs(track.GetZ()) > 10000)
17e0e535 2983 return NULL;
2984
d20df6fc 2985 track.ResetCovariance(1);
e79f8eb0 2986 Int_t nc = TMath::Abs(FollowBackProlongation(track));
9e85cb05 2987 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()){
393fda1c 2988 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2989 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2990 Double_t p[5]; // Track Params for the Debug Stream
2991 track.GetExternalParameters(params[0], p);
a2fbb6ec 2992 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
393fda1c 2993 cs << "MakeTrack"
2994 << "EventNumber=" << eventNumber
2995 << "CandidateNumber=" << candidateNumber
2996 << "nc=" << nc
2997 << "X=" << params[0]
2998 << "Y=" << p[0]
2999 << "Z=" << p[1]
3000 << "snp=" << p[2]
3001 << "tnd=" << p[3]
3002 << "crv=" << p[4]
3003 << "Yin=" << params[1]
3004 << "Zin=" << params[2]
3005 << "snpin=" << params[3]
3006 << "tndin=" << params[4]
3007 << "crvin=" << params[5]
3008 << "track.=" << &track
3009 << "\n";
3010 }
4d6aee34 3011 if (nc < 30) return NULL;
d20df6fc 3012
3013 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
4d6aee34 3014 ptrTrack->SetReconstructor(fkReconstructor);
48f8adf3 3015 ptrTrack->CookLabel(.9);
24253b0a 3016
d20df6fc 3017 // computes PID for track
3018 ptrTrack->CookPID();
3019 // update calibration references using this track
48f8adf3 3020 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
3021 if (!calibra){
3022 AliInfo("Could not get Calibra instance\n");
3023 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(ptrTrack);
3024 }
d20df6fc 3025 return ptrTrack;
e4f2f73d 3026}
3027
0906e73e 3028
e4f2f73d 3029//____________________________________________________________________
eb38ed55 3030Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed)
e4f2f73d 3031{
41702fec 3032 //
3033 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3034 //
3035 // Parameters :
3036 // layers : Array of propagation layers for a stack/supermodule
3037 // cseed : Array of 6 seeding tracklets which has to be improved
3038 //
f29f13a6 3039 // Output :
41702fec 3040 // cssed : Improved seeds
3041 //
3042 // Detailed description
3043 //
3044 // Iterative procedure in which new clusters are searched for each
3045 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3046 // can be maximized. If some optimization is found the old seeds are replaced.
3047 //
3048 // debug level: 7
3049 //
3050
3051 // make a local working copy
4d6aee34 3052 AliTRDtrackingChamber *chamber = NULL;
980d5a2a 3053 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3054
3055 Float_t quality(0.),
3056 lQuality[] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
3057 Int_t rLayers(0);
3058 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3059 bseed[jLayer] = cseed[jLayer];
3060 if(!bseed[jLayer].IsOK()) continue;
3061 rLayers++;
3062 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3063 quality += lQuality[jLayer];
3064 }
3065 Float_t chi2 = FitTiltedRieman(bseed, kTRUE);
41702fec 3066
3067 for (Int_t iter = 0; iter < 4; iter++) {
560e5c05 3068 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
3069
980d5a2a 3070 // Try better cluster set
3071 Int_t nLayers(0); Float_t qualitynew(0.);
3072 Int_t indexes[6];
3073 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3074 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3075 Int_t bLayer = indexes[jLayer];
3076 bseed[bLayer].Reset("c");
41702fec 3077 if(!(chamber = stack[bLayer])) continue;
980d5a2a 3078 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
f29f13a6 3079 bseed[bLayer].Fit(kTRUE);
980d5a2a 3080 if(!bseed[bLayer].IsOK()) continue;
3081 nLayers++;
3082 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3083 qualitynew += lQuality[jLayer];
41702fec 3084 }
980d5a2a 3085 if(rLayers > nLayers){
3086 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
3087 break;
3088 } else rLayers=nLayers;
3089
3090 if(qualitynew >= quality){
3091 AliDebug(4, Form("Quality worsen in iter[%d].", iter));
3092 break;
3093 } else quality = qualitynew;
3094
3095 // try improve track parameters
3096 AliTRDseedV1 tseed[AliTRDgeometry::kNlayer];
3097 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) tseed[jLayer]=bseed[jLayer];
3098 Float_t chi2new = FitTiltedRieman(tseed, kTRUE);
3099 if(chi2new > chi2){
3100 AliDebug(4, Form("Chi2 worsen in iter[%d].", iter));
3101 break;
3102 } else chi2 = chi2new;
3103
3104 // store better tracklets
3105 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer]=tseed[jLayer];
3106
41702fec 3107
9e85cb05 3108 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming()){
41702fec 3109 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3110 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3111 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
a2fbb6ec 3112 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3113 cstreamer << "ImproveSeedQuality"
980d5a2a 3114 << "EventNumber=" << eventNumber
3115 << "CandidateNumber=" << candidateNumber
3116 << "Iteration=" << iter
3117 << "S0.=" << &bseed[0]
3118 << "S1.=" << &bseed[1]
3119 << "S2.=" << &bseed[2]
3120 << "S3.=" << &bseed[3]
3121 << "S4.=" << &bseed[4]
3122 << "S5.=" << &bseed[5]
3123 << "FitterT.=" << tiltedRieman
3124 << "\n";
41702fec 3125 }
3126 } // Loop: iter
41702fec 3127 // we are sure that at least 2 tracklets are OK !
980d5a2a 3128 return rLayers;
e4f2f73d 3129}
3130
eb38ed55 3131//_________________________________________________________________________
4d6aee34 3132Double_t AliTRDtrackerV1::CalculateTrackLikelihood(const AliTRDseedV1 *const tracklets, Double_t *chi2){
41702fec 3133 //
3134 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3135 // the track selection
3136 // The likelihood value containes:
3137 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3138 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3139 // For all Parameters an exponential dependency is used
3140 //
3141 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3142 // - Array of chi2 values:
3143 // * Non-Constrained Tilted Riemann fit
3144 // * Vertex-Constrained Tilted Riemann fit
3145 // * z-Direction from Linear fit
3146 // Output: - The calculated track likelihood
3147 //
3148 // debug level 2
3149 //
3150
f29f13a6 3151 Double_t chi2phi = 0, nLayers = 0;
41702fec 3152 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3153 if(!tracklets[iLayer].IsOK()) continue;
f29f13a6 3154 chi2phi += tracklets[iLayer].GetChi2Phi();
41702fec 3155 nLayers++;
3156 }
f29f13a6 3157 chi2phi /= Float_t (nLayers - 2.0);
41702fec 3158
3159 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14); // Chi2Z
9e85cb05 3160 Double_t likeChi2TC = (fkRecoParam->IsVertexConstrained()) ?
d20df6fc 3161 TMath::Exp(-chi2[1] * 0.677) : 1; // Constrained Tilted Riemann
6e39bde4 3162 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078); // Non-constrained Tilted Riemann
3163 Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);//3.23
f29f13a6 3164 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2Phi;
41702fec 3165
9e85cb05 3166 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
41702fec 3167 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3168 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
a2fbb6ec 3169 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3170 cstreamer << "CalculateTrackLikelihood0"
3171 << "EventNumber=" << eventNumber
3172 << "CandidateNumber=" << candidateNumber
3173 << "LikeChi2Z=" << likeChi2Z
3174 << "LikeChi2TR=" << likeChi2TR
3175 << "LikeChi2TC=" << likeChi2TC
f29f13a6 3176 << "LikeChi2Phi=" << likeChi2Phi
41702fec 3177 << "TrackLikelihood=" << trackLikelihood
3178 << "\n";
3179 }
6e39bde4 3180
41702fec 3181 return trackLikelihood;
e4f2f73d 3182}
3183
3184//____________________________________________________________________
91834b8d 3185Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
e4f2f73d 3186{
41702fec 3187 //
3188 // Calculate the probability of this track candidate.
3189 //
3190 // Parameters :
3191 // cseeds : array of candidate tracklets
3192 // planes : array of seeding planes (see seeding configuration)
3193 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3194 //
3195 // Output :
3196 // likelihood value
3197 //
3198 // Detailed description
3199 //
3200 // The track quality is estimated based on the following 4 criteria:
3201 // 1. precision of the rieman fit on the Y direction (likea)
3202 // 2. chi2 on the Y direction (likechi2y)
3203 // 3. chi2 on the Z direction (likechi2z)
3204 // 4. number of attached clusters compared to a reference value
3205 // (see AliTRDrecoParam::fkFindable) (likeN)
3206 //
3207 // The distributions for each type of probabilities are given below as of
3208 // (date). They have to be checked to assure consistency of estimation.
3209 //
3210
3211 // ratio of the total number of clusters/track which are expected to be found by the tracker.
91834b8d 3212 Double_t chi2y = GetChi2Y(&cseed[0]);
3213 Double_t chi2z = GetChi2Z(&cseed[0]);
3214
8ae98148 3215 Float_t nclusters = 0.;
41702fec 3216 Double_t sumda = 0.;
3217 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3218 Int_t jlayer = planes[ilayer];
3219 nclusters += cseed[jlayer].GetN2();
e3cf3d02 3220 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
41702fec 3221 }
8ae98148 3222 nclusters *= .25;
3223
9e85cb05 3224 Double_t likea = TMath::Exp(-sumda * fkRecoParam->GetPhiSlope());
41702fec 3225 Double_t likechi2y = 0.0000000001;
9e85cb05 3226 if (fkReconstructor->IsCosmic() || chi2y < fkRecoParam->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fkRecoParam->GetChi2YSlope());
3227 Double_t likechi2z = TMath::Exp(-chi2z * fkRecoParam->GetChi2ZSlope());
3228 Double_t likeN = TMath::Exp(-(fkRecoParam->GetNMeanClusters() - nclusters) / fkRecoParam->GetNSigmaClusters());
41702fec 3229 Double_t like = likea * likechi2y * likechi2z * likeN;
3230
9e85cb05 3231 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
41702fec 3232 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3233 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
4d6aee34 3234 Int_t nTracklets = 0; Float_t meanNcls = 0;
91834b8d 3235 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3236 if(!cseed[iseed].IsOK()) continue;
3237 nTracklets++;
4d6aee34 3238 meanNcls += cseed[iseed].GetN2();
91834b8d 3239 }
4d6aee34 3240 if(nTracklets) meanNcls /= nTracklets;
41702fec 3241 // The Debug Stream contains the seed
a2fbb6ec 3242 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3243 cstreamer << "CookLikelihood"
3244 << "EventNumber=" << eventNumber
3245 << "CandidateNumber=" << candidateNumber
3246 << "tracklet0.=" << &cseed[0]
3247 << "tracklet1.=" << &cseed[1]
3248 << "tracklet2.=" << &cseed[2]
3249 << "tracklet3.=" << &cseed[3]
3250 << "tracklet4.=" << &cseed[4]
3251 << "tracklet5.=" << &cseed[5]
3252 << "sumda=" << sumda
91834b8d 3253 << "chi2y=" << chi2y
3254 << "chi2z=" << chi2z
41702fec 3255 << "likea=" << likea
3256 << "likechi2y=" << likechi2y
3257 << "likechi2z=" << likechi2z
3258 << "nclusters=" << nclusters
3259 << "likeN=" << likeN
3260 << "like=" << like
4d6aee34 3261 << "meanncls=" << meanNcls
41702fec 3262 << "\n";
3263 }
3264
3265 return like;
e4f2f73d 3266}
3267
e4f2f73d 3268//____________________________________________________________________
0906e73e 3269void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
e4f2f73d 3270{
41702fec 3271 //
3272 // Map seeding configurations to detector planes.
3273 //
3274 // Parameters :
3275 // iconfig : configuration index
3276 // planes : member planes of this configuration. On input empty.
3277 //
3278 // Output :
3279 // planes : contains the planes which are defining the configuration
3280 //
3281 // Detailed description
3282 //
3283 // Here is the list of seeding planes configurations together with
3284 // their topological classification:
3285 //
3286 // 0 - 5432 TQ 0
3287 // 1 - 4321 TQ 0
3288 // 2 - 3210 TQ 0
3289 // 3 - 5321 TQ 1
3290 // 4 - 4210 TQ 1
3291 // 5 - 5431 TQ 1
3292 // 6 - 4320 TQ 1
3293 // 7 - 5430 TQ 2
3294 // 8 - 5210 TQ 2
3295 // 9 - 5421 TQ 3
3296 // 10 - 4310 TQ 3
3297 // 11 - 5410 TQ 4
3298 // 12 - 5420 TQ 5
3299 // 13 - 5320 TQ 5
3300 // 14 - 5310 TQ 5
3301 //
3302 // The topologic quality is modeled as follows:
3303 // 1. The general model is define by the equation:
3304 // p(conf) = exp(-conf/2)
3305 // 2. According to the topologic classification, configurations from the same
3306 // class are assigned the agerage value over the model values.
3307 // 3. Quality values are normalized.
3308 //
3309 // The topologic quality distribution as function of configuration is given below:
3310 //Begin_Html
3311 // <img src="gif/topologicQA.gif">
3312 //End_Html
3313 //
3314
3315 switch(iconfig){
3316 case 0: // 5432 TQ 0
3317 planes[0] = 2;
3318 planes[1] = 3;
3319 planes[2] = 4;
3320 planes[3] = 5;
3321 break;
3322 case 1: // 4321 TQ 0
3323 planes[0] = 1;
3324 planes[1] = 2;
3325 planes[2] = 3;
3326 planes[3] = 4;
3327 break;
3328 case 2: // 3210 TQ 0
3329 planes[0] = 0;
3330 planes[1] = 1;
3331 planes[2] = 2;
3332 planes[3] = 3;
3333 break;
3334 case 3: // 5321 TQ 1
3335 planes[0] = 1;
3336 planes[1] = 2;
3337 planes[2] = 3;
3338 planes[3] = 5;
3339 break;
3340 case 4: // 4210 TQ 1
3341 planes[0] = 0;
3342 planes[1] = 1;
3343 planes[2] = 2;
3344 planes[3] = 4;
3345 break;
3346 case 5: // 5431 TQ 1
3347 planes[0] = 1;
3348 planes[1] = 3;
3349 planes[2] = 4;
3350 planes[3] = 5;
3351 break;
3352 case 6: // 4320 TQ 1
3353 planes[0] = 0;
3354 planes[1] = 2;
3355 planes[2] = 3;
3356 planes[3] = 4;
3357 break;
3358 case 7: // 5430 TQ 2
3359 planes[0] = 0;
3360 planes[1] = 3;
3361 planes[2] = 4;
3362 planes[3] = 5;
3363 break;
3364 case 8: // 5210 TQ 2
3365 planes[0] = 0;
3366 planes[1] = 1;
3367 planes[2] = 2;
3368 planes[3] = 5;
3369 break;
3370 case 9: // 5421 TQ 3
3371 planes[0] = 1;
3372 planes[1] = 2;
3373 planes[2] = 4;
3374 planes[3] = 5;
3375 break;
3376 case 10: // 4310 TQ 3
3377 planes[0] = 0;
3378 planes[1] = 1;
3379 planes[2] = 3;
3380 planes[3] = 4;
3381 break;
3382 case 11: // 5410 TQ 4
3383 planes[0] = 0;
3384 planes[1] = 1;
3385 planes[2] = 4;
3386 planes[3] = 5;
3387 break;
3388 case 12: // 5420 TQ 5
3389 planes[0] = 0;
3390 planes[1] = 2;
3391 planes[2] = 4;
3392 planes[3] = 5;
3393 break;
3394 case 13: // 5320 TQ 5
3395 planes[0] = 0;
3396 planes[1] = 2;
3397 planes[2] = 3;
3398 planes[3] = 5;
3399 break;
3400 case 14: // 5310 TQ 5
3401 planes[0] = 0;
3402 planes[1] = 1;
3403 planes[2] = 3;
3404 planes[3] = 5;
3405 break;
3406 }
e4f2f73d 3407}
3408
3409//____________________________________________________________________
0906e73e 3410void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
e4f2f73d 3411{
41702fec 3412 //
3413 // Returns the extrapolation planes for a seeding configuration.
3414 //
3415 // Parameters :
3416 // iconfig : configuration index
3417 // planes : planes which are not in this configuration. On input empty.
3418 //
3419 // Output :
3420 // planes : contains the planes which are not in the configuration
3421 //
3422 // Detailed description
3423 //
3424
3425 switch(iconfig){
3426 case 0: // 5432 TQ 0
3427 planes[0] = 1;
3428 planes[1] = 0;
3429 break;
3430 case 1: // 4321 TQ 0
3431 planes[0] = 5;
3432 planes[1] = 0;
3433 break;
3434 case 2: // 3210 TQ 0
3435 planes[0] = 4;
3436 planes[1] = 5;
3437 break;
3438 case 3: // 5321 TQ 1
3439 planes[0] = 4;
3440 planes[1] = 0;
3441 break;
3442 case 4: // 4210 TQ 1
3443 planes[0] = 5;
3444 planes[1] = 3;
3445 break;
3446 case 5: // 5431 TQ 1
3447 planes[0] = 2;
3448 planes[1] = 0;
3449 break;
3450 case 6: // 4320 TQ 1
3451 planes[0] = 5;
3452 planes[1] = 1;
3453 break;
3454 case 7: // 5430 TQ 2
3455 planes[0] = 2;
3456 planes[1] = 1;
3457 break;
3458 case 8: // 5210 TQ 2
3459 planes[0] = 4;
3460 planes[1] = 3;
3461 break;
3462 case 9: // 5421 TQ 3
3463 planes[0] = 3;
3464 planes[1] = 0;
3465 break;
3466 case 10: // 4310 TQ 3
3467 planes[0] = 5;
3468 planes[1] = 2;
3469 break;
3470 case 11: // 5410 TQ 4
3471 planes[0] = 3;
3472 planes[1] = 2;
3473 break;
3474 case 12: // 5420 TQ 5
3475 planes[0] = 3;
3476 planes[1] = 1;
3477 break;
3478 case 13: // 5320 TQ 5
3479 planes[0] = 4;
3480 planes[1] = 1;
3481 break;
3482 case 14: // 5310 TQ 5
3483 planes[0] = 4;
3484 planes[1] = 2;
3485 break;
3486 }
e4f2f73d 3487}
eb38ed55 3488
3489//____________________________________________________________________
3490AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3491{
971a356b 3492 if(!fClusters) return NULL;
41702fec 3493 Int_t ncls = fClusters->GetEntriesFast();
4d6aee34 3494 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
eb38ed55 3495}
3496
3b57a3f7 3497//____________________________________________________________________
3498AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3499{
971a356b 3500 if(!fTracklets) return NULL;
41702fec 3501 Int_t ntrklt = fTracklets->GetEntriesFast();
4d6aee34 3502 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3b57a3f7 3503}
3504
3505//____________________________________________________________________
3506AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3507{
971a356b 3508 if(!fTracks) return NULL;
41702fec 3509 Int_t ntrk = fTracks->GetEntriesFast();
4d6aee34 3510 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3b57a3f7 3511}
3512
6e39bde4 3513
eb38ed55 3514
fac58f00 3515// //_____________________________________________________________________________
3516// Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3517// , Int_t *outlist, Bool_t down)
3518// {
3519// //
3520// // Sort eleements according occurancy
3521// // The size of output array has is 2*n
3522// //
3523//
3524// if (n <= 0) {
3525// return 0;
3526// }
3527//
3528// Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3529// Int_t *sindexF = new Int_t[2*n];
3530// for (Int_t i = 0; i < n; i++) {
3531// sindexF[i] = 0;
3532// }
3533//
3534// TMath::Sort(n,inlist,sindexS,down);
3535//
3536// Int_t last = inlist[sindexS[0]];
3537// Int_t val = last;
3538// sindexF[0] = 1;
3539// sindexF[0+n] = last;
3540// Int_t countPos = 0;
3541//
3542// // Find frequency
3543// for (Int_t i = 1; i < n; i++) {
3544// val = inlist[sindexS[i]];
3545// if (last == val) {
3546// sindexF[countPos]++;
3547// }
3548// else {
3549// countPos++;
3550// sindexF[countPos+n] = val;
3551// sindexF[countPos]++;
3552// last = val;
3553// }
3554// }
3555// if (last == val) {
3556// countPos++;
3557// }
3558//
3559// // Sort according frequency
3560// TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3561//
3562// for (Int_t i = 0; i < countPos; i++) {
3563// outlist[2*i ] = sindexF[sindexS[i]+n];
3564// outlist[2*i+1] = sindexF[sindexS[i]];
3565// }
3566//
3567// delete [] sindexS;
3568// delete [] sindexF;
3569//
3570// return countPos;
3571//
3572// }
bb56afff 3573
06b32d95 3574
d611c74f 3575//____________________________________________________________________
3576void AliTRDtrackerV1::ResetSeedTB()
3577{
3578// reset buffer for seeding time bin layers. If the time bin
3579// layers are not allocated this function allocates them
3580
3581 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3582 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3583 else fSeedTB[isl]->Clear();
3584 }
3585}
3586
e3cf3d02 3587
3588//_____________________________________________________________________________
4d6aee34 3589Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
e3cf3d02 3590{
3591 // Calculates normalized chi2 in y-direction
3592 // chi2 = Sum chi2 / n_tracklets
3593
3594 Double_t chi2 = 0.; Int_t n = 0;
3595 for(Int_t ipl = kNPlanes; ipl--;){
3596 if(!tracklets[ipl].IsOK()) continue;
3597 chi2 += tracklets[ipl].GetChi2Y();
3598 n++;
3599 }
3600 return n ? chi2/n : 0.;
3601}
3602
bb56afff 3603//_____________________________________________________________________________
4d6aee34 3604Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
bb56afff 3605{
91834b8d 3606 // Calculates normalized chi2 in z-direction
e3cf3d02 3607 // chi2 = Sum chi2 / n_tracklets
41702fec 3608
e3cf3d02 3609 Double_t chi2 = 0; Int_t n = 0;
3610 for(Int_t ipl = kNPlanes; ipl--;){
41702fec 3611 if(!tracklets[ipl].IsOK()) continue;
e3cf3d02 3612 chi2 += tracklets[ipl].GetChi2Z();
3613 n++;
41702fec 3614 }
e3cf3d02 3615 return n ? chi2/n : 0.;
bb56afff 3616}
8acca6a3 3617
6e39bde4 3618//____________________________________________________________________
4d6aee34 3619Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
6e39bde4 3620 //
3621 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3622 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3623 // are taken into account
3624 //
3625 // Parameters: - Array of tracklets(AliTRDseedV1)
3626 //
3627 // Output: - The reference x-position(Float_t)
3628 // Only kept for compatibility with the old code
3629 //
3630 Int_t nDistances = 0;
3631 Float_t meanDistance = 0.;
3632 Int_t startIndex = 5;
3633 for(Int_t il =5; il > 0; il--){
3634 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3635 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3636 meanDistance += xdiff;
3637 nDistances++;
3638 }
3639 if(tracklets[il].IsOK()) startIndex = il;
3640 }
3641 if(tracklets[0].IsOK()) startIndex = 0;
3642 if(!nDistances){
3643 // We should normally never get here
3644 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3645 Int_t iok = 0, idiff = 0;
3646 // This attempt is worse and should be avoided:
3647 // check for two chambers which are OK and repeat this without taking the mean value
3648 // Strategy avoids a division by 0;
3649 for(Int_t il = 5; il >= 0; il--){
3650 if(tracklets[il].IsOK()){
3651 xpos[iok] = tracklets[il].GetX0();
3652 iok++;
3653 startIndex = il;
3654 }
3655 if(iok) idiff++; // to get the right difference;
3656 if(iok > 1) break;
3657 }
3658 if(iok > 1){
3659 meanDistance = (xpos[0] - xpos[1])/idiff;
3660 }
3661 else{
3662 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3663 return 331.;
3664 }
3665 }
3666 else{
3667 meanDistance /= nDistances;
3668 }
3669 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3670}
3671
3672//_____________________________________________________________________________
4d6aee34 3673Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
6e39bde4 3674 //
3675 // Track Fitter Function using the new class implementation of
3676 // the Rieman fit
3677 //
3678 AliTRDtrackFitterRieman fitter;
3679 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3680 fitter.Reset();
3681 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3682 Double_t chi2 = fitter.Eval();
3683 // Update the tracklets
3684 Double_t cov[15]; Double_t x0;
3685 memset(cov, 0, sizeof(Double_t) * 15);
3686 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3687 x0 = tracklets[il].GetX0();
3688 tracklets[il].SetYref(0, fitter.GetYat(x0));
3689 tracklets[il].SetZref(0, fitter.GetZat(x0));
3690 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3691 tracklets[il].SetZref(1, fitter.GetDzDx());
3692 tracklets[il].SetC(fitter.GetCurvature());
3693 fitter.GetCovAt(x0, cov);
3694 tracklets[il].SetCovRef(cov);
3695 tracklets[il].SetChi2(chi2);
3696 }
3697 return chi2;
3698}
3699
8acca6a3 3700///////////////////////////////////////////////////////
3701// //
3702// Resources of class AliTRDLeastSquare //
3703// //
3704///////////////////////////////////////////////////////
3705
3706//_____________________________________________________________________________
3707AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
903326c1 3708//
3709// Constructor of the nested class AliTRDtrackFitterLeastSquare
3710//
3711// Fast solving linear regresion in 2D
0323ef61 3712// y=a + bx
903326c1 3713// The data members have the following meaning
0323ef61 3714// fParams[0] : a
3715// fParams[1] : b
903326c1 3716//
3717// fSums[0] : S
3718// fSums[1] : Sx
3719// fSums[2] : Sy
3720// fSums[3] : Sxy
3721// fSums[4] : Sxx
3722// fSums[5] : Syy
3723//
0323ef61 3724// fCovarianceMatrix[0] : s2a
3725// fCovarianceMatrix[1] : s2b
903326c1 3726// fCovarianceMatrix[2] : cov(ab)
3727
41702fec 3728 memset(fParams, 0, sizeof(Double_t) * 2);
341512a4 3729 memset(fSums, 0, sizeof(Double_t) * 6);
41702fec 3730 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
8acca6a3 3731
3732}
3733
3734//_____________________________________________________________________________
4d6aee34 3735void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
41702fec 3736 //
3737 // Adding Point to the fitter
3738 //
5f1ae1e7 3739
2ed81ab2 3740 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3741 weight *= weight;
4d6aee34 3742 const Double_t &xpt = *x;
41702fec 3743 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3744 fSums[0] += weight;
3745 fSums[1] += weight * xpt;
3746 fSums[2] += weight * y;
3747 fSums[3] += weight * xpt * y;
3748 fSums[4] += weight * xpt * xpt;
3749 fSums[5] += weight * y * y;
8acca6a3 3750}
3751
3752//_____________________________________________________________________________
4d6aee34 3753void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
41702fec 3754 //
3755 // Remove Point from the sample
3756 //
5f1ae1e7 3757
2ed81ab2 3758 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3759 weight *= weight;
4d6aee34 3760 const Double_t &xpt = *x;
41702fec 3761 fSums[0] -= weight;
3762 fSums[1] -= weight * xpt;
3763 fSums[2] -= weight * y;
3764 fSums[3] -= weight * xpt * y;
3765 fSums[4] -= weight * xpt * xpt;
3766 fSums[5] -= weight * y * y;
8acca6a3 3767}
3768
3769//_____________________________________________________________________________
903326c1 3770Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
41702fec 3771 //
3772 // Evaluation of the fit:
3773 // Calculation of the parameters
3774 // Calculation of the covariance matrix
3775 //
3776
903326c1 3777 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
3778 if(det==0) return kFALSE;
aec26713 3779
41702fec 3780 // for(Int_t isum = 0; isum < 5; isum++)
3781 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3782 // printf("denominator = %f\n", denominator);
903326c1 3783 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
3784 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
41702fec 3785 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3786
3787 // Covariance matrix
0323ef61 3788 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
3789 fCovarianceMatrix[0] = fSums[4] / den;
3790 fCovarianceMatrix[1] = fSums[0] / den;
3791 fCovarianceMatrix[2] = -fSums[1] / den;
3792/* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
2ed81ab2 3793 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
0323ef61 3794 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
3795
3796
3797
903326c1 3798 return kTRUE;
8acca6a3 3799}
3800
46b6abd7 3801//_____________________________________________________________________________
4d6aee34 3802Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
41702fec 3803 //
3804 // Returns the Function value of the fitted function at a given x-position
3805 //
3806 return fParams[0] + fParams[1] * (*xpos);
46b6abd7 3807}
3808
3809//_____________________________________________________________________________
3810void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
41702fec 3811 //
3812 // Copies the values of the covariance matrix into the storage
3813 //
3814 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
46b6abd7 3815}
3816
6e39bde4 3817//_____________________________________________________________________________
3818void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
3819 //
3820 // Reset the fitter
3821 //
3822 memset(fParams, 0, sizeof(Double_t) * 2);
3823 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3824 memset(fSums, 0, sizeof(Double_t) * 6);
3825}
3826
3827///////////////////////////////////////////////////////
3828// //
3829// Resources of class AliTRDtrackFitterRieman //
3830// //
3831///////////////////////////////////////////////////////
3832
3833//_____________________________________________________________________________
3834AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
3835 fTrackFitter(NULL),
3836 fZfitter(NULL),
3837 fCovarPolY(NULL),
3838 fCovarPolZ(NULL),
3839 fXref(0.),
3840 fSysClusterError(0.)
3841{
3842 //
3843 // Default constructor
3844 //
3845 fZfitter = new AliTRDLeastSquare;
3846 fCovarPolY = new TMatrixD(3,3);
3847 fCovarPolZ = new TMatrixD(2,2);
3848 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
3849 memset(fParameters, 0, sizeof(Double_t) * 5);
3850 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3851 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3852}
3853
3854//_____________________________________________________________________________
3855AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
3856 //
3857 // Destructor
3858 //
3859 if(fZfitter) delete fZfitter;
3860 if(fCovarPolY) delete fCovarPolY;
3861 if(fCovarPolZ) delete fCovarPolZ;
3862}
3863
3864//_____________________________________________________________________________
3865void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
3866 //
3867 // Reset the Fitter
3868 //
3869 if(fTrackFitter){
3870 fTrackFitter->StoreData(kTRUE);
3871 fTrackFitter->ClearPoints();
3872 }
3873 if(fZfitter){
3874 fZfitter->Reset();
3875 }
3876 fXref = 0.;
3877 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
3878 memset(fParameters, 0, sizeof(Double_t) * 5);
3879 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3880 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3881 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
3882 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
3883 (*fCovarPolY)(irow, icol) = 0.;
3884 if(irow < 2 && icol < 2)
3885 (*fCovarPolZ)(irow, icol) = 0.;
3886 }
3887}
3888
3889//_____________________________________________________________________________
3890void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
3891 //
3892 // Add tracklet into the fitter
3893 //
3894 if(itr >= AliTRDgeometry::kNlayer) return;
3895 fTracklets[itr] = tracklet;
3896}
3897
3898//_____________________________________________________________________________
3899Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
3900 //
3901 // Perform the fit
3902 // 1. Apply linear transformation and store points in the fitter
3903 // 2. Evaluate the fit
3904 // 3. Check if the result of the fit in z-direction is reasonable
3905 // if not
3906 // 3a. Fix the parameters 3 and 4 with the results of a simple least
3907 // square fit
3908 // 3b. Redo the fit with the fixed parameters
3909 // 4. Store fit results (parameters and errors)
3910 //
3911 if(!fTrackFitter){
3912 return 1e10;
3913 }
3914 fXref = CalculateReferenceX();
3915 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
3916 if(!fTrackFitter->GetNpoints()) return 1e10;
3917 // perform the fit
3918 fTrackFitter->Eval();
3919 fZfitter->Eval();
3920 fParameters[3] = fTrackFitter->GetParameter(3);
3921 fParameters[4] = fTrackFitter->GetParameter(4);
3922 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
3923 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
3924 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
3925 fTrackFitter->Eval();
3926 fTrackFitter->ReleaseParameter(3);
3927 fTrackFitter->ReleaseParameter(4);
3928 fParameters[3] = fTrackFitter->GetParameter(3);
3929 fParameters[4] = fTrackFitter->GetParameter(4);
3930 }
3931 // Update the Fit Parameters and the errors
3932 fParameters[0] = fTrackFitter->GetParameter(0);
3933 fParameters[1] = fTrackFitter->GetParameter(1);
3934 fParameters[2] = fTrackFitter->GetParameter(2);
3935
3936 // Prepare Covariance estimation
3937 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
3938 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
3939 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
3940 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
3941 fCovarPolY->Invert();
3942 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
3943 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
3944 fCovarPolZ->Invert();
3945 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
3946}
3947
3948//_____________________________________________________________________________
4d6aee34 3949void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(AliTRDseedV1 * const tracklet){
6e39bde4 3950 //
3951 // Does the transformations and updates the fitters
3952 // The following transformation is applied
3953 //
3954 AliTRDcluster *cl = NULL;
3955 Double_t x, y, z, dx, t, w, we, yerr, zerr;
3956 Double_t uvt[4];
3957 if(!tracklet || !tracklet->IsOK()) return;
3958 Double_t tilt = tracklet->GetTilt();
3959 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
3960 if(!(cl = tracklet->GetClusters(itb))) continue;
3961 if(!cl->IsInChamber()) continue;
3962 if (!tracklet->IsUsable(itb)) continue;
3963 x = cl->GetX();
3964 y = cl->GetY();
3965 z = cl->GetZ();
3966 dx = x - fXref;
3967 // Transformation
3968 t = 1./(x*x + y*y);
3969 uvt[0] = 2. * x * t;
3970 uvt[1] = t;
3971 uvt[2] = 2. * tilt * t;
3972 uvt[3] = 2. * tilt * dx * t;
3973 w = 2. * (y + tilt*z) * t;
3974 // error definition changes for the different calls
3975 we = 2. * t;
3976 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
3977 // Update sums for error calculation
3978 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
3979 yerr *= yerr;
3980 zerr = 1./cl->GetSigmaZ2();
3981 for(Int_t ipol = 0; ipol < 5; ipol++){
3982 fSumPolY[ipol] += yerr;
3983 yerr *= x;
3984 if(ipol < 3){
3985 fSumPolZ[ipol] += zerr;
3986 zerr *= x;
3987 }
3988 }
3989 fTrackFitter->AddPoint(uvt, w, we);
3990 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
3991 }
3992}
3993
3994//_____________________________________________________________________________
3995Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
3996 //
3997 // Check whether z-results are acceptable
3998 // Definition: Distance between tracklet fit and track fit has to be
3999 // less then half a padlength
4000 // Point of comparision is at the anode wire
4001 //
4002 Bool_t acceptablez = kTRUE;
4003 Double_t zref = 0.0;
4004 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
4005 if(!fTracklets[iLayer]->IsOK()) continue;
4006 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
4007 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
4008 acceptablez = kFALSE;
4009 }
4010 return acceptablez;
4011}
4012
4013//_____________________________________________________________________________
4014Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
4015 //
4016 // Calculate y position out of the track parameters
4017 // y: R^2 = (x - x0)^2 + (y - y0)^2
4018 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
4019 // R = Sqrt() = 1/Curvature
4020 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
4021 //
4022 Double_t y = 0;
4023 Double_t disc = (x * fParameters[0] + fParameters[1]);
4024 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
4025 if (disc >= 0) {
4026 disc = TMath::Sqrt(disc);
4027 y = (1.0 - disc) / fParameters[0];
4028 }
4029 return y;
4030}
4031
4032//_____________________________________________________________________________
4033Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4034 //
4035 // Return z position for a given x position
4036 // Simple linear function
4037 //
4038 return fParameters[3] + fParameters[4] * (x - fXref);
4039}
4040
4041//_____________________________________________________________________________
4042Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4043 //
4044 // Calculate dydx at a given radial position out of the track parameters
4045 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4046 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4047 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4048 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4049 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4050 //
4051 Double_t x0 = -fParameters[1] / fParameters[0];
4052 Double_t curvature = GetCurvature();
4053 Double_t dy = 0;
4054 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4055 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4056 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4057 if (fParameters[0] < 0) yderiv *= -1.0;
4058 dy = yderiv;
4059 }
4060 }
4061 return dy;
4062}
4063
4064//_____________________________________________________________________________
4065Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4066 //
4067 // Calculate track curvature
4068 //
4069 //
4070 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4071 if (curvature > 0.0)
4072 curvature = fParameters[0] / TMath::Sqrt(curvature);
4073 return curvature;
4074}
4075
4076//_____________________________________________________________________________
4077void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4078 //
4079 // Error Definition according to gauss error propagation
4080 //
4081 TMatrixD transform(3,3);
4082 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4083 transform(0,1) = transform(1,2) = x;
4084 transform(0,2) = x*x;
4085 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4086 covariance *= transform.T();
4087 cov[0] = covariance(0,0);
4088 TMatrixD transformZ(2,2);
4089 transformZ(0,0) = transformZ(1,1) = 1;
4090 transformZ(0,1) = x;
4091 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4092 covarZ *= transformZ.T();
4093 cov[1] = covarZ(0,0);
4094 cov[2] = 0;
4095}
4096
4097//____________________________________________________________________
4098Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4099 //
4100 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4101 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4102 // are taken into account
4103 //
4104 // Parameters: - Array of tracklets(AliTRDseedV1)
4105 //
4106 // Output: - The reference x-position(Float_t)
4107 //
4108 Int_t nDistances = 0;
4109 Float_t meanDistance = 0.;
4110 Int_t startIndex = 5;
4111 for(Int_t il =5; il > 0; il--){
4112 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4113 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4114 meanDistance += xdiff;
4115 nDistances++;
4116 }
4117 if(fTracklets[il]->IsOK()) startIndex = il;
4118 }
4119 if(fTracklets[0]->IsOK()) startIndex = 0;
4120 if(!nDistances){
4121 // We should normally never get here
4122 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4123 Int_t iok = 0, idiff = 0;
4124 // This attempt is worse and should be avoided:
4125 // check for two chambers which are OK and repeat this without taking the mean value
4126 // Strategy avoids a division by 0;
4127 for(Int_t il = 5; il >= 0; il--){
4128 if(fTracklets[il]->IsOK()){
4129 xpos[iok] = fTracklets[il]->GetX0();
4130 iok++;
4131 startIndex = il;
4132 }
4133 if(iok) idiff++; // to get the right difference;
4134 if(iok > 1) break;
4135 }
4136 if(iok > 1){
4137 meanDistance = (xpos[0] - xpos[1])/idiff;
4138 }
4139 else{
4140 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4141 return 331.;
4142 }
4143 }
4144 else{
4145 meanDistance /= nDistances;
4146 }
4147 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
4148}