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 const Float_t AliTRDtrackerV1::fgkMinClustersInTrack = 0.5; //
65 const Float_t AliTRDtrackerV1::fgkLabelFraction = 0.8; //
66 const Double_t AliTRDtrackerV1::fgkMaxChi2 = 12.0; //
67 const Double_t AliTRDtrackerV1::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
68 const Double_t AliTRDtrackerV1::fgkMaxStep = 2.0; // Maximal step size in propagation
69 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
70 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
71 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
72 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
74 const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
75 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
76 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
77 AliRieman* AliTRDtrackerV1::fgRieman = NULL;
78 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
79 TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
81 //____________________________________________________________________
82 AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
84 ,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.
168 if(!fkReconstructor->GetRecoParam() ){
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 nSeeds = 0, // total number of ESD seeds
283 nTRDseeds= 0, // number of seeds in the TRD acceptance
284 nTPCseeds= 0; // number of TPC seeds
285 Float_t foundMin = 20.0;
287 Float_t *quality = NULL;
289 nSeeds = event->GetNumberOfTracks();
290 // Sort tracks according to quality
291 // (covariance in the yz plane)
293 quality = new Float_t[nSeeds];
294 index = new Int_t[nSeeds];
295 for (Int_t iSeed = nSeeds; iSeed--;) {
296 AliESDtrack *seed = event->GetTrack(iSeed);
297 Double_t covariance[15];
298 seed->GetExternalCovariance(covariance);
299 quality[iSeed] = covariance[0] + covariance[2];
301 TMath::Sort(nSeeds, quality, index,kFALSE);
304 // Propagate all seeds
307 for (Int_t iSeed = 0; iSeed < nSeeds; iSeed++) {
309 // Get the seeds in sorted sequence
310 AliESDtrack *seed = event->GetTrack(index[iSeed]);
311 Float_t p4 = seed->GetC(seed->GetBz());
313 // Check the seed status
314 ULong_t status = seed->GetStatus();
315 if ((status & AliESDtrack::kTPCout) == 0) continue;
316 if ((status & AliESDtrack::kTRDout) != 0) continue;
318 // Propagate to the entrance in the TRD mother volume
319 new(&track) AliTRDtrackV1(*seed);
320 if(AliTRDgeometry::GetXtrdBeg() > (fgkMaxStep + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), fgkMaxStep)){
321 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
324 if(!AdjustSector(&track)){
325 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
328 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp) {
329 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
335 // store track status at TRD entrance
336 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
338 // prepare track and do propagation in the TRD
339 track.SetReconstructor(fkReconstructor);
340 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
341 expectedClr = FollowBackProlongation(track);
342 // check if track entered the TRD fiducial volume
343 if(track.GetTrackLow()){
344 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
347 // check if track was stopped in the TRD
349 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
355 // computes PID for track
357 // update calibration references using this track
358 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
359 // save calibration object
360 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
361 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
362 calibTrack->SetOwner();
363 seed->AddCalibObject(calibTrack);
366 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
367 track.UpdateESDtrack(seed);
370 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
372 // Make backup for back propagation
373 Int_t foundClr = track.GetNumberOfClusters();
374 if (foundClr >= foundMin) {
375 track.CookLabel(1. - fgkLabelFraction);
376 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
378 // Sign only gold tracks
379 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
380 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
382 Bool_t isGold = kFALSE;
385 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
386 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
392 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
393 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
394 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
399 if ((!isGold) && (track.GetBackupTrack())) {
400 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
401 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
408 // Propagation to the TOF
409 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
410 Int_t sm = track.GetSector();
411 // default value in case we have problems with the geometry.
412 Double_t xtof = 371.;
413 //Calculate radial position of the beginning of the TOF
414 //mother volume. In order to avoid mixing of the TRD
415 //and TOF modules some hard values are needed. This are:
416 //1. The path to the TOF module.
417 //2. The width of the TOF (29.05 cm)
418 //(with the help of Annalisa de Caro Mar-17-2009)
420 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
421 TGeoHMatrix *m = NULL;
422 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
424 if((m=gGeoManager->GetCurrentMatrix())){
425 m->LocalToMaster(loc, glob);
426 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
429 if(xtof > (fgkMaxStep + track.GetX()) && !PropagateToX(track, xtof, fgkMaxStep)){
430 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
433 if(!AdjustSector(&track)){
434 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
437 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp){
438 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
441 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
442 // TODO obsolete - delete
443 seed->SetTRDQuality(track.StatusForTOF());
445 seed->SetTRDBudget(track.GetBudget(0));
447 if(index) delete [] index;
448 if(quality) delete [] quality;
450 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
451 AliInfo(Form("Number of tracks: TRDout[%d]", nFound));
453 // run stand alone tracking
454 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
460 //____________________________________________________________________
461 Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
464 // Refits tracks within the TRD. The ESD event is expected to contain seeds
465 // at the outer part of the TRD.
466 // The tracks are propagated to the innermost time bin
467 // of the TRD and the ESD event is updated
468 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
471 Int_t nseed = 0; // contor for loaded seeds
472 Int_t found = 0; // contor for updated TRD tracks
475 if(!fClusters || !fClusters->GetEntriesFast()){
476 AliInfo("No TRD clusters");
480 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
481 AliESDtrack *seed = event->GetTrack(itrack);
482 ULong_t status = seed->GetStatus();
484 new(&track) AliTRDtrackV1(*seed);
485 if (track.GetX() < 270.0) {
486 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
490 // reject tracks which failed propagation in the TRD or
491 // are produced by the TRD stand alone tracker
492 if(!(status & AliESDtrack::kTRDout)) continue;
493 if(!(status & AliESDtrack::kTRDin)) continue;
496 track.ResetCovariance(50.0);
498 // do the propagation and processing
499 Bool_t kUPDATE = kFALSE;
500 Double_t xTPC = 250.0;
501 if(FollowProlongation(track)){
503 if (PropagateToX(track, xTPC, fgkMaxStep)) { // -with update
504 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
509 // Update the friend track
510 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
511 TObject *o = NULL; Int_t ic = 0;
512 AliTRDtrackV1 *calibTrack = NULL;
513 while((o = seed->GetCalibObject(ic++))){
514 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
515 calibTrack->SetTrackHigh(track.GetTrackHigh());
520 // Prolongate to TPC without update
522 AliTRDtrackV1 tt(*seed);
523 if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
526 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
527 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
532 //____________________________________________________________________
533 Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
535 // Extrapolates the TRD track in the TPC direction.
538 // t : the TRD track which has to be extrapolated
541 // number of clusters attached to the track
543 // Detailed description
545 // Starting from current radial position of track <t> this function
546 // extrapolates the track through the 6 TRD layers. The following steps
547 // are being performed for each plane:
549 // a. get plane limits in the local x direction
550 // b. check crossing sectors
551 // c. check track inclination
552 // 2. search tracklet in the tracker list (see GetTracklet() for details)
553 // 3. evaluate material budget using the geo manager
554 // 4. propagate and update track using the tracklet information.
559 Bool_t kStoreIn = kTRUE;
560 Int_t nClustersExpected = 0;
561 for (Int_t iplane = kNPlanes; iplane--;) {
563 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
564 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
565 if(!tracklet) continue;
566 if(!tracklet->IsOK()){
567 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
570 Double_t x = tracklet->GetX();//GetX0();
571 // reject tracklets which are not considered for inward refit
572 if(x > t.GetX()+fgkMaxStep) continue;
574 // append tracklet to track
575 t.SetTracklet(tracklet, index);
577 if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
578 if (!AdjustSector(&t)) break;
580 // Start global position
584 // End global position
585 Double_t alpha = t.GetAlpha(), y, z;
586 if (!t.GetProlongation(x,y,z)) break;
588 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
589 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
592 Double_t length = TMath::Sqrt(
593 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
594 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
595 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
598 // Get material budget
600 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
601 Double_t xrho= param[0]*param[4];
602 Double_t xx0 = param[1]; // Get mean propagation parameters
604 // Propagate and update
605 t.PropagateTo(x, xx0, xrho);
606 if (!AdjustSector(&t)) break;
613 Double_t cov[3]; tracklet->GetCovAt(x, cov);
614 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
615 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
616 if (chi2 < 1e+10 && t.Update(p, cov, chi2)){
617 nClustersExpected += tracklet->GetN();
621 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
623 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
624 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
625 if(!tracklet) continue;
626 t.SetTracklet(tracklet, index);
629 if(fkReconstructor->IsDebugStreaming()){
630 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
631 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
632 AliTRDtrackV1 track(t);
634 cstreamer << "FollowProlongation"
635 << "EventNumber=" << eventNumber
636 << "ncl=" << nClustersExpected
637 << "track.=" << &track
641 return nClustersExpected;
645 //_____________________________________________________________________________
646 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
648 // Extrapolates/Build the TRD track in the TOF direction.
651 // t : the TRD track which has to be extrapolated
654 // number of clusters attached to the track
656 // Starting from current radial position of track <t> this function
657 // extrapolates the track through the 6 TRD layers. The following steps
658 // are being performed for each plane:
659 // 1. Propagate track to the entrance of the next chamber:
660 // - get chamber limits in the radial direction
661 // - check crossing sectors
662 // - check track inclination
663 // - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
664 // 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
665 // Kalman filter is needed and tracklets are already linked to the track this step is skipped.
666 // 3. Fit tracklet using the information from the Kalman filter.
667 // 4. Propagate and update track at reference radial position of the tracklet.
668 // 5. Register tracklet with the tracker and track; update pulls monitoring.
671 // 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:
672 // - AliTRDtrackV1::kProlongation : track prolongation failed
673 // - AliTRDtrackV1::kPropagation : track prolongation failed
674 // - AliTRDtrackV1::kAdjustSector : failed during sector crossing
675 // - AliTRDtrackV1::kSnp : too large bending
676 // - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
677 // - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
678 // - AliTRDtrackV1::kUnknown : anything which is not covered before
679 // 2. By default the status of the track before first TRD update is saved.
684 // Alexandru Bercuci <A.Bercuci@gsi.de>
688 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
689 AliTRDtrackingChamber *chamber = NULL;
691 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
692 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
694 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
695 // in case of stand alone tracking we store all the pointers to the tracklets in a temporary array
696 AliTRDseedV1 *tracklets[kNPlanes];
697 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
698 for(Int_t ip = 0; ip < kNPlanes; ip++){
699 tracklets[ip] = t.GetTracklet(ip);
702 Bool_t kStoreIn = kTRUE, kPropagateIn = kTRUE;
704 // Loop through the TRD layers
705 TGeoHMatrix *matrix = NULL;
707 for (Int_t ily=0, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
708 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
710 // rough estimate of the entry point
711 if (!t.GetProlongation(fR[ily], y, z)){
713 t.SetStatus(AliTRDtrackV1::kProlongation);
714 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
718 // find sector / stack / detector
720 // TODO cross check with y value !
721 stk = fGeom->GetStack(z, ily);
722 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
723 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
724 AliDebug(3, Form("Propagate to det[%3d]", det));
726 // check if supermodule/chamber is installed
727 if( !fGeom->GetSMstatus(sm) ||
729 fGeom->IsHole(ily, stk, sm) ||
731 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
732 // propagate to the default radial position
733 if(fR[ily] > (fgkMaxStep + t.GetX()) && !PropagateToX(t, fR[ily], fgkMaxStep)){
735 t.SetStatus(AliTRDtrackV1::kPropagation);
736 AliDebug(4, "Failed Propagation [Missing Geometry]");
739 if(!AdjustSector(&t)){
741 t.SetStatus(AliTRDtrackV1::kAdjustSector);
742 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
745 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp){
747 t.SetStatus(AliTRDtrackV1::kSnp);
748 AliDebug(4, "Failed Max Snp [Missing Geometry]");
751 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
755 // retrieve rotation matrix for the current chamber
756 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
757 Double_t glb[] = {0., 0., 0.};
758 matrix->LocalToMaster(loc, glb);
760 // Propagate to the radial distance of the current layer
761 x = glb[0] - fgkMaxStep;
762 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)){
764 t.SetStatus(AliTRDtrackV1::kPropagation);
765 AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
768 if(!AdjustSector(&t)){
770 t.SetStatus(AliTRDtrackV1::kAdjustSector);
771 AliDebug(4, "Failed Adjust Sector Start");
774 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
776 t.SetStatus(AliTRDtrackV1::kSnp);
777 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
780 Bool_t doRecalculate = kFALSE;
781 if(sm != t.GetSector()){
783 doRecalculate = kTRUE;
785 if(stk != fGeom->GetStack(z, ily)){
786 stk = fGeom->GetStack(z, ily);
787 doRecalculate = kTRUE;
790 det = AliTRDgeometry::GetDetector(ily, stk, sm);
791 if(!(matrix = fGeom->GetClusterMatrix(det))){
792 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
793 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
796 matrix->LocalToMaster(loc, glb);
797 x = glb[0] - fgkMaxStep;
800 // check if track is well inside fiducial volume
801 if (!t.GetProlongation(x+fgkMaxStep, y, z)) {
803 t.SetStatus(AliTRDtrackV1::kProlongation);
804 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+fgkMaxStep, y, z));
807 if(fGeom->IsOnBoundary(det, y, z, .5)){
808 t.SetStatus(AliTRDtrackV1::kBoundary, ily);
809 AliDebug(4, "Failed Track on Boundary");
812 // mark track as entering the FIDUCIAL volume of TRD
818 ptrTracklet = tracklets[ily];
819 if(!ptrTracklet){ // BUILD TRACKLET
820 AliDebug(3, Form("Building tracklet det[%d]", det));
821 // check data in supermodule
822 if(!fTrSec[sm].GetNChambers()){
823 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
824 AliDebug(4, "Failed NoClusters");
827 if(fTrSec[sm].GetX(ily) < 1.){
828 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
829 AliDebug(4, "Failed NoX");
833 // check data in chamber
834 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
835 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
836 AliDebug(4, "Failed No Detector");
839 if(chamber->GetNClusters() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){
840 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
841 AliDebug(4, "Failed Not Enough Clusters in Detector");
845 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
846 ptrTracklet->SetReconstructor(fkReconstructor);
847 ptrTracklet->SetKink(t.IsKink());
848 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
849 ptrTracklet->SetX0(glb[0]+driftLength);
850 if(!tracklet.Init(&t)){
852 t.SetStatus(AliTRDtrackV1::kTrackletInit);
853 AliDebug(4, "Failed Tracklet Init");
856 if(!tracklet.AttachClusters(chamber, kTRUE)){
857 t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
859 AliTRDseedV1 trackletCp(*ptrTracklet);
860 UChar_t status(t.GetStatusTRD(ily));
861 (*cstreamer) << "FollowBackProlongation2"
862 <<"status=" << status
863 <<"tracklet.=" << &trackletCp
866 AliDebug(4, "Failed Attach Clusters");
869 AliDebug(3, Form("Number of Clusters in Tracklet: %d", tracklet.GetN()));
870 if(tracklet.GetN() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){
871 t.SetStatus(AliTRDtrackV1::kNoClustersTracklet, ily);
873 AliTRDseedV1 trackletCp(*ptrTracklet);
874 UChar_t status(t.GetStatusTRD(ily));
875 (*cstreamer) << "FollowBackProlongation2"
876 <<"status=" << status
877 <<"tracklet.=" << &trackletCp
880 AliDebug(4, "Failed N Clusters Attached");
883 ptrTracklet->UpdateUsed();
884 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
885 // propagate track to the radial position of the tracklet
886 ptrTracklet->UseClusters(); // TODO ? do we need this here ?
887 // fit tracklet no tilt correction
888 if(!ptrTracklet->Fit(kFALSE)){
889 t.SetStatus(AliTRDtrackV1::kNoFit, ily);
890 AliDebug(4, "Failed Tracklet Fit");
893 x = ptrTracklet->GetX(); //GetX0();
894 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)) {
896 t.SetStatus(AliTRDtrackV1::kPropagation);
897 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
900 if(!AdjustSector(&t)) {
902 t.SetStatus(AliTRDtrackV1::kAdjustSector);
903 AliDebug(4, "Failed Adjust Sector");
906 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
908 t.SetStatus(AliTRDtrackV1::kSnp);
909 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
914 kPropagateIn = kFALSE;
916 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
917 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
918 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
919 // update Kalman with the TRD measurement
920 if(chi2>1e+10){ // TODO
921 t.SetStatus(AliTRDtrackV1::kChi2, ily);
923 UChar_t status(t.GetStatusTRD());
924 AliTRDseedV1 trackletCp(*ptrTracklet);
925 AliTRDtrackV1 trackCp(t);
927 (*cstreamer) << "FollowBackProlongation1"
928 << "status=" << status
929 << "tracklet.=" << &trackletCp
930 << "track.=" << &trackCp
933 AliDebug(4, Form("Failed Chi2[%f]", chi2));
936 if(!t.Update(p, cov, chi2)) {
938 t.SetStatus(AliTRDtrackV1::kUpdate);
940 UChar_t status(t.GetStatusTRD());
941 AliTRDseedV1 trackletCp(*ptrTracklet);
942 AliTRDtrackV1 trackCp(t);
944 (*cstreamer) << "FollowBackProlongation1"
945 << "status=" << status
946 << "tracklet.=" << &trackletCp
947 << "track.=" << &trackCp
950 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]));
954 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
957 // load tracklet to the tracker
958 ptrTracklet->Update(&t);
959 ptrTracklet = SetTracklet(ptrTracklet);
960 Int_t index(fTracklets->GetEntriesFast()-1);
961 t.SetTracklet(ptrTracklet, index);
962 n += ptrTracklet->GetN();
963 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
965 // Reset material budget if 2 consecutive gold
966 // if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
968 // Make backup of the track until is gold
969 // TO DO update quality check of the track.
970 // consider comparison with fTimeBinsRange
971 Float_t ratio0 = ptrTracklet->GetN() / Float_t(fgNTimeBins);
972 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
977 //(ratio0+ratio1 > 1.5) &&
978 (t.GetNCross() == 0) &&
979 (TMath::Abs(t.GetSnp()) < 0.85) &&
980 (t.GetNumberOfClusters() > 20)){
984 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
985 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
988 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
989 AliTRDtrackV1 track(t);
991 (*cstreamer) << "FollowBackProlongation0"
992 << "EventNumber=" << eventNumber
994 << "track.=" << &track
1001 //_________________________________________________________________________
1002 Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
1004 // Fits a Riemann-circle to the given points without tilting pad correction.
1005 // The fit is performed using an instance of the class AliRieman (equations
1006 // and transformations see documentation of this class)
1007 // Afterwards all the tracklets are Updated
1009 // Parameters: - Array of tracklets (AliTRDseedV1)
1010 // - Storage for the chi2 values (beginning with direction z)
1011 // - Seeding configuration
1012 // Output: - The curvature
1014 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1016 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1017 Int_t *ppl = &allplanes[0];
1018 Int_t maxLayers = 6;
1023 for(Int_t il = 0; il < maxLayers; il++){
1024 if(!tracklets[ppl[il]].IsOK()) continue;
1025 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
1028 // Set the reference position of the fit and calculate the chi2 values
1029 memset(chi2, 0, sizeof(Double_t) * 2);
1030 for(Int_t il = 0; il < maxLayers; il++){
1031 // Reference positions
1032 tracklets[ppl[il]].Init(fitter);
1035 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1036 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1037 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1039 return fitter->GetC();
1042 //_________________________________________________________________________
1043 void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1046 // Performs a Riemann helix fit using the seedclusters as spacepoints
1047 // Afterwards the chi2 values are calculated and the seeds are updated
1049 // Parameters: - The four seedclusters
1050 // - The tracklet array (AliTRDseedV1)
1051 // - The seeding configuration
1056 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1058 for(Int_t i = 0; i < 4; i++){
1059 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1064 // Update the seed and calculated the chi2 value
1065 chi2[0] = 0; chi2[1] = 0;
1066 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1068 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1069 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1074 //_________________________________________________________________________
1075 Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1078 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1079 // assumed that the vertex position is set to 0.
1080 // This method is very usefull for high-pt particles
1081 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1082 // x0, y0: Center of the circle
1083 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1084 // zc: center of the pad row
1085 // Equation which has to be fitted (after transformation):
1086 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1088 // t = 1/(x^2 + y^2)
1090 // v = 2 * x * tan(phiT) * t
1091 // Parameters in the equation:
1092 // a = -1/y0, b = x0/y0, e = dz/dx
1094 // The Curvature is calculated by the following equation:
1095 // - curv = a/Sqrt(b^2 + 1) = 1/R
1096 // Parameters: - the 6 tracklets
1097 // - the Vertex constraint
1098 // Output: - the Chi2 value of the track
1103 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1104 fitter->StoreData(kTRUE);
1105 fitter->ClearPoints();
1106 AliTRDcluster *cl = NULL;
1108 Float_t x, y, z, w, t, error, tilt;
1111 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1112 if(!tracklets[ilr].IsOK()) continue;
1113 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1114 if(!tracklets[ilr].IsUsable(itb)) continue;
1115 cl = tracklets[ilr].GetClusters(itb);
1116 if(!cl->IsInChamber()) continue;
1120 tilt = tracklets[ilr].GetTilt();
1122 t = 1./(x * x + y * y);
1123 uvt[0] = 2. * x * t;
1124 uvt[1] = 2. * x * t * tilt ;
1125 w = 2. * (y + tilt * (z - zVertex)) * t;
1126 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
1127 fitter->AddPoint(uvt, w, error);
1133 // Calculate curvature
1134 Double_t a = fitter->GetParameter(0);
1135 Double_t b = fitter->GetParameter(1);
1136 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1138 Float_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1139 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
1140 tracklets[ip].SetC(curvature);
1142 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
1143 //Linear Model on z-direction
1144 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1145 Double_t slope = fitter->GetParameter(2);
1146 Double_t zref = slope * xref;
1147 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1148 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1149 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1150 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
1151 treeStreamer << "FitTiltedRiemanConstraint"
1152 << "EventNumber=" << eventNumber
1153 << "CandidateNumber=" << candidateNumber
1154 << "Curvature=" << curvature
1155 << "Chi2Track=" << chi2track
1156 << "Chi2Z=" << chi2Z
1163 //_________________________________________________________________________
1164 Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1167 // Performs a Riemann fit taking tilting pad correction into account
1168 // The equation of a Riemann circle, where the y position is substituted by the
1169 // measured y-position taking pad tilting into account, has to be transformed
1170 // into a 4-dimensional hyperplane equation
1171 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1172 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1173 // zc: center of the pad row
1174 // zt: z-position of the track
1175 // The z-position of the track is assumed to be linear dependent on the x-position
1176 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1177 // Transformation: u = 2 * x * t
1178 // v = 2 * tan(phiT) * t
1179 // w = 2 * tan(phiT) * (x - xref) * t
1180 // t = 1 / (x^2 + ymeas^2)
1181 // Parameters: a = -1/y0
1183 // c = (R^2 -x0^2 - y0^2)/y0
1186 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1187 // results from the simple riemann fit. Afterwards the fit is redone.
1188 // The curvature is calculated according to the formula:
1189 // curv = a/(1 + b^2 + c*a) = 1/R
1191 // Paramters: - Array of tracklets (connected to the track candidate)
1192 // - Flag selecting the error definition
1193 // Output: - Chi2 values of the track (in Parameter list)
1195 TLinearFitter *fitter = GetTiltedRiemanFitter();
1196 fitter->StoreData(kTRUE);
1197 fitter->ClearPoints();
1198 AliTRDLeastSquare zfitter;
1199 AliTRDcluster *cl = NULL;
1201 Double_t xref = CalculateReferenceX(tracklets);
1202 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1203 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1204 memset(sumPolY, 0, sizeof(Double_t) * 5);
1205 memset(sumPolZ, 0, sizeof(Double_t) * 3);
1207 // Containers for Least-square fitter
1208 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1209 if(!tracklets[ipl].IsOK()) continue;
1210 tilt = tracklets[ipl].GetTilt();
1211 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1212 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1213 if(!cl->IsInChamber()) continue;
1214 if (!tracklets[ipl].IsUsable(itb)) continue;
1221 uvt[0] = 2. * x * t;
1223 uvt[2] = 2. * tilt * t;
1224 uvt[3] = 2. * tilt * dx * t;
1225 w = 2. * (y + tilt*z) * t;
1226 // error definition changes for the different calls
1228 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
1229 fitter->AddPoint(uvt, w, we);
1230 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1231 // adding points for covariance matrix estimation
1232 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1234 errz = 1./cl->GetSigmaZ2();
1235 for(Int_t ipol = 0; ipol < 5; ipol++){
1236 sumPolY[ipol] += erry;
1239 sumPolZ[ipol] += errz;
1249 Double_t offset = fitter->GetParameter(3);
1250 Double_t slope = fitter->GetParameter(4);
1252 // Linear fitter - not possible to make boundaries
1253 // Do not accept non possible z and dzdx combinations
1254 Bool_t acceptablez = kTRUE;
1255 Double_t zref = 0.0;
1256 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1257 if(!tracklets[iLayer].IsOK()) continue;
1258 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
1259 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1260 acceptablez = kFALSE;
1263 Double_t dzmf = zfitter.GetFunctionParameter(1);
1264 Double_t zmf = zfitter.GetFunctionValue(&xref);
1265 fgTiltedRieman->FixParameter(3, zmf);
1266 fgTiltedRieman->FixParameter(4, dzmf);
1268 fitter->ReleaseParameter(3);
1269 fitter->ReleaseParameter(4);
1270 offset = fitter->GetParameter(3);
1271 slope = fitter->GetParameter(4);
1274 // Calculate Curvarture
1275 Double_t a = fitter->GetParameter(0);
1276 Double_t b = fitter->GetParameter(1);
1277 Double_t c = fitter->GetParameter(2);
1278 Double_t curvature = 1.0 + b*b - c*a;
1279 if (curvature > 0.0)
1280 curvature = a / TMath::Sqrt(curvature);
1282 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1284 // Prepare error calculation
1285 TMatrixD covarPolY(3,3);
1286 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1287 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1288 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1289 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1291 TMatrixD covarPolZ(2,2);
1292 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1293 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1296 // Update the tracklets
1297 Double_t x1, dy, dz;
1299 memset(cov, 0, sizeof(Double_t) * 15);
1300 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1302 x = tracklets[iLayer].GetX0();
1308 memset(cov, 0, sizeof(Double_t) * 3);
1309 TMatrixD transform(3,3);
1312 transform(0,2) = x*x;
1316 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1317 covariance *= transform.T();
1318 TMatrixD transformZ(2,2);
1319 transformZ(0,0) = transformZ(1,1) = 1;
1320 transformZ(0,1) = x;
1321 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1322 covarZ *= transformZ.T();
1323 // y: R^2 = (x - x0)^2 + (y - y0)^2
1324 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1325 // R = Sqrt() = 1/Curvature
1326 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1327 Double_t res = (x * a + b); // = (x - x0)/y0
1329 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1331 res = TMath::Sqrt(res);
1332 y = (1.0 - res) / a;
1334 cov[0] = covariance(0,0);
1335 cov[2] = covarZ(0,0);
1338 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1339 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1340 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1341 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1342 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1343 Double_t x0 = -b / a;
1344 if (-c * a + b * b + 1 > 0) {
1345 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
1346 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1347 if (a < 0) yderiv *= -1.0;
1351 z = offset + slope * (x - xref);
1353 tracklets[iLayer].SetYref(0, y);
1354 tracklets[iLayer].SetYref(1, dy);
1355 tracklets[iLayer].SetZref(0, z);
1356 tracklets[iLayer].SetZref(1, dz);
1357 tracklets[iLayer].SetC(curvature);
1358 tracklets[iLayer].SetCovRef(cov);
1359 tracklets[iLayer].SetChi2(chi2track);
1362 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1363 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1364 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1365 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1366 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1367 cstreamer << "FitTiltedRieman0"
1368 << "EventNumber=" << eventNumber
1369 << "CandidateNumber=" << candidateNumber
1371 << "Chi2Z=" << chi2z
1378 //____________________________________________________________________
1379 Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
1382 // Fit track with a staight line
1383 // Fills an AliTrackPoint array with np points
1384 // Function should be used to refit tracks when no magnetic field was on
1386 AliTRDLeastSquare yfitter, zfitter;
1387 AliTRDcluster *cl = NULL;
1389 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1391 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1392 if(!(tracklet = track->GetTracklet(ipl))) continue;
1393 if(!tracklet->IsOK()) continue;
1394 new(&work[ipl]) AliTRDseedV1(*tracklet);
1396 tracklets = &work[0];
1399 Double_t xref = CalculateReferenceX(tracklets);
1400 Double_t x, y, z, dx, ye, yr, tilt;
1401 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1402 if(!tracklets[ipl].IsOK()) continue;
1403 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1404 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1405 if (!tracklets[ipl].IsUsable(itb)) continue;
1409 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1413 Double_t z0 = zfitter.GetFunctionParameter(0);
1414 Double_t dzdx = zfitter.GetFunctionParameter(1);
1415 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1416 if(!tracklets[ipl].IsOK()) continue;
1417 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1418 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1419 if (!tracklets[ipl].IsUsable(itb)) continue;
1423 tilt = tracklets[ipl].GetTilt();
1425 yr = y + tilt*(z - z0 - dzdx*dx);
1426 // error definition changes for the different calls
1427 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1428 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1429 yfitter.AddPoint(&dx, yr, ye);
1433 Double_t y0 = yfitter.GetFunctionParameter(0);
1434 Double_t dydx = yfitter.GetFunctionParameter(1);
1435 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1437 //update track points array
1440 for(int ip=0; ip<np; ip++){
1441 points[ip].GetXYZ(xyz);
1442 xyz[1] = y0 + dydx * (xyz[0] - xref);
1443 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1444 points[ip].SetXYZ(xyz);
1451 //_________________________________________________________________________
1452 Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
1455 // Performs a Riemann fit taking tilting pad correction into account
1457 // Paramters: - Array of tracklets (connected to the track candidate)
1458 // - Flag selecting the error definition
1459 // Output: - Chi2 values of the track (in Parameter list)
1461 // The equations which has to be solved simultaneously are:
1463 // R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1464 // y^{*} = y - tg(h)(z - z_{t})
1465 // z_{t} = z_{0}+dzdx*(x-x_{r})
1467 // with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1468 // R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1469 // track in the x-z plane. Using the following transformations
1471 // t = 1 / (x^{2} + y^{2})
1473 // v = 2 * tan(h) * t
1474 // w = 2 * tan(h) * (x - x_{r}) * t
1476 // One gets the following linear equation
1478 // a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1480 // where the coefficients have the following meaning
1484 // c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1488 // The error calculation for the free term is thus
1490 // #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1493 // From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1496 // C = 1/R = a/(1 + b^{2} + c*a)
1500 // M.Ivanov <M.Ivanov@gsi.de>
1501 // A.Bercuci <A.Bercuci@gsi.de>
1502 // M.Fasel <M.Fasel@gsi.de>
1504 TLinearFitter *fitter = GetTiltedRiemanFitter();
1505 fitter->StoreData(kTRUE);
1506 fitter->ClearPoints();
1507 AliTRDLeastSquare zfitter;
1508 AliTRDcluster *cl = NULL;
1510 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1512 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1513 if(!(tracklet = track->GetTracklet(ipl))) continue;
1514 if(!tracklet->IsOK()) continue;
1515 new(&work[ipl]) AliTRDseedV1(*tracklet);
1517 tracklets = &work[0];
1520 Double_t xref = CalculateReferenceX(tracklets);
1521 AliDebugGeneral("AliTRDtrackerV1::FitRiemanTilt()", 4,
1522 Form("\nx0[(0)%6.2f (1)%6.2f (2)%6.2f (3)%6.2f (4)%6.2f (5)%6.2f] xref[%6.2f]", tracklets[0].GetX0(), tracklets[1].GetX0(), tracklets[2].GetX0(), tracklets[3].GetX0(), tracklets[4].GetX0(), tracklets[5].GetX0(), xref));
1523 Double_t x, y, z, t, tilt, dx, w, we;
1526 // Containers for Least-square fitter
1527 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1528 if(!tracklets[ipl].IsOK()) continue;
1529 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1530 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1531 //if (!tracklets[ipl].IsUsable(itb)) continue;
1535 tilt = tracklets[ipl].GetTilt();
1539 uvt[0] = 2. * x * t;
1541 uvt[2] = 2. * tilt * t;
1542 uvt[3] = 2. * tilt * dx * t;
1543 w = 2. * (y + tilt*z) * t;
1544 // error definition changes for the different calls
1546 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
1547 fitter->AddPoint(uvt, w, we);
1548 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1552 if(fitter->Eval()) return 1.E10;
1554 Double_t z0 = fitter->GetParameter(3);
1555 Double_t dzdx = fitter->GetParameter(4);
1558 // Linear fitter - not possible to make boundaries
1559 // Do not accept non possible z and dzdx combinations
1560 Bool_t accept = kTRUE;
1561 Double_t zref = 0.0;
1562 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1563 if(!tracklets[iLayer].IsOK()) continue;
1564 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
1565 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1570 Double_t dzmf = zfitter.GetFunctionParameter(1);
1571 Double_t zmf = zfitter.GetFunctionValue(&xref);
1572 fitter->FixParameter(3, zmf);
1573 fitter->FixParameter(4, dzmf);
1575 fitter->ReleaseParameter(3);
1576 fitter->ReleaseParameter(4);
1577 z0 = fitter->GetParameter(3); // = zmf ?
1578 dzdx = fitter->GetParameter(4); // = dzmf ?
1581 // Calculate Curvature
1582 Double_t a = fitter->GetParameter(0);
1583 Double_t b = fitter->GetParameter(1);
1584 Double_t c = fitter->GetParameter(2);
1585 Double_t y0 = 1. / a;
1586 Double_t x0 = -b * y0;
1587 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1588 if(tmp<=0.) return 1.E10;
1589 Double_t radius = TMath::Sqrt(tmp);
1590 Double_t curvature = 1.0 + b*b - c*a;
1591 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1593 // Calculate chi2 of the fit
1594 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
1595 AliDebugGeneral("AliTRDtrackerV1::FitRiemanTilt()", 4,
1596 Form("x0[%6.2f] y0[%6.2f] R[%6.2f] chi2[%f]\n", x0, y0, radius, chi2));
1598 // Update the tracklets
1600 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1601 x = tracklets[ip].GetX0();
1602 tmp = radius*radius-(x-x0)*(x-x0);
1603 if(tmp <= 0.) continue;
1604 tmp = TMath::Sqrt(tmp);
1606 // y: R^2 = (x - x0)^2 + (y - y0)^2
1607 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1608 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1609 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1610 tracklets[ip].SetYref(1, (x - x0) / tmp);
1611 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1612 tracklets[ip].SetZref(1, dzdx);
1613 tracklets[ip].SetC(curvature);
1614 tracklets[ip].SetChi2(chi2);
1617 //update track points array
1620 for(int ip=0; ip<np; ip++){
1621 points[ip].GetXYZ(xyz);
1622 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
1623 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1624 points[ip].SetXYZ(xyz);
1632 //____________________________________________________________________
1633 Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1635 // Kalman filter implementation for the TRD.
1636 // It returns the positions of the fit in the array "points"
1638 // Author : A.Bercuci@gsi.de
1640 // printf("Start track @ x[%f]\n", track->GetX());
1642 //prepare marker points along the track
1643 Int_t ip = np ? 0 : 1;
1645 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1646 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1649 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1652 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
1654 //Loop through the TRD planes
1655 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1656 // GET TRACKLET OR BUILT IT
1657 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1659 if(!(ptrTracklet = &tracklets[iplane])) continue;
1661 if(!(ptrTracklet = track->GetTracklet(iplane))){
1662 /*AliTRDtrackerV1 *tracker = NULL;
1663 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1664 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1665 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1669 if(!ptrTracklet->IsOK()) continue;
1671 Double_t x = ptrTracklet->GetX0();
1674 //don't do anything if next marker is after next update point.
1675 if((up?-1:1) * (points[ip].GetX() - x) - fgkMaxStep < 0) break;
1676 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1678 Double_t xyz[3]; // should also get the covariance
1680 track->Global2LocalPosition(xyz, track->GetAlpha());
1681 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1684 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1686 // Propagate closer to the next update point
1687 if(((up?-1:1) * (x - track->GetX()) + fgkMaxStep < 0) && !PropagateToX(*track, x + (up?-1:1)*fgkMaxStep, fgkMaxStep)) return -1.;
1689 if(!AdjustSector(track)) return -1;
1690 if(TMath::Abs(track->GetSnp()) > fgkMaxSnp) return -1;
1692 //load tracklet to the tracker and the track
1694 if((index = FindTracklet(ptrTracklet)) < 0){
1695 ptrTracklet = SetTracklet(&tracklet);
1696 index = fTracklets->GetEntriesFast()-1;
1698 track->SetTracklet(ptrTracklet, index);*/
1701 // register tracklet to track with tracklet creation !!
1702 // PropagateBack : loaded tracklet to the tracker and update index
1703 // RefitInward : update index
1704 // MakeTrack : loaded tracklet to the tracker and update index
1705 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1708 //Calculate the mean material budget along the path inside the chamber
1709 Double_t xyz0[3]; track->GetXYZ(xyz0);
1710 Double_t alpha = track->GetAlpha();
1711 Double_t xyz1[3], y, z;
1712 if(!track->GetProlongation(x, y, z)) return -1;
1713 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1714 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1716 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
1718 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1719 Double_t xrho = param[0]*param[4]; // density*length
1720 Double_t xx0 = param[1]; // radiation length
1722 //Propagate the track
1723 track->PropagateTo(x, xx0, xrho);
1724 if (!AdjustSector(track)) break;
1727 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1728 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1729 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
1730 if(chi2<1e+10) track->Update(p, cov, chi2);
1733 //Reset material budget if 2 consecutive gold
1734 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1735 } // end planes loop
1739 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1741 Double_t xyz[3]; // should also get the covariance
1743 track->Global2LocalPosition(xyz, track->GetAlpha());
1744 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1748 return track->GetChi2();
1751 //_________________________________________________________________________
1752 Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
1755 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1756 // A linear dependence on the x-value serves as a model.
1757 // The parameters are related to the tilted Riemann fit.
1758 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1759 // - the offset for the reference x
1761 // - the reference x position
1762 // Output: - The Chi2 value of the track in z-Direction
1764 Float_t chi2Z = 0, nLayers = 0;
1765 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
1766 if(!tracklets[iLayer].IsOK()) continue;
1767 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1768 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
1771 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1775 //_____________________________________________________________________________
1776 Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1779 // Starting from current X-position of track <t> this function
1780 // extrapolates the track up to radial position <xToGo>.
1781 // Returns 1 if track reaches the plane, and 0 otherwise
1784 const Double_t kEpsilon = 0.00001;
1786 // Current track X-position
1787 Double_t xpos = t.GetX();
1789 // Direction: inward or outward
1790 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
1792 while (((xToGo - xpos) * dir) > kEpsilon) {
1801 // The next step size
1802 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
1804 // Get the global position of the starting point
1807 // X-position after next step
1810 // Get local Y and Z at the X-position of the next step
1811 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
1813 // The global position of the end point of this prolongation step
1814 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1815 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1818 // Calculate the mean material budget between start and
1819 // end point of this prolongation step
1820 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
1822 // Propagate the track to the X-position after the next step
1823 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
1825 // Rotate the track if necessary
1828 // New track X-position
1838 //_____________________________________________________________________________
1839 Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) const
1842 // Reads AliTRDclusters from the file.
1843 // The names of the cluster tree and branches
1844 // should match the ones used in AliTRDclusterizer::WriteClusters()
1847 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1848 TObjArray *clusterArray = new TObjArray(nsize+1000);
1850 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1852 AliError("Can't get the branch !");
1855 branch->SetAddress(&clusterArray);
1858 Float_t nclusters = fkReconstructor->GetRecoParam()->GetNClusters();
1859 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
1860 array = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1861 array->SetOwner(kTRUE);
1864 // Loop through all entries in the tree
1865 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1868 AliTRDcluster *c = NULL;
1869 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1871 nbytes += clusterTree->GetEvent(iEntry);
1873 // Get the number of points in the detector
1874 Int_t nCluster = clusterArray->GetEntriesFast();
1875 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1876 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
1877 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1878 delete (clusterArray->RemoveAt(iCluster));
1882 delete clusterArray;
1887 //_____________________________________________________________________________
1888 Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1891 // Fills clusters into TRD tracking sectors
1894 if(!fkReconstructor->IsWritingClusters()){
1895 fClusters = AliTRDReconstructor::GetClusters();
1897 if (ReadClusters(fClusters, cTree)) {
1898 AliError("Problem with reading the clusters !");
1904 if(!fClusters || !fClusters->GetEntriesFast()){
1905 AliInfo("No TRD clusters");
1910 BuildTrackingContainers();
1912 //Int_t ncl = fClusters->GetEntriesFast();
1913 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1918 //_____________________________________________________________________________
1919 Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
1922 // Fills clusters into TRD tracking sectors
1923 // Function for use in the HLT
1925 if(!clusters || !clusters->GetEntriesFast()){
1926 AliInfo("No TRD clusters");
1930 fClusters = clusters;
1934 BuildTrackingContainers();
1936 //Int_t ncl = fClusters->GetEntriesFast();
1937 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1943 //____________________________________________________________________
1944 Int_t AliTRDtrackerV1::BuildTrackingContainers()
1946 // Building tracking containers for clusters
1948 Int_t nin =0, icl = fClusters->GetEntriesFast();
1950 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
1951 if(c->IsInChamber()) nin++;
1952 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
1953 Int_t detector = c->GetDetector();
1954 Int_t sector = fGeom->GetSector(detector);
1955 Int_t stack = fGeom->GetStack(detector);
1956 Int_t layer = fGeom->GetLayer(detector);
1958 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, icl);
1961 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
1962 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
1963 if(!fTrSec[isector].GetNChambers()) continue;
1964 fTrSec[isector].Init(fkReconstructor, cal);
1972 //____________________________________________________________________
1973 void AliTRDtrackerV1::UnloadClusters()
1976 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1977 // If option "force" is also set the containers are also deleted. This is useful
1982 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
1985 fTracklets->Delete();
1986 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
1989 if(IsClustersOwner()) fClusters->Delete();
1991 // save clusters array in the reconstructor for further use.
1992 if(!fkReconstructor->IsWritingClusters()){
1993 AliTRDReconstructor::SetClusters(fClusters);
1994 SetClustersOwner(kFALSE);
1995 } else AliTRDReconstructor::SetClusters(NULL);
1998 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
2000 // Increment the Event Number
2001 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
2004 // //____________________________________________________________________
2005 // void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2007 // const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2008 // if(!track) return;
2010 // AliTRDseedV1 *tracklet = NULL;
2011 // for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2012 // if(!(tracklet = track->GetTracklet(ily))) continue;
2013 // AliTRDcluster *c = NULL;
2014 // for(Int_t ic=AliTRDseed::kNclusters; ic--;){
2015 // if(!(c=tracklet->GetClusters(ic))) continue;
2022 //_____________________________________________________________________________
2023 Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
2026 // Rotates the track when necessary
2029 Double_t alpha = AliTRDgeometry::GetAlpha();
2030 Double_t y = track->GetY();
2031 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
2034 if (!track->Rotate( alpha)) {
2038 else if (y < -ymax) {
2039 if (!track->Rotate(-alpha)) {
2049 //____________________________________________________________________
2050 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
2052 // Find tracklet for TRD track <track>
2061 // Detailed description
2063 idx = track->GetTrackletIndex(p);
2064 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
2069 //____________________________________________________________________
2070 AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
2072 // Add this tracklet to the list of tracklets stored in the tracker
2075 // - tracklet : pointer to the tracklet to be added to the list
2078 // - the index of the new tracklet in the tracker tracklets list
2080 // Detailed description
2081 // Build the tracklets list if it is not yet created (late initialization)
2082 // and adds the new tracklet to the list.
2085 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2086 fTracklets->SetOwner(kTRUE);
2088 Int_t nentries = fTracklets->GetEntriesFast();
2089 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
2092 //____________________________________________________________________
2093 AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
2095 // Add this track to the list of tracks stored in the tracker
2098 // - track : pointer to the track to be added to the list
2101 // - the pointer added
2103 // Detailed description
2104 // Build the tracks list if it is not yet created (late initialization)
2105 // and adds the new track to the list.
2108 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2109 fTracks->SetOwner(kTRUE);
2111 Int_t nentries = fTracks->GetEntriesFast();
2112 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2117 //____________________________________________________________________
2118 Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
2121 // Steer tracking for one SM.
2124 // sector : Array of (SM) propagation layers containing clusters
2125 // esd : The current ESD event. On output it contains the also
2126 // the ESD (TRD) tracks found in this SM.
2129 // Number of tracks found in this TRD supermodule.
2131 // Detailed description
2133 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2134 // 2. Launch stack tracking.
2135 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2136 // 3. Pack results in the ESD event.
2140 Int_t nChambers = 0;
2141 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
2142 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
2143 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2145 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2146 if(!(chamber = stack[ilayer])) continue;
2147 if(chamber->GetNClusters() < fgNTimeBins * fkReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
2149 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
2151 if(nChambers < 4) continue;
2152 //AliInfo(Form("Doing stack %d", istack));
2153 nTracks += Clusters2TracksStack(stack, fTracksESD);
2155 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2157 for(int itrack=0; itrack<nTracks; itrack++){
2158 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2159 Int_t id = esd->AddTrack(esdTrack);
2161 // set ESD id to stand alone TRD tracks
2162 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
2163 esdTrack=esd->GetTrack(id);
2164 TObject *o(NULL); Int_t ic(0);
2165 AliTRDtrackV1 *calibTrack(NULL);
2166 while((o = esdTrack->GetCalibObject(ic++))){
2167 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2168 calibTrack->SetESDid(esdTrack->GetID());
2174 // Reset Track and Candidate Number
2175 AliTRDtrackerDebug::SetCandidateNumber(0);
2176 AliTRDtrackerDebug::SetTrackNumber(0);
2178 // delete ESD tracks in the array
2179 fTracksESD->Delete();
2183 //____________________________________________________________________
2184 Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
2187 // Make tracks in one TRD stack.
2190 // layer : Array of stack propagation layers containing clusters
2191 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2192 // On exit the tracks found in this stack are appended.
2195 // Number of tracks found in this stack.
2197 // Detailed description
2199 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2200 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2201 // See AliTRDtrackerV1::MakeSeeds() for more details.
2202 // 3. Arrange track candidates in decreasing order of their quality
2203 // 4. Classify tracks in 5 categories according to:
2204 // a) number of layers crossed
2206 // 5. Sign clusters by tracks in decreasing order of track quality
2207 // 6. Build AliTRDtrack out of seeding tracklets
2209 // 8. Build ESD track and register it to the output list
2212 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
2213 AliTRDtrackingChamber *chamber = NULL;
2214 AliTRDtrackingChamber **ci = NULL;
2215 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2216 Int_t pars[4]; // MakeSeeds parameters
2218 //Double_t alpha = AliTRDgeometry::GetAlpha();
2219 //Double_t shift = .5 * alpha;
2220 Int_t configs[kNConfigs];
2222 // Purge used clusters from the containers
2224 for(Int_t ic = kNPlanes; ic--; ci++){
2225 if(!(*ci)) continue;
2229 // Build initial seeding configurations
2230 Double_t quality = BuildSeedingConfigs(stack, configs);
2231 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2232 AliInfo(Form("Plane config %d %d %d Quality %f"
2233 , configs[0], configs[1], configs[2], quality));
2237 // Initialize contors
2238 Int_t ntracks, // number of TRD track candidates
2239 ntracks1, // number of registered TRD tracks/iter
2240 ntracks2 = 0; // number of all registered TRD tracks in stack
2244 Int_t ic = 0; ci = &stack[0];
2245 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2246 if(!(*ci)) return ntracks2;
2247 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
2250 // Loop over seeding configurations
2251 ntracks = 0; ntracks1 = 0;
2252 for (Int_t iconf = 0; iconf<3; iconf++) {
2253 pars[0] = configs[iconf];
2256 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
2257 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
2258 if(ntracks == kMaxTracksStack) break;
2260 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
2264 // Sort the seeds according to their quality
2265 Int_t sort[kMaxTracksStack];
2266 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
2268 // Initialize number of tracks so far and logic switches
2269 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2270 Bool_t signedTrack[kMaxTracksStack];
2271 Bool_t fakeTrack[kMaxTracksStack];
2272 for (Int_t i=0; i<ntracks; i++){
2273 signedTrack[i] = kFALSE;
2274 fakeTrack[i] = kFALSE;
2276 //AliInfo("Selecting track candidates ...");
2278 // Sieve clusters in decreasing order of track quality
2279 Double_t trackParams[7];
2280 // AliTRDseedV1 *lseed = NULL;
2281 Int_t jSieve = 0, candidates;
2283 //AliInfo(Form("\t\tITER = %i ", jSieve));
2285 // Check track candidates
2287 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
2288 Int_t trackIndex = sort[itrack];
2289 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
2292 // Calculate track parameters from tracklets seeds
2297 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2298 Int_t jseed = kNPlanes*trackIndex+jLayer;
2299 if(!sseed[jseed].IsOK()) continue;
2300 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
2301 // TODO here we get a sig fault which should never happen !
2302 sseed[jseed].UpdateUsed();
2303 ncl += sseed[jseed].GetN2();
2304 nused += sseed[jseed].GetNUsed();
2308 // Filter duplicated tracks
2310 //printf("Skip %d nused %d\n", trackIndex, nused);
2311 fakeTrack[trackIndex] = kTRUE;
2314 if (ncl>0 && Float_t(nused)/ncl >= .25){
2315 //printf("Skip %d nused/ncl >= .25\n", trackIndex);
2316 fakeTrack[trackIndex] = kTRUE;
2321 Bool_t skip = kFALSE;
2324 if(nlayers < 6) {skip = kTRUE; break;}
2325 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2329 if(nlayers < findable){skip = kTRUE; break;}
2330 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2334 if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
2335 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2339 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2343 if (nlayers == 3){skip = kTRUE; break;}
2344 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2349 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2351 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2353 signedTrack[trackIndex] = kTRUE;
2355 // Build track parameters
2356 AliTRDseedV1 *lseed =&sseed[trackIndex*6];
2358 while(idx<3 && !lseed->IsOK()) {
2362 Double_t x = lseed->GetX0();// - 3.5;
2363 trackParams[0] = x; //NEW AB
2364 trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);
2365 trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x);
2366 trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
2367 trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
2368 trackParams[5] = lseed->GetC();
2369 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2370 trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift; // Supermodule*/
2372 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
2373 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
2375 AliTRDseedV1 *dseed[6];
2376 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
2378 //Int_t eventNrInFile = esd->GetEventNumberInFile();
2379 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2380 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2381 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2382 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2383 cstreamer << "Clusters2TracksStack"
2384 << "EventNumber=" << eventNumber
2385 << "TrackNumber=" << trackNumber
2386 << "CandidateNumber=" << candidateNumber
2387 << "Iter=" << fSieveSeeding
2388 << "Like=" << fTrackQuality[trackIndex]
2389 << "S0.=" << dseed[0]
2390 << "S1.=" << dseed[1]
2391 << "S2.=" << dseed[2]
2392 << "S3.=" << dseed[3]
2393 << "S4.=" << dseed[4]
2394 << "S5.=" << dseed[5]
2395 << "p0=" << trackParams[0]
2396 << "p1=" << trackParams[1]
2397 << "p2=" << trackParams[2]
2398 << "p3=" << trackParams[3]
2399 << "p4=" << trackParams[4]
2400 << "p5=" << trackParams[5]
2401 << "p6=" << trackParams[6]
2403 << "NLayers=" << nlayers
2404 << "Findable=" << findable
2405 << "NUsed=" << nused
2409 AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
2411 AliDebug(1, "Track building failed.");
2415 //AliInfo("End of MakeTrack()");
2416 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2417 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2418 esdTrack->SetLabel(track->GetLabel());
2419 track->UpdateESDtrack(esdTrack);
2420 // write ESD-friends if neccessary
2421 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
2422 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2423 calibTrack->SetOwner();
2424 esdTrack->AddCalibObject(calibTrack);
2427 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
2431 } while(jSieve<5 && candidates); // end track candidates sieve
2432 if(!ntracks1) break;
2434 // increment counters
2435 ntracks2 += ntracks1;
2437 if(fkReconstructor->IsHLT()) break;
2440 // Rebuild plane configurations and indices taking only unused clusters into account
2441 quality = BuildSeedingConfigs(stack, configs);
2442 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
2444 for(Int_t ip = 0; ip < kNPlanes; ip++){
2445 if(!(chamber = stack[ip])) continue;
2446 chamber->Build(fGeom, cal);//Indices(fSieveSeeding);
2449 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2450 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2452 } while(fSieveSeeding<10); // end stack clusters sieve
2456 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2461 //___________________________________________________________________
2462 Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
2465 // Assign probabilities to chambers according to their
2466 // capability of producing seeds.
2470 // layers : Array of stack propagation layers for all 6 chambers in one stack
2471 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2472 // for details) in the decreasing order of their seeding probabilities.
2476 // Return top configuration quality
2478 // Detailed description:
2480 // To each chamber seeding configuration (see GetSeedingConfig() for
2481 // the list of all configurations) one defines 2 quality factors:
2482 // - an apriori topological quality (see GetSeedingConfig() for details) and
2483 // - a data quality based on the uniformity of the distribution of
2484 // clusters over the x range (time bins population). See CookChamberQA() for details.
2485 // The overall chamber quality is given by the product of this 2 contributions.
2488 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
2489 AliTRDtrackingChamber *chamber = NULL;
2490 for(int iplane=0; iplane<kNPlanes; iplane++){
2491 if(!(chamber = stack[iplane])) continue;
2492 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2495 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2496 Int_t planes[] = {0, 0, 0, 0};
2497 for(int iconf=0; iconf<kNConfigs; iconf++){
2498 GetSeedingConfig(iconf, planes);
2499 tconfig[iconf] = fgTopologicQA[iconf];
2500 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2503 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2504 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2505 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2506 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2508 return tconfig[configs[0]];
2511 //____________________________________________________________________
2512 Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
2515 // Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2516 // either missed by TPC prolongation or conversions inside the TRD volume.
2517 // For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
2520 // layers : Array of stack propagation layers containing clusters
2521 // sseed : Array of empty tracklet seeds. On exit they are filled.
2522 // ipar : Control parameters:
2523 // ipar[0] -> seeding chambers configuration
2524 // ipar[1] -> stack index
2525 // ipar[2] -> number of track candidates found so far
2528 // Number of tracks candidates found.
2530 // The following steps are performed:
2531 // 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2532 // radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2533 // is described in AliTRDtrackerV1::Clusters2TracksStack().
2534 // 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2535 // - for each seeding cluster in the lower seeding layer find
2536 // - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2537 // is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2538 // - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2540 // - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2541 // seeding clusters.
2542 // The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2543 // and AliTRDchamberTimeBin::GetClusters().
2544 // 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2545 // performed at this level
2546 // 4. Initialize seeding tracklets in the seeding chambers.
2547 // 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2548 // 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2549 // AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2550 // 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2551 // 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2552 // approximation of the track.
2553 // 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2554 // checked against the Riemann fit:
2555 // - position resolution in y
2556 // - angular resolution in the bending plane
2557 // - likelihood of the number of clusters attached to the tracklet
2558 // 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2559 // - Initialization of extrapolation tracklets with the fit parameters
2560 // - Attach clusters to extrapolated tracklets
2561 // - Helix fit of tracklets
2562 // 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2563 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
2564 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2565 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2566 // 14. Cooking labels for tracklets. Should be done only for MC
2567 // 15. Register seeds.
2570 // Marian Ivanov <M.Ivanov@gsi.de>
2571 // Alexandru Bercuci <A.Bercuci@gsi.de>
2572 // Markus Fasel <M.Fasel@gsi.de>
2574 AliTRDtrackingChamber *chamber = NULL;
2575 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
2576 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
2577 Int_t ncl, mcl; // working variable for looping over clusters
2578 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2580 // chi2[0] = tracklet chi2 on the Z direction
2581 // chi2[1] = tracklet chi2 on the R direction
2584 // this should be data member of AliTRDtrack TODO
2585 Double_t seedQuality[kMaxTracksStack];
2587 // unpack control parameters
2588 Int_t config = ipar[0];
2589 Int_t ntracks = ipar[1];
2590 Int_t istack = ipar[2];
2591 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
2592 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
2595 // Init chambers geometry
2596 Double_t hL[kNPlanes]; // Tilting angle
2597 Float_t padlength[kNPlanes]; // pad lenghts
2598 Float_t padwidth[kNPlanes]; // pad widths
2599 AliTRDpadPlane *pp = NULL;
2600 for(int iplane=0; iplane<kNPlanes; iplane++){
2601 pp = fGeom->GetPadPlane(iplane, istack);
2602 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
2603 padlength[iplane] = pp->GetLengthIPad();
2604 padwidth[iplane] = pp->GetWidthIPad();
2607 // Init anode wire position for chambers
2608 Double_t x0[kNPlanes], // anode wire position
2609 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
2610 TGeoHMatrix *matrix = NULL;
2611 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2612 Double_t glb[] = {0., 0., 0.};
2613 AliTRDtrackingChamber **cIter = &stack[0];
2614 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
2615 if(!(*cIter)) continue;
2616 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
2618 x0[iLayer] = fgkX0[iLayer];
2620 matrix->LocalToMaster(loc, glb);
2621 x0[iLayer] = glb[0];
2624 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
2626 // Build seeding layers
2629 for(int isl=0; isl<kNSeedPlanes; isl++){
2630 if(!(chamber = stack[planes[isl]])) continue;
2631 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
2634 if(nlayers < kNSeedPlanes) return ntracks;
2637 // Start finding seeds
2638 Double_t cond0[4], cond1[4], cond2[4];
2640 while((c[3] = (*fSeedTB[3])[icl++])){
2642 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2643 fSeedTB[0]->GetClusters(cond0, index, ncl);
2644 //printf("Found c[3] candidates 0 %d\n", ncl);
2647 c[0] = (*fSeedTB[0])[index[jcl++]];
2649 Double_t dx = c[3]->GetX() - c[0]->GetX();
2650 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2651 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2652 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
2653 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
2654 //printf("Found c[0] candidates 1 %d\n", mcl);
2658 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2660 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
2661 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2662 //printf("Found c[1] candidate 2 %p\n", c[2]);
2665 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].",
2666 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2667 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2668 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2669 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
2671 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
2675 AliTRDseedV1 *tseed = &cseed[0];
2677 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2678 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
2679 tseed->SetDetector(det);
2680 tseed->SetTilt(hL[iLayer]);
2681 tseed->SetPadLength(padlength[iLayer]);
2682 tseed->SetPadWidth(padwidth[iLayer]);
2683 tseed->SetReconstructor(fkReconstructor);
2684 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
2685 tseed->Init(GetRiemanFitter());
2686 tseed->SetStandAlone(kTRUE);
2689 Bool_t isFake = kFALSE;
2690 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2691 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2692 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2693 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2696 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2698 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2699 Int_t ll = c[3]->GetLabel(0);
2700 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2701 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2702 AliRieman *rim = GetRiemanFitter();
2703 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2705 <<"EventNumber=" << eventNumber
2706 <<"CandidateNumber=" << candidateNumber
2707 <<"isFake=" << isFake
2708 <<"config=" << config
2710 <<"chi2z=" << chi2[0]
2711 <<"chi2y=" << chi2[1]
2712 <<"Y2exp=" << cond2[0]
2713 <<"Z2exp=" << cond2[1]
2714 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2715 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2716 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2717 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2718 <<"yref0=" << yref[0]
2719 <<"yref1=" << yref[1]
2720 <<"yref2=" << yref[2]
2721 <<"yref3=" << yref[3]
2726 <<"Seed0.=" << &cseed[planes[0]]
2727 <<"Seed1.=" << &cseed[planes[1]]
2728 <<"Seed2.=" << &cseed[planes[2]]
2729 <<"Seed3.=" << &cseed[planes[3]]
2730 <<"RiemanFitter.=" << rim
2733 if(chi2[0] > fkReconstructor->GetRecoParam() ->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
2734 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
2735 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2738 if(chi2[1] > fkReconstructor->GetRecoParam() ->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
2739 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
2740 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2743 //AliInfo("Passed chi2 filter.");
2745 // try attaching clusters to tracklets
2747 AliTRDcluster *cl = NULL;
2748 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2749 Int_t jLayer = planes[iLayer];
2750 Int_t nNotInChamber = 0;
2751 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
2752 if(/*fkReconstructor->IsHLT()*/kFALSE){
2753 cseed[jLayer].UpdateUsed();
2754 if(!cseed[jLayer].IsOK()) continue;
2756 cseed[jLayer].Fit();
2757 cseed[jLayer].UpdateUsed();
2758 cseed[jLayer].ResetClusterIter();
2759 while((cl = cseed[jLayer].NextCluster())){
2760 if(!cl->IsInChamber()) nNotInChamber++;
2762 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2763 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
2768 if(mlayers < kNSeedPlanes){
2769 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
2770 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2774 // temporary exit door for the HLT
2775 if(fkReconstructor->IsHLT()){
2776 // attach clusters to extrapolation chambers
2777 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2778 Int_t jLayer = planesExt[iLayer];
2779 if(!(chamber = stack[jLayer])) continue;
2780 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
2781 cseed[jLayer].Fit();
2783 fTrackQuality[ntracks] = 1.; // dummy value
2785 if(ntracks == kMaxTracksStack) return ntracks;
2791 // Update Seeds and calculate Likelihood
2792 // fit tracklets and cook likelihood
2793 FitTiltedRieman(&cseed[0], kTRUE);
2794 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2795 Int_t jLayer = planes[iLayer];
2796 cseed[jLayer].Fit(kTRUE);
2798 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
2800 if (TMath::Log(1.E-9 + like) < fkReconstructor->GetRecoParam() ->GetTrackLikelihood()){
2801 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2802 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2805 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2807 // book preliminary results
2808 seedQuality[ntracks] = like;
2809 fSeedLayer[ntracks] = config;/*sLayer;*/
2811 // attach clusters to the extrapolation seeds
2813 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2814 Int_t jLayer = planesExt[iLayer];
2815 if(!(chamber = stack[jLayer])) continue;
2817 // fit extrapolated seed
2818 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2819 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2820 AliTRDseedV1 pseed = cseed[jLayer];
2821 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2823 cseed[jLayer] = pseed;
2824 FitTiltedRieman(cseed, kTRUE);
2825 cseed[jLayer].Fit(kTRUE);
2829 // AliInfo("Extrapolation done.");
2830 // Debug Stream containing all the 6 tracklets
2831 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2832 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2833 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2834 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2835 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2836 cstreamer << "MakeSeeds1"
2837 << "EventNumber=" << eventNumber
2838 << "CandidateNumber=" << candidateNumber
2839 << "S0.=" << &cseed[0]
2840 << "S1.=" << &cseed[1]
2841 << "S2.=" << &cseed[2]
2842 << "S3.=" << &cseed[3]
2843 << "S4.=" << &cseed[4]
2844 << "S5.=" << &cseed[5]
2845 << "FitterT.=" << tiltedRieman
2849 if(fkReconstructor->GetRecoParam()->HasImproveTracklets()){
2850 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
2851 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer] = cseed[jLayer];
2853 if(ImproveSeedQuality(stack, cseed) < mlayers+elayers){
2854 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2855 AliDebug(3, "Filter on improve seeds.");
2858 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer] = bseed[jLayer];
2861 //AliInfo("Improve seed quality done.");
2863 // fit full track and cook likelihoods
2864 // Double_t curv = FitRieman(&cseed[0], chi2);
2865 // Double_t chi2ZF = chi2[0] / TMath::Max((mlayers - 3.), 1.);
2866 // Double_t chi2RF = chi2[1] / TMath::Max((mlayers - 3.), 1.);
2868 // do the final track fitting (Once with vertex constraint and once without vertex constraint)
2869 Double_t chi2Vals[3];
2870 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
2871 if(fkReconstructor->GetRecoParam()->IsVertexConstrained())
2872 chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ()); // Do Vertex Constrained fit if desired
2875 chi2Vals[2] = GetChi2Z(&cseed[0]) / TMath::Max((mlayers - 3.), 1.);
2876 // Chi2 definitions in testing stage
2877 //chi2Vals[2] = GetChi2ZTest(&cseed[0]);
2878 fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
2879 //AliInfo("Hyperplane fit done\n");
2881 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2882 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2883 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2884 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2885 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2886 TLinearFitter *fitterT = GetTiltedRiemanFitter();
2888 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2889 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2891 cstreamer << "MakeSeeds2"
2892 << "EventNumber=" << eventNumber
2893 << "CandidateNumber=" << candidateNumber
2894 << "Chi2TR=" << chi2Vals[0]
2895 << "Chi2TC=" << chi2Vals[1]
2896 << "Nlayers=" << mlayers
2897 << "NClusters=" << ncls
2899 << "S0.=" << &cseed[0]
2900 << "S1.=" << &cseed[1]
2901 << "S2.=" << &cseed[2]
2902 << "S3.=" << &cseed[3]
2903 << "S4.=" << &cseed[4]
2904 << "S5.=" << &cseed[5]
2905 << "FitterT.=" << fitterT
2906 << "FitterTC.=" << fitterTC
2911 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2912 if(ntracks == kMaxTracksStack){
2913 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2924 //_____________________________________________________________________________
2925 AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const seeds, Double_t *params)
2928 // Build a TRD track out of tracklet candidates
2931 // seeds : array of tracklets
2932 // params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
2933 // [0] - radial position of the track at reference point
2934 // [1] - y position of the fit at [0]
2935 // [2] - z position of the fit at [0]
2936 // [3] - snp of the first tracklet
2937 // [4] - tgl of the first tracklet
2938 // [5] - curvature of the Riemann fit - 1/pt
2939 // [6] - sector rotation angle
2944 // Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
2945 // (diagonal with constant variance terms TODO - correct parameterization)
2947 // In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
2948 // offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
2949 // for details). Do also MC label calculation and PID if propagation successfully.
2952 Double_t alpha = AliTRDgeometry::GetAlpha();
2953 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
2956 c[ 0] = 0.2; // s^2_y
2957 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
2958 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
2959 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
2960 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[5]*params[5]*0.01; // s^2_1/pt
2962 AliTRDtrackV1 track(seeds, ¶ms[1], c, params[0], params[6]*alpha+shift);
2963 track.PropagateTo(params[0]-5.0);
2964 AliTRDseedV1 *ptrTracklet = NULL;
2966 // skip Kalman filter for HLT
2967 if(/*fkReconstructor->IsHLT()*/kFALSE){
2968 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
2969 track.UnsetTracklet(jLayer);
2970 ptrTracklet = &seeds[jLayer];
2971 if(!ptrTracklet->IsOK()) continue;
2972 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
2973 ptrTracklet = SetTracklet(ptrTracklet);
2974 ptrTracklet->UseClusters();
2975 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
2977 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
2978 ptrTrack->CookPID();
2979 ptrTrack->CookLabel(.9);
2980 ptrTrack->SetReconstructor(fkReconstructor);
2984 // prevent the error message in AliTracker::MeanMaterialBudget: "start point out of geometry"
2985 if(TMath::Abs(track.GetX()) + TMath::Abs(track.GetY()) + TMath::Abs(track.GetZ()) > 10000)
2988 track.ResetCovariance(1);
2989 Int_t nc = TMath::Abs(FollowBackProlongation(track));
2990 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()){
2991 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2992 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2993 Double_t p[5]; // Track Params for the Debug Stream
2994 track.GetExternalParameters(params[0], p);
2995 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2997 << "EventNumber=" << eventNumber
2998 << "CandidateNumber=" << candidateNumber
3000 << "X=" << params[0]
3006 << "Yin=" << params[1]
3007 << "Zin=" << params[2]
3008 << "snpin=" << params[3]
3009 << "tndin=" << params[4]
3010 << "crvin=" << params[5]
3011 << "track.=" << &track
3014 if (nc < 30) return NULL;
3016 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
3017 ptrTrack->SetReconstructor(fkReconstructor);
3018 ptrTrack->CookLabel(.9);
3020 // computes PID for track
3021 ptrTrack->CookPID();
3022 // update calibration references using this track
3023 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
3025 AliInfo("Could not get Calibra instance\n");
3026 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(ptrTrack);
3032 //____________________________________________________________________
3033 Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed)
3036 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3039 // layers : Array of propagation layers for a stack/supermodule
3040 // cseed : Array of 6 seeding tracklets which has to be improved
3043 // cssed : Improved seeds
3045 // Detailed description
3047 // Iterative procedure in which new clusters are searched for each
3048 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3049 // can be maximized. If some optimization is found the old seeds are replaced.
3054 // make a local working copy
3055 AliTRDtrackingChamber *chamber = NULL;
3056 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3058 Float_t quality(0.),
3059 lQuality[] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
3061 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3062 bseed[jLayer] = cseed[jLayer];
3063 if(!bseed[jLayer].IsOK()) continue;
3065 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3066 quality += lQuality[jLayer];
3068 Float_t chi2 = FitTiltedRieman(bseed, kTRUE);
3070 for (Int_t iter = 0; iter < 4; iter++) {
3071 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
3073 // Try better cluster set
3074 Int_t nLayers(0); Float_t qualitynew(0.);
3076 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3077 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3078 Int_t bLayer = indexes[jLayer];
3079 bseed[bLayer].Reset("c");
3080 if(!(chamber = stack[bLayer])) continue;
3081 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
3082 bseed[bLayer].Fit(kTRUE);
3083 if(!bseed[bLayer].IsOK()) continue;
3085 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3086 qualitynew += lQuality[jLayer];
3088 if(rLayers > nLayers){
3089 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
3091 } else rLayers=nLayers;
3093 if(qualitynew >= quality){
3094 AliDebug(4, Form("Quality worsen in iter[%d].", iter));
3096 } else quality = qualitynew;
3098 // try improve track parameters
3099 AliTRDseedV1 tseed[AliTRDgeometry::kNlayer];
3100 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) tseed[jLayer]=bseed[jLayer];
3101 Float_t chi2new = FitTiltedRieman(tseed, kTRUE);
3103 AliDebug(4, Form("Chi2 worsen in iter[%d].", iter));
3105 } else chi2 = chi2new;
3107 // store better tracklets
3108 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer]=tseed[jLayer];
3111 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming()){
3112 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3113 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3114 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
3115 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3116 cstreamer << "ImproveSeedQuality"
3117 << "EventNumber=" << eventNumber
3118 << "CandidateNumber=" << candidateNumber
3119 << "Iteration=" << iter
3120 << "S0.=" << &bseed[0]
3121 << "S1.=" << &bseed[1]
3122 << "S2.=" << &bseed[2]
3123 << "S3.=" << &bseed[3]
3124 << "S4.=" << &bseed[4]
3125 << "S5.=" << &bseed[5]
3126 << "FitterT.=" << tiltedRieman
3130 // we are sure that at least 2 tracklets are OK !
3134 //_________________________________________________________________________
3135 Double_t AliTRDtrackerV1::CalculateTrackLikelihood(const AliTRDseedV1 *const tracklets, Double_t *chi2){
3137 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3138 // the track selection
3139 // The likelihood value containes:
3140 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3141 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3142 // For all Parameters an exponential dependency is used
3144 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3145 // - Array of chi2 values:
3146 // * Non-Constrained Tilted Riemann fit
3147 // * Vertex-Constrained Tilted Riemann fit
3148 // * z-Direction from Linear fit
3149 // Output: - The calculated track likelihood
3154 Double_t chi2phi = 0, nLayers = 0;
3155 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3156 if(!tracklets[iLayer].IsOK()) continue;
3157 chi2phi += tracklets[iLayer].GetChi2Phi();
3160 chi2phi /= Float_t (nLayers - 2.0);
3162 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14); // Chi2Z
3163 Double_t likeChi2TC = (fkReconstructor->GetRecoParam()->IsVertexConstrained()) ?
3164 TMath::Exp(-chi2[1] * 0.677) : 1; // Constrained Tilted Riemann
3165 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078); // Non-constrained Tilted Riemann
3166 Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);//3.23
3167 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2Phi;
3169 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3170 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3171 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3172 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3173 cstreamer << "CalculateTrackLikelihood0"
3174 << "EventNumber=" << eventNumber
3175 << "CandidateNumber=" << candidateNumber
3176 << "LikeChi2Z=" << likeChi2Z
3177 << "LikeChi2TR=" << likeChi2TR
3178 << "LikeChi2TC=" << likeChi2TC
3179 << "LikeChi2Phi=" << likeChi2Phi
3180 << "TrackLikelihood=" << trackLikelihood
3184 return trackLikelihood;
3187 //____________________________________________________________________
3188 Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
3191 // Calculate the probability of this track candidate.
3194 // cseeds : array of candidate tracklets
3195 // planes : array of seeding planes (see seeding configuration)
3196 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3201 // Detailed description
3203 // The track quality is estimated based on the following 4 criteria:
3204 // 1. precision of the rieman fit on the Y direction (likea)
3205 // 2. chi2 on the Y direction (likechi2y)
3206 // 3. chi2 on the Z direction (likechi2z)
3207 // 4. number of attached clusters compared to a reference value
3208 // (see AliTRDrecoParam::fkFindable) (likeN)
3210 // The distributions for each type of probabilities are given below as of
3211 // (date). They have to be checked to assure consistency of estimation.
3214 // ratio of the total number of clusters/track which are expected to be found by the tracker.
3215 const AliTRDrecoParam *fRecoPars = fkReconstructor->GetRecoParam();
3217 Double_t chi2y = GetChi2Y(&cseed[0]);
3218 Double_t chi2z = GetChi2Z(&cseed[0]);
3220 Float_t nclusters = 0.;
3221 Double_t sumda = 0.;
3222 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3223 Int_t jlayer = planes[ilayer];
3224 nclusters += cseed[jlayer].GetN2();
3225 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
3229 Double_t likea = TMath::Exp(-sumda * fRecoPars->GetPhiSlope());
3230 Double_t likechi2y = 0.0000000001;
3231 if (fkReconstructor->IsCosmic() || chi2y < fRecoPars->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fRecoPars->GetChi2YSlope());
3232 Double_t likechi2z = TMath::Exp(-chi2z * fRecoPars->GetChi2ZSlope());
3233 Double_t likeN = TMath::Exp(-(fRecoPars->GetNMeanClusters() - nclusters) / fRecoPars->GetNSigmaClusters());
3234 Double_t like = likea * likechi2y * likechi2z * likeN;
3236 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3237 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3238 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3239 Int_t nTracklets = 0; Float_t meanNcls = 0;
3240 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3241 if(!cseed[iseed].IsOK()) continue;
3243 meanNcls += cseed[iseed].GetN2();
3245 if(nTracklets) meanNcls /= nTracklets;
3246 // The Debug Stream contains the seed
3247 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3248 cstreamer << "CookLikelihood"
3249 << "EventNumber=" << eventNumber
3250 << "CandidateNumber=" << candidateNumber
3251 << "tracklet0.=" << &cseed[0]
3252 << "tracklet1.=" << &cseed[1]
3253 << "tracklet2.=" << &cseed[2]
3254 << "tracklet3.=" << &cseed[3]
3255 << "tracklet4.=" << &cseed[4]
3256 << "tracklet5.=" << &cseed[5]
3257 << "sumda=" << sumda
3258 << "chi2y=" << chi2y
3259 << "chi2z=" << chi2z
3260 << "likea=" << likea
3261 << "likechi2y=" << likechi2y
3262 << "likechi2z=" << likechi2z
3263 << "nclusters=" << nclusters
3264 << "likeN=" << likeN
3266 << "meanncls=" << meanNcls
3273 //____________________________________________________________________
3274 void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
3277 // Map seeding configurations to detector planes.
3280 // iconfig : configuration index
3281 // planes : member planes of this configuration. On input empty.
3284 // planes : contains the planes which are defining the configuration
3286 // Detailed description
3288 // Here is the list of seeding planes configurations together with
3289 // their topological classification:
3307 // The topologic quality is modeled as follows:
3308 // 1. The general model is define by the equation:
3309 // p(conf) = exp(-conf/2)
3310 // 2. According to the topologic classification, configurations from the same
3311 // class are assigned the agerage value over the model values.
3312 // 3. Quality values are normalized.
3314 // The topologic quality distribution as function of configuration is given below:
3316 // <img src="gif/topologicQA.gif">
3321 case 0: // 5432 TQ 0
3327 case 1: // 4321 TQ 0
3333 case 2: // 3210 TQ 0
3339 case 3: // 5321 TQ 1
3345 case 4: // 4210 TQ 1
3351 case 5: // 5431 TQ 1
3357 case 6: // 4320 TQ 1
3363 case 7: // 5430 TQ 2
3369 case 8: // 5210 TQ 2
3375 case 9: // 5421 TQ 3
3381 case 10: // 4310 TQ 3
3387 case 11: // 5410 TQ 4
3393 case 12: // 5420 TQ 5
3399 case 13: // 5320 TQ 5
3405 case 14: // 5310 TQ 5
3414 //____________________________________________________________________
3415 void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
3418 // Returns the extrapolation planes for a seeding configuration.
3421 // iconfig : configuration index
3422 // planes : planes which are not in this configuration. On input empty.
3425 // planes : contains the planes which are not in the configuration
3427 // Detailed description
3431 case 0: // 5432 TQ 0
3435 case 1: // 4321 TQ 0
3439 case 2: // 3210 TQ 0
3443 case 3: // 5321 TQ 1
3447 case 4: // 4210 TQ 1
3451 case 5: // 5431 TQ 1
3455 case 6: // 4320 TQ 1
3459 case 7: // 5430 TQ 2
3463 case 8: // 5210 TQ 2
3467 case 9: // 5421 TQ 3
3471 case 10: // 4310 TQ 3
3475 case 11: // 5410 TQ 4
3479 case 12: // 5420 TQ 5
3483 case 13: // 5320 TQ 5
3487 case 14: // 5310 TQ 5
3494 //____________________________________________________________________
3495 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3497 if(!fClusters) return NULL;
3498 Int_t ncls = fClusters->GetEntriesFast();
3499 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
3502 //____________________________________________________________________
3503 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3505 if(!fTracklets) return NULL;
3506 Int_t ntrklt = fTracklets->GetEntriesFast();
3507 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3510 //____________________________________________________________________
3511 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3513 if(!fTracks) return NULL;
3514 Int_t ntrk = fTracks->GetEntriesFast();
3515 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3520 // //_____________________________________________________________________________
3521 // Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3522 // , Int_t *outlist, Bool_t down)
3525 // // Sort eleements according occurancy
3526 // // The size of output array has is 2*n
3533 // Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3534 // Int_t *sindexF = new Int_t[2*n];
3535 // for (Int_t i = 0; i < n; i++) {
3539 // TMath::Sort(n,inlist,sindexS,down);
3541 // Int_t last = inlist[sindexS[0]];
3542 // Int_t val = last;
3544 // sindexF[0+n] = last;
3545 // Int_t countPos = 0;
3547 // // Find frequency
3548 // for (Int_t i = 1; i < n; i++) {
3549 // val = inlist[sindexS[i]];
3550 // if (last == val) {
3551 // sindexF[countPos]++;
3555 // sindexF[countPos+n] = val;
3556 // sindexF[countPos]++;
3560 // if (last == val) {
3564 // // Sort according frequency
3565 // TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3567 // for (Int_t i = 0; i < countPos; i++) {
3568 // outlist[2*i ] = sindexF[sindexS[i]+n];
3569 // outlist[2*i+1] = sindexF[sindexS[i]];
3572 // delete [] sindexS;
3573 // delete [] sindexF;
3580 //____________________________________________________________________
3581 void AliTRDtrackerV1::ResetSeedTB()
3583 // reset buffer for seeding time bin layers. If the time bin
3584 // layers are not allocated this function allocates them
3586 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3587 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3588 else fSeedTB[isl]->Clear();
3593 //_____________________________________________________________________________
3594 Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
3596 // Calculates normalized chi2 in y-direction
3597 // chi2 = Sum chi2 / n_tracklets
3599 Double_t chi2 = 0.; Int_t n = 0;
3600 for(Int_t ipl = kNPlanes; ipl--;){
3601 if(!tracklets[ipl].IsOK()) continue;
3602 chi2 += tracklets[ipl].GetChi2Y();
3605 return n ? chi2/n : 0.;
3608 //_____________________________________________________________________________
3609 Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
3611 // Calculates normalized chi2 in z-direction
3612 // chi2 = Sum chi2 / n_tracklets
3614 Double_t chi2 = 0; Int_t n = 0;
3615 for(Int_t ipl = kNPlanes; ipl--;){
3616 if(!tracklets[ipl].IsOK()) continue;
3617 chi2 += tracklets[ipl].GetChi2Z();
3620 return n ? chi2/n : 0.;
3623 //____________________________________________________________________
3624 Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
3626 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3627 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3628 // are taken into account
3630 // Parameters: - Array of tracklets(AliTRDseedV1)
3632 // Output: - The reference x-position(Float_t)
3633 // Only kept for compatibility with the old code
3635 Int_t nDistances = 0;
3636 Float_t meanDistance = 0.;
3637 Int_t startIndex = 5;
3638 for(Int_t il =5; il > 0; il--){
3639 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3640 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3641 meanDistance += xdiff;
3644 if(tracklets[il].IsOK()) startIndex = il;
3646 if(tracklets[0].IsOK()) startIndex = 0;
3648 // We should normally never get here
3649 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3650 Int_t iok = 0, idiff = 0;
3651 // This attempt is worse and should be avoided:
3652 // check for two chambers which are OK and repeat this without taking the mean value
3653 // Strategy avoids a division by 0;
3654 for(Int_t il = 5; il >= 0; il--){
3655 if(tracklets[il].IsOK()){
3656 xpos[iok] = tracklets[il].GetX0();
3660 if(iok) idiff++; // to get the right difference;
3664 meanDistance = (xpos[0] - xpos[1])/idiff;
3667 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3672 meanDistance /= nDistances;
3674 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3677 //_____________________________________________________________________________
3678 Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
3680 // Track Fitter Function using the new class implementation of
3683 AliTRDtrackFitterRieman fitter;
3684 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3686 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3687 Double_t chi2 = fitter.Eval();
3688 // Update the tracklets
3689 Double_t cov[15]; Double_t x0;
3690 memset(cov, 0, sizeof(Double_t) * 15);
3691 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3692 x0 = tracklets[il].GetX0();
3693 tracklets[il].SetYref(0, fitter.GetYat(x0));
3694 tracklets[il].SetZref(0, fitter.GetZat(x0));
3695 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3696 tracklets[il].SetZref(1, fitter.GetDzDx());
3697 tracklets[il].SetC(fitter.GetCurvature());
3698 fitter.GetCovAt(x0, cov);
3699 tracklets[il].SetCovRef(cov);
3700 tracklets[il].SetChi2(chi2);
3705 ///////////////////////////////////////////////////////
3707 // Resources of class AliTRDLeastSquare //
3709 ///////////////////////////////////////////////////////
3711 //_____________________________________________________________________________
3712 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
3714 // Constructor of the nested class AliTRDtrackFitterLeastSquare
3716 // Fast solving linear regresion in 2D
3718 // The data members have the following meaning
3729 // fCovarianceMatrix[0] : s2a
3730 // fCovarianceMatrix[1] : s2b
3731 // fCovarianceMatrix[2] : cov(ab)
3733 memset(fParams, 0, sizeof(Double_t) * 2);
3734 memset(fSums, 0, sizeof(Double_t) * 6);
3735 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3739 //_____________________________________________________________________________
3740 void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3742 // Adding Point to the fitter
3745 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3747 const Double_t &xpt = *x;
3748 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3750 fSums[1] += weight * xpt;
3751 fSums[2] += weight * y;
3752 fSums[3] += weight * xpt * y;
3753 fSums[4] += weight * xpt * xpt;
3754 fSums[5] += weight * y * y;
3757 //_____________________________________________________________________________
3758 void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3760 // Remove Point from the sample
3763 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3765 const Double_t &xpt = *x;
3767 fSums[1] -= weight * xpt;
3768 fSums[2] -= weight * y;
3769 fSums[3] -= weight * xpt * y;
3770 fSums[4] -= weight * xpt * xpt;
3771 fSums[5] -= weight * y * y;
3774 //_____________________________________________________________________________
3775 Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
3777 // Evaluation of the fit:
3778 // Calculation of the parameters
3779 // Calculation of the covariance matrix
3782 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
3783 if(det==0) return kFALSE;
3785 // for(Int_t isum = 0; isum < 5; isum++)
3786 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3787 // printf("denominator = %f\n", denominator);
3788 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
3789 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
3790 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3792 // Covariance matrix
3793 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
3794 fCovarianceMatrix[0] = fSums[4] / den;
3795 fCovarianceMatrix[1] = fSums[0] / den;
3796 fCovarianceMatrix[2] = -fSums[1] / den;
3797 /* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
3798 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
3799 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
3806 //_____________________________________________________________________________
3807 Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
3809 // Returns the Function value of the fitted function at a given x-position
3811 return fParams[0] + fParams[1] * (*xpos);
3814 //_____________________________________________________________________________
3815 void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
3817 // Copies the values of the covariance matrix into the storage
3819 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
3822 //_____________________________________________________________________________
3823 void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
3827 memset(fParams, 0, sizeof(Double_t) * 2);
3828 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3829 memset(fSums, 0, sizeof(Double_t) * 6);
3832 ///////////////////////////////////////////////////////
3834 // Resources of class AliTRDtrackFitterRieman //
3836 ///////////////////////////////////////////////////////
3838 //_____________________________________________________________________________
3839 AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
3845 fSysClusterError(0.)
3848 // Default constructor
3850 fZfitter = new AliTRDLeastSquare;
3851 fCovarPolY = new TMatrixD(3,3);
3852 fCovarPolZ = new TMatrixD(2,2);
3853 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
3854 memset(fParameters, 0, sizeof(Double_t) * 5);
3855 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3856 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3859 //_____________________________________________________________________________
3860 AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
3864 if(fZfitter) delete fZfitter;
3865 if(fCovarPolY) delete fCovarPolY;
3866 if(fCovarPolZ) delete fCovarPolZ;
3869 //_____________________________________________________________________________
3870 void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
3875 fTrackFitter->StoreData(kTRUE);
3876 fTrackFitter->ClearPoints();
3882 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
3883 memset(fParameters, 0, sizeof(Double_t) * 5);
3884 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3885 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3886 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
3887 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
3888 (*fCovarPolY)(irow, icol) = 0.;
3889 if(irow < 2 && icol < 2)
3890 (*fCovarPolZ)(irow, icol) = 0.;
3894 //_____________________________________________________________________________
3895 void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
3897 // Add tracklet into the fitter
3899 if(itr >= AliTRDgeometry::kNlayer) return;
3900 fTracklets[itr] = tracklet;
3903 //_____________________________________________________________________________
3904 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
3907 // 1. Apply linear transformation and store points in the fitter
3908 // 2. Evaluate the fit
3909 // 3. Check if the result of the fit in z-direction is reasonable
3911 // 3a. Fix the parameters 3 and 4 with the results of a simple least
3913 // 3b. Redo the fit with the fixed parameters
3914 // 4. Store fit results (parameters and errors)
3919 fXref = CalculateReferenceX();
3920 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
3921 if(!fTrackFitter->GetNpoints()) return 1e10;
3923 fTrackFitter->Eval();
3925 fParameters[3] = fTrackFitter->GetParameter(3);
3926 fParameters[4] = fTrackFitter->GetParameter(4);
3927 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
3928 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
3929 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
3930 fTrackFitter->Eval();
3931 fTrackFitter->ReleaseParameter(3);
3932 fTrackFitter->ReleaseParameter(4);
3933 fParameters[3] = fTrackFitter->GetParameter(3);
3934 fParameters[4] = fTrackFitter->GetParameter(4);
3936 // Update the Fit Parameters and the errors
3937 fParameters[0] = fTrackFitter->GetParameter(0);
3938 fParameters[1] = fTrackFitter->GetParameter(1);
3939 fParameters[2] = fTrackFitter->GetParameter(2);
3941 // Prepare Covariance estimation
3942 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
3943 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
3944 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
3945 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
3946 fCovarPolY->Invert();
3947 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
3948 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
3949 fCovarPolZ->Invert();
3950 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
3953 //_____________________________________________________________________________
3954 void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(AliTRDseedV1 * const tracklet){
3956 // Does the transformations and updates the fitters
3957 // The following transformation is applied
3959 AliTRDcluster *cl = NULL;
3960 Double_t x, y, z, dx, t, w, we, yerr, zerr;
3962 if(!tracklet || !tracklet->IsOK()) return;
3963 Double_t tilt = tracklet->GetTilt();
3964 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
3965 if(!(cl = tracklet->GetClusters(itb))) continue;
3966 if(!cl->IsInChamber()) continue;
3967 if (!tracklet->IsUsable(itb)) continue;
3974 uvt[0] = 2. * x * t;
3976 uvt[2] = 2. * tilt * t;
3977 uvt[3] = 2. * tilt * dx * t;
3978 w = 2. * (y + tilt*z) * t;
3979 // error definition changes for the different calls
3981 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
3982 // Update sums for error calculation
3983 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
3985 zerr = 1./cl->GetSigmaZ2();
3986 for(Int_t ipol = 0; ipol < 5; ipol++){
3987 fSumPolY[ipol] += yerr;
3990 fSumPolZ[ipol] += zerr;
3994 fTrackFitter->AddPoint(uvt, w, we);
3995 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
3999 //_____________________________________________________________________________
4000 Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
4002 // Check whether z-results are acceptable
4003 // Definition: Distance between tracklet fit and track fit has to be
4004 // less then half a padlength
4005 // Point of comparision is at the anode wire
4007 Bool_t acceptablez = kTRUE;
4008 Double_t zref = 0.0;
4009 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
4010 if(!fTracklets[iLayer]->IsOK()) continue;
4011 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
4012 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
4013 acceptablez = kFALSE;
4018 //_____________________________________________________________________________
4019 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
4021 // Calculate y position out of the track parameters
4022 // y: R^2 = (x - x0)^2 + (y - y0)^2
4023 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
4024 // R = Sqrt() = 1/Curvature
4025 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
4028 Double_t disc = (x * fParameters[0] + fParameters[1]);
4029 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
4031 disc = TMath::Sqrt(disc);
4032 y = (1.0 - disc) / fParameters[0];
4037 //_____________________________________________________________________________
4038 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4040 // Return z position for a given x position
4041 // Simple linear function
4043 return fParameters[3] + fParameters[4] * (x - fXref);
4046 //_____________________________________________________________________________
4047 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4049 // Calculate dydx at a given radial position out of the track parameters
4050 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4051 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4052 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4053 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4054 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4056 Double_t x0 = -fParameters[1] / fParameters[0];
4057 Double_t curvature = GetCurvature();
4059 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4060 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4061 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4062 if (fParameters[0] < 0) yderiv *= -1.0;
4069 //_____________________________________________________________________________
4070 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4072 // Calculate track curvature
4075 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4076 if (curvature > 0.0)
4077 curvature = fParameters[0] / TMath::Sqrt(curvature);
4081 //_____________________________________________________________________________
4082 void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4084 // Error Definition according to gauss error propagation
4086 TMatrixD transform(3,3);
4087 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4088 transform(0,1) = transform(1,2) = x;
4089 transform(0,2) = x*x;
4090 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4091 covariance *= transform.T();
4092 cov[0] = covariance(0,0);
4093 TMatrixD transformZ(2,2);
4094 transformZ(0,0) = transformZ(1,1) = 1;
4095 transformZ(0,1) = x;
4096 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4097 covarZ *= transformZ.T();
4098 cov[1] = covarZ(0,0);
4102 //____________________________________________________________________
4103 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4105 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4106 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4107 // are taken into account
4109 // Parameters: - Array of tracklets(AliTRDseedV1)
4111 // Output: - The reference x-position(Float_t)
4113 Int_t nDistances = 0;
4114 Float_t meanDistance = 0.;
4115 Int_t startIndex = 5;
4116 for(Int_t il =5; il > 0; il--){
4117 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4118 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4119 meanDistance += xdiff;
4122 if(fTracklets[il]->IsOK()) startIndex = il;
4124 if(fTracklets[0]->IsOK()) startIndex = 0;
4126 // We should normally never get here
4127 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4128 Int_t iok = 0, idiff = 0;
4129 // This attempt is worse and should be avoided:
4130 // check for two chambers which are OK and repeat this without taking the mean value
4131 // Strategy avoids a division by 0;
4132 for(Int_t il = 5; il >= 0; il--){
4133 if(fTracklets[il]->IsOK()){
4134 xpos[iok] = fTracklets[il]->GetX0();
4138 if(iok) idiff++; // to get the right difference;
4142 meanDistance = (xpos[0] - xpos[1])/idiff;
4145 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4150 meanDistance /= nDistances;
4152 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());