1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
23 // Alex Bercuci <A.Bercuci@gsi.de> //
24 // Markus Fasel <M.Fasel@gsi.de> //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include <TDirectory.h>
30 #include <TLinearFitter.h>
32 #include <TClonesArray.h>
33 #include <TTreeStream.h>
34 #include <TGeoMatrix.h>
35 #include <TGeoManager.h>
38 #include "AliMathBase.h"
39 #include "AliESDEvent.h"
40 #include "AliGeomManager.h"
41 #include "AliRieman.h"
42 #include "AliTrackPointArray.h"
44 #include "AliTRDgeometry.h"
45 #include "AliTRDpadPlane.h"
46 #include "AliTRDcalibDB.h"
47 #include "AliTRDReconstructor.h"
48 #include "AliTRDCalibraFillHisto.h"
49 #include "AliTRDrecoParam.h"
51 #include "AliTRDcluster.h"
52 #include "AliTRDdigitsParam.h"
53 #include "AliTRDseedV1.h"
54 #include "AliTRDtrackV1.h"
55 #include "AliTRDtrackerV1.h"
56 #include "AliTRDtrackerDebug.h"
57 #include "AliTRDtrackingChamber.h"
58 #include "AliTRDchamberTimeBin.h"
60 ClassImp(AliTRDtrackerV1)
61 ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62 ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
64 AliTRDtrackerV1::ETRDtrackerV1BetheBloch AliTRDtrackerV1::fgBB = AliTRDtrackerV1::kGeant;
65 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
66 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
67 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
68 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
70 const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
71 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
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
74 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
75 AliRieman* AliTRDtrackerV1::fgRieman = NULL;
76 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
77 TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
79 //____________________________________________________________________
80 AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
82 ,fkReconstructor(NULL)
93 // Default constructor.
96 SetReconstructor(rec); // initialize reconstructor
98 // initialize geometry
99 if(!AliGeomManager::GetGeometry()){
100 AliFatal("Could not get geometry.");
102 fGeom = new AliTRDgeometry();
103 fGeom->CreateClusterMatrixArray();
104 TGeoHMatrix *matrix = NULL;
105 Double_t loc[] = {0., 0., 0.};
106 Double_t glb[] = {0., 0., 0.};
107 for(Int_t ily=kNPlanes; ily--;){
109 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
111 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
112 fR[ily] = fgkX0[ily];
115 matrix->LocalToMaster(loc, glb);
116 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
119 // initialize cluster containers
120 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
123 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
124 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
125 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
126 fTracksESD = new TClonesArray("AliESDtrack", 2*kMaxTracksStack);
127 fTracksESD->SetOwner();
130 //____________________________________________________________________
131 AliTRDtrackerV1::~AliTRDtrackerV1()
137 if(fgRieman) delete fgRieman; fgRieman = NULL;
138 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
139 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
140 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
141 if(fTracksESD){ fTracksESD->Delete(); delete fTracksESD; }
142 if(fTracks) {fTracks->Delete(); delete fTracks;}
143 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
145 fClusters->Delete(); delete fClusters;
147 if(fGeom) delete fGeom;
150 //____________________________________________________________________
151 Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
154 // Steering stand alone tracking for full TRD detector
157 // esd : The ESD event. On output it contains
158 // the ESD tracks found in TRD.
161 // Number of tracks found in the TRD detector.
163 // Detailed description
164 // 1. Launch individual SM trackers.
165 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
169 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
173 //AliInfo("Start Track Finder ...");
175 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
176 // for(int ism=1; ism<2; ism++){
177 //AliInfo(Form("Processing supermodule %i ...", ism));
178 ntracks += Clusters2TracksSM(ism, esd);
180 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
185 //_____________________________________________________________________________
186 Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
188 //AliInfo(Form("Asking for tracklet %d", index));
190 // reset position of the point before using it
191 p.SetXYZ(0., 0., 0.);
192 AliTRDseedV1 *tracklet = GetTracklet(index);
193 if (!tracklet) return kFALSE;
195 // get detector for this tracklet
196 Int_t det = tracklet->GetDetector();
197 Int_t sec = fGeom->GetSector(det);
198 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
199 sinA = TMath::Sin(alpha),
200 cosA = TMath::Cos(alpha);
202 local[0] = tracklet->GetX();
203 local[1] = tracklet->GetY();
204 local[2] = tracklet->GetZ();
206 fGeom->RotateBack(det, local, global);
208 Double_t cov2D[3]; Float_t cov[6];
209 tracklet->GetCovAt(local[0], cov2D);
210 cov[0] = cov2D[0]*sinA*sinA;
211 cov[1] =-cov2D[0]*sinA*cosA;
212 cov[2] =-cov2D[1]*sinA;
213 cov[3] = cov2D[0]*cosA*cosA;
214 cov[4] = cov2D[1]*cosA;
216 // store the global position of the tracklet and its covariance matrix in the track point
217 p.SetXYZ(global[0],global[1],global[2], cov);
220 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
221 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
222 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
223 p.SetVolumeID(volid);
228 //____________________________________________________________________
229 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
231 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
232 return fgTiltedRieman;
235 //____________________________________________________________________
236 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
238 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
239 return fgTiltedRiemanConstrained;
242 //____________________________________________________________________
243 AliRieman* AliTRDtrackerV1::GetRiemanFitter()
245 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
249 //_____________________________________________________________________________
250 Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
252 // Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
253 // a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
254 // covariance, PID, etc.) are than used to update the corresponding ESD track.
255 // Each track seed is first propagated to the geometrical limit of the TRD detector.
256 // Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
257 // constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
258 // Otherwise the ESD track is left unchanged.
260 // The following steps are performed:
261 // 1. Selection of tracks based on the variance in the y-z plane.
262 // 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
263 // 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
264 // the following status bits:
265 // - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
266 // - AliESDtrack::kTRDStop - if the tracks fails propagation
267 // - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
268 // 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
269 // 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
272 if(!fClusters || !fClusters->GetEntriesFast()){
273 AliInfo("No TRD clusters");
276 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
277 if (!calibra) AliInfo("Could not get Calibra instance");
278 if (!fgNTimeBins) fgNTimeBins = fkReconstructor->GetNTimeBins();
281 Int_t nFound = 0, // number of tracks found
282 nBacked = 0, // number of tracks backed up for refit
283 nSeeds = 0, // total number of ESD seeds
284 nTRDseeds= 0, // number of seeds in the TRD acceptance
285 nTPCseeds= 0; // number of TPC seeds
286 Float_t foundMin = 20.0;
288 Float_t *quality = NULL;
290 fEventInFile = event->GetEventNumberInFile();
291 nSeeds = event->GetNumberOfTracks();
292 // Sort tracks according to quality
293 // (covariance in the yz plane)
295 quality = new Float_t[nSeeds];
296 index = new Int_t[4*nSeeds];
297 for (Int_t iSeed = nSeeds; iSeed--;) {
298 AliESDtrack *seed = event->GetTrack(iSeed);
299 Double_t covariance[15];
300 seed->GetExternalCovariance(covariance);
301 quality[iSeed] = covariance[0] + covariance[2];
303 TMath::Sort(nSeeds, quality, index,kFALSE);
306 // Propagate all seeds
309 for (Int_t iSeed = 0; iSeed < nSeeds; iSeed++) {
311 // Get the seeds in sorted sequence
312 AliESDtrack *seed = event->GetTrack(index[iSeed]);
313 Float_t p4 = seed->GetC(seed->GetBz());
315 // Check the seed status
316 ULong_t status = seed->GetStatus();
317 if ((status & AliESDtrack::kTPCout) == 0) continue;
318 if ((status & AliESDtrack::kTRDout) != 0) continue;
320 // Propagate to the entrance in the TRD mother volume
321 track.~AliTRDtrackV1();
322 new(&track) AliTRDtrackV1(*seed);
323 if(AliTRDgeometry::GetXtrdBeg() > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), AliTRDReconstructor::GetMaxStep())){
324 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
327 if(!AdjustSector(&track)){
328 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
331 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
332 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
336 AliDebug(2, Form("TRD propagate TPC seed[%d] = %d.", iSeed, index[iSeed]));
337 // store track status at TRD entrance
338 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
340 // prepare track and do propagation in the TRD
341 track.SetReconstructor(fkReconstructor);
342 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
343 track.SetPrimary(status & AliESDtrack::kTPCin);
344 expectedClr = FollowBackProlongation(track);
345 // check if track entered the TRD fiducial volume
346 if(track.GetTrackIn()){
347 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
350 // check if track was stopped in the TRD
352 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
358 // computes PID for track
360 // update calibration references using this track
361 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
362 // save calibration object
363 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0) {
364 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
365 calibTrack->SetOwner();
366 seed->AddCalibObject(calibTrack);
369 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
370 track.UpdateESDtrack(seed);
373 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
375 // Make backup for back propagation
376 Int_t foundClr = track.GetNumberOfClusters();
377 if (foundClr >= foundMin) {
378 track.CookLabel(1. - AliTRDReconstructor::GetLabelFraction());
379 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
381 // Sign only gold tracks
382 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
383 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
385 Bool_t isGold = kFALSE;
388 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
389 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
395 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
396 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
397 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
402 if ((!isGold) && (track.GetBackupTrack())) {
403 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
404 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
412 // Propagation to the TOF
413 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
414 Int_t sm = track.GetSector();
415 // default value in case we have problems with the geometry.
416 Double_t xtof = 371.;
417 //Calculate radial position of the beginning of the TOF
418 //mother volume. In order to avoid mixing of the TRD
419 //and TOF modules some hard values are needed. This are:
420 //1. The path to the TOF module.
421 //2. The width of the TOF (29.05 cm)
422 //(with the help of Annalisa de Caro Mar-17-2009)
424 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
425 TGeoHMatrix *m = NULL;
426 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
428 if((m=gGeoManager->GetCurrentMatrix())){
429 m->LocalToMaster(loc, glob);
430 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
433 if(xtof > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, xtof, AliTRDReconstructor::GetMaxStep())){
434 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
437 if(!AdjustSector(&track)){
438 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
441 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
442 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
445 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
446 // TODO obsolete - delete
447 seed->SetTRDQuality(track.StatusForTOF());
449 seed->SetTRDBudget(track.GetBudget(0));
451 if(index) delete [] index;
452 if(quality) delete [] quality;
454 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
455 AliInfo(Form("Number of tracks: TRDout[%d] TRDbackup[%d]", nFound, nBacked));
457 // run stand alone tracking
458 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
464 //____________________________________________________________________
465 Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
468 // Refits tracks within the TRD. The ESD event is expected to contain seeds
469 // at the outer part of the TRD.
470 // The tracks are propagated to the innermost time bin
471 // of the TRD and the ESD event is updated
472 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
475 Int_t nseed = 0; // contor for loaded seeds
476 Int_t found = 0; // contor for updated TRD tracks
479 if(!fClusters || !fClusters->GetEntriesFast()){
480 AliInfo("No TRD clusters");
484 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
485 AliESDtrack *seed = event->GetTrack(itrack);
486 ULong_t status = seed->GetStatus();
488 new(&track) AliTRDtrackV1(*seed);
489 if (track.GetX() < 270.0) {
490 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
494 // reject tracks which failed propagation in the TRD or
495 // are produced by the TRD stand alone tracker
496 if(!(status & AliESDtrack::kTRDout)) continue;
497 if(!(status & AliESDtrack::kTRDin)) continue;
500 track.ResetCovariance(50.0);
502 // do the propagation and processing
503 Bool_t kUPDATE = kFALSE;
504 Double_t xTPC = 250.0;
505 if(FollowProlongation(track)){
506 // Update the friend track
507 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
508 TObject *o = NULL; Int_t ic = 0;
509 AliTRDtrackV1 *calibTrack = NULL;
510 while((o = seed->GetCalibObject(ic++))){
511 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
512 calibTrack->SetTrackOut(&track);
517 if (PropagateToX(track, xTPC, AliTRDReconstructor::GetMaxStep())) { // -with update
518 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
524 // Prolongate to TPC without update
526 AliTRDtrackV1 tt(*seed);
527 if (PropagateToX(tt, xTPC, AliTRDReconstructor::GetMaxStep())) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
530 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
531 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
536 //____________________________________________________________________
537 Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
539 // Extrapolates the TRD track in the TPC direction.
542 // t : the TRD track which has to be extrapolated
545 // number of clusters attached to the track
547 // Detailed description
549 // Starting from current radial position of track <t> this function
550 // extrapolates the track through the 6 TRD layers. The following steps
551 // are being performed for each plane:
553 // a. get plane limits in the local x direction
554 // b. check crossing sectors
555 // c. check track inclination
556 // 2. search tracklet in the tracker list (see GetTracklet() for details)
557 // 3. evaluate material budget using the geo manager
558 // 4. propagate and update track using the tracklet information.
563 Int_t nClustersExpected = 0;
564 for (Int_t iplane = kNPlanes; iplane--;) {
566 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
567 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
568 if(!tracklet) continue;
569 if(!tracklet->IsOK()){
570 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
573 Double_t x = tracklet->GetX();//GetX0();
574 // reject tracklets which are not considered for inward refit
575 if(x > t.GetX()+AliTRDReconstructor::GetMaxStep()) continue;
577 // append tracklet to track
578 t.SetTracklet(tracklet, index);
580 if (x < (t.GetX()-AliTRDReconstructor::GetMaxStep()) && !PropagateToX(t, x+AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) break;
581 if (!AdjustSector(&t)) break;
583 // Start global position
587 // End global position
588 Double_t alpha = t.GetAlpha(), y, z;
589 if (!t.GetProlongation(x,y,z)) break;
591 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
592 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
595 Double_t length = TMath::Sqrt(
596 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
597 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
598 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
601 // Get material budget
603 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
604 Double_t xrho= param[0]*param[4];
605 Double_t xx0 = param[1]; // Get mean propagation parameters
607 // Propagate and update
608 t.PropagateTo(x, xx0, xrho);
609 if (!AdjustSector(&t)) break;
612 Double_t cov[3]; tracklet->GetCovAt(x, cov);
613 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
614 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
615 if (chi2 < 1e+10 && ((AliExternalTrackParam&)t).Update(p, cov)){
616 // Register info to track
617 t.SetNumberOfClusters();
619 nClustersExpected += tracklet->GetN();
623 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
625 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
626 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
627 if(!tracklet) continue;
628 t.SetTracklet(tracklet, index);
631 if(fkReconstructor->IsDebugStreaming()){
632 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
633 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
634 AliTRDtrackV1 track(t);
636 cstreamer << "FollowProlongation"
637 << "EventNumber=" << eventNumber
638 << "ncl=" << nClustersExpected
639 << "track.=" << &track
643 return nClustersExpected;
647 //_____________________________________________________________________________
648 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
650 // Extrapolates/Build the TRD track in the TOF direction.
653 // t : the TRD track which has to be extrapolated
656 // number of clusters attached to the track
658 // Starting from current radial position of track <t> this function
659 // extrapolates the track through the 6 TRD layers. The following steps
660 // are being performed for each plane:
661 // 1. Propagate track to the entrance of the next chamber:
662 // - get chamber limits in the radial direction
663 // - check crossing sectors
664 // - check track inclination
665 // - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
666 // 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
667 // Kalman filter is needed and tracklets are already linked to the track this step is skipped.
668 // 3. Fit tracklet using the information from the Kalman filter.
669 // 4. Propagate and update track at reference radial position of the tracklet.
670 // 5. Register tracklet with the tracker and track; update pulls monitoring.
673 // 1. During the propagation a bit map is filled detailing the status of the track in each TRD chamber. The following errors are being registered for each tracklet:
674 // - AliTRDtrackV1::kProlongation : track prolongation failed
675 // - AliTRDtrackV1::kPropagation : track prolongation failed
676 // - AliTRDtrackV1::kAdjustSector : failed during sector crossing
677 // - AliTRDtrackV1::kSnp : too large bending
678 // - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
679 // - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
680 // - AliTRDtrackV1::kUnknown : anything which is not covered before
681 // 2. By default the status of the track before first TRD update is saved.
686 // Alexandru Bercuci <A.Bercuci@gsi.de>
690 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
691 AliTRDtrackingChamber *chamber = NULL;
693 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
694 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
696 Bool_t kStoreIn(kTRUE), // toggel store track params. at TRD entry
697 kStandAlone(kFALSE), // toggle tracker awarness of stand alone seeding
698 kUseTRD(fkRecoParam->IsOverPtThreshold(t.Pt()));// use TRD measurment to update Kalman
701 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
702 // Special case for stand alone tracking
703 // - store all tracklets found by seeding
704 // - start propagation from first tracklet found
705 AliTRDseedV1 *tracklets[kNPlanes];
706 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
707 for(Int_t ip(kNPlanes); ip--;){
708 if(!(tracklets[ip] = t.GetTracklet(ip))) continue;
710 if(tracklets[ip]->IsOK()) startLayer=ip;
714 AliDebug(4, Form("SA[%c] Start[%d]\n"
715 " [0]idx[%d] traklet[%p]\n"
716 " [1]idx[%d] traklet[%p]\n"
717 " [2]idx[%d] traklet[%p]\n"
718 " [3]idx[%d] traklet[%p]\n"
719 " [4]idx[%d] traklet[%p]\n"
720 " [5]idx[%d] traklet[%p]"
721 , kStandAlone?'y':'n', startLayer
722 , t.GetTrackletIndex(0), (void*)tracklets[0]
723 , t.GetTrackletIndex(1), (void*)tracklets[1]
724 , t.GetTrackletIndex(2), (void*)tracklets[2]
725 , t.GetTrackletIndex(3), (void*)tracklets[3]
726 , t.GetTrackletIndex(4), (void*)tracklets[4]
727 , t.GetTrackletIndex(5), (void*)tracklets[5]));
729 // Loop through the TRD layers
730 TGeoHMatrix *matrix = NULL;
731 Double_t x(0.), y(0.), z(0.);
732 for (Int_t ily=startLayer, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
733 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
735 // rough estimate of the entry point
736 if (!t.GetProlongation(fR[ily], y, z)){
738 t.SetStatus(AliTRDtrackV1::kProlongation);
739 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
743 // find sector / stack / detector
745 // TODO cross check with y value !
746 stk = fGeom->GetStack(z, ily);
747 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
748 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
750 // check if supermodule/chamber is installed
751 if( !fGeom->GetSMstatus(sm) ||
753 fGeom->IsHole(ily, stk, sm) ||
755 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
756 // propagate to the default radial position
757 if(fR[ily] > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, fR[ily], AliTRDReconstructor::GetMaxStep())){
759 t.SetStatus(AliTRDtrackV1::kPropagation);
760 AliDebug(4, "Failed Propagation [Missing Geometry]");
763 if(!AdjustSector(&t)){
765 t.SetStatus(AliTRDtrackV1::kAdjustSector);
766 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
769 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
771 t.SetStatus(AliTRDtrackV1::kSnp);
772 AliDebug(4, "Failed Max Snp [Missing Geometry]");
775 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
779 // retrieve rotation matrix for the current chamber
780 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
781 Double_t glb[] = {0., 0., 0.};
782 matrix->LocalToMaster(loc, glb);
783 AliDebug(3, Form("Propagate to det[%3d] x_anode[%7.2f] (%f %f)", det, glb[0]+driftLength, glb[1], glb[2]));
785 // Propagate to the radial distance of the current layer
786 x = glb[0] - AliTRDReconstructor::GetMaxStep();
787 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())){
789 t.SetStatus(AliTRDtrackV1::kPropagation);
790 AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
793 if(!AdjustSector(&t)){
795 t.SetStatus(AliTRDtrackV1::kAdjustSector);
796 AliDebug(4, "Failed Adjust Sector Start");
799 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
801 t.SetStatus(AliTRDtrackV1::kSnp);
802 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
805 Bool_t doRecalculate = kFALSE;
806 if(sm != t.GetSector()){
808 doRecalculate = kTRUE;
810 if(stk != fGeom->GetStack(z, ily)){
811 stk = fGeom->GetStack(z, ily);
812 doRecalculate = kTRUE;
815 det = AliTRDgeometry::GetDetector(ily, stk, sm);
816 if(!(matrix = fGeom->GetClusterMatrix(det))){
817 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
818 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
821 matrix->LocalToMaster(loc, glb);
822 x = glb[0] - AliTRDReconstructor::GetMaxStep();
825 // check if track is well inside fiducial volume
826 if (!t.GetProlongation(x+AliTRDReconstructor::GetMaxStep(), y, z)) {
828 t.SetStatus(AliTRDtrackV1::kProlongation);
829 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+AliTRDReconstructor::GetMaxStep(), y, z));
832 if(fGeom->IsOnBoundary(det, y, z, .5)){
833 t.SetStatus(AliTRDtrackV1::kBoundary, ily);
834 AliDebug(4, "Failed Track on Boundary");
838 ptrTracklet = tracklets[ily];
839 if(!ptrTracklet){ // BUILD TRACKLET
840 AliDebug(3, Form("Building tracklet det[%d]", det));
841 // check data in supermodule
842 if(!fTrSec[sm].GetNChambers()){
843 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
844 AliDebug(4, "Failed NoClusters");
847 if(fTrSec[sm].GetX(ily) < 1.){
848 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
849 AliDebug(4, "Failed NoX");
853 // check data in chamber
854 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
855 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
856 AliDebug(4, "Failed No Detector");
859 if(chamber->GetNClusters() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
860 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
861 AliDebug(4, "Failed Not Enough Clusters in Detector");
865 tracklet.~AliTRDseedV1();
866 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
867 ptrTracklet->SetReconstructor(fkReconstructor);
868 ptrTracklet->SetKink(t.IsKink());
869 ptrTracklet->SetPrimary(t.IsPrimary());
870 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
871 ptrTracklet->SetX0(glb[0]+driftLength);
872 if(!ptrTracklet->Init(&t)){
874 t.SetStatus(AliTRDtrackV1::kTrackletInit);
875 AliDebug(4, "Failed Tracklet Init");
878 // Select attachment base on track to B field sign not only track charge which is buggy
879 // mark kFALSE same sign tracks and kTRUE opposite sign tracks
880 // A.Bercuci 3.11.2011
881 Float_t prod(t.GetBz()*t.Charge());
882 if(!ptrTracklet->AttachClusters(chamber, kTRUE, prod<0.?kTRUE:kFALSE, fEventInFile)){
883 t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
885 AliTRDseedV1 trackletCp(*ptrTracklet);
886 UChar_t status(t.GetStatusTRD(ily));
887 (*cstreamer) << "FollowBackProlongation4"
888 <<"status=" << status
889 <<"tracklet.=" << &trackletCp
892 AliDebug(4, "Failed Attach Clusters");
895 AliDebug(3, Form("Number of Clusters in Tracklet: %d", ptrTracklet->GetN()));
896 if(ptrTracklet->GetN() < fgNTimeBins*fkRecoParam->GetFindableClusters()){
897 t.SetStatus(AliTRDtrackV1::kNoClustersTracklet, ily);
899 AliTRDseedV1 trackletCp(*ptrTracklet);
900 UChar_t status(t.GetStatusTRD(ily));
901 (*cstreamer) << "FollowBackProlongation4"
902 <<"status=" << status
903 <<"tracklet.=" << &trackletCp
906 AliDebug(4, "Failed N Clusters Attached");
909 ptrTracklet->UpdateUsed();
910 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
911 // propagate track to the radial position of the tracklet
914 // tilt correction options
916 // 2 : pseudo tilt correction
917 if(!ptrTracklet->FitRobust(t.Charge()>0?kTRUE:kFALSE)){
918 t.SetStatus(AliTRDtrackV1::kNoFit, ily);
919 AliDebug(4, "Failed Tracklet Fit");
922 x = ptrTracklet->GetX(); //GetX0();
923 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())) {
925 t.SetStatus(AliTRDtrackV1::kPropagation);
926 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
929 if(!AdjustSector(&t)) {
931 t.SetStatus(AliTRDtrackV1::kAdjustSector);
932 AliDebug(4, "Failed Adjust Sector");
935 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
937 t.SetStatus(AliTRDtrackV1::kSnp);
938 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
941 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
942 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
943 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
944 // update Kalman with the TRD measurement
945 if(chi2>1e+10){ // TODO
946 t.SetStatus(AliTRDtrackV1::kChi2, ily);
948 UChar_t status(t.GetStatusTRD());
949 AliTRDseedV1 trackletCp(*ptrTracklet);
950 AliTRDtrackV1 trackCp(t);
952 (*cstreamer) << "FollowBackProlongation3"
953 << "status=" << status
954 << "tracklet.=" << &trackletCp
955 << "track.=" << &trackCp
958 AliDebug(4, Form("Failed Chi2[%f]", chi2));
961 // mark track as entering the FIDUCIAL volume of TRD
967 if(!((AliExternalTrackParam&)t).Update(p, cov)) {
969 t.SetStatus(AliTRDtrackV1::kUpdate);
971 UChar_t status(t.GetStatusTRD());
972 AliTRDseedV1 trackletCp(*ptrTracklet);
973 AliTRDtrackV1 trackCp(t);
975 (*cstreamer) << "FollowBackProlongation3"
976 << "status=" << status
977 << "tracklet.=" << &trackletCp
978 << "track.=" << &trackCp
981 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]));
985 if(!kStandAlone) ptrTracklet->UseClusters();
987 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
990 // register tracklet with the tracker and track
991 // Save inside the tracklet the track parameters BEFORE track update.
992 // Commented out their overwriting AFTER track update
993 // A.Bercuci 3.11.2011
994 //ptrTracklet->Update(&t);
995 ptrTracklet = SetTracklet(ptrTracklet);
996 Int_t index(fTracklets->GetEntriesFast()-1);
997 t.SetTracklet(ptrTracklet, index);
998 // Register info to track
999 t.SetNumberOfClusters();
1002 n += ptrTracklet->GetN();
1003 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
1005 // Reset material budget if 2 consecutive gold
1006 // if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
1008 // Make backup of the track until is gold
1010 if(!kStandAlone && (failed = t.MakeBackupTrack())) AliDebug(2, Form("Failed backup on cut[%d]", failed));
1012 } // end layers loop
1013 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
1014 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
1016 if(n && debugLevel > 1){
1017 //Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1018 AliTRDtrackV1 track(t);
1020 (*cstreamer) << "FollowBackProlongation2"
1021 << "EventNumber=" << fEventInFile
1022 << "track.=" << &track
1029 //_________________________________________________________________________
1030 Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
1032 // Fits a Riemann-circle to the given points without tilting pad correction.
1033 // The fit is performed using an instance of the class AliRieman (equations
1034 // and transformations see documentation of this class)
1035 // Afterwards all the tracklets are Updated
1037 // Parameters: - Array of tracklets (AliTRDseedV1)
1038 // - Storage for the chi2 values (beginning with direction z)
1039 // - Seeding configuration
1040 // Output: - The curvature
1042 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1044 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1045 Int_t *ppl = &allplanes[0];
1046 Int_t maxLayers = 6;
1051 for(Int_t il = 0; il < maxLayers; il++){
1052 if(!tracklets[ppl[il]].IsOK()) continue;
1053 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
1056 // Set the reference position of the fit and calculate the chi2 values
1057 memset(chi2, 0, sizeof(Double_t) * 2);
1058 for(Int_t il = 0; il < maxLayers; il++){
1059 // Reference positions
1060 tracklets[ppl[il]].Init(fitter);
1063 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1064 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1065 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1067 return fitter->GetC();
1070 //_________________________________________________________________________
1071 void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1074 // Performs a Riemann helix fit using the seedclusters as spacepoints
1075 // Afterwards the chi2 values are calculated and the seeds are updated
1077 // Parameters: - The four seedclusters
1078 // - The tracklet array (AliTRDseedV1)
1079 // - The seeding configuration
1084 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1086 for(Int_t i = 0; i < 4; i++){
1087 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1092 // Update the seed and calculated the chi2 value
1093 chi2[0] = 0; chi2[1] = 0;
1094 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1096 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1097 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1102 //_________________________________________________________________________
1103 Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1106 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1107 // assumed that the vertex position is set to 0.
1108 // This method is very usefull for high-pt particles
1109 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1110 // x0, y0: Center of the circle
1111 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1112 // zc: center of the pad row
1113 // Equation which has to be fitted (after transformation):
1114 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1116 // t = 1/(x^2 + y^2)
1118 // v = 2 * x * tan(phiT) * t
1119 // Parameters in the equation:
1120 // a = -1/y0, b = x0/y0, e = dz/dx
1122 // The Curvature is calculated by the following equation:
1123 // - curv = a/Sqrt(b^2 + 1) = 1/R
1124 // Parameters: - the 6 tracklets
1125 // - the Vertex constraint
1126 // Output: - the Chi2 value of the track
1131 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1132 fitter->StoreData(kTRUE);
1133 fitter->ClearPoints();
1134 AliTRDcluster *cl = NULL;
1136 Float_t x, y, z, w, t, error, tilt;
1139 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1140 if(!tracklets[ilr].IsOK()) continue;
1141 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1142 if(!tracklets[ilr].IsUsable(itb)) continue;
1143 if(!(cl = tracklets[ilr].GetClusters(itb))) continue;
1144 if(!cl->IsInChamber()) continue;
1148 tilt = tracklets[ilr].GetTilt();
1150 t = 1./(x * x + y * y);
1151 uvt[0] = 2. * x * t;
1152 uvt[1] = 2. * x * t * tilt ;
1153 w = 2. * (y + tilt * (z - zVertex)) * t;
1154 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
1155 fitter->AddPoint(uvt, w, error);
1161 // Calculate curvature
1162 Double_t a = fitter->GetParameter(0);
1163 Double_t b = fitter->GetParameter(1);
1164 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1166 Float_t chi2track = 0.0;
1168 chi2track = fitter->GetChisquare()/Double_t(nPoints);
1170 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
1171 tracklets[ip].SetC(curvature, 1);
1173 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRiemanConstraint: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
1175 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
1176 //Linear Model on z-direction
1177 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1178 Double_t slope = fitter->GetParameter(2);
1179 Double_t zref = slope * xref;
1180 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1181 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1182 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1183 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
1184 treeStreamer << "FitTiltedRiemanConstraint"
1185 << "EventNumber=" << eventNumber
1186 << "CandidateNumber=" << candidateNumber
1187 << "Curvature=" << curvature
1188 << "Chi2Track=" << chi2track
1189 << "Chi2Z=" << chi2Z
1196 //_________________________________________________________________________
1197 Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1200 // Performs a Riemann fit taking tilting pad correction into account
1201 // The equation of a Riemann circle, where the y position is substituted by the
1202 // measured y-position taking pad tilting into account, has to be transformed
1203 // into a 4-dimensional hyperplane equation
1204 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1205 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1206 // zc: center of the pad row
1207 // zt: z-position of the track
1208 // The z-position of the track is assumed to be linear dependent on the x-position
1209 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1210 // Transformation: u = 2 * x * t
1211 // v = 2 * tan(phiT) * t
1212 // w = 2 * tan(phiT) * (x - xref) * t
1213 // t = 1 / (x^2 + ymeas^2)
1214 // Parameters: a = -1/y0
1216 // c = (R^2 -x0^2 - y0^2)/y0
1219 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1220 // results from the simple riemann fit. Afterwards the fit is redone.
1221 // The curvature is calculated according to the formula:
1222 // curv = a/(1 + b^2 + c*a) = 1/R
1224 // Paramters: - Array of tracklets (connected to the track candidate)
1225 // - Flag selecting the error definition
1226 // Output: - Chi2 values of the track (in Parameter list)
1228 TLinearFitter *fitter = GetTiltedRiemanFitter();
1229 fitter->StoreData(kTRUE);
1230 fitter->ClearPoints();
1231 AliTRDLeastSquare zfitter;
1232 AliTRDcluster *cl = NULL;
1234 Double_t xref = CalculateReferenceX(tracklets);
1235 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1236 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1237 memset(sumPolY, 0, sizeof(Double_t) * 5);
1238 memset(sumPolZ, 0, sizeof(Double_t) * 3);
1240 // Containers for Least-square fitter
1241 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1242 if(!tracklets[ipl].IsOK()) continue;
1243 tilt = tracklets[ipl].GetTilt();
1244 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1245 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1246 if(!cl->IsInChamber()) continue;
1247 if (!tracklets[ipl].IsUsable(itb)) continue;
1254 uvt[0] = 2. * x * t;
1256 uvt[2] = 2. * tilt * t;
1257 uvt[3] = 2. * tilt * dx * t;
1258 w = 2. * (y + tilt*z) * t;
1259 // error definition changes for the different calls
1261 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
1262 fitter->AddPoint(uvt, w, we);
1263 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1264 // adding points for covariance matrix estimation
1265 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1267 errz = 1./cl->GetSigmaZ2();
1268 for(Int_t ipol = 0; ipol < 5; ipol++){
1269 sumPolY[ipol] += erry;
1272 sumPolZ[ipol] += errz;
1279 if (fitter->Eval()) return 1.e10;
1282 Double_t offset = fitter->GetParameter(3);
1283 Double_t slope = fitter->GetParameter(4);
1285 // Linear fitter - not possible to make boundaries
1286 // Do not accept non possible z and dzdx combinations
1287 Bool_t acceptablez = kTRUE;
1288 Double_t zref = 0.0;
1289 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1290 if(!tracklets[iLayer].IsOK()) continue;
1291 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
1292 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1293 acceptablez = kFALSE;
1296 Double_t dzmf = zfitter.GetFunctionParameter(1);
1297 Double_t zmf = zfitter.GetFunctionValue(&xref);
1298 fgTiltedRieman->FixParameter(3, zmf);
1299 fgTiltedRieman->FixParameter(4, dzmf);
1301 fitter->ReleaseParameter(3);
1302 fitter->ReleaseParameter(4);
1303 offset = fitter->GetParameter(3);
1304 slope = fitter->GetParameter(4);
1307 // Calculate Curvarture
1308 Double_t a = fitter->GetParameter(0);
1309 Double_t b = fitter->GetParameter(1);
1310 Double_t c = fitter->GetParameter(2);
1311 Double_t curvature = 1.0 + b*b - c*a;
1312 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1314 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1316 // Prepare error calculation
1317 TMatrixD covarPolY(3,3);
1318 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1319 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1320 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1321 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1323 TMatrixD covarPolZ(2,2);
1324 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1325 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1328 // Update the tracklets
1329 Double_t x1, dy, dz;
1331 memset(cov, 0, sizeof(Double_t) * 15);
1332 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1334 x = tracklets[iLayer].GetX0();
1340 memset(cov, 0, sizeof(Double_t) * 3);
1341 TMatrixD transform(3,3);
1344 transform(0,2) = x*x;
1348 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1349 covariance *= transform.T();
1350 TMatrixD transformZ(2,2);
1351 transformZ(0,0) = transformZ(1,1) = 1;
1352 transformZ(0,1) = x;
1353 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1354 covarZ *= transformZ.T();
1355 // y: R^2 = (x - x0)^2 + (y - y0)^2
1356 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1357 // R = Sqrt() = 1/Curvature
1358 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1359 Double_t res = (x * a + b); // = (x - x0)/y0
1361 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1363 res = TMath::Sqrt(res);
1364 y = (1.0 - res) / a;
1366 cov[0] = covariance(0,0);
1367 cov[2] = covarZ(0,0);
1370 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1371 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1372 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1373 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1374 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1375 Double_t x0 = -b / a;
1376 if (-c * a + b * b + 1 > 0) {
1377 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
1378 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1379 if (a < 0) yderiv *= -1.0;
1383 z = offset + slope * (x - xref);
1385 tracklets[iLayer].SetYref(0, y);
1386 tracklets[iLayer].SetYref(1, dy);
1387 tracklets[iLayer].SetZref(0, z);
1388 tracklets[iLayer].SetZref(1, dz);
1389 tracklets[iLayer].SetC(curvature);
1390 tracklets[iLayer].SetCovRef(cov);
1391 tracklets[iLayer].SetChi2(chi2track);
1393 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRieman: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
1395 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1396 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1397 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1398 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1399 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1400 cstreamer << "FitTiltedRieman0"
1401 << "EventNumber=" << eventNumber
1402 << "CandidateNumber=" << candidateNumber
1404 << "Chi2Z=" << chi2z
1411 //____________________________________________________________________
1412 Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
1415 // Fit track with a staight line
1416 // Fills an AliTrackPoint array with np points
1417 // Function should be used to refit tracks when no magnetic field was on
1419 AliTRDLeastSquare yfitter, zfitter;
1420 AliTRDcluster *cl = NULL;
1422 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1424 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1425 if(!(tracklet = track->GetTracklet(ipl))) continue;
1426 if(!tracklet->IsOK()) continue;
1427 new(&work[ipl]) AliTRDseedV1(*tracklet);
1429 tracklets = &work[0];
1432 Double_t xref = CalculateReferenceX(tracklets);
1433 Double_t x, y, z, dx, ye, yr, tilt;
1434 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1435 if(!tracklets[ipl].IsOK()) continue;
1436 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1437 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1438 if (!tracklets[ipl].IsUsable(itb)) continue;
1442 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1446 Double_t z0 = zfitter.GetFunctionParameter(0);
1447 Double_t dzdx = zfitter.GetFunctionParameter(1);
1448 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1449 if(!tracklets[ipl].IsOK()) continue;
1450 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1451 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1452 if (!tracklets[ipl].IsUsable(itb)) continue;
1456 tilt = tracklets[ipl].GetTilt();
1458 yr = y + tilt*(z - z0 - dzdx*dx);
1459 // error definition changes for the different calls
1460 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1461 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1462 yfitter.AddPoint(&dx, yr, ye);
1466 Double_t y0 = yfitter.GetFunctionParameter(0);
1467 Double_t dydx = yfitter.GetFunctionParameter(1);
1468 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1470 //update track points array
1473 for(int ip=0; ip<np; ip++){
1474 points[ip].GetXYZ(xyz);
1475 xyz[1] = y0 + dydx * (xyz[0] - xref);
1476 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1477 points[ip].SetXYZ(xyz);
1484 //_________________________________________________________________________
1485 Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
1488 // Performs a Riemann fit taking tilting pad correction into account
1490 // Paramters: - Array of tracklets (connected to the track candidate)
1491 // - Flag selecting the error definition
1492 // Output: - Chi2 values of the track (in Parameter list)
1494 // The equations which has to be solved simultaneously are:
1496 // R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1497 // y^{*} = y - tg(h)(z - z_{t})
1498 // z_{t} = z_{0}+dzdx*(x-x_{r})
1500 // with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1501 // R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1502 // track in the x-z plane. Using the following transformations
1504 // t = 1 / (x^{2} + y^{2})
1506 // v = 2 * tan(h) * t
1507 // w = 2 * tan(h) * (x - x_{r}) * t
1509 // One gets the following linear equation
1511 // a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1513 // where the coefficients have the following meaning
1517 // c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1521 // The error calculation for the free term is thus
1523 // #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1526 // From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1529 // C = 1/R = a/(1 + b^{2} + c*a)
1533 // M.Ivanov <M.Ivanov@gsi.de>
1534 // A.Bercuci <A.Bercuci@gsi.de>
1535 // M.Fasel <M.Fasel@gsi.de>
1537 TLinearFitter *fitter = GetTiltedRiemanFitter();
1538 fitter->StoreData(kTRUE);
1539 fitter->ClearPoints();
1540 AliTRDLeastSquare zfitter;
1541 AliTRDcluster *cl = NULL;
1543 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1545 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1546 if(!(tracklet = track->GetTracklet(ipl))) continue;
1547 if(!tracklet->IsOK()) continue;
1548 new(&work[ipl]) AliTRDseedV1(*tracklet);
1550 tracklets = &work[0];
1553 Double_t xref = CalculateReferenceX(tracklets);
1554 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);
1555 Double_t x, y, z, t, tilt, dx, w, we;
1558 // Containers for Least-square fitter
1559 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1560 if(!tracklets[ipl].IsOK()) continue;
1561 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1562 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1563 //if (!tracklets[ipl].IsUsable(itb)) continue;
1567 tilt = tracklets[ipl].GetTilt();
1571 uvt[0] = 2. * x * t;
1573 uvt[2] = 2. * tilt * t;
1574 uvt[3] = 2. * tilt * dx * t;
1575 w = 2. * (y + tilt*z) * t;
1576 // error definition changes for the different calls
1578 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
1579 fitter->AddPoint(uvt, w, we);
1580 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1584 if(fitter->Eval()) return 1.E10;
1586 Double_t z0 = fitter->GetParameter(3);
1587 Double_t dzdx = fitter->GetParameter(4);
1590 // Linear fitter - not possible to make boundaries
1591 // Do not accept non possible z and dzdx combinations
1592 Bool_t accept = kTRUE;
1593 Double_t zref = 0.0;
1594 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1595 if(!tracklets[iLayer].IsOK()) continue;
1596 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
1597 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1602 Double_t dzmf = zfitter.GetFunctionParameter(1);
1603 Double_t zmf = zfitter.GetFunctionValue(&xref);
1604 fitter->FixParameter(3, zmf);
1605 fitter->FixParameter(4, dzmf);
1607 fitter->ReleaseParameter(3);
1608 fitter->ReleaseParameter(4);
1609 z0 = fitter->GetParameter(3); // = zmf ?
1610 dzdx = fitter->GetParameter(4); // = dzmf ?
1613 // Calculate Curvature
1614 Double_t a = fitter->GetParameter(0);
1615 Double_t b = fitter->GetParameter(1);
1616 Double_t c = fitter->GetParameter(2);
1617 Double_t y0 = 1. / a;
1618 Double_t x0 = -b * y0;
1619 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1620 if(tmp<=0.) return 1.E10;
1621 Double_t radius = TMath::Sqrt(tmp);
1622 Double_t curvature = 1.0 + b*b - c*a;
1623 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1625 // Calculate chi2 of the fit
1626 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
1627 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);
1629 // Update the tracklets
1631 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1632 x = tracklets[ip].GetX0();
1633 tmp = radius*radius-(x-x0)*(x-x0);
1634 if(tmp <= 0.) continue;
1635 tmp = TMath::Sqrt(tmp);
1637 // y: R^2 = (x - x0)^2 + (y - y0)^2
1638 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1639 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1640 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1641 tracklets[ip].SetYref(1, (x - x0) / tmp);
1642 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1643 tracklets[ip].SetZref(1, dzdx);
1644 tracklets[ip].SetC(curvature);
1645 tracklets[ip].SetChi2(chi2);
1648 //update track points array
1651 for(int ip=0; ip<np; ip++){
1652 points[ip].GetXYZ(xyz);
1653 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
1654 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1655 points[ip].SetXYZ(xyz);
1663 //____________________________________________________________________
1664 Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1666 // Kalman filter implementation for the TRD.
1667 // It returns the positions of the fit in the array "points"
1669 // Author : A.Bercuci@gsi.de
1671 // printf("Start track @ x[%f]\n", track->GetX());
1673 //prepare marker points along the track
1674 Int_t ip = np ? 0 : 1;
1676 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1677 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1680 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1683 AliTRDseedV1 tracklet;
1684 AliTRDseedV1 *ptrTracklet = NULL;
1686 //Loop through the TRD planes
1687 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1688 // GET TRACKLET OR BUILT IT
1689 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1691 if(!(ptrTracklet = &tracklets[iplane])) continue;
1693 if(!(ptrTracklet = track->GetTracklet(iplane))){
1694 /*AliTRDtrackerV1 *tracker = NULL;
1695 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1696 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1697 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1701 if(!ptrTracklet->IsOK()) continue;
1703 Double_t x = ptrTracklet->GetX0();
1706 //don't do anything if next marker is after next update point.
1707 if((up?-1:1) * (points[ip].GetX() - x) - AliTRDReconstructor::GetMaxStep() < 0) break;
1708 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1710 Double_t xyz[3]; // should also get the covariance
1712 track->Global2LocalPosition(xyz, track->GetAlpha());
1713 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1716 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1718 // Propagate closer to the next update point
1719 if(((up?-1:1) * (x - track->GetX()) + AliTRDReconstructor::GetMaxStep() < 0) && !PropagateToX(*track, x + (up?-1:1)*AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) return -1.;
1721 if(!AdjustSector(track)) return -1;
1722 if(TMath::Abs(track->GetSnp()) > AliTRDReconstructor::GetMaxSnp()) return -1;
1724 //load tracklet to the tracker and the track
1726 if((index = FindTracklet(ptrTracklet)) < 0){
1727 ptrTracklet = SetTracklet(&tracklet);
1728 index = fTracklets->GetEntriesFast()-1;
1730 track->SetTracklet(ptrTracklet, index);*/
1733 // register tracklet to track with tracklet creation !!
1734 // PropagateBack : loaded tracklet to the tracker and update index
1735 // RefitInward : update index
1736 // MakeTrack : loaded tracklet to the tracker and update index
1737 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1740 //Calculate the mean material budget along the path inside the chamber
1741 Double_t xyz0[3]; track->GetXYZ(xyz0);
1742 Double_t alpha = track->GetAlpha();
1743 Double_t xyz1[3], y, z;
1744 if(!track->GetProlongation(x, y, z)) return -1;
1745 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1746 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1748 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
1750 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1751 Double_t xrho = param[0]*param[4]; // density*length
1752 Double_t xx0 = param[1]; // radiation length
1754 //Propagate the track
1755 track->PropagateTo(x, xx0, xrho);
1756 if (!AdjustSector(track)) break;
1759 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1760 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1761 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
1762 if(chi2<1e+10) ((AliExternalTrackParam*)track)->Update(p, cov);
1765 //Reset material budget if 2 consecutive gold
1766 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1767 } // end planes loop
1771 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1773 Double_t xyz[3]; // should also get the covariance
1775 track->Global2LocalPosition(xyz, track->GetAlpha());
1776 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1780 return track->GetChi2();
1783 //_________________________________________________________________________
1784 Float_t AliTRDtrackerV1::CalculateChi2Z(const AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
1787 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1788 // A linear dependence on the x-value serves as a model.
1789 // The parameters are related to the tilted Riemann fit.
1790 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1791 // - the offset for the reference x
1793 // - the reference x position
1794 // Output: - The Chi2 value of the track in z-Direction
1796 Float_t chi2Z = 0, nLayers = 0;
1797 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
1798 if(!tracklets[iLayer].IsOK()) continue;
1799 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1800 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
1803 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1807 //_____________________________________________________________________________
1808 Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1811 // Starting from current X-position of track <t> this function
1812 // extrapolates the track up to radial position <xToGo>.
1813 // Returns 1 if track reaches the plane, and 0 otherwise
1816 // Current track X-position
1817 Double_t xpos = t.GetX()/*,
1818 mass = t.GetMass()*/;
1820 // Direction: inward or outward
1821 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
1823 while (((xToGo - xpos) * dir) > AliTRDReconstructor::GetEpsilon()) {
1824 // printf("to go %f\n", (xToGo - xpos) * dir);
1832 // The next step size
1833 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
1835 // Get the global position of the starting point
1838 // X-position after next step
1841 // Get local Y and Z at the X-position of the next step
1842 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
1844 // The global position of the end point of this prolongation step
1845 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1846 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1849 // Calculate the mean material budget between start and
1850 // end point of this prolongation step
1851 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
1853 // Propagate the track to the X-position after the next step
1854 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
1856 /* // Correct for mean material budget
1859 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3){
1860 const char *pn[] = {"rho", "x/X0", "<A>", "<Z>", "L", "<Z/A>", "Nb"};
1861 printf("D-AliTRDtrackerV1::PropagateTo(): x[%6.2f] bg[%6.2f]\n", xpos, bg);
1862 printf(" param :: %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e]\n"
1873 dEdx = AliExternalTrackParam::BetheBlochSolid(bg);
1876 dEdx = AliExternalTrackParam::BetheBlochGas(bg);
1879 { // mean exitation energy (GeV)
1880 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;
1881 Double_t mZA = param[5]>1.e-5?param[5]:(param[3]/param[2]);
1882 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3) printf("D-AliTRDtrackerV1::PropagateTo(): Mee[%e] <Z/A>[%e]\n", mee, mZA);
1883 // protect against failed calculation of rho in MeanMaterialBudget()
1884 dEdx = AliExternalTrackParam::BetheBlochGeant(bg, param[0]>1.e-6?param[0]:2.33, 0.2, 3., mee, mZA);
1888 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=2) printf("D-AliTRDtrackerV1::PropagateTo(): dEdx(bg=%e, m=%e)= %e[GeV/cm]\n", bg, mass, dEdx);
1889 if (!t.CorrectForMeanMaterialdEdx(param[1], dir*param[0]*param[4], mass, dEdx)) return 0;
1891 // Rotate the track if necessary
1892 if(!AdjustSector(&t)) return 0;
1894 // New track X-position
1903 //_____________________________________________________________________________
1904 Bool_t AliTRDtrackerV1::ReadClusters(TTree *clusterTree)
1907 // Reads AliTRDclusters from the file.
1908 // The names of the cluster tree and branches
1909 // should match the ones used in AliTRDclusterizer::WriteClusters()
1912 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1913 TObjArray *clusterArray = new TObjArray(nsize+1000);
1915 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1917 AliError("Can't get the branch !");
1920 branch->SetAddress(&clusterArray);
1923 Float_t nclusters = fkRecoParam->GetNClusters();
1924 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
1925 fClusters = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1926 fClusters->SetOwner(kTRUE);
1929 // Loop through all entries in the tree
1930 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1933 AliTRDcluster *c = NULL;
1934 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1936 nbytes += clusterTree->GetEvent(iEntry);
1938 // Get the number of points in the detector
1939 Int_t nCluster = clusterArray->GetEntriesFast();
1940 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1941 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
1942 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1943 delete (clusterArray->RemoveAt(iCluster));
1946 delete clusterArray;
1951 //_____________________________________________________________________________
1952 Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1955 // Fills clusters into TRD tracking sectors
1958 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
1960 if(!fkReconstructor->IsWritingClusters()){
1961 fClusters = AliTRDReconstructor::GetClusters();
1963 if(!ReadClusters(cTree)) {
1964 AliError("Problem with reading the clusters !");
1970 if(!fClusters || !fClusters->GetEntriesFast()){
1971 AliInfo("No TRD clusters");
1976 BuildTrackingContainers();
1978 //Int_t ncl = fClusters->GetEntriesFast();
1979 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1984 //_____________________________________________________________________________
1985 Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
1988 // Fills clusters into TRD tracking sectors
1989 // Function for use in the HLT
1991 if(!clusters || !clusters->GetEntriesFast()){
1992 AliInfo("No TRD clusters");
1996 fClusters = clusters;
1999 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
2000 BuildTrackingContainers();
2002 //Int_t ncl = fClusters->GetEntriesFast();
2003 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
2009 //____________________________________________________________________
2010 Int_t AliTRDtrackerV1::BuildTrackingContainers()
2012 // Building tracking containers for clusters
2014 Int_t nin(0), ncl(fClusters->GetEntriesFast());
2016 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(ncl);
2017 if(c->IsInChamber()) nin++;
2018 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
2019 Int_t detector = c->GetDetector();
2020 Int_t sector = fGeom->GetSector(detector);
2021 Int_t stack = fGeom->GetStack(detector);
2022 Int_t layer = fGeom->GetLayer(detector);
2024 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, ncl);
2027 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
2028 if(!fTrSec[isector].GetNChambers()) continue;
2029 fTrSec[isector].Init(fkReconstructor);
2037 //____________________________________________________________________
2038 void AliTRDtrackerV1::UnloadClusters()
2041 // Clears the arrays of clusters and tracks. Resets sectors and timebins
2042 // If option "force" is also set the containers are also deleted. This is useful
2047 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
2050 fTracklets->Delete();
2051 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
2054 if(IsClustersOwner()) fClusters->Delete();
2056 // save clusters array in the reconstructor for further use.
2057 if(!fkReconstructor->IsWritingClusters()){
2058 AliTRDReconstructor::SetClusters(fClusters);
2059 SetClustersOwner(kFALSE);
2060 } else AliTRDReconstructor::SetClusters(NULL);
2063 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
2065 // Increment the Event Number
2066 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
2069 // //____________________________________________________________________
2070 // void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2072 // const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2073 // if(!track) return;
2075 // AliTRDseedV1 *tracklet = NULL;
2076 // for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2077 // if(!(tracklet = track->GetTracklet(ily))) continue;
2078 // AliTRDcluster *c = NULL;
2079 // for(Int_t ic=AliTRDseed::kNclusters; ic--;){
2080 // if(!(c=tracklet->GetClusters(ic))) continue;
2087 //_____________________________________________________________________________
2088 Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
2091 // Rotates the track when necessary
2094 Double_t alpha = AliTRDgeometry::GetAlpha();
2095 Double_t y = track->GetY();
2096 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
2099 if (!track->Rotate( alpha)) {
2103 else if (y < -ymax) {
2104 if (!track->Rotate(-alpha)) {
2114 //____________________________________________________________________
2115 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
2117 // Find tracklet for TRD track <track>
2126 // Detailed description
2128 idx = track->GetTrackletIndex(p);
2129 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
2134 //____________________________________________________________________
2135 AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
2137 // Add this tracklet to the list of tracklets stored in the tracker
2140 // - tracklet : pointer to the tracklet to be added to the list
2143 // - the index of the new tracklet in the tracker tracklets list
2145 // Detailed description
2146 // Build the tracklets list if it is not yet created (late initialization)
2147 // and adds the new tracklet to the list.
2150 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2151 fTracklets->SetOwner(kTRUE);
2153 Int_t nentries = fTracklets->GetEntriesFast();
2154 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
2157 //____________________________________________________________________
2158 AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
2160 // Add this track to the list of tracks stored in the tracker
2163 // - track : pointer to the track to be added to the list
2166 // - the pointer added
2168 // Detailed description
2169 // Build the tracks list if it is not yet created (late initialization)
2170 // and adds the new track to the list.
2173 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2174 fTracks->SetOwner(kTRUE);
2176 Int_t nentries = fTracks->GetEntriesFast();
2177 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2182 //____________________________________________________________________
2183 Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
2186 // Steer tracking for one SM.
2189 // sector : Array of (SM) propagation layers containing clusters
2190 // esd : The current ESD event. On output it contains the also
2191 // the ESD (TRD) tracks found in this SM.
2194 // Number of tracks found in this TRD supermodule.
2196 // Detailed description
2198 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2199 // 2. Launch stack tracking.
2200 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2201 // 3. Pack results in the ESD event.
2205 Int_t nChambers = 0;
2206 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
2207 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
2208 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2210 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2211 if(!(chamber = stack[ilayer])) continue;
2212 if(chamber->GetNClusters() < fgNTimeBins * fkRecoParam->GetFindableClusters()) continue;
2214 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
2216 if(nChambers < 4) continue;
2217 //AliInfo(Form("Doing stack %d", istack));
2218 nTracks += Clusters2TracksStack(stack, fTracksESD);
2220 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2222 for(int itrack=0; itrack<nTracks; itrack++){
2223 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2224 Int_t id = esd->AddTrack(esdTrack);
2226 // set ESD id to stand alone TRD tracks
2227 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
2228 esdTrack=esd->GetTrack(id);
2229 TObject *o(NULL); Int_t ic(0);
2230 AliTRDtrackV1 *calibTrack(NULL);
2231 while((o = esdTrack->GetCalibObject(ic++))){
2232 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2233 calibTrack->SetESDid(esdTrack->GetID());
2239 // Reset Track and Candidate Number
2240 AliTRDtrackerDebug::SetCandidateNumber(0);
2241 AliTRDtrackerDebug::SetTrackNumber(0);
2243 // delete ESD tracks in the array
2244 fTracksESD->Delete();
2248 //____________________________________________________________________
2249 Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
2252 // Make tracks in one TRD stack.
2255 // layer : Array of stack propagation layers containing clusters
2256 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2257 // On exit the tracks found in this stack are appended.
2260 // Number of tracks found in this stack.
2262 // Detailed description
2264 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2265 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2266 // See AliTRDtrackerV1::MakeSeeds() for more details.
2267 // 3. Arrange track candidates in decreasing order of their quality
2268 // 4. Classify tracks in 5 categories according to:
2269 // a) number of layers crossed
2271 // 5. Sign clusters by tracks in decreasing order of track quality
2272 // 6. Build AliTRDtrack out of seeding tracklets
2274 // 8. Build ESD track and register it to the output list
2277 AliTRDtrackingChamber *chamber = NULL;
2278 AliTRDtrackingChamber **ci = NULL;
2279 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2280 Int_t pars[4]; // MakeSeeds parameters
2282 //Double_t alpha = AliTRDgeometry::GetAlpha();
2283 //Double_t shift = .5 * alpha;
2284 Int_t configs[kNConfigs];
2286 // Purge used clusters from the containers
2288 for(Int_t ic = kNPlanes; ic--; ci++){
2289 if(!(*ci)) continue;
2293 // Build initial seeding configurations
2294 Double_t quality = BuildSeedingConfigs(stack, configs);
2295 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2296 AliInfo(Form("Plane config %d %d %d Quality %f"
2297 , configs[0], configs[1], configs[2], quality));
2301 // Initialize contors
2302 Int_t ntracks, // number of TRD track candidates
2303 ntracks1, // number of registered TRD tracks/iter
2304 ntracks2 = 0; // number of all registered TRD tracks in stack
2308 Int_t ic = 0; ci = &stack[0];
2309 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2310 if(!(*ci)) return ntracks2;
2311 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
2314 // Loop over seeding configurations
2315 ntracks = 0; ntracks1 = 0;
2316 for (Int_t iconf = 0; iconf<fkRecoParam->GetNumberOfSeedConfigs(); iconf++) {
2317 pars[0] = configs[iconf];
2320 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
2321 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
2322 if(ntracks == kMaxTracksStack) break;
2324 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
2327 // Sort the seeds according to their quality
2328 Int_t sort[kMaxTracksStack+1];
2329 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
2330 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 2){
2331 AliDebug(3, "Track candidates classification:");
2332 for (Int_t it(0); it < ntracks; it++) {
2334 printf(" %2d idx[%d] Quality[%e]\n", it, jt, fTrackQuality[jt]);
2338 // Initialize number of tracks so far and logic switches
2339 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2340 Bool_t signedTrack[kMaxTracksStack];
2341 Bool_t fakeTrack[kMaxTracksStack];
2342 for (Int_t i=0; i<ntracks; i++){
2343 signedTrack[i] = kFALSE;
2344 fakeTrack[i] = kFALSE;
2346 //AliInfo("Selecting track candidates ...");
2348 // Sieve clusters in decreasing order of track quality
2349 Int_t jSieve(0), rejectedCandidates(0);
2351 // Check track candidates
2352 rejectedCandidates=0;
2353 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
2354 Int_t trackIndex = sort[itrack];
2355 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
2357 // Calculate track parameters from tracklets seeds
2362 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2363 Int_t jseed = kNPlanes*trackIndex+jLayer;
2364 sseed[jseed].UpdateUsed();
2365 if(!sseed[jseed].IsOK()) continue;
2366 // check if primary candidate
2367 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
2368 ncl += sseed[jseed].GetN();
2369 nused += sseed[jseed].GetNUsed();
2373 // Filter duplicated tracks
2375 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2376 fakeTrack[trackIndex] = kTRUE;
2379 if (ncl>0 && Float_t(nused)/ncl >= .25){
2380 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));
2381 fakeTrack[trackIndex] = kTRUE;
2385 AliDebug(4, Form("Candidate[%d] Quality[%e] Tracklets[%d] Findable[%d] Ncl[%d] Nused[%d]", trackIndex, fTrackQuality[trackIndex], nlayers, findable, ncl, nused));
2388 Bool_t skip = kFALSE;
2390 case 0: // select 6 tracklets primary tracks, good quality
2391 if(nlayers > findable || nlayers < kNPlanes) {skip = kTRUE; break;}
2392 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2395 case 1: // select shorter primary tracks, good quality
2396 //if(findable<4){skip = kTRUE; break;}
2397 if(nlayers < findable){skip = kTRUE; break;}
2398 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2401 case 2: // select 6 tracklets secondary tracks
2402 if(nlayers < kNPlanes) { skip = kTRUE; break;}
2403 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2406 case 3: // select shorter tracks, good quality
2407 if (nlayers<4){skip = kTRUE; break;}
2408 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2411 case 4: // select anything with at least 4 tracklets
2412 if (nlayers<4){skip = kTRUE; break;}
2413 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2417 rejectedCandidates++;
2418 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2420 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2422 signedTrack[trackIndex] = kTRUE;
2424 AliTRDseedV1 *lseed =&sseed[trackIndex*kNPlanes];
2425 AliTRDtrackV1 *track = MakeTrack(lseed);
2427 AliDebug(1, "Track building failed.");
2430 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 1){
2431 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2432 AliDebug(2, Form("Track pt=%7.2fGeV/c SM[%2d] Done.", track->Pt(), fGeom->GetSector(chamber->GetDetector())));
2436 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
2437 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
2439 AliTRDseedV1 *dseed[6];
2440 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
2442 //Int_t eventNrInFile = esd->GetEventNumberInFile();
2443 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2444 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2445 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2446 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2447 cstreamer << "Clusters2TracksStack"
2448 << "EventNumber=" << eventNumber
2449 << "TrackNumber=" << trackNumber
2450 << "CandidateNumber=" << candidateNumber
2451 << "Iter=" << fSieveSeeding
2452 << "Like=" << fTrackQuality[trackIndex]
2453 << "S0.=" << dseed[0]
2454 << "S1.=" << dseed[1]
2455 << "S2.=" << dseed[2]
2456 << "S3.=" << dseed[3]
2457 << "S4.=" << dseed[4]
2458 << "S5.=" << dseed[5]
2460 << "NLayers=" << nlayers
2461 << "Findable=" << findable
2462 << "NUsed=" << nused
2467 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2468 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2469 esdTrack->SetLabel(track->GetLabel());
2470 track->UpdateESDtrack(esdTrack);
2471 // write ESD-friends if neccessary
2472 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
2473 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2474 calibTrack->SetOwner();
2475 esdTrack->AddCalibObject(calibTrack);
2478 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
2482 } while(jSieve<5 && rejectedCandidates); // end track candidates sieve
2483 if(!ntracks1) break;
2485 // increment counters
2486 ntracks2 += ntracks1;
2488 if(fkReconstructor->IsHLT()) break;
2491 // Rebuild plane configurations and indices taking only unused clusters into account
2492 quality = BuildSeedingConfigs(stack, configs);
2493 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
2495 for(Int_t ip = 0; ip < kNPlanes; ip++){
2496 if(!(chamber = stack[ip])) continue;
2497 chamber->Build(fGeom);//Indices(fSieveSeeding);
2500 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2501 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2503 } while(fSieveSeeding<10); // end stack clusters sieve
2507 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2512 //___________________________________________________________________
2513 Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
2516 // Assign probabilities to chambers according to their
2517 // capability of producing seeds.
2521 // layers : Array of stack propagation layers for all 6 chambers in one stack
2522 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2523 // for details) in the decreasing order of their seeding probabilities.
2527 // Return top configuration quality
2529 // Detailed description:
2531 // To each chamber seeding configuration (see GetSeedingConfig() for
2532 // the list of all configurations) one defines 2 quality factors:
2533 // - an apriori topological quality (see GetSeedingConfig() for details) and
2534 // - a data quality based on the uniformity of the distribution of
2535 // clusters over the x range (time bins population). See CookChamberQA() for details.
2536 // The overall chamber quality is given by the product of this 2 contributions.
2539 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
2540 AliTRDtrackingChamber *chamber = NULL;
2541 for(int iplane=0; iplane<kNPlanes; iplane++){
2542 if(!(chamber = stack[iplane])) continue;
2543 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2546 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2547 Int_t planes[] = {0, 0, 0, 0};
2548 for(int iconf=0; iconf<kNConfigs; iconf++){
2549 GetSeedingConfig(iconf, planes);
2550 tconfig[iconf] = fgTopologicQA[iconf];
2551 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2554 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2555 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2556 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2557 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2559 return tconfig[configs[0]];
2562 //____________________________________________________________________
2563 Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
2566 // Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2567 // either missed by TPC prolongation or conversions inside the TRD volume.
2568 // For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
2571 // layers : Array of stack propagation layers containing clusters
2572 // sseed : Array of empty tracklet seeds. On exit they are filled.
2573 // ipar : Control parameters:
2574 // ipar[0] -> seeding chambers configuration
2575 // ipar[1] -> stack index
2576 // ipar[2] -> number of track candidates found so far
2579 // Number of tracks candidates found.
2581 // The following steps are performed:
2582 // 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2583 // radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2584 // is described in AliTRDtrackerV1::Clusters2TracksStack().
2585 // 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2586 // - for each seeding cluster in the lower seeding layer find
2587 // - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2588 // is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2589 // - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2591 // - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2592 // seeding clusters.
2593 // The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2594 // and AliTRDchamberTimeBin::GetClusters().
2595 // 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2596 // performed at this level
2597 // 4. Initialize seeding tracklets in the seeding chambers.
2598 // 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2599 // 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2600 // AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2601 // 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2602 // 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2603 // approximation of the track.
2604 // 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2605 // checked against the Riemann fit:
2606 // - position resolution in y
2607 // - angular resolution in the bending plane
2608 // - likelihood of the number of clusters attached to the tracklet
2609 // 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2610 // - Initialization of extrapolation tracklets with the fit parameters
2611 // - Attach clusters to extrapolated tracklets
2612 // - Helix fit of tracklets
2613 // 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2614 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
2615 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2616 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2617 // 14. Cooking labels for tracklets. Should be done only for MC
2618 // 15. Register seeds.
2621 // Marian Ivanov <M.Ivanov@gsi.de>
2622 // Alexandru Bercuci <A.Bercuci@gsi.de>
2623 // Markus Fasel <M.Fasel@gsi.de>
2625 AliTRDtrackingChamber *chamber = NULL;
2626 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
2627 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
2628 Int_t ncl, mcl; // working variable for looping over clusters
2629 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2631 // chi2[0] = tracklet chi2 on the Z direction
2632 // chi2[1] = tracklet chi2 on the R direction
2635 // this should be data member of AliTRDtrack TODO
2636 Double_t seedQuality[kMaxTracksStack];
2638 // unpack control parameters
2639 Int_t config = ipar[0];
2640 Int_t ntracks = ipar[1];
2641 Int_t istack = ipar[2];
2642 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
2643 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
2646 // Init chambers geometry
2647 Double_t hL[kNPlanes]; // Tilting angle
2648 Float_t padlength[kNPlanes]; // pad lenghts
2649 Float_t padwidth[kNPlanes]; // pad widths
2650 AliTRDpadPlane *pp = NULL;
2651 for(int iplane=0; iplane<kNPlanes; iplane++){
2652 pp = fGeom->GetPadPlane(iplane, istack);
2653 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
2654 padlength[iplane] = pp->GetLengthIPad();
2655 padwidth[iplane] = pp->GetWidthIPad();
2658 // Init anode wire position for chambers
2659 Double_t x0[kNPlanes], // anode wire position
2660 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
2661 TGeoHMatrix *matrix = NULL;
2662 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2663 Double_t glb[] = {0., 0., 0.};
2664 AliTRDtrackingChamber **cIter = &stack[0];
2665 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
2666 if(!(*cIter)) continue;
2667 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
2668 x0[iLayer] = fgkX0[iLayer];
2671 matrix->LocalToMaster(loc, glb);
2672 x0[iLayer] = glb[0];
2675 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
2677 // Build seeding layers
2680 for(int isl=0; isl<kNSeedPlanes; isl++){
2681 if(!(chamber = stack[planes[isl]])) continue;
2682 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
2685 if(nlayers < kNSeedPlanes) return ntracks;
2688 // Start finding seeds
2689 Double_t cond0[4], cond1[4], cond2[4];
2691 while((c[3] = (*fSeedTB[3])[icl++])){
2693 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2694 fSeedTB[0]->GetClusters(cond0, index, ncl);
2695 //printf("Found c[3] candidates 0 %d\n", ncl);
2698 c[0] = (*fSeedTB[0])[index[jcl++]];
2700 Double_t dx = c[3]->GetX() - c[0]->GetX();
2701 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2702 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2703 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
2704 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
2705 //printf("Found c[0] candidates 1 %d\n", mcl);
2709 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2711 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
2712 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2713 //printf("Found c[1] candidate 2 %p\n", c[2]);
2716 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].",
2717 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2718 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2719 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2720 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
2722 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
2726 AliTRDseedV1 *tseed = &cseed[0];
2728 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2729 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
2730 tseed->SetDetector(det);
2731 tseed->SetTilt(hL[iLayer]);
2732 tseed->SetPadLength(padlength[iLayer]);
2733 tseed->SetPadWidth(padwidth[iLayer]);
2734 tseed->SetReconstructor(fkReconstructor);
2735 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
2736 tseed->Init(GetRiemanFitter());
2737 tseed->SetStandAlone(kTRUE);
2740 Bool_t isFake = kFALSE;
2741 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2742 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2743 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2744 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2747 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2749 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2750 Int_t ll = c[3]->GetLabel(0);
2751 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2752 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2753 AliRieman *rim = GetRiemanFitter();
2754 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2756 <<"EventNumber=" << eventNumber
2757 <<"CandidateNumber=" << candidateNumber
2758 <<"isFake=" << isFake
2759 <<"config=" << config
2761 <<"chi2z=" << chi2[0]
2762 <<"chi2y=" << chi2[1]
2763 <<"Y2exp=" << cond2[0]
2764 <<"Z2exp=" << cond2[1]
2765 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2766 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2767 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2768 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2769 <<"yref0=" << yref[0]
2770 <<"yref1=" << yref[1]
2771 <<"yref2=" << yref[2]
2772 <<"yref3=" << yref[3]
2777 <<"Seed0.=" << &cseed[planes[0]]
2778 <<"Seed1.=" << &cseed[planes[1]]
2779 <<"Seed2.=" << &cseed[planes[2]]
2780 <<"Seed3.=" << &cseed[planes[3]]
2781 <<"RiemanFitter.=" << rim
2784 if(chi2[0] > fkRecoParam->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
2785 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
2786 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2789 if(chi2[1] > fkRecoParam->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
2790 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
2791 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2794 //AliInfo("Passed chi2 filter.");
2796 // try attaching clusters to tracklets
2798 AliTRDcluster *cl = NULL;
2799 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2800 Int_t jLayer = planes[iLayer];
2801 Int_t nNotInChamber = 0;
2802 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
2803 if(/*fkReconstructor->IsHLT()*/kFALSE){
2804 cseed[jLayer].UpdateUsed();
2805 if(!cseed[jLayer].IsOK()) continue;
2807 cseed[jLayer].Fit();
2808 cseed[jLayer].UpdateUsed();
2809 cseed[jLayer].ResetClusterIter();
2810 while((cl = cseed[jLayer].NextCluster())){
2811 if(!cl->IsInChamber()) nNotInChamber++;
2813 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2814 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
2819 if(mlayers < kNSeedPlanes){
2820 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
2821 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2825 // temporary exit door for the HLT
2826 if(fkReconstructor->IsHLT()){
2827 // attach clusters to extrapolation chambers
2828 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2829 Int_t jLayer = planesExt[iLayer];
2830 if(!(chamber = stack[jLayer])) continue;
2831 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
2832 cseed[jLayer].Fit();
2834 //FitTiltedRiemanConstraint(&cseed[0], GetZ());
2835 fTrackQuality[ntracks] = 1.; // dummy value
2837 if(ntracks == kMaxTracksStack) return ntracks;
2843 // Update Seeds and calculate Likelihood
2844 // fit tracklets and cook likelihood
2845 Double_t chi2Vals[4];
2846 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
2847 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2848 Int_t jLayer = planes[iLayer];
2849 cseed[jLayer].Fit(1);
2851 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
2853 if (TMath::Log(1.E-9 + like) < fkRecoParam->GetTrackLikelihood()){
2854 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2855 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2858 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2860 // book preliminary results
2861 seedQuality[ntracks] = like;
2862 fSeedLayer[ntracks] = config;/*sLayer;*/
2864 // attach clusters to the extrapolation seeds
2866 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2867 Int_t jLayer = planesExt[iLayer];
2868 if(!(chamber = stack[jLayer])) continue;
2870 // fit extrapolated seed
2871 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2872 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2873 AliTRDseedV1 pseed = cseed[jLayer];
2874 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2876 cseed[jLayer] = pseed;
2877 chi2Vals[0] = FitTiltedRieman(cseed, kTRUE);
2878 cseed[jLayer].Fit(1);
2882 // AliInfo("Extrapolation done.");
2883 // Debug Stream containing all the 6 tracklets
2884 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2885 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2886 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2887 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2888 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2889 cstreamer << "MakeSeeds1"
2890 << "EventNumber=" << eventNumber
2891 << "CandidateNumber=" << candidateNumber
2892 << "S0.=" << &cseed[0]
2893 << "S1.=" << &cseed[1]
2894 << "S2.=" << &cseed[2]
2895 << "S3.=" << &cseed[3]
2896 << "S4.=" << &cseed[4]
2897 << "S5.=" << &cseed[5]
2898 << "FitterT.=" << tiltedRieman
2902 if(fkRecoParam->HasImproveTracklets()){
2903 if(!ImproveSeedQuality(stack, cseed, chi2Vals[0])){
2904 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2905 AliDebug(3, "ImproveSeedQuality() failed.");
2909 // do track fitting with vertex constraint
2910 if(fkRecoParam->IsVertexConstrained()) chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ());
2911 else chi2Vals[1] = -1.;
2912 chi2Vals[2] = GetChi2Z(&cseed[0]);
2913 chi2Vals[3] = GetChi2Phi(&cseed[0]);
2915 // calculate track quality
2916 fTrackQuality[ntracks] = CalculateTrackLikelihood(&chi2Vals[0]);
2918 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2919 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2920 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2921 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2922 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2923 TLinearFitter *fitterT = GetTiltedRiemanFitter();
2925 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2926 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2928 cstreamer << "MakeSeeds2"
2929 << "EventNumber=" << eventNumber
2930 << "CandidateNumber=" << candidateNumber
2931 << "Chi2TR=" << chi2Vals[0]
2932 << "Chi2TC=" << chi2Vals[1]
2933 << "Nlayers=" << mlayers
2934 << "NClusters=" << ncls
2936 << "S0.=" << &cseed[0]
2937 << "S1.=" << &cseed[1]
2938 << "S2.=" << &cseed[2]
2939 << "S3.=" << &cseed[3]
2940 << "S4.=" << &cseed[4]
2941 << "S5.=" << &cseed[5]
2942 << "FitterT.=" << fitterT
2943 << "FitterTC.=" << fitterTC
2946 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")){
2947 Double_t pt[]={0., 0.};
2948 for(Int_t il(0); il<kNPlanes; il++){
2949 if(!cseed[il].IsOK()) continue;
2950 pt[0] = GetBz()*kB2C/cseed[il].GetC();
2951 pt[1] = GetBz()*kB2C/cseed[il].GetC(1);
2954 AliDebug(2, Form("Candidate[%2d] pt[%7.3f %7.3f] Q[%e]\n"
2955 " [0] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
2956 " [1] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
2957 " [2] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
2958 " [3] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
2959 " [4] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
2960 " [5] x[%6.2f] n[%2d] nu[%d] OK[%c]"
2961 , ntracks, pt[0], pt[1], fTrackQuality[ntracks]
2962 ,cseed[0].GetX(), cseed[0].GetN(), cseed[0].GetNUsed(), cseed[0].IsOK()?'y':'n'
2963 ,cseed[1].GetX(), cseed[1].GetN(), cseed[1].GetNUsed(), cseed[1].IsOK()?'y':'n'
2964 ,cseed[2].GetX(), cseed[2].GetN(), cseed[2].GetNUsed(), cseed[2].IsOK()?'y':'n'
2965 ,cseed[3].GetX(), cseed[3].GetN(), cseed[3].GetNUsed(), cseed[3].IsOK()?'y':'n'
2966 ,cseed[4].GetX(), cseed[4].GetN(), cseed[4].GetNUsed(), cseed[4].IsOK()?'y':'n'
2967 ,cseed[5].GetX(), cseed[5].GetN(), cseed[5].GetNUsed(), cseed[5].IsOK()?'y':'n'));
2970 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2971 if(ntracks == kMaxTracksStack){
2972 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2983 //_____________________________________________________________________________
2984 AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const tracklet)
2987 // Build a TRD track out of tracklet candidates
2990 // seeds : array of tracklets
2991 // params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
2992 // [0] - radial position of the track at reference point
2993 // [1] - y position of the fit at [0]
2994 // [2] - z position of the fit at [0]
2995 // [3] - snp of the first tracklet
2996 // [4] - tgl of the first tracklet
2997 // [5] - curvature of the Riemann fit - 1/pt
2998 // [6] - sector rotation angle
3003 // Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
3004 // (diagonal with constant variance terms TODO - correct parameterization)
3006 // In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
3007 // offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
3008 // for details). Do also MC label calculation and PID if propagation successfully.
3010 if(fkReconstructor->IsHLT()) FitTiltedRiemanConstraint(tracklet, 0);
3011 Double_t alpha = AliTRDgeometry::GetAlpha();
3012 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
3014 // find first good tracklet
3015 Int_t idx(0); while(idx<kNPlanes && !tracklet[idx].IsOK()) idx++;
3016 if(idx>2){ AliDebug(1, Form("Found suspect track start @ layer idx[%d]\n"
3017 " %c[0] x0[%f] n[%d] nu[%d] OK[%c]\n"
3018 " %c[1] x0[%f] n[%d] nu[%d] OK[%c]\n"
3019 " %c[2] x0[%f] n[%d] nu[%d] OK[%c]\n"
3020 " %c[3] x0[%f] n[%d] nu[%d] OK[%c]\n"
3021 " %c[4] x0[%f] n[%d] nu[%d] OK[%c]\n"
3022 " %c[5] x0[%f] n[%d] nu[%d] OK[%c]"
3024 ,idx==0?'*':' ', tracklet[0].GetX0(), tracklet[0].GetN(), tracklet[0].GetNUsed(), tracklet[0].IsOK()?'y':'n'
3025 ,idx==1?'*':' ', tracklet[1].GetX0(), tracklet[1].GetN(), tracklet[1].GetNUsed(), tracklet[1].IsOK()?'y':'n'
3026 ,idx==2?'*':' ', tracklet[2].GetX0(), tracklet[2].GetN(), tracklet[2].GetNUsed(), tracklet[2].IsOK()?'y':'n'
3027 ,idx==3?'*':' ', tracklet[3].GetX0(), tracklet[3].GetN(), tracklet[3].GetNUsed(), tracklet[3].IsOK()?'y':'n'
3028 ,idx==4?'*':' ', tracklet[4].GetX0(), tracklet[4].GetN(), tracklet[4].GetNUsed(), tracklet[4].IsOK()?'y':'n'
3029 ,idx==5?'*':' ', tracklet[5].GetX0(), tracklet[5].GetN(), tracklet[5].GetNUsed(), tracklet[5].IsOK()?'y':'n'));
3034 Double_t x(tracklet[idx].GetX0() - dx);
3035 // Build track parameters
3036 Double_t params[] = {
3037 tracklet[idx].GetYref(0) - dx*tracklet[idx].GetYref(1) // y
3038 ,tracklet[idx].GetZref(0) - dx*tracklet[idx].GetZref(1) // z
3039 ,TMath::Sin(TMath::ATan(tracklet[idx].GetYref(1))) // snp
3040 ,tracklet[idx].GetZref(1) / TMath::Sqrt(1. + tracklet[idx].GetYref(1) * tracklet[idx].GetYref(1)) // tgl
3041 ,tracklet[idx].GetC(fkReconstructor->IsHLT()?1:0) // curvature -> 1/pt
3043 Int_t sector(fGeom->GetSector(tracklet[idx].GetDetector()));
3046 c[ 0] = 0.2; // s^2_y
3047 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
3048 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
3049 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
3050 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
3052 AliTRDtrackV1 track(tracklet, params, c, x, sector*alpha+shift);
3054 AliTRDseedV1 *ptrTracklet = NULL;
3056 // skip Kalman filter for HLT
3057 if(/*fkReconstructor->IsHLT()*/kFALSE){
3058 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
3059 track.UnsetTracklet(jLayer);
3060 ptrTracklet = &tracklet[jLayer];
3061 if(!ptrTracklet->IsOK()) continue;
3062 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
3063 ptrTracklet = SetTracklet(ptrTracklet);
3064 ptrTracklet->UseClusters();
3065 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
3067 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
3068 ptrTrack->CookPID();
3069 ptrTrack->CookLabel(.9);
3070 ptrTrack->SetReconstructor(fkReconstructor);
3074 // prevent the error message in AliTracker::MeanMaterialBudget: "start point out of geometry"
3075 if(TMath::Abs(track.GetX()) + TMath::Abs(track.GetY()) + TMath::Abs(track.GetZ()) > 10000) return NULL;
3077 track.ResetCovariance(1);
3078 Int_t nc = TMath::Abs(FollowBackProlongation(track));
3079 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()){
3080 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3081 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3082 Double_t p[5]; // Track Params for the Debug Stream
3083 track.GetExternalParameters(x, p);
3084 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3086 << "EventNumber=" << eventNumber
3087 << "CandidateNumber=" << candidateNumber
3095 << "Yin=" << params[0]
3096 << "Zin=" << params[1]
3097 << "snpin=" << params[2]
3098 << "tndin=" << params[3]
3099 << "crvin=" << params[4]
3100 << "track.=" << &track
3104 UnsetTrackletsTrack(&track);
3107 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
3108 ptrTrack->SetReconstructor(fkReconstructor);
3109 ptrTrack->CookLabel(.9);
3110 for(Int_t il(kNPlanes); il--;){
3111 if(!(ptrTracklet = ptrTrack->GetTracklet(il))) continue;
3112 ptrTracklet->UseClusters();
3115 // computes PID for track
3116 ptrTrack->CookPID();
3117 // update calibration references using this track
3118 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
3120 AliInfo("Could not get Calibra instance.");
3121 } else if(calibra->GetHisto2d()){
3122 calibra->UpdateHistogramsV1(ptrTrack);
3128 //____________________________________________________________________
3129 Bool_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed, Double_t &chi2)
3132 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3135 // layers : Array of propagation layers for a stack/supermodule
3136 // cseed : Array of 6 seeding tracklets which has to be improved
3139 // cssed : Improved seeds
3141 // Detailed description
3143 // Iterative procedure in which new clusters are searched for each
3144 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3145 // can be maximized. If some optimization is found the old seeds are replaced.
3150 // make a local working copy
3151 AliTRDtrackingChamber *chamber = NULL;
3152 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3154 Float_t quality(1.e3),
3155 lQuality[AliTRDgeometry::kNlayer] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
3157 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3158 bseed[jLayer] = cseed[jLayer];
3159 if(!bseed[jLayer].IsOK()) continue;
3161 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3162 quality += lQuality[jLayer];
3167 AliDebug(2, Form("Start N[%d] Q[%f] chi2[%f]", rLayers, quality, chi2));
3169 for (Int_t iter = 0; iter < 4; iter++) {
3170 // Try better cluster set
3171 Int_t nLayers(0); Float_t qualitynew(0.);
3172 Int_t indexes[4*AliTRDgeometry::kNlayer];
3173 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3174 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3175 Int_t bLayer = indexes[jLayer];
3176 bseed[bLayer].Reset("c");
3177 if(!(chamber = stack[bLayer])) continue;
3178 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
3179 bseed[bLayer].Fit(1);
3180 if(!bseed[bLayer].IsOK()) continue;
3182 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3183 qualitynew += lQuality[jLayer];
3185 if(rLayers > nLayers){
3186 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
3187 return iter>0?kTRUE:kFALSE;
3188 } else rLayers=nLayers;
3189 qualitynew /= rLayers;
3191 if(qualitynew > quality){
3192 AliDebug(4, Form("Quality[%f] worsen in iter[%d] to ref[%f].", qualitynew, iter, quality));
3193 return iter>0?kTRUE:kFALSE;
3194 } else quality = qualitynew;
3196 // try improve track parameters
3197 Float_t chi2new = FitTiltedRieman(bseed, kTRUE);
3199 AliDebug(4, Form("Chi2[%f] worsen in iter[%d] to ref[%f].", chi2new, iter, chi2));
3200 return iter>0?kTRUE:kFALSE;
3201 } else chi2 = chi2new;
3203 // store better tracklets
3204 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer]=bseed[jLayer];
3205 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
3208 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming()){
3209 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3210 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3211 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
3212 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3213 cstreamer << "ImproveSeedQuality"
3214 << "EventNumber=" << eventNumber
3215 << "CandidateNumber=" << candidateNumber
3216 << "Iteration=" << iter
3217 << "S0.=" << &cseed[0]
3218 << "S1.=" << &cseed[1]
3219 << "S2.=" << &cseed[2]
3220 << "S3.=" << &cseed[3]
3221 << "S4.=" << &cseed[4]
3222 << "S5.=" << &cseed[5]
3223 << "FitterT.=" << tiltedRieman
3228 // we are sure that at least 4 tracklets are OK !
3232 //_________________________________________________________________________
3233 Double_t AliTRDtrackerV1::CalculateTrackLikelihood(Double_t *chi2){
3235 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3236 // the track selection
3237 // The likelihood value containes:
3238 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3239 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3240 // For all Parameters an exponential dependency is used
3242 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3243 // - Array of chi2 values:
3244 // * Non-Constrained Tilted Riemann fit
3245 // * Vertex-Constrained Tilted Riemann fit
3246 // * z-Direction from Linear fit
3247 // Output: - The calculated track likelihood
3252 // Non-constrained Tilted Riemann
3253 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078);
3254 // Constrained Tilted Riemann
3255 Double_t likeChi2TC(1.);
3257 likeChi2TC = TMath::Exp(-chi2[1] * 0.677);
3258 Double_t r = likeChi2TC/likeChi2TR;
3259 if(r>1.e2){;} // -> a primary track use TC
3260 else if(r<1.e2) // -> a secondary track use TR
3262 else{;} // -> test not conclusive
3264 // Chi2 only on Z direction
3265 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14);
3266 // Chi2 angular resolution
3267 Double_t likeChi2Phi= TMath::Exp(-chi2[3] * 3.23);
3269 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2TC * likeChi2Phi;
3271 AliDebug(2, Form("Likelihood [%e]\n"
3272 " Rieman : chi2[%f] likelihood[%6.2e]\n"
3273 " Vertex : chi2[%f] likelihood[%6.2e]\n"
3274 " Z : chi2[%f] likelihood[%6.2e]\n"
3275 " Phi : chi2[%f] likelihood[%6.2e]"
3277 , chi2[0], likeChi2TR
3278 , chi2[1], likeChi2TC
3279 , chi2[2], likeChi2Z
3280 , chi2[3], likeChi2Phi
3283 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3284 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3285 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3286 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3287 cstreamer << "CalculateTrackLikelihood0"
3288 << "EventNumber=" << eventNumber
3289 << "CandidateNumber=" << candidateNumber
3290 << "LikeChi2Z=" << likeChi2Z
3291 << "LikeChi2TR=" << likeChi2TR
3292 << "LikeChi2TC=" << likeChi2TC
3293 << "LikeChi2Phi=" << likeChi2Phi
3294 << "TrackLikelihood=" << trackLikelihood
3298 return trackLikelihood;
3301 //____________________________________________________________________
3302 Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
3305 // Calculate the probability of this track candidate.
3308 // cseeds : array of candidate tracklets
3309 // planes : array of seeding planes (see seeding configuration)
3310 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3315 // Detailed description
3317 // The track quality is estimated based on the following 4 criteria:
3318 // 1. precision of the rieman fit on the Y direction (likea)
3319 // 2. chi2 on the Y direction (likechi2y)
3320 // 3. chi2 on the Z direction (likechi2z)
3321 // 4. number of attached clusters compared to a reference value
3322 // (see AliTRDrecoParam::fkFindable) (likeN)
3324 // The distributions for each type of probabilities are given below as of
3325 // (date). They have to be checked to assure consistency of estimation.
3328 // ratio of the total number of clusters/track which are expected to be found by the tracker.
3329 Double_t chi2y = GetChi2Y(&cseed[0]);
3330 Double_t chi2z = GetChi2Z(&cseed[0]);
3332 Float_t nclusters = 0.;
3333 Double_t sumda = 0.;
3334 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3335 Int_t jlayer = planes[ilayer];
3336 nclusters += cseed[jlayer].GetN2();
3337 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
3341 Double_t likea = TMath::Exp(-sumda * fkRecoParam->GetPhiSlope());
3342 Double_t likechi2y = 0.0000000001;
3343 if (fkReconstructor->IsCosmic() || chi2y < fkRecoParam->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fkRecoParam->GetChi2YSlope());
3344 Double_t likechi2z = TMath::Exp(-chi2z * fkRecoParam->GetChi2ZSlope());
3345 Double_t likeN = TMath::Exp(-(fkRecoParam->GetNMeanClusters() - nclusters) / fkRecoParam->GetNSigmaClusters());
3346 Double_t like = likea * likechi2y * likechi2z * likeN;
3348 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3349 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3350 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3351 Int_t nTracklets = 0; Float_t meanNcls = 0;
3352 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3353 if(!cseed[iseed].IsOK()) continue;
3355 meanNcls += cseed[iseed].GetN2();
3357 if(nTracklets) meanNcls /= nTracklets;
3358 // The Debug Stream contains the seed
3359 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3360 cstreamer << "CookLikelihood"
3361 << "EventNumber=" << eventNumber
3362 << "CandidateNumber=" << candidateNumber
3363 << "tracklet0.=" << &cseed[0]
3364 << "tracklet1.=" << &cseed[1]
3365 << "tracklet2.=" << &cseed[2]
3366 << "tracklet3.=" << &cseed[3]
3367 << "tracklet4.=" << &cseed[4]
3368 << "tracklet5.=" << &cseed[5]
3369 << "sumda=" << sumda
3370 << "chi2y=" << chi2y
3371 << "chi2z=" << chi2z
3372 << "likea=" << likea
3373 << "likechi2y=" << likechi2y
3374 << "likechi2z=" << likechi2z
3375 << "nclusters=" << nclusters
3376 << "likeN=" << likeN
3378 << "meanncls=" << meanNcls
3385 //____________________________________________________________________
3386 void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
3389 // Map seeding configurations to detector planes.
3392 // iconfig : configuration index
3393 // planes : member planes of this configuration. On input empty.
3396 // planes : contains the planes which are defining the configuration
3398 // Detailed description
3400 // Here is the list of seeding planes configurations together with
3401 // their topological classification:
3419 // The topologic quality is modeled as follows:
3420 // 1. The general model is define by the equation:
3421 // p(conf) = exp(-conf/2)
3422 // 2. According to the topologic classification, configurations from the same
3423 // class are assigned the agerage value over the model values.
3424 // 3. Quality values are normalized.
3426 // The topologic quality distribution as function of configuration is given below:
3428 // <img src="gif/topologicQA.gif">
3433 case 0: // 5432 TQ 0
3439 case 1: // 4321 TQ 0
3445 case 2: // 3210 TQ 0
3451 case 3: // 5321 TQ 1
3457 case 4: // 4210 TQ 1
3463 case 5: // 5431 TQ 1
3469 case 6: // 4320 TQ 1
3475 case 7: // 5430 TQ 2
3481 case 8: // 5210 TQ 2
3487 case 9: // 5421 TQ 3
3493 case 10: // 4310 TQ 3
3499 case 11: // 5410 TQ 4
3505 case 12: // 5420 TQ 5
3511 case 13: // 5320 TQ 5
3517 case 14: // 5310 TQ 5
3526 //____________________________________________________________________
3527 void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
3530 // Returns the extrapolation planes for a seeding configuration.
3533 // iconfig : configuration index
3534 // planes : planes which are not in this configuration. On input empty.
3537 // planes : contains the planes which are not in the configuration
3539 // Detailed description
3543 case 0: // 5432 TQ 0
3547 case 1: // 4321 TQ 0
3551 case 2: // 3210 TQ 0
3555 case 3: // 5321 TQ 1
3559 case 4: // 4210 TQ 1
3563 case 5: // 5431 TQ 1
3567 case 6: // 4320 TQ 1
3571 case 7: // 5430 TQ 2
3575 case 8: // 5210 TQ 2
3579 case 9: // 5421 TQ 3
3583 case 10: // 4310 TQ 3
3587 case 11: // 5410 TQ 4
3591 case 12: // 5420 TQ 5
3595 case 13: // 5320 TQ 5
3599 case 14: // 5310 TQ 5
3606 //____________________________________________________________________
3607 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3609 if(!fClusters) return NULL;
3610 Int_t ncls = fClusters->GetEntriesFast();
3611 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
3614 //____________________________________________________________________
3615 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3617 if(!fTracklets) return NULL;
3618 Int_t ntrklt = fTracklets->GetEntriesFast();
3619 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3622 //____________________________________________________________________
3623 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3625 if(!fTracks) return NULL;
3626 Int_t ntrk = fTracks->GetEntriesFast();
3627 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3632 // //_____________________________________________________________________________
3633 // Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3634 // , Int_t *outlist, Bool_t down)
3637 // // Sort eleements according occurancy
3638 // // The size of output array has is 2*n
3645 // Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3646 // Int_t *sindexF = new Int_t[2*n];
3647 // for (Int_t i = 0; i < n; i++) {
3651 // TMath::Sort(n,inlist,sindexS,down);
3653 // Int_t last = inlist[sindexS[0]];
3654 // Int_t val = last;
3656 // sindexF[0+n] = last;
3657 // Int_t countPos = 0;
3659 // // Find frequency
3660 // for (Int_t i = 1; i < n; i++) {
3661 // val = inlist[sindexS[i]];
3662 // if (last == val) {
3663 // sindexF[countPos]++;
3667 // sindexF[countPos+n] = val;
3668 // sindexF[countPos]++;
3672 // if (last == val) {
3676 // // Sort according frequency
3677 // TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3679 // for (Int_t i = 0; i < countPos; i++) {
3680 // outlist[2*i ] = sindexF[sindexS[i]+n];
3681 // outlist[2*i+1] = sindexF[sindexS[i]];
3684 // delete [] sindexS;
3685 // delete [] sindexF;
3692 //____________________________________________________________________
3693 void AliTRDtrackerV1::ResetSeedTB()
3695 // reset buffer for seeding time bin layers. If the time bin
3696 // layers are not allocated this function allocates them
3698 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3699 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3700 else fSeedTB[isl]->Clear();
3705 //_____________________________________________________________________________
3706 Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
3708 // Calculates normalized chi2 in y-direction
3709 // chi2 = Sum chi2 / n_tracklets
3711 Double_t chi2 = 0.; Int_t n = 0;
3712 for(Int_t ipl = kNPlanes; ipl--;){
3713 if(!tracklets[ipl].IsOK()) continue;
3714 chi2 += tracklets[ipl].GetChi2Y();
3717 return n ? chi2/n : 0.;
3720 //_____________________________________________________________________________
3721 Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
3723 // Calculates normalized chi2 in z-direction
3724 // chi2 = Sum chi2 / n_tracklets
3726 Double_t chi2 = 0; Int_t n = 0;
3727 for(Int_t ipl = kNPlanes; ipl--;){
3728 if(!tracklets[ipl].IsOK()) continue;
3729 chi2 += tracklets[ipl].GetChi2Z();
3732 return n ? chi2/n : 0.;
3735 //_____________________________________________________________________________
3736 Float_t AliTRDtrackerV1::GetChi2Phi(const AliTRDseedV1 *const tracklets) const
3738 // Calculates normalized chi2 for angular resolution
3739 // chi2 = Sum chi2 / n_tracklets
3741 Double_t chi2 = 0; Int_t n = 0;
3742 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3743 if(!tracklets[iLayer].IsOK()) continue;
3744 chi2 += tracklets[iLayer].GetChi2Phi();
3747 return n ? chi2/n: 0.;
3750 //____________________________________________________________________
3751 Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
3753 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3754 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3755 // are taken into account
3757 // Parameters: - Array of tracklets(AliTRDseedV1)
3759 // Output: - The reference x-position(Float_t)
3760 // Only kept for compatibility with the old code
3762 Int_t nDistances = 0;
3763 Float_t meanDistance = 0.;
3764 Int_t startIndex = 5;
3765 for(Int_t il =5; il > 0; il--){
3766 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3767 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3768 meanDistance += xdiff;
3771 if(tracklets[il].IsOK()) startIndex = il;
3773 if(tracklets[0].IsOK()) startIndex = 0;
3775 // We should normally never get here
3776 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3777 Int_t iok = 0, idiff = 0;
3778 // This attempt is worse and should be avoided:
3779 // check for two chambers which are OK and repeat this without taking the mean value
3780 // Strategy avoids a division by 0;
3781 for(Int_t il = 5; il >= 0; il--){
3782 if(tracklets[il].IsOK()){
3783 xpos[iok] = tracklets[il].GetX0();
3787 if(iok) idiff++; // to get the right difference;
3791 meanDistance = (xpos[0] - xpos[1])/idiff;
3794 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3799 meanDistance /= nDistances;
3801 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3804 //_____________________________________________________________________________
3805 Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
3807 // Track Fitter Function using the new class implementation of
3810 AliTRDtrackFitterRieman fitter;
3811 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3813 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3814 Double_t chi2 = fitter.Eval();
3815 // Update the tracklets
3816 Double_t cov[15]; Double_t x0;
3817 memset(cov, 0, sizeof(Double_t) * 15);
3818 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3819 x0 = tracklets[il].GetX0();
3820 tracklets[il].SetYref(0, fitter.GetYat(x0));
3821 tracklets[il].SetZref(0, fitter.GetZat(x0));
3822 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3823 tracklets[il].SetZref(1, fitter.GetDzDx());
3824 tracklets[il].SetC(fitter.GetCurvature());
3825 fitter.GetCovAt(x0, cov);
3826 tracklets[il].SetCovRef(cov);
3827 tracklets[il].SetChi2(chi2);
3832 //____________________________________________________________________
3833 void AliTRDtrackerV1::UnsetTrackletsTrack(const AliTRDtrackV1 * const track)
3835 // Remove tracklets from tracker list attached to "track"
3837 for(Int_t il(0); il<kNPlanes; il++){
3838 if((idx = track->GetTrackletIndex(il)) < 0) continue;
3839 delete (fTracklets->RemoveAt(idx));
3844 ///////////////////////////////////////////////////////
3846 // Resources of class AliTRDLeastSquare //
3848 ///////////////////////////////////////////////////////
3850 //_____________________________________________________________________________
3851 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
3853 // Constructor of the nested class AliTRDtrackFitterLeastSquare
3855 // Fast solving linear regresion in 2D
3857 // The data members have the following meaning
3868 // fCovarianceMatrix[0] : s2a
3869 // fCovarianceMatrix[1] : s2b
3870 // fCovarianceMatrix[2] : cov(ab)
3872 memset(fParams, 0, sizeof(Double_t) * 2);
3873 memset(fSums, 0, sizeof(Double_t) * 6);
3874 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3878 //_____________________________________________________________________________
3879 void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3881 // Adding Point to the fitter
3884 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3886 const Double_t &xpt = *x;
3887 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3889 fSums[1] += weight * xpt;
3890 fSums[2] += weight * y;
3891 fSums[3] += weight * xpt * y;
3892 fSums[4] += weight * xpt * xpt;
3893 fSums[5] += weight * y * y;
3896 //_____________________________________________________________________________
3897 void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3899 // Remove Point from the sample
3902 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3904 const Double_t &xpt = *x;
3906 fSums[1] -= weight * xpt;
3907 fSums[2] -= weight * y;
3908 fSums[3] -= weight * xpt * y;
3909 fSums[4] -= weight * xpt * xpt;
3910 fSums[5] -= weight * y * y;
3913 //_____________________________________________________________________________
3914 Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
3916 // Evaluation of the fit:
3917 // Calculation of the parameters
3918 // Calculation of the covariance matrix
3921 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
3922 if(TMath::Abs(det)<1.e-30) return kFALSE;
3924 // for(Int_t isum = 0; isum < 5; isum++)
3925 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3926 // printf("denominator = %f\n", denominator);
3927 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
3928 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
3929 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3931 // Covariance matrix
3932 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
3933 fCovarianceMatrix[0] = fSums[4] / den;
3934 fCovarianceMatrix[1] = fSums[0] / den;
3935 fCovarianceMatrix[2] = -fSums[1] / den;
3936 /* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
3937 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
3938 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
3945 //_____________________________________________________________________________
3946 Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
3948 // Returns the Function value of the fitted function at a given x-position
3950 return fParams[0] + fParams[1] * (*xpos);
3953 //_____________________________________________________________________________
3954 void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
3956 // Copies the values of the covariance matrix into the storage
3958 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
3961 //_____________________________________________________________________________
3962 void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
3966 memset(fParams, 0, sizeof(Double_t) * 2);
3967 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3968 memset(fSums, 0, sizeof(Double_t) * 6);
3971 ///////////////////////////////////////////////////////
3973 // Resources of class AliTRDtrackFitterRieman //
3975 ///////////////////////////////////////////////////////
3977 //_____________________________________________________________________________
3978 AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
3984 fSysClusterError(0.)
3987 // Default constructor
3989 fZfitter = new AliTRDLeastSquare;
3990 fCovarPolY = new TMatrixD(3,3);
3991 fCovarPolZ = new TMatrixD(2,2);
3992 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
3993 memset(fParameters, 0, sizeof(Double_t) * 5);
3994 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3995 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3998 //_____________________________________________________________________________
3999 AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
4003 if(fZfitter) delete fZfitter;
4004 if(fCovarPolY) delete fCovarPolY;
4005 if(fCovarPolZ) delete fCovarPolZ;
4008 //_____________________________________________________________________________
4009 void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
4014 fTrackFitter->StoreData(kTRUE);
4015 fTrackFitter->ClearPoints();
4021 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
4022 memset(fParameters, 0, sizeof(Double_t) * 5);
4023 memset(fSumPolY, 0, sizeof(Double_t) * 5);
4024 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
4025 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
4026 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
4027 (*fCovarPolY)(irow, icol) = 0.;
4028 if(irow < 2 && icol < 2)
4029 (*fCovarPolZ)(irow, icol) = 0.;
4033 //_____________________________________________________________________________
4034 void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
4036 // Add tracklet into the fitter
4038 if(itr >= AliTRDgeometry::kNlayer) return;
4039 fTracklets[itr] = tracklet;
4042 //_____________________________________________________________________________
4043 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
4046 // 1. Apply linear transformation and store points in the fitter
4047 // 2. Evaluate the fit
4048 // 3. Check if the result of the fit in z-direction is reasonable
4050 // 3a. Fix the parameters 3 and 4 with the results of a simple least
4052 // 3b. Redo the fit with the fixed parameters
4053 // 4. Store fit results (parameters and errors)
4058 fXref = CalculateReferenceX();
4059 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
4060 if(!fTrackFitter->GetNpoints()) return 1e10;
4062 fTrackFitter->Eval();
4064 fParameters[3] = fTrackFitter->GetParameter(3);
4065 fParameters[4] = fTrackFitter->GetParameter(4);
4066 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
4067 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
4068 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
4069 fTrackFitter->Eval();
4070 fTrackFitter->ReleaseParameter(3);
4071 fTrackFitter->ReleaseParameter(4);
4072 fParameters[3] = fTrackFitter->GetParameter(3);
4073 fParameters[4] = fTrackFitter->GetParameter(4);
4075 // Update the Fit Parameters and the errors
4076 fParameters[0] = fTrackFitter->GetParameter(0);
4077 fParameters[1] = fTrackFitter->GetParameter(1);
4078 fParameters[2] = fTrackFitter->GetParameter(2);
4080 // Prepare Covariance estimation
4081 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
4082 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
4083 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
4084 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
4085 fCovarPolY->Invert();
4086 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
4087 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
4088 fCovarPolZ->Invert();
4089 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
4092 //_____________________________________________________________________________
4093 void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(AliTRDseedV1 * const tracklet){
4095 // Does the transformations and updates the fitters
4096 // The following transformation is applied
4098 AliTRDcluster *cl = NULL;
4099 Double_t x, y, z, dx, t, w, we, yerr, zerr;
4101 if(!tracklet || !tracklet->IsOK()) return;
4102 Double_t tilt = tracklet->GetTilt();
4103 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
4104 if(!(cl = tracklet->GetClusters(itb))) continue;
4105 if(!cl->IsInChamber()) continue;
4106 if (!tracklet->IsUsable(itb)) continue;
4113 uvt[0] = 2. * x * t;
4115 uvt[2] = 2. * tilt * t;
4116 uvt[3] = 2. * tilt * dx * t;
4117 w = 2. * (y + tilt*z) * t;
4118 // error definition changes for the different calls
4120 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
4121 // Update sums for error calculation
4122 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
4124 zerr = 1./cl->GetSigmaZ2();
4125 for(Int_t ipol = 0; ipol < 5; ipol++){
4126 fSumPolY[ipol] += yerr;
4129 fSumPolZ[ipol] += zerr;
4133 fTrackFitter->AddPoint(uvt, w, we);
4134 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
4138 //_____________________________________________________________________________
4139 Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
4141 // Check whether z-results are acceptable
4142 // Definition: Distance between tracklet fit and track fit has to be
4143 // less then half a padlength
4144 // Point of comparision is at the anode wire
4146 Bool_t acceptablez = kTRUE;
4147 Double_t zref = 0.0;
4148 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
4149 if(!fTracklets[iLayer]->IsOK()) continue;
4150 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
4151 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
4152 acceptablez = kFALSE;
4157 //_____________________________________________________________________________
4158 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
4160 // Calculate y position out of the track parameters
4161 // y: R^2 = (x - x0)^2 + (y - y0)^2
4162 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
4163 // R = Sqrt() = 1/Curvature
4164 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
4167 Double_t disc = (x * fParameters[0] + fParameters[1]);
4168 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
4170 disc = TMath::Sqrt(disc);
4171 y = (1.0 - disc) / fParameters[0];
4176 //_____________________________________________________________________________
4177 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4179 // Return z position for a given x position
4180 // Simple linear function
4182 return fParameters[3] + fParameters[4] * (x - fXref);
4185 //_____________________________________________________________________________
4186 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4188 // Calculate dydx at a given radial position out of the track parameters
4189 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4190 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4191 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4192 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4193 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4195 Double_t x0 = -fParameters[1] / fParameters[0];
4196 Double_t curvature = GetCurvature();
4198 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4199 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4200 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4201 if (fParameters[0] < 0) yderiv *= -1.0;
4208 //_____________________________________________________________________________
4209 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4211 // Calculate track curvature
4214 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4215 if (curvature > 0.0)
4216 curvature = fParameters[0] / TMath::Sqrt(curvature);
4220 //_____________________________________________________________________________
4221 void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4223 // Error Definition according to gauss error propagation
4225 TMatrixD transform(3,3);
4226 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4227 transform(0,1) = transform(1,2) = x;
4228 transform(0,2) = x*x;
4229 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4230 covariance *= transform.T();
4231 cov[0] = covariance(0,0);
4232 TMatrixD transformZ(2,2);
4233 transformZ(0,0) = transformZ(1,1) = 1;
4234 transformZ(0,1) = x;
4235 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4236 covarZ *= transformZ.T();
4237 cov[1] = covarZ(0,0);
4241 //____________________________________________________________________
4242 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4244 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4245 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4246 // are taken into account
4248 // Parameters: - Array of tracklets(AliTRDseedV1)
4250 // Output: - The reference x-position(Float_t)
4252 Int_t nDistances = 0;
4253 Float_t meanDistance = 0.;
4254 Int_t startIndex = 5;
4255 for(Int_t il =5; il > 0; il--){
4256 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4257 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4258 meanDistance += xdiff;
4261 if(fTracklets[il]->IsOK()) startIndex = il;
4263 if(fTracklets[0]->IsOK()) startIndex = 0;
4265 // We should normally never get here
4266 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4267 Int_t iok = 0, idiff = 0;
4268 // This attempt is worse and should be avoided:
4269 // check for two chambers which are OK and repeat this without taking the mean value
4270 // Strategy avoids a division by 0;
4271 for(Int_t il = 5; il >= 0; il--){
4272 if(fTracklets[il]->IsOK()){
4273 xpos[iok] = fTracklets[il]->GetX0();
4277 if(iok) idiff++; // to get the right difference;
4281 meanDistance = (xpos[0] - xpos[1])/idiff;
4284 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4289 meanDistance /= nDistances;
4291 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());