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