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