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