1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
23 // Alex Bercuci <A.Bercuci@gsi.de> //
24 // Markus Fasel <M.Fasel@gsi.de> //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include <TDirectory.h>
30 #include <TLinearFitter.h>
32 #include <TClonesArray.h>
33 #include <TTreeStream.h>
34 #include <TGeoMatrix.h>
35 #include <TGeoManager.h>
38 #include "AliMathBase.h"
39 #include "AliESDEvent.h"
40 #include "AliGeomManager.h"
41 #include "AliRieman.h"
42 #include "AliTrackPointArray.h"
44 #include "AliTRDgeometry.h"
45 #include "AliTRDpadPlane.h"
46 #include "AliTRDcalibDB.h"
47 #include "AliTRDReconstructor.h"
48 #include "AliTRDCalibraFillHisto.h"
49 #include "AliTRDrecoParam.h"
51 #include "AliTRDcluster.h"
52 #include "AliTRDdigitsParam.h"
53 #include "AliTRDseedV1.h"
54 #include "AliTRDtrackV1.h"
55 #include "AliTRDtrackerV1.h"
56 #include "AliTRDtrackerDebug.h"
57 #include "AliTRDtrackingChamber.h"
58 #include "AliTRDchamberTimeBin.h"
60 ClassImp(AliTRDtrackerV1)
61 ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62 ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
64 AliTRDtrackerV1::ETRDtrackerV1BetheBloch AliTRDtrackerV1::fgBB = AliTRDtrackerV1::kGeant;
65 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
66 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
67 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
68 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
70 const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
71 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
72 // Number of Time Bins/chamber should be also stored independently by the traker
73 // (also in AliTRDReconstructor) in oder to be able to run HLT. Fix TODO
74 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
75 AliRieman* AliTRDtrackerV1::fgRieman = NULL;
76 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
77 TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
79 //____________________________________________________________________
80 AliTRDtrackerV1::AliTRDtrackerV1(const AliTRDReconstructor *rec)
82 ,fkReconstructor(NULL)
93 // Default constructor.
96 SetReconstructor(rec); // initialize reconstructor
98 // initialize geometry
99 if(!AliGeomManager::GetGeometry()){
100 AliFatal("Could not get geometry.");
102 fGeom = new AliTRDgeometry();
103 fGeom->CreateClusterMatrixArray();
104 TGeoHMatrix *matrix = NULL;
105 Double_t loc[] = {0., 0., 0.};
106 Double_t glb[] = {0., 0., 0.};
107 for(Int_t ily=kNPlanes; ily--;){
109 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
111 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
112 fR[ily] = fgkX0[ily];
115 matrix->LocalToMaster(loc, glb);
116 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
119 // initialize cluster containers
120 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
123 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
124 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
125 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
126 fTracksESD = new TClonesArray("AliESDtrack", 2*kMaxTracksStack);
127 fTracksESD->SetOwner();
130 //____________________________________________________________________
131 AliTRDtrackerV1::~AliTRDtrackerV1()
137 if(fgRieman) delete fgRieman; fgRieman = NULL;
138 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
139 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
140 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
141 if(fTracksESD){ fTracksESD->Delete(); delete fTracksESD; }
142 if(fTracks) {fTracks->Delete(); delete fTracks;}
143 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
144 if(IsClustersOwner() && fClusters) {
145 AliInfo(Form("tracker[%p] removing %d own clusters @ %p", (void*)this, fClusters->GetEntries(), (void*)fClusters));
146 fClusters->Delete(); delete fClusters;
148 if(fGeom) delete fGeom;
151 //____________________________________________________________________
152 Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
155 // Steering stand alone tracking for full TRD detector
158 // esd : The ESD event. On output it contains
159 // the ESD tracks found in TRD.
162 // Number of tracks found in the TRD detector.
164 // Detailed description
165 // 1. Launch individual SM trackers.
166 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
170 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
174 //AliInfo("Start Track Finder ...");
176 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
177 // for(int ism=1; ism<2; ism++){
178 //AliInfo(Form("Processing supermodule %i ...", ism));
179 ntracks += Clusters2TracksSM(ism, esd);
181 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
186 //_____________________________________________________________________________
187 Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
189 //AliInfo(Form("Asking for tracklet %d", index));
191 // reset position of the point before using it
192 p.SetXYZ(0., 0., 0.);
193 AliTRDseedV1 *tracklet = GetTracklet(index);
194 if (!tracklet) return kFALSE;
196 // get detector for this tracklet
197 Int_t det = tracklet->GetDetector();
198 Int_t sec = fGeom->GetSector(det);
199 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
200 sinA = TMath::Sin(alpha),
201 cosA = TMath::Cos(alpha);
203 local[0] = tracklet->GetX();
204 local[1] = tracklet->GetY();
205 local[2] = tracklet->GetZ();
207 fGeom->RotateBack(det, local, global);
209 Double_t cov2D[3]; Float_t cov[6];
210 tracklet->GetCovAt(local[0], cov2D);
211 cov[0] = cov2D[0]*sinA*sinA;
212 cov[1] =-cov2D[0]*sinA*cosA;
213 cov[2] =-cov2D[1]*sinA;
214 cov[3] = cov2D[0]*cosA*cosA;
215 cov[4] = cov2D[1]*cosA;
217 // store the global position of the tracklet and its covariance matrix in the track point
218 p.SetXYZ(global[0],global[1],global[2], cov);
221 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
222 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
223 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
224 p.SetVolumeID(volid);
229 //____________________________________________________________________
230 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
232 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
233 return fgTiltedRieman;
236 //____________________________________________________________________
237 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
239 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
240 return fgTiltedRiemanConstrained;
243 //____________________________________________________________________
244 AliRieman* AliTRDtrackerV1::GetRiemanFitter()
246 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
250 //_____________________________________________________________________________
251 Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
253 // Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
254 // a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
255 // covariance, PID, etc.) are than used to update the corresponding ESD track.
256 // Each track seed is first propagated to the geometrical limit of the TRD detector.
257 // Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
258 // constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
259 // Otherwise the ESD track is left unchanged.
261 // The following steps are performed:
262 // 1. Selection of tracks based on the variance in the y-z plane.
263 // 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
264 // 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
265 // the following status bits:
266 // - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
267 // - AliESDtrack::kTRDStop - if the tracks fails propagation
268 // - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
269 // 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
270 // 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
273 if(!fClusters || !fClusters->GetEntriesFast()){
274 AliInfo("No TRD clusters");
277 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
278 if (!calibra) AliInfo("Could not get Calibra instance");
279 if (!fgNTimeBins) fgNTimeBins = fkReconstructor->GetNTimeBins();
282 Int_t nFound = 0, // number of tracks found
283 nBacked = 0, // number of tracks backed up for refit
284 nSeeds = 0, // total number of ESD seeds
285 nTRDseeds= 0, // number of seeds in the TRD acceptance
286 nTPCseeds= 0; // number of TPC seeds
287 Float_t foundMin = 20.0;
289 Float_t *quality = NULL;
291 fEventInFile = event->GetEventNumberInFile();
292 nSeeds = event->GetNumberOfTracks();
293 // Sort tracks according to quality
294 // (covariance in the yz plane)
296 quality = new Float_t[nSeeds];
297 index = new Int_t[4*nSeeds];
298 for (Int_t iSeed = nSeeds; iSeed--;) {
299 AliESDtrack *seed = event->GetTrack(iSeed);
300 Double_t covariance[15];
301 seed->GetExternalCovariance(covariance);
302 quality[iSeed] = covariance[0] + covariance[2];
304 TMath::Sort(nSeeds, quality, index,kFALSE);
307 // Propagate all seeds
310 for (Int_t iSeed = 0; iSeed < nSeeds; iSeed++) {
312 // Get the seeds in sorted sequence
313 AliESDtrack *seed = event->GetTrack(index[iSeed]);
314 Float_t p4 = seed->GetC(seed->GetBz());
316 // Check the seed status
317 ULong_t status = seed->GetStatus();
318 if ((status & AliESDtrack::kTRDout) != 0) continue;
319 if ((status & AliESDtrack::kTPCout)){
320 AliDebug(3, Form("Prolongate seed[%2d] which is TPC.", iSeed));
321 // set steering parameters for TPC
322 //fkRecoParam->SetTrackParam(kTPC);
324 if ((status & AliESDtrack::kITSout)){
325 AliDebug(3, Form("Prolongate seed[%2d] which is ITS.", iSeed));
326 // set steering parameters for ITS
327 //fkRecoParam->SetTrackParam(kITS);
329 Float_t globalToTracking = AliTRDgeometry::GetAlpha()*(Int_t(seed->GetAlpha()/AliTRDgeometry::GetAlpha()) + (seed->GetAlpha()>0. ? 0.5 : -0.5));
330 if(!seed->Rotate(globalToTracking)) continue;
334 // Propagate to the entrance in the TRD mother volume
335 track.~AliTRDtrackV1();
336 new(&track) AliTRDtrackV1(*seed);
337 if(AliTRDgeometry::GetXtrdBeg() > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), AliTRDReconstructor::GetMaxStep())){
338 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
341 if(!AdjustSector(&track)){
342 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
345 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
346 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
350 AliDebug(2, Form("TRD propagate TPC seed[%d] = %d.", iSeed, index[iSeed]));
351 // store track status at TRD entrance
352 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
354 // prepare track and do propagation in the TRD
355 track.SetReconstructor(fkReconstructor);
356 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
357 track.SetPrimary(status & AliESDtrack::kTPCin);
358 expectedClr = FollowBackProlongation(track);
359 // check if track entered the TRD fiducial volume
360 if(track.GetTrackIn()){
361 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
364 // check if track was stopped in the TRD
366 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
373 track.CookLabel(1. - AliTRDReconstructor::GetLabelFraction());
374 // update calibration references using this track
375 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
376 // save calibration object
377 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ) {
378 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
379 calibTrack->SetOwner();
380 seed->AddCalibObject(calibTrack);
383 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
384 track.UpdateESDtrack(seed);
387 // Make backup for back propagation
388 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) || (track.Pt() > 0.8)) {
389 Int_t foundClr = track.GetNumberOfClusters();
390 if (foundClr >= foundMin) {
391 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
393 // Sign only gold tracks
394 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
395 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
397 Bool_t isGold = kFALSE;
400 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
401 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
407 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
408 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
409 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
414 if ((!isGold) && (track.GetBackupTrack())) {
415 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
416 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
424 // Propagation to the TOF
425 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
426 Int_t sm = track.GetSector();
427 // default value in case we have problems with the geometry.
428 Double_t xtof = 371.;
429 //Calculate radial position of the beginning of the TOF
430 //mother volume. In order to avoid mixing of the TRD
431 //and TOF modules some hard values are needed. This are:
432 //1. The path to the TOF module.
433 //2. The width of the TOF (29.05 cm)
434 //(with the help of Annalisa de Caro Mar-17-2009)
436 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
437 TGeoHMatrix *m = NULL;
438 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
440 if((m=gGeoManager->GetCurrentMatrix())){
441 m->LocalToMaster(loc, glob);
442 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
445 if(xtof > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, xtof, AliTRDReconstructor::GetMaxStep())){
446 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
449 if(!AdjustSector(&track)){
450 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
453 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
454 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
457 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
458 // TODO obsolete - delete
459 seed->SetTRDQuality(track.StatusForTOF());
461 seed->SetTRDBudget(track.GetBudget(0));
463 if(index) delete [] index;
464 if(quality) delete [] quality;
466 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
467 AliInfo(Form("Number of tracks: TRDout[%d] TRDbackup[%d]", nFound, nBacked));
469 // run stand alone tracking
470 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
476 //____________________________________________________________________
477 Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
480 // Refits tracks within the TRD. The ESD event is expected to contain seeds
481 // at the outer part of the TRD.
482 // The tracks are propagated to the innermost time bin
483 // of the TRD and the ESD event is updated
484 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
487 Int_t nseed = 0; // contor for loaded seeds
488 Int_t found = 0; // contor for updated TRD tracks
491 if(!fClusters || !fClusters->GetEntriesFast()){
492 AliInfo("No TRD clusters");
496 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
497 AliESDtrack *seed = event->GetTrack(itrack);
498 ULong_t status = seed->GetStatus();
500 new(&track) AliTRDtrackV1(*seed);
501 if (track.GetX() < 270.0) {
502 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
506 // reject tracks which failed propagation in the TRD or
507 // are produced by the TRD stand alone tracker
508 if(!(status & AliESDtrack::kTRDout)) continue;
509 if(!(status & AliESDtrack::kTRDin)) continue;
512 track.ResetCovariance(50.0);
514 // do the propagation and processing
515 Bool_t kUPDATE = kFALSE;
516 Double_t xTPC = 250.0;
517 if(FollowProlongation(track)){
518 // Update the friend track
519 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
520 TObject *o = NULL; Int_t ic = 0;
521 AliTRDtrackV1 *calibTrack = NULL;
522 while((o = seed->GetCalibObject(ic++))){
523 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
524 calibTrack->SetTrackOut(&track);
529 if (PropagateToX(track, xTPC, AliTRDReconstructor::GetMaxStep())) { // -with update
530 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
536 // Prolongate to TPC without update
538 AliTRDtrackV1 tt(*seed);
539 if (PropagateToX(tt, xTPC, AliTRDReconstructor::GetMaxStep())) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
542 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
543 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
548 //____________________________________________________________________
549 Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
551 // Extrapolates the TRD track in the TPC direction.
554 // t : the TRD track which has to be extrapolated
557 // number of clusters attached to the track
559 // Detailed description
561 // Starting from current radial position of track <t> this function
562 // extrapolates the track through the 6 TRD layers. The following steps
563 // are being performed for each plane:
565 // a. get plane limits in the local x direction
566 // b. check crossing sectors
567 // c. check track inclination
568 // 2. search tracklet in the tracker list (see GetTracklet() for details)
569 // 3. evaluate material budget using the geo manager
570 // 4. propagate and update track using the tracklet information.
575 Int_t nClustersExpected = 0;
576 for (Int_t iplane = kNPlanes; iplane--;) {
578 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
579 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
580 if(!tracklet) continue;
581 if(!tracklet->IsOK()){
582 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
585 Double_t x = tracklet->GetX();//GetX0();
586 // reject tracklets which are not considered for inward refit
587 if(x > t.GetX()+AliTRDReconstructor::GetMaxStep()) continue;
589 // append tracklet to track
590 t.SetTracklet(tracklet, index);
592 if (x < (t.GetX()-AliTRDReconstructor::GetMaxStep()) && !PropagateToX(t, x+AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) break;
593 if (!AdjustSector(&t)) break;
595 // Start global position
599 // End global position
600 Double_t alpha = t.GetAlpha(), y, z;
601 if (!t.GetProlongation(x,y,z)) break;
603 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
604 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
607 Double_t length = TMath::Sqrt(
608 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
609 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
610 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
613 // Get material budget
615 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
616 Double_t xrho= param[0]*param[4];
617 Double_t xx0 = param[1]; // Get mean propagation parameters
619 // Propagate and update
620 t.PropagateTo(x, xx0, xrho);
621 if (!AdjustSector(&t)) break;
624 Double_t cov[3]; tracklet->GetCovAt(x, cov);
625 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
626 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
628 if(fkReconstructor->IsDebugStreaming()){
629 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
630 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
631 AliExternalTrackParam param0(t);
632 AliExternalTrackParam param1(t);
633 param1.Update(p, cov);
634 TVectorD vcov(3,cov);
636 cstreamer << "FollowProlongationInfo"
637 << "EventNumber=" << eventNumber
641 << "tracklet.=" << tracklet
643 << "param0.=" << ¶m0
644 << "param1.=" << ¶m1
648 AliInfo(Form("Pl:%d X:%+e : %+e P: %+e %+e Cov:%+e %+e %+e -> dXY: %+e %+e | chi2:%.2f pT:%.2f alp:%.3f",
649 iplane,x,t.GetX(),p[0],p[1],cov[0],cov[1],cov[2],
650 p[0]-t.GetY(),p[1]-t.GetZ(),
651 chi2,t.Pt()*t.Charge(),t.GetAlpha()));
653 if (chi2 < fkRecoParam->GetChi2Cut() && ((AliExternalTrackParam&)t).Update(p, cov)){ // MI parameterizad chi2 cut 03.05.2014
654 // if (chi2 < 1e+10 && ((AliExternalTrackParam&)t).Update(p, cov)){
655 // Register info to track
656 t.SetNumberOfClusters();
658 nClustersExpected += tracklet->GetN();
662 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 || AliTRDReconstructor::GetStreamLevel()>1){
664 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
665 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
666 if(!tracklet) continue;
667 t.SetTracklet(tracklet, index);
670 if(fkReconstructor->IsDebugStreaming()){
671 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
672 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
673 AliTRDtrackV1 track(t);
675 cstreamer << "FollowProlongation"
676 << "EventNumber=" << eventNumber
677 << "ncl=" << nClustersExpected
678 << "track.=" << &track
682 return nClustersExpected;
686 //_____________________________________________________________________________
687 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
689 // Extrapolates/Build the TRD track in the TOF direction.
692 // t : the TRD track which has to be extrapolated
695 // number of clusters attached to the track
697 // Starting from current radial position of track <t> this function
698 // extrapolates the track through the 6 TRD layers. The following steps
699 // are being performed for each plane:
700 // 1. Propagate track to the entrance of the next chamber:
701 // - get chamber limits in the radial direction
702 // - check crossing sectors
703 // - check track inclination
704 // - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
705 // 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
706 // Kalman filter is needed and tracklets are already linked to the track this step is skipped.
707 // 3. Fit tracklet using the information from the Kalman filter.
708 // 4. Propagate and update track at reference radial position of the tracklet.
709 // 5. Register tracklet with the tracker and track; update pulls monitoring.
712 // 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:
713 // - AliTRDtrackV1::kProlongation : track prolongation failed
714 // - AliTRDtrackV1::kPropagation : track prolongation failed
715 // - AliTRDtrackV1::kAdjustSector : failed during sector crossing
716 // - AliTRDtrackV1::kSnp : too large bending
717 // - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
718 // - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
719 // - AliTRDtrackV1::kUnknown : anything which is not covered before
720 // 2. By default the status of the track before first TRD update is saved.
725 // Alexandru Bercuci <A.Bercuci@gsi.de>
729 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
730 AliTRDtrackingChamber *chamber = NULL;
732 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
733 if ( AliTRDReconstructor::GetStreamLevel()>0) debugLevel= AliTRDReconstructor::GetStreamLevel();
734 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
736 Bool_t kStoreIn(kTRUE), // toggel store track params. at TRD entry
737 kStandAlone(kFALSE), // toggle tracker awarness of stand alone seeding
738 kUseTRD(fkRecoParam->IsOverPtThreshold(t.Pt()));// use TRD measurment to update Kalman
741 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
742 // Special case for stand alone tracking
743 // - store all tracklets found by seeding
744 // - start propagation from first tracklet found
745 AliTRDseedV1 *tracklets[kNPlanes];
746 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
747 for(Int_t ip(kNPlanes); ip--;){
748 if(!(tracklets[ip] = t.GetTracklet(ip))) continue;
750 if(tracklets[ip]->IsOK()) startLayer=ip;
754 AliDebug(4, Form("SA[%c] Start[%d]\n"
755 " [0]idx[%d] traklet[%p]\n"
756 " [1]idx[%d] traklet[%p]\n"
757 " [2]idx[%d] traklet[%p]\n"
758 " [3]idx[%d] traklet[%p]\n"
759 " [4]idx[%d] traklet[%p]\n"
760 " [5]idx[%d] traklet[%p]"
761 , kStandAlone?'y':'n', startLayer
762 , t.GetTrackletIndex(0), (void*)tracklets[0]
763 , t.GetTrackletIndex(1), (void*)tracklets[1]
764 , t.GetTrackletIndex(2), (void*)tracklets[2]
765 , t.GetTrackletIndex(3), (void*)tracklets[3]
766 , t.GetTrackletIndex(4), (void*)tracklets[4]
767 , t.GetTrackletIndex(5), (void*)tracklets[5]));
769 // Loop through the TRD layers
770 TGeoHMatrix *matrix = NULL;
771 Double_t x(0.), y(0.), z(0.);
772 for (Int_t ily=startLayer, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
773 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
775 // rough estimate of the entry point
776 if (!t.GetProlongation(fR[ily], y, z)){
778 t.SetErrStat(AliTRDtrackV1::kProlongation);
779 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
783 // find sector / stack / detector
785 // TODO cross check with y value !
786 stk = fGeom->GetStack(z, ily);
787 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
788 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
790 // check if supermodule/chamber is installed
791 if( !fGeom->GetSMstatus(sm) ||
793 fGeom->IsHole(ily, stk, sm) ||
795 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
796 // propagate to the default radial position
797 if(fR[ily] > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, fR[ily], AliTRDReconstructor::GetMaxStep())){
799 t.SetErrStat(AliTRDtrackV1::kPropagation);
800 AliDebug(4, "Failed Propagation [Missing Geometry]");
803 if(!AdjustSector(&t)){
805 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
806 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
809 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
811 t.SetErrStat(AliTRDtrackV1::kSnp);
812 AliDebug(4, "Failed Max Snp [Missing Geometry]");
815 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
819 // retrieve rotation matrix for the current chamber
820 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
821 Double_t glb[] = {0., 0., 0.};
822 matrix->LocalToMaster(loc, glb);
823 AliDebug(3, Form("Propagate to det[%3d] x_anode[%7.2f] (%f %f)", det, glb[0]+driftLength, glb[1], glb[2]));
825 // Propagate to the radial distance of the current layer
826 x = glb[0] - AliTRDReconstructor::GetMaxStep();
827 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())){
829 t.SetErrStat(AliTRDtrackV1::kPropagation);
830 AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
833 if(!AdjustSector(&t)){
835 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
836 AliDebug(4, "Failed Adjust Sector Start");
839 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
841 t.SetErrStat(AliTRDtrackV1::kSnp);
842 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
845 Bool_t doRecalculate = kFALSE;
846 if(sm != t.GetSector()){
848 doRecalculate = kTRUE;
850 if(stk != fGeom->GetStack(z, ily)){
851 stk = fGeom->GetStack(z, ily);
852 doRecalculate = kTRUE;
855 det = AliTRDgeometry::GetDetector(ily, stk, sm);
856 if(!(matrix = fGeom->GetClusterMatrix(det))){
857 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
858 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
861 matrix->LocalToMaster(loc, glb);
862 x = glb[0] - AliTRDReconstructor::GetMaxStep();
865 // check if track is well inside fiducial volume
866 if (!t.GetProlongation(x+AliTRDReconstructor::GetMaxStep(), y, z)) {
868 t.SetErrStat(AliTRDtrackV1::kProlongation);
869 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+AliTRDReconstructor::GetMaxStep(), y, z));
872 if(fGeom->IsOnBoundary(det, y, z, .5)){
873 t.SetErrStat(AliTRDtrackV1::kBoundary, ily);
874 AliDebug(4, "Failed Track on Boundary");
878 ptrTracklet = tracklets[ily];
879 if(!ptrTracklet){ // BUILD TRACKLET
880 AliDebug(3, Form("Building tracklet det[%d]", det));
881 // check data in supermodule
882 if(!fTrSec[sm].GetNChambers()){
883 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
884 AliDebug(4, "Failed NoClusters");
887 if(fTrSec[sm].GetX(ily) < 1.){
888 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
889 AliDebug(4, "Failed NoX");
893 // check data in chamber
894 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
895 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
896 AliDebug(4, "Failed No Detector");
899 if(chamber->GetNClusters() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
900 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
901 AliDebug(4, "Failed Not Enough Clusters in Detector");
905 tracklet.~AliTRDseedV1();
906 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
907 ptrTracklet->SetReconstructor(fkReconstructor);
908 ptrTracklet->SetKink(t.IsKink());
909 ptrTracklet->SetPrimary(t.IsPrimary());
910 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
911 //set first approximation of radial position of anode wire corresponding to middle chamber y=0, z=0
912 // the uncertainty is given by the actual position of the tracklet (y,z) and chamber inclination
913 ptrTracklet->SetX0(glb[0]+driftLength);
914 if(!ptrTracklet->Init(&t)){
916 t.SetErrStat(AliTRDtrackV1::kTrackletInit);
917 AliDebug(4, "Failed Tracklet Init");
920 // Select attachment base on track to B field sign not only track charge which is buggy
921 // mark kFALSE same sign tracks and kTRUE opposite sign tracks
922 // A.Bercuci 3.11.2011
923 Float_t prod(t.GetBz()*t.Charge());
924 if(!ptrTracklet->AttachClusters(chamber, kTRUE, prod<0.?kTRUE:kFALSE, fEventInFile)){
925 t.SetErrStat(AliTRDtrackV1::kNoAttach, ily);
927 AliTRDseedV1 trackletCp(*ptrTracklet);
928 UChar_t status(t.GetStatusTRD(ily));
929 (*cstreamer) << "FollowBackProlongation4"
930 <<"status=" << status
931 <<"tracklet.=" << &trackletCp
934 AliDebug(4, "Failed Attach Clusters");
937 AliDebug(3, Form("Number of Clusters in Tracklet: %d", ptrTracklet->GetN()));
938 if(ptrTracklet->GetN() < fgNTimeBins*fkRecoParam->GetFindableClusters()){
939 t.SetErrStat(AliTRDtrackV1::kNoClustersTracklet, ily);
941 AliTRDseedV1 trackletCp(*ptrTracklet);
942 UChar_t status(t.GetStatusTRD(ily));
943 (*cstreamer) << "FollowBackProlongation4"
944 <<"status=" << status
945 <<"tracklet.=" << &trackletCp
948 AliDebug(4, "Failed N Clusters Attached");
951 ptrTracklet->UpdateUsed();
952 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
953 // propagate track to the radial position of the tracklet
955 // fit tracklet in the local chamber coordinate system
956 // tilt correction options
958 // 2 : pseudo tilt correction
959 if(!ptrTracklet->FitRobust(fGeom->GetPadPlane(ily, stk))){
960 t.SetErrStat(AliTRDtrackV1::kNoFit, ily);
961 AliDebug(4, "Failed Tracklet Fit");
964 // Calculate tracklet position in tracking coordinates
965 // A.Bercuci 27.11.2013
966 ptrTracklet->SetXYZ(matrix);
968 x = ptrTracklet->GetX(); //GetX0();
969 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())) {
971 t.SetErrStat(AliTRDtrackV1::kPropagation);
972 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
975 if(!AdjustSector(&t)) {
977 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
978 AliDebug(4, "Failed Adjust Sector");
981 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
983 t.SetErrStat(AliTRDtrackV1::kSnp);
984 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
987 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
988 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
989 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
991 AliInfo(Form("Pl:%d X:%+e : %+e P: %+e %+e Cov:%+e %+e %+e -> dXY: %+e %+e | chi2:%.2f pT:%.2f alp:%.3f",
992 ily,x,t.GetX(),p[0],p[1],cov[0],cov[1],cov[2],
993 p[0]-t.GetY(),p[1]-t.GetZ(),
994 chi2,t.Pt()*t.Charge(),t.GetAlpha()));
997 if(fkReconstructor->IsDebugStreaming()){
998 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
999 // TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1000 AliExternalTrackParam param0(t);
1001 AliExternalTrackParam param1(t);
1002 param1.Update(p, cov);
1003 TVectorD vcov(3,cov);
1005 (*cstreamer) << "FollowBackProlongationInfo"
1006 << "EventNumber=" << eventNumber
1011 << "tracklet.=" << ptrTracklet
1012 << "param0.=" << ¶m0
1013 << "param1.=" << ¶m1
1017 // update Kalman with the TRD measurement
1018 if (chi2> fkRecoParam->GetChi2Cut()){ // MI parameterizad chi2 cut 03.05.2014
1019 // if(chi2>10){ // RS
1020 // if(chi2>1e+10){ // TODO
1021 t.SetErrStat(AliTRDtrackV1::kChi2, ily);
1023 UChar_t status(t.GetStatusTRD());
1024 AliTRDseedV1 trackletCp(*ptrTracklet);
1025 AliTRDtrackV1 trackCp(t);
1027 (*cstreamer) << "FollowBackProlongation3"
1028 << "status=" << status
1029 << "tracklet.=" << &trackletCp
1030 << "track.=" << &trackCp
1033 AliDebug(4, Form("Failed Chi2[%f]", chi2));
1036 // mark track as entering the FIDUCIAL volume of TRD
1042 if(!((AliExternalTrackParam&)t).Update(p, cov)) {
1044 t.SetErrStat(AliTRDtrackV1::kUpdate);
1046 UChar_t status(t.GetStatusTRD());
1047 AliTRDseedV1 trackletCp(*ptrTracklet);
1048 AliTRDtrackV1 trackCp(t);
1050 (*cstreamer) << "FollowBackProlongation3"
1051 << "status=" << status
1052 << "tracklet.=" << &trackletCp
1053 << "track.=" << &trackCp
1056 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]));
1060 if(!kStandAlone) ptrTracklet->UseClusters();
1061 // fill residuals ?!
1062 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
1065 // register tracklet with the tracker and track
1066 // Save inside the tracklet the track parameters BEFORE track update.
1067 // Commented out their overwriting AFTER track update
1068 // A.Bercuci 3.11.2011
1069 //ptrTracklet->Update(&t);
1070 ptrTracklet = SetTracklet(ptrTracklet);
1071 Int_t index(fTracklets->GetEntriesFast()-1);
1072 t.SetTracklet(ptrTracklet, index);
1073 // Register info to track
1074 t.SetNumberOfClusters();
1077 n += ptrTracklet->GetN();
1078 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
1080 // Reset material budget if 2 consecutive gold
1081 // if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
1083 // Make backup of the track until is gold
1085 if(!kStandAlone && (failed = t.MakeBackupTrack())) AliDebug(2, Form("Failed backup on cut[%d]", failed));
1087 } // end layers loop
1088 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
1089 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
1091 if(n && debugLevel > 1){
1092 //Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1093 AliTRDtrackV1 track(t);
1095 (*cstreamer) << "FollowBackProlongation2"
1096 << "EventNumber=" << fEventInFile
1097 << "track.=" << &track
1104 //_________________________________________________________________________
1105 Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
1107 // Fits a Riemann-circle to the given points without tilting pad correction.
1108 // The fit is performed using an instance of the class AliRieman (equations
1109 // and transformations see documentation of this class)
1110 // Afterwards all the tracklets are Updated
1112 // Parameters: - Array of tracklets (AliTRDseedV1)
1113 // - Storage for the chi2 values (beginning with direction z)
1114 // - Seeding configuration
1115 // Output: - The curvature
1117 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1119 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1120 Int_t *ppl = &allplanes[0];
1121 Int_t maxLayers = 6;
1126 for(Int_t il = 0; il < maxLayers; il++){
1127 if(!tracklets[ppl[il]].IsOK()) continue;
1128 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
1131 // Set the reference position of the fit and calculate the chi2 values
1132 memset(chi2, 0, sizeof(Double_t) * 2);
1133 for(Int_t il = 0; il < maxLayers; il++){
1134 // Reference positions
1135 tracklets[ppl[il]].Init(fitter);
1138 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1139 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1140 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1142 return fitter->GetC();
1145 //_________________________________________________________________________
1146 void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1149 // Performs a Riemann helix fit using the seedclusters as spacepoints
1150 // Afterwards the chi2 values are calculated and the seeds are updated
1152 // Parameters: - The four seedclusters
1153 // - The tracklet array (AliTRDseedV1)
1154 // - The seeding configuration
1159 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1161 for(Int_t i = 0; i < 4; i++){
1162 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1167 // Update the seed and calculated the chi2 value
1168 chi2[0] = 0; chi2[1] = 0;
1169 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1171 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1172 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1177 //_________________________________________________________________________
1178 Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1181 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1182 // assumed that the vertex position is set to 0.
1183 // This method is very usefull for high-pt particles
1184 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1185 // x0, y0: Center of the circle
1186 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1187 // zc: center of the pad row
1188 // Equation which has to be fitted (after transformation):
1189 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1191 // t = 1/(x^2 + y^2)
1193 // v = 2 * x * tan(phiT) * t
1194 // Parameters in the equation:
1195 // a = -1/y0, b = x0/y0, e = dz/dx
1197 // The Curvature is calculated by the following equation:
1198 // - curv = a/Sqrt(b^2 + 1) = 1/R
1199 // Parameters: - the 6 tracklets
1200 // - the Vertex constraint
1201 // Output: - the Chi2 value of the track
1206 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1207 fitter->StoreData(kTRUE);
1208 fitter->ClearPoints();
1209 AliTRDcluster *cl = NULL;
1211 Float_t x, y, z, w, t, error, tilt;
1214 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1215 if(!tracklets[ilr].IsOK()) continue;
1216 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1217 if(!tracklets[ilr].IsUsable(itb)) continue;
1218 if(!(cl = tracklets[ilr].GetClusters(itb))) continue;
1219 if(!cl->IsInChamber()) continue;
1223 tilt = tracklets[ilr].GetTilt();
1225 t = 1./(x * x + y * y);
1226 uvt[0] = 2. * x * t;
1227 uvt[1] = 2. * x * t * tilt ;
1228 w = 2. * (y + tilt * (z - zVertex)) * t;
1229 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
1230 fitter->AddPoint(uvt, w, error);
1236 // Calculate curvature
1237 Double_t a = fitter->GetParameter(0);
1238 Double_t b = fitter->GetParameter(1);
1239 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1241 Float_t chi2track = 0.0;
1243 chi2track = fitter->GetChisquare()/Double_t(nPoints);
1245 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
1246 tracklets[ip].SetC(curvature, 1);
1248 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRiemanConstraint: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
1250 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
1251 //Linear Model on z-direction
1252 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1253 Double_t slope = fitter->GetParameter(2);
1254 Double_t zref = slope * xref;
1255 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1256 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1257 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1258 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
1259 treeStreamer << "FitTiltedRiemanConstraint"
1260 << "EventNumber=" << eventNumber
1261 << "CandidateNumber=" << candidateNumber
1262 << "Curvature=" << curvature
1263 << "Chi2Track=" << chi2track
1264 << "Chi2Z=" << chi2Z
1271 //_________________________________________________________________________
1272 Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1275 // Performs a Riemann fit taking tilting pad correction into account
1276 // The equation of a Riemann circle, where the y position is substituted by the
1277 // measured y-position taking pad tilting into account, has to be transformed
1278 // into a 4-dimensional hyperplane equation
1279 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1280 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1281 // zc: center of the pad row
1282 // zt: z-position of the track
1283 // The z-position of the track is assumed to be linear dependent on the x-position
1284 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1285 // Transformation: u = 2 * x * t
1286 // v = 2 * tan(phiT) * t
1287 // w = 2 * tan(phiT) * (x - xref) * t
1288 // t = 1 / (x^2 + ymeas^2)
1289 // Parameters: a = -1/y0
1291 // c = (R^2 -x0^2 - y0^2)/y0
1294 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1295 // results from the simple riemann fit. Afterwards the fit is redone.
1296 // The curvature is calculated according to the formula:
1297 // curv = a/(1 + b^2 + c*a) = 1/R
1299 // Paramters: - Array of tracklets (connected to the track candidate)
1300 // - Flag selecting the error definition
1301 // Output: - Chi2 values of the track (in Parameter list)
1303 TLinearFitter *fitter = GetTiltedRiemanFitter();
1304 fitter->StoreData(kTRUE);
1305 fitter->ClearPoints();
1306 AliTRDLeastSquare zfitter;
1307 AliTRDcluster *cl = NULL;
1309 Double_t xref = CalculateReferenceX(tracklets);
1310 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1311 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1312 memset(sumPolY, 0, sizeof(Double_t) * 5);
1313 memset(sumPolZ, 0, sizeof(Double_t) * 3);
1315 // Containers for Least-square fitter
1316 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1317 if(!tracklets[ipl].IsOK()) continue;
1318 tilt = tracklets[ipl].GetTilt();
1319 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1320 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1321 if(!cl->IsInChamber()) continue;
1322 if (!tracklets[ipl].IsUsable(itb)) continue;
1329 uvt[0] = 2. * x * t;
1331 uvt[2] = 2. * tilt * t;
1332 uvt[3] = 2. * tilt * dx * t;
1333 w = 2. * (y + tilt*z) * t;
1334 // error definition changes for the different calls
1336 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
1337 fitter->AddPoint(uvt, w, we);
1338 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1339 // adding points for covariance matrix estimation
1340 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1342 errz = 1./cl->GetSigmaZ2();
1343 for(Int_t ipol = 0; ipol < 5; ipol++){
1344 sumPolY[ipol] += erry;
1347 sumPolZ[ipol] += errz;
1354 if (fitter->Eval()) return 1.e10;
1357 Double_t offset = fitter->GetParameter(3);
1358 Double_t slope = fitter->GetParameter(4);
1360 // Linear fitter - not possible to make boundaries
1361 // Do not accept non possible z and dzdx combinations
1362 Bool_t acceptablez = kTRUE;
1363 Double_t zref = 0.0;
1364 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1365 if(!tracklets[iLayer].IsOK()) continue;
1366 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
1367 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1368 acceptablez = kFALSE;
1371 Double_t dzmf = zfitter.GetFunctionParameter(1);
1372 Double_t zmf = zfitter.GetFunctionValue(&xref);
1373 fgTiltedRieman->FixParameter(3, zmf);
1374 fgTiltedRieman->FixParameter(4, dzmf);
1376 fitter->ReleaseParameter(3);
1377 fitter->ReleaseParameter(4);
1378 offset = fitter->GetParameter(3);
1379 slope = fitter->GetParameter(4);
1382 // Calculate Curvarture
1383 Double_t a = fitter->GetParameter(0);
1384 Double_t b = fitter->GetParameter(1);
1385 Double_t c = fitter->GetParameter(2);
1386 Double_t curvature = 1.0 + b*b - c*a;
1387 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1389 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1391 // Prepare error calculation
1392 TMatrixD covarPolY(3,3);
1393 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1394 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1395 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1396 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1398 TMatrixD covarPolZ(2,2);
1399 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1400 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1403 // Update the tracklets
1406 memset(cov, 0, sizeof(Double_t) * 15);
1407 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1409 x = tracklets[iLayer].GetX0();
1415 memset(cov, 0, sizeof(Double_t) * 3);
1416 TMatrixD transform(3,3);
1419 transform(0,2) = x*x;
1423 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1424 covariance *= transform.T();
1425 TMatrixD transformZ(2,2);
1426 transformZ(0,0) = transformZ(1,1) = 1;
1427 transformZ(0,1) = x;
1428 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1429 covarZ *= transformZ.T();
1430 // y: R^2 = (x - x0)^2 + (y - y0)^2
1431 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1432 // R = Sqrt() = 1/Curvature
1433 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1434 Double_t res = (x * a + b); // = (x - x0)/y0
1436 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1438 res = TMath::Sqrt(res);
1439 y = (1.0 - res) / a;
1441 cov[0] = covariance(0,0);
1442 cov[2] = covarZ(0,0);
1445 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1446 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1447 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1448 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1449 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1450 Double_t x0 = -b / a;
1451 if (-c * a + b * b + 1 > 0) {
1452 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
1453 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1454 if (a < 0) yderiv *= -1.0;
1458 z = offset + slope * (x - xref);
1460 tracklets[iLayer].SetYref(0, y);
1461 tracklets[iLayer].SetYref(1, dy);
1462 tracklets[iLayer].SetZref(0, z);
1463 tracklets[iLayer].SetZref(1, dz);
1464 tracklets[iLayer].SetC(curvature);
1465 tracklets[iLayer].SetCovRef(cov);
1466 tracklets[iLayer].SetChi2(chi2track);
1468 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRieman: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
1470 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1471 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1472 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1473 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1474 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1475 cstreamer << "FitTiltedRieman0"
1476 << "EventNumber=" << eventNumber
1477 << "CandidateNumber=" << candidateNumber
1479 << "Chi2Z=" << chi2z
1486 //____________________________________________________________________
1487 Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
1490 // Fit track with a staight line
1491 // Fills an AliTrackPoint array with np points
1492 // Function should be used to refit tracks when no magnetic field was on
1494 AliTRDLeastSquare yfitter, zfitter;
1495 AliTRDcluster *cl = NULL;
1497 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1499 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1500 if(!(tracklet = track->GetTracklet(ipl))) continue;
1501 if(!tracklet->IsOK()) continue;
1502 new(&work[ipl]) AliTRDseedV1(*tracklet);
1504 tracklets = &work[0];
1507 Double_t xref = CalculateReferenceX(tracklets);
1508 Double_t x, y, z, dx, ye, yr, tilt;
1509 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1510 if(!tracklets[ipl].IsOK()) continue;
1511 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1512 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1513 if (!tracklets[ipl].IsUsable(itb)) continue;
1517 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1521 Double_t z0 = zfitter.GetFunctionParameter(0);
1522 Double_t dzdx = zfitter.GetFunctionParameter(1);
1523 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1524 if(!tracklets[ipl].IsOK()) continue;
1525 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1526 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1527 if (!tracklets[ipl].IsUsable(itb)) continue;
1531 tilt = tracklets[ipl].GetTilt();
1533 yr = y + tilt*(z - z0 - dzdx*dx);
1534 // error definition changes for the different calls
1535 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1536 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1537 yfitter.AddPoint(&dx, yr, ye);
1541 Double_t y0 = yfitter.GetFunctionParameter(0);
1542 Double_t dydx = yfitter.GetFunctionParameter(1);
1543 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1545 //update track points array
1548 for(int ip=0; ip<np; ip++){
1549 points[ip].GetXYZ(xyz);
1550 xyz[1] = y0 + dydx * (xyz[0] - xref);
1551 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1552 points[ip].SetXYZ(xyz);
1559 //_________________________________________________________________________
1560 Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
1563 // Performs a Riemann fit taking tilting pad correction into account
1565 // Paramters: - Array of tracklets (connected to the track candidate)
1566 // - Flag selecting the error definition
1567 // Output: - Chi2 values of the track (in Parameter list)
1569 // The equations which has to be solved simultaneously are:
1571 // R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1572 // y^{*} = y - tg(h)(z - z_{t})
1573 // z_{t} = z_{0}+dzdx*(x-x_{r})
1575 // with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1576 // R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1577 // track in the x-z plane. Using the following transformations
1579 // t = 1 / (x^{2} + y^{2})
1581 // v = 2 * tan(h) * t
1582 // w = 2 * tan(h) * (x - x_{r}) * t
1584 // One gets the following linear equation
1586 // a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1588 // where the coefficients have the following meaning
1592 // c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1596 // The error calculation for the free term is thus
1598 // #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1601 // From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1604 // C = 1/R = a/(1 + b^{2} + c*a)
1608 // M.Ivanov <M.Ivanov@gsi.de>
1609 // A.Bercuci <A.Bercuci@gsi.de>
1610 // M.Fasel <M.Fasel@gsi.de>
1612 TLinearFitter *fitter = GetTiltedRiemanFitter();
1613 fitter->StoreData(kTRUE);
1614 fitter->ClearPoints();
1615 AliTRDLeastSquare zfitter;
1616 AliTRDcluster *cl = NULL;
1618 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1620 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1621 if(!(tracklet = track->GetTracklet(ipl))) continue;
1622 if(!tracklet->IsOK()) continue;
1623 new(&work[ipl]) AliTRDseedV1(*tracklet);
1625 tracklets = &work[0];
1628 Double_t xref = CalculateReferenceX(tracklets);
1629 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:\nx0[(0)%6.2f (1)%6.2f (2)%6.2f (3)%6.2f (4)%6.2f (5)%6.2f] xref[%6.2f]", tracklets[0].GetX0(), tracklets[1].GetX0(), tracklets[2].GetX0(), tracklets[3].GetX0(), tracklets[4].GetX0(), tracklets[5].GetX0(), xref);
1630 Double_t x, y, z, t, tilt, dx, w, we;
1633 // Containers for Least-square fitter
1634 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1635 if(!tracklets[ipl].IsOK()) continue;
1636 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1637 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1638 //if (!tracklets[ipl].IsUsable(itb)) continue;
1642 tilt = tracklets[ipl].GetTilt();
1646 uvt[0] = 2. * x * t;
1648 uvt[2] = 2. * tilt * t;
1649 uvt[3] = 2. * tilt * dx * t;
1650 w = 2. * (y + tilt*z) * t;
1651 // error definition changes for the different calls
1653 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
1654 fitter->AddPoint(uvt, w, we);
1655 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1659 if(fitter->Eval()) return 1.E10;
1661 Double_t z0 = fitter->GetParameter(3);
1662 Double_t dzdx = fitter->GetParameter(4);
1665 // Linear fitter - not possible to make boundaries
1666 // Do not accept non possible z and dzdx combinations
1667 Bool_t accept = kTRUE;
1668 Double_t zref = 0.0;
1669 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1670 if(!tracklets[iLayer].IsOK()) continue;
1671 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
1672 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1677 Double_t dzmf = zfitter.GetFunctionParameter(1);
1678 Double_t zmf = zfitter.GetFunctionValue(&xref);
1679 fitter->FixParameter(3, zmf);
1680 fitter->FixParameter(4, dzmf);
1682 fitter->ReleaseParameter(3);
1683 fitter->ReleaseParameter(4);
1684 z0 = fitter->GetParameter(3); // = zmf ?
1685 dzdx = fitter->GetParameter(4); // = dzmf ?
1688 // Calculate Curvature
1689 Double_t a = fitter->GetParameter(0);
1690 Double_t b = fitter->GetParameter(1);
1691 Double_t c = fitter->GetParameter(2);
1692 Double_t y0 = 1. / a;
1693 Double_t x0 = -b * y0;
1694 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1695 if(tmp<=0.) return 1.E10;
1696 Double_t radius = TMath::Sqrt(tmp);
1697 Double_t curvature = 1.0 + b*b - c*a;
1698 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1700 // Calculate chi2 of the fit
1701 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
1702 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:x0[%6.2f] y0[%6.2f] R[%6.2f] chi2[%f]\n", x0, y0, radius, chi2);
1704 // Update the tracklets
1706 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1707 x = tracklets[ip].GetX0();
1708 tmp = radius*radius-(x-x0)*(x-x0);
1709 if(tmp <= 0.) continue;
1710 tmp = TMath::Sqrt(tmp);
1712 // y: R^2 = (x - x0)^2 + (y - y0)^2
1713 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1714 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1715 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1716 tracklets[ip].SetYref(1, (x - x0) / tmp);
1717 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1718 tracklets[ip].SetZref(1, dzdx);
1719 tracklets[ip].SetC(curvature);
1720 tracklets[ip].SetChi2(chi2);
1723 //update track points array
1726 for(int ip=0; ip<np; ip++){
1727 points[ip].GetXYZ(xyz);
1728 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
1729 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1730 points[ip].SetXYZ(xyz);
1738 //____________________________________________________________________
1739 Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1741 // Kalman filter implementation for the TRD.
1742 // It returns the positions of the fit in the array "points"
1744 // Author : A.Bercuci@gsi.de
1746 // printf("Start track @ x[%f]\n", track->GetX());
1748 //prepare marker points along the track
1749 Int_t ip = np ? 0 : 1;
1751 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1752 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1755 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1758 AliTRDseedV1 tracklet;
1759 AliTRDseedV1 *ptrTracklet = NULL;
1761 //Loop through the TRD planes
1762 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1763 // GET TRACKLET OR BUILT IT
1764 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1766 if(!(ptrTracklet = &tracklets[iplane])) continue;
1768 if(!(ptrTracklet = track->GetTracklet(iplane))){
1769 /*AliTRDtrackerV1 *tracker = NULL;
1770 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1771 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1772 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1776 if(!ptrTracklet->IsOK()) continue;
1778 Double_t x = ptrTracklet->GetX0();
1781 //don't do anything if next marker is after next update point.
1782 if((up?-1:1) * (points[ip].GetX() - x) - AliTRDReconstructor::GetMaxStep() < 0) break;
1783 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1785 Double_t xyz[3]; // should also get the covariance
1787 track->Global2LocalPosition(xyz, track->GetAlpha());
1788 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1791 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1793 // Propagate closer to the next update point
1794 if(((up?-1:1) * (x - track->GetX()) + AliTRDReconstructor::GetMaxStep() < 0) && !PropagateToX(*track, x + (up?-1:1)*AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) return -1.;
1796 if(!AdjustSector(track)) return -1;
1797 if(TMath::Abs(track->GetSnp()) > AliTRDReconstructor::GetMaxSnp()) return -1;
1799 //load tracklet to the tracker and the track
1801 if((index = FindTracklet(ptrTracklet)) < 0){
1802 ptrTracklet = SetTracklet(&tracklet);
1803 index = fTracklets->GetEntriesFast()-1;
1805 track->SetTracklet(ptrTracklet, index);*/
1808 // register tracklet to track with tracklet creation !!
1809 // PropagateBack : loaded tracklet to the tracker and update index
1810 // RefitInward : update index
1811 // MakeTrack : loaded tracklet to the tracker and update index
1812 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1815 //Calculate the mean material budget along the path inside the chamber
1816 Double_t xyz0[3]; track->GetXYZ(xyz0);
1817 Double_t alpha = track->GetAlpha();
1818 Double_t xyz1[3], y, z;
1819 if(!track->GetProlongation(x, y, z)) return -1;
1820 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1821 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1823 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
1825 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1826 Double_t xrho = param[0]*param[4]; // density*length
1827 Double_t xx0 = param[1]; // radiation length
1829 //Propagate the track
1830 track->PropagateTo(x, xx0, xrho);
1831 if (!AdjustSector(track)) break;
1834 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1835 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1836 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
1837 if(chi2<1e+10) ((AliExternalTrackParam*)track)->Update(p, cov);
1840 //Reset material budget if 2 consecutive gold
1841 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1842 } // end planes loop
1846 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1848 Double_t xyz[3]; // should also get the covariance
1850 track->Global2LocalPosition(xyz, track->GetAlpha());
1851 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1855 return track->GetChi2();
1858 //_________________________________________________________________________
1859 Float_t AliTRDtrackerV1::CalculateChi2Z(const AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
1862 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1863 // A linear dependence on the x-value serves as a model.
1864 // The parameters are related to the tilted Riemann fit.
1865 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1866 // - the offset for the reference x
1868 // - the reference x position
1869 // Output: - The Chi2 value of the track in z-Direction
1871 Float_t chi2Z = 0, nLayers = 0;
1872 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
1873 if(!tracklets[iLayer].IsOK()) continue;
1874 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1875 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
1878 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1882 //_____________________________________________________________________________
1883 Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1886 // Starting from current X-position of track <t> this function
1887 // extrapolates the track up to radial position <xToGo> in steps of <maxStep>.
1888 // Returns 1 if track reaches the plane, and 0 otherwise
1891 // Current track X-position
1892 Double_t xpos = t.GetX()/*,
1893 mass = t.GetMass()*/;
1895 // Direction: inward or outward
1896 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
1898 while (((xToGo - xpos) * dir) > AliTRDReconstructor::GetEpsilon()) {
1899 // printf("to go %f\n", (xToGo - xpos) * dir);
1907 // The next step size
1908 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
1910 // Get the global position of the starting point
1913 // X-position after next step
1916 // Get local Y and Z at the X-position of the next step
1917 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
1919 // The global position of the end point of this prolongation step
1920 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1921 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1924 // Calculate the mean material budget between start and
1925 // end point of this prolongation step
1926 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
1928 // Propagate the track to the X-position after the next step
1929 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
1931 /* // Correct for mean material budget
1933 bg(TMath::Abs(t.GetP()/mass));
1934 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3){
1935 const char *pn[] = {"rho", "x/X0", "<A>", "<Z>", "L", "<Z/A>", "Nb"};
1936 printf("D-AliTRDtrackerV1::PropagateTo(): x[%6.2f] bg[%6.2f]\n", xpos, bg);
1937 printf(" param :: %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e]\n"
1948 dEdx = AliExternalTrackParam::BetheBlochSolid(bg);
1951 dEdx = AliExternalTrackParam::BetheBlochGas(bg);
1954 { // mean exitation energy (GeV)
1955 Double_t mee = ((param[3] < 13.) ? (12. * param[3] + 7.) : (9.76 * param[3] + 58.8 * TMath::Power(param[3],-0.19))) * 1.e-9;
1956 Double_t mZA = param[5]>1.e-5?param[5]:(param[3]/param[2]);
1957 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3) printf("D-AliTRDtrackerV1::PropagateTo(): Mee[%e] <Z/A>[%e]\n", mee, mZA);
1958 // protect against failed calculation of rho in MeanMaterialBudget()
1959 dEdx = AliExternalTrackParam::BetheBlochGeant(bg, param[0]>1.e-6?param[0]:2.33, 0.2, 3., mee, mZA);
1963 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=2) printf("D-AliTRDtrackerV1::PropagateTo(): dEdx(bg=%e, m=%e)= %e[GeV/cm]\n", bg, mass, dEdx);
1964 if (!t.CorrectForMeanMaterialdEdx(param[1], dir*param[0]*param[4], mass, dEdx)) return 0;
1966 // Rotate the track if necessary
1967 if(!AdjustSector(&t)) return 0;
1969 // New track X-position
1978 //_____________________________________________________________________________
1979 Bool_t AliTRDtrackerV1::ReadClusters(TTree *clusterTree)
1982 // Reads AliTRDclusters from the file.
1983 // The names of the cluster tree and branches
1984 // should match the ones used in AliTRDclusterizer::WriteClusters()
1987 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1988 TObjArray *clusterArray = new TObjArray(nsize+1000);
1990 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1992 AliError("Can't get the branch !");
1995 branch->SetAddress(&clusterArray);
1998 Float_t nclusters = fkRecoParam->GetNClusters();
1999 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
2000 fClusters = new TClonesArray("AliTRDcluster", Int_t(nclusters));
2001 fClusters->SetOwner(kTRUE);
2003 AliInfo(Form("Tracker owning clusters @ %p", (void*)fClusters));
2006 // Loop through all entries in the tree
2007 Int_t nEntries = (Int_t) clusterTree->GetEntries();
2010 AliTRDcluster *c = NULL;
2011 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
2013 nbytes += clusterTree->GetEvent(iEntry);
2015 // Get the number of points in the detector
2016 Int_t nCluster = clusterArray->GetEntriesFast();
2017 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
2018 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
2019 new((*fClusters)[ncl++]) AliTRDcluster(*c);
2020 delete (clusterArray->RemoveAt(iCluster));
2023 delete clusterArray;
2028 //_____________________________________________________________________________
2029 Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
2032 // Fills clusters into TRD tracking sectors
2035 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
2037 // if(!fkReconstructor->IsWritingClusters()) AliInfo(Form("IsWritingClusters[%c]", fkReconstructor->IsWritingClusters()?'y':'n'));
2038 if(!(fClusters = AliTRDReconstructor::GetClusters())){
2039 AliWarning("Clusters unavailable from TRD reconstructor. Trying reading from tree ...");
2041 if(!ReadClusters(cTree)) {
2042 AliError("Reading clusters from tree failed.");
2047 if(!fClusters || !fClusters->GetEntriesFast()){
2048 AliInfo("No TRD clusters");
2050 } else AliInfo(Form("Using :: clusters[%d] onl.tracklets[%d] onl.tracks[%d]",
2051 fClusters?fClusters->GetEntriesFast():0,
2052 AliTRDReconstructor::GetTracklets()?AliTRDReconstructor::GetTracklets()->GetEntriesFast():0,
2053 AliTRDReconstructor::GetTracks()?AliTRDReconstructor::GetTracks()->GetEntriesFast():0));
2055 BuildTrackingContainers();
2060 //_____________________________________________________________________________
2061 Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
2064 // Fills clusters into TRD tracking sectors
2065 // Function for use in the HLT
2067 if(!clusters || !clusters->GetEntriesFast()){
2068 AliInfo("No TRD clusters");
2070 } else AliInfo(Form("Using :: external.clusters[%d]", clusters->GetEntriesFast()));
2073 fClusters = clusters;
2075 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
2076 BuildTrackingContainers();
2082 //____________________________________________________________________
2083 Int_t AliTRDtrackerV1::BuildTrackingContainers()
2085 // Building tracking containers for clusters
2087 Int_t nin(0), ncl(fClusters->GetEntriesFast());
2089 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(ncl);
2090 if(c->IsInChamber()) nin++;
2091 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
2092 Int_t detector = c->GetDetector();
2093 Int_t sector = fGeom->GetSector(detector);
2094 Int_t stack = fGeom->GetStack(detector);
2095 Int_t layer = fGeom->GetLayer(detector);
2097 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, ncl);
2100 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
2101 if(!fTrSec[isector].GetNChambers()) continue;
2102 fTrSec[isector].Init(fkReconstructor);
2110 //____________________________________________________________________
2111 void AliTRDtrackerV1::UnloadClusters()
2114 // Clears the arrays of clusters and tracks. Resets sectors and timebins
2115 // If option "force" is also set the containers are also deleted. This is useful
2120 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
2123 fTracklets->Delete();
2124 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
2126 if(fClusters && IsClustersOwner()){
2127 AliInfo(Form("tracker[%p] clearing %d own clusters @ %p", (void*)this, fClusters->GetEntries(), (void*)fClusters));
2128 fClusters->Delete();
2130 // // save clusters array in the reconstructor for further use.
2131 // if(!fkReconstructor->IsWritingClusters()){
2132 // AliTRDReconstructor::SetClusters(fClusters);
2133 // SetClustersOwner(kFALSE);
2134 // } else AliTRDReconstructor::SetClusters(NULL);
2137 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
2139 // Increment the Event Number
2140 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
2143 // //____________________________________________________________________
2144 // void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2146 // const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2147 // if(!track) return;
2149 // AliTRDseedV1 *tracklet = NULL;
2150 // for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2151 // if(!(tracklet = track->GetTracklet(ily))) continue;
2152 // AliTRDcluster *c = NULL;
2153 // for(Int_t ic=AliTRDseed::kNclusters; ic--;){
2154 // if(!(c=tracklet->GetClusters(ic))) continue;
2161 //_____________________________________________________________________________
2162 Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
2165 // Rotates the track when necessary
2168 Double_t alpha = AliTRDgeometry::GetAlpha();
2169 Double_t y = track->GetY();
2170 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
2173 if (!track->Rotate( alpha)) {
2177 else if (y < -ymax) {
2178 if (!track->Rotate(-alpha)) {
2188 //____________________________________________________________________
2189 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(const AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
2191 // Find tracklet for TRD track <track>
2200 // Detailed description
2202 idx = track->GetTrackletIndex(p);
2203 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
2208 //____________________________________________________________________
2209 AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
2211 // Add this tracklet to the list of tracklets stored in the tracker
2214 // - tracklet : pointer to the tracklet to be added to the list
2217 // - the index of the new tracklet in the tracker tracklets list
2219 // Detailed description
2220 // Build the tracklets list if it is not yet created (late initialization)
2221 // and adds the new tracklet to the list.
2224 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2225 fTracklets->SetOwner(kTRUE);
2227 Int_t nentries = fTracklets->GetEntriesFast();
2228 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
2231 //____________________________________________________________________
2232 AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
2234 // Add this track to the list of tracks stored in the tracker
2237 // - track : pointer to the track to be added to the list
2240 // - the pointer added
2242 // Detailed description
2243 // Build the tracks list if it is not yet created (late initialization)
2244 // and adds the new track to the list.
2247 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2248 fTracks->SetOwner(kTRUE);
2250 Int_t nentries = fTracks->GetEntriesFast();
2251 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2256 //____________________________________________________________________
2257 Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
2260 // Steer tracking for one SM.
2263 // sector : Array of (SM) propagation layers containing clusters
2264 // esd : The current ESD event. On output it contains the also
2265 // the ESD (TRD) tracks found in this SM.
2268 // Number of tracks found in this TRD supermodule.
2270 // Detailed description
2272 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2273 // 2. Launch stack tracking.
2274 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2275 // 3. Pack results in the ESD event.
2279 Int_t nChambers = 0;
2280 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
2281 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
2282 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2284 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2285 if(!(chamber = stack[ilayer])) continue;
2286 if(chamber->GetNClusters() < fgNTimeBins * fkRecoParam->GetFindableClusters()) continue;
2288 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
2290 if(nChambers < 4) continue;
2291 //AliInfo(Form("Doing stack %d", istack));
2292 nTracks += Clusters2TracksStack(stack, fTracksESD);
2294 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2296 for(int itrack=0; itrack<nTracks; itrack++){
2297 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2298 Int_t id = esd->AddTrack(esdTrack);
2300 // set ESD id to stand alone TRD tracks
2301 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
2302 esdTrack=esd->GetTrack(id);
2303 TObject *o(NULL); Int_t ic(0);
2304 AliTRDtrackV1 *calibTrack(NULL);
2305 while((o = esdTrack->GetCalibObject(ic++))){
2306 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2307 calibTrack->SetESDid(esdTrack->GetID());
2313 // Reset Track and Candidate Number
2314 AliTRDtrackerDebug::SetCandidateNumber(0);
2315 AliTRDtrackerDebug::SetTrackNumber(0);
2317 // delete ESD tracks in the array
2318 fTracksESD->Delete();
2322 //____________________________________________________________________
2323 Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
2326 // Make tracks in one TRD stack.
2329 // layer : Array of stack propagation layers containing clusters
2330 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2331 // On exit the tracks found in this stack are appended.
2334 // Number of tracks found in this stack.
2336 // Detailed description
2338 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2339 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2340 // See AliTRDtrackerV1::MakeSeeds() for more details.
2341 // 3. Arrange track candidates in decreasing order of their quality
2342 // 4. Classify tracks in 5 categories according to:
2343 // a) number of layers crossed
2345 // 5. Sign clusters by tracks in decreasing order of track quality
2346 // 6. Build AliTRDtrack out of seeding tracklets
2348 // 8. Build ESD track and register it to the output list
2351 AliTRDtrackingChamber *chamber = NULL;
2352 AliTRDtrackingChamber **ci = NULL;
2353 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2354 Int_t pars[4]; // MakeSeeds parameters
2356 //Double_t alpha = AliTRDgeometry::GetAlpha();
2357 //Double_t shift = .5 * alpha;
2358 Int_t configs[kNConfigs];
2360 // Purge used clusters from the containers
2362 for(Int_t ic = kNPlanes; ic--; ci++){
2363 if(!(*ci)) continue;
2367 // Build initial seeding configurations
2368 Double_t quality = BuildSeedingConfigs(stack, configs);
2369 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10 || AliTRDReconstructor::GetStreamLevel()>10){
2370 AliInfo(Form("Plane config %d %d %d Quality %f"
2371 , configs[0], configs[1], configs[2], quality));
2375 // Initialize contors
2376 Int_t ntracks, // number of TRD track candidates
2377 ntracks1, // number of registered TRD tracks/iter
2378 ntracks2 = 0; // number of all registered TRD tracks in stack
2382 Int_t ic = 0; ci = &stack[0];
2383 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2384 if(!(*ci)) return ntracks2;
2385 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
2388 // Loop over seeding configurations
2389 ntracks = 0; ntracks1 = 0;
2390 for (Int_t iconf = 0; iconf<fkRecoParam->GetNumberOfSeedConfigs(); iconf++) {
2391 pars[0] = configs[iconf];
2394 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
2395 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
2396 if(ntracks == kMaxTracksStack) break;
2398 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
2401 // Sort the seeds according to their quality
2402 Int_t sort[kMaxTracksStack+1];
2403 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
2404 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 2){
2405 AliDebug(3, "Track candidates classification:");
2406 for (Int_t it(0); it < ntracks; it++) {
2408 printf(" %2d idx[%d] Quality[%e]\n", it, jt, fTrackQuality[jt]);
2412 // Initialize number of tracks so far and logic switches
2413 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2414 Bool_t signedTrack[kMaxTracksStack];
2415 Bool_t fakeTrack[kMaxTracksStack];
2416 for (Int_t i=0; i<ntracks; i++){
2417 signedTrack[i] = kFALSE;
2418 fakeTrack[i] = kFALSE;
2420 //AliInfo("Selecting track candidates ...");
2422 // Sieve clusters in decreasing order of track quality
2423 Int_t jSieve(0), rejectedCandidates(0);
2425 // Check track candidates
2426 rejectedCandidates=0;
2427 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
2428 Int_t trackIndex = sort[itrack];
2429 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
2431 // Calculate track parameters from tracklets seeds
2436 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2437 Int_t jseed = kNPlanes*trackIndex+jLayer;
2438 sseed[jseed].UpdateUsed();
2439 if(!sseed[jseed].IsOK()) continue;
2440 // check if primary candidate
2441 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
2442 ncl += sseed[jseed].GetN();
2443 nused += sseed[jseed].GetNUsed();
2447 // Filter duplicated tracks
2449 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2450 fakeTrack[trackIndex] = kTRUE;
2453 if (ncl>0 && Float_t(nused)/ncl >= .25){
2454 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d] used/ncl[%f]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused, Float_t(nused)/ncl));
2455 fakeTrack[trackIndex] = kTRUE;
2459 AliDebug(4, Form("Candidate[%d] Quality[%e] Tracklets[%d] Findable[%d] Ncl[%d] Nused[%d]", trackIndex, fTrackQuality[trackIndex], nlayers, findable, ncl, nused));
2462 Bool_t skip = kFALSE;
2464 case 0: // select 6 tracklets primary tracks, good quality
2465 if(nlayers > findable || nlayers < kNPlanes) {skip = kTRUE; break;}
2466 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2469 case 1: // select shorter primary tracks, good quality
2470 //if(findable<4){skip = kTRUE; break;}
2471 if(nlayers < findable){skip = kTRUE; break;}
2472 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2475 case 2: // select 6 tracklets secondary tracks
2476 if(nlayers < kNPlanes) { skip = kTRUE; break;}
2477 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2480 case 3: // select shorter tracks, good quality
2481 if (nlayers<4){skip = kTRUE; break;}
2482 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2485 case 4: // select anything with at least 4 tracklets
2486 if (nlayers<4){skip = kTRUE; break;}
2487 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2491 rejectedCandidates++;
2492 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2494 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2496 signedTrack[trackIndex] = kTRUE;
2498 AliTRDseedV1 *lseed =&sseed[trackIndex*kNPlanes];
2499 AliTRDtrackV1 *track = MakeTrack(lseed);
2501 AliDebug(1, "Track building failed.");
2504 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 1){
2505 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2506 AliDebug(2, Form("Track pt=%7.2fGeV/c SM[%2d] Done.", track->Pt(), fGeom->GetSector(chamber->GetDetector())));
2510 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
2511 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
2513 AliTRDseedV1 *dseed[6];
2514 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
2516 //Int_t eventNrInFile = esd->GetEventNumberInFile();
2517 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2518 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2519 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2520 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2521 cstreamer << "Clusters2TracksStack"
2522 << "EventNumber=" << eventNumber
2523 << "TrackNumber=" << trackNumber
2524 << "CandidateNumber=" << candidateNumber
2525 << "Iter=" << fSieveSeeding
2526 << "Like=" << fTrackQuality[trackIndex]
2527 << "S0.=" << dseed[0]
2528 << "S1.=" << dseed[1]
2529 << "S2.=" << dseed[2]
2530 << "S3.=" << dseed[3]
2531 << "S4.=" << dseed[4]
2532 << "S5.=" << dseed[5]
2534 << "NLayers=" << nlayers
2535 << "Findable=" << findable
2536 << "NUsed=" << nused
2541 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2542 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2543 esdTrack->SetLabel(track->GetLabel());
2544 track->UpdateESDtrack(esdTrack);
2545 // write ESD-friends if neccessary
2546 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
2547 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2548 calibTrack->SetOwner();
2549 esdTrack->AddCalibObject(calibTrack);
2552 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
2556 } while(jSieve<5 && rejectedCandidates); // end track candidates sieve
2557 if(!ntracks1) break;
2559 // increment counters
2560 ntracks2 += ntracks1;
2562 if(fkReconstructor->IsHLT()) break;
2565 // Rebuild plane configurations and indices taking only unused clusters into account
2566 quality = BuildSeedingConfigs(stack, configs);
2567 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
2569 for(Int_t ip = 0; ip < kNPlanes; ip++){
2570 if(!(chamber = stack[ip])) continue;
2571 chamber->Build(fGeom);//Indices(fSieveSeeding);
2574 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10 || AliTRDReconstructor::GetStreamLevel()>10){
2575 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2577 } while(fSieveSeeding<10); // end stack clusters sieve
2581 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2586 //___________________________________________________________________
2587 Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
2590 // Assign probabilities to chambers according to their
2591 // capability of producing seeds.
2595 // layers : Array of stack propagation layers for all 6 chambers in one stack
2596 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2597 // for details) in the decreasing order of their seeding probabilities.
2601 // Return top configuration quality
2603 // Detailed description:
2605 // To each chamber seeding configuration (see GetSeedingConfig() for
2606 // the list of all configurations) one defines 2 quality factors:
2607 // - an apriori topological quality (see GetSeedingConfig() for details) and
2608 // - a data quality based on the uniformity of the distribution of
2609 // clusters over the x range (time bins population). See CookChamberQA() for details.
2610 // The overall chamber quality is given by the product of this 2 contributions.
2613 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
2614 AliTRDtrackingChamber *chamber = NULL;
2615 for(int iplane=0; iplane<kNPlanes; iplane++){
2616 if(!(chamber = stack[iplane])) continue;
2617 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2620 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2621 Int_t planes[] = {0, 0, 0, 0};
2622 for(int iconf=0; iconf<kNConfigs; iconf++){
2623 GetSeedingConfig(iconf, planes);
2624 tconfig[iconf] = fgTopologicQA[iconf];
2625 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2628 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2629 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2630 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2631 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2633 return tconfig[configs[0]];
2636 //____________________________________________________________________
2637 Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
2640 // Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2641 // either missed by TPC prolongation or conversions inside the TRD volume.
2642 // For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
2645 // layers : Array of stack propagation layers containing clusters
2646 // sseed : Array of empty tracklet seeds. On exit they are filled.
2647 // ipar : Control parameters:
2648 // ipar[0] -> seeding chambers configuration
2649 // ipar[1] -> stack index
2650 // ipar[2] -> number of track candidates found so far
2653 // Number of tracks candidates found.
2655 // The following steps are performed:
2656 // 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2657 // radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2658 // is described in AliTRDtrackerV1::Clusters2TracksStack().
2659 // 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2660 // - for each seeding cluster in the lower seeding layer find
2661 // - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2662 // is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2663 // - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2665 // - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2666 // seeding clusters.
2667 // The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2668 // and AliTRDchamberTimeBin::GetClusters().
2669 // 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2670 // performed at this level
2671 // 4. Initialize seeding tracklets in the seeding chambers.
2672 // 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2673 // 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2674 // AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2675 // 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2676 // 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2677 // approximation of the track.
2678 // 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2679 // checked against the Riemann fit:
2680 // - position resolution in y
2681 // - angular resolution in the bending plane
2682 // - likelihood of the number of clusters attached to the tracklet
2683 // 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2684 // - Initialization of extrapolation tracklets with the fit parameters
2685 // - Attach clusters to extrapolated tracklets
2686 // - Helix fit of tracklets
2687 // 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2688 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
2689 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2690 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2691 // 14. Cooking labels for tracklets. Should be done only for MC
2692 // 15. Register seeds.
2695 // Marian Ivanov <M.Ivanov@gsi.de>
2696 // Alexandru Bercuci <A.Bercuci@gsi.de>
2697 // Markus Fasel <M.Fasel@gsi.de>
2699 AliTRDtrackingChamber *chamber = NULL;
2700 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
2701 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
2702 Int_t ncl, mcl; // working variable for looping over clusters
2703 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2705 // chi2[0] = tracklet chi2 on the Z direction
2706 // chi2[1] = tracklet chi2 on the R direction
2709 // this should be data member of AliTRDtrack TODO
2710 // Double_t seedQuality[kMaxTracksStack];
2712 // unpack control parameters
2713 Int_t config = ipar[0];
2714 Int_t ntracks = ipar[1];
2715 Int_t istack = ipar[2];
2716 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
2717 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
2720 // Init chambers geometry
2721 Double_t hL[kNPlanes]; // Tilting angle
2722 Float_t padlength[kNPlanes]; // pad lenghts
2723 Float_t padwidth[kNPlanes]; // pad widths
2724 AliTRDpadPlane *pp = NULL;
2725 for(int iplane=0; iplane<kNPlanes; iplane++){
2726 pp = fGeom->GetPadPlane(iplane, istack);
2727 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
2728 padlength[iplane] = pp->GetLengthIPad();
2729 padwidth[iplane] = pp->GetWidthIPad();
2732 // Init anode wire position for chambers
2733 Double_t x0[kNPlanes], // anode wire position
2734 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
2735 TGeoHMatrix *matrix = NULL;
2736 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2737 Double_t glb[] = {0., 0., 0.};
2738 AliTRDtrackingChamber **cIter = &stack[0];
2739 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
2740 if(!(*cIter)) continue;
2741 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
2742 x0[iLayer] = fgkX0[iLayer];
2745 matrix->LocalToMaster(loc, glb);
2746 x0[iLayer] = glb[0];
2749 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
2751 // Build seeding layers
2754 for(int isl=0; isl<kNSeedPlanes; isl++){
2755 if(!(chamber = stack[planes[isl]])) continue;
2756 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
2759 if(nlayers < kNSeedPlanes) return ntracks;
2762 // Start finding seeds
2763 Double_t cond0[4], cond1[4], cond2[4];
2765 while((c[3] = (*fSeedTB[3])[icl++])){
2767 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2768 fSeedTB[0]->GetClusters(cond0, index, ncl);
2769 //printf("Found c[3] candidates 0 %d\n", ncl);
2772 c[0] = (*fSeedTB[0])[index[jcl++]];
2774 Double_t dx = c[3]->GetX() - c[0]->GetX();
2775 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2776 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2777 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
2778 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
2779 //printf("Found c[0] candidates 1 %d\n", mcl);
2783 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2785 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
2786 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2787 //printf("Found c[1] candidate 2 %p\n", c[2]);
2790 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].",
2791 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2792 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2793 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2794 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
2796 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
2800 AliTRDseedV1 *tseed = &cseed[0];
2802 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2803 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
2804 tseed->SetDetector(det);
2805 tseed->SetTilt(hL[iLayer]);
2806 tseed->SetPadLength(padlength[iLayer]);
2807 tseed->SetPadWidth(padwidth[iLayer]);
2808 tseed->SetReconstructor(fkReconstructor);
2809 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
2810 tseed->Init(GetRiemanFitter());
2811 tseed->SetStandAlone(kTRUE);
2814 Bool_t isFake = kFALSE;
2815 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())
2816 ||AliTRDReconstructor::GetStreamLevel()>=2 ){
2817 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2818 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2819 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2822 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2824 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2825 Int_t ll = c[3]->GetLabel(0);
2826 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2827 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2828 AliRieman *rim = GetRiemanFitter();
2829 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2831 <<"EventNumber=" << eventNumber
2832 <<"CandidateNumber=" << candidateNumber
2833 <<"isFake=" << isFake
2834 <<"config=" << config
2836 <<"chi2z=" << chi2[0]
2837 <<"chi2y=" << chi2[1]
2838 <<"Y2exp=" << cond2[0]
2839 <<"Z2exp=" << cond2[1]
2840 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2841 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2842 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2843 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2844 <<"yref0=" << yref[0]
2845 <<"yref1=" << yref[1]
2846 <<"yref2=" << yref[2]
2847 <<"yref3=" << yref[3]
2852 <<"Seed0.=" << &cseed[planes[0]]
2853 <<"Seed1.=" << &cseed[planes[1]]
2854 <<"Seed2.=" << &cseed[planes[2]]
2855 <<"Seed3.=" << &cseed[planes[3]]
2856 <<"RiemanFitter.=" << rim
2859 if(chi2[0] > fkRecoParam->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
2860 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
2861 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2864 if(chi2[1] > fkRecoParam->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
2865 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
2866 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2869 //AliInfo("Passed chi2 filter.");
2871 // try attaching clusters to tracklets
2873 AliTRDcluster *cl = NULL;
2874 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2875 Int_t jLayer = planes[iLayer];
2876 Int_t nNotInChamber = 0;
2877 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
2878 if(/*fkReconstructor->IsHLT()*/kFALSE){
2879 cseed[jLayer].UpdateUsed();
2880 if(!cseed[jLayer].IsOK()) continue;
2882 cseed[jLayer].Fit();
2883 cseed[jLayer].UpdateUsed();
2884 cseed[jLayer].ResetClusterIter();
2885 while((cl = cseed[jLayer].NextCluster())){
2886 if(!cl->IsInChamber()) nNotInChamber++;
2888 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2889 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
2894 if(mlayers < kNSeedPlanes){
2895 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
2896 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2900 // temporary exit door for the HLT
2901 if(fkReconstructor->IsHLT()){
2902 // attach clusters to extrapolation chambers
2903 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2904 Int_t jLayer = planesExt[iLayer];
2905 if(!(chamber = stack[jLayer])) continue;
2906 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
2907 cseed[jLayer].Fit();
2909 //FitTiltedRiemanConstraint(&cseed[0], GetZ());
2910 fTrackQuality[ntracks] = 1.; // dummy value
2912 if(ntracks == kMaxTracksStack) return ntracks;
2918 // Update Seeds and calculate Likelihood
2919 // fit tracklets and cook likelihood
2920 Double_t chi2Vals[4];
2921 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
2922 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2923 Int_t jLayer = planes[iLayer];
2924 cseed[jLayer].Fit(1);
2926 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
2928 if (TMath::Log(1.E-9 + like) < fkRecoParam->GetTrackLikelihood()){
2929 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2930 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2933 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2935 // book preliminry results
2936 //seedQuality[ntracks] = like;
2937 fSeedLayer[ntracks] = config;/*sLayer;*/
2939 // attach clusters to the extrapolation seeds
2941 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2942 Int_t jLayer = planesExt[iLayer];
2943 if(!(chamber = stack[jLayer])) continue;
2945 // fit extrapolated seed
2946 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2947 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2948 AliTRDseedV1 pseed = cseed[jLayer];
2949 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2951 cseed[jLayer] = pseed;
2952 chi2Vals[0] = FitTiltedRieman(cseed, kTRUE);
2953 cseed[jLayer].Fit(1);
2957 // AliInfo("Extrapolation done.");
2958 // Debug Stream containing all the 6 tracklets
2959 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())
2960 ||AliTRDReconstructor::GetStreamLevel()>=2){
2961 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2962 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2963 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2964 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2965 cstreamer << "MakeSeeds1"
2966 << "EventNumber=" << eventNumber
2967 << "CandidateNumber=" << candidateNumber
2968 << "S0.=" << &cseed[0]
2969 << "S1.=" << &cseed[1]
2970 << "S2.=" << &cseed[2]
2971 << "S3.=" << &cseed[3]
2972 << "S4.=" << &cseed[4]
2973 << "S5.=" << &cseed[5]
2974 << "FitterT.=" << tiltedRieman
2978 if(fkRecoParam->HasImproveTracklets()){
2979 if(!ImproveSeedQuality(stack, cseed, chi2Vals[0])){
2980 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2981 AliDebug(3, "ImproveSeedQuality() failed.");
2985 // do track fitting with vertex constraint
2986 if(fkRecoParam->IsVertexConstrained()) chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ());
2987 else chi2Vals[1] = -1.;
2988 chi2Vals[2] = GetChi2Z(&cseed[0]);
2989 chi2Vals[3] = GetChi2Phi(&cseed[0]);
2991 // calculate track quality
2992 fTrackQuality[ntracks] = CalculateTrackLikelihood(&chi2Vals[0]);
2994 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())
2995 ||AliTRDReconstructor::GetStreamLevel()>=2){
2996 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2997 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2998 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2999 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
3000 TLinearFitter *fitterT = GetTiltedRiemanFitter();
3002 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
3003 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
3005 cstreamer << "MakeSeeds2"
3006 << "EventNumber=" << eventNumber
3007 << "CandidateNumber=" << candidateNumber
3008 << "Chi2TR=" << chi2Vals[0]
3009 << "Chi2TC=" << chi2Vals[1]
3010 << "Nlayers=" << mlayers
3011 << "NClusters=" << ncls
3013 << "S0.=" << &cseed[0]
3014 << "S1.=" << &cseed[1]
3015 << "S2.=" << &cseed[2]
3016 << "S3.=" << &cseed[3]
3017 << "S4.=" << &cseed[4]
3018 << "S5.=" << &cseed[5]
3019 << "FitterT.=" << fitterT
3020 << "FitterTC.=" << fitterTC
3023 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")){
3024 Double_t pt[]={0., 0.};
3025 for(Int_t il(0); il<kNPlanes; il++){
3026 if(!cseed[il].IsOK()) continue;
3027 pt[0] = GetBz()*kB2C/cseed[il].GetC();
3028 pt[1] = GetBz()*kB2C/cseed[il].GetC(1);
3031 AliDebug(2, Form("Candidate[%2d] pt[%7.3f %7.3f] Q[%e]\n"
3032 " [0] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3033 " [1] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3034 " [2] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3035 " [3] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3036 " [4] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3037 " [5] x[%6.2f] n[%2d] nu[%d] OK[%c]"
3038 , ntracks, pt[0], pt[1], fTrackQuality[ntracks]
3039 ,cseed[0].GetX(), cseed[0].GetN(), cseed[0].GetNUsed(), cseed[0].IsOK()?'y':'n'
3040 ,cseed[1].GetX(), cseed[1].GetN(), cseed[1].GetNUsed(), cseed[1].IsOK()?'y':'n'
3041 ,cseed[2].GetX(), cseed[2].GetN(), cseed[2].GetNUsed(), cseed[2].IsOK()?'y':'n'
3042 ,cseed[3].GetX(), cseed[3].GetN(), cseed[3].GetNUsed(), cseed[3].IsOK()?'y':'n'
3043 ,cseed[4].GetX(), cseed[4].GetN(), cseed[4].GetNUsed(), cseed[4].IsOK()?'y':'n'
3044 ,cseed[5].GetX(), cseed[5].GetN(), cseed[5].GetNUsed(), cseed[5].IsOK()?'y':'n'));
3047 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
3048 if(ntracks == kMaxTracksStack){
3049 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
3060 //_____________________________________________________________________________
3061 AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const tracklet)
3064 // Build a TRD track out of tracklet candidates
3067 // seeds : array of tracklets
3068 // params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
3069 // [0] - radial position of the track at reference point
3070 // [1] - y position of the fit at [0]
3071 // [2] - z position of the fit at [0]
3072 // [3] - snp of the first tracklet
3073 // [4] - tgl of the first tracklet
3074 // [5] - curvature of the Riemann fit - 1/pt
3075 // [6] - sector rotation angle
3080 // Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
3081 // (diagonal with constant variance terms TODO - correct parameterization)
3083 // In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
3084 // offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
3085 // for details). Do also MC label calculation and PID if propagation successfully.
3087 if(fkReconstructor->IsHLT()) FitTiltedRiemanConstraint(tracklet, 0);
3088 Double_t alpha = AliTRDgeometry::GetAlpha();
3089 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
3091 // find first good tracklet
3092 Int_t idx(0); while(idx<kNPlanes && !tracklet[idx].IsOK()) idx++;
3093 if(idx>2){ AliDebug(1, Form("Found suspect track start @ layer idx[%d]\n"
3094 " %c[0] x0[%f] n[%d] nu[%d] OK[%c]\n"
3095 " %c[1] x0[%f] n[%d] nu[%d] OK[%c]\n"
3096 " %c[2] x0[%f] n[%d] nu[%d] OK[%c]\n"
3097 " %c[3] x0[%f] n[%d] nu[%d] OK[%c]\n"
3098 " %c[4] x0[%f] n[%d] nu[%d] OK[%c]\n"
3099 " %c[5] x0[%f] n[%d] nu[%d] OK[%c]"
3101 ,idx==0?'*':' ', tracklet[0].GetX0(), tracklet[0].GetN(), tracklet[0].GetNUsed(), tracklet[0].IsOK()?'y':'n'
3102 ,idx==1?'*':' ', tracklet[1].GetX0(), tracklet[1].GetN(), tracklet[1].GetNUsed(), tracklet[1].IsOK()?'y':'n'
3103 ,idx==2?'*':' ', tracklet[2].GetX0(), tracklet[2].GetN(), tracklet[2].GetNUsed(), tracklet[2].IsOK()?'y':'n'
3104 ,idx==3?'*':' ', tracklet[3].GetX0(), tracklet[3].GetN(), tracklet[3].GetNUsed(), tracklet[3].IsOK()?'y':'n'
3105 ,idx==4?'*':' ', tracklet[4].GetX0(), tracklet[4].GetN(), tracklet[4].GetNUsed(), tracklet[4].IsOK()?'y':'n'
3106 ,idx==5?'*':' ', tracklet[5].GetX0(), tracklet[5].GetN(), tracklet[5].GetNUsed(), tracklet[5].IsOK()?'y':'n'));
3111 Double_t x(tracklet[idx].GetX0() - dx);
3112 // Build track parameters
3113 Double_t params[] = {
3114 tracklet[idx].GetYref(0) - dx*tracklet[idx].GetYref(1) // y
3115 ,tracklet[idx].GetZref(0) - dx*tracklet[idx].GetZref(1) // z
3116 ,TMath::Sin(TMath::ATan(tracklet[idx].GetYref(1))) // snp
3117 ,tracklet[idx].GetZref(1) / TMath::Sqrt(1. + tracklet[idx].GetYref(1) * tracklet[idx].GetYref(1)) // tgl
3118 ,tracklet[idx].GetC(fkReconstructor->IsHLT()?1:0) // curvature -> 1/pt
3120 Int_t sector(fGeom->GetSector(tracklet[idx].GetDetector()));
3123 c[ 0] = 0.2; // s^2_y
3124 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
3125 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
3126 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
3127 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[4]*params[4]*0.01; // s^2_1/pt
3129 AliTRDtrackV1 track(tracklet, params, c, x, sector*alpha+shift);
3131 AliTRDseedV1 *ptrTracklet = NULL;
3133 // skip Kalman filter for HLT
3134 if(/*fkReconstructor->IsHLT()*/kFALSE){
3135 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
3136 track.UnsetTracklet(jLayer);
3137 ptrTracklet = &tracklet[jLayer];
3138 if(!ptrTracklet->IsOK()) continue;
3139 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
3140 ptrTracklet = SetTracklet(ptrTracklet);
3141 ptrTracklet->UseClusters();
3142 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
3144 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
3145 ptrTrack->CookPID();
3146 ptrTrack->CookLabel(.9);
3147 ptrTrack->SetReconstructor(fkReconstructor);
3151 // prevent the error message in AliTracker::MeanMaterialBudget: "start point out of geometry"
3152 if(TMath::Abs(track.GetX()) + TMath::Abs(track.GetY()) + TMath::Abs(track.GetZ()) > 10000) return NULL;
3154 track.ResetCovariance(1);
3155 Int_t nc = TMath::Abs(FollowBackProlongation(track));
3156 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming())
3157 ||AliTRDReconstructor::GetStreamLevel()>5){
3158 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3159 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3160 Double_t p[5]; // Track Params for the Debug Stream
3161 track.GetExternalParameters(x, p);
3162 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3164 << "EventNumber=" << eventNumber
3165 << "CandidateNumber=" << candidateNumber
3173 << "Yin=" << params[0]
3174 << "Zin=" << params[1]
3175 << "snpin=" << params[2]
3176 << "tndin=" << params[3]
3177 << "crvin=" << params[4]
3178 << "track.=" << &track
3182 UnsetTrackletsTrack(&track);
3185 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
3186 ptrTrack->SetReconstructor(fkReconstructor);
3187 ptrTrack->CookLabel(.9);
3188 for(Int_t il(kNPlanes); il--;){
3189 if(!(ptrTracklet = ptrTrack->GetTracklet(il))) continue;
3190 ptrTracklet->UseClusters();
3193 // computes PID for track
3194 ptrTrack->CookPID();
3195 // update calibration references using this track
3196 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
3198 AliInfo("Could not get Calibra instance.");
3199 } else if(calibra->GetHisto2d()){
3200 calibra->UpdateHistogramsV1(ptrTrack);
3206 //____________________________________________________________________
3207 Bool_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed, Double_t &chi2)
3210 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3213 // layers : Array of propagation layers for a stack/supermodule
3214 // cseed : Array of 6 seeding tracklets which has to be improved
3217 // cssed : Improved seeds
3219 // Detailed description
3221 // Iterative procedure in which new clusters are searched for each
3222 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3223 // can be maximized. If some optimization is found the old seeds are replaced.
3228 // make a local working copy
3229 AliTRDtrackingChamber *chamber = NULL;
3230 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3232 Float_t quality(1.e3),
3233 lQuality[AliTRDgeometry::kNlayer] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
3235 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3236 bseed[jLayer] = cseed[jLayer];
3237 if(!bseed[jLayer].IsOK()) continue;
3239 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3240 quality += lQuality[jLayer];
3245 AliDebug(2, Form("Start N[%d] Q[%f] chi2[%f]", rLayers, quality, chi2));
3247 for (Int_t iter = 0; iter < 4; iter++) {
3248 // Try better cluster set
3249 Int_t nLayers(0); Float_t qualitynew(0.);
3250 Int_t indexes[4*AliTRDgeometry::kNlayer];
3251 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3252 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3253 Int_t bLayer = indexes[jLayer];
3254 bseed[bLayer].Reset("c");
3255 if(!(chamber = stack[bLayer])) continue;
3256 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
3257 bseed[bLayer].Fit(1);
3258 if(!bseed[bLayer].IsOK()) continue;
3260 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3261 qualitynew += lQuality[jLayer];
3263 if(rLayers > nLayers){
3264 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
3265 return iter>0?kTRUE:kFALSE;
3266 } else rLayers=nLayers;
3267 qualitynew /= rLayers;
3269 if(qualitynew > quality){
3270 AliDebug(4, Form("Quality[%f] worsen in iter[%d] to ref[%f].", qualitynew, iter, quality));
3271 return iter>0?kTRUE:kFALSE;
3272 } else quality = qualitynew;
3274 // try improve track parameters
3275 Float_t chi2new = FitTiltedRieman(bseed, kTRUE);
3277 AliDebug(4, Form("Chi2[%f] worsen in iter[%d] to ref[%f].", chi2new, iter, chi2));
3278 return iter>0?kTRUE:kFALSE;
3279 } else chi2 = chi2new;
3281 // store better tracklets
3282 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer]=bseed[jLayer];
3283 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
3286 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming())
3287 ||AliTRDReconstructor::GetStreamLevel()>=7){
3288 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3289 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3290 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
3291 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3292 cstreamer << "ImproveSeedQuality"
3293 << "EventNumber=" << eventNumber
3294 << "CandidateNumber=" << candidateNumber
3295 << "Iteration=" << iter
3296 << "S0.=" << &cseed[0]
3297 << "S1.=" << &cseed[1]
3298 << "S2.=" << &cseed[2]
3299 << "S3.=" << &cseed[3]
3300 << "S4.=" << &cseed[4]
3301 << "S5.=" << &cseed[5]
3302 << "FitterT.=" << tiltedRieman
3307 // we are sure that at least 4 tracklets are OK !
3311 //_________________________________________________________________________
3312 Double_t AliTRDtrackerV1::CalculateTrackLikelihood(Double_t *chi2){
3314 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3315 // the track selection
3316 // The likelihood value containes:
3317 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3318 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3319 // For all Parameters an exponential dependency is used
3321 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3322 // - Array of chi2 values:
3323 // * Non-Constrained Tilted Riemann fit
3324 // * Vertex-Constrained Tilted Riemann fit
3325 // * z-Direction from Linear fit
3326 // Output: - The calculated track likelihood
3331 // Non-constrained Tilted Riemann
3332 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078);
3333 // Constrained Tilted Riemann
3334 Double_t likeChi2TC(1.);
3336 likeChi2TC = TMath::Exp(-chi2[1] * 0.677);
3337 Double_t r = likeChi2TC/likeChi2TR;
3338 if(r>1.e2){;} // -> a primary track use TC
3339 else if(r<1.e2) // -> a secondary track use TR
3341 else{;} // -> test not conclusive
3343 // Chi2 only on Z direction
3344 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14);
3345 // Chi2 angular resolution
3346 Double_t likeChi2Phi= TMath::Exp(-chi2[3] * 3.23);
3348 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2TC * likeChi2Phi;
3350 AliDebug(2, Form("Likelihood [%e]\n"
3351 " Rieman : chi2[%f] likelihood[%6.2e]\n"
3352 " Vertex : chi2[%f] likelihood[%6.2e]\n"
3353 " Z : chi2[%f] likelihood[%6.2e]\n"
3354 " Phi : chi2[%f] likelihood[%6.2e]"
3356 , chi2[0], likeChi2TR
3357 , chi2[1], likeChi2TC
3358 , chi2[2], likeChi2Z
3359 , chi2[3], likeChi2Phi
3362 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())
3363 ||AliTRDReconstructor::GetStreamLevel()>=2){
3364 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3365 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3366 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3367 cstreamer << "CalculateTrackLikelihood0"
3368 << "EventNumber=" << eventNumber
3369 << "CandidateNumber=" << candidateNumber
3370 << "LikeChi2Z=" << likeChi2Z
3371 << "LikeChi2TR=" << likeChi2TR
3372 << "LikeChi2TC=" << likeChi2TC
3373 << "LikeChi2Phi=" << likeChi2Phi
3374 << "TrackLikelihood=" << trackLikelihood
3378 return trackLikelihood;
3381 //____________________________________________________________________
3382 Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
3385 // Calculate the probability of this track candidate.
3388 // cseeds : array of candidate tracklets
3389 // planes : array of seeding planes (see seeding configuration)
3390 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3395 // Detailed description
3397 // The track quality is estimated based on the following 4 criteria:
3398 // 1. precision of the rieman fit on the Y direction (likea)
3399 // 2. chi2 on the Y direction (likechi2y)
3400 // 3. chi2 on the Z direction (likechi2z)
3401 // 4. number of attached clusters compared to a reference value
3402 // (see AliTRDrecoParam::fkFindable) (likeN)
3404 // The distributions for each type of probabilities are given below as of
3405 // (date). They have to be checked to assure consistency of estimation.
3408 // ratio of the total number of clusters/track which are expected to be found by the tracker.
3409 Double_t chi2y = GetChi2Y(&cseed[0]);
3410 Double_t chi2z = GetChi2Z(&cseed[0]);
3412 Float_t nclusters = 0.;
3413 Double_t sumda = 0.;
3414 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3415 Int_t jlayer = planes[ilayer];
3416 nclusters += cseed[jlayer].GetN2();
3417 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
3421 Double_t likea = TMath::Exp(-sumda * fkRecoParam->GetPhiSlope());
3422 Double_t likechi2y = 0.0000000001;
3423 if (fkReconstructor->IsCosmic() || chi2y < fkRecoParam->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fkRecoParam->GetChi2YSlope());
3424 Double_t likechi2z = TMath::Exp(-chi2z * fkRecoParam->GetChi2ZSlope());
3425 Double_t likeN = TMath::Exp(-(fkRecoParam->GetNMeanClusters() - nclusters) / fkRecoParam->GetNSigmaClusters());
3426 Double_t like = likea * likechi2y * likechi2z * likeN;
3428 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())
3429 ||AliTRDReconstructor::GetStreamLevel()>=2){
3430 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3431 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3432 Int_t nTracklets = 0; Float_t meanNcls = 0;
3433 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3434 if(!cseed[iseed].IsOK()) continue;
3436 meanNcls += cseed[iseed].GetN2();
3438 if(nTracklets) meanNcls /= nTracklets;
3439 // The Debug Stream contains the seed
3440 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3441 cstreamer << "CookLikelihood"
3442 << "EventNumber=" << eventNumber
3443 << "CandidateNumber=" << candidateNumber
3444 << "tracklet0.=" << &cseed[0]
3445 << "tracklet1.=" << &cseed[1]
3446 << "tracklet2.=" << &cseed[2]
3447 << "tracklet3.=" << &cseed[3]
3448 << "tracklet4.=" << &cseed[4]
3449 << "tracklet5.=" << &cseed[5]
3450 << "sumda=" << sumda
3451 << "chi2y=" << chi2y
3452 << "chi2z=" << chi2z
3453 << "likea=" << likea
3454 << "likechi2y=" << likechi2y
3455 << "likechi2z=" << likechi2z
3456 << "nclusters=" << nclusters
3457 << "likeN=" << likeN
3459 << "meanncls=" << meanNcls
3466 //____________________________________________________________________
3467 void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
3470 // Map seeding configurations to detector planes.
3473 // iconfig : configuration index
3474 // planes : member planes of this configuration. On input empty.
3477 // planes : contains the planes which are defining the configuration
3479 // Detailed description
3481 // Here is the list of seeding planes configurations together with
3482 // their topological classification:
3500 // The topologic quality is modeled as follows:
3501 // 1. The general model is define by the equation:
3502 // p(conf) = exp(-conf/2)
3503 // 2. According to the topologic classification, configurations from the same
3504 // class are assigned the agerage value over the model values.
3505 // 3. Quality values are normalized.
3507 // The topologic quality distribution as function of configuration is given below:
3509 // <img src="gif/topologicQA.gif">
3514 case 0: // 5432 TQ 0
3520 case 1: // 4321 TQ 0
3526 case 2: // 3210 TQ 0
3532 case 3: // 5321 TQ 1
3538 case 4: // 4210 TQ 1
3544 case 5: // 5431 TQ 1
3550 case 6: // 4320 TQ 1
3556 case 7: // 5430 TQ 2
3562 case 8: // 5210 TQ 2
3568 case 9: // 5421 TQ 3
3574 case 10: // 4310 TQ 3
3580 case 11: // 5410 TQ 4
3586 case 12: // 5420 TQ 5
3592 case 13: // 5320 TQ 5
3598 case 14: // 5310 TQ 5
3607 //____________________________________________________________________
3608 void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
3611 // Returns the extrapolation planes for a seeding configuration.
3614 // iconfig : configuration index
3615 // planes : planes which are not in this configuration. On input empty.
3618 // planes : contains the planes which are not in the configuration
3620 // Detailed description
3624 case 0: // 5432 TQ 0
3628 case 1: // 4321 TQ 0
3632 case 2: // 3210 TQ 0
3636 case 3: // 5321 TQ 1
3640 case 4: // 4210 TQ 1
3644 case 5: // 5431 TQ 1
3648 case 6: // 4320 TQ 1
3652 case 7: // 5430 TQ 2
3656 case 8: // 5210 TQ 2
3660 case 9: // 5421 TQ 3
3664 case 10: // 4310 TQ 3
3668 case 11: // 5410 TQ 4
3672 case 12: // 5420 TQ 5
3676 case 13: // 5320 TQ 5
3680 case 14: // 5310 TQ 5
3687 //____________________________________________________________________
3688 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3690 if(!fClusters) return NULL;
3691 Int_t ncls = fClusters->GetEntriesFast();
3692 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
3695 //____________________________________________________________________
3696 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3698 if(!fTracklets) return NULL;
3699 Int_t ntrklt = fTracklets->GetEntriesFast();
3700 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3703 //____________________________________________________________________
3704 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3706 if(!fTracks) return NULL;
3707 Int_t ntrk = fTracks->GetEntriesFast();
3708 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3713 // //_____________________________________________________________________________
3714 // Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3715 // , Int_t *outlist, Bool_t down)
3718 // // Sort eleements according occurancy
3719 // // The size of output array has is 2*n
3726 // Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3727 // Int_t *sindexF = new Int_t[2*n];
3728 // for (Int_t i = 0; i < n; i++) {
3732 // TMath::Sort(n,inlist,sindexS,down);
3734 // Int_t last = inlist[sindexS[0]];
3735 // Int_t val = last;
3737 // sindexF[0+n] = last;
3738 // Int_t countPos = 0;
3740 // // Find frequency
3741 // for (Int_t i = 1; i < n; i++) {
3742 // val = inlist[sindexS[i]];
3743 // if (last == val) {
3744 // sindexF[countPos]++;
3748 // sindexF[countPos+n] = val;
3749 // sindexF[countPos]++;
3753 // if (last == val) {
3757 // // Sort according frequency
3758 // TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3760 // for (Int_t i = 0; i < countPos; i++) {
3761 // outlist[2*i ] = sindexF[sindexS[i]+n];
3762 // outlist[2*i+1] = sindexF[sindexS[i]];
3765 // delete [] sindexS;
3766 // delete [] sindexF;
3773 //____________________________________________________________________
3774 void AliTRDtrackerV1::ResetSeedTB()
3776 // reset buffer for seeding time bin layers. If the time bin
3777 // layers are not allocated this function allocates them
3779 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3780 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3781 else fSeedTB[isl]->Clear();
3786 //_____________________________________________________________________________
3787 Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
3789 // Calculates normalized chi2 in y-direction
3790 // chi2 = Sum chi2 / n_tracklets
3792 Double_t chi2 = 0.; Int_t n = 0;
3793 for(Int_t ipl = kNPlanes; ipl--;){
3794 if(!tracklets[ipl].IsOK()) continue;
3795 chi2 += tracklets[ipl].GetChi2Y();
3798 return n ? chi2/n : 0.;
3801 //_____________________________________________________________________________
3802 Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
3804 // Calculates normalized chi2 in z-direction
3805 // chi2 = Sum chi2 / n_tracklets
3807 Double_t chi2 = 0; Int_t n = 0;
3808 for(Int_t ipl = kNPlanes; ipl--;){
3809 if(!tracklets[ipl].IsOK()) continue;
3810 chi2 += tracklets[ipl].GetChi2Z();
3813 return n ? chi2/n : 0.;
3816 //_____________________________________________________________________________
3817 Float_t AliTRDtrackerV1::GetChi2Phi(const AliTRDseedV1 *const tracklets) const
3819 // Calculates normalized chi2 for angular resolution
3820 // chi2 = Sum chi2 / n_tracklets
3822 Double_t chi2 = 0; Int_t n = 0;
3823 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3824 if(!tracklets[iLayer].IsOK()) continue;
3825 chi2 += tracklets[iLayer].GetChi2Phi();
3828 return n ? chi2/n: 0.;
3831 //____________________________________________________________________
3832 Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
3834 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3835 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3836 // are taken into account
3838 // Parameters: - Array of tracklets(AliTRDseedV1)
3840 // Output: - The reference x-position(Float_t)
3841 // Only kept for compatibility with the old code
3843 Int_t nDistances = 0;
3844 Float_t meanDistance = 0.;
3845 Int_t startIndex = 5;
3846 for(Int_t il =5; il > 0; il--){
3847 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3848 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3849 meanDistance += xdiff;
3852 if(tracklets[il].IsOK()) startIndex = il;
3854 if(tracklets[0].IsOK()) startIndex = 0;
3856 // We should normally never get here
3857 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3858 Int_t iok = 0, idiff = 0;
3859 // This attempt is worse and should be avoided:
3860 // check for two chambers which are OK and repeat this without taking the mean value
3861 // Strategy avoids a division by 0;
3862 for(Int_t il = 5; il >= 0; il--){
3863 if(tracklets[il].IsOK()){
3864 xpos[iok] = tracklets[il].GetX0();
3868 if(iok) idiff++; // to get the right difference;
3872 meanDistance = (xpos[0] - xpos[1])/idiff;
3875 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3880 meanDistance /= nDistances;
3882 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3885 //_____________________________________________________________________________
3886 Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
3888 // Track Fitter Function using the new class implementation of
3891 AliTRDtrackFitterRieman fitter;
3892 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3894 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3895 Double_t chi2 = fitter.Eval();
3896 // Update the tracklets
3897 Double_t cov[15]; Double_t x0;
3898 memset(cov, 0, sizeof(Double_t) * 15);
3899 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3900 x0 = tracklets[il].GetX0();
3901 tracklets[il].SetYref(0, fitter.GetYat(x0));
3902 tracklets[il].SetZref(0, fitter.GetZat(x0));
3903 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3904 tracklets[il].SetZref(1, fitter.GetDzDx());
3905 tracklets[il].SetC(fitter.GetCurvature());
3906 fitter.GetCovAt(x0, cov);
3907 tracklets[il].SetCovRef(cov);
3908 tracklets[il].SetChi2(chi2);
3913 //____________________________________________________________________
3914 void AliTRDtrackerV1::UnsetTrackletsTrack(const AliTRDtrackV1 * const track)
3916 // Remove tracklets from tracker list attached to "track"
3918 for(Int_t il(0); il<kNPlanes; il++){
3919 if((idx = track->GetTrackletIndex(il)) < 0) continue;
3920 delete (fTracklets->RemoveAt(idx));
3925 ///////////////////////////////////////////////////////
3927 // Resources of class AliTRDLeastSquare //
3929 ///////////////////////////////////////////////////////
3931 //_____________________________________________________________________________
3932 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
3934 // Constructor of the nested class AliTRDtrackFitterLeastSquare
3936 // Fast solving linear regresion in 2D
3938 // The data members have the following meaning
3949 // fCovarianceMatrix[0] : s2a
3950 // fCovarianceMatrix[1] : s2b
3951 // fCovarianceMatrix[2] : cov(ab)
3953 memset(fParams, 0, sizeof(Double_t) * 2);
3954 memset(fSums, 0, sizeof(Double_t) * 6);
3955 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3959 //_____________________________________________________________________________
3960 void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3962 // Adding Point to the fitter
3965 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3967 const Double_t &xpt = *x;
3968 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3970 fSums[1] += weight * xpt;
3971 fSums[2] += weight * y;
3972 fSums[3] += weight * xpt * y;
3973 fSums[4] += weight * xpt * xpt;
3974 fSums[5] += weight * y * y;
3977 //_____________________________________________________________________________
3978 void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3980 // Remove Point from the sample
3983 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3985 const Double_t &xpt = *x;
3987 fSums[1] -= weight * xpt;
3988 fSums[2] -= weight * y;
3989 fSums[3] -= weight * xpt * y;
3990 fSums[4] -= weight * xpt * xpt;
3991 fSums[5] -= weight * y * y;
3994 //_____________________________________________________________________________
3995 Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
3997 // Evaluation of the fit:
3998 // Calculation of the parameters
3999 // Calculation of the covariance matrix
4002 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
4003 if(TMath::Abs(det)<1.e-30) return kFALSE;
4005 // for(Int_t isum = 0; isum < 5; isum++)
4006 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
4007 // printf("denominator = %f\n", denominator);
4008 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
4009 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
4010 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
4012 // Covariance matrix
4013 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
4014 fCovarianceMatrix[0] = fSums[4] / den;
4015 fCovarianceMatrix[1] = fSums[0] / den;
4016 fCovarianceMatrix[2] = -fSums[1] / den;
4017 /* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
4018 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
4019 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
4026 //_____________________________________________________________________________
4027 Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
4029 // Returns the Function value of the fitted function at a given x-position
4031 return fParams[0] + fParams[1] * (*xpos);
4034 //_____________________________________________________________________________
4035 void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
4037 // Copies the values of the covariance matrix into the storage
4039 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
4042 //_____________________________________________________________________________
4043 void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
4047 memset(fParams, 0, sizeof(Double_t) * 2);
4048 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
4049 memset(fSums, 0, sizeof(Double_t) * 6);
4052 ///////////////////////////////////////////////////////
4054 // Resources of class AliTRDtrackFitterRieman //
4056 ///////////////////////////////////////////////////////
4058 //_____________________________________________________________________________
4059 AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
4065 fSysClusterError(0.)
4068 // Default constructor
4070 fZfitter = new AliTRDLeastSquare;
4071 fCovarPolY = new TMatrixD(3,3);
4072 fCovarPolZ = new TMatrixD(2,2);
4073 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
4074 memset(fParameters, 0, sizeof(Double_t) * 5);
4075 memset(fSumPolY, 0, sizeof(Double_t) * 5);
4076 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
4079 //_____________________________________________________________________________
4080 AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
4084 if(fZfitter) delete fZfitter;
4085 if(fCovarPolY) delete fCovarPolY;
4086 if(fCovarPolZ) delete fCovarPolZ;
4089 //_____________________________________________________________________________
4090 void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
4095 fTrackFitter->StoreData(kTRUE);
4096 fTrackFitter->ClearPoints();
4102 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
4103 memset(fParameters, 0, sizeof(Double_t) * 5);
4104 memset(fSumPolY, 0, sizeof(Double_t) * 5);
4105 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
4106 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
4107 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
4108 (*fCovarPolY)(irow, icol) = 0.;
4109 if(irow < 2 && icol < 2)
4110 (*fCovarPolZ)(irow, icol) = 0.;
4114 //_____________________________________________________________________________
4115 void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
4117 // Add tracklet into the fitter
4119 if(itr >= AliTRDgeometry::kNlayer) return;
4120 fTracklets[itr] = tracklet;
4123 //_____________________________________________________________________________
4124 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
4127 // 1. Apply linear transformation and store points in the fitter
4128 // 2. Evaluate the fit
4129 // 3. Check if the result of the fit in z-direction is reasonable
4131 // 3a. Fix the parameters 3 and 4 with the results of a simple least
4133 // 3b. Redo the fit with the fixed parameters
4134 // 4. Store fit results (parameters and errors)
4139 fXref = CalculateReferenceX();
4140 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
4141 if(!fTrackFitter->GetNpoints()) return 1e10;
4143 fTrackFitter->Eval();
4145 fParameters[3] = fTrackFitter->GetParameter(3);
4146 fParameters[4] = fTrackFitter->GetParameter(4);
4147 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
4148 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
4149 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
4150 fTrackFitter->Eval();
4151 fTrackFitter->ReleaseParameter(3);
4152 fTrackFitter->ReleaseParameter(4);
4153 fParameters[3] = fTrackFitter->GetParameter(3);
4154 fParameters[4] = fTrackFitter->GetParameter(4);
4156 // Update the Fit Parameters and the errors
4157 fParameters[0] = fTrackFitter->GetParameter(0);
4158 fParameters[1] = fTrackFitter->GetParameter(1);
4159 fParameters[2] = fTrackFitter->GetParameter(2);
4161 // Prepare Covariance estimation
4162 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
4163 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
4164 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
4165 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
4166 fCovarPolY->Invert();
4167 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
4168 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
4169 fCovarPolZ->Invert();
4170 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
4173 //_____________________________________________________________________________
4174 void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(const AliTRDseedV1 * const tracklet){
4176 // Does the transformations and updates the fitters
4177 // The following transformation is applied
4179 AliTRDcluster *cl = NULL;
4180 Double_t x, y, z, dx, t, w, we, yerr, zerr;
4182 if(!tracklet || !tracklet->IsOK()) return;
4183 Double_t tilt = tracklet->GetTilt();
4184 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
4185 if(!(cl = tracklet->GetClusters(itb))) continue;
4186 if(!cl->IsInChamber()) continue;
4187 if (!tracklet->IsUsable(itb)) continue;
4194 uvt[0] = 2. * x * t;
4196 uvt[2] = 2. * tilt * t;
4197 uvt[3] = 2. * tilt * dx * t;
4198 w = 2. * (y + tilt*z) * t;
4199 // error definition changes for the different calls
4201 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
4202 // Update sums for error calculation
4203 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
4205 zerr = 1./cl->GetSigmaZ2();
4206 for(Int_t ipol = 0; ipol < 5; ipol++){
4207 fSumPolY[ipol] += yerr;
4210 fSumPolZ[ipol] += zerr;
4214 fTrackFitter->AddPoint(uvt, w, we);
4215 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
4219 //_____________________________________________________________________________
4220 Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
4222 // Check whether z-results are acceptable
4223 // Definition: Distance between tracklet fit and track fit has to be
4224 // less then half a padlength
4225 // Point of comparision is at the anode wire
4227 Bool_t acceptablez = kTRUE;
4228 Double_t zref = 0.0;
4229 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
4230 if(!fTracklets[iLayer]->IsOK()) continue;
4231 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
4232 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
4233 acceptablez = kFALSE;
4238 //_____________________________________________________________________________
4239 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
4241 // Calculate y position out of the track parameters
4242 // y: R^2 = (x - x0)^2 + (y - y0)^2
4243 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
4244 // R = Sqrt() = 1/Curvature
4245 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
4248 Double_t disc = (x * fParameters[0] + fParameters[1]);
4249 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
4251 disc = TMath::Sqrt(disc);
4252 y = (1.0 - disc) / fParameters[0];
4257 //_____________________________________________________________________________
4258 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4260 // Return z position for a given x position
4261 // Simple linear function
4263 return fParameters[3] + fParameters[4] * (x - fXref);
4266 //_____________________________________________________________________________
4267 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4269 // Calculate dydx at a given radial position out of the track parameters
4270 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4271 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4272 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4273 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4274 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4276 Double_t x0 = -fParameters[1] / fParameters[0];
4277 Double_t curvature = GetCurvature();
4279 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4280 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4281 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4282 if (fParameters[0] < 0) yderiv *= -1.0;
4289 //_____________________________________________________________________________
4290 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4292 // Calculate track curvature
4295 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4296 if (curvature > 0.0)
4297 curvature = fParameters[0] / TMath::Sqrt(curvature);
4301 //_____________________________________________________________________________
4302 void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4304 // Error Definition according to gauss error propagation
4306 TMatrixD transform(3,3);
4307 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4308 transform(0,1) = transform(1,2) = x;
4309 transform(0,2) = x*x;
4310 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4311 covariance *= transform.T();
4312 cov[0] = covariance(0,0);
4313 TMatrixD transformZ(2,2);
4314 transformZ(0,0) = transformZ(1,1) = 1;
4315 transformZ(0,1) = x;
4316 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4317 covarZ *= transformZ.T();
4318 cov[1] = covarZ(0,0);
4322 //____________________________________________________________________
4323 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4325 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4326 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4327 // are taken into account
4329 // Parameters: - Array of tracklets(AliTRDseedV1)
4331 // Output: - The reference x-position(Float_t)
4333 Int_t nDistances = 0;
4334 Float_t meanDistance = 0.;
4335 Int_t startIndex = 5;
4336 for(Int_t il =5; il > 0; il--){
4337 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4338 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4339 meanDistance += xdiff;
4342 if(fTracklets[il]->IsOK()) startIndex = il;
4344 if(fTracklets[0]->IsOK()) startIndex = 0;
4346 // We should normally never get here
4347 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4348 Int_t iok = 0, idiff = 0;
4349 // This attempt is worse and should be avoided:
4350 // check for two chambers which are OK and repeat this without taking the mean value
4351 // Strategy avoids a division by 0;
4352 for(Int_t il = 5; il >= 0; il--){
4353 if(fTracklets[il]->IsOK()){
4354 xpos[iok] = fTracklets[il]->GetX0();
4358 if(iok) idiff++; // to get the right difference;
4362 meanDistance = (xpos[0] - xpos[1])/idiff;
4365 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4370 meanDistance /= nDistances;
4372 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());