2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
24 // Alex Bercuci <A.Bercuci@gsi.de> //
25 // Markus Fasel <M.Fasel@gsi.de> //
27 ///////////////////////////////////////////////////////////////////////////////
29 // #include <Riostream.h>
31 // #include <string.h>
34 #include <TDirectory.h>
35 #include <TLinearFitter.h>
37 #include <TClonesArray.h>
38 #include <TTreeStream.h>
41 #include "AliESDEvent.h"
42 #include "AliGeomManager.h"
43 #include "AliRieman.h"
44 #include "AliTrackPointArray.h"
46 #include "AliTRDgeometry.h"
47 #include "AliTRDpadPlane.h"
48 #include "AliTRDcalibDB.h"
49 #include "AliTRDReconstructor.h"
50 #include "AliTRDCalibraFillHisto.h"
51 #include "AliTRDrecoParam.h"
53 #include "AliTRDcluster.h"
54 #include "AliTRDseedV1.h"
55 #include "AliTRDtrackV1.h"
56 #include "AliTRDtrackerV1.h"
57 #include "AliTRDtrackerDebug.h"
58 #include "AliTRDtrackingChamber.h"
59 #include "AliTRDchamberTimeBin.h"
63 ClassImp(AliTRDtrackerV1)
66 const Float_t AliTRDtrackerV1::fgkMinClustersInTrack = 0.5; //
67 const Float_t AliTRDtrackerV1::fgkLabelFraction = 0.8; //
68 const Double_t AliTRDtrackerV1::fgkMaxChi2 = 12.0; //
69 const Double_t AliTRDtrackerV1::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
70 const Double_t AliTRDtrackerV1::fgkMaxStep = 2.0; // Maximal step size in propagation
71 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
72 0.1112, 0.1112, 0.1112, 0.0786, 0.0786,
73 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
74 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
76 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
77 TTreeSRedirector *AliTRDtrackerV1::fgDebugStreamer = 0x0;
78 AliRieman* AliTRDtrackerV1::fgRieman = 0x0;
79 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = 0x0;
80 TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = 0x0;
82 //____________________________________________________________________
83 AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
86 ,fGeom(new AliTRDgeometry())
93 // Default constructor.
95 AliTRDcalibDB *trd = 0x0;
96 if (!(trd = AliTRDcalibDB::Instance())) {
97 AliFatal("Could not get calibration object");
100 if(!fgNTimeBins) fgNTimeBins = trd->GetNumberOfTimeBins();
102 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
104 for(Int_t isl =0; isl<kNSeedPlanes; isl++) fSeedTB[isl] = 0x0;
106 // Initialize debug stream
107 if(rec) SetReconstructor(rec);
110 //____________________________________________________________________
111 AliTRDtrackerV1::~AliTRDtrackerV1()
117 if(fgDebugStreamer) delete fgDebugStreamer;
118 if(fgRieman) delete fgRieman;
119 if(fgTiltedRieman) delete fgTiltedRieman;
120 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained;
121 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
122 if(fTracks) {fTracks->Delete(); delete fTracks;}
123 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
125 fClusters->Delete(); delete fClusters;
127 if(fGeom) delete fGeom;
130 //____________________________________________________________________
131 Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
134 // Steering stand alone tracking for full TRD detector
137 // esd : The ESD event. On output it contains
138 // the ESD tracks found in TRD.
141 // Number of tracks found in the TRD detector.
143 // Detailed description
144 // 1. Launch individual SM trackers.
145 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
148 if(!fReconstructor->GetRecoParam() ){
149 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
153 //AliInfo("Start Track Finder ...");
155 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
156 // for(int ism=1; ism<2; ism++){
157 //AliInfo(Form("Processing supermodule %i ...", ism));
158 ntracks += Clusters2TracksSM(ism, esd);
160 AliInfo(Form("Number of found tracks : %d", ntracks));
165 //_____________________________________________________________________________
166 Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
168 //AliInfo(Form("Asking for tracklet %d", index));
170 AliTRDseedV1 *tracklet = GetTracklet(index);
171 if (!tracklet) return kFALSE;
173 // get detector for this tracklet
174 AliTRDcluster *cl = 0x0;
175 Int_t ic = 0; do; while(!(cl = tracklet->GetClusters(ic++)));
176 Int_t idet = cl->GetDetector();
179 local[0] = tracklet->GetX0();
180 local[1] = tracklet->GetYfit(0);
181 local[2] = tracklet->GetZfit(0);
183 fGeom->RotateBack(idet, local, global);
184 p.SetXYZ(global[0],global[1],global[2]);
188 AliGeomManager::ELayerID iLayer = AliGeomManager::kTRD1;
189 switch (fGeom->GetLayer(idet)) {
191 iLayer = AliGeomManager::kTRD1;
194 iLayer = AliGeomManager::kTRD2;
197 iLayer = AliGeomManager::kTRD3;
200 iLayer = AliGeomManager::kTRD4;
203 iLayer = AliGeomManager::kTRD5;
206 iLayer = AliGeomManager::kTRD6;
209 Int_t modId = fGeom->GetSector(idet) * fGeom->Nstack() + fGeom->GetStack(idet);
210 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
211 p.SetVolumeID(volid);
216 //____________________________________________________________________
217 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
219 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
220 return fgTiltedRieman;
223 //____________________________________________________________________
224 TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
226 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
227 return fgTiltedRiemanConstrained;
230 //____________________________________________________________________
231 AliRieman* AliTRDtrackerV1::GetRiemanFitter()
233 if(!fgRieman) fgRieman = new AliRieman(AliTRDtrackingChamber::kNTimeBins * AliTRDgeometry::kNlayer);
237 //_____________________________________________________________________________
238 Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
241 // Gets seeds from ESD event. The seeds are AliTPCtrack's found and
242 // backpropagated by the TPC tracker. Each seed is first propagated
243 // to the TRD, and then its prolongation is searched in the TRD.
244 // If sufficiently long continuation of the track is found in the TRD
245 // the track is updated, otherwise it's stored as originaly defined
246 // by the TPC tracker.
249 // Calibration monitor
250 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
251 if (!calibra) AliInfo("Could not get Calibra instance\n");
253 Int_t found = 0; // number of tracks found
254 Float_t foundMin = 20.0;
256 Float_t *quality = 0x0;
258 Int_t nSeed = event->GetNumberOfTracks();
260 quality = new Float_t[nSeed];
261 index = new Int_t[nSeed];
262 for (Int_t iSeed = 0; iSeed < nSeed; iSeed++) {
263 AliESDtrack *seed = event->GetTrack(iSeed);
264 Double_t covariance[15];
265 seed->GetExternalCovariance(covariance);
266 quality[iSeed] = covariance[0] + covariance[2];
268 // Sort tracks according to covariance of local Y and Z
269 TMath::Sort(nSeed,quality,index,kFALSE);
272 // Backpropagate all seeds
275 for (Int_t iSeed = 0; iSeed < nSeed; iSeed++) {
277 // Get the seeds in sorted sequence
278 AliESDtrack *seed = event->GetTrack(index[iSeed]);
280 // Check the seed status
281 ULong_t status = seed->GetStatus();
282 if ((status & AliESDtrack::kTPCout) == 0) continue;
283 if ((status & AliESDtrack::kTRDout) != 0) continue;
285 // Do the back prolongation
286 new(&track) AliTRDtrackV1(*seed);
287 track.SetReconstructor(fReconstructor);
289 //Int_t lbl = seed->GetLabel();
290 //track.SetSeedLabel(lbl);
292 // Make backup and mark entrance in the TRD
293 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
294 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
295 Float_t p4 = track.GetC();
296 expectedClr = FollowBackProlongation(track);
298 if (expectedClr<0) continue; // Back prolongation failed
302 // computes PID for track
304 // update calibration references using this track
305 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
306 // save calibration object
307 if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0 /*&& quality TODO*/){
308 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
309 calibTrack->SetOwner();
310 seed->AddCalibObject(calibTrack);
313 if ((track.GetNumberOfClusters() > 15) && (track.GetNumberOfClusters() > 0.5*expectedClr)) {
314 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
315 track.UpdateESDtrack(seed);
319 if ((TMath::Abs(track.GetC() - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
321 // Make backup for back propagation
323 Int_t foundClr = track.GetNumberOfClusters();
324 if (foundClr >= foundMin) {
325 //AliInfo(Form("Making backup track ncls [%d]...", foundClr));
327 //track.CookdEdxTimBin(seed->GetID());
328 track.CookLabel(1. - fgkLabelFraction);
329 if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
331 // Sign only gold tracks
332 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
333 if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)){
334 //UseClusters(&track);
337 Bool_t isGold = kFALSE;
340 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
341 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
347 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
348 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
349 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
354 if ((!isGold) && (track.GetBackupTrack())) {
355 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
356 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
361 //if ((track->StatusForTOF() > 0) && (track->GetNCross() == 0) && (Float_t(track->GetNumberOfClusters()) / Float_t(track->GetNExpected()) > 0.4)) {
362 //seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
367 // Propagation to the TOF (I.Belikov)
368 if (track.IsStopped() == kFALSE) {
369 Double_t xtof = 371.0;
370 Double_t xTOF0 = 370.0;
372 Double_t c2 = track.GetSnp() + track.GetC() * (xtof - track.GetX());
373 if (TMath::Abs(c2) >= 0.99) continue;
375 if (!PropagateToX(track, xTOF0, fgkMaxStep)) continue;
377 // Energy losses taken to the account - check one more time
378 c2 = track.GetSnp() + track.GetC() * (xtof - track.GetX());
379 if (TMath::Abs(c2) >= 0.99) continue;
381 //if (!PropagateToX(*track,xTOF0,fgkMaxStep)) {
382 // fHBackfit->Fill(7);
387 Double_t ymax = xtof * TMath::Tan(0.5 * AliTRDgeometry::GetAlpha());
389 track.GetYAt(xtof,GetBz(),y);
391 if (!track.Rotate( AliTRDgeometry::GetAlpha())) continue;
392 }else if (y < -ymax) {
393 if (!track.Rotate(-AliTRDgeometry::GetAlpha())) continue;
396 if (track.PropagateTo(xtof)) {
397 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
398 track.UpdateESDtrack(seed);
401 if ((track.GetNumberOfClusters() > 15) && (track.GetNumberOfClusters() > 0.5*expectedClr)) {
402 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
404 track.UpdateESDtrack(seed);
408 seed->SetTRDQuality(track.StatusForTOF());
409 seed->SetTRDBudget(track.GetBudget(0));
411 if(index) delete [] index;
412 if(quality) delete [] quality;
415 AliInfo(Form("Number of seeds: %d", nSeed));
416 AliInfo(Form("Number of back propagated TRD tracks: %d", found));
418 // run stand alone tracking
419 if (fReconstructor->IsSeeding()) Clusters2Tracks(event);
425 //____________________________________________________________________
426 Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
429 // Refits tracks within the TRD. The ESD event is expected to contain seeds
430 // at the outer part of the TRD.
431 // The tracks are propagated to the innermost time bin
432 // of the TRD and the ESD event is updated
433 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
436 Int_t nseed = 0; // contor for loaded seeds
437 Int_t found = 0; // contor for updated TRD tracks
441 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
442 AliESDtrack *seed = event->GetTrack(itrack);
443 new(&track) AliTRDtrackV1(*seed);
445 if (track.GetX() < 270.0) {
446 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
450 ULong_t status = seed->GetStatus();
451 // reject tracks which failed propagation in the TRD
452 if((status & AliESDtrack::kTRDout) == 0) continue;
454 // reject tracks which are produced by the TRD stand alone track finder.
455 if((status & AliESDtrack::kTRDin) == 0) continue;
458 track.ResetCovariance(50.0);
460 // do the propagation and processing
461 Bool_t kUPDATE = kFALSE;
462 Double_t xTPC = 250.0;
463 if(FollowProlongation(track)){
465 if (PropagateToX(track, xTPC, fgkMaxStep)) { // -with update
466 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
472 // Prolongate to TPC without update
474 AliTRDtrackV1 tt(*seed);
475 if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDrefit);
478 AliInfo(Form("Number of loaded seeds: %d",nseed));
479 AliInfo(Form("Number of found tracks from loaded seeds: %d",found));
484 //____________________________________________________________________
485 Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
487 // Extrapolates the TRD track in the TPC direction.
490 // t : the TRD track which has to be extrapolated
493 // number of clusters attached to the track
495 // Detailed description
497 // Starting from current radial position of track <t> this function
498 // extrapolates the track through the 6 TRD layers. The following steps
499 // are being performed for each plane:
501 // a. get plane limits in the local x direction
502 // b. check crossing sectors
503 // c. check track inclination
504 // 2. search tracklet in the tracker list (see GetTracklet() for details)
505 // 3. evaluate material budget using the geo manager
506 // 4. propagate and update track using the tracklet information.
511 Int_t nClustersExpected = 0;
512 Int_t lastplane = 5; //GetLastPlane(&t);
513 for (Int_t iplane = lastplane; iplane >= 0; iplane--) {
515 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
516 if(!tracklet) continue;
517 if(!tracklet->IsOK()) AliWarning("tracklet not OK");
519 Double_t x = tracklet->GetX0();
520 // reject tracklets which are not considered for inward refit
521 if(x > t.GetX()+fgkMaxStep) continue;
523 // append tracklet to track
524 t.SetTracklet(tracklet, index);
526 if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
527 if (!AdjustSector(&t)) break;
529 // Start global position
533 // End global position
534 Double_t alpha = t.GetAlpha(), y, z;
535 if (!t.GetProlongation(x,y,z)) break;
537 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
538 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
541 // Get material budget
543 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
544 Double_t xrho= param[0]*param[4];
545 Double_t xx0 = param[1]; // Get mean propagation parameters
547 // Propagate and update
548 t.PropagateTo(x, xx0, xrho);
549 if (!AdjustSector(&t)) break;
551 Double_t maxChi2 = t.GetPredictedChi2(tracklet);
552 if (maxChi2 < 1e+10 && t.Update(tracklet, maxChi2)){
553 nClustersExpected += tracklet->GetN();
557 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
559 for(int iplane=0; iplane<6; iplane++){
560 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
561 if(!tracklet) continue;
562 t.SetTracklet(tracklet, index);
565 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
566 TTreeSRedirector &cstreamer = *fgDebugStreamer;
567 cstreamer << "FollowProlongation"
568 << "EventNumber=" << eventNumber
569 << "ncl=" << nClustersExpected
574 return nClustersExpected;
578 //_____________________________________________________________________________
579 Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
581 // Extrapolates the TRD track in the TOF direction.
584 // t : the TRD track which has to be extrapolated
587 // number of clusters attached to the track
589 // Detailed description
591 // Starting from current radial position of track <t> this function
592 // extrapolates the track through the 6 TRD layers. The following steps
593 // are being performed for each plane:
595 // a. get plane limits in the local x direction
596 // b. check crossing sectors
597 // c. check track inclination
598 // 2. build tracklet (see AliTRDseed::AttachClusters() for details)
599 // 3. evaluate material budget using the geo manager
600 // 4. propagate and update track using the tracklet information.
605 Int_t nClustersExpected = 0;
606 Double_t clength = AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
607 AliTRDtrackingChamber *chamber = 0x0;
609 AliTRDseedV1 tracklet, *ptrTracklet = 0x0;
610 // in case of stand alone tracking we store all the pointers to the tracklets in a temporary array
611 AliTRDseedV1 *tracklets[kNPlanes];
612 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
613 for(Int_t ip = 0; ip < kNPlanes; ip++){
614 tracklets[ip] = t.GetTracklet(ip);
618 // Loop through the TRD layers
619 for (Int_t ilayer = 0; ilayer < AliTRDgeometry::Nlayer(); ilayer++) {
620 // BUILD TRACKLET IF NOT ALREADY BUILT
621 Double_t x = 0., y, z, alpha;
622 ptrTracklet = tracklets[ilayer];
624 ptrTracklet = new(&tracklet) AliTRDseedV1(ilayer);
625 ptrTracklet->SetReconstructor(fReconstructor);
626 alpha = t.GetAlpha();
627 Int_t sector = Int_t(alpha/AliTRDgeometry::GetAlpha() + (alpha>0. ? 0 : AliTRDgeometry::kNsector));
629 if(!fTrSec[sector].GetNChambers()) continue;
631 if((x = fTrSec[sector].GetX(ilayer)) < 1.) continue;
633 if (!t.GetProlongation(x, y, z)) return -nClustersExpected;
634 Int_t stack = fGeom->GetStack(z, ilayer);
635 Int_t nCandidates = stack >= 0 ? 1 : 2;
636 z -= stack >= 0 ? 0. : 4.;
638 for(int icham=0; icham<nCandidates; icham++, z+=8){
639 if((stack = fGeom->GetStack(z, ilayer)) < 0) continue;
641 if(!(chamber = fTrSec[sector].GetChamber(stack, ilayer))) continue;
643 if(chamber->GetNClusters() < fgNTimeBins*fReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
647 AliTRDpadPlane *pp = fGeom->GetPadPlane(ilayer, stack);
648 tracklet.SetTilt(TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle()));
649 tracklet.SetPadLength(pp->GetLengthIPad());
650 tracklet.SetDetector(chamber->GetDetector());
652 if(!tracklet.Init(&t)){
654 return nClustersExpected;
656 if(!tracklet.AttachClustersIter(chamber, 1., kTRUE)) continue;
659 if(tracklet.GetN() < fgNTimeBins*fReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
663 //ptrTracklet->UseClusters();
665 if(!ptrTracklet->IsOK()){
666 if(x < 1.) continue; //temporary
667 if(!PropagateToX(t, x-fgkMaxStep, fgkMaxStep)) return -nClustersExpected;
668 if(!AdjustSector(&t)) return -nClustersExpected;
669 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) return -nClustersExpected;
673 // Propagate closer to the current chamber if neccessary
675 if (x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x-fgkMaxStep, fgkMaxStep)) return -nClustersExpected;
676 if (!AdjustSector(&t)) return -nClustersExpected;
677 if (TMath::Abs(t.GetSnp()) > fgkMaxSnp) return -nClustersExpected;
679 // load tracklet to the tracker and the track
680 ptrTracklet = SetTracklet(ptrTracklet);
681 t.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
684 // Calculate the mean material budget along the path inside the chamber
685 //Calculate global entry and exit positions of the track in chamber (only track prolongation)
686 Double_t xyz0[3]; // entry point
688 alpha = t.GetAlpha();
689 x = ptrTracklet->GetX0();
690 if (!t.GetProlongation(x, y, z)) return -nClustersExpected;
691 Double_t xyz1[3]; // exit point
692 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
693 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
696 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
697 // The mean propagation parameters
698 Double_t xrho = param[0]*param[4]; // density*length
699 Double_t xx0 = param[1]; // radiation length
701 // Propagate and update track
702 if (!t.PropagateTo(x, xx0, xrho)) return -nClustersExpected;
703 if (!AdjustSector(&t)) return -nClustersExpected;
704 Double_t maxChi2 = t.GetPredictedChi2(ptrTracklet);
705 if (!t.Update(ptrTracklet, maxChi2)) return -nClustersExpected;
707 nClustersExpected += ptrTracklet->GetN();
708 //t.SetTracklet(&tracklet, index);
710 // Reset material budget if 2 consecutive gold
711 if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
713 // Make backup of the track until is gold
714 // TO DO update quality check of the track.
715 // consider comparison with fTimeBinsRange
716 Float_t ratio0 = ptrTracklet->GetN() / Float_t(fgNTimeBins);
717 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
718 //printf("tracklet.GetChi2() %f [< 18.0]\n", tracklet.GetChi2());
719 //printf("ratio0 %f [> 0.8]\n", ratio0);
720 //printf("ratio1 %f [> 0.6]\n", ratio1);
721 //printf("ratio0+ratio1 %f [> 1.5]\n", ratio0+ratio1);
722 //printf("t.GetNCross() %d [== 0]\n", t.GetNCross());
723 //printf("TMath::Abs(t.GetSnp()) %f [< 0.85]\n", TMath::Abs(t.GetSnp()));
724 //printf("t.GetNumberOfClusters() %d [> 20]\n", t.GetNumberOfClusters());
726 if (//(tracklet.GetChi2() < 18.0) && TO DO check with FindClusters and move it to AliTRDseed::Update
729 //(ratio0+ratio1 > 1.5) &&
730 (t.GetNCross() == 0) &&
731 (TMath::Abs(t.GetSnp()) < 0.85) &&
732 (t.GetNumberOfClusters() > 20)) t.MakeBackupTrack();
736 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
737 TTreeSRedirector &cstreamer = *fgDebugStreamer;
738 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
739 //AliTRDtrackV1 *debugTrack = new AliTRDtrackV1(t);
740 //debugTrack->SetOwner();
741 cstreamer << "FollowBackProlongation"
742 << "EventNumber=" << eventNumber
743 << "ncl=" << nClustersExpected
744 //<< "track.=" << debugTrack
748 return nClustersExpected;
751 //_________________________________________________________________________
752 Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *planes){
754 // Fits a Riemann-circle to the given points without tilting pad correction.
755 // The fit is performed using an instance of the class AliRieman (equations
756 // and transformations see documentation of this class)
757 // Afterwards all the tracklets are Updated
759 // Parameters: - Array of tracklets (AliTRDseedV1)
760 // - Storage for the chi2 values (beginning with direction z)
761 // - Seeding configuration
762 // Output: - The curvature
764 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
766 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
767 Int_t *ppl = &allplanes[0];
773 for(Int_t il = 0; il < maxLayers; il++){
774 if(!tracklets[ppl[il]].IsOK()) continue;
775 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfitR(0), tracklets[ppl[il]].GetZProb(),1,10);
778 // Set the reference position of the fit and calculate the chi2 values
779 memset(chi2, 0, sizeof(Double_t) * 2);
780 for(Int_t il = 0; il < maxLayers; il++){
781 // Reference positions
782 tracklets[ppl[il]].Init(fitter);
785 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
786 chi2[0] += tracklets[ppl[il]].GetChi2Y();
787 chi2[1] += tracklets[ppl[il]].GetChi2Z();
789 return fitter->GetC();
792 //_________________________________________________________________________
793 void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
796 // Performs a Riemann helix fit using the seedclusters as spacepoints
797 // Afterwards the chi2 values are calculated and the seeds are updated
799 // Parameters: - The four seedclusters
800 // - The tracklet array (AliTRDseedV1)
801 // - The seeding configuration
806 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
808 for(Int_t i = 0; i < 4; i++)
809 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1, 10);
813 // Update the seed and calculated the chi2 value
814 chi2[0] = 0; chi2[1] = 0;
815 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
817 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
818 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
823 //_________________________________________________________________________
824 Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
827 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
828 // assumed that the vertex position is set to 0.
829 // This method is very usefull for high-pt particles
830 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
831 // x0, y0: Center of the circle
832 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
833 // zc: center of the pad row
834 // Equation which has to be fitted (after transformation):
835 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
839 // v = 2 * x * tan(phiT) * t
840 // Parameters in the equation:
841 // a = -1/y0, b = x0/y0, e = dz/dx
843 // The Curvature is calculated by the following equation:
844 // - curv = a/Sqrt(b^2 + 1) = 1/R
845 // Parameters: - the 6 tracklets
846 // - the Vertex constraint
847 // Output: - the Chi2 value of the track
852 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
853 fitter->StoreData(kTRUE);
854 fitter->ClearPoints();
855 AliTRDcluster *cl = 0x0;
857 Float_t x, y, z, w, t, error, tilt;
860 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
861 if(!tracklets[ilr].IsOK()) continue;
862 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
863 if(!tracklets[ilr].IsUsable(itb)) continue;
864 cl = tracklets[ilr].GetClusters(itb);
868 tilt = tracklets[ilr].GetTilt();
870 t = 1./(x * x + y * y);
872 uvt[1] = 2. * x * t * tilt ;
873 w = 2. * (y + tilt * (z - zVertex)) * t;
874 error = 2. * 0.2 * t;
875 fitter->AddPoint(uvt, w, error);
881 // Calculate curvature
882 Double_t a = fitter->GetParameter(0);
883 Double_t b = fitter->GetParameter(1);
884 Double_t curvature = a/TMath::Sqrt(b*b + 1);
886 Float_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
887 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
888 tracklets[ip].SetCC(curvature);
890 /* if(fReconstructor->GetStreamLevel() >= 5){
891 //Linear Model on z-direction
892 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
893 Double_t slope = fitter->GetParameter(2);
894 Double_t zref = slope * xref;
895 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
896 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
897 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
898 TTreeSRedirector &treeStreamer = *fgDebugStreamer;
899 treeStreamer << "FitTiltedRiemanConstraint"
900 << "EventNumber=" << eventNumber
901 << "CandidateNumber=" << candidateNumber
902 << "Curvature=" << curvature
903 << "Chi2Track=" << chi2track
911 //_________________________________________________________________________
912 Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
915 // Performs a Riemann fit taking tilting pad correction into account
916 // The equation of a Riemann circle, where the y position is substituted by the
917 // measured y-position taking pad tilting into account, has to be transformed
918 // into a 4-dimensional hyperplane equation
919 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
920 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
921 // zc: center of the pad row
922 // zt: z-position of the track
923 // The z-position of the track is assumed to be linear dependent on the x-position
924 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
925 // Transformation: u = 2 * x * t
926 // v = 2 * tan(phiT) * t
927 // w = 2 * tan(phiT) * (x - xref) * t
928 // t = 1 / (x^2 + ymeas^2)
929 // Parameters: a = -1/y0
931 // c = (R^2 -x0^2 - y0^2)/y0
934 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
935 // results from the simple riemann fit. Afterwards the fit is redone.
936 // The curvature is calculated according to the formula:
937 // curv = a/(1 + b^2 + c*a) = 1/R
939 // Paramters: - Array of tracklets (connected to the track candidate)
940 // - Flag selecting the error definition
941 // Output: - Chi2 values of the track (in Parameter list)
943 TLinearFitter *fitter = GetTiltedRiemanFitter();
944 fitter->StoreData(kTRUE);
945 fitter->ClearPoints();
946 AliTRDLeastSquare zfitter;
947 AliTRDcluster *cl = 0x0;
949 Double_t xref = CalculateReferenceX(tracklets);
950 Double_t x, y, z, t, tilt, dx, w, we;
953 // Containers for Least-square fitter
954 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
955 if(!tracklets[ipl].IsOK()) continue;
956 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
957 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
958 if (!tracklets[ipl].IsUsable(itb)) continue;
962 tilt = tracklets[ipl].GetTilt();
968 uvt[2] = 2. * tilt * t;
969 uvt[3] = 2. * tilt * dx * t;
970 w = 2. * (y + tilt*z) * t;
971 // error definition changes for the different calls
973 we *= sigError ? tracklets[ipl].GetSigmaY() : 0.2;
974 fitter->AddPoint(uvt, w, we);
975 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
982 Double_t offset = fitter->GetParameter(3);
983 Double_t slope = fitter->GetParameter(4);
985 // Linear fitter - not possible to make boundaries
986 // Do not accept non possible z and dzdx combinations
987 Bool_t acceptablez = kTRUE;
989 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
990 if(!tracklets[iLayer].IsOK()) continue;
991 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
992 if (TMath::Abs(tracklets[iLayer].GetZProb() - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
993 acceptablez = kFALSE;
996 Double_t dzmf = zfitter.GetFunctionParameter(1);
997 Double_t zmf = zfitter.GetFunctionValue(&xref);
998 fgTiltedRieman->FixParameter(3, zmf);
999 fgTiltedRieman->FixParameter(4, dzmf);
1001 fitter->ReleaseParameter(3);
1002 fitter->ReleaseParameter(4);
1003 offset = fitter->GetParameter(3);
1004 slope = fitter->GetParameter(4);
1007 // Calculate Curvarture
1008 Double_t a = fitter->GetParameter(0);
1009 Double_t b = fitter->GetParameter(1);
1010 Double_t c = fitter->GetParameter(2);
1011 Double_t curvature = 1.0 + b*b - c*a;
1012 if (curvature > 0.0)
1013 curvature = a / TMath::Sqrt(curvature);
1015 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1017 // Update the tracklets
1019 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1021 x = tracklets[iLayer].GetX0();
1027 // y: R^2 = (x - x0)^2 + (y - y0)^2
1028 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1029 // R = Sqrt() = 1/Curvature
1030 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1031 Double_t res = (x * a + b); // = (x - x0)/y0
1033 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1035 res = TMath::Sqrt(res);
1036 y = (1.0 - res) / a;
1039 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1040 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1041 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1042 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1043 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1044 Double_t x0 = -b / a;
1045 if (-c * a + b * b + 1 > 0) {
1046 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
1047 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1048 if (a < 0) yderiv *= -1.0;
1052 z = offset + slope * (x - xref);
1054 tracklets[iLayer].SetYref(0, y);
1055 tracklets[iLayer].SetYref(1, dy);
1056 tracklets[iLayer].SetZref(0, z);
1057 tracklets[iLayer].SetZref(1, dz);
1058 tracklets[iLayer].SetC(curvature);
1059 tracklets[iLayer].SetChi2(chi2track);
1062 /* if(fReconstructor->GetStreamLevel() >=5){
1063 TTreeSRedirector &cstreamer = *fgDebugStreamer;
1064 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1065 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1066 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1067 cstreamer << "FitTiltedRieman0"
1068 << "EventNumber=" << eventNumber
1069 << "CandidateNumber=" << candidateNumber
1071 << "Chi2Z=" << chi2z
1078 //____________________________________________________________________
1079 Double_t AliTRDtrackerV1::FitLine(AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
1081 AliTRDLeastSquare yfitter, zfitter;
1082 AliTRDcluster *cl = 0x0;
1084 AliTRDseedV1 work[kNPlanes], *tracklet = 0x0;
1086 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1087 if(!(tracklet = track->GetTracklet(ipl))) continue;
1088 if(!tracklet->IsOK()) continue;
1089 new(&work[ipl]) AliTRDseedV1(*tracklet);
1091 tracklets = &work[0];
1094 Double_t xref = CalculateReferenceX(tracklets);
1095 Double_t x, y, z, dx, ye, yr, tilt;
1096 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1097 if(!tracklets[ipl].IsOK()) continue;
1098 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1099 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1100 if (!tracklets[ipl].IsUsable(itb)) continue;
1104 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1108 Double_t z0 = zfitter.GetFunctionParameter(0);
1109 Double_t dzdx = zfitter.GetFunctionParameter(1);
1110 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1111 if(!tracklets[ipl].IsOK()) continue;
1112 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1113 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1114 if (!tracklets[ipl].IsUsable(itb)) continue;
1118 tilt = tracklets[ipl].GetTilt();
1120 yr = y + tilt*(z - z0 - dzdx*dx);
1121 // error definition changes for the different calls
1122 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1123 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1124 yfitter.AddPoint(&dx, yr, ye);
1128 Double_t y0 = yfitter.GetFunctionParameter(0);
1129 Double_t dydx = yfitter.GetFunctionParameter(1);
1130 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1132 //update track points array
1135 for(int ip=0; ip<np; ip++){
1136 points[ip].GetXYZ(xyz);
1137 xyz[1] = y0 + dydx * (xyz[0] - xref);
1138 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1139 points[ip].SetXYZ(xyz);
1146 //_________________________________________________________________________
1147 Double_t AliTRDtrackerV1::FitRiemanTilt(AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
1150 // Performs a Riemann fit taking tilting pad correction into account
1151 // The equation of a Riemann circle, where the y position is substituted by the
1152 // measured y-position taking pad tilting into account, has to be transformed
1153 // into a 4-dimensional hyperplane equation
1154 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1155 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1156 // zc: center of the pad row
1157 // zt: z-position of the track
1158 // The z-position of the track is assumed to be linear dependent on the x-position
1159 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1160 // Transformation: u = 2 * x * t
1161 // v = 2 * tan(phiT) * t
1162 // w = 2 * tan(phiT) * (x - xref) * t
1163 // t = 1 / (x^2 + ymeas^2)
1164 // Parameters: a = -1/y0
1166 // c = (R^2 -x0^2 - y0^2)/y0
1169 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1170 // results from the simple riemann fit. Afterwards the fit is redone.
1171 // The curvature is calculated according to the formula:
1172 // curv = a/(1 + b^2 + c*a) = 1/R
1174 // Paramters: - Array of tracklets (connected to the track candidate)
1175 // - Flag selecting the error definition
1176 // Output: - Chi2 values of the track (in Parameter list)
1178 TLinearFitter *fitter = GetTiltedRiemanFitter();
1179 fitter->StoreData(kTRUE);
1180 fitter->ClearPoints();
1181 AliTRDLeastSquare zfitter;
1182 AliTRDcluster *cl = 0x0;
1184 AliTRDseedV1 work[kNPlanes], *tracklet = 0x0;
1186 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1187 if(!(tracklet = track->GetTracklet(ipl))) continue;
1188 if(!tracklet->IsOK()) continue;
1189 new(&work[ipl]) AliTRDseedV1(*tracklet);
1191 tracklets = &work[0];
1194 Double_t xref = CalculateReferenceX(tracklets);
1195 Double_t x, y, z, t, tilt, dx, w, we;
1198 // Containers for Least-square fitter
1199 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1200 if(!tracklets[ipl].IsOK()) continue;
1201 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1202 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1203 if (!tracklets[ipl].IsUsable(itb)) continue;
1207 tilt = tracklets[ipl].GetTilt();
1211 uvt[0] = 2. * x * t;
1213 uvt[2] = 2. * tilt * t;
1214 uvt[3] = 2. * tilt * dx * t;
1215 w = 2. * (y + tilt*z) * t;
1216 // error definition changes for the different calls
1218 we *= sigError ? tracklets[ipl].GetSigmaY() : 0.2;
1219 fitter->AddPoint(uvt, w, we);
1220 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1224 if(fitter->Eval()) return 1.E10;
1226 Double_t z0 = fitter->GetParameter(3);
1227 Double_t dzdx = fitter->GetParameter(4);
1230 // Linear fitter - not possible to make boundaries
1231 // Do not accept non possible z and dzdx combinations
1232 Bool_t accept = kTRUE;
1233 Double_t zref = 0.0;
1234 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1235 if(!tracklets[iLayer].IsOK()) continue;
1236 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
1237 if (TMath::Abs(tracklets[iLayer].GetZProb() - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
1242 Double_t dzmf = zfitter.GetFunctionParameter(1);
1243 Double_t zmf = zfitter.GetFunctionValue(&xref);
1244 fitter->FixParameter(3, zmf);
1245 fitter->FixParameter(4, dzmf);
1247 fitter->ReleaseParameter(3);
1248 fitter->ReleaseParameter(4);
1249 z0 = fitter->GetParameter(3); // = zmf ?
1250 dzdx = fitter->GetParameter(4); // = dzmf ?
1253 // Calculate Curvature
1254 Double_t a = fitter->GetParameter(0);
1255 Double_t b = fitter->GetParameter(1);
1256 Double_t c = fitter->GetParameter(2);
1257 Double_t y0 = 1. / a;
1258 Double_t x0 = -b * y0;
1259 Double_t R = TMath::Sqrt(y0*y0 + x0*x0 - c*y0);
1260 Double_t C = 1.0 + b*b - c*a;
1261 if (C > 0.0) C = a / TMath::Sqrt(C);
1263 // Calculate chi2 of the fit
1264 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
1266 // Update the tracklets
1268 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1269 x = tracklets[ip].GetX0();
1270 Double_t tmp = TMath::Sqrt(R*R-(x-x0)*(x-x0));
1272 // y: R^2 = (x - x0)^2 + (y - y0)^2
1273 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1274 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1275 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1276 tracklets[ip].SetYref(1, (x - x0) / tmp);
1277 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1278 tracklets[ip].SetZref(1, dzdx);
1279 tracklets[ip].SetC(C);
1280 tracklets[ip].SetChi2(chi2);
1284 //update track points array
1287 for(int ip=0; ip<np; ip++){
1288 points[ip].GetXYZ(xyz);
1289 xyz[1] = y0 - (y0>0.?1.:-1)*TMath::Sqrt(R*R-(xyz[0]-x0)*(xyz[0]-x0));
1290 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1291 points[ip].SetXYZ(xyz);
1295 /* if(fReconstructor->GetStreamLevel() >=5){
1296 TTreeSRedirector &cstreamer = *fgDebugStreamer;
1297 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1298 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1299 Double_t chi2z = CalculateChi2Z(tracklets, z0, dzdx, xref);
1300 cstreamer << "FitRiemanTilt"
1301 << "EventNumber=" << eventNumber
1302 << "CandidateNumber=" << candidateNumber
1304 << "Chi2Z=" << chi2z
1311 //____________________________________________________________________
1312 Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1314 // Kalman filter implementation for the TRD.
1315 // It returns the positions of the fit in the array "points"
1317 // Author : A.Bercuci@gsi.de
1319 //printf("Start track @ x[%f]\n", track->GetX());
1321 //prepare marker points along the track
1322 Int_t ip = np ? 0 : 1;
1324 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1325 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1328 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1331 AliTRDseedV1 tracklet, *ptrTracklet = 0x0;
1333 //Loop through the TRD planes
1334 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1335 // GET TRACKLET OR BUILT IT
1336 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1338 if(!(ptrTracklet = &tracklets[iplane])) continue;
1340 if(!(ptrTracklet = track->GetTracklet(iplane))){
1341 /*AliTRDtrackerV1 *tracker = 0x0;
1342 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDReconstructor::Tracker()))) continue;
1343 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1344 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1348 if(!ptrTracklet->IsOK()) continue;
1350 Double_t x = ptrTracklet->GetX0();
1353 //don't do anything if next marker is after next update point.
1354 if((up?-1:1) * (points[ip].GetX() - x) - fgkMaxStep < 0) break;
1356 //printf("Propagate to x[%d] = %f\n", ip, points[ip].GetX());
1358 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1360 Double_t xyz[3]; // should also get the covariance
1361 track->GetXYZ(xyz); points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1364 //printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1366 //Propagate closer to the next update point
1367 if(((up?-1:1) * (x - track->GetX()) + fgkMaxStep < 0) && !PropagateToX(*track, x + (up?-1:1)*fgkMaxStep, fgkMaxStep)) return -1.;
1369 if(!AdjustSector(track)) return -1;
1370 if(TMath::Abs(track->GetSnp()) > fgkMaxSnp) return -1;
1372 //load tracklet to the tracker and the track
1374 if((index = FindTracklet(ptrTracklet)) < 0){
1375 ptrTracklet = SetTracklet(&tracklet);
1376 index = fTracklets->GetEntriesFast()-1;
1378 track->SetTracklet(ptrTracklet, index);*/
1381 // register tracklet to track with tracklet creation !!
1382 // PropagateBack : loaded tracklet to the tracker and update index
1383 // RefitInward : update index
1384 // MakeTrack : loaded tracklet to the tracker and update index
1385 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1388 //Calculate the mean material budget along the path inside the chamber
1389 Double_t xyz0[3]; track->GetXYZ(xyz0);
1390 Double_t alpha = track->GetAlpha();
1391 Double_t xyz1[3], y, z;
1392 if(!track->GetProlongation(x, y, z)) return -1;
1393 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1394 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1397 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
1398 Double_t xrho = param[0]*param[4]; // density*length
1399 Double_t xx0 = param[1]; // radiation length
1401 //Propagate the track
1402 track->PropagateTo(x, xx0, xrho);
1403 if (!AdjustSector(track)) break;
1406 Double_t chi2 = track->GetPredictedChi2(ptrTracklet);
1407 if(chi2<1e+10) track->Update(ptrTracklet, chi2);
1411 //Reset material budget if 2 consecutive gold
1412 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1413 } // end planes loop
1417 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
1419 Double_t xyz[3]; // should also get the covariance
1420 track->GetXYZ(xyz); points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1424 return track->GetChi2();
1427 //_________________________________________________________________________
1428 Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
1431 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1432 // A linear dependence on the x-value serves as a model.
1433 // The parameters are related to the tilted Riemann fit.
1434 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1435 // - the offset for the reference x
1437 // - the reference x position
1438 // Output: - The Chi2 value of the track in z-Direction
1440 Float_t chi2Z = 0, nLayers = 0;
1441 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
1442 if(!tracklets[iLayer].IsOK()) continue;
1443 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1444 chi2Z += TMath::Abs(tracklets[iLayer].GetMeanz() - z);
1447 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1451 //_____________________________________________________________________________
1452 Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1455 // Starting from current X-position of track <t> this function
1456 // extrapolates the track up to radial position <xToGo>.
1457 // Returns 1 if track reaches the plane, and 0 otherwise
1460 const Double_t kEpsilon = 0.00001;
1462 // Current track X-position
1463 Double_t xpos = t.GetX();
1465 // Direction: inward or outward
1466 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
1468 while (((xToGo - xpos) * dir) > kEpsilon) {
1477 // The next step size
1478 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
1480 // Get the global position of the starting point
1483 // X-position after next step
1486 // Get local Y and Z at the X-position of the next step
1487 if (!t.GetProlongation(x,y,z)) {
1488 return 0; // No prolongation possible
1491 // The global position of the end point of this prolongation step
1492 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1493 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1496 // Calculate the mean material budget between start and
1497 // end point of this prolongation step
1498 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
1500 // Propagate the track to the X-position after the next step
1501 if (!t.PropagateTo(x,param[1],param[0]*param[4])) {
1505 // Rotate the track if necessary
1508 // New track X-position
1518 //_____________________________________________________________________________
1519 Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) const
1522 // Reads AliTRDclusters from the file.
1523 // The names of the cluster tree and branches
1524 // should match the ones used in AliTRDclusterizer::WriteClusters()
1527 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1528 TObjArray *clusterArray = new TObjArray(nsize+1000);
1530 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1532 AliError("Can't get the branch !");
1535 branch->SetAddress(&clusterArray);
1538 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1539 if(fReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
1540 array = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1541 array->SetOwner(kTRUE);
1544 // Loop through all entries in the tree
1545 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1548 AliTRDcluster *c = 0x0;
1549 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1551 nbytes += clusterTree->GetEvent(iEntry);
1553 // Get the number of points in the detector
1554 Int_t nCluster = clusterArray->GetEntriesFast();
1555 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1556 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
1558 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1559 delete (clusterArray->RemoveAt(iCluster));
1563 delete clusterArray;
1568 //_____________________________________________________________________________
1569 Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1572 // Fills clusters into TRD tracking sectors
1575 if(!fReconstructor->IsWritingClusters()){
1576 fClusters = AliTRDReconstructor::GetClusters();
1578 if (ReadClusters(fClusters, cTree)) {
1579 AliError("Problem with reading the clusters !");
1585 if(!fClusters || !fClusters->GetEntriesFast()){
1586 AliInfo("No TRD clusters");
1591 BuildTrackingContainers();
1593 //Int_t ncl = fClusters->GetEntriesFast();
1594 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1599 //_____________________________________________________________________________
1600 Int_t AliTRDtrackerV1::LoadClusters(TClonesArray *clusters)
1603 // Fills clusters into TRD tracking sectors
1604 // Function for use in the HLT
1606 if(!clusters || !clusters->GetEntriesFast()){
1607 AliInfo("No TRD clusters");
1611 fClusters = clusters;
1615 BuildTrackingContainers();
1617 //Int_t ncl = fClusters->GetEntriesFast();
1618 //AliInfo(Form("Clusters %d [%6.2f %% in the active volume]", ncl, 100.*float(nin)/ncl));
1624 //____________________________________________________________________
1625 Int_t AliTRDtrackerV1::BuildTrackingContainers()
1627 // Building tracking containers for clusters
1629 Int_t nin =0, icl = fClusters->GetEntriesFast();
1631 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
1632 if(c->IsInChamber()) nin++;
1633 Int_t detector = c->GetDetector();
1634 Int_t sector = fGeom->GetSector(detector);
1635 Int_t stack = fGeom->GetStack(detector);
1636 Int_t layer = fGeom->GetLayer(detector);
1638 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, icl);
1641 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
1642 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
1643 if(!fTrSec[isector].GetNChambers()) continue;
1644 fTrSec[isector].Init(fReconstructor, cal);
1652 //____________________________________________________________________
1653 void AliTRDtrackerV1::UnloadClusters()
1656 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1659 if(fTracks) fTracks->Delete();
1660 if(fTracklets) fTracklets->Delete();
1662 if(IsClustersOwner()) fClusters->Delete();
1664 // save clusters array in the reconstructor for further use.
1665 if(!fReconstructor->IsWritingClusters()){
1666 AliTRDReconstructor::SetClusters(fClusters);
1667 SetClustersOwner(kFALSE);
1668 } else AliTRDReconstructor::SetClusters(0x0);
1671 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
1673 // Increment the Event Number
1674 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
1677 //_____________________________________________________________________________
1678 Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *track)
1681 // Rotates the track when necessary
1684 Double_t alpha = AliTRDgeometry::GetAlpha();
1685 Double_t y = track->GetY();
1686 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
1689 if (!track->Rotate( alpha)) {
1693 else if (y < -ymax) {
1694 if (!track->Rotate(-alpha)) {
1704 //____________________________________________________________________
1705 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *track, Int_t p, Int_t &idx)
1707 // Find tracklet for TRD track <track>
1716 // Detailed description
1718 idx = track->GetTrackletIndex(p);
1719 AliTRDseedV1 *tracklet = (idx==0xffff) ? 0x0 : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
1724 //____________________________________________________________________
1725 AliTRDseedV1* AliTRDtrackerV1::SetTracklet(AliTRDseedV1 *tracklet)
1727 // Add this tracklet to the list of tracklets stored in the tracker
1730 // - tracklet : pointer to the tracklet to be added to the list
1733 // - the index of the new tracklet in the tracker tracklets list
1735 // Detailed description
1736 // Build the tracklets list if it is not yet created (late initialization)
1737 // and adds the new tracklet to the list.
1740 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
1741 fTracklets->SetOwner(kTRUE);
1743 Int_t nentries = fTracklets->GetEntriesFast();
1744 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
1747 //____________________________________________________________________
1748 AliTRDtrackV1* AliTRDtrackerV1::SetTrack(AliTRDtrackV1 *track)
1750 // Add this track to the list of tracks stored in the tracker
1753 // - track : pointer to the track to be added to the list
1756 // - the pointer added
1758 // Detailed description
1759 // Build the tracks list if it is not yet created (late initialization)
1760 // and adds the new track to the list.
1763 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
1764 fTracks->SetOwner(kTRUE);
1766 Int_t nentries = fTracks->GetEntriesFast();
1767 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
1772 //____________________________________________________________________
1773 Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
1776 // Steer tracking for one SM.
1779 // sector : Array of (SM) propagation layers containing clusters
1780 // esd : The current ESD event. On output it contains the also
1781 // the ESD (TRD) tracks found in this SM.
1784 // Number of tracks found in this TRD supermodule.
1786 // Detailed description
1788 // 1. Unpack AliTRDpropagationLayers objects for each stack.
1789 // 2. Launch stack tracking.
1790 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
1791 // 3. Pack results in the ESD event.
1794 // allocate space for esd tracks in this SM
1795 TClonesArray esdTrackList("AliESDtrack", 2*kMaxTracksStack);
1796 esdTrackList.SetOwner();
1799 Int_t nChambers = 0;
1800 AliTRDtrackingChamber **stack = 0x0, *chamber = 0x0;
1801 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
1802 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
1804 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
1805 if(!(chamber = stack[ilayer])) continue;
1806 if(chamber->GetNClusters() < fgNTimeBins * fReconstructor->GetRecoParam() ->GetFindableClusters()) continue;
1808 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
1810 if(nChambers < 4) continue;
1811 //AliInfo(Form("Doing stack %d", istack));
1812 nTracks += Clusters2TracksStack(stack, &esdTrackList);
1814 //AliInfo(Form("Found %d tracks in SM %d [%d]\n", nTracks, sector, esd->GetNumberOfTracks()));
1816 for(int itrack=0; itrack<nTracks; itrack++)
1817 esd->AddTrack((AliESDtrack*)esdTrackList[itrack]);
1819 // Reset Track and Candidate Number
1820 AliTRDtrackerDebug::SetCandidateNumber(0);
1821 AliTRDtrackerDebug::SetTrackNumber(0);
1825 //____________________________________________________________________
1826 Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray *esdTrackList)
1829 // Make tracks in one TRD stack.
1832 // layer : Array of stack propagation layers containing clusters
1833 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
1834 // On exit the tracks found in this stack are appended.
1837 // Number of tracks found in this stack.
1839 // Detailed description
1841 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
1842 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
1843 // See AliTRDtrackerV1::MakeSeeds() for more details.
1844 // 3. Arrange track candidates in decreasing order of their quality
1845 // 4. Classify tracks in 5 categories according to:
1846 // a) number of layers crossed
1848 // 5. Sign clusters by tracks in decreasing order of track quality
1849 // 6. Build AliTRDtrack out of seeding tracklets
1851 // 8. Build ESD track and register it to the output list
1854 const AliTRDCalDet *cal = AliTRDcalibDB::Instance()->GetT0Det();
1855 AliTRDtrackingChamber *chamber = 0x0;
1856 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
1857 Int_t pars[4]; // MakeSeeds parameters
1859 //Double_t alpha = AliTRDgeometry::GetAlpha();
1860 //Double_t shift = .5 * alpha;
1861 Int_t configs[kNConfigs];
1863 // Build initial seeding configurations
1864 Double_t quality = BuildSeedingConfigs(stack, configs);
1865 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
1866 AliInfo(Form("Plane config %d %d %d Quality %f"
1867 , configs[0], configs[1], configs[2], quality));
1871 // Initialize contors
1872 Int_t ntracks, // number of TRD track candidates
1873 ntracks1, // number of registered TRD tracks/iter
1874 ntracks2 = 0; // number of all registered TRD tracks in stack
1878 Int_t ic = 0; AliTRDtrackingChamber **cIter = &stack[0];
1879 while(ic<kNPlanes && !(*cIter)){ic++; cIter++;}
1880 if(!(*cIter)) return ntracks2;
1881 Int_t istack = fGeom->GetStack((*cIter)->GetDetector());
1884 // Loop over seeding configurations
1885 ntracks = 0; ntracks1 = 0;
1886 for (Int_t iconf = 0; iconf<3; iconf++) {
1887 pars[0] = configs[iconf];
1890 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
1891 if(ntracks == kMaxTracksStack) break;
1893 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1) AliInfo(Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
1897 // Sort the seeds according to their quality
1898 Int_t sort[kMaxTracksStack];
1899 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
1901 // Initialize number of tracks so far and logic switches
1902 Int_t ntracks0 = esdTrackList->GetEntriesFast();
1903 Bool_t signedTrack[kMaxTracksStack];
1904 Bool_t fakeTrack[kMaxTracksStack];
1905 for (Int_t i=0; i<ntracks; i++){
1906 signedTrack[i] = kFALSE;
1907 fakeTrack[i] = kFALSE;
1909 //AliInfo("Selecting track candidates ...");
1911 // Sieve clusters in decreasing order of track quality
1912 Double_t trackParams[7];
1913 // AliTRDseedV1 *lseed = 0x0;
1914 Int_t jSieve = 0, candidates;
1916 //AliInfo(Form("\t\tITER = %i ", jSieve));
1918 // Check track candidates
1920 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
1921 Int_t trackIndex = sort[itrack];
1922 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
1925 // Calculate track parameters from tracklets seeds
1930 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
1931 Int_t jseed = kNPlanes*trackIndex+jLayer;
1932 if(!sseed[jseed].IsOK()) continue;
1933 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.15) findable++;
1935 sseed[jseed].UpdateUsed();
1936 ncl += sseed[jseed].GetN2();
1937 nused += sseed[jseed].GetNUsed();
1941 // Filter duplicated tracks
1943 //printf("Skip %d nused %d\n", trackIndex, nused);
1944 fakeTrack[trackIndex] = kTRUE;
1947 if (Float_t(nused)/ncl >= .25){
1948 //printf("Skip %d nused/ncl >= .25\n", trackIndex);
1949 fakeTrack[trackIndex] = kTRUE;
1954 Bool_t skip = kFALSE;
1957 if(nlayers < 6) {skip = kTRUE; break;}
1958 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
1962 if(nlayers < findable){skip = kTRUE; break;}
1963 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
1967 if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
1968 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
1972 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
1976 if (nlayers == 3){skip = kTRUE; break;}
1977 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
1982 //printf("REJECTED : %d [%d] nlayers %d trackQuality = %e nused %d\n", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused);
1985 signedTrack[trackIndex] = kTRUE;
1989 AliTRDcluster *cl = 0x0; Int_t clusterIndex = -1;
1990 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
1991 Int_t jseed = kNPlanes*trackIndex+jLayer;
1992 if(!sseed[jseed].IsOK()) continue;
1993 if(TMath::Abs(sseed[jseed].GetYfit(1) - sseed[jseed].GetYfit(1)) >= .2) continue; // check this condition with Marian
1994 sseed[jseed].UseClusters();
1997 while(!(cl = sseed[jseed].GetClusters(ic))) ic++;
1998 clusterIndex = sseed[jseed].GetIndexes(ic);
2004 // Build track parameters
2005 AliTRDseedV1 *lseed =&sseed[trackIndex*6];
2007 while(idx<3 && !lseed->IsOK()) {
2011 Double_t x = lseed->GetX0();// - 3.5;
2012 trackParams[0] = x; //NEW AB
2013 trackParams[1] = lseed->GetYref(0); // lseed->GetYat(x);
2014 trackParams[2] = lseed->GetZref(0); // lseed->GetZat(x);
2015 trackParams[3] = TMath::Sin(TMath::ATan(lseed->GetYref(1)));
2016 trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
2017 trackParams[5] = lseed->GetC();
2018 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2019 trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift; // Supermodule*/
2021 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
2022 AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
2024 Int_t nclusters = 0;
2025 AliTRDseedV1 *dseed[6];
2027 // Build track label - what happens if measured data ???
2032 Int_t labelsall[1000];
2033 Int_t nlabelsall = 0;
2034 Int_t naccepted = 0;
2036 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
2037 Int_t jseed = kNPlanes*trackIndex+iLayer;
2038 dseed[iLayer] = new AliTRDseedV1(sseed[jseed]);
2039 dseed[iLayer]->SetOwner();
2040 nclusters += sseed[jseed].GetN2();
2041 if(!sseed[jseed].IsOK()) continue;
2042 for(int ilab=0; ilab<2; ilab++){
2043 if(sseed[jseed].GetLabels(ilab) < 0) continue;
2044 labels[nlab] = sseed[jseed].GetLabels(ilab);
2049 for (Int_t itime = 0; itime < fgNTimeBins; itime++) {
2050 if(!sseed[jseed].IsUsable(itime)) continue;
2052 Int_t tindex = 0, ilab = 0;
2053 while(ilab<3 && (tindex = sseed[jseed].GetClusters(itime)->GetLabel(ilab)) >= 0){
2054 labelsall[nlabelsall++] = tindex;
2059 Freq(nlab,labels,outlab,kFALSE);
2060 Int_t label = outlab[0];
2061 Int_t frequency = outlab[1];
2062 Freq(nlabelsall,labelsall,outlab,kFALSE);
2063 Int_t label1 = outlab[0];
2064 Int_t label2 = outlab[2];
2065 Float_t fakeratio = (naccepted - outlab[1]) / Float_t(naccepted);
2067 //Int_t eventNrInFile = esd->GetEventNumberInFile();
2068 //AliInfo(Form("Number of clusters %d.", nclusters));
2069 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2070 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2071 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2072 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2073 cstreamer << "Clusters2TracksStack"
2074 << "EventNumber=" << eventNumber
2075 << "TrackNumber=" << trackNumber
2076 << "CandidateNumber=" << candidateNumber
2077 << "Iter=" << fSieveSeeding
2078 << "Like=" << fTrackQuality[trackIndex]
2079 << "S0.=" << dseed[0]
2080 << "S1.=" << dseed[1]
2081 << "S2.=" << dseed[2]
2082 << "S3.=" << dseed[3]
2083 << "S4.=" << dseed[4]
2084 << "S5.=" << dseed[5]
2085 << "p0=" << trackParams[0]
2086 << "p1=" << trackParams[1]
2087 << "p2=" << trackParams[2]
2088 << "p3=" << trackParams[3]
2089 << "p4=" << trackParams[4]
2090 << "p5=" << trackParams[5]
2091 << "p6=" << trackParams[6]
2092 << "Label=" << label
2093 << "Label1=" << label1
2094 << "Label2=" << label2
2095 << "FakeRatio=" << fakeratio
2096 << "Freq=" << frequency
2098 << "NLayers=" << nlayers
2099 << "Findable=" << findable
2100 << "NUsed=" << nused
2104 AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
2106 AliWarning("Fail to build a TRD Track.");
2110 //AliInfo("End of MakeTrack()");
2111 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2112 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2113 esdTrack->SetLabel(track->GetLabel());
2114 track->UpdateESDtrack(esdTrack);
2115 // write ESD-friends if neccessary
2116 if (fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 0){
2117 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2118 calibTrack->SetOwner();
2119 esdTrack->AddCalibObject(calibTrack);
2122 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
2126 } while(jSieve<5 && candidates); // end track candidates sieve
2127 if(!ntracks1) break;
2129 // increment counters
2130 ntracks2 += ntracks1;
2132 if(fReconstructor->IsHLT()) break;
2135 // Rebuild plane configurations and indices taking only unused clusters into account
2136 quality = BuildSeedingConfigs(stack, configs);
2137 if(quality < 1.E-7) break; //fReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
2139 for(Int_t ip = 0; ip < kNPlanes; ip++){
2140 if(!(chamber = stack[ip])) continue;
2141 chamber->Build(fGeom, cal);//Indices(fSieveSeeding);
2144 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
2145 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2147 } while(fSieveSeeding<10); // end stack clusters sieve
2151 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2156 //___________________________________________________________________
2157 Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
2160 // Assign probabilities to chambers according to their
2161 // capability of producing seeds.
2165 // layers : Array of stack propagation layers for all 6 chambers in one stack
2166 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2167 // for details) in the decreasing order of their seeding probabilities.
2171 // Return top configuration quality
2173 // Detailed description:
2175 // To each chamber seeding configuration (see GetSeedingConfig() for
2176 // the list of all configurations) one defines 2 quality factors:
2177 // - an apriori topological quality (see GetSeedingConfig() for details) and
2178 // - a data quality based on the uniformity of the distribution of
2179 // clusters over the x range (time bins population). See CookChamberQA() for details.
2180 // The overall chamber quality is given by the product of this 2 contributions.
2183 Double_t chamberQ[kNPlanes];
2184 AliTRDtrackingChamber *chamber = 0x0;
2185 for(int iplane=0; iplane<kNPlanes; iplane++){
2186 if(!(chamber = stack[iplane])) continue;
2187 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2190 Double_t tconfig[kNConfigs];
2192 for(int iconf=0; iconf<kNConfigs; iconf++){
2193 GetSeedingConfig(iconf, planes);
2194 tconfig[iconf] = fgTopologicQA[iconf];
2195 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2198 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
2199 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
2200 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2201 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2203 return tconfig[configs[0]];
2206 //____________________________________________________________________
2207 Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *sseed, Int_t *ipar)
2210 // Make tracklet seeds in the TRD stack.
2213 // layers : Array of stack propagation layers containing clusters
2214 // sseed : Array of empty tracklet seeds. On exit they are filled.
2215 // ipar : Control parameters:
2216 // ipar[0] -> seeding chambers configuration
2217 // ipar[1] -> stack index
2218 // ipar[2] -> number of track candidates found so far
2221 // Number of tracks candidates found.
2223 // Detailed description
2225 // The following steps are performed:
2226 // 1. Select seeding layers from seeding chambers
2227 // 2. Select seeding clusters from the seeding AliTRDpropagationLayerStack.
2228 // The clusters are taken from layer 3, layer 0, layer 1 and layer 2, in
2229 // this order. The parameters controling the range of accepted clusters in
2230 // layer 0, 1, and 2 are defined in AliTRDchamberTimeBin::BuildCond().
2231 // 3. Helix fit of the cluster set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**))
2232 // 4. Initialize seeding tracklets in the seeding chambers.
2234 // Chi2 in the Y direction less than threshold ... (1./(3. - sLayer))
2235 // Chi2 in the Z direction less than threshold ... (1./(3. - sLayer))
2236 // 6. Attach clusters to seeding tracklets and find linear approximation of
2237 // the tracklet (see AliTRDseedV1::AttachClustersIter()). The number of used
2238 // clusters used by current seeds should not exceed ... (25).
2240 // All 4 seeding tracklets should be correctly constructed (see
2241 // AliTRDseedV1::AttachClustersIter())
2242 // 8. Helix fit of the seeding tracklets
2244 // Likelihood calculation of the fit. (See AliTRDtrackerV1::CookLikelihood() for details)
2245 // 10. Extrapolation of the helix fit to the other 2 chambers:
2246 // a) Initialization of extrapolation tracklet with fit parameters
2247 // b) Helix fit of tracklets
2248 // c) Attach clusters and linear interpolation to extrapolated tracklets
2249 // d) Helix fit of tracklets
2250 // 11. Improve seeding tracklets quality by reassigning clusters.
2251 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
2252 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2253 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2254 // 14. Cooking labels for tracklets. Should be done only for MC
2255 // 15. Register seeds.
2258 AliTRDtrackingChamber *chamber = 0x0;
2259 AliTRDcluster *c[kNSeedPlanes] = {0x0, 0x0, 0x0, 0x0}; // initilize seeding clusters
2260 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
2261 Int_t ncl, mcl; // working variable for looping over clusters
2262 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2264 // chi2[0] = tracklet chi2 on the Z direction
2265 // chi2[1] = tracklet chi2 on the R direction
2268 // Default positions for the anode wire in all 6 Layers in case of a stack with missing clusters
2269 // Positions taken using cosmic data taken with SM3 after rebuild
2270 Double_t x_def[kNPlanes] = {300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
2272 // this should be data member of AliTRDtrack
2273 Double_t seedQuality[kMaxTracksStack];
2275 // unpack control parameters
2276 Int_t config = ipar[0];
2277 Int_t ntracks = ipar[1];
2278 Int_t istack = ipar[2];
2279 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
2280 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
2283 // Init chambers geometry
2284 Double_t hL[kNPlanes]; // Tilting angle
2285 Float_t padlength[kNPlanes]; // pad lenghts
2286 AliTRDpadPlane *pp = 0x0;
2287 for(int iplane=0; iplane<kNPlanes; iplane++){
2288 pp = fGeom->GetPadPlane(iplane, istack);
2289 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
2290 padlength[iplane] = pp->GetLengthIPad();
2293 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
2294 AliInfo(Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
2297 // Build seeding layers
2300 for(int isl=0; isl<kNSeedPlanes; isl++){
2301 if(!(chamber = stack[planes[isl]])) continue;
2302 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fReconstructor)) continue;
2305 if(nlayers < 4) return 0;
2308 // Start finding seeds
2309 Double_t cond0[4], cond1[4], cond2[4];
2311 while((c[3] = (*fSeedTB[3])[icl++])){
2313 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2314 fSeedTB[0]->GetClusters(cond0, index, ncl);
2315 //printf("Found c[3] candidates 0 %d\n", ncl);
2318 c[0] = (*fSeedTB[0])[index[jcl++]];
2320 Double_t dx = c[3]->GetX() - c[0]->GetX();
2321 Double_t theta = (c[3]->GetZ() - c[0]->GetZ())/dx;
2322 Double_t phi = (c[3]->GetY() - c[0]->GetY())/dx;
2323 fSeedTB[1]->BuildCond(c[0], cond1, 1, theta, phi);
2324 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
2325 //printf("Found c[0] candidates 1 %d\n", mcl);
2329 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2331 fSeedTB[2]->BuildCond(c[1], cond2, 2, theta, phi);
2332 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2333 //printf("Found c[1] candidate 2 %p\n", c[2]);
2336 // AliInfo("Seeding clusters found. Building seeds ...");
2337 // for(Int_t i = 0; i < kNSeedPlanes; i++) printf("%i. coordinates: x = %6.3f, y = %6.3f, z = %6.3f\n", i, c[i]->GetX(), c[i]->GetY(), c[i]->GetZ());
2339 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
2343 AliTRDseedV1 *tseed = &cseed[0];
2344 AliTRDtrackingChamber **cIter = &stack[0];
2345 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2346 tseed->SetDetector((*cIter) ? (*cIter)->GetDetector() : -1);
2347 tseed->SetTilt(hL[iLayer]);
2348 tseed->SetPadLength(padlength[iLayer]);
2349 tseed->SetReconstructor(fReconstructor);
2350 tseed->SetX0((*cIter) ? (*cIter)->GetX() : x_def[iLayer]);
2351 tseed->Init(GetRiemanFitter());
2354 Bool_t isFake = kFALSE;
2355 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
2356 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2357 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2358 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2361 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2363 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2364 Int_t ll = c[3]->GetLabel(0);
2365 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2366 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2367 AliRieman *rim = GetRiemanFitter();
2368 TTreeSRedirector &cs0 = *fgDebugStreamer;
2370 <<"EventNumber=" << eventNumber
2371 <<"CandidateNumber=" << candidateNumber
2372 <<"isFake=" << isFake
2373 <<"config=" << config
2375 <<"chi2z=" << chi2[0]
2376 <<"chi2y=" << chi2[1]
2377 <<"Y2exp=" << cond2[0]
2378 <<"Z2exp=" << cond2[1]
2379 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2380 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2381 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2382 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2383 <<"yref0=" << yref[0]
2384 <<"yref1=" << yref[1]
2385 <<"yref2=" << yref[2]
2386 <<"yref3=" << yref[3]
2391 <<"Seed0.=" << &cseed[planes[0]]
2392 <<"Seed1.=" << &cseed[planes[1]]
2393 <<"Seed2.=" << &cseed[planes[2]]
2394 <<"Seed3.=" << &cseed[planes[3]]
2395 <<"RiemanFitter.=" << rim
2398 if(chi2[0] > fReconstructor->GetRecoParam() ->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
2399 // //AliInfo(Form("Failed chi2 filter on chi2Z [%f].", chi2[0]));
2400 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2403 if(chi2[1] > fReconstructor->GetRecoParam() ->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
2404 // //AliInfo(Form("Failed chi2 filter on chi2Y [%f].", chi2[1]));
2405 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2408 //AliInfo("Passed chi2 filter.");
2410 // try attaching clusters to tracklets
2413 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2414 Int_t jLayer = planes[iLayer];
2415 if(!cseed[jLayer].AttachClustersIter(stack[jLayer], 5., kFALSE, c[iLayer])) continue;
2416 nUsedCl += cseed[jLayer].GetNUsed();
2417 if(nUsedCl > 25) break;
2421 if(mlayers < kNSeedPlanes){
2422 //AliInfo(Form("Failed updating all seeds %d [%d].", mlayers, kNSeedPlanes));
2423 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2427 // temporary exit door for the HLT
2428 if(fReconstructor->IsHLT()){
2429 // attach clusters to extrapolation chambers
2430 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2431 Int_t jLayer = planesExt[iLayer];
2432 if(!(chamber = stack[jLayer])) continue;
2433 cseed[jLayer].AttachClustersIter(chamber, 1000.);
2435 fTrackQuality[ntracks] = 1.; // dummy value
2437 if(ntracks == kMaxTracksStack) return ntracks;
2443 // fit tracklets and cook likelihood
2444 FitTiltedRieman(&cseed[0], kTRUE);// Update Seeds and calculate Likelihood
2445 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
2447 if (TMath::Log(1.E-9 + like) < fReconstructor->GetRecoParam() ->GetTrackLikelihood()){
2448 //AliInfo(Form("Failed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2449 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2452 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2454 // book preliminary results
2455 seedQuality[ntracks] = like;
2456 fSeedLayer[ntracks] = config;/*sLayer;*/
2458 // attach clusters to the extrapolation seeds
2459 Int_t nusedf = 0; // debug value
2460 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2461 Int_t jLayer = planesExt[iLayer];
2462 if(!(chamber = stack[jLayer])) continue;
2464 // fit extrapolated seed
2465 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2466 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2467 AliTRDseedV1 pseed = cseed[jLayer];
2468 if(!pseed.AttachClustersIter(chamber, 1000.)) continue;
2469 cseed[jLayer] = pseed;
2470 nusedf += cseed[jLayer].GetNUsed(); // debug value
2471 FitTiltedRieman(cseed, kTRUE);
2474 // AliInfo("Extrapolation done.");
2475 // Debug Stream containing all the 6 tracklets
2476 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
2477 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2478 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2479 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2480 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2481 cstreamer << "MakeSeeds1"
2482 << "EventNumber=" << eventNumber
2483 << "CandidateNumber=" << candidateNumber
2484 << "S0.=" << &cseed[0]
2485 << "S1.=" << &cseed[1]
2486 << "S2.=" << &cseed[2]
2487 << "S3.=" << &cseed[3]
2488 << "S4.=" << &cseed[4]
2489 << "S5.=" << &cseed[5]
2490 << "FitterT.=" << tiltedRieman
2494 if(fReconstructor->GetRecoParam()->HasImproveTracklets() && ImproveSeedQuality(stack, cseed) < 4){
2495 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2498 //AliInfo("Improve seed quality done.");
2500 // fit full track and cook likelihoods
2501 // Double_t curv = FitRieman(&cseed[0], chi2);
2502 // Double_t chi2ZF = chi2[0] / TMath::Max((mlayers - 3.), 1.);
2503 // Double_t chi2RF = chi2[1] / TMath::Max((mlayers - 3.), 1.);
2505 // do the final track fitting (Once with vertex constraint and once without vertex constraint)
2506 Double_t chi2Vals[3];
2507 chi2Vals[0] = FitTiltedRieman(&cseed[0], kFALSE);
2508 if(fReconstructor->GetRecoParam()->IsVertexConstrained())
2509 chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ()); // Do Vertex Constrained fit if desired
2512 chi2Vals[2] = GetChi2Z(&cseed[0]) / TMath::Max((mlayers - 3.), 1.);
2513 // Chi2 definitions in testing stage
2514 //chi2Vals[2] = GetChi2ZTest(&cseed[0]);
2515 fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
2516 //AliInfo("Hyperplane fit done\n");
2518 // finalize tracklets
2522 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
2523 if (!cseed[iLayer].IsOK()) continue;
2525 if (cseed[iLayer].GetLabels(0) >= 0) {
2526 labels[nlab] = cseed[iLayer].GetLabels(0);
2530 if (cseed[iLayer].GetLabels(1) >= 0) {
2531 labels[nlab] = cseed[iLayer].GetLabels(1);
2535 Freq(nlab,labels,outlab,kFALSE);
2536 Int_t label = outlab[0];
2537 Int_t frequency = outlab[1];
2538 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
2539 cseed[iLayer].SetFreq(frequency);
2540 cseed[iLayer].SetChi2Z(chi2[1]);
2543 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
2544 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2545 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2546 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2547 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2548 TLinearFitter *fitterT = GetTiltedRiemanFitter();
2550 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2551 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2553 cstreamer << "MakeSeeds2"
2554 << "EventNumber=" << eventNumber
2555 << "CandidateNumber=" << candidateNumber
2556 << "Chi2TR=" << chi2Vals[0]
2557 << "Chi2TC=" << chi2Vals[1]
2558 << "Nlayers=" << mlayers
2559 << "NClusters=" << ncls
2560 << "NUsedS=" << nUsedCl
2561 << "NUsed=" << nusedf
2563 << "S0.=" << &cseed[0]
2564 << "S1.=" << &cseed[1]
2565 << "S2.=" << &cseed[2]
2566 << "S3.=" << &cseed[3]
2567 << "S4.=" << &cseed[4]
2568 << "S5.=" << &cseed[5]
2569 << "Label=" << label
2570 << "Freq=" << frequency
2571 << "FitterT.=" << fitterT
2572 << "FitterTC.=" << fitterTC
2577 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2578 if(ntracks == kMaxTracksStack){
2579 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2590 //_____________________________________________________________________________
2591 AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 *seeds, Double_t *params)
2594 // Build a TRD track out of tracklet candidates
2597 // seeds : array of tracklets
2598 // params : track parameters (see MakeSeeds() function body for a detailed description)
2603 // Detailed description
2605 // To be discussed with Marian !!
2609 Double_t alpha = AliTRDgeometry::GetAlpha();
2610 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
2614 c[ 1] = 0.0; c[ 2] = 2.0;
2615 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02;
2616 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1;
2617 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[5]*params[5]*0.01;
2619 AliTRDtrackV1 track(seeds, ¶ms[1], c, params[0], params[6]*alpha+shift);
2620 track.PropagateTo(params[0]-5.0);
2621 if(fReconstructor->IsHLT()){
2622 AliTRDseedV1 *ptrTracklet = 0x0;
2623 for(Int_t ip=0; ip<kNPlanes; ip++){
2624 track.UnsetTracklet(ip);
2625 ptrTracklet = SetTracklet(&seeds[ip]);
2626 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
2628 return SetTrack(&track);
2631 track.ResetCovariance(1);
2632 Int_t nc = TMath::Abs(FollowBackProlongation(track));
2633 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 5){
2634 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2635 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2636 Double_t p[5]; // Track Params for the Debug Stream
2637 track.GetExternalParameters(params[0], p);
2638 TTreeSRedirector &cs = *fgDebugStreamer;
2640 << "EventNumber=" << eventNumber
2641 << "CandidateNumber=" << candidateNumber
2643 << "X=" << params[0]
2649 << "Yin=" << params[1]
2650 << "Zin=" << params[2]
2651 << "snpin=" << params[3]
2652 << "tndin=" << params[4]
2653 << "crvin=" << params[5]
2654 << "track.=" << &track
2657 if (nc < 30) return 0x0;
2659 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
2660 ptrTrack->SetReconstructor(fReconstructor);
2661 ptrTrack->CookLabel(.9);
2663 // computes PID for track
2664 ptrTrack->CookPID();
2665 // update calibration references using this track
2666 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
2668 AliInfo("Could not get Calibra instance\n");
2669 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(ptrTrack);
2675 //____________________________________________________________________
2676 Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed)
2679 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
2682 // layers : Array of propagation layers for a stack/supermodule
2683 // cseed : Array of 6 seeding tracklets which has to be improved
2686 // cssed : Improved seeds
2688 // Detailed description
2690 // Iterative procedure in which new clusters are searched for each
2691 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
2692 // can be maximized. If some optimization is found the old seeds are replaced.
2697 // make a local working copy
2698 AliTRDtrackingChamber *chamber = 0x0;
2699 AliTRDseedV1 bseed[6];
2701 for (Int_t jLayer = 0; jLayer < 6; jLayer++) bseed[jLayer] = cseed[jLayer];
2703 Float_t lastquality = 10000.0;
2704 Float_t lastchi2 = 10000.0;
2705 Float_t chi2 = 1000.0;
2707 for (Int_t iter = 0; iter < 4; iter++) {
2708 Float_t sumquality = 0.0;
2709 Float_t squality[6];
2710 Int_t sortindexes[6];
2712 for (Int_t jLayer = 0; jLayer < 6; jLayer++) {
2713 squality[jLayer] = bseed[jLayer].IsOK() ? bseed[jLayer].GetQuality(kTRUE) : 1000.;
2714 sumquality += squality[jLayer];
2716 if ((sumquality >= lastquality) || (chi2 > lastchi2)) break;
2719 lastquality = sumquality;
2721 if (iter > 0) for (Int_t jLayer = 0; jLayer < 6; jLayer++) cseed[jLayer] = bseed[jLayer];
2723 TMath::Sort(6, squality, sortindexes, kFALSE);
2724 for (Int_t jLayer = 5; jLayer > 1; jLayer--) {
2725 Int_t bLayer = sortindexes[jLayer];
2726 if(!(chamber = stack[bLayer])) continue;
2727 bseed[bLayer].AttachClustersIter(chamber, squality[bLayer], kTRUE);
2728 if(bseed[bLayer].IsOK()) nLayers++;
2731 chi2 = FitTiltedRieman(bseed, kTRUE);
2732 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 7){
2733 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2734 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2735 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2736 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2737 cstreamer << "ImproveSeedQuality"
2738 << "EventNumber=" << eventNumber
2739 << "CandidateNumber=" << candidateNumber
2740 << "Iteration=" << iter
2741 << "S0.=" << &bseed[0]
2742 << "S1.=" << &bseed[1]
2743 << "S2.=" << &bseed[2]
2744 << "S3.=" << &bseed[3]
2745 << "S4.=" << &bseed[4]
2746 << "S5.=" << &bseed[5]
2747 << "FitterT.=" << tiltedRieman
2752 // we are sure that at least 2 tracklets are OK !
2756 //_________________________________________________________________________
2757 Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Double_t *chi2){
2759 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
2760 // the track selection
2761 // The likelihood value containes:
2762 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
2763 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
2764 // For all Parameters an exponential dependency is used
2766 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
2767 // - Array of chi2 values:
2768 // * Non-Constrained Tilted Riemann fit
2769 // * Vertex-Constrained Tilted Riemann fit
2770 // * z-Direction from Linear fit
2771 // Output: - The calculated track likelihood
2776 Double_t sumdaf = 0, nLayers = 0;
2777 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
2778 if(!tracklets[iLayer].IsOK()) continue;
2779 sumdaf += TMath::Abs((tracklets[iLayer].GetYfit(1) - tracklets[iLayer].GetYref(1))/ tracklets[iLayer].GetSigmaY2());
2782 sumdaf /= Float_t (nLayers - 2.0);
2784 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14); // Chi2Z
2785 Double_t likeChi2TC = (fReconstructor->GetRecoParam() ->IsVertexConstrained()) ?
2786 TMath::Exp(-chi2[1] * 0.677) : 1; // Constrained Tilted Riemann
2787 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.78); // Non-constrained Tilted Riemann
2788 Double_t likeAF = TMath::Exp(-sumdaf * 3.23);
2789 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeAF;
2791 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
2792 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2793 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2794 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2795 cstreamer << "CalculateTrackLikelihood0"
2796 << "EventNumber=" << eventNumber
2797 << "CandidateNumber=" << candidateNumber
2798 << "LikeChi2Z=" << likeChi2Z
2799 << "LikeChi2TR=" << likeChi2TR
2800 << "LikeChi2TC=" << likeChi2TC
2801 << "LikeAF=" << likeAF
2802 << "TrackLikelihood=" << trackLikelihood
2806 return trackLikelihood;
2809 //____________________________________________________________________
2810 Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
2813 // Calculate the probability of this track candidate.
2816 // cseeds : array of candidate tracklets
2817 // planes : array of seeding planes (see seeding configuration)
2818 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
2823 // Detailed description
2825 // The track quality is estimated based on the following 4 criteria:
2826 // 1. precision of the rieman fit on the Y direction (likea)
2827 // 2. chi2 on the Y direction (likechi2y)
2828 // 3. chi2 on the Z direction (likechi2z)
2829 // 4. number of attached clusters compared to a reference value
2830 // (see AliTRDrecoParam::fkFindable) (likeN)
2832 // The distributions for each type of probabilities are given below as of
2833 // (date). They have to be checked to assure consistency of estimation.
2836 // ratio of the total number of clusters/track which are expected to be found by the tracker.
2837 const AliTRDrecoParam *fRecoPars = fReconstructor->GetRecoParam();
2839 Double_t chi2y = GetChi2Y(&cseed[0]);
2840 Double_t chi2z = GetChi2Z(&cseed[0]);
2842 Float_t nclusters = 0.;
2843 Double_t sumda = 0.;
2844 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
2845 Int_t jlayer = planes[ilayer];
2846 nclusters += cseed[jlayer].GetN2();
2847 sumda += TMath::Abs(cseed[jlayer].GetYfitR(1) - cseed[jlayer].GetYref(1));
2851 Double_t likea = TMath::Exp(-sumda * fRecoPars->GetPhiCut());
2852 Double_t likechi2y = 0.0000000001;
2853 if (fReconstructor->IsCosmic() || chi2y < 0.5) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fRecoPars->GetChi2YCut());
2854 Double_t likechi2z = TMath::Exp(-chi2z * fRecoPars->GetChi2ZCut());
2855 Double_t likeN = TMath::Exp(-(fRecoPars->GetNMeanClusters() - nclusters) / fRecoPars->GetNSigmaClusters());
2856 Double_t like = likea * likechi2y * likechi2z * likeN;
2858 // AliInfo(Form("sumda(%f) chi2[0](%f) chi2[1](%f) likea(%f) likechi2y(%f) likechi2z(%f) nclusters(%d) likeN(%f)", sumda, chi2[0], chi2[1], likea, likechi2y, likechi2z, nclusters, likeN));
2859 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 2){
2860 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2861 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2862 Int_t nTracklets = 0; Float_t mean_ncls = 0;
2863 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
2864 if(!cseed[iseed].IsOK()) continue;
2866 mean_ncls += cseed[iseed].GetN2();
2868 if(nTracklets) mean_ncls /= nTracklets;
2869 // The Debug Stream contains the seed
2870 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2871 cstreamer << "CookLikelihood"
2872 << "EventNumber=" << eventNumber
2873 << "CandidateNumber=" << candidateNumber
2874 << "tracklet0.=" << &cseed[0]
2875 << "tracklet1.=" << &cseed[1]
2876 << "tracklet2.=" << &cseed[2]
2877 << "tracklet3.=" << &cseed[3]
2878 << "tracklet4.=" << &cseed[4]
2879 << "tracklet5.=" << &cseed[5]
2880 << "sumda=" << sumda
2881 << "chi2y=" << chi2y
2882 << "chi2z=" << chi2z
2883 << "likea=" << likea
2884 << "likechi2y=" << likechi2y
2885 << "likechi2z=" << likechi2z
2886 << "nclusters=" << nclusters
2887 << "likeN=" << likeN
2889 << "meanncls=" << mean_ncls
2898 //____________________________________________________________________
2899 void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
2902 // Map seeding configurations to detector planes.
2905 // iconfig : configuration index
2906 // planes : member planes of this configuration. On input empty.
2909 // planes : contains the planes which are defining the configuration
2911 // Detailed description
2913 // Here is the list of seeding planes configurations together with
2914 // their topological classification:
2932 // The topologic quality is modeled as follows:
2933 // 1. The general model is define by the equation:
2934 // p(conf) = exp(-conf/2)
2935 // 2. According to the topologic classification, configurations from the same
2936 // class are assigned the agerage value over the model values.
2937 // 3. Quality values are normalized.
2939 // The topologic quality distribution as function of configuration is given below:
2941 // <img src="gif/topologicQA.gif">
2946 case 0: // 5432 TQ 0
2952 case 1: // 4321 TQ 0
2958 case 2: // 3210 TQ 0
2964 case 3: // 5321 TQ 1
2970 case 4: // 4210 TQ 1
2976 case 5: // 5431 TQ 1
2982 case 6: // 4320 TQ 1
2988 case 7: // 5430 TQ 2
2994 case 8: // 5210 TQ 2
3000 case 9: // 5421 TQ 3
3006 case 10: // 4310 TQ 3
3012 case 11: // 5410 TQ 4
3018 case 12: // 5420 TQ 5
3024 case 13: // 5320 TQ 5
3030 case 14: // 5310 TQ 5
3039 //____________________________________________________________________
3040 void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
3043 // Returns the extrapolation planes for a seeding configuration.
3046 // iconfig : configuration index
3047 // planes : planes which are not in this configuration. On input empty.
3050 // planes : contains the planes which are not in the configuration
3052 // Detailed description
3056 case 0: // 5432 TQ 0
3060 case 1: // 4321 TQ 0
3064 case 2: // 3210 TQ 0
3068 case 3: // 5321 TQ 1
3072 case 4: // 4210 TQ 1
3076 case 5: // 5431 TQ 1
3080 case 6: // 4320 TQ 1
3084 case 7: // 5430 TQ 2
3088 case 8: // 5210 TQ 2
3092 case 9: // 5421 TQ 3
3096 case 10: // 4310 TQ 3
3100 case 11: // 5410 TQ 4
3104 case 12: // 5420 TQ 5
3108 case 13: // 5320 TQ 5
3112 case 14: // 5310 TQ 5
3119 //____________________________________________________________________
3120 AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3122 Int_t ncls = fClusters->GetEntriesFast();
3123 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : 0x0;
3126 //____________________________________________________________________
3127 AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3129 Int_t ntrklt = fTracklets->GetEntriesFast();
3130 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : 0x0;
3133 //____________________________________________________________________
3134 AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3136 Int_t ntrk = fTracks->GetEntriesFast();
3137 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : 0x0;
3140 //____________________________________________________________________
3141 Float_t AliTRDtrackerV1::CalculateReferenceX(AliTRDseedV1 *tracklets){
3143 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3144 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3145 // are taken into account
3147 // Parameters: - Array of tracklets(AliTRDseedV1)
3149 // Output: - The reference x-position(Float_t)
3151 Int_t nDistances = 0;
3152 Float_t meanDistance = 0.;
3153 Int_t startIndex = 5;
3154 for(Int_t il =5; il > 0; il--){
3155 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3156 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3157 meanDistance += xdiff;
3160 if(tracklets[il].IsOK()) startIndex = il;
3162 if(tracklets[0].IsOK()) startIndex = 0;
3164 // We should normally never get here
3165 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3166 Int_t iok = 0, idiff = 0;
3167 // This attempt is worse and should be avoided:
3168 // check for two chambers which are OK and repeat this without taking the mean value
3169 // Strategy avoids a division by 0;
3170 for(Int_t il = 5; il >= 0; il--){
3171 if(tracklets[il].IsOK()){
3172 xpos[iok] = tracklets[il].GetX0();
3176 if(iok) idiff++; // to get the right difference;
3180 meanDistance = (xpos[0] - xpos[1])/idiff;
3183 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3188 meanDistance /= nDistances;
3190 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3193 //_____________________________________________________________________________
3194 Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3195 , Int_t *outlist, Bool_t down)
3198 // Sort eleements according occurancy
3199 // The size of output array has is 2*n
3206 Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3207 Int_t *sindexF = new Int_t[2*n];
3208 for (Int_t i = 0; i < n; i++) {
3212 TMath::Sort(n,inlist,sindexS,down);
3214 Int_t last = inlist[sindexS[0]];
3217 sindexF[0+n] = last;
3221 for (Int_t i = 1; i < n; i++) {
3222 val = inlist[sindexS[i]];
3224 sindexF[countPos]++;
3228 sindexF[countPos+n] = val;
3229 sindexF[countPos]++;
3237 // Sort according frequency
3238 TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3240 for (Int_t i = 0; i < countPos; i++) {
3241 outlist[2*i ] = sindexF[sindexS[i]+n];
3242 outlist[2*i+1] = sindexF[sindexS[i]];
3253 //____________________________________________________________________
3254 void AliTRDtrackerV1::SetReconstructor(const AliTRDReconstructor *rec)
3256 fReconstructor = rec;
3257 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) > 1){
3258 if(!fgDebugStreamer){
3259 TDirectory *savedir = gDirectory;
3260 fgDebugStreamer = new TTreeSRedirector("TRD.TrackerDebug.root");
3266 //_____________________________________________________________________________
3267 Float_t AliTRDtrackerV1::GetChi2Y(AliTRDseedV1 *tracklets) const
3269 // Chi2 definition on y-direction
3272 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
3273 if(!tracklets[ipl].IsOK()) continue;
3274 Double_t distLayer = (tracklets[ipl].GetYfit(0) - tracklets[ipl].GetYref(0));// /tracklets[ipl].GetSigmaY();
3275 chi2 += distLayer * distLayer;
3280 //____________________________________________________________________
3281 void AliTRDtrackerV1::ResetSeedTB()
3283 // reset buffer for seeding time bin layers. If the time bin
3284 // layers are not allocated this function allocates them
3286 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3287 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3288 else fSeedTB[isl]->Clear();
3292 //_____________________________________________________________________________
3293 Float_t AliTRDtrackerV1::GetChi2Z(AliTRDseedV1 *tracklets) const
3295 // Calculates normalized chi2 in z-direction
3298 // chi2 = Sum ((z - zmu)/sigma)^2
3299 // Sigma for the z direction is defined as half of the padlength
3300 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
3301 if(!tracklets[ipl].IsOK()) continue;
3302 Double_t distLayer = (tracklets[ipl].GetMeanz() - tracklets[ipl].GetZref(0)); // /(tracklets[ipl].GetPadLength()/2);
3303 chi2 += distLayer * distLayer;
3308 ///////////////////////////////////////////////////////
3310 // Resources of class AliTRDLeastSquare //
3312 ///////////////////////////////////////////////////////
3314 //_____________________________________________________________________________
3315 AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
3317 // Constructor of the nested class AliTRDtrackFitterLeastSquare
3319 memset(fParams, 0, sizeof(Double_t) * 2);
3320 memset(fSums, 0, sizeof(Double_t) * 5);
3321 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
3325 //_____________________________________________________________________________
3326 void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(Double_t *x, Double_t y, Double_t sigmaY){
3328 // Adding Point to the fitter
3330 Double_t weight = 1/(sigmaY * sigmaY);
3332 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3334 fSums[1] += weight * xpt;
3335 fSums[2] += weight * y;
3336 fSums[3] += weight * xpt * y;
3337 fSums[4] += weight * xpt * xpt;
3338 fSums[5] += weight * y * y;
3341 //_____________________________________________________________________________
3342 void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(Double_t *x, Double_t y, Double_t sigmaY){
3344 // Remove Point from the sample
3346 Double_t weight = 1/(sigmaY * sigmaY);
3349 fSums[1] -= weight * xpt;
3350 fSums[2] -= weight * y;
3351 fSums[3] -= weight * xpt * y;
3352 fSums[4] -= weight * xpt * xpt;
3353 fSums[5] -= weight * y * y;
3356 //_____________________________________________________________________________
3357 void AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
3359 // Evaluation of the fit:
3360 // Calculation of the parameters
3361 // Calculation of the covariance matrix
3364 Double_t denominator = fSums[0] * fSums[4] - fSums[1] *fSums[1];
3365 if(denominator==0) return;
3367 // for(Int_t isum = 0; isum < 5; isum++)
3368 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3369 // printf("denominator = %f\n", denominator);
3370 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/ denominator;
3371 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2]) / denominator;
3372 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3374 // Covariance matrix
3375 fCovarianceMatrix[0] = fSums[4] - fSums[1] * fSums[1] / fSums[0];
3376 fCovarianceMatrix[1] = fSums[5] - fSums[2] * fSums[2] / fSums[0];
3377 fCovarianceMatrix[2] = fSums[3] - fSums[1] * fSums[2] / fSums[0];
3380 //_____________________________________________________________________________
3381 Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(Double_t *xpos) const {
3383 // Returns the Function value of the fitted function at a given x-position
3385 return fParams[0] + fParams[1] * (*xpos);
3388 //_____________________________________________________________________________
3389 void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
3391 // Copies the values of the covariance matrix into the storage
3393 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);