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