]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrackerV1.cxx
Added #include <cassert> by request of Mateusz Ploskon
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
CommitLineData
bcb6fb78 1
e4f2f73d 2/**************************************************************************
972ef65e 3* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4* *
5* Author: The ALICE Off-line Project. *
6* Contributors are mentioned in the code where appropriate. *
7* *
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**************************************************************************/
e4f2f73d 16
17/* $Id$ */
18
19///////////////////////////////////////////////////////////////////////////////
20// //
21// Track finder //
22// //
23// Authors: //
24// Alex Bercuci <A.Bercuci@gsi.de> //
25// Markus Fasel <M.Fasel@gsi.de> //
26// //
27///////////////////////////////////////////////////////////////////////////////
28
bb56afff 29// #include <Riostream.h>
30// #include <stdio.h>
31// #include <string.h>
e4f2f73d 32
33#include <TBranch.h>
bb56afff 34#include <TDirectory.h>
e4f2f73d 35#include <TLinearFitter.h>
e4f2f73d 36#include <TTree.h>
37#include <TClonesArray.h>
e4f2f73d 38#include <TTreeStream.h>
39
40#include "AliLog.h"
41#include "AliESDEvent.h"
bb56afff 42#include "AliGeomManager.h"
e4f2f73d 43#include "AliRieman.h"
44#include "AliTrackPointArray.h"
45
e4f2f73d 46#include "AliTRDgeometry.h"
47#include "AliTRDpadPlane.h"
e4f2f73d 48#include "AliTRDcalibDB.h"
e4f2f73d 49#include "AliTRDReconstructor.h"
50#include "AliTRDCalibraFillHisto.h"
e4f2f73d 51#include "AliTRDrecoParam.h"
bb56afff 52
53#include "AliTRDcluster.h"
e4f2f73d 54#include "AliTRDseedV1.h"
0906e73e 55#include "AliTRDtrackV1.h"
bb56afff 56#include "AliTRDtrackerV1.h"
57#include "AliTRDtrackerDebug.h"
58#include "AliTRDtrackingChamber.h"
59#include "AliTRDchamberTimeBin.h"
60
e4f2f73d 61
e4f2f73d 62
63ClassImp(AliTRDtrackerV1)
eb38ed55 64
65
66const Float_t AliTRDtrackerV1::fgkMinClustersInTrack = 0.5; //
67const Float_t AliTRDtrackerV1::fgkLabelFraction = 0.8; //
68const Double_t AliTRDtrackerV1::fgkMaxChi2 = 12.0; //
69const Double_t AliTRDtrackerV1::fgkMaxSnp = 0.95; // Maximum local sine of the azimuthal angle
70const Double_t AliTRDtrackerV1::fgkMaxStep = 2.0; // Maximal step size in propagation
d76231c8 71Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
972ef65e 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
e4f2f73d 75};
2985ffcb 76Int_t AliTRDtrackerV1::fgNTimeBins = 0;
eb38ed55 77TTreeSRedirector *AliTRDtrackerV1::fgDebugStreamer = 0x0;
78AliRieman* AliTRDtrackerV1::fgRieman = 0x0;
79TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = 0x0;
80TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = 0x0;
e4f2f73d 81
82//____________________________________________________________________
eb38ed55 83AliTRDtrackerV1::AliTRDtrackerV1()
972ef65e 84 :AliTracker()
85 ,fGeom(new AliTRDgeometry())
86 ,fClusters(0x0)
87 ,fTracklets(0x0)
88 ,fTracks(0x0)
89 ,fSieveSeeding(0)
e4f2f73d 90{
972ef65e 91 //
92 // Default constructor.
93 //
94 if (!AliTRDcalibDB::Instance()) {
95 AliFatal("Could not get calibration object");
96 }
97 fgNTimeBins = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
98
99 for (Int_t isector = 0; isector < AliTRDgeometry::kNsect; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
100
101 if(AliTRDReconstructor::StreamLevel() > 1){
102 TDirectory *savedir = gDirectory;
103 fgDebugStreamer = new TTreeSRedirector("TRD.TrackerDebug.root");
104 savedir->cd();
105 }
eb38ed55 106}
107
e4f2f73d 108//____________________________________________________________________
109AliTRDtrackerV1::~AliTRDtrackerV1()
110{
972ef65e 111 //
112 // Destructor
113 //
114
115 if(fgDebugStreamer) delete fgDebugStreamer;
116 if(fgRieman) delete fgRieman;
117 if(fgTiltedRieman) delete fgTiltedRieman;
118 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained;
119 if(fTracks) {fTracks->Delete(); delete fTracks;}
120 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
121 if(fClusters) {fClusters->Delete(); delete fClusters;}
122 if(fGeom) delete fGeom;
e4f2f73d 123}
124
125//____________________________________________________________________
126Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
127{
972ef65e 128 //
129 // Steering stand alone tracking for full TRD detector
130 //
131 // Parameters :
132 // esd : The ESD event. On output it contains
133 // the ESD tracks found in TRD.
134 //
135 // Output :
136 // Number of tracks found in the TRD detector.
137 //
138 // Detailed description
139 // 1. Launch individual SM trackers.
140 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
141 //
142
143 if(!AliTRDReconstructor::RecoParam()){
144 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
145 return 0;
146 }
147
148 //AliInfo("Start Track Finder ...");
149 Int_t ntracks = 0;
150 for(int ism=0; ism<AliTRDgeometry::kNsect; ism++){
151 // for(int ism=1; ism<2; ism++){
152 //AliInfo(Form("Processing supermodule %i ...", ism));
153 ntracks += Clusters2TracksSM(ism, esd);
154 }
155 AliInfo(Form("Number of found tracks : %d", ntracks));
156 return ntracks;
e4f2f73d 157}
158
0906e73e 159
160//_____________________________________________________________________________
eb38ed55 161Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
0906e73e 162{
972ef65e 163 //AliInfo(Form("Asking for tracklet %d", index));
0906e73e 164
972ef65e 165 if(index<0) return kFALSE;
166 AliTRDseedV1 *tracklet = 0x0;
167 if(!(tracklet = (AliTRDseedV1*)fTracklets->UncheckedAt(index))) return kFALSE;
eb38ed55 168
972ef65e 169 // get detector for this tracklet
170 AliTRDcluster *cl = 0x0;
171 Int_t ic = 0; do; while(!(cl = tracklet->GetClusters(ic++)));
172 Int_t idet = cl->GetDetector();
eb38ed55 173
972ef65e 174 Double_t local[3];
175 local[0] = tracklet->GetX0();
176 local[1] = tracklet->GetYfit(0);
177 local[2] = tracklet->GetZfit(0);
178 Double_t global[3];
179 fGeom->RotateBack(idet, local, global);
180 p.SetXYZ(global[0],global[1],global[2]);
181
182
183 // setting volume id
184 AliGeomManager::ELayerID iLayer = AliGeomManager::kTRD1;
185 switch (fGeom->GetPlane(idet)) {
186 case 0:
187 iLayer = AliGeomManager::kTRD1;
188 break;
189 case 1:
190 iLayer = AliGeomManager::kTRD2;
191 break;
192 case 2:
193 iLayer = AliGeomManager::kTRD3;
194 break;
195 case 3:
196 iLayer = AliGeomManager::kTRD4;
197 break;
198 case 4:
199 iLayer = AliGeomManager::kTRD5;
200 break;
201 case 5:
202 iLayer = AliGeomManager::kTRD6;
203 break;
204 };
205 Int_t modId = fGeom->GetSector(idet) * fGeom->Ncham() + fGeom->GetChamber(idet);
206 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
207 p.SetVolumeID(volid);
eb38ed55 208
972ef65e 209 return kTRUE;
0906e73e 210}
211
eb38ed55 212//____________________________________________________________________
213TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
214{
972ef65e 215 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
216 return fgTiltedRieman;
eb38ed55 217}
0906e73e 218
eb38ed55 219//____________________________________________________________________
220TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
221{
972ef65e 222 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
223 return fgTiltedRiemanConstrained;
eb38ed55 224}
225
226//____________________________________________________________________
227AliRieman* AliTRDtrackerV1::GetRiemanFitter()
228{
972ef65e 229 if(!fgRieman) fgRieman = new AliRieman(AliTRDtrackingChamber::kNTimeBins * AliTRDgeometry::kNplan);
230 return fgRieman;
eb38ed55 231}
232
0906e73e 233//_____________________________________________________________________________
234Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
235{
972ef65e 236 //
237 // Gets seeds from ESD event. The seeds are AliTPCtrack's found and
238 // backpropagated by the TPC tracker. Each seed is first propagated
239 // to the TRD, and then its prolongation is searched in the TRD.
240 // If sufficiently long continuation of the track is found in the TRD
241 // the track is updated, otherwise it's stored as originaly defined
242 // by the TPC tracker.
243 //
244
245 // Calibration monitor
246 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
247 if (!calibra) AliInfo("Could not get Calibra instance\n");
248
249 Int_t found = 0; // number of tracks found
250 Float_t foundMin = 20.0;
251
252 Int_t nSeed = event->GetNumberOfTracks();
253 if(!nSeed){
254 // run stand alone tracking
255 if (AliTRDReconstructor::SeedingOn()) Clusters2Tracks(event);
256 return 0;
257 }
258
259 Float_t *quality = new Float_t[nSeed];
260 Int_t *index = new Int_t[nSeed];
261 for (Int_t iSeed = 0; iSeed < nSeed; iSeed++) {
262 AliESDtrack *seed = event->GetTrack(iSeed);
263 Double_t covariance[15];
264 seed->GetExternalCovariance(covariance);
265 quality[iSeed] = covariance[0] + covariance[2];
266 }
267 // Sort tracks according to covariance of local Y and Z
268 TMath::Sort(nSeed,quality,index,kFALSE);
269
270 // Backpropagate all seeds
271 Int_t expectedClr;
272 AliTRDtrackV1 track;
273 for (Int_t iSeed = 0; iSeed < nSeed; iSeed++) {
274
275 // Get the seeds in sorted sequence
276 AliESDtrack *seed = event->GetTrack(index[iSeed]);
277
278 // Check the seed status
279 ULong_t status = seed->GetStatus();
280 if ((status & AliESDtrack::kTPCout) == 0) continue;
281 if ((status & AliESDtrack::kTRDout) != 0) continue;
282
283 // Do the back prolongation
284 Int_t lbl = seed->GetLabel();
285 new(&track) AliTRDtrackV1(*seed);
286 //track->Print();
287 track.SetSeedLabel(lbl);
288 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup); // Make backup
289 Float_t p4 = track.GetC();
290 if((expectedClr = FollowBackProlongation(track))){
291 // computes PID for track
292 track.CookPID();
293 // update calibration references using this track
294 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
295 }
296
297 if ((TMath::Abs(track.GetC() - p4) / TMath::Abs(p4) < 0.2) ||(track.Pt() > 0.8)) {
298 //
299 // Make backup for back propagation
300 //
301 Int_t foundClr = track.GetNumberOfClusters();
302 if (foundClr >= foundMin) {
303 //AliInfo(Form("Making backup track ncls [%d]...", foundClr));
304 track.CookdEdx();
305 track.CookdEdxTimBin(seed->GetID());
306 track.CookLabel(1. - fgkLabelFraction);
307 if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
0906e73e 308
0906e73e 309
972ef65e 310 // Sign only gold tracks
311 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
312 if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
313 }
314 Bool_t isGold = kFALSE;
0906e73e 315
972ef65e 316 // Full gold track
317 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
318 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
0906e73e 319
972ef65e 320 isGold = kTRUE;
321 }
0906e73e 322
972ef65e 323 // Almost gold track
324 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
325 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
326 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
327
328 isGold = kTRUE;
329 }
0906e73e 330
972ef65e 331 if ((!isGold) && (track.GetBackupTrack())) {
332 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
333 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
334 isGold = kTRUE;
335 }
336 }
337
338 //if ((track->StatusForTOF() > 0) && (track->GetNCross() == 0) && (Float_t(track->GetNumberOfClusters()) / Float_t(track->GetNExpected()) > 0.4)) {
339 //seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
340 //}
341 }
342 }
343
344 // Propagation to the TOF (I.Belikov)
345 if (track.GetStop() == kFALSE) {
346 Double_t xtof = 371.0;
347 Double_t xTOF0 = 370.0;
0906e73e 348
972ef65e 349 Double_t c2 = track.GetSnp() + track.GetC() * (xtof - track.GetX());
350 if (TMath::Abs(c2) >= 0.99) continue;
0906e73e 351
972ef65e 352 PropagateToX(track, xTOF0, fgkMaxStep);
0906e73e 353
972ef65e 354 // Energy losses taken to the account - check one more time
355 c2 = track.GetSnp() + track.GetC() * (xtof - track.GetX());
356 if (TMath::Abs(c2) >= 0.99) continue;
0906e73e 357
972ef65e 358 //if (!PropagateToX(*track,xTOF0,fgkMaxStep)) {
359 // fHBackfit->Fill(7);
360 //delete track;
361 // continue;
362 //}
363
364 Double_t ymax = xtof * TMath::Tan(0.5 * AliTRDgeometry::GetAlpha());
365 Double_t y;
366 track.GetYAt(xtof,GetBz(),y);
367 if (y > ymax) {
368 if (!track.Rotate( AliTRDgeometry::GetAlpha())) continue;
369 }else if (y < -ymax) {
370 if (!track.Rotate(-AliTRDgeometry::GetAlpha())) continue;
371 }
0906e73e 372
972ef65e 373 if (track.PropagateTo(xtof)) {
374 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
375 track.UpdateESDtrack(seed);
a23edf15 376
972ef65e 377 // Add TRD track to ESDfriendTrack
378 if (AliTRDReconstructor::StreamLevel() > 0 /*&& quality TODO*/){
379 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
380 calibTrack->SetOwner();
381 seed->AddCalibObject(calibTrack);
382 }
383 found++;
384 }
385 } else {
386 if ((track.GetNumberOfClusters() > 15) && (track.GetNumberOfClusters() > 0.5*expectedClr)) {
387 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
0906e73e 388
972ef65e 389 track.UpdateESDtrack(seed);
a23edf15 390
972ef65e 391 // Add TRD track to ESDfriendTrack
392 if (AliTRDReconstructor::StreamLevel() > 0 /*&& quality TODO*/){
393 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
394 calibTrack->SetOwner();
395 seed->AddCalibObject(calibTrack);
396 }
397 found++;
398 }
399 }
d739fd4e 400
972ef65e 401 seed->SetTRDQuality(track.StatusForTOF());
402 seed->SetTRDBudget(track.GetBudget(0));
403 }
0906e73e 404
405
972ef65e 406 AliInfo(Form("Number of seeds: %d", nSeed));
407 AliInfo(Form("Number of back propagated TRD tracks: %d", found));
eb38ed55 408
972ef65e 409 delete [] index;
410 delete [] quality;
0906e73e 411
972ef65e 412 return 0;
0906e73e 413}
414
415
416//____________________________________________________________________
417Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
418{
972ef65e 419 //
420 // Refits tracks within the TRD. The ESD event is expected to contain seeds
421 // at the outer part of the TRD.
422 // The tracks are propagated to the innermost time bin
423 // of the TRD and the ESD event is updated
424 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
425 //
426
427 Int_t nseed = 0; // contor for loaded seeds
428 Int_t found = 0; // contor for updated TRD tracks
429
430
431 AliTRDtrackV1 track;
432 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
433 AliESDtrack *seed = event->GetTrack(itrack);
434 new(&track) AliTRDtrackV1(*seed);
435
436 if (track.GetX() < 270.0) {
437 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
438 continue;
439 }
440
441 ULong_t status = seed->GetStatus();
442 if((status & AliESDtrack::kTRDout) == 0) continue;
443 if((status & AliESDtrack::kTRDin) != 0) continue;
444 nseed++;
445
446 track.ResetCovariance(50.0);
447
448 // do the propagation and processing
449 Bool_t kUPDATE = kFALSE;
450 Double_t xTPC = 250.0;
451 if(FollowProlongation(track)){
452 // Prolongate to TPC
453 if (PropagateToX(track, xTPC, fgkMaxStep)) { // -with update
d739fd4e 454 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
455 found++;
456 kUPDATE = kTRUE;
972ef65e 457 }
458 }
bcb6fb78 459
972ef65e 460 // Prolongate to TPC without update
461 if(!kUPDATE) {
462 AliTRDtrackV1 tt(*seed);
463 if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDrefit);
464 }
465 }
466 AliInfo(Form("Number of loaded seeds: %d",nseed));
467 AliInfo(Form("Number of found tracks from loaded seeds: %d",found));
468
469 return 0;
0906e73e 470}
471
472
473//____________________________________________________________________
474Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
475{
972ef65e 476 // Extrapolates the TRD track in the TPC direction.
477 //
478 // Parameters
479 // t : the TRD track which has to be extrapolated
480 //
481 // Output
482 // number of clusters attached to the track
483 //
484 // Detailed description
485 //
486 // Starting from current radial position of track <t> this function
487 // extrapolates the track through the 6 TRD layers. The following steps
488 // are being performed for each plane:
489 // 1. prepare track:
490 // a. get plane limits in the local x direction
491 // b. check crossing sectors
492 // c. check track inclination
493 // 2. search tracklet in the tracker list (see GetTracklet() for details)
494 // 3. evaluate material budget using the geo manager
495 // 4. propagate and update track using the tracklet information.
496 //
497 // Debug level 2
498 //
499
500 Int_t nClustersExpected = 0;
501 Int_t lastplane = 5; //GetLastPlane(&t);
502 for (Int_t iplane = lastplane; iplane >= 0; iplane--) {
503 Int_t index = 0;
504 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
505 if(!tracklet) continue;
506 if(!tracklet->IsOK()) AliWarning("tracklet not OK");
eb38ed55 507
972ef65e 508 Double_t x = tracklet->GetX0();
509 // reject tracklets which are not considered for inward refit
510 if(x > t.GetX()+fgkMaxStep) continue;
a23edf15 511
972ef65e 512 // append tracklet to track
513 t.SetTracklet(tracklet, iplane, index);
514
515 if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
516 if (!AdjustSector(&t)) break;
eb38ed55 517
972ef65e 518 // Start global position
519 Double_t xyz0[3];
520 t.GetXYZ(xyz0);
521
522 // End global position
523 Double_t alpha = t.GetAlpha(), y, z;
524 if (!t.GetProlongation(x,y,z)) break;
525 Double_t xyz1[3];
526 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
527 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
528 xyz1[2] = z;
eb38ed55 529
972ef65e 530 // Get material budget
531 Double_t param[7];
532 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
533 Double_t xrho= param[0]*param[4];
534 Double_t xx0 = param[1]; // Get mean propagation parameters
535
536 // Propagate and update
537 t.PropagateTo(x, xx0, xrho);
538 if (!AdjustSector(&t)) break;
539
540 Double_t maxChi2 = t.GetPredictedChi2(tracklet);
541 if (maxChi2 < 1e+10 && t.Update(tracklet, maxChi2)){
542 nClustersExpected += tracklet->GetN();
543 }
544 }
545
546 if(AliTRDReconstructor::StreamLevel() > 1){
547 Int_t index;
548 for(int iplane=0; iplane<6; iplane++){
549 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
550 if(!tracklet) continue;
551 t.SetTracklet(tracklet, iplane, index);
552 }
553
554 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
555 TTreeSRedirector &cstreamer = *fgDebugStreamer;
556 cstreamer << "FollowProlongation"
557 << "EventNumber=" << eventNumber
558 << "ncl=" << nClustersExpected
559 << "track.=" << &t
560 << "\n";
561 }
562
563 return nClustersExpected;
0906e73e 564
565}
566
567//_____________________________________________________________________________
568Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
569{
972ef65e 570 // Extrapolates the TRD track in the TOF direction.
571 //
572 // Parameters
573 // t : the TRD track which has to be extrapolated
574 //
575 // Output
576 // number of clusters attached to the track
577 //
578 // Detailed description
579 //
580 // Starting from current radial position of track <t> this function
581 // extrapolates the track through the 6 TRD layers. The following steps
582 // are being performed for each plane:
583 // 1. prepare track:
584 // a. get plane limits in the local x direction
585 // b. check crossing sectors
586 // c. check track inclination
587 // 2. build tracklet (see AliTRDseed::AttachClusters() for details)
588 // 3. evaluate material budget using the geo manager
589 // 4. propagate and update track using the tracklet information.
590 //
591 // Debug level 2
592 //
593
594 Int_t nClustersExpected = 0;
595 Double_t clength = AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
596 AliTRDtrackingChamber *chamber = 0x0;
597
598 // Loop through the TRD planes
599 for (Int_t iplane = 0; iplane < AliTRDgeometry::Nplan(); iplane++) {
600 // BUILD TRACKLET IF NOT ALREADY BUILT
601 Double_t x = 0., y, z, alpha;
602 AliTRDseedV1 tracklet(*t.GetTracklet(iplane));
603 if(!tracklet.IsOK()){
604 alpha = t.GetAlpha();
605 Int_t sector = Int_t(alpha/AliTRDgeometry::GetAlpha() + (alpha>0. ? 0 : AliTRDgeometry::kNsect));
606
607 if(!fTrSec[sector].GetNChambers()) continue;
608
609 if((x = fTrSec[sector].GetX(iplane)) < 1.) continue;
eb38ed55 610
972ef65e 611 if (!t.GetProlongation(x, y, z)) break;
612 Int_t stack = fGeom->GetChamber(z, iplane);
613 Int_t nCandidates = stack >= 0 ? 1 : 2;
614 z -= stack >= 0 ? 0. : 4.;
eb38ed55 615
972ef65e 616 for(int icham=0; icham<nCandidates; icham++, z+=8){
51863bc0 617 if((stack = fGeom->GetChamber(z, iplane)) < 0) continue;
972ef65e 618
51863bc0 619 if(!(chamber = fTrSec[sector].GetChamber(stack, iplane))) continue;
972ef65e 620
51863bc0 621 if(chamber->GetNClusters() < fgNTimeBins*AliTRDReconstructor::RecoParam()->GetFindableClusters()) continue;
972ef65e 622
51863bc0 623 x = chamber->GetX();
972ef65e 624
51863bc0 625 AliTRDpadPlane *pp = fGeom->GetPadPlane(iplane, stack);
626 tracklet.SetTilt(TMath::Tan(-TMath::DegToRad()*pp->GetTiltingAngle()));
627 tracklet.SetPadLength(pp->GetLengthIPad());
628 tracklet.SetPlane(iplane);
629 tracklet.SetX0(x);
972ef65e 630 tracklet.Init(&t);
51863bc0 631 if(!tracklet.AttachClustersIter(chamber, 1000.)) continue;
632 tracklet.Init(&t);
972ef65e 633
51863bc0 634 if(tracklet.GetN() < fgNTimeBins * AliTRDReconstructor::RecoParam()->GetFindableClusters()) continue;
972ef65e 635
51863bc0 636 break;
637 }
972ef65e 638 }
639 if(!tracklet.IsOK()){
640 if(x < 1.) continue; //temporary
641 if(!PropagateToX(t, x-fgkMaxStep, fgkMaxStep)) break;
642 if(!AdjustSector(&t)) break;
643 if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) break;
644 continue;
645 }
0906e73e 646
972ef65e 647 // Propagate closer to the current chamber if neccessary
648 x -= clength;
649 if (x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x-fgkMaxStep, fgkMaxStep)) break;
650 if (!AdjustSector(&t)) break;
651 if (TMath::Abs(t.GetSnp()) > fgkMaxSnp) break;
0906e73e 652
972ef65e 653 // load tracklet to the tracker and the track
654 Int_t index = SetTracklet(&tracklet);
655 t.SetTracklet(&tracklet, iplane, index);
656
657
658 // Calculate the mean material budget along the path inside the chamber
659 //Calculate global entry and exit positions of the track in chamber (only track prolongation)
660 Double_t xyz0[3]; // entry point
661 t.GetXYZ(xyz0);
662 alpha = t.GetAlpha();
663 x = tracklet.GetX0();
664 if (!t.GetProlongation(x, y, z)) break;
665 Double_t xyz1[3]; // exit point
666 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
667 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
668 xyz1[2] = z;
669 Double_t param[7];
670 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
671 // The mean propagation parameters
672 Double_t xrho = param[0]*param[4]; // density*length
673 Double_t xx0 = param[1]; // radiation length
674
675 // Propagate and update track
676 t.PropagateTo(x, xx0, xrho);
677 if (!AdjustSector(&t)) break;
678 Double_t maxChi2 = t.GetPredictedChi2(&tracklet);
679 if (maxChi2<1e+10 && t.Update(&tracklet, maxChi2)){
680 nClustersExpected += tracklet.GetN();
681 t.SetTracklet(&tracklet, iplane, index);
682 UpdateTracklet(&tracklet, index);
683 }
684 // Reset material budget if 2 consecutive gold
685 if(iplane>0 && tracklet.GetN() + t.GetTracklet(iplane-1)->GetN() > 20) t.SetBudget(2, 0.);
686
687 // Make backup of the track until is gold
688 // TO DO update quality check of the track.
689 // consider comparison with fTimeBinsRange
690 Float_t ratio0 = tracklet.GetN() / Float_t(fgNTimeBins);
691 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
692 //printf("tracklet.GetChi2() %f [< 18.0]\n", tracklet.GetChi2());
693 //printf("ratio0 %f [> 0.8]\n", ratio0);
694 //printf("ratio1 %f [> 0.6]\n", ratio1);
695 //printf("ratio0+ratio1 %f [> 1.5]\n", ratio0+ratio1);
696 //printf("t.GetNCross() %d [== 0]\n", t.GetNCross());
697 //printf("TMath::Abs(t.GetSnp()) %f [< 0.85]\n", TMath::Abs(t.GetSnp()));
698 //printf("t.GetNumberOfClusters() %d [> 20]\n", t.GetNumberOfClusters());
0906e73e 699
972ef65e 700 if (//(tracklet.GetChi2() < 18.0) && TO DO check with FindClusters and move it to AliTRDseed::Update
701 (ratio0 > 0.8) &&
702 //(ratio1 > 0.6) &&
703 //(ratio0+ratio1 > 1.5) &&
704 (t.GetNCross() == 0) &&
705 (TMath::Abs(t.GetSnp()) < 0.85) &&
706 (t.GetNumberOfClusters() > 20)) t.MakeBackupTrack();
707
708 } // end planes loop
709
710 if(AliTRDReconstructor::StreamLevel() > 1){
711 TTreeSRedirector &cstreamer = *fgDebugStreamer;
712 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
713 cstreamer << "FollowBackProlongation"
714 << "EventNumber=" << eventNumber
715 << "ncl=" << nClustersExpected
716 << "track.=" << &t
717 << "\n";
718 }
719
720 return nClustersExpected;
0906e73e 721}
722
eb38ed55 723//_________________________________________________________________________
724Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *planes){
972ef65e 725 //
726 // Fits a Riemann-circle to the given points without tilting pad correction.
727 // The fit is performed using an instance of the class AliRieman (equations
728 // and transformations see documentation of this class)
729 // Afterwards all the tracklets are Updated
730 //
731 // Parameters: - Array of tracklets (AliTRDseedV1)
732 // - Storage for the chi2 values (beginning with direction z)
733 // - Seeding configuration
734 // Output: - The curvature
735 //
736 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
737 fitter->Reset();
738 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
739 Int_t *ppl = &allplanes[0];
740 Int_t maxLayers = 6;
741 if(planes){
742 maxLayers = 4;
743 ppl = planes;
744 }
745 for(Int_t il = 0; il < maxLayers; il++){
746 if(!tracklets[ppl[il]].IsOK()) continue;
747 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfitR(0), tracklets[ppl[il]].GetZProb(),1,10);
748 }
749 fitter->Update();
750 // Set the reference position of the fit and calculate the chi2 values
751 memset(chi2, 0, sizeof(Double_t) * 2);
752 for(Int_t il = 0; il < maxLayers; il++){
753 // Reference positions
754 tracklets[ppl[il]].Init(fitter);
eb38ed55 755
972ef65e 756 // chi2
757 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
758 chi2[0] += tracklets[ppl[il]].GetChi2Y();
759 chi2[1] += tracklets[ppl[il]].GetChi2Z();
760 }
761 return fitter->GetC();
eb38ed55 762}
763
764//_________________________________________________________________________
765void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
766{
972ef65e 767 //
768 // Performs a Riemann helix fit using the seedclusters as spacepoints
769 // Afterwards the chi2 values are calculated and the seeds are updated
770 //
771 // Parameters: - The four seedclusters
772 // - The tracklet array (AliTRDseedV1)
773 // - The seeding configuration
774 // - Chi2 array
775 //
776 // debug level 2
777 //
778 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
779 fitter->Reset();
780 for(Int_t i = 0; i < 4; i++)
781 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1, 10);
782 fitter->Update();
783
784
785 // Update the seed and calculated the chi2 value
786 chi2[0] = 0; chi2[1] = 0;
787 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
788 // chi2
789 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
790 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
791 }
eb38ed55 792}
793
794
795//_________________________________________________________________________
796Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
797{
972ef65e 798 //
799 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
800 // assumed that the vertex position is set to 0.
801 // This method is very usefull for high-pt particles
802 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
803 // x0, y0: Center of the circle
804 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
805 // zc: center of the pad row
806 // Equation which has to be fitted (after transformation):
807 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
808 // Transformation:
809 // t = 1/(x^2 + y^2)
810 // u = 2 * x * t
811 // v = 2 * x * tan(phiT) * t
812 // Parameters in the equation:
813 // a = -1/y0, b = x0/y0, e = dz/dx
814 //
815 // The Curvature is calculated by the following equation:
816 // - curv = a/Sqrt(b^2 + 1) = 1/R
817 // Parameters: - the 6 tracklets
818 // - the Vertex constraint
819 // Output: - the Chi2 value of the track
820 //
821 // debug level 5
822 //
823
824 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
825 fitter->StoreData(kTRUE);
826 fitter->ClearPoints();
827 AliTRDcluster *cl = 0x0;
828
829 Float_t x, y, z, w, t, error, tilt;
830 Double_t uvt[2];
831 Int_t nPoints = 0;
832 for(Int_t ipl = 0; ipl < AliTRDgeometry::kNplan; ipl++){
833 if(!tracklets[ipl].IsOK()) continue;
834 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
835 if(!tracklets[ipl].IsUsable(itb)) continue;
836 cl = tracklets[ipl].GetClusters(itb);
837 x = cl->GetX();
838 y = cl->GetY();
839 z = cl->GetZ();
840 tilt = tracklets[ipl].GetTilt();
841 // Transformation
842 t = 1./(x * x + y * y);
843 uvt[0] = 2. * x * t;
844 uvt[1] = 2. * x * t * tilt ;
845 w = 2. * (y + tilt * (z - zVertex)) * t;
846 error = 2. * 0.2 * t;
847 fitter->AddPoint(uvt, w, error);
848 nPoints++;
849 }
850 }
851 fitter->Eval();
852
853 // Calculate curvature
854 Double_t a = fitter->GetParameter(0);
855 Double_t b = fitter->GetParameter(1);
856 Double_t curvature = a/TMath::Sqrt(b*b + 1);
857
858 Float_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
859 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
860 tracklets[ip].SetCC(curvature);
861
862 if(AliTRDReconstructor::StreamLevel() >= 5){
863 //Linear Model on z-direction
864 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
865 Double_t slope = fitter->GetParameter(2);
866 Double_t zref = slope * xref;
867 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
868 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
869 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
870 TTreeSRedirector &treeStreamer = *fgDebugStreamer;
871 treeStreamer << "FitTiltedRiemanConstraint"
872 << "EventNumber=" << eventNumber
873 << "CandidateNumber=" << candidateNumber
874 << "Curvature=" << curvature
875 << "Chi2Track=" << chi2track
876 << "Chi2Z=" << chi2Z
877 << "zref=" << zref
878 << "\n";
879 }
880 return chi2track;
eb38ed55 881}
882
883//_________________________________________________________________________
884Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
885{
972ef65e 886 //
887 // Performs a Riemann fit taking tilting pad correction into account
888 // The equation of a Riemann circle, where the y position is substituted by the
889 // measured y-position taking pad tilting into account, has to be transformed
890 // into a 4-dimensional hyperplane equation
891 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
892 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
893 // zc: center of the pad row
894 // zt: z-position of the track
895 // The z-position of the track is assumed to be linear dependent on the x-position
896 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
897 // Transformation: u = 2 * x * t
898 // v = 2 * tan(phiT) * t
899 // w = 2 * tan(phiT) * (x - xref) * t
900 // t = 1 / (x^2 + ymeas^2)
901 // Parameters: a = -1/y0
902 // b = x0/y0
903 // c = (R^2 -x0^2 - y0^2)/y0
904 // d = offset
905 // e = dz/dx
906 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
907 // results from the simple riemann fit. Afterwards the fit is redone.
908 // The curvature is calculated according to the formula:
909 // curv = a/(1 + b^2 + c*a) = 1/R
910 //
911 // Paramters: - Array of tracklets (connected to the track candidate)
912 // - Flag selecting the error definition
913 // Output: - Chi2 values of the track (in Parameter list)
914 //
915 TLinearFitter *fitter = GetTiltedRiemanFitter();
916 fitter->StoreData(kTRUE);
917 fitter->ClearPoints();
918 AliTRDLeastSquare zfitter;
919 AliTRDcluster *cl = 0x0;
920
921 Double_t xref = CalculateReferenceX(tracklets);
922 Double_t x, y, z, t, tilt, dx, w, we;
923 Double_t uvt[4];
924 Int_t nPoints = 0;
925 // Containers for Least-square fitter
926 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
927 if(!tracklets[ipl].IsOK()) continue;
928 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
929 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
930 if (!tracklets[ipl].IsUsable(itb)) continue;
931 x = cl->GetX();
932 y = cl->GetY();
933 z = cl->GetZ();
934 tilt = tracklets[ipl].GetTilt();
935 dx = x - xref;
936 // Transformation
937 t = 1./(x*x + y*y);
938 uvt[0] = 2. * x * t;
939 uvt[1] = t;
940 uvt[2] = 2. * tilt * t;
941 uvt[3] = 2. * tilt * dx * t;
942 w = 2. * (y + tilt*z) * t;
943 // error definition changes for the different calls
944 we = 2. * t;
945 we *= sigError ? tracklets[ipl].GetSigmaY() : 0.2;
946 fitter->AddPoint(uvt, w, we);
947 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
948 nPoints++;
949 }
950 }
951 fitter->Eval();
952 zfitter.Eval();
953
954 Double_t offset = fitter->GetParameter(3);
955 Double_t slope = fitter->GetParameter(4);
956
957 // Linear fitter - not possible to make boundaries
958 // Do not accept non possible z and dzdx combinations
959 Bool_t acceptablez = kTRUE;
960 Double_t zref = 0.0;
961 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
962 if(!tracklets[iLayer].IsOK()) continue;
963 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
964 if (TMath::Abs(tracklets[iLayer].GetZProb() - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
965 acceptablez = kFALSE;
966 }
967 if (!acceptablez) {
968 Double_t dzmf = zfitter.GetFunctionParameter(1);
969 Double_t zmf = zfitter.GetFunctionValue(&xref);
970 fgTiltedRieman->FixParameter(3, zmf);
971 fgTiltedRieman->FixParameter(4, dzmf);
972 fitter->Eval();
973 fitter->ReleaseParameter(3);
974 fitter->ReleaseParameter(4);
975 offset = fitter->GetParameter(3);
976 slope = fitter->GetParameter(4);
977 }
978
979 // Calculate Curvarture
980 Double_t a = fitter->GetParameter(0);
981 Double_t b = fitter->GetParameter(1);
982 Double_t c = fitter->GetParameter(2);
983 Double_t curvature = 1.0 + b*b - c*a;
984 if (curvature > 0.0)
985 curvature = a / TMath::Sqrt(curvature);
986
987 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
988
989 // Update the tracklets
990 Double_t dy, dz;
991 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
992
993 x = tracklets[iLayer].GetX0();
994 y = 0;
995 z = 0;
996 dy = 0;
997 dz = 0;
998
999 // y: R^2 = (x - x0)^2 + (y - y0)^2
1000 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1001 // R = Sqrt() = 1/Curvature
1002 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1003 Double_t res = (x * a + b); // = (x - x0)/y0
1004 res *= res;
1005 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1006 if (res >= 0) {
1007 res = TMath::Sqrt(res);
1008 y = (1.0 - res) / a;
1009 }
1010
1011 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1012 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1013 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1014 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1015 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1016 Double_t x0 = -b / a;
1017 if (-c * a + b * b + 1 > 0) {
1018 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
d739fd4e 1019 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1020 if (a < 0) yderiv *= -1.0;
1021 dy = yderiv;
972ef65e 1022 }
1023 }
1024 z = offset + slope * (x - xref);
1025 dz = slope;
1026 tracklets[iLayer].SetYref(0, y);
1027 tracklets[iLayer].SetYref(1, dy);
1028 tracklets[iLayer].SetZref(0, z);
1029 tracklets[iLayer].SetZref(1, dz);
1030 tracklets[iLayer].SetC(curvature);
1031 tracklets[iLayer].SetChi2(chi2track);
1032 }
1033
1034 if(AliTRDReconstructor::StreamLevel() >=5){
1035 TTreeSRedirector &cstreamer = *fgDebugStreamer;
1036 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1037 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1038 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1039 cstreamer << "FitTiltedRieman0"
1040 << "EventNumber=" << eventNumber
1041 << "CandidateNumber=" << candidateNumber
1042 << "xref=" << xref
1043 << "Chi2Z=" << chi2z
1044 << "\n";
1045 }
1046 return chi2track;
eb38ed55 1047}
1048
1049//_________________________________________________________________________
bb56afff 1050Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
eb38ed55 1051{
972ef65e 1052 //
1053 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1054 // A linear dependence on the x-value serves as a model.
1055 // The parameters are related to the tilted Riemann fit.
1056 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1057 // - the offset for the reference x
1058 // - the slope
1059 // - the reference x position
1060 // Output: - The Chi2 value of the track in z-Direction
1061 //
1062 Float_t chi2Z = 0, nLayers = 0;
1063 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNplan; iLayer++) {
1064 if(!tracklets[iLayer].IsOK()) continue;
1065 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
1066 chi2Z += TMath::Abs(tracklets[iLayer].GetMeanz() - z);
1067 nLayers++;
1068 }
1069 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1070 return chi2Z;
eb38ed55 1071}
1072
bccda319 1073//_____________________________________________________________________________
1074Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1075{
972ef65e 1076 //
1077 // Starting from current X-position of track <t> this function
1078 // extrapolates the track up to radial position <xToGo>.
1079 // Returns 1 if track reaches the plane, and 0 otherwise
1080 //
bccda319 1081
972ef65e 1082 const Double_t kEpsilon = 0.00001;
bccda319 1083
972ef65e 1084 // Current track X-position
1085 Double_t xpos = t.GetX();
bccda319 1086
972ef65e 1087 // Direction: inward or outward
1088 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
bccda319 1089
972ef65e 1090 while (((xToGo - xpos) * dir) > kEpsilon) {
bccda319 1091
972ef65e 1092 Double_t xyz0[3];
1093 Double_t xyz1[3];
1094 Double_t param[7];
1095 Double_t x;
1096 Double_t y;
1097 Double_t z;
bccda319 1098
972ef65e 1099 // The next step size
1100 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
bccda319 1101
972ef65e 1102 // Get the global position of the starting point
1103 t.GetXYZ(xyz0);
bccda319 1104
972ef65e 1105 // X-position after next step
1106 x = xpos + step;
bccda319 1107
972ef65e 1108 // Get local Y and Z at the X-position of the next step
1109 if (!t.GetProlongation(x,y,z)) {
1110 return 0; // No prolongation possible
1111 }
bccda319 1112
972ef65e 1113 // The global position of the end point of this prolongation step
1114 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1115 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1116 xyz1[2] = z;
bccda319 1117
972ef65e 1118 // Calculate the mean material budget between start and
1119 // end point of this prolongation step
1120 AliTracker::MeanMaterialBudget(xyz0, xyz1, param);
bccda319 1121
972ef65e 1122 // Propagate the track to the X-position after the next step
1123 if (!t.PropagateTo(x,param[1],param[0]*param[4])) {
1124 return 0;
1125 }
bccda319 1126
972ef65e 1127 // Rotate the track if necessary
1128 AdjustSector(&t);
bccda319 1129
972ef65e 1130 // New track X-position
1131 xpos = t.GetX();
bccda319 1132
972ef65e 1133 }
bccda319 1134
972ef65e 1135 return 1;
bccda319 1136
1137}
1138
eb38ed55 1139
1140//_____________________________________________________________________________
1141Int_t AliTRDtrackerV1::ReadClusters(TClonesArray* &array, TTree *clusterTree) const
1142{
972ef65e 1143 //
1144 // Reads AliTRDclusters from the file.
1145 // The names of the cluster tree and branches
1146 // should match the ones used in AliTRDclusterizer::WriteClusters()
1147 //
1148
1149 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1150 TObjArray *clusterArray = new TObjArray(nsize+1000);
1151
1152 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1153 if (!branch) {
1154 AliError("Can't get the branch !");
1155 return 1;
1156 }
1157 branch->SetAddress(&clusterArray);
1158
1159 if(!fClusters){
1160 array = new TClonesArray("AliTRDcluster", nsize);
1161 array->SetOwner(kTRUE);
1162 }
1163
1164 // Loop through all entries in the tree
1165 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1166 Int_t nbytes = 0;
1167 Int_t ncl = 0;
1168 AliTRDcluster *c = 0x0;
1169 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1170 // Import the tree
1171 nbytes += clusterTree->GetEvent(iEntry);
1172
1173 // Get the number of points in the detector
1174 Int_t nCluster = clusterArray->GetEntriesFast();
1175 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1176 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
1177 c->SetInChamber();
1178 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1179 clusterArray->RemoveAt(iCluster);
1180 }
1181
1182 }
1183 delete clusterArray;
1184
1185 return 0;
eb38ed55 1186}
1187
1188//_____________________________________________________________________________
1189Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
1190{
972ef65e 1191 //
1192 // Fills clusters into TRD tracking_sectors
1193 // Note that the numbering scheme for the TRD tracking_sectors
1194 // differs from that of TRD sectors
1195 //
1196
1197
1198 if (ReadClusters(fClusters, cTree)) {
1199 AliError("Problem with reading the clusters !");
1200 return 1;
1201 }
1202 Int_t ncl = fClusters->GetEntriesFast(), nin = 0;
1203 if(!ncl){
1204 AliInfo("Clusters 0");
1205 return 1;
1206 }
1207
1208 Int_t icl = ncl;
1209 while (icl--) {
1210 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(icl);
1211 if(c->IsInChamber()) nin++;
1212 Int_t detector = c->GetDetector();
1213 Int_t sector = fGeom->GetSector(detector);
1214 Int_t stack = fGeom->GetChamber(detector);
1215 Int_t plane = fGeom->GetPlane(detector);
eb38ed55 1216
972ef65e 1217 fTrSec[sector].GetChamber(stack, plane, kTRUE)->InsertCluster(c, icl);
1218 }
1219 AliInfo(Form("Clusters %d in %6.2f %%", ncl, 100.*float(nin)/ncl));
1220
1221 for(int isector =0; isector<AliTRDgeometry::kNsect; isector++){
1222 if(!fTrSec[isector].GetNChambers()) continue;
1223 fTrSec[isector].Init();
1224 }
1225
1226 return 0;
eb38ed55 1227}
1228
1229
0906e73e 1230//____________________________________________________________________
1231void AliTRDtrackerV1::UnloadClusters()
1232{
972ef65e 1233 //
1234 // Clears the arrays of clusters and tracks. Resets sectors and timebins
1235 //
0906e73e 1236
972ef65e 1237 if(fTracks) fTracks->Delete();
1238 if(fTracklets) fTracklets->Delete();
1239 if(fClusters) fClusters->Delete();
0906e73e 1240
972ef65e 1241 for (int i = 0; i < AliTRDgeometry::kNsect; i++) fTrSec[i].Clear();
0906e73e 1242
972ef65e 1243 // Increment the Event Number
1244 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
eb38ed55 1245}
0906e73e 1246
eb38ed55 1247//_____________________________________________________________________________
1248Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *track)
1249{
972ef65e 1250 //
1251 // Rotates the track when necessary
1252 //
1253
1254 Double_t alpha = AliTRDgeometry::GetAlpha();
1255 Double_t y = track->GetY();
1256 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
1257
1258 if (y > ymax) {
1259 if (!track->Rotate( alpha)) {
1260 return kFALSE;
1261 }
1262 }
1263 else if (y < -ymax) {
1264 if (!track->Rotate(-alpha)) {
1265 return kFALSE;
1266 }
1267 }
1268
1269 return kTRUE;
0906e73e 1270
1271}
1272
eb38ed55 1273
0906e73e 1274//____________________________________________________________________
1275AliTRDseedV1* AliTRDtrackerV1::GetTracklet(AliTRDtrackV1 *track, Int_t p, Int_t &idx)
1276{
972ef65e 1277 // Find tracklet for TRD track <track>
1278 // Parameters
1279 // - track
1280 // - sector
1281 // - plane
1282 // - index
1283 // Output
1284 // tracklet
1285 // index
1286 // Detailed description
1287 //
1288 idx = track->GetTrackletIndex(p);
1289 AliTRDseedV1 *tracklet = idx<0 ? 0x0 : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
1290
1291 return tracklet;
0906e73e 1292}
1293
1294//____________________________________________________________________
bc11c056 1295Int_t AliTRDtrackerV1::SetTracklet(AliTRDseedV1 *tracklet)
0906e73e 1296{
972ef65e 1297 // Add this tracklet to the list of tracklets stored in the tracker
1298 //
1299 // Parameters
1300 // - tracklet : pointer to the tracklet to be added to the list
1301 //
1302 // Output
1303 // - the index of the new tracklet in the tracker tracklets list
1304 //
1305 // Detailed description
1306 // Build the tracklets list if it is not yet created (late initialization)
1307 // and adds the new tracklet to the list.
1308 //
1309 if(!fTracklets){
1310 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsect()*kMaxTracksStack);
1311 fTracklets->SetOwner(kTRUE);
1312 }
1313 Int_t nentries = fTracklets->GetEntriesFast();
1314 new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
1315 return nentries;
1316}
1317
1318//____________________________________________________________________
1319Bool_t AliTRDtrackerV1::UpdateTracklet(AliTRDseedV1 *tracklet, Int_t index){
1320 //
1321 // Update Tracklet in the tracklet container
1322 //
1323 // Parameters:
1324 // - the tracklet information
1325 // - the index of the tracklet which has to be updated
1326 //
1327 // Output:
1328 // - True if successfull
1329 // - false if the container doesn't exist or the index is out of range
1330 //
1331 if(!fTracklets || index >= fTracklets->GetEntriesFast()) return kFALSE;
1332
1333 new((*fTracklets)[index]) AliTRDseedV1(*tracklet);
1334 return kTRUE;
0906e73e 1335}
1336
e4f2f73d 1337//____________________________________________________________________
eb38ed55 1338Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
e4f2f73d 1339{
972ef65e 1340 //
1341 // Steer tracking for one SM.
1342 //
1343 // Parameters :
1344 // sector : Array of (SM) propagation layers containing clusters
1345 // esd : The current ESD event. On output it contains the also
1346 // the ESD (TRD) tracks found in this SM.
1347 //
1348 // Output :
1349 // Number of tracks found in this TRD supermodule.
1350 //
1351 // Detailed description
1352 //
1353 // 1. Unpack AliTRDpropagationLayers objects for each stack.
1354 // 2. Launch stack tracking.
1355 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
1356 // 3. Pack results in the ESD event.
1357 //
1358
1359 // allocate space for esd tracks in this SM
1360 TClonesArray esdTrackList("AliESDtrack", 2*kMaxTracksStack);
1361 esdTrackList.SetOwner();
1362
1363 Int_t nTracks = 0;
1364 Int_t nChambers = 0;
1365 AliTRDtrackingChamber **stack = 0x0, *chamber = 0x0;
1366 for(int istack = 0; istack<AliTRDgeometry::kNcham; istack++){
1367 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
1368 nChambers = 0;
1369 for(int iplane=0; iplane<AliTRDgeometry::kNplan; iplane++){
1370 if(!(chamber = stack[iplane])) continue;
1371 if(chamber->GetNClusters() < fgNTimeBins * AliTRDReconstructor::RecoParam()->GetFindableClusters()) continue;
1372 nChambers++;
1373 //AliInfo(Form("sector %d stack %d plane %d clusters %d", sector, istack, iplane, chamber->GetNClusters()));
1374 }
1375 if(nChambers < 4) continue;
1376 //AliInfo(Form("Doing stack %d", istack));
1377 nTracks += Clusters2TracksStack(stack, &esdTrackList);
1378 }
1379 //AliInfo(Form("Found %d tracks in SM %d [%d]\n", nTracks, sector, esd->GetNumberOfTracks()));
1380
1381 for(int itrack=0; itrack<nTracks; itrack++)
1382 esd->AddTrack((AliESDtrack*)esdTrackList[itrack]);
1383
1384 // Reset Track and Candidate Number
1385 AliTRDtrackerDebug::SetCandidateNumber(0);
1386 AliTRDtrackerDebug::SetTrackNumber(0);
1387 return nTracks;
e4f2f73d 1388}
1389
1390//____________________________________________________________________
eb38ed55 1391Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray *esdTrackList)
e4f2f73d 1392{
972ef65e 1393 //
1394 // Make tracks in one TRD stack.
1395 //
1396 // Parameters :
1397 // layer : Array of stack propagation layers containing clusters
1398 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
1399 // On exit the tracks found in this stack are appended.
1400 //
1401 // Output :
1402 // Number of tracks found in this stack.
1403 //
1404 // Detailed description
1405 //
1406 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
1407 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
1408 // See AliTRDtrackerV1::MakeSeeds() for more details.
1409 // 3. Arrange track candidates in decreasing order of their quality
1410 // 4. Classify tracks in 5 categories according to:
1411 // a) number of layers crossed
1412 // b) track quality
1413 // 5. Sign clusters by tracks in decreasing order of track quality
1414 // 6. Build AliTRDtrack out of seeding tracklets
1415 // 7. Cook MC label
1416 // 8. Build ESD track and register it to the output list
1417 //
1418
1419 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
1420 if (!calibra) AliInfo("Could not get Calibra instance\n");
1421
1422 AliTRDtrackingChamber *chamber = 0x0;
1423 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
1424 Int_t pars[4]; // MakeSeeds parameters
1425
1426 //Double_t alpha = AliTRDgeometry::GetAlpha();
1427 //Double_t shift = .5 * alpha;
1428 Int_t configs[kNConfigs];
1429
1430 // Build initial seeding configurations
1431 Double_t quality = BuildSeedingConfigs(stack, configs);
1432 if(AliTRDReconstructor::StreamLevel() > 1){
1433 AliInfo(Form("Plane config %d %d %d Quality %f"
1434 , configs[0], configs[1], configs[2], quality));
1435 }
1436
1437 // Initialize contors
1438 Int_t ntracks, // number of TRD track candidates
1439 ntracks1, // number of registered TRD tracks/iter
1440 ntracks2 = 0; // number of all registered TRD tracks in stack
1441 fSieveSeeding = 0;
1442 do{
1443 // Loop over seeding configurations
1444 ntracks = 0; ntracks1 = 0;
1445 for (Int_t iconf = 0; iconf<3; iconf++) {
1446 pars[0] = configs[iconf];
1447 pars[1] = ntracks;
1448 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
1449 if(ntracks == kMaxTracksStack) break;
1450 }
1451 if(AliTRDReconstructor::StreamLevel() > 1) AliInfo(Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
eb38ed55 1452
972ef65e 1453 if(!ntracks) break;
e4f2f73d 1454
972ef65e 1455 // Sort the seeds according to their quality
1456 Int_t sort[kMaxTracksStack];
1457 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
1458
1459 // Initialize number of tracks so far and logic switches
1460 Int_t ntracks0 = esdTrackList->GetEntriesFast();
1461 Bool_t signedTrack[kMaxTracksStack];
1462 Bool_t fakeTrack[kMaxTracksStack];
1463 for (Int_t i=0; i<ntracks; i++){
1464 signedTrack[i] = kFALSE;
1465 fakeTrack[i] = kFALSE;
1466 }
1467 //AliInfo("Selecting track candidates ...");
e4f2f73d 1468
972ef65e 1469 // Sieve clusters in decreasing order of track quality
1470 Double_t trackParams[7];
1471 // AliTRDseedV1 *lseed = 0x0;
1472 Int_t jSieve = 0, candidates;
1473 do{
1474 //AliInfo(Form("\t\tITER = %i ", jSieve));
1475
1476 // Check track candidates
1477 candidates = 0;
1478 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
d739fd4e 1479 Int_t trackIndex = sort[itrack];
1480 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
e4f2f73d 1481
1482
d739fd4e 1483 // Calculate track parameters from tracklets seeds
1484 Int_t labelsall[1000];
1485 Int_t nlabelsall = 0;
1486 Int_t naccepted = 0;
1487 Int_t ncl = 0;
1488 Int_t nused = 0;
1489 Int_t nlayers = 0;
1490 Int_t findable = 0;
1491 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
972ef65e 1492 Int_t jseed = kNPlanes*trackIndex+jLayer;
1493 if(!sseed[jseed].IsOK()) continue;
1494 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.15) findable++;
1495
1496 sseed[jseed].UpdateUsed();
1497 ncl += sseed[jseed].GetN2();
1498 nused += sseed[jseed].GetNUsed();
1499 nlayers++;
1500
1501 // Cooking label
1502 for (Int_t itime = 0; itime < fgNTimeBins; itime++) {
1503 if(!sseed[jseed].IsUsable(itime)) continue;
1504 naccepted++;
1505 Int_t tindex = 0, ilab = 0;
1506 while(ilab<3 && (tindex = sseed[jseed].GetClusters(itime)->GetLabel(ilab)) >= 0){
1507 labelsall[nlabelsall++] = tindex;
1508 ilab++;
1509 }
1510 }
d739fd4e 1511 }
1512 // Filter duplicated tracks
1513 if (nused > 30){
972ef65e 1514 //printf("Skip %d nused %d\n", trackIndex, nused);
1515 fakeTrack[trackIndex] = kTRUE;
1516 continue;
d739fd4e 1517 }
1518 if (Float_t(nused)/ncl >= .25){
972ef65e 1519 //printf("Skip %d nused/ncl >= .25\n", trackIndex);
1520 fakeTrack[trackIndex] = kTRUE;
1521 continue;
d739fd4e 1522 }
e4f2f73d 1523
d739fd4e 1524 // Classify tracks
1525 Bool_t skip = kFALSE;
1526 switch(jSieve){
1527 case 0:
972ef65e 1528 if(nlayers < 6) {skip = kTRUE; break;}
1529 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
1530 break;
e4f2f73d 1531
d739fd4e 1532 case 1:
972ef65e 1533 if(nlayers < findable){skip = kTRUE; break;}
1534 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
1535 break;
e4f2f73d 1536
d739fd4e 1537 case 2:
972ef65e 1538 if ((nlayers == findable) || (nlayers == 6)) { skip = kTRUE; break;}
1539 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
1540 break;
e4f2f73d 1541
d739fd4e 1542 case 3:
972ef65e 1543 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
1544 break;
e4f2f73d 1545
d739fd4e 1546 case 4:
972ef65e 1547 if (nlayers == 3){skip = kTRUE; break;}
1548 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
1549 break;
d739fd4e 1550 }
1551 if(skip){
972ef65e 1552 candidates++;
1553 //printf("REJECTED : %d [%d] nlayers %d trackQuality = %e nused %d\n", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused);
1554 continue;
d739fd4e 1555 }
1556 signedTrack[trackIndex] = kTRUE;
e4f2f73d 1557
1558
d739fd4e 1559 // Build track label - what happens if measured data ???
1560 Int_t labels[1000];
1561 Int_t outlab[1000];
1562 Int_t nlab = 0;
1563 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
972ef65e 1564 Int_t jseed = kNPlanes*trackIndex+iLayer;
1565 if(!sseed[jseed].IsOK()) continue;
1566 for(int ilab=0; ilab<2; ilab++){
1567 if(sseed[jseed].GetLabels(ilab) < 0) continue;
1568 labels[nlab] = sseed[jseed].GetLabels(ilab);
1569 nlab++;
1570 }
d739fd4e 1571 }
1572 Freq(nlab,labels,outlab,kFALSE);
1573 Int_t label = outlab[0];
1574 Int_t frequency = outlab[1];
1575 Freq(nlabelsall,labelsall,outlab,kFALSE);
1576 Int_t label1 = outlab[0];
1577 Int_t label2 = outlab[2];
1578 Float_t fakeratio = (naccepted - outlab[1]) / Float_t(naccepted);
e4f2f73d 1579
1580
d739fd4e 1581 // Sign clusters
1582 AliTRDcluster *cl = 0x0; Int_t clusterIndex = -1;
1583 for (Int_t jLayer = 0; jLayer < 6; jLayer++) {
972ef65e 1584 Int_t jseed = kNPlanes*trackIndex+jLayer;
1585 if(!sseed[jseed].IsOK()) continue;
1586 if(TMath::Abs(sseed[jseed].GetYfit(1) - sseed[jseed].GetYfit(1)) >= .2) continue; // check this condition with Marian
1587 sseed[jseed].UseClusters();
1588 if(!cl){
1589 Int_t ic = 0;
1590 while(!(cl = sseed[jseed].GetClusters(ic))) ic++;
1591 clusterIndex = sseed[jseed].GetIndexes(ic);
1592 }
d739fd4e 1593 }
1594 if(!cl) continue;
e4f2f73d 1595
1596
d739fd4e 1597 // Build track parameters
1598 AliTRDseedV1 *lseed =&sseed[trackIndex*6];
1599 Int_t idx = 0;
1600 while(idx<3 && !lseed->IsOK()) {
972ef65e 1601 idx++;
1602 lseed++;
d739fd4e 1603 }
1604 Double_t cR = lseed->GetC();
1605 trackParams[1] = lseed->GetYref(0);
1606 trackParams[2] = lseed->GetZref(0);
1607 trackParams[3] = lseed->GetX0() * cR - TMath::Sin(TMath::ATan(lseed->GetYref(1)));
1608 trackParams[4] = lseed->GetZref(1) / TMath::Sqrt(1. + lseed->GetYref(1) * lseed->GetYref(1));
1609 trackParams[5] = cR;
1610 trackParams[0] = lseed->GetX0();
1611 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
1612 trackParams[6] = fGeom->GetSector(chamber->GetDetector());/* *alpha+shift; // Supermodule*/
1613
1614 if(AliTRDReconstructor::StreamLevel() > 1){
972ef65e 1615 AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
eb38ed55 1616
972ef65e 1617 Int_t nclusters = 0;
1618 AliTRDseedV1 *dseed[6];
1619 for(int is=0; is<6; is++){
1620 dseed[is] = new AliTRDseedV1(sseed[trackIndex*6+is]);
1621 dseed[is]->SetOwner();
1622 nclusters += sseed[is].GetN2();
1623 }
1624 //Int_t eventNrInFile = esd->GetEventNumberInFile();
1625 //AliInfo(Form("Number of clusters %d.", nclusters));
1626 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1627 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
1628 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1629 TTreeSRedirector &cstreamer = *fgDebugStreamer;
1630 cstreamer << "Clusters2TracksStack"
1631 << "EventNumber=" << eventNumber
1632 << "TrackNumber=" << trackNumber
1633 << "CandidateNumber=" << candidateNumber
1634 << "Iter=" << fSieveSeeding
1635 << "Like=" << fTrackQuality[trackIndex]
1636 << "S0.=" << dseed[0]
1637 << "S1.=" << dseed[1]
1638 << "S2.=" << dseed[2]
1639 << "S3.=" << dseed[3]
1640 << "S4.=" << dseed[4]
1641 << "S5.=" << dseed[5]
1642 << "p0=" << trackParams[0]
1643 << "p1=" << trackParams[1]
1644 << "p2=" << trackParams[2]
1645 << "p3=" << trackParams[3]
1646 << "p4=" << trackParams[4]
1647 << "p5=" << trackParams[5]
1648 << "p6=" << trackParams[6]
1649 << "Label=" << label
1650 << "Label1=" << label1
1651 << "Label2=" << label2
1652 << "FakeRatio=" << fakeratio
1653 << "Freq=" << frequency
1654 << "Ncl=" << ncl
1655 << "NLayers=" << nlayers
1656 << "Findable=" << findable
1657
1658 << "NUsed=" << nused
1659 << "\n";
d739fd4e 1660 }
e4f2f73d 1661
d739fd4e 1662 AliTRDtrackV1 *track = MakeTrack(&sseed[trackIndex*kNPlanes], trackParams);
d739fd4e 1663 if(!track){
972ef65e 1664 //AliWarning("Fail to build a TRD Track.");
1665 continue;
d739fd4e 1666 }
1667 //AliInfo("End of MakeTrack()");
749f58fa 1668 // computes PID for track
1669 track->CookPID();
1670 // update calibration references using this track
1671 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(track);
d739fd4e 1672 AliESDtrack esdTrack;
1673 esdTrack.UpdateTrackParams(track, AliESDtrack::kTRDout);
1674 esdTrack.SetLabel(track->GetLabel());
749f58fa 1675 track->UpdateESDtrack(&esdTrack);
d739fd4e 1676 // write ESD-friends if neccessary
1677 if (AliTRDReconstructor::StreamLevel() > 0){
972ef65e 1678 //printf("Creating Calibrations Object\n");
1679 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
1680 calibTrack->SetOwner();
1681 esdTrack.AddCalibObject(calibTrack);
d739fd4e 1682 }
1683 new ((*esdTrackList)[ntracks0++]) AliESDtrack(esdTrack);
1684 ntracks1++;
1685 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
972ef65e 1686 }
d739fd4e 1687
972ef65e 1688 jSieve++;
1689 } while(jSieve<5 && candidates); // end track candidates sieve
1690 if(!ntracks1) break;
d739fd4e 1691
972ef65e 1692 // increment counters
1693 ntracks2 += ntracks1;
1694 fSieveSeeding++;
d739fd4e 1695
972ef65e 1696 // Rebuild plane configurations and indices taking only unused clusters into account
1697 quality = BuildSeedingConfigs(stack, configs);
1698 if(quality < 1.E-7) break; //AliTRDReconstructor::RecoParam()->GetPlaneQualityThreshold()) break;
e4f2f73d 1699
972ef65e 1700 for(Int_t ip = 0; ip < kNPlanes; ip++){
1701 if(!(chamber = stack[ip])) continue;
1702 chamber->Build(fGeom);//Indices(fSieveSeeding);
1703 }
1704
1705 if(AliTRDReconstructor::StreamLevel() > 1){
1706 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
1707 }
1708 } while(fSieveSeeding<10); // end stack clusters sieve
e4f2f73d 1709
1710
1711
972ef65e 1712 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
e4f2f73d 1713
972ef65e 1714 return ntracks2;
e4f2f73d 1715}
1716
1717//___________________________________________________________________
eb38ed55 1718Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
e4f2f73d 1719{
972ef65e 1720 //
1721 // Assign probabilities to chambers according to their
1722 // capability of producing seeds.
1723 //
1724 // Parameters :
1725 //
1726 // layers : Array of stack propagation layers for all 6 chambers in one stack
1727 // configs : On exit array of configuration indexes (see GetSeedingConfig()
1728 // for details) in the decreasing order of their seeding probabilities.
1729 //
1730 // Output :
1731 //
1732 // Return top configuration quality
1733 //
1734 // Detailed description:
1735 //
1736 // To each chamber seeding configuration (see GetSeedingConfig() for
1737 // the list of all configurations) one defines 2 quality factors:
1738 // - an apriori topological quality (see GetSeedingConfig() for details) and
1739 // - a data quality based on the uniformity of the distribution of
1740 // clusters over the x range (time bins population). See CookChamberQA() for details.
1741 // The overall chamber quality is given by the product of this 2 contributions.
1742 //
1743
1744 Double_t chamberQ[kNPlanes];
1745 AliTRDtrackingChamber *chamber = 0x0;
1746 for(int iplane=0; iplane<kNPlanes; iplane++){
1747 if(!(chamber = stack[iplane])) continue;
1748 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
1749 }
1750
1751 Double_t tconfig[kNConfigs];
1752 Int_t planes[4];
1753 for(int iconf=0; iconf<kNConfigs; iconf++){
1754 GetSeedingConfig(iconf, planes);
1755 tconfig[iconf] = fgTopologicQA[iconf];
1756 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
1757 }
1758
1759 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
1760 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
1761 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
1762 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
1763
1764 return tconfig[configs[0]];
e4f2f73d 1765}
1766
1767//____________________________________________________________________
eb38ed55 1768Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 *sseed, Int_t *ipar)
e4f2f73d 1769{
972ef65e 1770 //
1771 // Make tracklet seeds in the TRD stack.
1772 //
1773 // Parameters :
1774 // layers : Array of stack propagation layers containing clusters
1775 // sseed : Array of empty tracklet seeds. On exit they are filled.
1776 // ipar : Control parameters:
1777 // ipar[0] -> seeding chambers configuration
1778 // ipar[1] -> stack index
1779 // ipar[2] -> number of track candidates found so far
1780 //
1781 // Output :
1782 // Number of tracks candidates found.
1783 //
1784 // Detailed description
1785 //
1786 // The following steps are performed:
1787 // 1. Select seeding layers from seeding chambers
1788 // 2. Select seeding clusters from the seeding AliTRDpropagationLayerStack.
1789 // The clusters are taken from layer 3, layer 0, layer 1 and layer 2, in
1790 // this order. The parameters controling the range of accepted clusters in
1791 // layer 0, 1, and 2 are defined in AliTRDchamberTimeBin::BuildCond().
1792 // 3. Helix fit of the cluster set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**))
1793 // 4. Initialize seeding tracklets in the seeding chambers.
1794 // 5. Filter 0.
1795 // Chi2 in the Y direction less than threshold ... (1./(3. - sLayer))
1796 // Chi2 in the Z direction less than threshold ... (1./(3. - sLayer))
1797 // 6. Attach clusters to seeding tracklets and find linear approximation of
1798 // the tracklet (see AliTRDseedV1::AttachClustersIter()). The number of used
1799 // clusters used by current seeds should not exceed ... (25).
1800 // 7. Filter 1.
1801 // All 4 seeding tracklets should be correctly constructed (see
1802 // AliTRDseedV1::AttachClustersIter())
1803 // 8. Helix fit of the seeding tracklets
1804 // 9. Filter 2.
1805 // Likelihood calculation of the fit. (See AliTRDtrackerV1::CookLikelihood() for details)
1806 // 10. Extrapolation of the helix fit to the other 2 chambers:
1807 // a) Initialization of extrapolation tracklet with fit parameters
1808 // b) Helix fit of tracklets
1809 // c) Attach clusters and linear interpolation to extrapolated tracklets
1810 // d) Helix fit of tracklets
1811 // 11. Improve seeding tracklets quality by reassigning clusters.
1812 // See AliTRDtrackerV1::ImproveSeedQuality() for details.
1813 // 12. Helix fit of all 6 seeding tracklets and chi2 calculation
1814 // 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
1815 // 14. Cooking labels for tracklets. Should be done only for MC
1816 // 15. Register seeds.
1817 //
1818
1819 AliTRDtrackingChamber *chamber = 0x0;
1820 AliTRDcluster *c[4] = {0x0, 0x0, 0x0, 0x0}; // initilize seeding clusters
1821 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
1822 Int_t ncl, mcl; // working variable for looping over clusters
1823 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
1824 // chi2 storage
1825 // chi2[0] = tracklet chi2 on the Z direction
1826 // chi2[1] = tracklet chi2 on the R direction
1827 Double_t chi2[4];
1828
1829
1830 // this should be data member of AliTRDtrack
1831 Double_t seedQuality[kMaxTracksStack];
1832
1833 // unpack control parameters
1834 Int_t config = ipar[0];
1835 Int_t ntracks = ipar[1];
1836 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
1837
1838 // Init chambers geometry
1839 Int_t ic = 0; while(!(chamber = stack[ic])) ic++;
1840 Int_t istack = fGeom->GetChamber(chamber->GetDetector());
1841 Double_t hL[kNPlanes]; // Tilting angle
1842 Float_t padlength[kNPlanes]; // pad lenghts
1843 AliTRDpadPlane *pp = 0x0;
1844 for(int iplane=0; iplane<kNPlanes; iplane++){
1845 pp = fGeom->GetPadPlane(iplane, istack);
1846 hL[iplane] = TMath::Tan(-TMath::DegToRad()*pp->GetTiltingAngle());
1847 padlength[iplane] = pp->GetLengthIPad();
1848 }
1849
1850 if(AliTRDReconstructor::StreamLevel() > 1){
1851 AliInfo(Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
1852 }
1853
1854 Int_t nlayers = 0;
1855 AliTRDchamberTimeBin *layer[] = {0x0, 0x0, 0x0, 0x0};
1856 for(int isl=0; isl<kNSeedPlanes; isl++){
1857 if(!(chamber = stack[planes[isl]])) continue;
1858 if(!(layer[isl] = chamber->GetSeedingLayer(fGeom))) continue;
1859 nlayers++;
1860 //AliInfo(Form("seeding plane %d clusters %d", planes[isl], Int_t(*layer[isl])));
1861 }
1862 if(nlayers < 4) return 0;
1863
1864
1865 // Start finding seeds
1866 Double_t cond0[4], cond1[4], cond2[4];
1867 Int_t icl = 0;
1868 while((c[3] = (*layer[3])[icl++])){
1869 if(!c[3]) continue;
1870 layer[0]->BuildCond(c[3], cond0, 0);
1871 layer[0]->GetClusters(cond0, index, ncl);
1872 //printf("Found c[3] candidates 0 %d\n", ncl);
1873 Int_t jcl = 0;
1874 while(jcl<ncl) {
1875 c[0] = (*layer[0])[index[jcl++]];
1876 if(!c[0]) continue;
1877 Double_t dx = c[3]->GetX() - c[0]->GetX();
1878 Double_t theta = (c[3]->GetZ() - c[0]->GetZ())/dx;
1879 Double_t phi = (c[3]->GetY() - c[0]->GetY())/dx;
1880 layer[1]->BuildCond(c[0], cond1, 1, theta, phi);
1881 layer[1]->GetClusters(cond1, jndex, mcl);
1882 //printf("Found c[0] candidates 1 %d\n", mcl);
1883
1884 Int_t kcl = 0;
1885 while(kcl<mcl) {
d739fd4e 1886 c[1] = (*layer[1])[jndex[kcl++]];
1887 if(!c[1]) continue;
1888 layer[2]->BuildCond(c[1], cond2, 2, theta, phi);
1889 c[2] = layer[2]->GetNearestCluster(cond2);
1890 //printf("Found c[1] candidate 2 %p\n", c[2]);
1891 if(!c[2]) continue;
e4f2f73d 1892
d739fd4e 1893 // AliInfo("Seeding clusters found. Building seeds ...");
1894 // 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());
eb38ed55 1895
d739fd4e 1896 for (Int_t il = 0; il < 6; il++) cseed[il].Reset();
1897
1898 FitRieman(c, chi2);
1899
1900 AliTRDseedV1 *tseed = 0x0;
1901 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
972ef65e 1902 Int_t jLayer = planes[iLayer];
1903 tseed = &cseed[jLayer];
1904 tseed->SetPlane(jLayer);
1905 tseed->SetTilt(hL[jLayer]);
1906 tseed->SetPadLength(padlength[jLayer]);
1907 tseed->SetX0(stack[jLayer]->GetX());
1908 tseed->Init(GetRiemanFitter());
d739fd4e 1909 }
1910
1911 Bool_t isFake = kFALSE;
1912 if(AliTRDReconstructor::StreamLevel() >= 2){
972ef65e 1913 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
1914 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
1915 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
1916
1917 Double_t xpos[4];
1918 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = layer[l]->GetX();
1919 Float_t yref[4];
1920 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
1921 Int_t ll = c[3]->GetLabel(0);
1922 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1923 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1924 AliRieman *rim = GetRiemanFitter();
1925 TTreeSRedirector &cs0 = *fgDebugStreamer;
1926 cs0 << "MakeSeeds0"
1927 <<"EventNumber=" << eventNumber
1928 <<"CandidateNumber=" << candidateNumber
1929 <<"isFake=" << isFake
1930 <<"config=" << config
1931 <<"label=" << ll
1932 <<"chi2z=" << chi2[0]
1933 <<"chi2y=" << chi2[1]
1934 <<"Y2exp=" << cond2[0]
1935 <<"Z2exp=" << cond2[1]
1936 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
1937 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
1938 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
1939 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
1940 <<"yref0=" << yref[0]
1941 <<"yref1=" << yref[1]
1942 <<"yref2=" << yref[2]
1943 <<"yref3=" << yref[3]
1944 <<"c0.=" << c[0]
1945 <<"c1.=" << c[1]
1946 <<"c2.=" << c[2]
1947 <<"c3.=" << c[3]
1948 <<"Seed0.=" << &cseed[planes[0]]
1949 <<"Seed1.=" << &cseed[planes[1]]
1950 <<"Seed2.=" << &cseed[planes[2]]
1951 <<"Seed3.=" << &cseed[planes[3]]
1952 <<"RiemanFitter.=" << rim
1953 <<"\n";
d739fd4e 1954 }
1955
1956 if(chi2[0] > AliTRDReconstructor::RecoParam()->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
972ef65e 1957 //AliInfo(Form("Failed chi2 filter on chi2Z [%f].", chi2[0]));
1958 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
1959 continue;
d739fd4e 1960 }
1961 if(chi2[1] > AliTRDReconstructor::RecoParam()->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
972ef65e 1962 //AliInfo(Form("Failed chi2 filter on chi2Y [%f].", chi2[1]));
1963 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
1964 continue;
d739fd4e 1965 }
1966 //AliInfo("Passed chi2 filter.");
1967
1968 // try attaching clusters to tracklets
1969 Int_t nUsedCl = 0;
1970 Int_t nlayers = 0;
1971 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
972ef65e 1972 Int_t jLayer = planes[iLayer];
1973 if(!cseed[jLayer].AttachClustersIter(stack[jLayer], 5., kFALSE, c[iLayer])) continue;
1974 nUsedCl += cseed[jLayer].GetNUsed();
1975 if(nUsedCl > 25) break;
1976 nlayers++;
d739fd4e 1977 }
1978 if(nlayers < kNSeedPlanes){
972ef65e 1979 //AliInfo(Form("Failed updating all seeds %d [%d].", nlayers, kNSeedPlanes));
1980 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
1981 continue;
d739fd4e 1982 }
1983 // fit tracklets and cook likelihood
1984 FitTiltedRieman(&cseed[0], kTRUE);// Update Seeds and calculate Likelihood
1985 chi2[0] = GetChi2Y(&cseed[0]);
1986 chi2[1] = GetChi2Z(&cseed[0]);
1987 //Chi2 definitions in testing stage
1988 //chi2[0] = GetChi2YTest(&cseed[0]);
1989 //chi2[1] = GetChi2ZTest(&cseed[0]);
1990 Double_t like = CookLikelihood(&cseed[0], planes, chi2); // to be checked
1991
1992 if (TMath::Log(1.E-9 + like) < AliTRDReconstructor::RecoParam()->GetTrackLikelihood()){
972ef65e 1993 //AliInfo(Form("Failed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
1994 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
1995 continue;
d739fd4e 1996 }
1997 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
1998
1999 // book preliminary results
2000 seedQuality[ntracks] = like;
2001 fSeedLayer[ntracks] = config;/*sLayer;*/
2002
2003 // attach clusters to the extrapolation seeds
2004 Int_t lextrap[2];
2005 GetExtrapolationConfig(config, lextrap);
2006 Int_t nusedf = 0; // debug value
2007 for(int iLayer=0; iLayer<2; iLayer++){
972ef65e 2008 Int_t jLayer = lextrap[iLayer];
2009 if(!(chamber = stack[jLayer])) continue;
eb38ed55 2010
972ef65e 2011 // prepare extrapolated seed
2012 cseed[jLayer].Reset();
2013 cseed[jLayer].SetPlane(jLayer);
2014 cseed[jLayer].SetTilt(hL[jLayer]);
2015 cseed[jLayer].SetX0(chamber->GetX());
2016 cseed[jLayer].SetPadLength(padlength[jLayer]);
2017
2018 // fit extrapolated seed
2019 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2020 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2021 AliTRDseedV1 tseed = cseed[jLayer];
2022 if(!tseed.AttachClustersIter(chamber, 1000.)) continue;
2023 cseed[jLayer] = tseed;
2024 nusedf += cseed[jLayer].GetNUsed(); // debug value
2025 FitTiltedRieman(cseed, kTRUE);
d739fd4e 2026 }
2027
2028 // AliInfo("Extrapolation done.");
2029 // Debug Stream containing all the 6 tracklets
2030 if(AliTRDReconstructor::StreamLevel() >= 2){
972ef65e 2031 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2032 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2033 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2034 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2035 cstreamer << "MakeSeeds1"
2036 << "EventNumber=" << eventNumber
2037 << "CandidateNumber=" << candidateNumber
2038 << "S0.=" << &cseed[0]
2039 << "S1.=" << &cseed[1]
2040 << "S2.=" << &cseed[2]
2041 << "S3.=" << &cseed[3]
2042 << "S4.=" << &cseed[4]
2043 << "S5.=" << &cseed[5]
2044 << "FitterT.=" << tiltedRieman
2045 << "\n";
d739fd4e 2046 }
bb56afff 2047
d739fd4e 2048 if(ImproveSeedQuality(stack, cseed) < 4){
972ef65e 2049 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2050 continue;
d739fd4e 2051 }
2052 //AliInfo("Improve seed quality done.");
2053
2054 // fit full track and cook likelihoods
2055 // Double_t curv = FitRieman(&cseed[0], chi2);
2056 // Double_t chi2ZF = chi2[0] / TMath::Max((nlayers - 3.), 1.);
2057 // Double_t chi2RF = chi2[1] / TMath::Max((nlayers - 3.), 1.);
2058
2059 // do the final track fitting (Once with vertex constraint and once without vertex constraint)
2060 Double_t chi2Vals[3];
2061 chi2Vals[0] = FitTiltedRieman(&cseed[0], kFALSE);
2062 chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ());
2063 chi2Vals[2] = GetChi2Z(&cseed[0]) / TMath::Max((nlayers - 3.), 1.);
2064 // Chi2 definitions in testing stage
2065 //chi2Vals[2] = GetChi2ZTest(&cseed[0]);
2066 fTrackQuality[ntracks] = CalculateTrackLikelihood(&cseed[0], &chi2Vals[0]);
2067 //AliInfo("Hyperplane fit done\n");
2068
2069 // finalize tracklets
2070 Int_t labels[12];
2071 Int_t outlab[24];
2072 Int_t nlab = 0;
2073 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
972ef65e 2074 if (!cseed[iLayer].IsOK()) continue;
d739fd4e 2075
972ef65e 2076 if (cseed[iLayer].GetLabels(0) >= 0) {
2077 labels[nlab] = cseed[iLayer].GetLabels(0);
2078 nlab++;
2079 }
d739fd4e 2080
972ef65e 2081 if (cseed[iLayer].GetLabels(1) >= 0) {
2082 labels[nlab] = cseed[iLayer].GetLabels(1);
2083 nlab++;
2084 }
d739fd4e 2085 }
2086 Freq(nlab,labels,outlab,kFALSE);
2087 Int_t label = outlab[0];
2088 Int_t frequency = outlab[1];
2089 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
972ef65e 2090 cseed[iLayer].SetFreq(frequency);
2091 cseed[iLayer].SetChi2Z(chi2[1]);
d739fd4e 2092 }
972ef65e 2093
d739fd4e 2094 if(AliTRDReconstructor::StreamLevel() >= 2){
972ef65e 2095 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2096 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2097 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2098 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2099 TLinearFitter *fitterT = GetTiltedRiemanFitter();
2100 cstreamer << "MakeSeeds2"
2101 << "EventNumber=" << eventNumber
2102 << "CandidateNumber=" << candidateNumber
2103 << "Chi2TR=" << chi2Vals[0]
2104 << "Chi2TC=" << chi2Vals[1]
2105 << "Nlayers=" << nlayers
2106 << "NUsedS=" << nUsedCl
2107 << "NUsed=" << nusedf
2108 << "Like=" << like
2109 << "S0.=" << &cseed[0]
2110 << "S1.=" << &cseed[1]
2111 << "S2.=" << &cseed[2]
2112 << "S3.=" << &cseed[3]
2113 << "S4.=" << &cseed[4]
2114 << "S5.=" << &cseed[5]
2115 << "Label=" << label
2116 << "Freq=" << frequency
2117 << "FitterT.=" << fitterT
2118 << "FitterTC.=" << fitterTC
2119 << "\n";
d739fd4e 2120 }
e4f2f73d 2121
d739fd4e 2122 ntracks++;
2123 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2124 if(ntracks == kMaxTracksStack){
972ef65e 2125 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
2126 for(int isl=0; isl<4; isl++) delete layer[isl];
2127 return ntracks;
e4f2f73d 2128 }
d739fd4e 2129 cseed += 6;
972ef65e 2130 }
2131 }
2132 }
2133 for(int isl=0; isl<4; isl++) delete layer[isl];
e4f2f73d 2134
972ef65e 2135 return ntracks;
e4f2f73d 2136}
2137
2138//_____________________________________________________________________________
0906e73e 2139AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 *seeds, Double_t *params)
e4f2f73d 2140{
972ef65e 2141 //
2142 // Build a TRD track out of tracklet candidates
2143 //
2144 // Parameters :
2145 // seeds : array of tracklets
2146 // params : track parameters (see MakeSeeds() function body for a detailed description)
2147 //
2148 // Output :
2149 // The TRD track.
2150 //
2151 // Detailed description
2152 //
2153 // To be discussed with Marian !!
2154 //
2155
2156 Double_t alpha = AliTRDgeometry::GetAlpha();
2157 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
2158 Double_t c[15];
2159
2160 c[ 0] = 0.2;
2161 c[ 1] = 0.0; c[ 2] = 2.0;
2162 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02;
2163 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1;
2164 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[5]*params[5]*0.01;
2165
2166 AliTRDtrackV1 *track = new AliTRDtrackV1(seeds, &params[1], c, params[0], params[6]*alpha+shift);
2167 track->PropagateTo(params[0]-5.0);
2168 track->ResetCovariance(1);
2169 Int_t nc = FollowBackProlongation(*track);
2170 //AliInfo(Form("N clusters for track %d", nc));
2171 if (nc < 30) {
2172 delete track;
2173 track = 0x0;
2174 } else {
2175 track->CookdEdx();
2176 track->CookdEdxTimBin(-1);
2177 track->CookLabel(.9);
2178 }
2179
2180 return track;
e4f2f73d 2181}
2182
0906e73e 2183
e4f2f73d 2184//____________________________________________________________________
eb38ed55 2185Int_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed)
e4f2f73d 2186{
972ef65e 2187 //
2188 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
2189 //
2190 // Parameters :
2191 // layers : Array of propagation layers for a stack/supermodule
2192 // cseed : Array of 6 seeding tracklets which has to be improved
2193 //
2194 // Output :
2195 // cssed : Improved seeds
2196 //
2197 // Detailed description
2198 //
2199 // Iterative procedure in which new clusters are searched for each
2200 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
2201 // can be maximized. If some optimization is found the old seeds are replaced.
2202 //
2203 // debug level: 7
2204 //
2205
2206 // make a local working copy
2207 AliTRDtrackingChamber *chamber = 0x0;
2208 AliTRDseedV1 bseed[6];
2209 Int_t nLayers = 0;
2210 for (Int_t jLayer = 0; jLayer < 6; jLayer++) bseed[jLayer] = cseed[jLayer];
2211
2212 Float_t lastquality = 10000.0;
2213 Float_t lastchi2 = 10000.0;
2214 Float_t chi2 = 1000.0;
2215
2216 for (Int_t iter = 0; iter < 4; iter++) {
2217 Float_t sumquality = 0.0;
2218 Float_t squality[6];
2219 Int_t sortindexes[6];
2220
2221 for (Int_t jLayer = 0; jLayer < 6; jLayer++) {
2222 squality[jLayer] = bseed[jLayer].IsOK() ? bseed[jLayer].GetQuality(kTRUE) : -1.;
2223 sumquality += squality[jLayer];
2224 }
2225 if ((sumquality >= lastquality) || (chi2 > lastchi2)) break;
2226
2227 nLayers = 0;
2228 lastquality = sumquality;
2229 lastchi2 = chi2;
2230 if (iter > 0) for (Int_t jLayer = 0; jLayer < 6; jLayer++) cseed[jLayer] = bseed[jLayer];
2231
2232 TMath::Sort(6, squality, sortindexes, kFALSE);
2233 for (Int_t jLayer = 5; jLayer > 1; jLayer--) {
2234 Int_t bLayer = sortindexes[jLayer];
2235 if(!(chamber = stack[bLayer])) continue;
2236 bseed[bLayer].AttachClustersIter(chamber, squality[bLayer], kTRUE);
2237 if(bseed[bLayer].IsOK()) nLayers++;
2238 }
2239
2240 chi2 = FitTiltedRieman(bseed, kTRUE);
2241 if(AliTRDReconstructor::StreamLevel() >= 7){
2242 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2243 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2244 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2245 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2246 cstreamer << "ImproveSeedQuality"
d739fd4e 2247 << "EventNumber=" << eventNumber
2248 << "CandidateNumber=" << candidateNumber
2249 << "Iteration=" << iter
2250 << "S0.=" << &bseed[0]
2251 << "S1.=" << &bseed[1]
2252 << "S2.=" << &bseed[2]
2253 << "S3.=" << &bseed[3]
2254 << "S4.=" << &bseed[4]
2255 << "S5.=" << &bseed[5]
2256 << "FitterT.=" << tiltedRieman
2257 << "\n";
972ef65e 2258 }
2259 } // Loop: iter
eb38ed55 2260
972ef65e 2261 // we are sure that at least 2 tracklets are OK !
2262 return nLayers+2;
e4f2f73d 2263}
2264
eb38ed55 2265//_________________________________________________________________________
2266Double_t AliTRDtrackerV1::CalculateTrackLikelihood(AliTRDseedV1 *tracklets, Double_t *chi2){
972ef65e 2267 //
2268 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
2269 // the track selection
2270 // The likelihood value containes:
2271 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
2272 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
2273 // For all Parameters an exponential dependency is used
2274 //
2275 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
2276 // - Array of chi2 values:
2277 // * Non-Constrained Tilted Riemann fit
2278 // * Vertex-Constrained Tilted Riemann fit
2279 // * z-Direction from Linear fit
2280 // Output: - The calculated track likelihood
2281 //
2282 // debug level 2
2283 //
2284
2285 Double_t sumdaf = 0, nLayers = 0;
2286 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
2287 if(!tracklets[iLayer].IsOK()) continue;
2288 sumdaf += TMath::Abs((tracklets[iLayer].GetYfit(1) - tracklets[iLayer].GetYref(1))/ tracklets[iLayer].GetSigmaY2());
2289 nLayers++;
2290 }
2291 sumdaf /= Float_t (nLayers - 2.0);
2292
2293 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14); // Chi2Z
2294 Double_t likeChi2TC = TMath::Exp(-chi2[1] * 0.677); // Constrained Tilted Riemann
2295 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.78); // Non-constrained Tilted Riemann
2296 Double_t likeAF = TMath::Exp(-sumdaf * 3.23);
2297 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeAF;
2298
2299 if(AliTRDReconstructor::StreamLevel() >= 2){
2300 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2301 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2302 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2303 cstreamer << "CalculateTrackLikelihood0"
2304 << "EventNumber=" << eventNumber
2305 << "CandidateNumber=" << candidateNumber
2306 << "LikeChi2Z=" << likeChi2Z
2307 << "LikeChi2TR=" << likeChi2TR
2308 << "LikeChi2TC=" << likeChi2TC
2309 << "LikeAF=" << likeAF
2310 << "TrackLikelihood=" << trackLikelihood
2311 << "\n";
2312 }
2313
2314 return trackLikelihood;
e4f2f73d 2315}
2316
2317//____________________________________________________________________
eb38ed55 2318Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4]
972ef65e 2319 , Double_t *chi2)
e4f2f73d 2320{
972ef65e 2321 //
2322 // Calculate the probability of this track candidate.
2323 //
2324 // Parameters :
2325 // cseeds : array of candidate tracklets
2326 // planes : array of seeding planes (see seeding configuration)
2327 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
2328 //
2329 // Output :
2330 // likelihood value
2331 //
2332 // Detailed description
2333 //
2334 // The track quality is estimated based on the following 4 criteria:
2335 // 1. precision of the rieman fit on the Y direction (likea)
2336 // 2. chi2 on the Y direction (likechi2y)
2337 // 3. chi2 on the Z direction (likechi2z)
2338 // 4. number of attached clusters compared to a reference value
2339 // (see AliTRDrecoParam::fkFindable) (likeN)
2340 //
2341 // The distributions for each type of probabilities are given below as of
2342 // (date). They have to be checked to assure consistency of estimation.
2343 //
2344
2345 // ratio of the total number of clusters/track which are expected to be found by the tracker.
2346 Float_t fgFindable = AliTRDReconstructor::RecoParam()->GetFindableClusters();
2347
2348
2349 Int_t nclusters = 0;
2350 Double_t sumda = 0.;
2351 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
2352 Int_t jlayer = planes[ilayer];
2353 nclusters += cseed[jlayer].GetN2();
2354 sumda += TMath::Abs(cseed[jlayer].GetYfitR(1) - cseed[jlayer].GetYref(1));
2355 }
2356 Double_t likea = TMath::Exp(-sumda*10.6);
2357 Double_t likechi2y = 0.0000000001;
2358 if (chi2[0] < 0.5) likechi2y += TMath::Exp(-TMath::Sqrt(chi2[0]) * 7.73);
2359 Double_t likechi2z = TMath::Exp(-chi2[1] * 0.088) / TMath::Exp(-chi2[1] * 0.019);
2360 Int_t enc = Int_t(fgFindable*4.*fgNTimeBins); // Expected Number Of Clusters, normally 72
2361 Double_t likeN = TMath::Exp(-(enc - nclusters) * 0.19);
2362
2363 Double_t like = likea * likechi2y * likechi2z * likeN;
2364
2365 // 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));
2366 if(AliTRDReconstructor::StreamLevel() >= 2){
2367 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2368 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2369 // The Debug Stream contains the seed
2370 TTreeSRedirector &cstreamer = *fgDebugStreamer;
2371 cstreamer << "CookLikelihood"
2372 << "EventNumber=" << eventNumber
2373 << "CandidateNumber=" << candidateNumber
2374 << "tracklet0.=" << &cseed[0]
2375 << "tracklet1.=" << &cseed[1]
2376 << "tracklet2.=" << &cseed[2]
2377 << "tracklet3.=" << &cseed[3]
2378 << "tracklet4.=" << &cseed[4]
2379 << "tracklet5.=" << &cseed[5]
2380 << "sumda=" << sumda
2381 << "chi0=" << chi2[0]
2382 << "chi1=" << chi2[1]
2383 << "likea=" << likea
2384 << "likechi2y=" << likechi2y
2385 << "likechi2z=" << likechi2z
2386 << "nclusters=" << nclusters
2387 << "likeN=" << likeN
2388 << "like=" << like
2389 << "\n";
2390 }
2391
2392 return like;
e4f2f73d 2393}
2394
eb38ed55 2395
e4f2f73d 2396
2397//____________________________________________________________________
0906e73e 2398void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
e4f2f73d 2399{
972ef65e 2400 //
2401 // Map seeding configurations to detector planes.
2402 //
2403 // Parameters :
2404 // iconfig : configuration index
2405 // planes : member planes of this configuration. On input empty.
2406 //
2407 // Output :
2408 // planes : contains the planes which are defining the configuration
2409 //
2410 // Detailed description
2411 //
2412 // Here is the list of seeding planes configurations together with
2413 // their topological classification:
2414 //
2415 // 0 - 5432 TQ 0
2416 // 1 - 4321 TQ 0
2417 // 2 - 3210 TQ 0
2418 // 3 - 5321 TQ 1
2419 // 4 - 4210 TQ 1
2420 // 5 - 5431 TQ 1
2421 // 6 - 4320 TQ 1
2422 // 7 - 5430 TQ 2
2423 // 8 - 5210 TQ 2
2424 // 9 - 5421 TQ 3
2425 // 10 - 4310 TQ 3
2426 // 11 - 5410 TQ 4
2427 // 12 - 5420 TQ 5
2428 // 13 - 5320 TQ 5
2429 // 14 - 5310 TQ 5
2430 //
2431 // The topologic quality is modeled as follows:
2432 // 1. The general model is define by the equation:
2433 // p(conf) = exp(-conf/2)
2434 // 2. According to the topologic classification, configurations from the same
2435 // class are assigned the agerage value over the model values.
2436 // 3. Quality values are normalized.
2437 //
2438 // The topologic quality distribution as function of configuration is given below:
2439 //Begin_Html
2440 // <img src="gif/topologicQA.gif">
2441 //End_Html
2442 //
2443
2444 switch(iconfig){
2445 case 0: // 5432 TQ 0
2446 planes[0] = 2;
2447 planes[1] = 3;
2448 planes[2] = 4;
2449 planes[3] = 5;
2450 break;
2451 case 1: // 4321 TQ 0
2452 planes[0] = 1;
2453 planes[1] = 2;
2454 planes[2] = 3;
2455 planes[3] = 4;
2456 break;
2457 case 2: // 3210 TQ 0
2458 planes[0] = 0;
2459 planes[1] = 1;
2460 planes[2] = 2;
2461 planes[3] = 3;
2462 break;
2463 case 3: // 5321 TQ 1
2464 planes[0] = 1;
2465 planes[1] = 2;
2466 planes[2] = 3;
2467 planes[3] = 5;
2468 break;
2469 case 4: // 4210 TQ 1
2470 planes[0] = 0;
2471 planes[1] = 1;
2472 planes[2] = 2;
2473 planes[3] = 4;
2474 break;
2475 case 5: // 5431 TQ 1
2476 planes[0] = 1;
2477 planes[1] = 3;
2478 planes[2] = 4;
2479 planes[3] = 5;
2480 break;
2481 case 6: // 4320 TQ 1
2482 planes[0] = 0;
2483 planes[1] = 2;
2484 planes[2] = 3;
2485 planes[3] = 4;
2486 break;
2487 case 7: // 5430 TQ 2
2488 planes[0] = 0;
2489 planes[1] = 3;
2490 planes[2] = 4;
2491 planes[3] = 5;
2492 break;
2493 case 8: // 5210 TQ 2
2494 planes[0] = 0;
2495 planes[1] = 1;
2496 planes[2] = 2;
2497 planes[3] = 5;
2498 break;
2499 case 9: // 5421 TQ 3
2500 planes[0] = 1;
2501 planes[1] = 2;
2502 planes[2] = 4;
2503 planes[3] = 5;
2504 break;
2505 case 10: // 4310 TQ 3
2506 planes[0] = 0;
2507 planes[1] = 1;
2508 planes[2] = 3;
2509 planes[3] = 4;
2510 break;
2511 case 11: // 5410 TQ 4
2512 planes[0] = 0;
2513 planes[1] = 1;
2514 planes[2] = 4;
2515 planes[3] = 5;
2516 break;
2517 case 12: // 5420 TQ 5
2518 planes[0] = 0;
2519 planes[1] = 2;
2520 planes[2] = 4;
2521 planes[3] = 5;
2522 break;
2523 case 13: // 5320 TQ 5
2524 planes[0] = 0;
2525 planes[1] = 2;
2526 planes[2] = 3;
2527 planes[3] = 5;
2528 break;
2529 case 14: // 5310 TQ 5
2530 planes[0] = 0;
2531 planes[1] = 1;
2532 planes[2] = 3;
2533 planes[3] = 5;
2534 break;
2535 }
e4f2f73d 2536}
2537
2538//____________________________________________________________________
0906e73e 2539void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
e4f2f73d 2540{
972ef65e 2541 //
2542 // Returns the extrapolation planes for a seeding configuration.
2543 //
2544 // Parameters :
2545 // iconfig : configuration index
2546 // planes : planes which are not in this configuration. On input empty.
2547 //
2548 // Output :
2549 // planes : contains the planes which are not in the configuration
2550 //
2551 // Detailed description
2552 //
2553
2554 switch(iconfig){
2555 case 0: // 5432 TQ 0
2556 planes[0] = 1;
2557 planes[1] = 0;
2558 break;
2559 case 1: // 4321 TQ 0
2560 planes[0] = 5;
2561 planes[1] = 0;
2562 break;
2563 case 2: // 3210 TQ 0
2564 planes[0] = 4;
2565 planes[1] = 5;
2566 break;
2567 case 3: // 5321 TQ 1
2568 planes[0] = 4;
2569 planes[1] = 0;
2570 break;
2571 case 4: // 4210 TQ 1
2572 planes[0] = 5;
2573 planes[1] = 3;
2574 break;
2575 case 5: // 5431 TQ 1
2576 planes[0] = 2;
2577 planes[1] = 0;
2578 break;
2579 case 6: // 4320 TQ 1
2580 planes[0] = 5;
2581 planes[1] = 1;
2582 break;
2583 case 7: // 5430 TQ 2
2584 planes[0] = 2;
2585 planes[1] = 1;
2586 break;
2587 case 8: // 5210 TQ 2
2588 planes[0] = 4;
2589 planes[1] = 3;
2590 break;
2591 case 9: // 5421 TQ 3
2592 planes[0] = 3;
2593 planes[1] = 0;
2594 break;
2595 case 10: // 4310 TQ 3
2596 planes[0] = 5;
2597 planes[1] = 2;
2598 break;
2599 case 11: // 5410 TQ 4
2600 planes[0] = 3;
2601 planes[1] = 2;
2602 break;
2603 case 12: // 5420 TQ 5
2604 planes[0] = 3;
2605 planes[1] = 1;
2606 break;
2607 case 13: // 5320 TQ 5
2608 planes[0] = 4;
2609 planes[1] = 1;
2610 break;
2611 case 14: // 5310 TQ 5
2612 planes[0] = 4;
2613 planes[1] = 2;
2614 break;
2615 }
e4f2f73d 2616}
eb38ed55 2617
2618//____________________________________________________________________
2619AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
2620{
972ef65e 2621 Int_t ncls = fClusters->GetEntriesFast();
2622 return idx >= 0 || idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : 0x0;
eb38ed55 2623}
2624
bb56afff 2625//____________________________________________________________________
2626Float_t AliTRDtrackerV1::CalculateReferenceX(AliTRDseedV1 *tracklets){
972ef65e 2627 //
2628 // Calculates the reference x-position for the tilted Rieman fit defined as middle
2629 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
2630 // are taken into account
2631 //
2632 // Parameters: - Array of tracklets(AliTRDseedV1)
2633 //
2634 // Output: - The reference x-position(Float_t)
2635 //
2636 Int_t nDistances = 0;
2637 Float_t meanDistance = 0.;
2638 Int_t startIndex = 5;
2639 for(Int_t il =5; il > 0; il--){
2640 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
2641 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
2642 meanDistance += xdiff;
2643 nDistances++;
2644 }
2645 if(tracklets[il].IsOK()) startIndex = il;
2646 }
2647 if(tracklets[0].IsOK()) startIndex = 0;
2648 if(!nDistances){
2649 // We should normally never get here
2650 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
2651 Int_t iok = 0, idiff = 0;
2652 // This attempt is worse and should be avoided:
2653 // check for two chambers which are OK and repeat this without taking the mean value
2654 // Strategy avoids a division by 0;
2655 for(Int_t il = 5; il >= 0; il--){
2656 if(tracklets[il].IsOK()){
d739fd4e 2657 xpos[iok] = tracklets[il].GetX0();
2658 iok++;
2659 startIndex = il;
972ef65e 2660 }
2661 if(iok) idiff++; // to get the right difference;
2662 if(iok > 1) break;
2663 }
2664 if(iok > 1){
2665 meanDistance = (xpos[0] - xpos[1])/idiff;
2666 }
2667 else{
2668 // we have do not even have 2 layers which are OK? The we do not need to fit at all
2669 return 331.;
2670 }
2671 }
2672 else{
2673 meanDistance /= nDistances;
2674 }
2675 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
bb56afff 2676}
eb38ed55 2677
2678//_____________________________________________________________________________
2679Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
972ef65e 2680 , Int_t *outlist, Bool_t down)
eb38ed55 2681{
972ef65e 2682 //
2683 // Sort eleements according occurancy
2684 // The size of output array has is 2*n
2685 //
2686
2687 if (n <= 0) {
2688 return 0;
2689 }
2690
2691 Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
2692 Int_t *sindexF = new Int_t[2*n];
2693 for (Int_t i = 0; i < n; i++) {
2694 sindexF[i] = 0;
2695 }
2696
2697 TMath::Sort(n,inlist,sindexS,down);
2698
2699 Int_t last = inlist[sindexS[0]];
2700 Int_t val = last;
2701 sindexF[0] = 1;
2702 sindexF[0+n] = last;
2703 Int_t countPos = 0;
2704
2705 // Find frequency
2706 for (Int_t i = 1; i < n; i++) {
2707 val = inlist[sindexS[i]];
2708 if (last == val) {
2709 sindexF[countPos]++;
2710 }
2711 else {
2712 countPos++;
2713 sindexF[countPos+n] = val;
2714 sindexF[countPos]++;
2715 last = val;
2716 }
2717 }
2718 if (last == val) {
2719 countPos++;
2720 }
2721
2722 // Sort according frequency
2723 TMath::Sort(countPos,sindexF,sindexS,kTRUE);
2724
2725 for (Int_t i = 0; i < countPos; i++) {
2726 outlist[2*i ] = sindexF[sindexS[i]+n];
2727 outlist[2*i+1] = sindexF[sindexS[i]];
2728 }
2729
2730 delete [] sindexS;
2731 delete [] sindexF;
2732
2733 return countPos;
eb38ed55 2734
2735}
bb56afff 2736
2737//_____________________________________________________________________________
2738Float_t AliTRDtrackerV1::GetChi2Y(AliTRDseedV1 *tracklets) const
2739{
972ef65e 2740 // Chi2 definition on y-direction
2741
2742 Float_t chi2 = 0;
2743 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
2744 if(!tracklets[ipl].IsOK()) continue;
2745 Double_t distLayer = tracklets[ipl].GetYfit(0) - tracklets[ipl].GetYref(0);
2746 chi2 += distLayer * distLayer;
2747 }
2748 return chi2;
bb56afff 2749}
2750
2751//_____________________________________________________________________________
2752Float_t AliTRDtrackerV1::GetChi2Z(AliTRDseedV1 *tracklets) const
2753{
972ef65e 2754 // Chi2 definition on z-direction
2755
2756 Float_t chi2 = 0;
2757 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
2758 if(!tracklets[ipl].IsOK()) continue;
2759 Double_t distLayer = tracklets[ipl].GetMeanz() - tracklets[ipl].GetZref(0);
2760 chi2 += distLayer * distLayer;
2761 }
2762 return chi2;
bb56afff 2763}
8acca6a3 2764
2765///////////////////////////////////////////////////////
2766// //
2767// Resources of class AliTRDLeastSquare //
2768// //
2769///////////////////////////////////////////////////////
2770
2771//_____________________________________________________________________________
2772AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
972ef65e 2773 //
2774 // Constructor of the nested class AliTRDtrackFitterLeastSquare
2775 //
2776 memset(fParams, 0, sizeof(Double_t) * 2);
2777 memset(fSums, 0, sizeof(Double_t) * 5);
2778 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
8acca6a3 2779
2780}
2781
2782//_____________________________________________________________________________
2783void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(Double_t *x, Double_t y, Double_t sigmaY){
972ef65e 2784 //
2785 // Adding Point to the fitter
2786 //
2787 Double_t weight = 1/(sigmaY * sigmaY);
2788 Double_t &xpt = *x;
2789 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
2790 fSums[0] += weight;
2791 fSums[1] += weight * xpt;
2792 fSums[2] += weight * y;
2793 fSums[3] += weight * xpt * y;
2794 fSums[4] += weight * xpt * xpt;
2795 fSums[5] += weight * y * y;
8acca6a3 2796}
2797
2798//_____________________________________________________________________________
2799void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(Double_t *x, Double_t y, Double_t sigmaY){
972ef65e 2800 //
2801 // Remove Point from the sample
2802 //
2803 Double_t weight = 1/(sigmaY * sigmaY);
2804 Double_t &xpt = *x;
2805 fSums[0] -= weight;
2806 fSums[1] -= weight * xpt;
2807 fSums[2] -= weight * y;
2808 fSums[3] -= weight * xpt * y;
2809 fSums[4] -= weight * xpt * xpt;
2810 fSums[5] -= weight * y * y;
8acca6a3 2811}
2812
2813//_____________________________________________________________________________
2814void AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
972ef65e 2815 //
2816 // Evaluation of the fit:
2817 // Calculation of the parameters
2818 // Calculation of the covariance matrix
2819 //
2820
2821 Double_t denominator = fSums[0] * fSums[4] - fSums[1] *fSums[1];
2822 // for(Int_t isum = 0; isum < 5; isum++)
2823 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
2824 // printf("denominator = %f\n", denominator);
2825 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/ denominator;
2826 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2]) / denominator;
2827 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
2828
2829 // Covariance matrix
2830 fCovarianceMatrix[0] = fSums[4] - fSums[1] * fSums[1] / fSums[0];
2831 fCovarianceMatrix[1] = fSums[5] - fSums[2] * fSums[2] / fSums[0];
2832 fCovarianceMatrix[2] = fSums[3] - fSums[1] * fSums[2] / fSums[0];
8acca6a3 2833}
2834
46b6abd7 2835//_____________________________________________________________________________
2836Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(Double_t *xpos) const {
972ef65e 2837 //
2838 // Returns the Function value of the fitted function at a given x-position
2839 //
2840 return fParams[0] + fParams[1] * (*xpos);
46b6abd7 2841}
2842
2843//_____________________________________________________________________________
2844void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
972ef65e 2845 //
2846 // Copies the values of the covariance matrix into the storage
2847 //
2848 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
46b6abd7 2849}
2850