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