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