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