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