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