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