1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
23 // Alex Bercuci <A.Bercuci@gsi.de> //
24 // Markus Fasel <M.Fasel@gsi.de> //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include <TDirectory.h>
30 #include <TLinearFitter.h>
32 #include <TClonesArray.h>
33 #include <TTreeStream.h>
34 #include <TGeoMatrix.h>
35 #include <TGeoManager.h>
38 #include "AliMathBase.h"
39 #include "AliESDEvent.h"
40 #include "AliGeomManager.h"
41 #include "AliRieman.h"
42 #include "AliTrackPointArray.h"
44 #include "AliTRDgeometry.h"
45 #include "AliTRDpadPlane.h"
46 #include "AliTRDcalibDB.h"
47 #include "AliTRDReconstructor.h"
48 #include "AliTRDCalibraFillHisto.h"
49 #include "AliTRDrecoParam.h"
51 #include "AliTRDcluster.h"
52 #include "AliTRDdigitsParam.h"
53 #include "AliTRDseedV1.h"
54 #include "AliTRDtrackV1.h"
55 #include "AliTRDtrackerV1.h"
56 #include "AliTRDtrackerDebug.h"
57 #include "AliTRDtrackingChamber.h"
58 #include "AliTRDchamberTimeBin.h"
60 ClassImp(AliTRDtrackerV1)
61 ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62 ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
64 const Float_t AliTRDtrackerV1::fgkMinClustersInTrack = 0.5; //
65 const Float_t AliTRDtrackerV1::fgkLabelFraction = 0.8; //
66 const Double_t AliTRDtrackerV1::fgkMaxChi2 = 12.0; //
67 const Double_t AliTRDtrackerV1::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
68 const Double_t AliTRDtrackerV1::fgkMaxStep = 2.0; // Maximal step size in propagation
69 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
70 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
71 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
72 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
74 const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
75 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
76 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
77 AliRieman* AliTRDtrackerV1::fgRieman = NULL;
78 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
79 TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
81 //____________________________________________________________________
82 AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
84 ,fkReconstructor(NULL)
92 // Default constructor.
95 SetReconstructor(rec); // initialize reconstructor
97 // initialize geometry
98 if(!AliGeomManager::GetGeometry()){
99 AliFatal("Could not get geometry.");
101 fGeom = new AliTRDgeometry();
102 fGeom->CreateClusterMatrixArray();
103 TGeoHMatrix *matrix = NULL;
104 Double_t loc[] = {0., 0., 0.};
105 Double_t glb[] = {0., 0., 0.};
106 for(Int_t ily=kNPlanes; ily--;){
108 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
110 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
111 fR[ily] = fgkX0[ily];
114 matrix->LocalToMaster(loc, glb);
115 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
118 // initialize cluster containers
119 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
122 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
123 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
124 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
127 //____________________________________________________________________
128 AliTRDtrackerV1::~AliTRDtrackerV1()
134 if(fgRieman) delete fgRieman; fgRieman = NULL;
135 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
136 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
137 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
138 if(fTracks) {fTracks->Delete(); delete fTracks;}
139 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
141 fClusters->Delete(); delete fClusters;
143 if(fGeom) delete fGeom;
146 //____________________________________________________________________
147 Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
150 // Steering stand alone tracking for full TRD detector
153 // esd : The ESD event. On output it contains
154 // the ESD tracks found in TRD.
157 // Number of tracks found in the TRD detector.
159 // Detailed description
160 // 1. Launch individual SM trackers.
161 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
164 if(!fkReconstructor->GetRecoParam() ){
165 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
169 //AliInfo("Start Track Finder ...");
171 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
172 // for(int ism=1; ism<2; ism++){
173 //AliInfo(Form("Processing supermodule %i ...", ism));
174 ntracks += Clusters2TracksSM(ism, esd);
176 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
181 //_____________________________________________________________________________
182 Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
184 //AliInfo(Form("Asking for tracklet %d", index));
186 // reset position of the point before using it
187 p.SetXYZ(0., 0., 0.);
188 AliTRDseedV1 *tracklet = GetTracklet(index);
189 if (!tracklet) return kFALSE;
191 // get detector for this tracklet
192 Int_t det = tracklet->GetDetector();
193 Int_t sec = fGeom->GetSector(det);
194 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
195 sinA = TMath::Sin(alpha),
196 cosA = TMath::Cos(alpha);
198 local[0] = tracklet->GetX();
199 local[1] = tracklet->GetY();
200 local[2] = tracklet->GetZ();
202 fGeom->RotateBack(det, local, global);
204 Double_t cov2D[3]; Float_t cov[6];
205 tracklet->GetCovAt(local[0], cov2D);
206 cov[0] = cov2D[0]*sinA*sinA;
207 cov[1] =-cov2D[0]*sinA*cosA;
208 cov[2] =-cov2D[1]*sinA;
209 cov[3] = cov2D[0]*cosA*cosA;
210 cov[4] = cov2D[1]*cosA;
212 // store the global position of the tracklet and its covariance matrix in the track point
213 p.SetXYZ(global[0],global[1],global[2], cov);
216 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
217 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
218 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
219 p.SetVolumeID(volid);
224 //____________________________________________________________________
225 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
227 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
228 return fgTiltedRieman;
231 //____________________________________________________________________
232 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
234 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
235 return fgTiltedRiemanConstrained;
238 //____________________________________________________________________
239 AliRieman* AliTRDtrackerV1::GetRiemanFitter()
241 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
245 //_____________________________________________________________________________
246 Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
248 // Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
249 // a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
250 // covariance, PID, etc.) are than used to update the corresponding ESD track.
251 // Each track seed is first propagated to the geometrical limit of the TRD detector.
252 // Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
253 // constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
254 // Otherwise the ESD track is left unchanged.
256 // The following steps are performed:
257 // 1. Selection of tracks based on the variance in the y-z plane.
258 // 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
259 // 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
260 // the following status bits:
261 // - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
262 // - AliESDtrack::kTRDStop - if the tracks fails propagation
263 // - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
264 // 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
265 // 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
268 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
269 if (!calibra) AliInfo("Could not get Calibra instance\n");
270 if(!fgNTimeBins) CookNTimeBins();
273 Int_t nFound = 0, // number of tracks found
274 nSeeds = 0, // total number of ESD seeds
275 nTRDseeds= 0, // number of seeds in the TRD acceptance
276 nTPCseeds= 0; // number of TPC seeds
277 Float_t foundMin = 20.0;
279 Float_t *quality = NULL;
281 nSeeds = event->GetNumberOfTracks();
282 // Sort tracks according to quality
283 // (covariance in the yz plane)
285 quality = new Float_t[nSeeds];
286 index = new Int_t[nSeeds];
287 for (Int_t iSeed = nSeeds; iSeed--;) {
288 AliESDtrack *seed = event->GetTrack(iSeed);
289 Double_t covariance[15];
290 seed->GetExternalCovariance(covariance);
291 quality[iSeed] = covariance[0] + covariance[2];
293 TMath::Sort(nSeeds, quality, index,kFALSE);
296 // Propagate all seeds
299 for (Int_t iSeed = 0; iSeed < nSeeds; iSeed++) {
301 // Get the seeds in sorted sequence
302 AliESDtrack *seed = event->GetTrack(index[iSeed]);
303 Float_t p4 = seed->GetC(seed->GetBz());
305 // Check the seed status
306 ULong_t status = seed->GetStatus();
307 if ((status & AliESDtrack::kTPCout) == 0) continue;
308 if ((status & AliESDtrack::kTRDout) != 0) continue;
310 // Propagate to the entrance in the TRD mother volume
311 new(&track) AliTRDtrackV1(*seed);
312 if(AliTRDgeometry::GetXtrdBeg() > (fgkMaxStep + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), fgkMaxStep)){
313 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
316 if(!AdjustSector(&track)){
317 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
320 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp) {
321 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
327 // store track status at TRD entrance
328 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
330 // prepare track and do propagation in the TRD
331 track.SetReconstructor(fkReconstructor);
332 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
333 expectedClr = FollowBackProlongation(track);
334 // check if track entered the TRD fiducial volume
335 if(track.GetTrackLow()){
336 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
339 // check if track was stopped in the TRD
341 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
347 // computes PID for track
349 // update calibration references using this track
350 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
351 // save calibration object
352 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
353 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
354 calibTrack->SetOwner();
355 seed->AddCalibObject(calibTrack);
358 if ((track.GetNumberOfClusters() > 15) && (track.GetNumberOfClusters() > 0.5*expectedClr)) {
359 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
360 track.UpdateESDtrack(seed);
364 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
366 // Make backup for back propagation
367 Int_t foundClr = track.GetNumberOfClusters();
368 if (foundClr >= foundMin) {
369 track.CookLabel(1. - fgkLabelFraction);
370 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
372 // Sign only gold tracks
373 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
374 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
376 Bool_t isGold = kFALSE;
379 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
380 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
386 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
387 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
388 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
393 if ((!isGold) && (track.GetBackupTrack())) {
394 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
395 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
402 // Propagation to the TOF
403 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
404 Int_t sm = track.GetSector();
405 // default value in case we have problems with the geometry.
406 Double_t xtof = 371.;
407 //Calculate radial position of the beginning of the TOF
408 //mother volume. In order to avoid mixing of the TRD
409 //and TOF modules some hard values are needed. This are:
410 //1. The path to the TOF module.
411 //2. The width of the TOF (29.05 cm)
412 //(with the help of Annalisa de Caro Mar-17-2009)
414 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
415 TGeoHMatrix *m = NULL;
416 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
418 if((m=gGeoManager->GetCurrentMatrix())){
419 m->LocalToMaster(loc, glob);
420 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
423 if(xtof > (fgkMaxStep + track.GetX()) && !PropagateToX(track, xtof, fgkMaxStep)){
424 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
427 if(!AdjustSector(&track)){
428 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
431 if(TMath::Abs(track.GetSnp()) > fgkMaxSnp){
432 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
435 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
436 // TODO obsolete - delete
437 seed->SetTRDQuality(track.StatusForTOF());
439 seed->SetTRDBudget(track.GetBudget(0));
441 if(index) delete [] index;
442 if(quality) delete [] quality;
444 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
445 AliInfo(Form("Number of tracks: TRDout[%d]", nFound));
447 // run stand alone tracking
448 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
454 //____________________________________________________________________
455 Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
458 // Refits tracks within the TRD. The ESD event is expected to contain seeds
459 // at the outer part of the TRD.
460 // The tracks are propagated to the innermost time bin
461 // of the TRD and the ESD event is updated
462 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
465 Int_t nseed = 0; // contor for loaded seeds
466 Int_t found = 0; // contor for updated TRD tracks
470 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
471 AliESDtrack *seed = event->GetTrack(itrack);
472 new(&track) AliTRDtrackV1(*seed);
474 if (track.GetX() < 270.0) {
475 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
479 // reject tracks which failed propagation in the TRD or
480 // are produced by the TRD stand alone tracker
481 ULong_t status = seed->GetStatus();
482 if(!(status & AliESDtrack::kTRDout)) continue;
483 if(!(status & AliESDtrack::kTRDin)) continue;
486 track.ResetCovariance(50.0);
488 // do the propagation and processing
489 Bool_t kUPDATE = kFALSE;
490 Double_t xTPC = 250.0;
491 if(FollowProlongation(track)){
493 if (PropagateToX(track, xTPC, fgkMaxStep)) { // -with update
494 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
499 // Update the friend track
500 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
501 TObject *o = NULL; Int_t ic = 0;
502 AliTRDtrackV1 *calibTrack = NULL;
503 while((o = seed->GetCalibObject(ic++))){
504 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
505 calibTrack->SetTrackHigh(track.GetTrackHigh());
510 // Prolongate to TPC without update
512 AliTRDtrackV1 tt(*seed);
513 if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
516 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
517 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
522 //____________________________________________________________________
523 Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
525 // Extrapolates the TRD track in the TPC direction.
528 // t : the TRD track which has to be extrapolated
531 // number of clusters attached to the track
533 // Detailed description
535 // Starting from current radial position of track <t> this function
536 // extrapolates the track through the 6 TRD layers. The following steps
537 // are being performed for each plane:
539 // a. get plane limits in the local x direction
540 // b. check crossing sectors
541 // c. check track inclination
542 // 2. search tracklet in the tracker list (see GetTracklet() for details)
543 // 3. evaluate material budget using the geo manager
544 // 4. propagate and update track using the tracklet information.
549 Bool_t kStoreIn = kTRUE;
550 Int_t nClustersExpected = 0;
551 for (Int_t iplane = kNPlanes; iplane--;) {
553 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
554 if(!tracklet) continue;
555 if(!tracklet->IsOK()){
556 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
559 Double_t x = tracklet->GetX();//GetX0();
560 // reject tracklets which are not considered for inward refit
561 if(x > t.GetX()+fgkMaxStep) continue;
563 // append tracklet to track
564 t.SetTracklet(tracklet, index);
566 if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
567 if (!AdjustSector(&t)) break;
569 // Start global position
573 // End global position
574 Double_t alpha = t.GetAlpha(), y, z;
575 if (!t.GetProlongation(x,y,z)) break;
577 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
578 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
581 Double_t length = TMath::Sqrt(
582 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
583 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
584 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
587 // Get material budget
589 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
590 Double_t xrho= param[0]*param[4];
591 Double_t xx0 = param[1]; // Get mean propagation parameters
593 // Propagate and update
594 t.PropagateTo(x, xx0, xrho);
595 if (!AdjustSector(&t)) break;
602 Double_t cov[3]; tracklet->GetCovAt(x, cov);
603 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
604 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
605 if (chi2 < 1e+10 && t.Update(p, cov, chi2)){
606 nClustersExpected += tracklet->GetN();
610 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1){
612 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
613 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
614 if(!tracklet) continue;
615 t.SetTracklet(tracklet, index);
618 if(fkReconstructor->IsDebugStreaming()){
619 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
620 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
621 AliTRDtrackV1 track(t);
623 cstreamer << "FollowProlongation"
624 << "EventNumber=" << eventNumber
625 << "ncl=" << nClustersExpected
626 << "track.=" << &track
630 return nClustersExpected;
634 //_____________________________________________________________________________
635 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
637 // Extrapolates/Build the TRD track in the TOF direction.
640 // t : the TRD track which has to be extrapolated
643 // number of clusters attached to the track
645 // Starting from current radial position of track <t> this function
646 // extrapolates the track through the 6 TRD layers. The following steps
647 // are being performed for each plane:
648 // 1. Propagate track to the entrance of the next chamber:
649 // - get chamber limits in the radial direction
650 // - check crossing sectors
651 // - check track inclination
652 // - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
653 // 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
654 // Kalman filter is needed and tracklets are already linked to the track this step is skipped.
655 // 3. Fit tracklet using the information from the Kalman filter.
656 // 4. Propagate and update track at reference radial position of the tracklet.
657 // 5. Register tracklet with the tracker and track; update pulls monitoring.
660 // 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:
661 // - AliTRDtrackV1::kProlongation : track prolongation failed
662 // - AliTRDtrackV1::kPropagation : track prolongation failed
663 // - AliTRDtrackV1::kAdjustSector : failed during sector crossing
664 // - AliTRDtrackV1::kSnp : too large bending
665 // - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
666 // - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
667 // - AliTRDtrackV1::kUnknown : anything which is not covered before
668 // 2. By default the status of the track before first TRD update is saved.
673 // Alexandru Bercuci <A.Bercuci@gsi.de>
677 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
678 AliTRDtrackingChamber *chamber = NULL;
680 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
681 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
683 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
684 // in case of stand alone tracking we store all the pointers to the tracklets in a temporary array
685 AliTRDseedV1 *tracklets[kNPlanes];
686 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
687 for(Int_t ip = 0; ip < kNPlanes; ip++){
688 tracklets[ip] = t.GetTracklet(ip);
691 Bool_t kStoreIn = kTRUE, kPropagateIn = kTRUE;
693 // Loop through the TRD layers
694 TGeoHMatrix *matrix = NULL;
696 for (Int_t ily=0, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
697 // rough estimate of the entry point
698 if (!t.GetProlongation(fR[ily], y, z)){
700 t.SetStatus(AliTRDtrackV1::kProlongation);
704 // find sector / stack / detector
706 // TODO cross check with y value !
707 stk = fGeom->GetStack(z, ily);
708 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
709 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
711 // check if supermodule/chamber is installed
712 if( !fGeom->GetSMstatus(sm) ||
714 fGeom->IsHole(ily, stk, sm) ||
716 // propagate to the default radial position
717 if(fR[ily] > (fgkMaxStep + t.GetX()) && !PropagateToX(t, fR[ily], fgkMaxStep)){
719 t.SetStatus(AliTRDtrackV1::kPropagation);
722 if(!AdjustSector(&t)){
724 t.SetStatus(AliTRDtrackV1::kAdjustSector);
727 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp){
729 t.SetStatus(AliTRDtrackV1::kSnp);
732 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
736 // retrieve rotation matrix for the current chamber
737 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
738 Double_t glb[] = {0., 0., 0.};
739 matrix->LocalToMaster(loc, glb);
741 // Propagate to the radial distance of the current layer
742 x = glb[0] - fgkMaxStep;
743 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)){
745 t.SetStatus(AliTRDtrackV1::kPropagation);
748 if(!AdjustSector(&t)){
750 t.SetStatus(AliTRDtrackV1::kAdjustSector);
753 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
755 t.SetStatus(AliTRDtrackV1::kSnp);
758 Bool_t doRecalculate = kFALSE;
759 if(sm != t.GetSector()){
761 doRecalculate = kTRUE;
763 if(stk != fGeom->GetStack(z, ily)){
764 stk = fGeom->GetStack(z, ily);
765 doRecalculate = kTRUE;
768 det = AliTRDgeometry::GetDetector(ily, stk, sm);
769 if(!(matrix = fGeom->GetClusterMatrix(det))){
770 t.SetStatus(AliTRDtrackV1::kGeometry, ily);
773 matrix->LocalToMaster(loc, glb);
774 x = glb[0] - fgkMaxStep;
777 // check if track is well inside fiducial volume
778 if (!t.GetProlongation(x+fgkMaxStep, y, z)) {
780 t.SetStatus(AliTRDtrackV1::kProlongation);
783 if(fGeom->IsOnBoundary(det, y, z, .5)){
784 t.SetStatus(AliTRDtrackV1::kBoundary, ily);
787 // mark track as entering the FIDUCIAL volume of TRD
793 ptrTracklet = tracklets[ily];
794 if(!ptrTracklet){ // BUILD TRACKLET
795 AliDebug(2, Form("Building tracklet ly[%d]", ily));
796 // check data in supermodule
797 if(!fTrSec[sm].GetNChambers()){
798 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
801 if(fTrSec[sm].GetX(ily) < 1.){
802 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
806 // check data in chamber
807 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
808 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
811 if(chamber->GetNClusters() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){
812 t.SetStatus(AliTRDtrackV1::kNoClusters, ily);
816 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
817 ptrTracklet->SetReconstructor(fkReconstructor);
818 ptrTracklet->SetKink(t.IsKink());
819 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
820 ptrTracklet->SetX0(glb[0]+driftLength);
821 if(!tracklet.Init(&t)){
823 t.SetStatus(AliTRDtrackV1::kTrackletInit);
826 if(!tracklet.AttachClusters(chamber, kTRUE)){
827 t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
829 AliTRDseedV1 trackletCp(*ptrTracklet);
830 UChar_t status(t.GetStatusTRD(ily));
831 (*cstreamer) << "FollowBackProlongation2"
832 <<"status=" << status
833 <<"tracklet.=" << &trackletCp
838 if(tracklet.GetN() < fgNTimeBins*fkReconstructor->GetRecoParam() ->GetFindableClusters()){
839 t.SetStatus(AliTRDtrackV1::kNoClustersTracklet, ily);
841 AliTRDseedV1 trackletCp(*ptrTracklet);
842 UChar_t status(t.GetStatusTRD(ily));
843 (*cstreamer) << "FollowBackProlongation2"
844 <<"status=" << status
845 <<"tracklet.=" << &trackletCp
850 ptrTracklet->UpdateUsed();
851 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
852 // propagate track to the radial position of the tracklet
853 ptrTracklet->UseClusters(); // TODO ? do we need this here ?
854 // fit tracklet no tilt correction
855 if(!ptrTracklet->Fit(kFALSE)){
856 t.SetStatus(AliTRDtrackV1::kNoFit, ily);
859 x = ptrTracklet->GetX(); //GetX0();
860 if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)) {
862 t.SetStatus(AliTRDtrackV1::kPropagation);
865 if(!AdjustSector(&t)) {
867 t.SetStatus(AliTRDtrackV1::kAdjustSector);
870 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
872 t.SetStatus(AliTRDtrackV1::kSnp);
877 kPropagateIn = kFALSE;
879 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
880 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
881 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
882 // update Kalman with the TRD measurement
883 if(chi2>1e+10){ // TODO
884 t.SetStatus(AliTRDtrackV1::kChi2, ily);
886 UChar_t status(t.GetStatusTRD());
887 AliTRDseedV1 trackletCp(*ptrTracklet);
888 AliTRDtrackV1 trackCp(t);
890 (*cstreamer) << "FollowBackProlongation1"
891 << "status=" << status
892 << "tracklet.=" << &trackletCp
893 << "track.=" << &trackCp
898 if(!t.Update(p, cov, chi2)) {
900 t.SetStatus(AliTRDtrackV1::kUpdate);
902 UChar_t status(t.GetStatusTRD());
903 AliTRDseedV1 trackletCp(*ptrTracklet);
904 AliTRDtrackV1 trackCp(t);
906 (*cstreamer) << "FollowBackProlongation1"
907 << "status=" << status
908 << "tracklet.=" << &trackletCp
909 << "track.=" << &trackCp
915 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
918 // load tracklet to the tracker
919 ptrTracklet->Update(&t);
920 ptrTracklet = SetTracklet(ptrTracklet);
921 t.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
922 n += ptrTracklet->GetN();
924 // Reset material budget if 2 consecutive gold
925 // if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
927 // Make backup of the track until is gold
928 // TO DO update quality check of the track.
929 // consider comparison with fTimeBinsRange
930 Float_t ratio0 = ptrTracklet->GetN() / Float_t(fgNTimeBins);
931 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
936 //(ratio0+ratio1 > 1.5) &&
937 (t.GetNCross() == 0) &&
938 (TMath::Abs(t.GetSnp()) < 0.85) &&
939 (t.GetNumberOfClusters() > 20)){
943 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
944 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
947 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
948 AliTRDtrackV1 track(t);
950 (*cstreamer) << "FollowBackProlongation0"
951 << "EventNumber=" << eventNumber
953 << "track.=" << &track
960 //_________________________________________________________________________
961 Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
963 // Fits a Riemann-circle to the given points without tilting pad correction.
964 // The fit is performed using an instance of the class AliRieman (equations
965 // and transformations see documentation of this class)
966 // Afterwards all the tracklets are Updated
968 // Parameters: - Array of tracklets (AliTRDseedV1)
969 // - Storage for the chi2 values (beginning with direction z)
970 // - Seeding configuration
971 // Output: - The curvature
973 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
975 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
976 Int_t *ppl = &allplanes[0];
982 for(Int_t il = 0; il < maxLayers; il++){
983 if(!tracklets[ppl[il]].IsOK()) continue;
984 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
987 // Set the reference position of the fit and calculate the chi2 values
988 memset(chi2, 0, sizeof(Double_t) * 2);
989 for(Int_t il = 0; il < maxLayers; il++){
990 // Reference positions
991 tracklets[ppl[il]].Init(fitter);
994 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
995 chi2[0] += tracklets[ppl[il]].GetChi2Y();
996 chi2[1] += tracklets[ppl[il]].GetChi2Z();
998 return fitter->GetC();
1001 //_________________________________________________________________________
1002 void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1005 // Performs a Riemann helix fit using the seedclusters as spacepoints
1006 // Afterwards the chi2 values are calculated and the seeds are updated
1008 // Parameters: - The four seedclusters
1009 // - The tracklet array (AliTRDseedV1)
1010 // - The seeding configuration
1015 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1017 for(Int_t i = 0; i < 4; i++){
1018 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1023 // Update the seed and calculated the chi2 value
1024 chi2[0] = 0; chi2[1] = 0;
1025 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1027 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1028 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1033 //_________________________________________________________________________
1034 Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1037 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1038 // assumed that the vertex position is set to 0.
1039 // This method is very usefull for high-pt particles
1040 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1041 // x0, y0: Center of the circle
1042 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1043 // zc: center of the pad row
1044 // Equation which has to be fitted (after transformation):
1045 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1047 // t = 1/(x^2 + y^2)
1049 // v = 2 * x * tan(phiT) * t
1050 // Parameters in the equation:
1051 // a = -1/y0, b = x0/y0, e = dz/dx
1053 // The Curvature is calculated by the following equation:
1054 // - curv = a/Sqrt(b^2 + 1) = 1/R
1055 // Parameters: - the 6 tracklets
1056 // - the Vertex constraint
1057 // Output: - the Chi2 value of the track
1062 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1063 fitter->StoreData(kTRUE);
1064 fitter->ClearPoints();
1065 AliTRDcluster *cl = NULL;
1067 Float_t x, y, z, w, t, error, tilt;
1070 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1071 if(!tracklets[ilr].IsOK()) continue;
1072 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1073 if(!tracklets[ilr].IsUsable(itb)) continue;
1074 cl = tracklets[ilr].GetClusters(itb);
1075 if(!cl->IsInChamber()) continue;
1079 tilt = tracklets[ilr].GetTilt();
1081 t = 1./(x * x + y * y);
1082 uvt[0] = 2. * x * t;
1083 uvt[1] = 2. * x * t * tilt ;
1084 w = 2. * (y + tilt * (z - zVertex)) * t;
1085 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
1086 fitter->AddPoint(uvt, w, error);
1092 // Calculate curvature
1093 Double_t a = fitter->GetParameter(0);
1094 Double_t b = fitter->GetParameter(1);
1095 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1097 Float_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1098 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
1099 tracklets[ip].SetC(curvature);
1101 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
1102 //Linear Model on z-direction
1103 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1104 Double_t slope = fitter->GetParameter(2);
1105 Double_t zref = slope * xref;
1106 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1107 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1108 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1109 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
1110 treeStreamer << "FitTiltedRiemanConstraint"
1111 << "EventNumber=" << eventNumber
1112 << "CandidateNumber=" << candidateNumber
1113 << "Curvature=" << curvature
1114 << "Chi2Track=" << chi2track
1115 << "Chi2Z=" << chi2Z
1122 //_________________________________________________________________________
1123 Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1126 // Performs a Riemann fit taking tilting pad correction into account
1127 // The equation of a Riemann circle, where the y position is substituted by the
1128 // measured y-position taking pad tilting into account, has to be transformed
1129 // into a 4-dimensional hyperplane equation
1130 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1131 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1132 // zc: center of the pad row
1133 // zt: z-position of the track
1134 // The z-position of the track is assumed to be linear dependent on the x-position
1135 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1136 // Transformation: u = 2 * x * t
1137 // v = 2 * tan(phiT) * t
1138 // w = 2 * tan(phiT) * (x - xref) * t
1139 // t = 1 / (x^2 + ymeas^2)
1140 // Parameters: a = -1/y0
1142 // c = (R^2 -x0^2 - y0^2)/y0
1145 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1146 // results from the simple riemann fit. Afterwards the fit is redone.
1147 // The curvature is calculated according to the formula:
1148 // curv = a/(1 + b^2 + c*a) = 1/R
1150 // Paramters: - Array of tracklets (connected to the track candidate)
1151 // - Flag selecting the error definition
1152 // Output: - Chi2 values of the track (in Parameter list)
1154 TLinearFitter *fitter = GetTiltedRiemanFitter();
1155 fitter->StoreData(kTRUE);
1156 fitter->ClearPoints();
1157 AliTRDLeastSquare zfitter;
1158 AliTRDcluster *cl = NULL;
1160 Double_t xref = CalculateReferenceX(tracklets);
1161 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1162 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1163 memset(sumPolY, 0, sizeof(Double_t) * 5);
1164 memset(sumPolZ, 0, sizeof(Double_t) * 3);
1166 // Containers for Least-square fitter
1167 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1168 if(!tracklets[ipl].IsOK()) continue;
1169 tilt = tracklets[ipl].GetTilt();
1170 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1171 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1172 if(!cl->IsInChamber()) continue;
1173 if (!tracklets[ipl].IsUsable(itb)) continue;
1180 uvt[0] = 2. * x * t;
1182 uvt[2] = 2. * tilt * t;
1183 uvt[3] = 2. * tilt * dx * t;
1184 w = 2. * (y + tilt*z) * t;
1185 // error definition changes for the different calls
1187 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
1188 fitter->AddPoint(uvt, w, we);
1189 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1190 // adding points for covariance matrix estimation
1191 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1193 errz = 1./cl->GetSigmaZ2();
1194 for(Int_t ipol = 0; ipol < 5; ipol++){
1195 sumPolY[ipol] += erry;
1198 sumPolZ[ipol] += errz;
1208 Double_t offset = fitter->GetParameter(3);
1209 Double_t slope = fitter->GetParameter(4);
1211 // Linear fitter - not possible to make boundaries
1212 // Do not accept non possible z and dzdx combinations
1213 Bool_t acceptablez = kTRUE;
1214 Double_t zref = 0.0;
1215 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1216 if(!tracklets[iLayer].IsOK()) continue;
1217 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
1218 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1219 acceptablez = kFALSE;
1222 Double_t dzmf = zfitter.GetFunctionParameter(1);
1223 Double_t zmf = zfitter.GetFunctionValue(&xref);
1224 fgTiltedRieman->FixParameter(3, zmf);
1225 fgTiltedRieman->FixParameter(4, dzmf);
1227 fitter->ReleaseParameter(3);
1228 fitter->ReleaseParameter(4);
1229 offset = fitter->GetParameter(3);
1230 slope = fitter->GetParameter(4);
1233 // Calculate Curvarture
1234 Double_t a = fitter->GetParameter(0);
1235 Double_t b = fitter->GetParameter(1);
1236 Double_t c = fitter->GetParameter(2);
1237 Double_t curvature = 1.0 + b*b - c*a;
1238 if (curvature > 0.0)
1239 curvature = a / TMath::Sqrt(curvature);
1241 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1243 // Prepare error calculation
1244 TMatrixD covarPolY(3,3);
1245 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1246 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1247 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1248 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1250 TMatrixD covarPolZ(2,2);
1251 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1252 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1255 // Update the tracklets
1256 Double_t x1, dy, dz;
1258 memset(cov, 0, sizeof(Double_t) * 15);
1259 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1261 x = tracklets[iLayer].GetX0();
1267 memset(cov, 0, sizeof(Double_t) * 3);
1268 TMatrixD transform(3,3);
1271 transform(0,2) = x*x;
1275 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1276 covariance *= transform.T();
1277 TMatrixD transformZ(2,2);
1278 transformZ(0,0) = transformZ(1,1) = 1;
1279 transformZ(0,1) = x;
1280 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1281 covarZ *= transformZ.T();
1282 // y: R^2 = (x - x0)^2 + (y - y0)^2
1283 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1284 // R = Sqrt() = 1/Curvature
1285 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1286 Double_t res = (x * a + b); // = (x - x0)/y0
1288 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1290 res = TMath::Sqrt(res);
1291 y = (1.0 - res) / a;
1293 cov[0] = covariance(0,0);
1294 cov[2] = covarZ(0,0);
1297 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1298 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1299 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1300 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1301 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1302 Double_t x0 = -b / a;
1303 if (-c * a + b * b + 1 > 0) {
1304 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
1305 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1306 if (a < 0) yderiv *= -1.0;
1310 z = offset + slope * (x - xref);
1312 tracklets[iLayer].SetYref(0, y);
1313 tracklets[iLayer].SetYref(1, dy);
1314 tracklets[iLayer].SetZref(0, z);
1315 tracklets[iLayer].SetZref(1, dz);
1316 tracklets[iLayer].SetC(curvature);
1317 tracklets[iLayer].SetCovRef(cov);
1318 tracklets[iLayer].SetChi2(chi2track);
1321 /* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1322 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1323 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1324 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1325 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1326 cstreamer << "FitTiltedRieman0"
1327 << "EventNumber=" << eventNumber
1328 << "CandidateNumber=" << candidateNumber
1330 << "Chi2Z=" << chi2z
1337 //____________________________________________________________________
1338 Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
1341 // Fit track with a staight line
1342 // Fills an AliTrackPoint array with np points
1343 // Function should be used to refit tracks when no magnetic field was on
1345 AliTRDLeastSquare yfitter, zfitter;
1346 AliTRDcluster *cl = NULL;
1348 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1350 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1351 if(!(tracklet = track->GetTracklet(ipl))) continue;
1352 if(!tracklet->IsOK()) continue;
1353 new(&work[ipl]) AliTRDseedV1(*tracklet);
1355 tracklets = &work[0];
1358 Double_t xref = CalculateReferenceX(tracklets);
1359 Double_t x, y, z, dx, ye, yr, tilt;
1360 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1361 if(!tracklets[ipl].IsOK()) continue;
1362 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1363 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1364 if (!tracklets[ipl].IsUsable(itb)) continue;
1368 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1372 Double_t z0 = zfitter.GetFunctionParameter(0);
1373 Double_t dzdx = zfitter.GetFunctionParameter(1);
1374 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1375 if(!tracklets[ipl].IsOK()) continue;
1376 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1377 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1378 if (!tracklets[ipl].IsUsable(itb)) continue;
1382 tilt = tracklets[ipl].GetTilt();
1384 yr = y + tilt*(z - z0 - dzdx*dx);
1385 // error definition changes for the different calls
1386 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1387 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1388 yfitter.AddPoint(&dx, yr, ye);
1392 Double_t y0 = yfitter.GetFunctionParameter(0);
1393 Double_t dydx = yfitter.GetFunctionParameter(1);
1394 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1396 //update track points array
1399 for(int ip=0; ip<np; ip++){
1400 points[ip].GetXYZ(xyz);
1401 xyz[1] = y0 + dydx * (xyz[0] - xref);
1402 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1403 points[ip].SetXYZ(xyz);
1410 //_________________________________________________________________________
1411 Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
1414 // Performs a Riemann fit taking tilting pad correction into account
1416 // Paramters: - Array of tracklets (connected to the track candidate)
1417 // - Flag selecting the error definition
1418 // Output: - Chi2 values of the track (in Parameter list)
1420 // The equations which has to be solved simultaneously are:
1422 // R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1423 // y^{*} = y - tg(h)(z - z_{t})
1424 // z_{t} = z_{0}+dzdx*(x-x_{r})
1426 // with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1427 // R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1428 // track in the x-z plane. Using the following transformations
1430 // t = 1 / (x^{2} + y^{2})
1432 // v = 2 * tan(h) * t
1433 // w = 2 * tan(h) * (x - x_{r}) * t
1435 // One gets the following linear equation
1437 // a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1439 // where the coefficients have the following meaning
1443 // c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1447 // The error calculation for the free term is thus
1449 // #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1452 // From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1455 // C = 1/R = a/(1 + b^{2} + c*a)
1459 // M.Ivanov <M.Ivanov@gsi.de>
1460 // A.Bercuci <A.Bercuci@gsi.de>
1461 // M.Fasel <M.Fasel@gsi.de>
1463 TLinearFitter *fitter = GetTiltedRiemanFitter();
1464 fitter->StoreData(kTRUE);
1465 fitter->ClearPoints();
1466 AliTRDLeastSquare zfitter;
1467 AliTRDcluster *cl = NULL;
1469 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
1471 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1472 if(!(tracklet = track->GetTracklet(ipl))) continue;
1473 if(!tracklet->IsOK()) continue;
1474 new(&work[ipl]) AliTRDseedV1(*tracklet);
1476 tracklets = &work[0];
1479 Double_t xref = CalculateReferenceX(tracklets);
1480 Double_t x, y, z, t, tilt, dx, w, we;
1483 // Containers for Least-square fitter
1484 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1485 if(!tracklets[ipl].IsOK()) continue;
1486 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
1487 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1488 if (!tracklets[ipl].IsUsable(itb)) continue;
1492 tilt = tracklets[ipl].GetTilt();
1496 uvt[0] = 2. * x * t;
1498 uvt[2] = 2. * tilt * t;
1499 uvt[3] = 2. * tilt * dx * t;
1500 w = 2. * (y + tilt*z) * t;
1501 // error definition changes for the different calls
1503 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
1504 fitter->AddPoint(uvt, w, we);
1505 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1509 if(fitter->Eval()) return 1.E10;
1511 Double_t z0 = fitter->GetParameter(3);
1512 Double_t dzdx = fitter->GetParameter(4);
1515 // Linear fitter - not possible to make boundaries
1516 // Do not accept non possible z and dzdx combinations
1517 Bool_t accept = kTRUE;
1518 Double_t zref = 0.0;
1519 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1520 if(!tracklets[iLayer].IsOK()) continue;
1521 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
1522 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1527 Double_t dzmf = zfitter.GetFunctionParameter(1);
1528 Double_t zmf = zfitter.GetFunctionValue(&xref);
1529 fitter->FixParameter(3, zmf);
1530 fitter->FixParameter(4, dzmf);
1532 fitter->ReleaseParameter(3);
1533 fitter->ReleaseParameter(4);
1534 z0 = fitter->GetParameter(3); // = zmf ?
1535 dzdx = fitter->GetParameter(4); // = dzmf ?
1538 // Calculate Curvature
1539 Double_t a = fitter->GetParameter(0);
1540 Double_t b = fitter->GetParameter(1);
1541 Double_t c = fitter->GetParameter(2);
1542 Double_t y0 = 1. / a;
1543 Double_t x0 = -b * y0;
1544 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1545 if(tmp<=0.) return 1.E10;
1546 Double_t radius = TMath::Sqrt(tmp);
1547 Double_t curvature = 1.0 + b*b - c*a;
1548 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
1550 // Calculate chi2 of the fit
1551 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
1553 // Update the tracklets
1555 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1556 x = tracklets[ip].GetX0();
1557 tmp = radius*radius-(x-x0)*(x-x0);
1558 if(tmp <= 0.) continue;
1559 tmp = TMath::Sqrt(tmp);
1561 // y: R^2 = (x - x0)^2 + (y - y0)^2
1562 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1563 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1564 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1565 tracklets[ip].SetYref(1, (x - x0) / tmp);
1566 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1567 tracklets[ip].SetZref(1, dzdx);
1568 tracklets[ip].SetC(curvature);
1569 tracklets[ip].SetChi2(chi2);
1572 //update track points array
1575 for(int ip=0; ip<np; ip++){
1576 points[ip].GetXYZ(xyz);
1577 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
1578 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1579 points[ip].SetXYZ(xyz);
1587 //____________________________________________________________________
1588 Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1590 // Kalman filter implementation for the TRD.
1591 // It returns the positions of the fit in the array "points"
1593 // Author : A.Bercuci@gsi.de
1595 // printf("Start track @ x[%f]\n", track->GetX());
1597 //prepare marker points along the track
1598 Int_t ip = np ? 0 : 1;
1600 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1601 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1604 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1607 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
1609 //Loop through the TRD planes
1610 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1611 // GET TRACKLET OR BUILT IT
1612 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1614 if(!(ptrTracklet = &tracklets[iplane])) continue;
1616 if(!(ptrTracklet = track->GetTracklet(iplane))){
1617 /*AliTRDtrackerV1 *tracker = NULL;
1618 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1619 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1620 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1624 if(!ptrTracklet->IsOK()) continue;
1626 Double_t x = ptrTracklet->GetX0();
1629 //don't do anything if next marker is after next update point.
1630 if((up?-1:1) * (points[ip].GetX() - x) - fgkMaxStep < 0) break;
1631 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1633 Double_t xyz[3]; // should also get the covariance
1635 track->Global2LocalPosition(xyz, track->GetAlpha());
1636 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1639 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1641 // Propagate closer to the next update point
1642 if(((up?-1:1) * (x - track->GetX()) + fgkMaxStep < 0) && !PropagateToX(*track, x + (up?-1:1)*fgkMaxStep, fgkMaxStep)) return -1.;
1644 if(!AdjustSector(track)) return -1;
1645 if(TMath::Abs(track->GetSnp()) > fgkMaxSnp) return -1;
1647 //load tracklet to the tracker and the track
1649 if((index = FindTracklet(ptrTracklet)) < 0){
1650 ptrTracklet = SetTracklet(&tracklet);
1651 index = fTracklets->GetEntriesFast()-1;
1653 track->SetTracklet(ptrTracklet, index);*/
1656 // register tracklet to track with tracklet creation !!
1657 // PropagateBack : loaded tracklet to the tracker and update index
1658 // RefitInward : update index
1659 // MakeTrack : loaded tracklet to the tracker and update index
1660 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1663 //Calculate the mean material budget along the path inside the chamber
1664 Double_t xyz0[3]; track->GetXYZ(xyz0);
1665 Double_t alpha = track->GetAlpha();
1666 Double_t xyz1[3], y, z;
1667 if(!track->GetProlongation(x, y, z)) return -1;
1668 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1669 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1671 if((xyz0[0] - xyz1[9] < 1e-3) && (xyz0[0] - xyz1[9] < 1e-3)) continue; // check wheter we are at the same global x position
1673 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1674 Double_t xrho = param[0]*param[4]; // density*length
1675 Double_t xx0 = param[1]; // radiation length
1677 //Propagate the track
1678 track->PropagateTo(x, xx0, xrho);
1679 if (!AdjustSector(track)) break;
1682 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1683 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1684 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
1685 if(chi2<1e+10) track->Update(p, cov, chi2);
1688 //Reset material budget if 2 consecutive gold
1689 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1690 } // end planes loop
1694 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1696 Double_t xyz[3]; // should also get the covariance
1698 track->Global2LocalPosition(xyz, track->GetAlpha());
1699 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1703 return track->GetChi2();
1706 //_________________________________________________________________________
1707 Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
1710 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1711 // A linear dependence on the x-value serves as a model.
1712 // The parameters are related to the tilted Riemann fit.
1713 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1714 // - the offset for the reference x
1716 // - the reference x position
1717 // Output: - The Chi2 value of the track in z-Direction
1719 Float_t chi2Z = 0, nLayers = 0;
1720 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
1721 if(!tracklets[iLayer].IsOK()) continue;
1722 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1723 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
1726 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1730 //_____________________________________________________________________________
1731 Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1734 // Starting from current X-position of track <t> this function
1735 // extrapolates the track up to radial position <xToGo>.
1736 // Returns 1 if track reaches the plane, and 0 otherwise
1739 const Double_t kEpsilon = 0.00001;
1741 // Current track X-position
1742 Double_t xpos = t.GetX();
1744 // Direction: inward or outward
1745 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
1747 while (((xToGo - xpos) * dir) > kEpsilon) {
1756 // The next step size
1757 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
1759 // Get the global position of the starting point
1762 // X-position after next step
1765 // Get local Y and Z at the X-position of the next step
1766 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
1768 // The global position of the end point of this prolongation step
1769 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1770 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1773 // Calculate the mean material budget between start and
1774 // end point of this prolongation step
1775 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
1777 // Propagate the track to the X-position after the next step
1778 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
1780 // Rotate the track if necessary
1783 // New track X-position
1793 //_____________________________________________________________________________
1794 Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) const
1797 // Reads AliTRDclusters from the file.
1798 // The names of the cluster tree and branches
1799 // should match the ones used in AliTRDclusterizer::WriteClusters()
1802 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1803 TObjArray *clusterArray = new TObjArray(nsize+1000);
1805 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1807 AliError("Can't get the branch !");
1810 branch->SetAddress(&clusterArray);
1813 Float_t nclusters = fkReconstructor->GetRecoParam()->GetNClusters();
1814 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
1815 array = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1816 array->SetOwner(kTRUE);
1819 // Loop through all entries in the tree
1820 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1823 AliTRDcluster *c = NULL;
1824 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1826 nbytes += clusterTree->GetEvent(iEntry);
1828 // Get the number of points in the detector
1829 Int_t nCluster = clusterArray->GetEntriesFast();
1830 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1831 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
1832 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1833 delete (clusterArray->RemoveAt(iCluster));
1837 delete clusterArray;
1842 //_____________________________________________________________________________
1843 Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1846 // Fills clusters into TRD tracking sectors
1849 if(!fkReconstructor->IsWritingClusters()){
1850 fClusters = AliTRDReconstructor::GetClusters();
1852 if (ReadClusters(fClusters, cTree)) {
1853 AliError("Problem with reading the clusters !");
1859 if(!fClusters || !fClusters->GetEntriesFast()){
1860 AliInfo("No TRD clusters");
1865 BuildTrackingContainers();
1867 //Int_t ncl = fClusters->GetEntriesFast();
1868 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1873 //_____________________________________________________________________________
1874 Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
1877 // Fills clusters into TRD tracking sectors
1878 // Function for use in the HLT
1880 if(!clusters || !clusters->GetEntriesFast()){
1881 AliInfo("No TRD clusters");
1885 fClusters = clusters;
1889 BuildTrackingContainers();
1891 //Int_t ncl = fClusters->GetEntriesFast();
1892 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1898 //____________________________________________________________________
1899 Int_t AliTRDtrackerV1::BuildTrackingContainers()
1901 // Building tracking containers for clusters
1903 Int_t nin =0, icl = fClusters->GetEntriesFast();
1905 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
1906 if(c->IsInChamber()) nin++;
1907 Int_t detector = c->GetDetector();
1908 Int_t sector = fGeom->GetSector(detector);
1909 Int_t stack = fGeom->GetStack(detector);
1910 Int_t layer = fGeom->GetLayer(detector);
1912 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, icl);
1915 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
1916 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
1917 if(!fTrSec[isector].GetNChambers()) continue;
1918 fTrSec[isector].Init(fkReconstructor, cal);
1926 //____________________________________________________________________
1927 void AliTRDtrackerV1::UnloadClusters()
1930 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1931 // If option "force" is also set the containers are also deleted. This is useful
1936 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
1939 fTracklets->Delete();
1940 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
1943 if(IsClustersOwner()) fClusters->Delete();
1945 // save clusters array in the reconstructor for further use.
1946 if(!fkReconstructor->IsWritingClusters()){
1947 AliTRDReconstructor::SetClusters(fClusters);
1948 SetClustersOwner(kFALSE);
1949 } else AliTRDReconstructor::SetClusters(NULL);
1952 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
1954 // Increment the Event Number
1955 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
1958 // //____________________________________________________________________
1959 // void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
1961 // const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
1962 // if(!track) return;
1964 // AliTRDseedV1 *tracklet = NULL;
1965 // for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
1966 // if(!(tracklet = track->GetTracklet(ily))) continue;
1967 // AliTRDcluster *c = NULL;
1968 // for(Int_t ic=AliTRDseed::kNclusters; ic--;){
1969 // if(!(c=tracklet->GetClusters(ic))) continue;
1976 //_____________________________________________________________________________
1977 Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
1980 // Rotates the track when necessary
1983 Double_t alpha = AliTRDgeometry::GetAlpha();
1984 Double_t y = track->GetY();
1985 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
1988 if (!track->Rotate( alpha)) {
1992 else if (y < -ymax) {
1993 if (!track->Rotate(-alpha)) {
2003 //____________________________________________________________________
2004 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
2006 // Find tracklet for TRD track <track>
2015 // Detailed description
2017 idx = track->GetTrackletIndex(p);
2018 AliTRDseedV1 *tracklet = (idx==0xffff) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
2023 //____________________________________________________________________
2024 AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
2026 // Add this tracklet to the list of tracklets stored in the tracker
2029 // - tracklet : pointer to the tracklet to be added to the list
2032 // - the index of the new tracklet in the tracker tracklets list
2034 // Detailed description
2035 // Build the tracklets list if it is not yet created (late initialization)
2036 // and adds the new tracklet to the list.
2039 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2040 fTracklets->SetOwner(kTRUE);
2042 Int_t nentries = fTracklets->GetEntriesFast();
2043 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
2046 //____________________________________________________________________
2047 void AliTRDtrackerV1::CookNTimeBins()
2049 // Initialize number of time bins
2052 // first look if set by hand
2053 AliDebug(2, Form("NTimeBins [%d] (set by user)", fgNTimeBins));
2054 } else if(fkReconstructor && fkReconstructor->HasDigitsParam()) {
2055 // second look into digits param to avoid DB query
2056 fgNTimeBins = fkReconstructor->GetDigitsParam()->GetNTimeBins();
2057 AliDebug(2, Form("NTimeBins [%d] (set from digits param)", fgNTimeBins));
2058 } else { // third query DB
2059 AliTRDcalibDB *trd(NULL);
2060 if((trd = AliTRDcalibDB::Instance())) {
2061 if((fgNTimeBins = trd->GetNumberOfTimeBinsDCS()) <= 0){
2062 AliError("Corrupted DCS Object in OCDB");
2064 AliDebug(2, Form("NTimeBins [%d] (set to default)", fgNTimeBins));
2065 } else AliDebug(2, Form("NTimeBins [%d] (set from DB)", fgNTimeBins));
2066 } else AliFatal("Could not get DB.");
2069 AliFatal("Could not get number of time bins.");
2073 //____________________________________________________________________
2074 AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
2076 // Add this track to the list of tracks stored in the tracker
2079 // - track : pointer to the track to be added to the list
2082 // - the pointer added
2084 // Detailed description
2085 // Build the tracks list if it is not yet created (late initialization)
2086 // and adds the new track to the list.
2089 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
2090 fTracks->SetOwner(kTRUE);
2092 Int_t nentries = fTracks->GetEntriesFast();
2093 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2098 //____________________________________________________________________
2099 Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
2102 // Steer tracking for one SM.
2105 // sector : Array of (SM) propagation layers containing clusters
2106 // esd : The current ESD event. On output it contains the also
2107 // the ESD (TRD) tracks found in this SM.
2110 // Number of tracks found in this TRD supermodule.
2112 // Detailed description
2114 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2115 // 2. Launch stack tracking.
2116 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2117 // 3. Pack results in the ESD event.
2120 // allocate space for esd tracks in this SM
2121 TClonesArray esdTrackList("AliESDtrack", 2*kMaxTracksStack);
2122 esdTrackList.SetOwner();
2125 Int_t nChambers = 0;
2126 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
2127 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
2128 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2130 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2131 if(!(chamber = stack[ilayer])) continue;
2132 if(chamber->GetNClusters() < fgNTimeBins * fkReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
2134 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
2136 if(nChambers < 4) continue;
2137 //AliInfo(Form("Doing stack %d", istack));
2138 nTracks += Clusters2TracksStack(stack, &esdTrackList);
2140 //AliInfo(Form("Found %d tracks in SM %d [%d]\n", nTracks, sector, esd->GetNumberOfTracks()));
2142 for(int itrack=0; itrack<nTracks; itrack++)
2143 esd->AddTrack((AliESDtrack*)esdTrackList[itrack]);
2145 // Reset Track and Candidate Number
2146 AliTRDtrackerDebug::SetCandidateNumber(0);
2147 AliTRDtrackerDebug::SetTrackNumber(0);
2151 //____________________________________________________________________
2152 Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
2155 // Make tracks in one TRD stack.
2158 // layer : Array of stack propagation layers containing clusters
2159 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2160 // On exit the tracks found in this stack are appended.
2163 // Number of tracks found in this stack.
2165 // Detailed description
2167 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2168 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2169 // See AliTRDtrackerV1::MakeSeeds() for more details.
2170 // 3. Arrange track candidates in decreasing order of their quality
2171 // 4. Classify tracks in 5 categories according to:
2172 // a) number of layers crossed
2174 // 5. Sign clusters by tracks in decreasing order of track quality
2175 // 6. Build AliTRDtrack out of seeding tracklets
2177 // 8. Build ESD track and register it to the output list
2180 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
2181 AliTRDtrackingChamber *chamber = NULL;
2182 AliTRDtrackingChamber **ci = NULL;
2183 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2184 Int_t pars[4]; // MakeSeeds parameters
2186 //Double_t alpha = AliTRDgeometry::GetAlpha();
2187 //Double_t shift = .5 * alpha;
2188 Int_t configs[kNConfigs];
2190 // Purge used clusters from the containers
2192 for(Int_t ic = kNPlanes; ic--; ci++){
2193 if(!(*ci)) continue;
2197 // Build initial seeding configurations
2198 Double_t quality = BuildSeedingConfigs(stack, configs);
2199 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2200 AliInfo(Form("Plane config %d %d %d Quality %f"
2201 , configs[0], configs[1], configs[2], quality));
2205 // Initialize contors
2206 Int_t ntracks, // number of TRD track candidates
2207 ntracks1, // number of registered TRD tracks/iter
2208 ntracks2 = 0; // number of all registered TRD tracks in stack
2212 Int_t ic = 0; ci = &stack[0];
2213 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2214 if(!(*ci)) return ntracks2;
2215 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
2218 // Loop over seeding configurations
2219 ntracks = 0; ntracks1 = 0;
2220 for (Int_t iconf = 0; iconf<3; iconf++) {
2221 pars[0] = configs[iconf];
2224 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
2225 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
2226 if(ntracks == kMaxTracksStack) break;
2228 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
2232 // Sort the seeds according to their quality
2233 Int_t sort[kMaxTracksStack];
2234 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
2236 // Initialize number of tracks so far and logic switches
2237 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2238 Bool_t signedTrack[kMaxTracksStack];
2239 Bool_t fakeTrack[kMaxTracksStack];
2240 for (Int_t i=0; i<ntracks; i++){
2241 signedTrack[i] = kFALSE;
2242 fakeTrack[i] = kFALSE;
2244 //AliInfo("Selecting track candidates ...");
2246 // Sieve clusters in decreasing order of track quality
2247 Double_t trackParams[7];
2248 // AliTRDseedV1 *lseed = NULL;
2249 Int_t jSieve = 0, candidates;
2251 //AliInfo(Form("\t\tITER = %i ", jSieve));
2253 // Check track candidates
2255 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
2256 Int_t trackIndex = sort[itrack];
2257 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
2260 // Calculate track parameters from tracklets seeds
2265 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2266 Int_t jseed = kNPlanes*trackIndex+jLayer;
2267 if(!sseed[jseed].IsOK()) continue;
2268 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
2269 // TODO here we get a sig fault which should never happen !
2270 sseed[jseed].UpdateUsed();
2271 ncl += sseed[jseed].GetN2();
2272 nused += sseed[jseed].GetNUsed();
2276 // Filter duplicated tracks
2278 //printf("Skip %d nused %d\n", trackIndex, nused);
2279 fakeTrack[trackIndex] = kTRUE;
2282 if (Float_t(nused)/ncl >= .25){
2283 //printf("Skip %d nused/ncl >= .25\n", trackIndex);
2284 fakeTrack[trackIndex] = kTRUE;
2289 Bool_t skip = kFALSE;
2292 if(nlayers < 6) {skip = kTRUE; break;}
2293 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2297 if(nlayers < findable){skip = kTRUE; break;}
2298 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2302 if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
2303 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2307 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2311 if (nlayers == 3){skip = kTRUE; break;}
2312 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2317 //printf("REJECTED : %d [%d] nlayers %d trackQuality = %e nused %d\n", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused);
2320 signedTrack[trackIndex] = kTRUE;
2322 // Build track parameters
2323 AliTRDseedV1 *lseed =&sseed[trackIndex*6];
2325 while(idx<3 && !lseed->IsOK()) {
2329 Double_t x = lseed->GetX0();// - 3.5;
2330 trackParams[0] = x; //NEW AB
2331 trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);
2332 trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x);
2333 trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
2334 trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
2335 trackParams[5] = lseed->GetC();
2336 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2337 trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift; // Supermodule*/
2339 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
2340 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
2342 AliTRDseedV1 *dseed[6];
2343 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
2345 //Int_t eventNrInFile = esd->GetEventNumberInFile();
2346 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2347 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2348 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2349 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2350 cstreamer << "Clusters2TracksStack"
2351 << "EventNumber=" << eventNumber
2352 << "TrackNumber=" << trackNumber
2353 << "CandidateNumber=" << candidateNumber
2354 << "Iter=" << fSieveSeeding
2355 << "Like=" << fTrackQuality[trackIndex]
2356 << "S0.=" << dseed[0]
2357 << "S1.=" << dseed[1]
2358 << "S2.=" << dseed[2]
2359 << "S3.=" << dseed[3]
2360 << "S4.=" << dseed[4]
2361 << "S5.=" << dseed[5]
2362 << "p0=" << trackParams[0]
2363 << "p1=" << trackParams[1]
2364 << "p2=" << trackParams[2]
2365 << "p3=" << trackParams[3]
2366 << "p4=" << trackParams[4]
2367 << "p5=" << trackParams[5]
2368 << "p6=" << trackParams[6]
2370 << "NLayers=" << nlayers
2371 << "Findable=" << findable
2372 << "NUsed=" << nused
2376 AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
2378 AliDebug(1, "Track building failed.");
2382 //AliInfo("End of MakeTrack()");
2383 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2384 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2385 esdTrack->SetLabel(track->GetLabel());
2386 track->UpdateESDtrack(esdTrack);
2387 // write ESD-friends if neccessary
2388 if (fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 0){
2389 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2390 calibTrack->SetOwner();
2391 esdTrack->AddCalibObject(calibTrack);
2394 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
2398 } while(jSieve<5 && candidates); // end track candidates sieve
2399 if(!ntracks1) break;
2401 // increment counters
2402 ntracks2 += ntracks1;
2404 if(fkReconstructor->IsHLT()) break;
2407 // Rebuild plane configurations and indices taking only unused clusters into account
2408 quality = BuildSeedingConfigs(stack, configs);
2409 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
2411 for(Int_t ip = 0; ip < kNPlanes; ip++){
2412 if(!(chamber = stack[ip])) continue;
2413 chamber->Build(fGeom, cal);//Indices(fSieveSeeding);
2416 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 10){
2417 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2419 } while(fSieveSeeding<10); // end stack clusters sieve
2423 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2428 //___________________________________________________________________
2429 Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
2432 // Assign probabilities to chambers according to their
2433 // capability of producing seeds.
2437 // layers : Array of stack propagation layers for all 6 chambers in one stack
2438 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2439 // for details) in the decreasing order of their seeding probabilities.
2443 // Return top configuration quality
2445 // Detailed description:
2447 // To each chamber seeding configuration (see GetSeedingConfig() for
2448 // the list of all configurations) one defines 2 quality factors:
2449 // - an apriori topological quality (see GetSeedingConfig() for details) and
2450 // - a data quality based on the uniformity of the distribution of
2451 // clusters over the x range (time bins population). See CookChamberQA() for details.
2452 // The overall chamber quality is given by the product of this 2 contributions.
2455 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
2456 AliTRDtrackingChamber *chamber = NULL;
2457 for(int iplane=0; iplane<kNPlanes; iplane++){
2458 if(!(chamber = stack[iplane])) continue;
2459 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2462 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2463 Int_t planes[] = {0, 0, 0, 0};
2464 for(int iconf=0; iconf<kNConfigs; iconf++){
2465 GetSeedingConfig(iconf, planes);
2466 tconfig[iconf] = fgTopologicQA[iconf];
2467 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2470 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2471 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2472 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2473 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2475 return tconfig[configs[0]];
2478 //____________________________________________________________________
2479 Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
2482 // Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2483 // either missed by TPC prolongation or conversions inside the TRD volume.
2484 // For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
2487 // layers : Array of stack propagation layers containing clusters
2488 // sseed : Array of empty tracklet seeds. On exit they are filled.
2489 // ipar : Control parameters:
2490 // ipar[0] -> seeding chambers configuration
2491 // ipar[1] -> stack index
2492 // ipar[2] -> number of track candidates found so far
2495 // Number of tracks candidates found.
2497 // The following steps are performed:
2498 // 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2499 // radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2500 // is described in AliTRDtrackerV1::Clusters2TracksStack().
2501 // 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2502 // - for each seeding cluster in the lower seeding layer find
2503 // - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2504 // is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2505 // - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2507 // - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2508 // seeding clusters.
2509 // The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2510 // and AliTRDchamberTimeBin::GetClusters().
2511 // 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2512 // performed at this level
2513 // 4. Initialize seeding tracklets in the seeding chambers.
2514 // 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2515 // 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2516 // AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2517 // 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2518 // 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2519 // approximation of the track.
2520 // 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2521 // checked against the Riemann fit:
2522 // - position resolution in y
2523 // - angular resolution in the bending plane
2524 // - likelihood of the number of clusters attached to the tracklet
2525 // 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2526 // - Initialization of extrapolation tracklets with the fit parameters
2527 // - Attach clusters to extrapolated tracklets
2528 // - Helix fit of tracklets
2529 // 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2530 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
2531 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2532 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2533 // 14. Cooking labels for tracklets. Should be done only for MC
2534 // 15. Register seeds.
2537 // Marian Ivanov <M.Ivanov@gsi.de>
2538 // Alexandru Bercuci <A.Bercuci@gsi.de>
2539 // Markus Fasel <M.Fasel@gsi.de>
2541 AliTRDtrackingChamber *chamber = NULL;
2542 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
2543 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
2544 Int_t ncl, mcl; // working variable for looping over clusters
2545 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2547 // chi2[0] = tracklet chi2 on the Z direction
2548 // chi2[1] = tracklet chi2 on the R direction
2551 // this should be data member of AliTRDtrack TODO
2552 Double_t seedQuality[kMaxTracksStack];
2554 // unpack control parameters
2555 Int_t config = ipar[0];
2556 Int_t ntracks = ipar[1];
2557 Int_t istack = ipar[2];
2558 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
2559 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
2562 // Init chambers geometry
2563 Double_t hL[kNPlanes]; // Tilting angle
2564 Float_t padlength[kNPlanes]; // pad lenghts
2565 Float_t padwidth[kNPlanes]; // pad widths
2566 AliTRDpadPlane *pp = NULL;
2567 for(int iplane=0; iplane<kNPlanes; iplane++){
2568 pp = fGeom->GetPadPlane(iplane, istack);
2569 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
2570 padlength[iplane] = pp->GetLengthIPad();
2571 padwidth[iplane] = pp->GetWidthIPad();
2574 // Init anode wire position for chambers
2575 Double_t x0[kNPlanes], // anode wire position
2576 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
2577 TGeoHMatrix *matrix = NULL;
2578 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2579 Double_t glb[] = {0., 0., 0.};
2580 AliTRDtrackingChamber **cIter = &stack[0];
2581 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
2582 if(!(*cIter)) continue;
2583 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
2585 x0[iLayer] = fgkX0[iLayer];
2587 matrix->LocalToMaster(loc, glb);
2588 x0[iLayer] = glb[0];
2591 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
2593 // Build seeding layers
2596 for(int isl=0; isl<kNSeedPlanes; isl++){
2597 if(!(chamber = stack[planes[isl]])) continue;
2598 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
2601 if(nlayers < kNSeedPlanes) return ntracks;
2604 // Start finding seeds
2605 Double_t cond0[4], cond1[4], cond2[4];
2607 while((c[3] = (*fSeedTB[3])[icl++])){
2609 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2610 fSeedTB[0]->GetClusters(cond0, index, ncl);
2611 //printf("Found c[3] candidates 0 %d\n", ncl);
2614 c[0] = (*fSeedTB[0])[index[jcl++]];
2616 Double_t dx = c[3]->GetX() - c[0]->GetX();
2617 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2618 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2619 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
2620 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
2621 //printf("Found c[0] candidates 1 %d\n", mcl);
2625 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2627 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
2628 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2629 //printf("Found c[1] candidate 2 %p\n", c[2]);
2632 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].",
2633 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2634 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2635 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2636 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
2638 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
2642 AliTRDseedV1 *tseed = &cseed[0];
2644 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2645 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
2646 tseed->SetDetector(det);
2647 tseed->SetTilt(hL[iLayer]);
2648 tseed->SetPadLength(padlength[iLayer]);
2649 tseed->SetPadWidth(padwidth[iLayer]);
2650 tseed->SetReconstructor(fkReconstructor);
2651 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
2652 tseed->Init(GetRiemanFitter());
2653 tseed->SetStandAlone(kTRUE);
2656 Bool_t isFake = kFALSE;
2657 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2658 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2659 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2660 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2663 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2665 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2666 Int_t ll = c[3]->GetLabel(0);
2667 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2668 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2669 AliRieman *rim = GetRiemanFitter();
2670 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2672 <<"EventNumber=" << eventNumber
2673 <<"CandidateNumber=" << candidateNumber
2674 <<"isFake=" << isFake
2675 <<"config=" << config
2677 <<"chi2z=" << chi2[0]
2678 <<"chi2y=" << chi2[1]
2679 <<"Y2exp=" << cond2[0]
2680 <<"Z2exp=" << cond2[1]
2681 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2682 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2683 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2684 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2685 <<"yref0=" << yref[0]
2686 <<"yref1=" << yref[1]
2687 <<"yref2=" << yref[2]
2688 <<"yref3=" << yref[3]
2693 <<"Seed0.=" << &cseed[planes[0]]
2694 <<"Seed1.=" << &cseed[planes[1]]
2695 <<"Seed2.=" << &cseed[planes[2]]
2696 <<"Seed3.=" << &cseed[planes[3]]
2697 <<"RiemanFitter.=" << rim
2700 if(chi2[0] > fkReconstructor->GetRecoParam() ->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
2701 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
2702 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2705 if(chi2[1] > fkReconstructor->GetRecoParam() ->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
2706 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
2707 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2710 //AliInfo("Passed chi2 filter.");
2712 // try attaching clusters to tracklets
2714 AliTRDcluster *cl = NULL;
2715 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2716 Int_t jLayer = planes[iLayer];
2717 Int_t nNotInChamber = 0;
2718 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
2719 if(/*fkReconstructor->IsHLT()*/kFALSE){
2720 cseed[jLayer].UpdateUsed();
2721 if(!cseed[jLayer].IsOK()) continue;
2723 cseed[jLayer].Fit();
2724 cseed[jLayer].UpdateUsed();
2725 cseed[jLayer].ResetClusterIter();
2726 while((cl = cseed[jLayer].NextCluster())){
2727 if(!cl->IsInChamber()) nNotInChamber++;
2729 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2730 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
2735 if(mlayers < kNSeedPlanes){
2736 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
2737 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2741 // temporary exit door for the HLT
2742 if(fkReconstructor->IsHLT()){
2743 // attach clusters to extrapolation chambers
2744 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2745 Int_t jLayer = planesExt[iLayer];
2746 if(!(chamber = stack[jLayer])) continue;
2747 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
2748 cseed[jLayer].Fit();
2750 fTrackQuality[ntracks] = 1.; // dummy value
2752 if(ntracks == kMaxTracksStack) return ntracks;
2758 // Update Seeds and calculate Likelihood
2759 // fit tracklets and cook likelihood
2760 FitTiltedRieman(&cseed[0], kTRUE);
2761 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2762 Int_t jLayer = planes[iLayer];
2763 cseed[jLayer].Fit(kTRUE);
2765 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
2767 if (TMath::Log(1.E-9 + like) < fkReconstructor->GetRecoParam() ->GetTrackLikelihood()){
2768 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2769 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2772 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2774 // book preliminary results
2775 seedQuality[ntracks] = like;
2776 fSeedLayer[ntracks] = config;/*sLayer;*/
2778 // attach clusters to the extrapolation seeds
2780 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2781 Int_t jLayer = planesExt[iLayer];
2782 if(!(chamber = stack[jLayer])) continue;
2784 // fit extrapolated seed
2785 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2786 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2787 AliTRDseedV1 pseed = cseed[jLayer];
2788 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2790 cseed[jLayer] = pseed;
2791 FitTiltedRieman(cseed, kTRUE);
2792 cseed[jLayer].Fit(kTRUE);
2796 // AliInfo("Extrapolation done.");
2797 // Debug Stream containing all the 6 tracklets
2798 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2799 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2800 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2801 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2802 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2803 cstreamer << "MakeSeeds1"
2804 << "EventNumber=" << eventNumber
2805 << "CandidateNumber=" << candidateNumber
2806 << "S0.=" << &cseed[0]
2807 << "S1.=" << &cseed[1]
2808 << "S2.=" << &cseed[2]
2809 << "S3.=" << &cseed[3]
2810 << "S4.=" << &cseed[4]
2811 << "S5.=" << &cseed[5]
2812 << "FitterT.=" << tiltedRieman
2816 if(fkReconstructor->GetRecoParam()->HasImproveTracklets()){
2817 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
2818 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer] = cseed[jLayer];
2820 if(ImproveSeedQuality(stack, cseed) < mlayers+elayers){
2821 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2822 AliDebug(3, "Filter on improve seeds.");
2825 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer] = bseed[jLayer];
2828 //AliInfo("Improve seed quality done.");
2830 // fit full track and cook likelihoods
2831 // Double_t curv = FitRieman(&cseed[0], chi2);
2832 // Double_t chi2ZF = chi2[0] / TMath::Max((mlayers - 3.), 1.);
2833 // Double_t chi2RF = chi2[1] / TMath::Max((mlayers - 3.), 1.);
2835 // do the final track fitting (Once with vertex constraint and once without vertex constraint)
2836 Double_t chi2Vals[3];
2837 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
2838 if(fkReconstructor->GetRecoParam()->IsVertexConstrained())
2839 chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ()); // Do Vertex Constrained fit if desired
2842 chi2Vals[2] = GetChi2Z(&cseed[0]) / TMath::Max((mlayers - 3.), 1.);
2843 // Chi2 definitions in testing stage
2844 //chi2Vals[2] = GetChi2ZTest(&cseed[0]);
2845 fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
2846 //AliInfo("Hyperplane fit done\n");
2848 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
2849 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2850 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2851 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2852 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2853 TLinearFitter *fitterT = GetTiltedRiemanFitter();
2855 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2856 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2858 cstreamer << "MakeSeeds2"
2859 << "EventNumber=" << eventNumber
2860 << "CandidateNumber=" << candidateNumber
2861 << "Chi2TR=" << chi2Vals[0]
2862 << "Chi2TC=" << chi2Vals[1]
2863 << "Nlayers=" << mlayers
2864 << "NClusters=" << ncls
2866 << "S0.=" << &cseed[0]
2867 << "S1.=" << &cseed[1]
2868 << "S2.=" << &cseed[2]
2869 << "S3.=" << &cseed[3]
2870 << "S4.=" << &cseed[4]
2871 << "S5.=" << &cseed[5]
2872 << "FitterT.=" << fitterT
2873 << "FitterTC.=" << fitterTC
2878 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2879 if(ntracks == kMaxTracksStack){
2880 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2891 //_____________________________________________________________________________
2892 AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const seeds, Double_t *params)
2895 // Build a TRD track out of tracklet candidates
2898 // seeds : array of tracklets
2899 // params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
2900 // [0] - radial position of the track at reference point
2901 // [1] - y position of the fit at [0]
2902 // [2] - z position of the fit at [0]
2903 // [3] - snp of the first tracklet
2904 // [4] - tgl of the first tracklet
2905 // [5] - curvature of the Riemann fit - 1/pt
2906 // [6] - sector rotation angle
2911 // Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
2912 // (diagonal with constant variance terms TODO - correct parameterization)
2914 // In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
2915 // offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
2916 // for details). Do also MC label calculation and PID if propagation successfully.
2919 Double_t alpha = AliTRDgeometry::GetAlpha();
2920 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
2923 c[ 0] = 0.2; // s^2_y
2924 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
2925 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
2926 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
2927 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[5]*params[5]*0.01; // s^2_1/pt
2929 AliTRDtrackV1 track(seeds, ¶ms[1], c, params[0], params[6]*alpha+shift);
2930 track.PropagateTo(params[0]-5.0);
2931 AliTRDseedV1 *ptrTracklet = NULL;
2933 // skip Kalman filter for HLT
2934 if(/*fkReconstructor->IsHLT()*/kFALSE){
2935 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
2936 track.UnsetTracklet(jLayer);
2937 ptrTracklet = &seeds[jLayer];
2938 if(!ptrTracklet->IsOK()) continue;
2939 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
2940 ptrTracklet = SetTracklet(ptrTracklet);
2941 ptrTracklet->UseClusters();
2942 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
2944 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
2945 ptrTrack->CookPID();
2946 ptrTrack->CookLabel(.9);
2947 ptrTrack->SetReconstructor(fkReconstructor);
2951 if(TMath::Abs(track.GetY())>1000)
2954 track.ResetCovariance(1);
2955 Int_t nc = TMath::Abs(FollowBackProlongation(track));
2956 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()){
2957 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2958 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2959 Double_t p[5]; // Track Params for the Debug Stream
2960 track.GetExternalParameters(params[0], p);
2961 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2963 << "EventNumber=" << eventNumber
2964 << "CandidateNumber=" << candidateNumber
2966 << "X=" << params[0]
2972 << "Yin=" << params[1]
2973 << "Zin=" << params[2]
2974 << "snpin=" << params[3]
2975 << "tndin=" << params[4]
2976 << "crvin=" << params[5]
2977 << "track.=" << &track
2980 if (nc < 30) return NULL;
2982 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
2983 ptrTrack->SetReconstructor(fkReconstructor);
2984 ptrTrack->CookLabel(.9);
2986 // computes PID for track
2987 ptrTrack->CookPID();
2988 // update calibration references using this track
2989 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
2991 AliInfo("Could not get Calibra instance\n");
2992 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(ptrTrack);
2998 //____________________________________________________________________
2999 Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed)
3002 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3005 // layers : Array of propagation layers for a stack/supermodule
3006 // cseed : Array of 6 seeding tracklets which has to be improved
3009 // cssed : Improved seeds
3011 // Detailed description
3013 // Iterative procedure in which new clusters are searched for each
3014 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3015 // can be maximized. If some optimization is found the old seeds are replaced.
3020 // make a local working copy
3021 AliTRDtrackingChamber *chamber = NULL;
3022 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3024 Float_t quality(0.),
3025 lQuality[] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
3027 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3028 bseed[jLayer] = cseed[jLayer];
3029 if(!bseed[jLayer].IsOK()) continue;
3031 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3032 quality += lQuality[jLayer];
3034 Float_t chi2 = FitTiltedRieman(bseed, kTRUE);
3036 for (Int_t iter = 0; iter < 4; iter++) {
3037 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
3039 // Try better cluster set
3040 Int_t nLayers(0); Float_t qualitynew(0.);
3042 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3043 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3044 Int_t bLayer = indexes[jLayer];
3045 bseed[bLayer].Reset("c");
3046 if(!(chamber = stack[bLayer])) continue;
3047 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
3048 bseed[bLayer].Fit(kTRUE);
3049 if(!bseed[bLayer].IsOK()) continue;
3051 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3052 qualitynew += lQuality[jLayer];
3054 if(rLayers > nLayers){
3055 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
3057 } else rLayers=nLayers;
3059 if(qualitynew >= quality){
3060 AliDebug(4, Form("Quality worsen in iter[%d].", iter));
3062 } else quality = qualitynew;
3064 // try improve track parameters
3065 AliTRDseedV1 tseed[AliTRDgeometry::kNlayer];
3066 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) tseed[jLayer]=bseed[jLayer];
3067 Float_t chi2new = FitTiltedRieman(tseed, kTRUE);
3069 AliDebug(4, Form("Chi2 worsen in iter[%d].", iter));
3071 } else chi2 = chi2new;
3073 // store better tracklets
3074 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) bseed[jLayer]=tseed[jLayer];
3077 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming()){
3078 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3079 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3080 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
3081 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3082 cstreamer << "ImproveSeedQuality"
3083 << "EventNumber=" << eventNumber
3084 << "CandidateNumber=" << candidateNumber
3085 << "Iteration=" << iter
3086 << "S0.=" << &bseed[0]
3087 << "S1.=" << &bseed[1]
3088 << "S2.=" << &bseed[2]
3089 << "S3.=" << &bseed[3]
3090 << "S4.=" << &bseed[4]
3091 << "S5.=" << &bseed[5]
3092 << "FitterT.=" << tiltedRieman
3096 // we are sure that at least 2 tracklets are OK !
3100 //_________________________________________________________________________
3101 Double_t AliTRDtrackerV1::CalculateTrackLikelihood(const AliTRDseedV1 *const tracklets, Double_t *chi2){
3103 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3104 // the track selection
3105 // The likelihood value containes:
3106 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3107 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3108 // For all Parameters an exponential dependency is used
3110 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3111 // - Array of chi2 values:
3112 // * Non-Constrained Tilted Riemann fit
3113 // * Vertex-Constrained Tilted Riemann fit
3114 // * z-Direction from Linear fit
3115 // Output: - The calculated track likelihood
3120 Double_t chi2phi = 0, nLayers = 0;
3121 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3122 if(!tracklets[iLayer].IsOK()) continue;
3123 chi2phi += tracklets[iLayer].GetChi2Phi();
3126 chi2phi /= Float_t (nLayers - 2.0);
3128 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14); // Chi2Z
3129 Double_t likeChi2TC = (fkReconstructor->GetRecoParam()->IsVertexConstrained()) ?
3130 TMath::Exp(-chi2[1] * 0.677) : 1; // Constrained Tilted Riemann
3131 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078); // Non-constrained Tilted Riemann
3132 Double_t likeChi2Phi= TMath::Exp(-chi2phi * 3.23);//3.23
3133 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2Phi;
3135 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3136 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3137 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3138 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3139 cstreamer << "CalculateTrackLikelihood0"
3140 << "EventNumber=" << eventNumber
3141 << "CandidateNumber=" << candidateNumber
3142 << "LikeChi2Z=" << likeChi2Z
3143 << "LikeChi2TR=" << likeChi2TR
3144 << "LikeChi2TC=" << likeChi2TC
3145 << "LikeChi2Phi=" << likeChi2Phi
3146 << "TrackLikelihood=" << trackLikelihood
3150 return trackLikelihood;
3153 //____________________________________________________________________
3154 Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
3157 // Calculate the probability of this track candidate.
3160 // cseeds : array of candidate tracklets
3161 // planes : array of seeding planes (see seeding configuration)
3162 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3167 // Detailed description
3169 // The track quality is estimated based on the following 4 criteria:
3170 // 1. precision of the rieman fit on the Y direction (likea)
3171 // 2. chi2 on the Y direction (likechi2y)
3172 // 3. chi2 on the Z direction (likechi2z)
3173 // 4. number of attached clusters compared to a reference value
3174 // (see AliTRDrecoParam::fkFindable) (likeN)
3176 // The distributions for each type of probabilities are given below as of
3177 // (date). They have to be checked to assure consistency of estimation.
3180 // ratio of the total number of clusters/track which are expected to be found by the tracker.
3181 const AliTRDrecoParam *fRecoPars = fkReconstructor->GetRecoParam();
3183 Double_t chi2y = GetChi2Y(&cseed[0]);
3184 Double_t chi2z = GetChi2Z(&cseed[0]);
3186 Float_t nclusters = 0.;
3187 Double_t sumda = 0.;
3188 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3189 Int_t jlayer = planes[ilayer];
3190 nclusters += cseed[jlayer].GetN2();
3191 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
3195 Double_t likea = TMath::Exp(-sumda * fRecoPars->GetPhiSlope());
3196 Double_t likechi2y = 0.0000000001;
3197 if (fkReconstructor->IsCosmic() || chi2y < fRecoPars->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fRecoPars->GetChi2YSlope());
3198 Double_t likechi2z = TMath::Exp(-chi2z * fRecoPars->GetChi2ZSlope());
3199 Double_t likeN = TMath::Exp(-(fRecoPars->GetNMeanClusters() - nclusters) / fRecoPars->GetNSigmaClusters());
3200 Double_t like = likea * likechi2y * likechi2z * likeN;
3202 if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()){
3203 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3204 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3205 Int_t nTracklets = 0; Float_t meanNcls = 0;
3206 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3207 if(!cseed[iseed].IsOK()) continue;
3209 meanNcls += cseed[iseed].GetN2();
3211 if(nTracklets) meanNcls /= nTracklets;
3212 // The Debug Stream contains the seed
3213 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
3214 cstreamer << "CookLikelihood"
3215 << "EventNumber=" << eventNumber
3216 << "CandidateNumber=" << candidateNumber
3217 << "tracklet0.=" << &cseed[0]
3218 << "tracklet1.=" << &cseed[1]
3219 << "tracklet2.=" << &cseed[2]
3220 << "tracklet3.=" << &cseed[3]
3221 << "tracklet4.=" << &cseed[4]
3222 << "tracklet5.=" << &cseed[5]
3223 << "sumda=" << sumda
3224 << "chi2y=" << chi2y
3225 << "chi2z=" << chi2z
3226 << "likea=" << likea
3227 << "likechi2y=" << likechi2y
3228 << "likechi2z=" << likechi2z
3229 << "nclusters=" << nclusters
3230 << "likeN=" << likeN
3232 << "meanncls=" << meanNcls
3239 //____________________________________________________________________
3240 void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
3243 // Map seeding configurations to detector planes.
3246 // iconfig : configuration index
3247 // planes : member planes of this configuration. On input empty.
3250 // planes : contains the planes which are defining the configuration
3252 // Detailed description
3254 // Here is the list of seeding planes configurations together with
3255 // their topological classification:
3273 // The topologic quality is modeled as follows:
3274 // 1. The general model is define by the equation:
3275 // p(conf) = exp(-conf/2)
3276 // 2. According to the topologic classification, configurations from the same
3277 // class are assigned the agerage value over the model values.
3278 // 3. Quality values are normalized.
3280 // The topologic quality distribution as function of configuration is given below:
3282 // <img src="gif/topologicQA.gif">
3287 case 0: // 5432 TQ 0
3293 case 1: // 4321 TQ 0
3299 case 2: // 3210 TQ 0
3305 case 3: // 5321 TQ 1
3311 case 4: // 4210 TQ 1
3317 case 5: // 5431 TQ 1
3323 case 6: // 4320 TQ 1
3329 case 7: // 5430 TQ 2
3335 case 8: // 5210 TQ 2
3341 case 9: // 5421 TQ 3
3347 case 10: // 4310 TQ 3
3353 case 11: // 5410 TQ 4
3359 case 12: // 5420 TQ 5
3365 case 13: // 5320 TQ 5
3371 case 14: // 5310 TQ 5
3380 //____________________________________________________________________
3381 void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
3384 // Returns the extrapolation planes for a seeding configuration.
3387 // iconfig : configuration index
3388 // planes : planes which are not in this configuration. On input empty.
3391 // planes : contains the planes which are not in the configuration
3393 // Detailed description
3397 case 0: // 5432 TQ 0
3401 case 1: // 4321 TQ 0
3405 case 2: // 3210 TQ 0
3409 case 3: // 5321 TQ 1
3413 case 4: // 4210 TQ 1
3417 case 5: // 5431 TQ 1
3421 case 6: // 4320 TQ 1
3425 case 7: // 5430 TQ 2
3429 case 8: // 5210 TQ 2
3433 case 9: // 5421 TQ 3
3437 case 10: // 4310 TQ 3
3441 case 11: // 5410 TQ 4
3445 case 12: // 5420 TQ 5
3449 case 13: // 5320 TQ 5
3453 case 14: // 5310 TQ 5
3460 //____________________________________________________________________
3461 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3463 Int_t ncls = fClusters->GetEntriesFast();
3464 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
3467 //____________________________________________________________________
3468 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3470 Int_t ntrklt = fTracklets->GetEntriesFast();
3471 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3474 //____________________________________________________________________
3475 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3477 Int_t ntrk = fTracks->GetEntriesFast();
3478 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3483 // //_____________________________________________________________________________
3484 // Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3485 // , Int_t *outlist, Bool_t down)
3488 // // Sort eleements according occurancy
3489 // // The size of output array has is 2*n
3496 // Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3497 // Int_t *sindexF = new Int_t[2*n];
3498 // for (Int_t i = 0; i < n; i++) {
3502 // TMath::Sort(n,inlist,sindexS,down);
3504 // Int_t last = inlist[sindexS[0]];
3505 // Int_t val = last;
3507 // sindexF[0+n] = last;
3508 // Int_t countPos = 0;
3510 // // Find frequency
3511 // for (Int_t i = 1; i < n; i++) {
3512 // val = inlist[sindexS[i]];
3513 // if (last == val) {
3514 // sindexF[countPos]++;
3518 // sindexF[countPos+n] = val;
3519 // sindexF[countPos]++;
3523 // if (last == val) {
3527 // // Sort according frequency
3528 // TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3530 // for (Int_t i = 0; i < countPos; i++) {
3531 // outlist[2*i ] = sindexF[sindexS[i]+n];
3532 // outlist[2*i+1] = sindexF[sindexS[i]];
3535 // delete [] sindexS;
3536 // delete [] sindexF;
3543 //____________________________________________________________________
3544 void AliTRDtrackerV1::ResetSeedTB()
3546 // reset buffer for seeding time bin layers. If the time bin
3547 // layers are not allocated this function allocates them
3549 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3550 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3551 else fSeedTB[isl]->Clear();
3556 //_____________________________________________________________________________
3557 Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
3559 // Calculates normalized chi2 in y-direction
3560 // chi2 = Sum chi2 / n_tracklets
3562 Double_t chi2 = 0.; Int_t n = 0;
3563 for(Int_t ipl = kNPlanes; ipl--;){
3564 if(!tracklets[ipl].IsOK()) continue;
3565 chi2 += tracklets[ipl].GetChi2Y();
3568 return n ? chi2/n : 0.;
3571 //_____________________________________________________________________________
3572 Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
3574 // Calculates normalized chi2 in z-direction
3575 // chi2 = Sum chi2 / n_tracklets
3577 Double_t chi2 = 0; Int_t n = 0;
3578 for(Int_t ipl = kNPlanes; ipl--;){
3579 if(!tracklets[ipl].IsOK()) continue;
3580 chi2 += tracklets[ipl].GetChi2Z();
3583 return n ? chi2/n : 0.;
3586 //____________________________________________________________________
3587 Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
3589 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3590 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3591 // are taken into account
3593 // Parameters: - Array of tracklets(AliTRDseedV1)
3595 // Output: - The reference x-position(Float_t)
3596 // Only kept for compatibility with the old code
3598 Int_t nDistances = 0;
3599 Float_t meanDistance = 0.;
3600 Int_t startIndex = 5;
3601 for(Int_t il =5; il > 0; il--){
3602 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3603 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3604 meanDistance += xdiff;
3607 if(tracklets[il].IsOK()) startIndex = il;
3609 if(tracklets[0].IsOK()) startIndex = 0;
3611 // We should normally never get here
3612 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3613 Int_t iok = 0, idiff = 0;
3614 // This attempt is worse and should be avoided:
3615 // check for two chambers which are OK and repeat this without taking the mean value
3616 // Strategy avoids a division by 0;
3617 for(Int_t il = 5; il >= 0; il--){
3618 if(tracklets[il].IsOK()){
3619 xpos[iok] = tracklets[il].GetX0();
3623 if(iok) idiff++; // to get the right difference;
3627 meanDistance = (xpos[0] - xpos[1])/idiff;
3630 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3635 meanDistance /= nDistances;
3637 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3640 //_____________________________________________________________________________
3641 Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
3643 // Track Fitter Function using the new class implementation of
3646 AliTRDtrackFitterRieman fitter;
3647 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3649 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3650 Double_t chi2 = fitter.Eval();
3651 // Update the tracklets
3652 Double_t cov[15]; Double_t x0;
3653 memset(cov, 0, sizeof(Double_t) * 15);
3654 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3655 x0 = tracklets[il].GetX0();
3656 tracklets[il].SetYref(0, fitter.GetYat(x0));
3657 tracklets[il].SetZref(0, fitter.GetZat(x0));
3658 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3659 tracklets[il].SetZref(1, fitter.GetDzDx());
3660 tracklets[il].SetC(fitter.GetCurvature());
3661 fitter.GetCovAt(x0, cov);
3662 tracklets[il].SetCovRef(cov);
3663 tracklets[il].SetChi2(chi2);
3668 ///////////////////////////////////////////////////////
3670 // Resources of class AliTRDLeastSquare //
3672 ///////////////////////////////////////////////////////
3674 //_____________________________________________________________________________
3675 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
3677 // Constructor of the nested class AliTRDtrackFitterLeastSquare
3679 // Fast solving linear regresion in 2D
3681 // The data members have the following meaning
3692 // fCovarianceMatrix[0] : s2a
3693 // fCovarianceMatrix[1] : s2b
3694 // fCovarianceMatrix[2] : cov(ab)
3696 memset(fParams, 0, sizeof(Double_t) * 2);
3697 memset(fSums, 0, sizeof(Double_t) * 6);
3698 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3702 //_____________________________________________________________________________
3703 void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3705 // Adding Point to the fitter
3708 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3710 const Double_t &xpt = *x;
3711 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3713 fSums[1] += weight * xpt;
3714 fSums[2] += weight * y;
3715 fSums[3] += weight * xpt * y;
3716 fSums[4] += weight * xpt * xpt;
3717 fSums[5] += weight * y * y;
3720 //_____________________________________________________________________________
3721 void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
3723 // Remove Point from the sample
3726 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3728 const Double_t &xpt = *x;
3730 fSums[1] -= weight * xpt;
3731 fSums[2] -= weight * y;
3732 fSums[3] -= weight * xpt * y;
3733 fSums[4] -= weight * xpt * xpt;
3734 fSums[5] -= weight * y * y;
3737 //_____________________________________________________________________________
3738 Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
3740 // Evaluation of the fit:
3741 // Calculation of the parameters
3742 // Calculation of the covariance matrix
3745 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
3746 if(det==0) return kFALSE;
3748 // for(Int_t isum = 0; isum < 5; isum++)
3749 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3750 // printf("denominator = %f\n", denominator);
3751 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
3752 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
3753 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3755 // Covariance matrix
3756 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
3757 fCovarianceMatrix[0] = fSums[4] / den;
3758 fCovarianceMatrix[1] = fSums[0] / den;
3759 fCovarianceMatrix[2] = -fSums[1] / den;
3760 /* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
3761 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
3762 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
3769 //_____________________________________________________________________________
3770 Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
3772 // Returns the Function value of the fitted function at a given x-position
3774 return fParams[0] + fParams[1] * (*xpos);
3777 //_____________________________________________________________________________
3778 void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
3780 // Copies the values of the covariance matrix into the storage
3782 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
3785 //_____________________________________________________________________________
3786 void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
3790 memset(fParams, 0, sizeof(Double_t) * 2);
3791 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3792 memset(fSums, 0, sizeof(Double_t) * 6);
3795 ///////////////////////////////////////////////////////
3797 // Resources of class AliTRDtrackFitterRieman //
3799 ///////////////////////////////////////////////////////
3801 //_____________________________________________________________________________
3802 AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
3808 fSysClusterError(0.)
3811 // Default constructor
3813 fZfitter = new AliTRDLeastSquare;
3814 fCovarPolY = new TMatrixD(3,3);
3815 fCovarPolZ = new TMatrixD(2,2);
3816 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
3817 memset(fParameters, 0, sizeof(Double_t) * 5);
3818 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3819 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3822 //_____________________________________________________________________________
3823 AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
3827 if(fZfitter) delete fZfitter;
3828 if(fCovarPolY) delete fCovarPolY;
3829 if(fCovarPolZ) delete fCovarPolZ;
3832 //_____________________________________________________________________________
3833 void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
3838 fTrackFitter->StoreData(kTRUE);
3839 fTrackFitter->ClearPoints();
3845 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
3846 memset(fParameters, 0, sizeof(Double_t) * 5);
3847 memset(fSumPolY, 0, sizeof(Double_t) * 5);
3848 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
3849 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
3850 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
3851 (*fCovarPolY)(irow, icol) = 0.;
3852 if(irow < 2 && icol < 2)
3853 (*fCovarPolZ)(irow, icol) = 0.;
3857 //_____________________________________________________________________________
3858 void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
3860 // Add tracklet into the fitter
3862 if(itr >= AliTRDgeometry::kNlayer) return;
3863 fTracklets[itr] = tracklet;
3866 //_____________________________________________________________________________
3867 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
3870 // 1. Apply linear transformation and store points in the fitter
3871 // 2. Evaluate the fit
3872 // 3. Check if the result of the fit in z-direction is reasonable
3874 // 3a. Fix the parameters 3 and 4 with the results of a simple least
3876 // 3b. Redo the fit with the fixed parameters
3877 // 4. Store fit results (parameters and errors)
3882 fXref = CalculateReferenceX();
3883 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
3884 if(!fTrackFitter->GetNpoints()) return 1e10;
3886 fTrackFitter->Eval();
3888 fParameters[3] = fTrackFitter->GetParameter(3);
3889 fParameters[4] = fTrackFitter->GetParameter(4);
3890 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
3891 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
3892 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
3893 fTrackFitter->Eval();
3894 fTrackFitter->ReleaseParameter(3);
3895 fTrackFitter->ReleaseParameter(4);
3896 fParameters[3] = fTrackFitter->GetParameter(3);
3897 fParameters[4] = fTrackFitter->GetParameter(4);
3899 // Update the Fit Parameters and the errors
3900 fParameters[0] = fTrackFitter->GetParameter(0);
3901 fParameters[1] = fTrackFitter->GetParameter(1);
3902 fParameters[2] = fTrackFitter->GetParameter(2);
3904 // Prepare Covariance estimation
3905 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
3906 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
3907 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
3908 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
3909 fCovarPolY->Invert();
3910 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
3911 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
3912 fCovarPolZ->Invert();
3913 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
3916 //_____________________________________________________________________________
3917 void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(AliTRDseedV1 * const tracklet){
3919 // Does the transformations and updates the fitters
3920 // The following transformation is applied
3922 AliTRDcluster *cl = NULL;
3923 Double_t x, y, z, dx, t, w, we, yerr, zerr;
3925 if(!tracklet || !tracklet->IsOK()) return;
3926 Double_t tilt = tracklet->GetTilt();
3927 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
3928 if(!(cl = tracklet->GetClusters(itb))) continue;
3929 if(!cl->IsInChamber()) continue;
3930 if (!tracklet->IsUsable(itb)) continue;
3937 uvt[0] = 2. * x * t;
3939 uvt[2] = 2. * tilt * t;
3940 uvt[3] = 2. * tilt * dx * t;
3941 w = 2. * (y + tilt*z) * t;
3942 // error definition changes for the different calls
3944 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
3945 // Update sums for error calculation
3946 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
3948 zerr = 1./cl->GetSigmaZ2();
3949 for(Int_t ipol = 0; ipol < 5; ipol++){
3950 fSumPolY[ipol] += yerr;
3953 fSumPolZ[ipol] += zerr;
3957 fTrackFitter->AddPoint(uvt, w, we);
3958 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
3962 //_____________________________________________________________________________
3963 Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
3965 // Check whether z-results are acceptable
3966 // Definition: Distance between tracklet fit and track fit has to be
3967 // less then half a padlength
3968 // Point of comparision is at the anode wire
3970 Bool_t acceptablez = kTRUE;
3971 Double_t zref = 0.0;
3972 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3973 if(!fTracklets[iLayer]->IsOK()) continue;
3974 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
3975 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
3976 acceptablez = kFALSE;
3981 //_____________________________________________________________________________
3982 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
3984 // Calculate y position out of the track parameters
3985 // y: R^2 = (x - x0)^2 + (y - y0)^2
3986 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
3987 // R = Sqrt() = 1/Curvature
3988 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
3991 Double_t disc = (x * fParameters[0] + fParameters[1]);
3992 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
3994 disc = TMath::Sqrt(disc);
3995 y = (1.0 - disc) / fParameters[0];
4000 //_____________________________________________________________________________
4001 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4003 // Return z position for a given x position
4004 // Simple linear function
4006 return fParameters[3] + fParameters[4] * (x - fXref);
4009 //_____________________________________________________________________________
4010 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4012 // Calculate dydx at a given radial position out of the track parameters
4013 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4014 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4015 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4016 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4017 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4019 Double_t x0 = -fParameters[1] / fParameters[0];
4020 Double_t curvature = GetCurvature();
4022 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4023 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4024 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4025 if (fParameters[0] < 0) yderiv *= -1.0;
4032 //_____________________________________________________________________________
4033 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4035 // Calculate track curvature
4038 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4039 if (curvature > 0.0)
4040 curvature = fParameters[0] / TMath::Sqrt(curvature);
4044 //_____________________________________________________________________________
4045 void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4047 // Error Definition according to gauss error propagation
4049 TMatrixD transform(3,3);
4050 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4051 transform(0,1) = transform(1,2) = x;
4052 transform(0,2) = x*x;
4053 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4054 covariance *= transform.T();
4055 cov[0] = covariance(0,0);
4056 TMatrixD transformZ(2,2);
4057 transformZ(0,0) = transformZ(1,1) = 1;
4058 transformZ(0,1) = x;
4059 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4060 covarZ *= transformZ.T();
4061 cov[1] = covarZ(0,0);
4065 //____________________________________________________________________
4066 Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4068 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4069 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4070 // are taken into account
4072 // Parameters: - Array of tracklets(AliTRDseedV1)
4074 // Output: - The reference x-position(Float_t)
4076 Int_t nDistances = 0;
4077 Float_t meanDistance = 0.;
4078 Int_t startIndex = 5;
4079 for(Int_t il =5; il > 0; il--){
4080 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4081 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4082 meanDistance += xdiff;
4085 if(fTracklets[il]->IsOK()) startIndex = il;
4087 if(fTracklets[0]->IsOK()) startIndex = 0;
4089 // We should normally never get here
4090 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4091 Int_t iok = 0, idiff = 0;
4092 // This attempt is worse and should be avoided:
4093 // check for two chambers which are OK and repeat this without taking the mean value
4094 // Strategy avoids a division by 0;
4095 for(Int_t il = 5; il >= 0; il--){
4096 if(fTracklets[il]->IsOK()){
4097 xpos[iok] = fTracklets[il]->GetX0();
4101 if(iok) idiff++; // to get the right difference;
4105 meanDistance = (xpos[0] - xpos[1])/idiff;
4108 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4113 meanDistance /= nDistances;
4115 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());