]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDtrackerV1.cxx
Merge branch 'master' into TPCdev
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
CommitLineData
e4f2f73d 1/**************************************************************************
972ef65e 2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
e4f2f73d 15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Track finder //
21// //
22// Authors: //
23// Alex Bercuci <A.Bercuci@gsi.de> //
24// Markus Fasel <M.Fasel@gsi.de> //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
e4f2f73d 28#include <TBranch.h>
bb56afff 29#include <TDirectory.h>
e4f2f73d 30#include <TLinearFitter.h>
e4f2f73d 31#include <TTree.h>
32#include <TClonesArray.h>
e4f2f73d 33#include <TTreeStream.h>
eb2b4f91 34#include <TGeoMatrix.h>
35#include <TGeoManager.h>
e4f2f73d 36
37#include "AliLog.h"
fac58f00 38#include "AliMathBase.h"
e4f2f73d 39#include "AliESDEvent.h"
bb56afff 40#include "AliGeomManager.h"
e4f2f73d 41#include "AliRieman.h"
42#include "AliTrackPointArray.h"
43
e4f2f73d 44#include "AliTRDgeometry.h"
45#include "AliTRDpadPlane.h"
e4f2f73d 46#include "AliTRDcalibDB.h"
e4f2f73d 47#include "AliTRDReconstructor.h"
48#include "AliTRDCalibraFillHisto.h"
e4f2f73d 49#include "AliTRDrecoParam.h"
bb56afff 50
51#include "AliTRDcluster.h"
828c6f80 52#include "AliTRDdigitsParam.h"
e4f2f73d 53#include "AliTRDseedV1.h"
0906e73e 54#include "AliTRDtrackV1.h"
bb56afff 55#include "AliTRDtrackerV1.h"
56#include "AliTRDtrackerDebug.h"
57#include "AliTRDtrackingChamber.h"
58#include "AliTRDchamberTimeBin.h"
59
e4f2f73d 60ClassImp(AliTRDtrackerV1)
903326c1 61ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
62ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
eb38ed55 63
2f4384e6 64AliTRDtrackerV1::ETRDtrackerV1BetheBloch AliTRDtrackerV1::fgBB = AliTRDtrackerV1::kGeant;
d76231c8 65Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
6e39bde4 66 0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
41702fec 67 0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
68 0.0474, 0.0408, 0.0335, 0.0335, 0.0335
e165b64b 69};
70const Double_t AliTRDtrackerV1::fgkX0[kNPlanes] = {
71 300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
952051c5 72// Number of Time Bins/chamber should be also stored independently by the traker
73// (also in AliTRDReconstructor) in oder to be able to run HLT. Fix TODO
2985ffcb 74Int_t AliTRDtrackerV1::fgNTimeBins = 0;
4d6aee34 75AliRieman* AliTRDtrackerV1::fgRieman = NULL;
76TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
77TLinearFitter* AliTRDtrackerV1::fgTiltedRiemanConstrained = NULL;
e4f2f73d 78
79//____________________________________________________________________
33ab3872 80AliTRDtrackerV1::AliTRDtrackerV1(const AliTRDReconstructor *rec)
41702fec 81 :AliTracker()
4d6aee34 82 ,fkReconstructor(NULL)
9e85cb05 83 ,fkRecoParam(NULL)
4d6aee34 84 ,fGeom(NULL)
85 ,fClusters(NULL)
86 ,fTracklets(NULL)
87 ,fTracks(NULL)
b1135f96 88 ,fTracksESD(NULL)
41702fec 89 ,fSieveSeeding(0)
9dcc64cc 90 ,fEventInFile(-1)
e4f2f73d 91{
41702fec 92 //
93 // Default constructor.
94 //
eb2b4f91 95
96 SetReconstructor(rec); // initialize reconstructor
97
98 // initialize geometry
99 if(!AliGeomManager::GetGeometry()){
100 AliFatal("Could not get geometry.");
101 }
102 fGeom = new AliTRDgeometry();
103 fGeom->CreateClusterMatrixArray();
4d6aee34 104 TGeoHMatrix *matrix = NULL;
eb2b4f91 105 Double_t loc[] = {0., 0., 0.};
106 Double_t glb[] = {0., 0., 0.};
107 for(Int_t ily=kNPlanes; ily--;){
e165b64b 108 Int_t ism = 0;
109 while(!(matrix = fGeom->GetClusterMatrix(AliTRDgeometry::GetDetector(ily, 2, ism)))) ism++;
110 if(!matrix){
111 AliError(Form("Could not get transformation matrix for layer %d. Use default.", ily));
112 fR[ily] = fgkX0[ily];
eb2b4f91 113 continue;
114 }
115 matrix->LocalToMaster(loc, glb);
116 fR[ily] = glb[0]+ AliTRDgeometry::AnodePos()-.5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick();
117 }
118
eb2b4f91 119 // initialize cluster containers
053767a4 120 for (Int_t isector = 0; isector < AliTRDgeometry::kNsector; isector++) new(&fTrSec[isector]) AliTRDtrackingSector(fGeom, isector);
3a039a31 121
eb2b4f91 122 // initialize arrays
123 memset(fTrackQuality, 0, kMaxTracksStack*sizeof(Double_t));
124 memset(fSeedLayer, 0, kMaxTracksStack*sizeof(Int_t));
125 memset(fSeedTB, 0, kNSeedPlanes*sizeof(AliTRDchamberTimeBin*));
b1135f96 126 fTracksESD = new TClonesArray("AliESDtrack", 2*kMaxTracksStack);
ddfbc51a 127 fTracksESD->SetOwner();
eb38ed55 128}
129
e4f2f73d 130//____________________________________________________________________
131AliTRDtrackerV1::~AliTRDtrackerV1()
132{
41702fec 133 //
134 // Destructor
135 //
d2eba04b 136
4d6aee34 137 if(fgRieman) delete fgRieman; fgRieman = NULL;
138 if(fgTiltedRieman) delete fgTiltedRieman; fgTiltedRieman = NULL;
139 if(fgTiltedRiemanConstrained) delete fgTiltedRiemanConstrained; fgTiltedRiemanConstrained = NULL;
d611c74f 140 for(Int_t isl =0; isl<kNSeedPlanes; isl++) if(fSeedTB[isl]) delete fSeedTB[isl];
b1135f96 141 if(fTracksESD){ fTracksESD->Delete(); delete fTracksESD; }
41702fec 142 if(fTracks) {fTracks->Delete(); delete fTracks;}
143 if(fTracklets) {fTracklets->Delete(); delete fTracklets;}
d2eba04b 144 if(IsClustersOwner() && fClusters) {
145 AliInfo(Form("tracker[%p] removing %d own clusters @ %p", (void*)this, fClusters->GetEntries(), (void*)fClusters));
48f8adf3 146 fClusters->Delete(); delete fClusters;
147 }
41702fec 148 if(fGeom) delete fGeom;
e4f2f73d 149}
150
151//____________________________________________________________________
152Int_t AliTRDtrackerV1::Clusters2Tracks(AliESDEvent *esd)
153{
41702fec 154 //
155 // Steering stand alone tracking for full TRD detector
156 //
157 // Parameters :
158 // esd : The ESD event. On output it contains
159 // the ESD tracks found in TRD.
160 //
161 // Output :
162 // Number of tracks found in the TRD detector.
163 //
164 // Detailed description
165 // 1. Launch individual SM trackers.
166 // See AliTRDtrackerV1::Clusters2TracksSM() for details.
167 //
168
9e85cb05 169 if(!fkRecoParam){
3a039a31 170 AliError("Reconstruction configuration not initialized. Call first AliTRDReconstructor::SetRecoParam().");
41702fec 171 return 0;
172 }
173
174 //AliInfo("Start Track Finder ...");
175 Int_t ntracks = 0;
053767a4 176 for(int ism=0; ism<AliTRDgeometry::kNsector; ism++){
41702fec 177 // for(int ism=1; ism<2; ism++){
178 //AliInfo(Form("Processing supermodule %i ...", ism));
179 ntracks += Clusters2TracksSM(ism, esd);
180 }
980d5a2a 181 AliInfo(Form("Number of tracks: !TRDin[%d]", ntracks));
41702fec 182 return ntracks;
e4f2f73d 183}
184
0906e73e 185
186//_____________________________________________________________________________
eb38ed55 187Bool_t AliTRDtrackerV1::GetTrackPoint(Int_t index, AliTrackPoint &p) const
0906e73e 188{
41702fec 189 //AliInfo(Form("Asking for tracklet %d", index));
190
84eab75a 191 // reset position of the point before using it
192 p.SetXYZ(0., 0., 0.);
2f7514a6 193 AliTRDseedV1 *tracklet = GetTracklet(index);
194 if (!tracklet) return kFALSE;
84eab75a 195
41702fec 196 // get detector for this tracklet
e165b64b 197 Int_t det = tracklet->GetDetector();
198 Int_t sec = fGeom->GetSector(det);
199 Double_t alpha = (sec+.5)*AliTRDgeometry::GetAlpha(),
200 sinA = TMath::Sin(alpha),
201 cosA = TMath::Cos(alpha);
41702fec 202 Double_t local[3];
e165b64b 203 local[0] = tracklet->GetX();
204 local[1] = tracklet->GetY();
205 local[2] = tracklet->GetZ();
41702fec 206 Double_t global[3];
e165b64b 207 fGeom->RotateBack(det, local, global);
208
209 Double_t cov2D[3]; Float_t cov[6];
210 tracklet->GetCovAt(local[0], cov2D);
211 cov[0] = cov2D[0]*sinA*sinA;
212 cov[1] =-cov2D[0]*sinA*cosA;
213 cov[2] =-cov2D[1]*sinA;
214 cov[3] = cov2D[0]*cosA*cosA;
215 cov[4] = cov2D[1]*cosA;
216 cov[5] = cov2D[2];
217 // store the global position of the tracklet and its covariance matrix in the track point
218 p.SetXYZ(global[0],global[1],global[2], cov);
41702fec 219
220 // setting volume id
e165b64b 221 AliGeomManager::ELayerID iLayer = AliGeomManager::ELayerID(AliGeomManager::kTRD1+fGeom->GetLayer(det));
222 Int_t modId = fGeom->GetSector(det) * AliTRDgeometry::kNstack + fGeom->GetStack(det);
41702fec 223 UShort_t volid = AliGeomManager::LayerToVolUID(iLayer, modId);
224 p.SetVolumeID(volid);
225
226 return kTRUE;
0906e73e 227}
228
eb38ed55 229//____________________________________________________________________
230TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitter()
231{
41702fec 232 if(!fgTiltedRieman) fgTiltedRieman = new TLinearFitter(4, "hyp4");
233 return fgTiltedRieman;
eb38ed55 234}
0906e73e 235
eb38ed55 236//____________________________________________________________________
237TLinearFitter* AliTRDtrackerV1::GetTiltedRiemanFitterConstraint()
238{
41702fec 239 if(!fgTiltedRiemanConstrained) fgTiltedRiemanConstrained = new TLinearFitter(2, "hyp2");
240 return fgTiltedRiemanConstrained;
eb38ed55 241}
41702fec 242
eb38ed55 243//____________________________________________________________________
244AliRieman* AliTRDtrackerV1::GetRiemanFitter()
245{
fac58f00 246 if(!fgRieman) fgRieman = new AliRieman(AliTRDseedV1::kNtb * AliTRDgeometry::kNlayer);
41702fec 247 return fgRieman;
eb38ed55 248}
41702fec 249
0906e73e 250//_____________________________________________________________________________
251Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
252{
2a3191bb 253// Propagation of ESD tracks from TPC to TOF detectors and building of the TRD track. For building
254// a TRD track an ESD track is used as seed. The informations obtained on the TRD track (measured points,
255// covariance, PID, etc.) are than used to update the corresponding ESD track.
256// Each track seed is first propagated to the geometrical limit of the TRD detector.
257// Its prolongation is searched in the TRD and if corresponding clusters are found tracklets are
258// constructed out of them (see AliTRDseedV1::AttachClusters()) and the track is updated.
259// Otherwise the ESD track is left unchanged.
260//
261// The following steps are performed:
262// 1. Selection of tracks based on the variance in the y-z plane.
263// 2. Propagation to the geometrical limit of the TRD volume. If track propagation fails the AliESDtrack::kTRDStop is set.
264// 3. Prolongation inside the fiducial volume (see AliTRDtrackerV1::FollowBackProlongation()) and marking
265// the following status bits:
266// - AliESDtrack::kTRDin - if the tracks enters the TRD fiducial volume
267// - AliESDtrack::kTRDStop - if the tracks fails propagation
268// - AliESDtrack::kTRDbackup - if the tracks fulfills chi2 conditions and qualify for refitting
269// 4. Writting to friends, PID, MC label, quality etc. Setting status bit AliESDtrack::kTRDout.
270// 5. Propagation to TOF. If track propagation fails the AliESDtrack::kTRDStop is set.
271//
272
e3d45279 273 if(!fClusters || !fClusters->GetEntriesFast()){
274 AliInfo("No TRD clusters");
275 return 0;
276 }
2a3191bb 277 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance(); // Calibration monitor
e3d45279 278 if (!calibra) AliInfo("Could not get Calibra instance");
c6f7c6cb 279 if (!fgNTimeBins) fgNTimeBins = fkReconstructor->GetNTimeBins();
828c6f80 280
eb2b4f91 281 // Define scalers
88987d18 282 Int_t nFound = 0, // number of tracks found
283 nBacked = 0, // number of tracks backed up for refit
284 nSeeds = 0, // total number of ESD seeds
285 nTRDseeds= 0, // number of seeds in the TRD acceptance
286 nTPCseeds= 0; // number of TPC seeds
41702fec 287 Float_t foundMin = 20.0;
88987d18 288
289 Float_t *quality = NULL;
290 Int_t *index = NULL;
9dcc64cc 291 fEventInFile = event->GetEventNumberInFile();
eb2b4f91 292 nSeeds = event->GetNumberOfTracks();
293 // Sort tracks according to quality
294 // (covariance in the yz plane)
295 if(nSeeds){
88987d18 296 quality = new Float_t[nSeeds];
297 index = new Int_t[4*nSeeds];
298 for (Int_t iSeed = nSeeds; iSeed--;) {
d611c74f 299 AliESDtrack *seed = event->GetTrack(iSeed);
300 Double_t covariance[15];
301 seed->GetExternalCovariance(covariance);
88987d18 302 quality[iSeed] = covariance[0] + covariance[2];
d611c74f 303 }
88987d18 304 TMath::Sort(nSeeds, quality, index,kFALSE);
41702fec 305 }
88987d18 306
eb2b4f91 307 // Propagate all seeds
41702fec 308 Int_t expectedClr;
309 AliTRDtrackV1 track;
88987d18 310 for (Int_t iSeed = 0; iSeed < nSeeds; iSeed++) {
311
312 // Get the seeds in sorted sequence
313 AliESDtrack *seed = event->GetTrack(index[iSeed]);
314 Float_t p4 = seed->GetC(seed->GetBz());
315
316 // Check the seed status
317 ULong_t status = seed->GetStatus();
318 if ((status & AliESDtrack::kTRDout) != 0) continue;
319 if ((status & AliESDtrack::kTPCout)){
320 AliDebug(3, Form("Prolongate seed[%2d] which is TPC.", iSeed));
321 // set steering parameters for TPC
322 //fkRecoParam->SetTrackParam(kTPC);
323/* } else {
324 if ((status & AliESDtrack::kITSout)){
325 AliDebug(3, Form("Prolongate seed[%2d] which is ITS.", iSeed));
326 // set steering parameters for ITS
327 //fkRecoParam->SetTrackParam(kITS);
328 // rotate
329 Float_t globalToTracking = AliTRDgeometry::GetAlpha()*(Int_t(seed->GetAlpha()/AliTRDgeometry::GetAlpha()) + (seed->GetAlpha()>0. ? 0.5 : -0.5));
330 if(!seed->Rotate(globalToTracking)) continue;
331 } else continue;*/
332 } else continue;
333
334 // Propagate to the entrance in the TRD mother volume
335 track.~AliTRDtrackV1();
336 new(&track) AliTRDtrackV1(*seed);
337 if(AliTRDgeometry::GetXtrdBeg() > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), AliTRDReconstructor::GetMaxStep())){
338 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
339 continue;
340 }
341 if(!AdjustSector(&track)){
342 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
343 continue;
344 }
345 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
346 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
347 continue;
348 }
349 nTPCseeds++;
350 AliDebug(2, Form("TRD propagate TPC seed[%d] = %d.", iSeed, index[iSeed]));
351 // store track status at TRD entrance
352 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
353
354 // prepare track and do propagation in the TRD
355 track.SetReconstructor(fkReconstructor);
356 track.SetKink(Bool_t(seed->GetKinkIndex(0)));
357 track.SetPrimary(status & AliESDtrack::kTPCin);
358 expectedClr = FollowBackProlongation(track);
359 // check if track entered the TRD fiducial volume
360 if(track.GetTrackIn()){
361 seed->UpdateTrackParams(&track, AliESDtrack::kTRDin);
362 nTRDseeds++;
363 }
364 // check if track was stopped in the TRD
365 if (expectedClr<0){
366 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
367 continue;
368 } else {
369 nFound++;
370 // compute PID
371 track.CookPID();
372 //compute MC label
373 track.CookLabel(1. - AliTRDReconstructor::GetLabelFraction());
374 // update calibration references using this track
375 if(calibra->GetHisto2d()) calibra->UpdateHistogramsV1(&track);
41702fec 376 // save calibration object
d0177bb6 377 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ) {
224f357f 378 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(track);
379 calibTrack->SetOwner();
380 seed->AddCalibObject(calibTrack);
381 }
88987d18 382 //update ESD track
383 seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
384 track.UpdateESDtrack(seed);
385 }
4b5b4c5b 386
88987d18 387 // Make backup for back propagation
388 if ((TMath::Abs(track.GetC(track.GetBz()) - p4) / TMath::Abs(p4) < 0.2) || (track.Pt() > 0.8)) {
389 Int_t foundClr = track.GetNumberOfClusters();
390 if (foundClr >= foundMin) {
391 //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
4b5b4c5b 392
88987d18 393 // Sign only gold tracks
394 if (track.GetChi2() / track.GetNumberOfClusters() < 4) {
395 //if ((seed->GetKinkIndex(0) == 0) && (track.Pt() < 1.5)) UseClusters(&track);
396 }
397 Bool_t isGold = kFALSE;
398
399 // Full gold track
400 if (track.GetChi2() / track.GetNumberOfClusters() < 5) {
401 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
402 nBacked++;
403 isGold = kTRUE;
404 }
405
406 // Almost gold track
407 if ((!isGold) && (track.GetNCross() == 0) && (track.GetChi2() / track.GetNumberOfClusters() < 7)) {
408 //seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
409 if (track.GetBackupTrack()) seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
410 nBacked++;
411 isGold = kTRUE;
412 }
413
414 if ((!isGold) && (track.GetBackupTrack())) {
415 if ((track.GetBackupTrack()->GetNumberOfClusters() > foundMin) && ((track.GetBackupTrack()->GetChi2()/(track.GetBackupTrack()->GetNumberOfClusters()+1)) < 7)) {
416 seed->UpdateTrackParams(track.GetBackupTrack(),AliESDtrack::kTRDbackup);
4b5b4c5b 417 nBacked++;
418 isGold = kTRUE;
419 }
41702fec 420 }
41702fec 421 }
88987d18 422 }
423
424 // Propagation to the TOF
425 if(!(seed->GetStatus()&AliESDtrack::kTRDStop)) {
426 Int_t sm = track.GetSector();
427 // default value in case we have problems with the geometry.
428 Double_t xtof = 371.;
429 //Calculate radial position of the beginning of the TOF
430 //mother volume. In order to avoid mixing of the TRD
431 //and TOF modules some hard values are needed. This are:
432 //1. The path to the TOF module.
433 //2. The width of the TOF (29.05 cm)
434 //(with the help of Annalisa de Caro Mar-17-2009)
435 if(gGeoManager){
436 gGeoManager->cd(Form("/ALIC_1/B077_1/BSEGMO%d_1/BTOF%d_1", sm, sm));
437 TGeoHMatrix *m = NULL;
438 Double_t loc[]={0., 0., -.5*29.05}, glob[3];
439
440 if((m=gGeoManager->GetCurrentMatrix())){
441 m->LocalToMaster(loc, glob);
442 xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
4b5b4c5b 443 }
41702fec 444 }
88987d18 445 if(xtof > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, xtof, AliTRDReconstructor::GetMaxStep())){
446 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
447 continue;
448 }
449 if(!AdjustSector(&track)){
450 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
451 continue;
452 }
453 if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
454 seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
455 continue;
456 }
457 //seed->UpdateTrackParams(&track, AliESDtrack::kTRDout);
458 // TODO obsolete - delete
459 seed->SetTRDQuality(track.StatusForTOF());
41702fec 460 }
88987d18 461 seed->SetTRDBudget(track.GetBudget(0));
41702fec 462 }
88987d18 463 if(index) delete [] index;
464 if(quality) delete [] quality;
41702fec 465
88987d18 466 AliInfo(Form("Number of seeds: TPCout[%d] TRDin[%d]", nTPCseeds, nTRDseeds));
467 AliInfo(Form("Number of tracks: TRDout[%d] TRDbackup[%d]", nFound, nBacked));
d4cf71ca 468
d611c74f 469 // run stand alone tracking
4d6aee34 470 if (fkReconstructor->IsSeeding()) Clusters2Tracks(event);
41702fec 471
472 return 0;
0906e73e 473}
474
475
476//____________________________________________________________________
477Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
478{
41702fec 479 //
480 // Refits tracks within the TRD. The ESD event is expected to contain seeds
481 // at the outer part of the TRD.
482 // The tracks are propagated to the innermost time bin
483 // of the TRD and the ESD event is updated
484 // Origin: Thomas KUHR (Thomas.Kuhr@cern.ch)
485 //
486
487 Int_t nseed = 0; // contor for loaded seeds
488 Int_t found = 0; // contor for updated TRD tracks
489
490
e3d45279 491 if(!fClusters || !fClusters->GetEntriesFast()){
492 AliInfo("No TRD clusters");
493 return 0;
494 }
41702fec 495 AliTRDtrackV1 track;
496 for (Int_t itrack = 0; itrack < event->GetNumberOfTracks(); itrack++) {
497 AliESDtrack *seed = event->GetTrack(itrack);
050875b0 498 ULong_t status = seed->GetStatus();
88987d18 499
050875b0 500 new(&track) AliTRDtrackV1(*seed);
41702fec 501 if (track.GetX() < 270.0) {
502 seed->UpdateTrackParams(&track, AliESDtrack::kTRDbackup);
503 continue;
504 }
88987d18 505
506 // reject tracks which failed propagation in the TRD or
507 // are produced by the TRD stand alone tracker
508 if(!(status & AliESDtrack::kTRDout)) continue;
509 if(!(status & AliESDtrack::kTRDin)) continue;
510 nseed++;
41702fec 511
512 track.ResetCovariance(50.0);
513
514 // do the propagation and processing
515 Bool_t kUPDATE = kFALSE;
88987d18 516 Double_t xTPC = 250.0;
41702fec 517 if(FollowProlongation(track)){
e3cf3d02 518 // Update the friend track
d0177bb6 519 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
4d6aee34 520 TObject *o = NULL; Int_t ic = 0;
521 AliTRDtrackV1 *calibTrack = NULL;
e3cf3d02 522 while((o = seed->GetCalibObject(ic++))){
523 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
a310e49b 524 calibTrack->SetTrackOut(&track);
e3cf3d02 525 }
41702fec 526 }
a310e49b 527
528 // Prolongate to TPC
88987d18 529 if (PropagateToX(track, xTPC, AliTRDReconstructor::GetMaxStep())) { // -with update
a310e49b 530 seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
531 found++;
532 kUPDATE = kTRUE;
533 }
e3cf3d02 534 }
41702fec 535
536 // Prolongate to TPC without update
537 if(!kUPDATE) {
538 AliTRDtrackV1 tt(*seed);
88987d18 539 if (PropagateToX(tt, xTPC, AliTRDReconstructor::GetMaxStep())) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
41702fec 540 }
541 }
980d5a2a 542 AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
543 AliInfo(Form("Number of tracks: TRDrefit[%d]", found));
41702fec 544
545 return 0;
0906e73e 546}
547
0906e73e 548//____________________________________________________________________
549Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
550{
41702fec 551 // Extrapolates the TRD track in the TPC direction.
552 //
553 // Parameters
554 // t : the TRD track which has to be extrapolated
555 //
556 // Output
557 // number of clusters attached to the track
558 //
559 // Detailed description
560 //
561 // Starting from current radial position of track <t> this function
562 // extrapolates the track through the 6 TRD layers. The following steps
563 // are being performed for each plane:
564 // 1. prepare track:
565 // a. get plane limits in the local x direction
566 // b. check crossing sectors
567 // c. check track inclination
568 // 2. search tracklet in the tracker list (see GetTracklet() for details)
569 // 3. evaluate material budget using the geo manager
570 // 4. propagate and update track using the tracklet information.
571 //
572 // Debug level 2
573 //
574
575 Int_t nClustersExpected = 0;
e3cf3d02 576 for (Int_t iplane = kNPlanes; iplane--;) {
17896e82 577 Int_t index(-1);
41702fec 578 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
17896e82 579 AliDebug(2, Form("Tracklet[%p] ly[%d] idx[%d]", (void*)tracklet, iplane, index));
41702fec 580 if(!tracklet) continue;
980d5a2a 581 if(!tracklet->IsOK()){
582 AliDebug(1, Form("Tracklet Det[%d] !OK", tracklet->GetDetector()));
583 continue;
584 }
e3cf3d02 585 Double_t x = tracklet->GetX();//GetX0();
41702fec 586 // reject tracklets which are not considered for inward refit
88987d18 587 if(x > t.GetX()+AliTRDReconstructor::GetMaxStep()) continue;
588
41702fec 589 // append tracklet to track
590 t.SetTracklet(tracklet, index);
591
952051c5 592 if (x < (t.GetX()-AliTRDReconstructor::GetMaxStep()) && !PropagateToX(t, x+AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) break;
41702fec 593 if (!AdjustSector(&t)) break;
594
595 // Start global position
596 Double_t xyz0[3];
597 t.GetXYZ(xyz0);
598
599 // End global position
600 Double_t alpha = t.GetAlpha(), y, z;
601 if (!t.GetProlongation(x,y,z)) break;
602 Double_t xyz1[3];
603 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
604 xyz1[1] = x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
605 xyz1[2] = z;
606
51a23065 607 Double_t length = TMath::Sqrt(
608 (xyz0[0]-xyz1[0])*(xyz0[0]-xyz1[0]) +
609 (xyz0[1]-xyz1[1])*(xyz0[1]-xyz1[1]) +
610 (xyz0[2]-xyz1[2])*(xyz0[2]-xyz1[2])
611 );
612 if(length>0.){
613 // Get material budget
614 Double_t param[7];
615 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) break;
616 Double_t xrho= param[0]*param[4];
617 Double_t xx0 = param[1]; // Get mean propagation parameters
618
619 // Propagate and update
620 t.PropagateTo(x, xx0, xrho);
621 if (!AdjustSector(&t)) break;
622 }
e3cf3d02 623
b72f4eaf 624 Double_t cov[3]; tracklet->GetCovAt(x, cov);
625 Double_t p[2] = { tracklet->GetY(), tracklet->GetZ()};
626 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
68d29486 627 if(fkReconstructor->IsDebugStreaming()){
bda5ad6d 628 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
629 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
630 AliExternalTrackParam param0(t);
631 AliExternalTrackParam param1(t);
632 param1.Update(p, cov);
633 TVectorD vcov(3,cov);
634 TVectorD vpar(3,p);
635 cstreamer << "FollowProlongationInfo"
636 << "EventNumber=" << eventNumber
637 << "iplane="<<iplane
638 << "vcov.="<<&vcov
639 << "vpar.="<<&vpar
640 << "tracklet.=" << tracklet
641 << "param0.=" << &param0
642 << "param1.=" << &param1
643 << "\n";
644 }
ef867f55 645 if (chi2 < 1e+10 && ((AliExternalTrackParam&)t).Update(p, cov)){
646 // Register info to track
647 t.SetNumberOfClusters();
648 t.UpdateChi2(chi2);
41702fec 649 nClustersExpected += tracklet->GetN();
650 }
651 }
652
d0177bb6 653 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 || AliTRDReconstructor::GetStreamLevel()>1){
41702fec 654 Int_t index;
51a23065 655 for(int iplane=0; iplane<AliTRDgeometry::kNlayer; iplane++){
41702fec 656 AliTRDseedV1 *tracklet = GetTracklet(&t, iplane, index);
657 if(!tracklet) continue;
658 t.SetTracklet(tracklet, index);
659 }
660
a2fbb6ec 661 if(fkReconstructor->IsDebugStreaming()){
662 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
663 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
664 AliTRDtrackV1 track(t);
665 track.SetOwner();
666 cstreamer << "FollowProlongation"
667 << "EventNumber=" << eventNumber
668 << "ncl=" << nClustersExpected
669 << "track.=" << &track
670 << "\n";
671 }
41702fec 672 }
41702fec 673 return nClustersExpected;
0906e73e 674
675}
676
677//_____________________________________________________________________________
678Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
679{
afa21247 680// Extrapolates/Build the TRD track in the TOF direction.
681//
682// Parameters
683// t : the TRD track which has to be extrapolated
684//
685// Output
686// number of clusters attached to the track
687//
688// Starting from current radial position of track <t> this function
689// extrapolates the track through the 6 TRD layers. The following steps
690// are being performed for each plane:
691// 1. Propagate track to the entrance of the next chamber:
692// - get chamber limits in the radial direction
693// - check crossing sectors
694// - check track inclination
695// - check track prolongation against boundary conditions (see exclusion boundaries on AliTRDgeometry::IsOnBoundary())
696// 2. Build tracklet (see AliTRDseed::AttachClusters() for details) for this layer if needed. If only
697// Kalman filter is needed and tracklets are already linked to the track this step is skipped.
698// 3. Fit tracklet using the information from the Kalman filter.
699// 4. Propagate and update track at reference radial position of the tracklet.
700// 5. Register tracklet with the tracker and track; update pulls monitoring.
701//
702// Observation
2a3191bb 703// 1. During the propagation a bit map is filled detailing the status of the track in each TRD chamber. The following errors are being registered for each tracklet:
704// - AliTRDtrackV1::kProlongation : track prolongation failed
705// - AliTRDtrackV1::kPropagation : track prolongation failed
706// - AliTRDtrackV1::kAdjustSector : failed during sector crossing
707// - AliTRDtrackV1::kSnp : too large bending
708// - AliTRDtrackV1::kTrackletInit : fail to initialize tracklet
709// - AliTRDtrackV1::kUpdate : fail to attach clusters or fit the tracklet
710// - AliTRDtrackV1::kUnknown : anything which is not covered before
afa21247 711// 2. By default the status of the track before first TRD update is saved.
712//
713// Debug level 2
714//
715// Author
716// Alexandru Bercuci <A.Bercuci@gsi.de>
717//
41702fec 718
eb2b4f91 719 Int_t n = 0;
720 Double_t driftLength = .5*AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick();
4d6aee34 721 AliTRDtrackingChamber *chamber = NULL;
41702fec 722
9e85cb05 723 Int_t debugLevel = fkReconstructor->IsDebugStreaming() ? fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) : 0;
d0177bb6 724 if ( AliTRDReconstructor::GetStreamLevel()>0) debugLevel= AliTRDReconstructor::GetStreamLevel();
7c3eecb8 725 TTreeSRedirector *cstreamer = fkReconstructor->IsDebugStreaming() ? fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker) : 0x0;
726
36574ea4 727 Bool_t kStoreIn(kTRUE), // toggel store track params. at TRD entry
68f9b6bd 728 kStandAlone(kFALSE), // toggle tracker awarness of stand alone seeding
729 kUseTRD(fkRecoParam->IsOverPtThreshold(t.Pt()));// use TRD measurment to update Kalman
730
731 Int_t startLayer(0);
4d6aee34 732 AliTRDseedV1 tracklet, *ptrTracklet = NULL;
68f9b6bd 733 // Special case for stand alone tracking
734 // - store all tracklets found by seeding
735 // - start propagation from first tracklet found
181d2c97 736 AliTRDseedV1 *tracklets[kNPlanes];
737 memset(tracklets, 0, sizeof(AliTRDseedV1 *) * kNPlanes);
68f9b6bd 738 for(Int_t ip(kNPlanes); ip--;){
739 if(!(tracklets[ip] = t.GetTracklet(ip))) continue;
181d2c97 740 t.UnsetTracklet(ip);
68f9b6bd 741 if(tracklets[ip]->IsOK()) startLayer=ip;
742 kStandAlone = kTRUE;
0b559d95 743 kUseTRD = kTRUE;
181d2c97 744 }
68f9b6bd 745 AliDebug(4, Form("SA[%c] Start[%d]\n"
746 " [0]idx[%d] traklet[%p]\n"
747 " [1]idx[%d] traklet[%p]\n"
748 " [2]idx[%d] traklet[%p]\n"
749 " [3]idx[%d] traklet[%p]\n"
750 " [4]idx[%d] traklet[%p]\n"
751 " [5]idx[%d] traklet[%p]"
752 , kStandAlone?'y':'n', startLayer
753 , t.GetTrackletIndex(0), (void*)tracklets[0]
754 , t.GetTrackletIndex(1), (void*)tracklets[1]
755 , t.GetTrackletIndex(2), (void*)tracklets[2]
756 , t.GetTrackletIndex(3), (void*)tracklets[3]
757 , t.GetTrackletIndex(4), (void*)tracklets[4]
758 , t.GetTrackletIndex(5), (void*)tracklets[5]));
e3cf3d02 759
053767a4 760 // Loop through the TRD layers
4d6aee34 761 TGeoHMatrix *matrix = NULL;
3e860707 762 Double_t x(0.), y(0.), z(0.);
68f9b6bd 763 for (Int_t ily=startLayer, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
1bd708e3 764 AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
765
eb2b4f91 766 // rough estimate of the entry point
767 if (!t.GetProlongation(fR[ily], y, z)){
88987d18 768 n=-1;
34b5e42d 769 t.SetErrStat(AliTRDtrackV1::kProlongation);
1bd708e3 770 AliDebug(4, Form("Failed Rough Prolongation to ly[%d] x[%7.2f] y[%7.2f] z[%7.2f]", ily, fR[ily], y, z));
eb2b4f91 771 break;
772 }
41702fec 773
eb2b4f91 774 // find sector / stack / detector
775 sm = t.GetSector();
776 // TODO cross check with y value !
777 stk = fGeom->GetStack(z, ily);
778 det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
4d6aee34 779 matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
eb2b4f91 780
781 // check if supermodule/chamber is installed
782 if( !fGeom->GetSMstatus(sm) ||
783 stk<0. ||
784 fGeom->IsHole(ily, stk, sm) ||
785 !matrix ){
1bd708e3 786 AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
eb2b4f91 787 // propagate to the default radial position
952051c5 788 if(fR[ily] > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, fR[ily], AliTRDReconstructor::GetMaxStep())){
88987d18 789 n=-1;
34b5e42d 790 t.SetErrStat(AliTRDtrackV1::kPropagation);
1bd708e3 791 AliDebug(4, "Failed Propagation [Missing Geometry]");
41702fec 792 break;
793 }
eb2b4f91 794 if(!AdjustSector(&t)){
88987d18 795 n=-1;
34b5e42d 796 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 797 AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
eb2b4f91 798 break;
799 }
952051c5 800 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
88987d18 801 n=-1;
34b5e42d 802 t.SetErrStat(AliTRDtrackV1::kSnp);
1bd708e3 803 AliDebug(4, "Failed Max Snp [Missing Geometry]");
eb2b4f91 804 break;
805 }
34b5e42d 806 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
41702fec 807 continue;
808 }
e3cf3d02 809
eb2b4f91 810 // retrieve rotation matrix for the current chamber
811 Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
812 Double_t glb[] = {0., 0., 0.};
813 matrix->LocalToMaster(loc, glb);
88987d18 814 AliDebug(3, Form("Propagate to det[%3d] x_anode[%7.2f] (%f %f)", det, glb[0]+driftLength, glb[1], glb[2]));
eb2b4f91 815
816 // Propagate to the radial distance of the current layer
952051c5 817 x = glb[0] - AliTRDReconstructor::GetMaxStep();
818 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())){
88987d18 819 n=-1;
34b5e42d 820 t.SetErrStat(AliTRDtrackV1::kPropagation);
88987d18 821 AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
eb2b4f91 822 break;
823 }
824 if(!AdjustSector(&t)){
88987d18 825 n=-1;
34b5e42d 826 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 827 AliDebug(4, "Failed Adjust Sector Start");
eb2b4f91 828 break;
829 }
952051c5 830 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
88987d18 831 n=-1;
34b5e42d 832 t.SetErrStat(AliTRDtrackV1::kSnp);
952051c5 833 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
eb2b4f91 834 break;
835 }
4d6aee34 836 Bool_t doRecalculate = kFALSE;
eb2b4f91 837 if(sm != t.GetSector()){
838 sm = t.GetSector();
4d6aee34 839 doRecalculate = kTRUE;
eb2b4f91 840 }
841 if(stk != fGeom->GetStack(z, ily)){
842 stk = fGeom->GetStack(z, ily);
4d6aee34 843 doRecalculate = kTRUE;
eb2b4f91 844 }
4d6aee34 845 if(doRecalculate){
eb2b4f91 846 det = AliTRDgeometry::GetDetector(ily, stk, sm);
847 if(!(matrix = fGeom->GetClusterMatrix(det))){
34b5e42d 848 t.SetErrStat(AliTRDtrackV1::kGeometry, ily);
1bd708e3 849 AliDebug(4, Form("Failed Geometry Matrix ly[%d]", ily));
eb2b4f91 850 continue;
851 }
852 matrix->LocalToMaster(loc, glb);
952051c5 853 x = glb[0] - AliTRDReconstructor::GetMaxStep();
eb2b4f91 854 }
855
856 // check if track is well inside fiducial volume
952051c5 857 if (!t.GetProlongation(x+AliTRDReconstructor::GetMaxStep(), y, z)) {
88987d18 858 n=-1;
34b5e42d 859 t.SetErrStat(AliTRDtrackV1::kProlongation);
952051c5 860 AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+AliTRDReconstructor::GetMaxStep(), y, z));
eb2b4f91 861 break;
862 }
863 if(fGeom->IsOnBoundary(det, y, z, .5)){
34b5e42d 864 t.SetErrStat(AliTRDtrackV1::kBoundary, ily);
1bd708e3 865 AliDebug(4, "Failed Track on Boundary");
eb2b4f91 866 continue;
867 }
b1957d3c 868
eb2b4f91 869 ptrTracklet = tracklets[ily];
870 if(!ptrTracklet){ // BUILD TRACKLET
1bd708e3 871 AliDebug(3, Form("Building tracklet det[%d]", det));
eb2b4f91 872 // check data in supermodule
873 if(!fTrSec[sm].GetNChambers()){
34b5e42d 874 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
88987d18 875 AliDebug(4, "Failed NoClusters");
eb2b4f91 876 continue;
877 }
878 if(fTrSec[sm].GetX(ily) < 1.){
34b5e42d 879 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
88987d18 880 AliDebug(4, "Failed NoX");
eb2b4f91 881 continue;
882 }
883
884 // check data in chamber
885 if(!(chamber = fTrSec[sm].GetChamber(stk, ily))){
34b5e42d 886 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
88987d18 887 AliDebug(4, "Failed No Detector");
eb2b4f91 888 continue;
889 }
9e85cb05 890 if(chamber->GetNClusters() < fgNTimeBins*fkRecoParam ->GetFindableClusters()){
34b5e42d 891 t.SetErrStat(AliTRDtrackV1::kNoClusters, ily);
88987d18 892 AliDebug(4, "Failed Not Enough Clusters in Detector");
eb2b4f91 893 continue;
894 }
895 // build tracklet
4d8f1bd9 896 tracklet.~AliTRDseedV1();
eb2b4f91 897 ptrTracklet = new(&tracklet) AliTRDseedV1(det);
4d6aee34 898 ptrTracklet->SetReconstructor(fkReconstructor);
eb2b4f91 899 ptrTracklet->SetKink(t.IsKink());
2eb10c34 900 ptrTracklet->SetPrimary(t.IsPrimary());
eb2b4f91 901 ptrTracklet->SetPadPlane(fGeom->GetPadPlane(ily, stk));
902 ptrTracklet->SetX0(glb[0]+driftLength);
4d8f1bd9 903 if(!ptrTracklet->Init(&t)){
88987d18 904 n=-1;
34b5e42d 905 t.SetErrStat(AliTRDtrackV1::kTrackletInit);
1bd708e3 906 AliDebug(4, "Failed Tracklet Init");
eb2b4f91 907 break;
908 }
803dc399 909 // Select attachment base on track to B field sign not only track charge which is buggy
910 // mark kFALSE same sign tracks and kTRUE opposite sign tracks
911 // A.Bercuci 3.11.2011
912 Float_t prod(t.GetBz()*t.Charge());
913 if(!ptrTracklet->AttachClusters(chamber, kTRUE, prod<0.?kTRUE:kFALSE, fEventInFile)){
34b5e42d 914 t.SetErrStat(AliTRDtrackV1::kNoAttach, ily);
7c3eecb8 915 if(debugLevel>3){
916 AliTRDseedV1 trackletCp(*ptrTracklet);
917 UChar_t status(t.GetStatusTRD(ily));
9dcc64cc 918 (*cstreamer) << "FollowBackProlongation4"
7c3eecb8 919 <<"status=" << status
920 <<"tracklet.=" << &trackletCp
921 << "\n";
922 }
1bd708e3 923 AliDebug(4, "Failed Attach Clusters");
eb2b4f91 924 continue;
925 }
88987d18 926 AliDebug(3, Form("Number of Clusters in Tracklet: %d", ptrTracklet->GetN()));
927 if(ptrTracklet->GetN() < fgNTimeBins*fkRecoParam->GetFindableClusters()){
34b5e42d 928 t.SetErrStat(AliTRDtrackV1::kNoClustersTracklet, ily);
7c3eecb8 929 if(debugLevel>3){
930 AliTRDseedV1 trackletCp(*ptrTracklet);
931 UChar_t status(t.GetStatusTRD(ily));
9dcc64cc 932 (*cstreamer) << "FollowBackProlongation4"
7c3eecb8 933 <<"status=" << status
934 <<"tracklet.=" << &trackletCp
935 << "\n";
936 }
88987d18 937 AliDebug(4, "Failed N Clusters Attached");
eb2b4f91 938 continue;
939 }
940 ptrTracklet->UpdateUsed();
0217fcd0 941 } else AliDebug(2, Form("Use external tracklet ly[%d]", ily));
eb2b4f91 942 // propagate track to the radial position of the tracklet
68f9b6bd 943
2eb10c34 944 // fit tracklet
945 // tilt correction options
946 // 0 : no correction
947 // 2 : pseudo tilt correction
9dcc64cc 948 if(!ptrTracklet->FitRobust(t.Charge()>0?kTRUE:kFALSE)){
34b5e42d 949 t.SetErrStat(AliTRDtrackV1::kNoFit, ily);
1bd708e3 950 AliDebug(4, "Failed Tracklet Fit");
eb2b4f91 951 continue;
952 }
953 x = ptrTracklet->GetX(); //GetX0();
952051c5 954 if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())) {
88987d18 955 n=-1;
34b5e42d 956 t.SetErrStat(AliTRDtrackV1::kPropagation);
1bd708e3 957 AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
eb2b4f91 958 break;
959 }
960 if(!AdjustSector(&t)) {
88987d18 961 n=-1;
34b5e42d 962 t.SetErrStat(AliTRDtrackV1::kAdjustSector);
1bd708e3 963 AliDebug(4, "Failed Adjust Sector");
eb2b4f91 964 break;
41702fec 965 }
952051c5 966 if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
88987d18 967 n=-1;
34b5e42d 968 t.SetErrStat(AliTRDtrackV1::kSnp);
952051c5 969 AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
eb2b4f91 970 break;
971 }
b72f4eaf 972 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
973 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
974 Double_t chi2 = ((AliExternalTrackParam)t).GetPredictedChi2(p, cov);
6e39bde4 975 // update Kalman with the TRD measurement
b72f4eaf 976 if(chi2>1e+10){ // TODO
34b5e42d 977 t.SetErrStat(AliTRDtrackV1::kChi2, ily);
7c3eecb8 978 if(debugLevel > 2){
979 UChar_t status(t.GetStatusTRD());
980 AliTRDseedV1 trackletCp(*ptrTracklet);
981 AliTRDtrackV1 trackCp(t);
982 trackCp.SetOwner();
9dcc64cc 983 (*cstreamer) << "FollowBackProlongation3"
7c3eecb8 984 << "status=" << status
985 << "tracklet.=" << &trackletCp
986 << "track.=" << &trackCp
987 << "\n";
988 }
1bd708e3 989 AliDebug(4, Form("Failed Chi2[%f]", chi2));
eb2b4f91 990 continue;
991 }
68d29486 992 if(fkReconstructor->IsDebugStreaming()){
993 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
994 // TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
995 AliExternalTrackParam param0(t);
996 AliExternalTrackParam param1(t);
997 param1.Update(p, cov);
998 TVectorD vcov(3,cov);
999 TVectorD vpar(3,p);
1000 (*cstreamer) << "FollowBackProlongationInfo"
1001 << "EventNumber=" << eventNumber
1002 << "chi2="<<chi2
1003 << "iplane="<<ily
1004 << "vcov.="<<&vcov
1005 << "vpar.="<<&vpar
1006 << "tracklet.=" << ptrTracklet
1007 << "param0.=" << &param0
1008 << "param1.=" << &param1
1009 << "\n";
1010 }
1011
88987d18 1012 // mark track as entering the FIDUCIAL volume of TRD
1013 if(kStoreIn){
1014 t.SetTrackIn();
1015 kStoreIn = kFALSE;
1016 }
ef867f55 1017 if(kUseTRD){
1018 if(!((AliExternalTrackParam&)t).Update(p, cov)) {
88987d18 1019 n=-1;
34b5e42d 1020 t.SetErrStat(AliTRDtrackV1::kUpdate);
ef867f55 1021 if(debugLevel > 2){
1022 UChar_t status(t.GetStatusTRD());
1023 AliTRDseedV1 trackletCp(*ptrTracklet);
1024 AliTRDtrackV1 trackCp(t);
1025 trackCp.SetOwner();
9dcc64cc 1026 (*cstreamer) << "FollowBackProlongation3"
ef867f55 1027 << "status=" << status
1028 << "tracklet.=" << &trackletCp
1029 << "track.=" << &trackCp
1030 << "\n";
1031 }
1032 AliDebug(4, Form("Failed Track Update @ y[%7.2f] z[%7.2f] s2y[%f] s2z[%f] covyz[%f]", p[0], p[1], cov[0], cov[2], cov[1]));
1033 break;
7c3eecb8 1034 }
eb2b4f91 1035 }
68f9b6bd 1036 if(!kStandAlone) ptrTracklet->UseClusters();
b72f4eaf 1037 // fill residuals ?!
1038 AliTracker::FillResiduals(&t, p, cov, ptrTracklet->GetVolumeId());
1039
eb2b4f91 1040
4d8f1bd9 1041 // register tracklet with the tracker and track
803dc399 1042 // Save inside the tracklet the track parameters BEFORE track update.
1043 // Commented out their overwriting AFTER track update
1044 // A.Bercuci 3.11.2011
1045 //ptrTracklet->Update(&t);
eb2b4f91 1046 ptrTracklet = SetTracklet(ptrTracklet);
17896e82 1047 Int_t index(fTracklets->GetEntriesFast()-1);
1048 t.SetTracklet(ptrTracklet, index);
ef867f55 1049 // Register info to track
1050 t.SetNumberOfClusters();
1051 t.UpdateChi2(chi2);
1052
eb2b4f91 1053 n += ptrTracklet->GetN();
17896e82 1054 AliDebug(2, Form("Setting Tracklet[%d] @ Idx[%d]", ily, index));
eb2b4f91 1055
41702fec 1056 // Reset material budget if 2 consecutive gold
eb2b4f91 1057// if(ilayer>0 && t.GetTracklet(ilayer-1) && ptrTracklet->GetN() + t.GetTracklet(ilayer-1)->GetN() > 20) t.SetBudget(2, 0.);
41702fec 1058
1059 // Make backup of the track until is gold
b453ef55 1060 Int_t failed(0);
68f9b6bd 1061 if(!kStandAlone && (failed = t.MakeBackupTrack())) AliDebug(2, Form("Failed backup on cut[%d]", failed));
9e85cb05 1062
053767a4 1063 } // end layers loop
eb2b4f91 1064 //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
1065 //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
41702fec 1066
9dcc64cc 1067 if(n && debugLevel > 1){
1068 //Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
eb2b4f91 1069 AliTRDtrackV1 track(t);
1070 track.SetOwner();
9dcc64cc 1071 (*cstreamer) << "FollowBackProlongation2"
1072 << "EventNumber=" << fEventInFile
eb2b4f91 1073 << "track.=" << &track
41702fec 1074 << "\n";
1075 }
1076
eb2b4f91 1077 return n;
0906e73e 1078}
1079
eb38ed55 1080//_________________________________________________________________________
4d6aee34 1081Float_t AliTRDtrackerV1::FitRieman(AliTRDseedV1 *tracklets, Double_t *chi2, Int_t *const planes){
41702fec 1082 //
1083 // Fits a Riemann-circle to the given points without tilting pad correction.
1084 // The fit is performed using an instance of the class AliRieman (equations
1085 // and transformations see documentation of this class)
1086 // Afterwards all the tracklets are Updated
1087 //
1088 // Parameters: - Array of tracklets (AliTRDseedV1)
1089 // - Storage for the chi2 values (beginning with direction z)
1090 // - Seeding configuration
1091 // Output: - The curvature
1092 //
1093 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1094 fitter->Reset();
1095 Int_t allplanes[] = {0, 1, 2, 3, 4, 5};
1096 Int_t *ppl = &allplanes[0];
1097 Int_t maxLayers = 6;
1098 if(planes){
1099 maxLayers = 4;
1100 ppl = planes;
1101 }
1102 for(Int_t il = 0; il < maxLayers; il++){
1103 if(!tracklets[ppl[il]].IsOK()) continue;
e3cf3d02 1104 fitter->AddPoint(tracklets[ppl[il]].GetX0(), tracklets[ppl[il]].GetYfit(0), tracklets[ppl[il]].GetZfit(0),1,10);
41702fec 1105 }
1106 fitter->Update();
1107 // Set the reference position of the fit and calculate the chi2 values
1108 memset(chi2, 0, sizeof(Double_t) * 2);
1109 for(Int_t il = 0; il < maxLayers; il++){
1110 // Reference positions
1111 tracklets[ppl[il]].Init(fitter);
1112
1113 // chi2
1114 if((!tracklets[ppl[il]].IsOK()) && (!planes)) continue;
1115 chi2[0] += tracklets[ppl[il]].GetChi2Y();
1116 chi2[1] += tracklets[ppl[il]].GetChi2Z();
1117 }
1118 return fitter->GetC();
eb38ed55 1119}
1120
1121//_________________________________________________________________________
1122void AliTRDtrackerV1::FitRieman(AliTRDcluster **seedcl, Double_t chi2[2])
1123{
41702fec 1124 //
1125 // Performs a Riemann helix fit using the seedclusters as spacepoints
1126 // Afterwards the chi2 values are calculated and the seeds are updated
1127 //
1128 // Parameters: - The four seedclusters
1129 // - The tracklet array (AliTRDseedV1)
1130 // - The seeding configuration
1131 // - Chi2 array
1132 //
1133 // debug level 2
1134 //
1135 AliRieman *fitter = AliTRDtrackerV1::GetRiemanFitter();
1136 fitter->Reset();
a3743898 1137 for(Int_t i = 0; i < 4; i++){
a3743898 1138 fitter->AddPoint(seedcl[i]->GetX(), seedcl[i]->GetY(), seedcl[i]->GetZ(), 1., 10.);
1139 }
41702fec 1140 fitter->Update();
1141
1142
1143 // Update the seed and calculated the chi2 value
1144 chi2[0] = 0; chi2[1] = 0;
1145 for(Int_t ipl = 0; ipl < kNSeedPlanes; ipl++){
1146 // chi2
1147 chi2[0] += (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetZ() - fitter->GetZat(seedcl[ipl]->GetX()));
1148 chi2[1] += (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX())) * (seedcl[ipl]->GetY() - fitter->GetYat(seedcl[ipl]->GetX()));
1149 }
eb38ed55 1150}
1151
1152
1153//_________________________________________________________________________
1154Float_t AliTRDtrackerV1::FitTiltedRiemanConstraint(AliTRDseedV1 *tracklets, Double_t zVertex)
1155{
41702fec 1156 //
1157 // Fits a helix to the clusters. Pad tilting is considered. As constraint it is
1158 // assumed that the vertex position is set to 0.
1159 // This method is very usefull for high-pt particles
1160 // Basis for the fit: (x - x0)^2 + (y - y0)^2 - R^2 = 0
1161 // x0, y0: Center of the circle
1162 // Measured y-position: ymeas = y - tan(phiT)(zc - zt)
1163 // zc: center of the pad row
1164 // Equation which has to be fitted (after transformation):
1165 // a + b * u + e * v + 2*(ymeas + tan(phiT)(z - zVertex))*t = 0
1166 // Transformation:
1167 // t = 1/(x^2 + y^2)
1168 // u = 2 * x * t
1169 // v = 2 * x * tan(phiT) * t
1170 // Parameters in the equation:
1171 // a = -1/y0, b = x0/y0, e = dz/dx
1172 //
1173 // The Curvature is calculated by the following equation:
1174 // - curv = a/Sqrt(b^2 + 1) = 1/R
1175 // Parameters: - the 6 tracklets
1176 // - the Vertex constraint
1177 // Output: - the Chi2 value of the track
1178 //
1179 // debug level 5
1180 //
1181
1182 TLinearFitter *fitter = GetTiltedRiemanFitterConstraint();
1183 fitter->StoreData(kTRUE);
1184 fitter->ClearPoints();
4d6aee34 1185 AliTRDcluster *cl = NULL;
41702fec 1186
1187 Float_t x, y, z, w, t, error, tilt;
1188 Double_t uvt[2];
1189 Int_t nPoints = 0;
053767a4 1190 for(Int_t ilr = 0; ilr < AliTRDgeometry::kNlayer; ilr++){
1191 if(!tracklets[ilr].IsOK()) continue;
8d2bec9e 1192 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
053767a4 1193 if(!tracklets[ilr].IsUsable(itb)) continue;
e7542a7e 1194 if(!(cl = tracklets[ilr].GetClusters(itb))) continue;
1742f24c 1195 if(!cl->IsInChamber()) continue;
41702fec 1196 x = cl->GetX();
1197 y = cl->GetY();
1198 z = cl->GetZ();
053767a4 1199 tilt = tracklets[ilr].GetTilt();
41702fec 1200 // Transformation
1201 t = 1./(x * x + y * y);
1202 uvt[0] = 2. * x * t;
1203 uvt[1] = 2. * x * t * tilt ;
1204 w = 2. * (y + tilt * (z - zVertex)) * t;
78b7d24c 1205 error = 2. * TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) * t;
41702fec 1206 fitter->AddPoint(uvt, w, error);
1207 nPoints++;
1208 }
1209 }
e17f4785 1210 fitter->Eval();
41702fec 1211
1212 // Calculate curvature
1213 Double_t a = fitter->GetParameter(0);
1214 Double_t b = fitter->GetParameter(1);
1215 Double_t curvature = a/TMath::Sqrt(b*b + 1);
1216
ce42378b 1217 Float_t chi2track = 0.0;
1218 if (nPoints > 0) {
1219 chi2track = fitter->GetChisquare()/Double_t(nPoints);
1220 }
41702fec 1221 for(Int_t ip = 0; ip < AliTRDtrackerV1::kNPlanes; ip++)
68f9b6bd 1222 tracklets[ip].SetC(curvature, 1);
1223
1224 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRiemanConstraint: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
41702fec 1225
a2fbb6ec 1226/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker()) >= 5){
41702fec 1227 //Linear Model on z-direction
1228 Double_t xref = CalculateReferenceX(tracklets); // Relative to the middle of the stack
1229 Double_t slope = fitter->GetParameter(2);
1230 Double_t zref = slope * xref;
1231 Float_t chi2Z = CalculateChi2Z(tracklets, zref, slope, xref);
1232 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1233 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
4d6aee34 1234 TTreeSRedirector &treeStreamer = *fkReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
41702fec 1235 treeStreamer << "FitTiltedRiemanConstraint"
1236 << "EventNumber=" << eventNumber
1237 << "CandidateNumber=" << candidateNumber
1238 << "Curvature=" << curvature
1239 << "Chi2Track=" << chi2track
1240 << "Chi2Z=" << chi2Z
1241 << "zref=" << zref
1242 << "\n";
3a039a31 1243 }*/
41702fec 1244 return chi2track;
eb38ed55 1245}
1246
1247//_________________________________________________________________________
1248Float_t AliTRDtrackerV1::FitTiltedRieman(AliTRDseedV1 *tracklets, Bool_t sigError)
1249{
41702fec 1250 //
1251 // Performs a Riemann fit taking tilting pad correction into account
1252 // The equation of a Riemann circle, where the y position is substituted by the
1253 // measured y-position taking pad tilting into account, has to be transformed
1254 // into a 4-dimensional hyperplane equation
1255 // Riemann circle: (x-x0)^2 + (y-y0)^2 -R^2 = 0
1256 // Measured y-Position: ymeas = y - tan(phiT)(zc - zt)
1257 // zc: center of the pad row
1258 // zt: z-position of the track
1259 // The z-position of the track is assumed to be linear dependent on the x-position
1260 // Transformed equation: a + b * u + c * t + d * v + e * w - 2 * (ymeas + tan(phiT) * zc) * t = 0
1261 // Transformation: u = 2 * x * t
1262 // v = 2 * tan(phiT) * t
1263 // w = 2 * tan(phiT) * (x - xref) * t
1264 // t = 1 / (x^2 + ymeas^2)
1265 // Parameters: a = -1/y0
1266 // b = x0/y0
1267 // c = (R^2 -x0^2 - y0^2)/y0
1268 // d = offset
1269 // e = dz/dx
1270 // If the offset respectively the slope in z-position is impossible, the parameters are fixed using
1271 // results from the simple riemann fit. Afterwards the fit is redone.
1272 // The curvature is calculated according to the formula:
1273 // curv = a/(1 + b^2 + c*a) = 1/R
1274 //
1275 // Paramters: - Array of tracklets (connected to the track candidate)
1276 // - Flag selecting the error definition
1277 // Output: - Chi2 values of the track (in Parameter list)
1278 //
1279 TLinearFitter *fitter = GetTiltedRiemanFitter();
1280 fitter->StoreData(kTRUE);
1281 fitter->ClearPoints();
1282 AliTRDLeastSquare zfitter;
4d6aee34 1283 AliTRDcluster *cl = NULL;
41702fec 1284
1285 Double_t xref = CalculateReferenceX(tracklets);
6e39bde4 1286 Double_t x, y, z, t, tilt, dx, w, we, erry, errz;
1287 Double_t uvt[4], sumPolY[5], sumPolZ[3];
1288 memset(sumPolY, 0, sizeof(Double_t) * 5);
1289 memset(sumPolZ, 0, sizeof(Double_t) * 3);
41702fec 1290 Int_t nPoints = 0;
1291 // Containers for Least-square fitter
1292 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1293 if(!tracklets[ipl].IsOK()) continue;
ed15ef4f 1294 tilt = tracklets[ipl].GetTilt();
8d2bec9e 1295 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1296 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1742f24c 1297 if(!cl->IsInChamber()) continue;
c79857d5 1298 if (!tracklets[ipl].IsUsable(itb)) continue;
41702fec 1299 x = cl->GetX();
1300 y = cl->GetY();
1301 z = cl->GetZ();
41702fec 1302 dx = x - xref;
1303 // Transformation
1304 t = 1./(x*x + y*y);
1305 uvt[0] = 2. * x * t;
1306 uvt[1] = t;
1307 uvt[2] = 2. * tilt * t;
1308 uvt[3] = 2. * tilt * dx * t;
1309 w = 2. * (y + tilt*z) * t;
1310 // error definition changes for the different calls
1311 we = 2. * t;
78b7d24c 1312 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2()) : 0.2;
41702fec 1313 fitter->AddPoint(uvt, w, we);
1314 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
6e39bde4 1315 // adding points for covariance matrix estimation
1316 erry = 1./(TMath::Sqrt(cl->GetSigmaY2()) + 0.1); // 0.1 is a systematic error (due to misalignment and miscalibration)
1317 erry *= erry;
1318 errz = 1./cl->GetSigmaZ2();
1319 for(Int_t ipol = 0; ipol < 5; ipol++){
1320 sumPolY[ipol] += erry;
1321 erry *= x;
1322 if(ipol < 3){
1323 sumPolZ[ipol] += errz;
1324 errz *= x;
1325 }
1326 }
41702fec 1327 nPoints++;
1328 }
1329 }
c08b1cc7 1330 if (fitter->Eval()) return 1.e10;
41702fec 1331 zfitter.Eval();
1332
1333 Double_t offset = fitter->GetParameter(3);
1334 Double_t slope = fitter->GetParameter(4);
1335
1336 // Linear fitter - not possible to make boundaries
1337 // Do not accept non possible z and dzdx combinations
1338 Bool_t acceptablez = kTRUE;
1339 Double_t zref = 0.0;
1340 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1341 if(!tracklets[iLayer].IsOK()) continue;
1342 zref = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1343 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
41702fec 1344 acceptablez = kFALSE;
1345 }
1346 if (!acceptablez) {
1347 Double_t dzmf = zfitter.GetFunctionParameter(1);
1348 Double_t zmf = zfitter.GetFunctionValue(&xref);
1349 fgTiltedRieman->FixParameter(3, zmf);
1350 fgTiltedRieman->FixParameter(4, dzmf);
e17f4785 1351 fitter->Eval();
41702fec 1352 fitter->ReleaseParameter(3);
1353 fitter->ReleaseParameter(4);
1354 offset = fitter->GetParameter(3);
1355 slope = fitter->GetParameter(4);
1356 }
1357
1358 // Calculate Curvarture
1359 Double_t a = fitter->GetParameter(0);
1360 Double_t b = fitter->GetParameter(1);
1361 Double_t c = fitter->GetParameter(2);
1362 Double_t curvature = 1.0 + b*b - c*a;
68f9b6bd 1363 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
41702fec 1364
1365 Double_t chi2track = fitter->GetChisquare()/Double_t(nPoints);
1366
6e39bde4 1367 // Prepare error calculation
1368 TMatrixD covarPolY(3,3);
1369 covarPolY(0,0) = sumPolY[0]; covarPolY(1,1) = sumPolY[2]; covarPolY(2,2) = sumPolY[4];
1370 covarPolY(0,1) = covarPolY(1,0) = sumPolY[1];
1371 covarPolY(0,2) = covarPolY(2,0) = sumPolY[2];
1372 covarPolY(2,1) = covarPolY(1,2) = sumPolY[3];
1373 covarPolY.Invert();
1374 TMatrixD covarPolZ(2,2);
1375 covarPolZ(0,0) = sumPolZ[0]; covarPolZ(1,1) = sumPolZ[2];
1376 covarPolZ(1,0) = covarPolZ(0,1) = sumPolZ[1];
1377 covarPolZ.Invert();
1378
41702fec 1379 // Update the tracklets
d2eba04b 1380 Double_t dy, dz;
6e39bde4 1381 Double_t cov[15];
1382 memset(cov, 0, sizeof(Double_t) * 15);
41702fec 1383 for(Int_t iLayer = 0; iLayer < AliTRDtrackerV1::kNPlanes; iLayer++) {
1384
1385 x = tracklets[iLayer].GetX0();
d2eba04b 1386// x1 = x - xref;
41702fec 1387 y = 0;
1388 z = 0;
1389 dy = 0;
1390 dz = 0;
6e39bde4 1391 memset(cov, 0, sizeof(Double_t) * 3);
1392 TMatrixD transform(3,3);
1393 transform(0,0) = 1;
1394 transform(0,1) = x;
1395 transform(0,2) = x*x;
1396 transform(1,1) = 1;
1397 transform(1,2) = x;
1398 transform(2,2) = 1;
1399 TMatrixD covariance(transform, TMatrixD::kMult, covarPolY);
1400 covariance *= transform.T();
1401 TMatrixD transformZ(2,2);
1402 transformZ(0,0) = transformZ(1,1) = 1;
1403 transformZ(0,1) = x;
1404 TMatrixD covarZ(transformZ, TMatrixD::kMult, covarPolZ);
1405 covarZ *= transformZ.T();
41702fec 1406 // y: R^2 = (x - x0)^2 + (y - y0)^2
1407 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1408 // R = Sqrt() = 1/Curvature
1409 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
1410 Double_t res = (x * a + b); // = (x - x0)/y0
1411 res *= res;
1412 res = 1.0 - c * a + b * b - res; // = (R^2 - (x - x0)^2)/y0^2
1413 if (res >= 0) {
1414 res = TMath::Sqrt(res);
1415 y = (1.0 - res) / a;
1416 }
6e39bde4 1417 cov[0] = covariance(0,0);
1418 cov[2] = covarZ(0,0);
1419 cov[1] = 0.;
41702fec 1420
1421 // dy: R^2 = (x - x0)^2 + (y - y0)^2
1422 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
1423 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1424 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
1425 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
1426 Double_t x0 = -b / a;
1427 if (-c * a + b * b + 1 > 0) {
1428 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
6e39bde4 1429 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
1430 if (a < 0) yderiv *= -1.0;
1431 dy = yderiv;
41702fec 1432 }
1433 }
1434 z = offset + slope * (x - xref);
1435 dz = slope;
1436 tracklets[iLayer].SetYref(0, y);
1437 tracklets[iLayer].SetYref(1, dy);
1438 tracklets[iLayer].SetZref(0, z);
1439 tracklets[iLayer].SetZref(1, dz);
1440 tracklets[iLayer].SetC(curvature);
6e39bde4 1441 tracklets[iLayer].SetCovRef(cov);
41702fec 1442 tracklets[iLayer].SetChi2(chi2track);
1443 }
68f9b6bd 1444 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitTiltedRieman: Chi2[%f] C[%5.2e] pt[%8.3f]\n", chi2track, curvature, GetBz()*kB2C/curvature);
41702fec 1445
a2fbb6ec 1446/* if(fkReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kTracker) >=5){
1447 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 1448 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
1449 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
1450 Double_t chi2z = CalculateChi2Z(tracklets, offset, slope, xref);
1451 cstreamer << "FitTiltedRieman0"
1452 << "EventNumber=" << eventNumber
1453 << "CandidateNumber=" << candidateNumber
1454 << "xref=" << xref
1455 << "Chi2Z=" << chi2z
1456 << "\n";
3a039a31 1457 }*/
41702fec 1458 return chi2track;
eb38ed55 1459}
1460
3b57a3f7 1461
9e333711 1462//____________________________________________________________________
6e4d4425 1463Double_t AliTRDtrackerV1::FitLine(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t err, Int_t np, AliTrackPoint *points)
9e333711 1464{
4d6aee34 1465 //
1466 // Fit track with a staight line
1467 // Fills an AliTrackPoint array with np points
1468 // Function should be used to refit tracks when no magnetic field was on
1469 //
9e333711 1470 AliTRDLeastSquare yfitter, zfitter;
4d6aee34 1471 AliTRDcluster *cl = NULL;
9e333711 1472
4d6aee34 1473 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
9e333711 1474 if(!tracklets){
1475 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1476 if(!(tracklet = track->GetTracklet(ipl))) continue;
1477 if(!tracklet->IsOK()) continue;
1478 new(&work[ipl]) AliTRDseedV1(*tracklet);
1479 }
1480 tracklets = &work[0];
1481 }
1482
1483 Double_t xref = CalculateReferenceX(tracklets);
1484 Double_t x, y, z, dx, ye, yr, tilt;
1485 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1486 if(!tracklets[ipl].IsOK()) continue;
1487 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1488 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1489 if (!tracklets[ipl].IsUsable(itb)) continue;
1490 x = cl->GetX();
1491 z = cl->GetZ();
1492 dx = x - xref;
1493 zfitter.AddPoint(&dx, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1494 }
1495 }
1496 zfitter.Eval();
1497 Double_t z0 = zfitter.GetFunctionParameter(0);
1498 Double_t dzdx = zfitter.GetFunctionParameter(1);
1499 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1500 if(!tracklets[ipl].IsOK()) continue;
1501 for(Int_t itb = 0; itb < fgNTimeBins; itb++){
1502 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
1503 if (!tracklets[ipl].IsUsable(itb)) continue;
1504 x = cl->GetX();
1505 y = cl->GetY();
1506 z = cl->GetZ();
1507 tilt = tracklets[ipl].GetTilt();
1508 dx = x - xref;
1509 yr = y + tilt*(z - z0 - dzdx*dx);
1510 // error definition changes for the different calls
1511 ye = tilt*TMath::Sqrt(cl->GetSigmaZ2());
1512 ye += err ? tracklets[ipl].GetSigmaY() : 0.2;
1513 yfitter.AddPoint(&dx, yr, ye);
1514 }
1515 }
1516 yfitter.Eval();
1517 Double_t y0 = yfitter.GetFunctionParameter(0);
1518 Double_t dydx = yfitter.GetFunctionParameter(1);
1519 Double_t chi2 = 0.;//yfitter.GetChisquare()/Double_t(nPoints);
1520
1521 //update track points array
1522 if(np && points){
1523 Float_t xyz[3];
1524 for(int ip=0; ip<np; ip++){
1525 points[ip].GetXYZ(xyz);
1526 xyz[1] = y0 + dydx * (xyz[0] - xref);
1527 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1528 points[ip].SetXYZ(xyz);
1529 }
1530 }
1531 return chi2;
1532}
1533
1534
3b57a3f7 1535//_________________________________________________________________________
6e4d4425 1536Double_t AliTRDtrackerV1::FitRiemanTilt(const AliTRDtrackV1 *track, AliTRDseedV1 *tracklets, Bool_t sigError, Int_t np, AliTrackPoint *points)
3b57a3f7 1537{
0fa1a8ee 1538//
1539// Performs a Riemann fit taking tilting pad correction into account
1540//
1541// Paramters: - Array of tracklets (connected to the track candidate)
1542// - Flag selecting the error definition
1543// Output: - Chi2 values of the track (in Parameter list)
1544//
1545// The equations which has to be solved simultaneously are:
1546// BEGIN_LATEX
1547// R^{2} = (x-x_{0})^{2} + (y^{*}-y_{0})^{2}
1548// y^{*} = y - tg(h)(z - z_{t})
1549// z_{t} = z_{0}+dzdx*(x-x_{r})
1550// END_LATEX
1551// with (x, y, z) the coordinate of the cluster, (x_0, y_0, z_0) the coordinate of the center of the Riemann circle,
1552// R its radius, x_r a constant refrence radial position in the middle of the TRD stack and dzdx the slope of the
1553// track in the x-z plane. Using the following transformations
1554// BEGIN_LATEX
1555// t = 1 / (x^{2} + y^{2})
1556// u = 2 * x * t
1557// v = 2 * tan(h) * t
1558// w = 2 * tan(h) * (x - x_{r}) * t
1559// END_LATEX
1560// One gets the following linear equation
1561// BEGIN_LATEX
1562// a + b * u + c * t + d * v + e * w = 2 * (y + tg(h) * z) * t
1563// END_LATEX
1564// where the coefficients have the following meaning
1565// BEGIN_LATEX
1566// a = -1/y_{0}
1567// b = x_{0}/y_{0}
1568// c = (R^{2} -x_{0}^{2} - y_{0}^{2})/y_{0}
1569// d = z_{0}
1570// e = dz/dx
1571// END_LATEX
1572// The error calculation for the free term is thus
1573// BEGIN_LATEX
1574// #sigma = 2 * #sqrt{#sigma^{2}_{y} + (tilt corr ...) + tg^{2}(h) * #sigma^{2}_{z}} * t
1575// END_LATEX
1576//
1577// From this simple model one can compute chi^2 estimates and a rough approximation of pt from the curvature according
1578// to the formula:
1579// BEGIN_LATEX
1580// C = 1/R = a/(1 + b^{2} + c*a)
1581// END_LATEX
1582//
1583// Authors
1584// M.Ivanov <M.Ivanov@gsi.de>
1585// A.Bercuci <A.Bercuci@gsi.de>
1586// M.Fasel <M.Fasel@gsi.de>
1587
41702fec 1588 TLinearFitter *fitter = GetTiltedRiemanFitter();
1589 fitter->StoreData(kTRUE);
1590 fitter->ClearPoints();
1591 AliTRDLeastSquare zfitter;
4d6aee34 1592 AliTRDcluster *cl = NULL;
3b57a3f7 1593
4d6aee34 1594 AliTRDseedV1 work[kNPlanes], *tracklet = NULL;
3b57a3f7 1595 if(!tracklets){
1596 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1597 if(!(tracklet = track->GetTracklet(ipl))) continue;
1598 if(!tracklet->IsOK()) continue;
1599 new(&work[ipl]) AliTRDseedV1(*tracklet);
1600 }
1601 tracklets = &work[0];
1602 }
1603
41702fec 1604 Double_t xref = CalculateReferenceX(tracklets);
68f9b6bd 1605 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:\nx0[(0)%6.2f (1)%6.2f (2)%6.2f (3)%6.2f (4)%6.2f (5)%6.2f] xref[%6.2f]", tracklets[0].GetX0(), tracklets[1].GetX0(), tracklets[2].GetX0(), tracklets[3].GetX0(), tracklets[4].GetX0(), tracklets[5].GetX0(), xref);
41702fec 1606 Double_t x, y, z, t, tilt, dx, w, we;
1607 Double_t uvt[4];
1608 Int_t nPoints = 0;
1609 // Containers for Least-square fitter
1610 for(Int_t ipl = 0; ipl < kNPlanes; ipl++){
1611 if(!tracklets[ipl].IsOK()) continue;
8d2bec9e 1612 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
41702fec 1613 if(!(cl = tracklets[ipl].GetClusters(itb))) continue;
352cef8f 1614 //if (!tracklets[ipl].IsUsable(itb)) continue;
41702fec 1615 x = cl->GetX();
1616 y = cl->GetY();
1617 z = cl->GetZ();
1618 tilt = tracklets[ipl].GetTilt();
1619 dx = x - xref;
1620 // Transformation
1621 t = 1./(x*x + y*y);
1622 uvt[0] = 2. * x * t;
1623 uvt[1] = t;
1624 uvt[2] = 2. * tilt * t;
1625 uvt[3] = 2. * tilt * dx * t;
1626 w = 2. * (y + tilt*z) * t;
1627 // error definition changes for the different calls
1628 we = 2. * t;
f29f13a6 1629 we *= sigError ? TMath::Sqrt(cl->GetSigmaY2()) : 0.2;
41702fec 1630 fitter->AddPoint(uvt, w, we);
1631 zfitter.AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
1632 nPoints++;
1633 }
1634 }
aec26713 1635 if(fitter->Eval()) return 1.E10;
1636
41702fec 1637 Double_t z0 = fitter->GetParameter(3);
1638 Double_t dzdx = fitter->GetParameter(4);
3b57a3f7 1639
1640
1641 // Linear fitter - not possible to make boundaries
1642 // Do not accept non possible z and dzdx combinations
1643 Bool_t accept = kTRUE;
1644 Double_t zref = 0.0;
1645 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
1646 if(!tracklets[iLayer].IsOK()) continue;
1647 zref = z0 + dzdx * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1648 if (TMath::Abs(tracklets[iLayer].GetZfit(0) - zref) > tracklets[iLayer].GetPadLength() * 0.5 + 1.0)
3b57a3f7 1649 accept = kFALSE;
1650 }
1651 if (!accept) {
41702fec 1652 zfitter.Eval();
3b57a3f7 1653 Double_t dzmf = zfitter.GetFunctionParameter(1);
1654 Double_t zmf = zfitter.GetFunctionValue(&xref);
1655 fitter->FixParameter(3, zmf);
1656 fitter->FixParameter(4, dzmf);
e17f4785 1657 fitter->Eval();
3b57a3f7 1658 fitter->ReleaseParameter(3);
1659 fitter->ReleaseParameter(4);
1660 z0 = fitter->GetParameter(3); // = zmf ?
1661 dzdx = fitter->GetParameter(4); // = dzmf ?
1662 }
1663
1664 // Calculate Curvature
1665 Double_t a = fitter->GetParameter(0);
1666 Double_t b = fitter->GetParameter(1);
1667 Double_t c = fitter->GetParameter(2);
1668 Double_t y0 = 1. / a;
1669 Double_t x0 = -b * y0;
a015e406 1670 Double_t tmp = y0*y0 + x0*x0 - c*y0;
1671 if(tmp<=0.) return 1.E10;
4d6aee34 1672 Double_t radius = TMath::Sqrt(tmp);
1673 Double_t curvature = 1.0 + b*b - c*a;
1674 if (curvature > 0.0) curvature = a / TMath::Sqrt(curvature);
3b57a3f7 1675
1676 // Calculate chi2 of the fit
1677 Double_t chi2 = fitter->GetChisquare()/Double_t(nPoints);
68f9b6bd 1678 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>3) printf("D-AliTRDtrackerV1::FitRiemanTilt:x0[%6.2f] y0[%6.2f] R[%6.2f] chi2[%f]\n", x0, y0, radius, chi2);
3b57a3f7 1679
1680 // Update the tracklets
1681 if(!track){
1682 for(Int_t ip = 0; ip < kNPlanes; ip++) {
1683 x = tracklets[ip].GetX0();
4d6aee34 1684 tmp = radius*radius-(x-x0)*(x-x0);
a015e406 1685 if(tmp <= 0.) continue;
1686 tmp = TMath::Sqrt(tmp);
3b57a3f7 1687
1688 // y: R^2 = (x - x0)^2 + (y - y0)^2
1689 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
1690 tracklets[ip].SetYref(0, y0 - (y0>0.?1.:-1)*tmp);
1691 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
1692 tracklets[ip].SetYref(1, (x - x0) / tmp);
1693 tracklets[ip].SetZref(0, z0 + dzdx * (x - xref));
1694 tracklets[ip].SetZref(1, dzdx);
4d6aee34 1695 tracklets[ip].SetC(curvature);
3b57a3f7 1696 tracklets[ip].SetChi2(chi2);
1697 }
1698 }
3b57a3f7 1699 //update track points array
1700 if(np && points){
1701 Float_t xyz[3];
1702 for(int ip=0; ip<np; ip++){
1703 points[ip].GetXYZ(xyz);
4d6aee34 1704 xyz[1] = TMath::Abs(xyz[0] - x0) > radius ? 100. : y0 - (y0>0.?1.:-1.)*TMath::Sqrt((radius-(xyz[0]-x0))*(radius+(xyz[0]-x0)));
3b57a3f7 1705 xyz[2] = z0 + dzdx * (xyz[0] - xref);
1706 points[ip].SetXYZ(xyz);
1707 }
1708 }
1709
3b57a3f7 1710 return chi2;
1711}
1712
1713
1bf51039 1714//____________________________________________________________________
e17f4785 1715Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const tracklets, Bool_t up, Int_t np, AliTrackPoint *points)
1bf51039 1716{
1717// Kalman filter implementation for the TRD.
1718// It returns the positions of the fit in the array "points"
1719//
1720// Author : A.Bercuci@gsi.de
1721
3cfaffa4 1722 // printf("Start track @ x[%f]\n", track->GetX());
1bf51039 1723
1724 //prepare marker points along the track
1725 Int_t ip = np ? 0 : 1;
1726 while(ip<np){
1727 if((up?-1:1) * (track->GetX() - points[ip].GetX()) > 0.) break;
1728 //printf("AliTRDtrackerV1::FitKalman() : Skip track marker x[%d] = %7.3f. Before track start ( %7.3f ).\n", ip, points[ip].GetX(), track->GetX());
1729 ip++;
1730 }
1731 //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
1732
1733
d8069611 1734 AliTRDseedV1 tracklet;
1735 AliTRDseedV1 *ptrTracklet = NULL;
1bf51039 1736
1737 //Loop through the TRD planes
1738 for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
1739 // GET TRACKLET OR BUILT IT
1740 Int_t iplane = up ? jplane : kNPlanes - 1 - jplane;
1741 if(tracklets){
e17f4785 1742 if(!(ptrTracklet = &tracklets[iplane])) continue;
1bf51039 1743 }else{
1744 if(!(ptrTracklet = track->GetTracklet(iplane))){
4d6aee34 1745 /*AliTRDtrackerV1 *tracker = NULL;
a2fbb6ec 1746 if(!(tracker = dynamic_cast<AliTRDtrackerV1*>( AliTRDrecoParam:Tracker()))) continue;
1bf51039 1747 ptrTracklet = new(&tracklet) AliTRDseedV1(iplane);
1748 if(!tracker->MakeTracklet(ptrTracklet, track)) */
1749 continue;
1750 }
1751 }
1752 if(!ptrTracklet->IsOK()) continue;
1753
1754 Double_t x = ptrTracklet->GetX0();
1755
1756 while(ip < np){
1757 //don't do anything if next marker is after next update point.
952051c5 1758 if((up?-1:1) * (points[ip].GetX() - x) - AliTRDReconstructor::GetMaxStep() < 0) break;
1759 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1760
1761 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1762 track->GetXYZ(xyz);
1763 track->Global2LocalPosition(xyz, track->GetAlpha());
1764 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1765 ip++;
1766 }
3cfaffa4 1767 // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
1bf51039 1768
3cfaffa4 1769 // Propagate closer to the next update point
952051c5 1770 if(((up?-1:1) * (x - track->GetX()) + AliTRDReconstructor::GetMaxStep() < 0) && !PropagateToX(*track, x + (up?-1:1)*AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1771
1772 if(!AdjustSector(track)) return -1;
952051c5 1773 if(TMath::Abs(track->GetSnp()) > AliTRDReconstructor::GetMaxSnp()) return -1;
1bf51039 1774
1775 //load tracklet to the tracker and the track
1776/* Int_t index;
1777 if((index = FindTracklet(ptrTracklet)) < 0){
1778 ptrTracklet = SetTracklet(&tracklet);
1779 index = fTracklets->GetEntriesFast()-1;
1780 }
1781 track->SetTracklet(ptrTracklet, index);*/
1782
1783
1784 // register tracklet to track with tracklet creation !!
1785 // PropagateBack : loaded tracklet to the tracker and update index
1786 // RefitInward : update index
1787 // MakeTrack : loaded tracklet to the tracker and update index
1788 if(!tracklets) track->SetTracklet(ptrTracklet, -1);
1789
1790
1791 //Calculate the mean material budget along the path inside the chamber
1792 Double_t xyz0[3]; track->GetXYZ(xyz0);
1793 Double_t alpha = track->GetAlpha();
1794 Double_t xyz1[3], y, z;
1795 if(!track->GetProlongation(x, y, z)) return -1;
1796 xyz1[0] = x * TMath::Cos(alpha) - y * TMath::Sin(alpha);
1797 xyz1[1] = +x * TMath::Sin(alpha) + y * TMath::Cos(alpha);
1798 xyz1[2] = z;
fbe11be7 1799 if(TMath::Abs(xyz0[0] - xyz1[0]) < 1e-3 && TMath::Abs(xyz0[1] - xyz1[1]) < 1e-3) continue; // check wheter we are at the same global x position
1bf51039 1800 Double_t param[7];
3cfaffa4 1801 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param) <=0.) break;
1bf51039 1802 Double_t xrho = param[0]*param[4]; // density*length
1803 Double_t xx0 = param[1]; // radiation length
1804
1805 //Propagate the track
1806 track->PropagateTo(x, xx0, xrho);
1807 if (!AdjustSector(track)) break;
1808
1809 //Update track
b72f4eaf 1810 Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
1811 Double_t p[2] = { ptrTracklet->GetY(), ptrTracklet->GetZ()};
1812 Double_t chi2 = ((AliExternalTrackParam*)track)->GetPredictedChi2(p, cov);
ef867f55 1813 if(chi2<1e+10) ((AliExternalTrackParam*)track)->Update(p, cov);
1bf51039 1814 if(!up) continue;
1815
1816 //Reset material budget if 2 consecutive gold
1817 if(iplane>0 && track->GetTracklet(iplane-1) && ptrTracklet->GetN() + track->GetTracklet(iplane-1)->GetN() > 20) track->SetBudget(2, 0.);
1818 } // end planes loop
1819
1820 // extrapolation
1821 while(ip < np){
952051c5 1822 if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
1bf51039 1823
1824 Double_t xyz[3]; // should also get the covariance
3cfaffa4 1825 track->GetXYZ(xyz);
1826 track->Global2LocalPosition(xyz, track->GetAlpha());
1827 points[ip].SetXYZ(xyz[0], xyz[1], xyz[2]);
1bf51039 1828 ip++;
1829 }
1830
1831 return track->GetChi2();
1832}
3b57a3f7 1833
eb38ed55 1834//_________________________________________________________________________
d8069611 1835Float_t AliTRDtrackerV1::CalculateChi2Z(const AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
eb38ed55 1836{
41702fec 1837 //
1838 // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
1839 // A linear dependence on the x-value serves as a model.
1840 // The parameters are related to the tilted Riemann fit.
1841 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
1842 // - the offset for the reference x
1843 // - the slope
1844 // - the reference x position
1845 // Output: - The Chi2 value of the track in z-Direction
1846 //
1847 Float_t chi2Z = 0, nLayers = 0;
053767a4 1848 for (Int_t iLayer = 0; iLayer < AliTRDgeometry::kNlayer; iLayer++) {
41702fec 1849 if(!tracklets[iLayer].IsOK()) continue;
1850 Double_t z = offset + slope * (tracklets[iLayer].GetX0() - xref);
e3cf3d02 1851 chi2Z += TMath::Abs(tracklets[iLayer].GetZfit(0) - z);
41702fec 1852 nLayers++;
1853 }
1854 chi2Z /= TMath::Max((nLayers - 3.0),1.0);
1855 return chi2Z;
eb38ed55 1856}
1857
bccda319 1858//_____________________________________________________________________________
1859Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t maxStep)
1860{
41702fec 1861 //
1862 // Starting from current X-position of track <t> this function
1863 // extrapolates the track up to radial position <xToGo>.
1864 // Returns 1 if track reaches the plane, and 0 otherwise
1865 //
bccda319 1866
41702fec 1867 // Current track X-position
15a2657d 1868 Double_t xpos = t.GetX()/*,
1869 mass = t.GetMass()*/;
bccda319 1870
41702fec 1871 // Direction: inward or outward
1872 Double_t dir = (xpos < xToGo) ? 1.0 : -1.0;
bccda319 1873
952051c5 1874 while (((xToGo - xpos) * dir) > AliTRDReconstructor::GetEpsilon()) {
2f4384e6 1875// printf("to go %f\n", (xToGo - xpos) * dir);
41702fec 1876 Double_t xyz0[3];
1877 Double_t xyz1[3];
1878 Double_t param[7];
1879 Double_t x;
1880 Double_t y;
1881 Double_t z;
bccda319 1882
41702fec 1883 // The next step size
1884 Double_t step = dir * TMath::Min(TMath::Abs(xToGo-xpos),maxStep);
bccda319 1885
41702fec 1886 // Get the global position of the starting point
1887 t.GetXYZ(xyz0);
bccda319 1888
41702fec 1889 // X-position after next step
1890 x = xpos + step;
bccda319 1891
41702fec 1892 // Get local Y and Z at the X-position of the next step
3352b455 1893 if(t.GetProlongation(x,y,z)<0) return 0; // No prolongation possible
bccda319 1894
41702fec 1895 // The global position of the end point of this prolongation step
1896 xyz1[0] = x * TMath::Cos(t.GetAlpha()) - y * TMath::Sin(t.GetAlpha());
1897 xyz1[1] = +x * TMath::Sin(t.GetAlpha()) + y * TMath::Cos(t.GetAlpha());
1898 xyz1[2] = z;
bccda319 1899
41702fec 1900 // Calculate the mean material budget between start and
1901 // end point of this prolongation step
83dea92e 1902 if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
2f4384e6 1903
41702fec 1904 // Propagate the track to the X-position after the next step
9c87a076 1905 if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
bccda319 1906
15a2657d 1907/* // Correct for mean material budget
2f4384e6 1908 Double_t dEdx(0.),
1d26da6d 1909 bg(TMath::Abs(t.GetP()/mass));
2f4384e6 1910 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3){
1911 const char *pn[] = {"rho", "x/X0", "<A>", "<Z>", "L", "<Z/A>", "Nb"};
1912 printf("D-AliTRDtrackerV1::PropagateTo(): x[%6.2f] bg[%6.2f]\n", xpos, bg);
1913 printf(" param :: %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e]\n"
1914 , pn[0], param[0]
1915 , pn[1], param[1]
1916 , pn[2], param[2]
1917 , pn[3], param[3]
1918 , pn[4], param[4]
1919 , pn[5], param[5]
1920 , pn[6], param[6]);
1921 }
1922 switch(fgBB){
1923 case kSolid:
1924 dEdx = AliExternalTrackParam::BetheBlochSolid(bg);
1925 break;
1926 case kGas:
1927 dEdx = AliExternalTrackParam::BetheBlochGas(bg);
1928 break;
1929 case kGeant:
1930 { // mean exitation energy (GeV)
1931 Double_t mee = ((param[3] < 13.) ? (12. * param[3] + 7.) : (9.76 * param[3] + 58.8 * TMath::Power(param[3],-0.19))) * 1.e-9;
1932 Double_t mZA = param[5]>1.e-5?param[5]:(param[3]/param[2]);
1933 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3) printf("D-AliTRDtrackerV1::PropagateTo(): Mee[%e] <Z/A>[%e]\n", mee, mZA);
1934 // protect against failed calculation of rho in MeanMaterialBudget()
1935 dEdx = AliExternalTrackParam::BetheBlochGeant(bg, param[0]>1.e-6?param[0]:2.33, 0.2, 3., mee, mZA);
1936 }
1937 break;
1938 }
1939 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=2) printf("D-AliTRDtrackerV1::PropagateTo(): dEdx(bg=%e, m=%e)= %e[GeV/cm]\n", bg, mass, dEdx);
1940 if (!t.CorrectForMeanMaterialdEdx(param[1], dir*param[0]*param[4], mass, dEdx)) return 0;
15a2657d 1941*/
41702fec 1942 // Rotate the track if necessary
e7542a7e 1943 if(!AdjustSector(&t)) return 0;
bccda319 1944
41702fec 1945 // New track X-position
1946 xpos = t.GetX();
bccda319 1947
41702fec 1948 }
bccda319 1949
41702fec 1950 return 1;
bccda319 1951
1952}
1953
eb38ed55 1954//_____________________________________________________________________________
e7542a7e 1955Bool_t AliTRDtrackerV1::ReadClusters(TTree *clusterTree)
eb38ed55 1956{
41702fec 1957 //
1958 // Reads AliTRDclusters from the file.
1959 // The names of the cluster tree and branches
1960 // should match the ones used in AliTRDclusterizer::WriteClusters()
1961 //
1962
1963 Int_t nsize = Int_t(clusterTree->GetTotBytes() / (sizeof(AliTRDcluster)));
1964 TObjArray *clusterArray = new TObjArray(nsize+1000);
1965
1966 TBranch *branch = clusterTree->GetBranch("TRDcluster");
1967 if (!branch) {
1968 AliError("Can't get the branch !");
e7542a7e 1969 return kFALSE;
41702fec 1970 }
1971 branch->SetAddress(&clusterArray);
d2eba04b 1972
41702fec 1973 if(!fClusters){
9e85cb05 1974 Float_t nclusters = fkRecoParam->GetNClusters();
4d6aee34 1975 if(fkReconstructor->IsHLT()) nclusters /= AliTRDgeometry::kNsector;
e7542a7e 1976 fClusters = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1977 fClusters->SetOwner(kTRUE);
d2eba04b 1978 SetClustersOwner();
1979 AliInfo(Form("Tracker owning clusters @ %p", (void*)fClusters));
41702fec 1980 }
1981
1982 // Loop through all entries in the tree
1983 Int_t nEntries = (Int_t) clusterTree->GetEntries();
1984 Int_t nbytes = 0;
1985 Int_t ncl = 0;
4d6aee34 1986 AliTRDcluster *c = NULL;
41702fec 1987 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
1988 // Import the tree
1989 nbytes += clusterTree->GetEvent(iEntry);
1990
1991 // Get the number of points in the detector
1992 Int_t nCluster = clusterArray->GetEntriesFast();
1993 for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
1994 if(!(c = (AliTRDcluster *) clusterArray->UncheckedAt(iCluster))) continue;
41702fec 1995 new((*fClusters)[ncl++]) AliTRDcluster(*c);
1996 delete (clusterArray->RemoveAt(iCluster));
1997 }
41702fec 1998 }
1999 delete clusterArray;
2000
e7542a7e 2001 return kTRUE;
eb38ed55 2002}
2003
2004//_____________________________________________________________________________
2005Int_t AliTRDtrackerV1::LoadClusters(TTree *cTree)
2006{
41702fec 2007 //
66f6bfd9 2008 // Fills clusters into TRD tracking sectors
41702fec 2009 //
41702fec 2010
9e85cb05 2011 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
2012
d2eba04b 2013// if(!fkReconstructor->IsWritingClusters()) AliInfo(Form("IsWritingClusters[%c]", fkReconstructor->IsWritingClusters()?'y':'n'));
2014 if(!(fClusters = AliTRDReconstructor::GetClusters())){
2015 AliWarning("Clusters unavailable from TRD reconstructor. Trying reading from tree ...");
48f8adf3 2016 } else {
e7542a7e 2017 if(!ReadClusters(cTree)) {
d2eba04b 2018 AliError("Reading clusters from tree failed.");
66f6bfd9 2019 return 1;
2020 }
2021 }
66f6bfd9 2022
48f8adf3 2023 if(!fClusters || !fClusters->GetEntriesFast()){
66f6bfd9 2024 AliInfo("No TRD clusters");
41702fec 2025 return 1;
d2eba04b 2026 } else AliInfo(Form("Using :: clusters[%d] onl.tracklets[%d] onl.tracks[%d]",
2027 fClusters?fClusters->GetEntriesFast():0,
2028 AliTRDReconstructor::GetTracklets()?AliTRDReconstructor::GetTracklets()->GetEntriesFast():0,
2029 AliTRDReconstructor::GetTracks()?AliTRDReconstructor::GetTracks()->GetEntriesFast():0));
66f6bfd9 2030
66f6bfd9 2031 BuildTrackingContainers();
2032
66f6bfd9 2033 return 0;
2034}
2035
2036//_____________________________________________________________________________
4d6aee34 2037Int_t AliTRDtrackerV1::LoadClusters(TClonesArray * const clusters)
66f6bfd9 2038{
2039 //
2040 // Fills clusters into TRD tracking sectors
2041 // Function for use in the HLT
2042
2043 if(!clusters || !clusters->GetEntriesFast()){
2044 AliInfo("No TRD clusters");
41702fec 2045 return 1;
d2eba04b 2046 } else AliInfo(Form("Using :: external.clusters[%d]", clusters->GetEntriesFast()));
2047
41702fec 2048
66f6bfd9 2049 fClusters = clusters;
66f6bfd9 2050
9e85cb05 2051 fkRecoParam = fkReconstructor->GetRecoParam(); // load reco param for this event
66f6bfd9 2052 BuildTrackingContainers();
2053
66f6bfd9 2054 return 0;
2055}
2056
2057
2058//____________________________________________________________________
2059Int_t AliTRDtrackerV1::BuildTrackingContainers()
2060{
2061// Building tracking containers for clusters
2062
c79857d5 2063 Int_t nin(0), ncl(fClusters->GetEntriesFast());
2064 while (ncl--) {
2065 AliTRDcluster *c = (AliTRDcluster *) fClusters->UncheckedAt(ncl);
41702fec 2066 if(c->IsInChamber()) nin++;
4226b195 2067 if(fkReconstructor->IsHLT()) c->SetRPhiMethod(AliTRDcluster::kCOG);
41702fec 2068 Int_t detector = c->GetDetector();
2069 Int_t sector = fGeom->GetSector(detector);
053767a4 2070 Int_t stack = fGeom->GetStack(detector);
2071 Int_t layer = fGeom->GetLayer(detector);
41702fec 2072
0b559d95 2073 fTrSec[sector].GetChamber(stack, layer, kTRUE)->InsertCluster(c, ncl);
41702fec 2074 }
b0a48c4d 2075
053767a4 2076 for(int isector =0; isector<AliTRDgeometry::kNsector; isector++){
41702fec 2077 if(!fTrSec[isector].GetNChambers()) continue;
c79857d5 2078 fTrSec[isector].Init(fkReconstructor);
41702fec 2079 }
66f6bfd9 2080
2081 return nin;
eb38ed55 2082}
2083
2084
66f6bfd9 2085
0906e73e 2086//____________________________________________________________________
172b6f82 2087void AliTRDtrackerV1::UnloadClusters()
0906e73e 2088{
d4cf71ca 2089//
2090// Clears the arrays of clusters and tracks. Resets sectors and timebins
2091// If option "force" is also set the containers are also deleted. This is useful
2092// in case of HLT
2093
2094 if(fTracks){
2095 fTracks->Delete();
4d6aee34 2096 if(HasRemoveContainers()){delete fTracks; fTracks = NULL;}
d4cf71ca 2097 }
2098 if(fTracklets){
2099 fTracklets->Delete();
4d6aee34 2100 if(HasRemoveContainers()){delete fTracklets; fTracklets = NULL;}
d4cf71ca 2101 }
d2eba04b 2102 if(fClusters && IsClustersOwner()){
2103 AliInfo(Form("tracker[%p] clearing %d own clusters @ %p", (void*)this, fClusters->GetEntries(), (void*)fClusters));
2104 fClusters->Delete();
2105//
2106// // save clusters array in the reconstructor for further use.
2107// if(!fkReconstructor->IsWritingClusters()){
2108// AliTRDReconstructor::SetClusters(fClusters);
2109// SetClustersOwner(kFALSE);
2110// } else AliTRDReconstructor::SetClusters(NULL);
48f8adf3 2111 }
0906e73e 2112
053767a4 2113 for (int i = 0; i < AliTRDgeometry::kNsector; i++) fTrSec[i].Clear();
0906e73e 2114
41702fec 2115 // Increment the Event Number
2116 AliTRDtrackerDebug::SetEventNumber(AliTRDtrackerDebug::GetEventNumber() + 1);
eb38ed55 2117}
0906e73e 2118
fac58f00 2119// //____________________________________________________________________
2120// void AliTRDtrackerV1::UseClusters(const AliKalmanTrack *t, Int_t) const
2121// {
2122// const AliTRDtrackV1 *track = dynamic_cast<const AliTRDtrackV1*>(t);
2123// if(!track) return;
2124//
4d6aee34 2125// AliTRDseedV1 *tracklet = NULL;
fac58f00 2126// for(Int_t ily=AliTRDgeometry::kNlayer; ily--;){
2127// if(!(tracklet = track->GetTracklet(ily))) continue;
4d6aee34 2128// AliTRDcluster *c = NULL;
8d2bec9e 2129// for(Int_t ic=AliTRDseed::kNclusters; ic--;){
fac58f00 2130// if(!(c=tracklet->GetClusters(ic))) continue;
2131// c->Use();
2132// }
2133// }
2134// }
2135//
b1957d3c 2136
eb38ed55 2137//_____________________________________________________________________________
4d6aee34 2138Bool_t AliTRDtrackerV1::AdjustSector(AliTRDtrackV1 *const track)
eb38ed55 2139{
41702fec 2140 //
2141 // Rotates the track when necessary
2142 //
2143
2144 Double_t alpha = AliTRDgeometry::GetAlpha();
2145 Double_t y = track->GetY();
2146 Double_t ymax = track->GetX()*TMath::Tan(0.5*alpha);
3cfaffa4 2147
41702fec 2148 if (y > ymax) {
2149 if (!track->Rotate( alpha)) {
2150 return kFALSE;
2151 }
2152 }
2153 else if (y < -ymax) {
2154 if (!track->Rotate(-alpha)) {
2155 return kFALSE;
2156 }
2157 }
2158
2159 return kTRUE;
0906e73e 2160
2161}
2162
eb38ed55 2163
0906e73e 2164//____________________________________________________________________
33ab3872 2165AliTRDseedV1* AliTRDtrackerV1::GetTracklet(const AliTRDtrackV1 *const track, Int_t p, Int_t &idx)
0906e73e 2166{
41702fec 2167 // Find tracklet for TRD track <track>
2168 // Parameters
2169 // - track
2170 // - sector
2171 // - plane
2172 // - index
2173 // Output
2174 // tracklet
2175 // index
2176 // Detailed description
2177 //
2178 idx = track->GetTrackletIndex(p);
17896e82 2179 AliTRDseedV1 *tracklet = (idx<0) ? NULL : (AliTRDseedV1*)fTracklets->UncheckedAt(idx);
41702fec 2180
2181 return tracklet;
0906e73e 2182}
2183
2184//____________________________________________________________________
4d6aee34 2185AliTRDseedV1* AliTRDtrackerV1::SetTracklet(const AliTRDseedV1 * const tracklet)
0906e73e 2186{
41702fec 2187 // Add this tracklet to the list of tracklets stored in the tracker
2188 //
2189 // Parameters
2190 // - tracklet : pointer to the tracklet to be added to the list
2191 //
2192 // Output
2193 // - the index of the new tracklet in the tracker tracklets list
2194 //
2195 // Detailed description
2196 // Build the tracklets list if it is not yet created (late initialization)
2197 // and adds the new tracklet to the list.
2198 //
2199 if(!fTracklets){
053767a4 2200 fTracklets = new TClonesArray("AliTRDseedV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
41702fec 2201 fTracklets->SetOwner(kTRUE);
2202 }
2203 Int_t nentries = fTracklets->GetEntriesFast();
2204 return new ((*fTracklets)[nentries]) AliTRDseedV1(*tracklet);
972ef65e 2205}
2206
d20df6fc 2207//____________________________________________________________________
4d6aee34 2208AliTRDtrackV1* AliTRDtrackerV1::SetTrack(const AliTRDtrackV1 * const track)
d20df6fc 2209{
2210 // Add this track to the list of tracks stored in the tracker
2211 //
2212 // Parameters
2213 // - track : pointer to the track to be added to the list
2214 //
2215 // Output
2216 // - the pointer added
2217 //
2218 // Detailed description
2219 // Build the tracks list if it is not yet created (late initialization)
2220 // and adds the new track to the list.
2221 //
2222 if(!fTracks){
053767a4 2223 fTracks = new TClonesArray("AliTRDtrackV1", AliTRDgeometry::Nsector()*kMaxTracksStack);
d20df6fc 2224 fTracks->SetOwner(kTRUE);
2225 }
2226 Int_t nentries = fTracks->GetEntriesFast();
2227 return new ((*fTracks)[nentries]) AliTRDtrackV1(*track);
2228}
2229
2230
0906e73e 2231
e4f2f73d 2232//____________________________________________________________________
eb38ed55 2233Int_t AliTRDtrackerV1::Clusters2TracksSM(Int_t sector, AliESDEvent *esd)
e4f2f73d 2234{
41702fec 2235 //
2236 // Steer tracking for one SM.
2237 //
2238 // Parameters :
2239 // sector : Array of (SM) propagation layers containing clusters
2240 // esd : The current ESD event. On output it contains the also
2241 // the ESD (TRD) tracks found in this SM.
2242 //
2243 // Output :
2244 // Number of tracks found in this TRD supermodule.
2245 //
2246 // Detailed description
2247 //
2248 // 1. Unpack AliTRDpropagationLayers objects for each stack.
2249 // 2. Launch stack tracking.
2250 // See AliTRDtrackerV1::Clusters2TracksStack() for details.
2251 // 3. Pack results in the ESD event.
2252 //
2253
41702fec 2254 Int_t nTracks = 0;
2255 Int_t nChambers = 0;
4d6aee34 2256 AliTRDtrackingChamber **stack = NULL, *chamber = NULL;
053767a4 2257 for(int istack = 0; istack<AliTRDgeometry::kNstack; istack++){
41702fec 2258 if(!(stack = fTrSec[sector].GetStack(istack))) continue;
2259 nChambers = 0;
053767a4 2260 for(int ilayer=0; ilayer<AliTRDgeometry::kNlayer; ilayer++){
2261 if(!(chamber = stack[ilayer])) continue;
9e85cb05 2262 if(chamber->GetNClusters() < fgNTimeBins * fkRecoParam->GetFindableClusters()) continue;
41702fec 2263 nChambers++;
053767a4 2264 //AliInfo(Form("sector %d stack %d layer %d clusters %d", sector, istack, ilayer, chamber->GetNClusters()));
41702fec 2265 }
2266 if(nChambers < 4) continue;
2267 //AliInfo(Form("Doing stack %d", istack));
b1135f96 2268 nTracks += Clusters2TracksStack(stack, fTracksESD);
41702fec 2269 }
050875b0 2270 if(nTracks) AliDebug(2, Form("Number of tracks: SM_%02d[%d]", sector, nTracks));
2271
352cef8f 2272 for(int itrack=0; itrack<nTracks; itrack++){
2273 AliESDtrack *esdTrack((AliESDtrack*)(fTracksESD->operator[](itrack)));
2274 Int_t id = esd->AddTrack(esdTrack);
2275
2276 // set ESD id to stand alone TRD tracks
d0177bb6 2277 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
352cef8f 2278 esdTrack=esd->GetTrack(id);
2279 TObject *o(NULL); Int_t ic(0);
2280 AliTRDtrackV1 *calibTrack(NULL);
2281 while((o = esdTrack->GetCalibObject(ic++))){
2282 if(!(calibTrack = dynamic_cast<AliTRDtrackV1*>(o))) continue;
2283 calibTrack->SetESDid(esdTrack->GetID());
2284 break;
2285 }
2286 }
2287 }
41702fec 2288
2289 // Reset Track and Candidate Number
2290 AliTRDtrackerDebug::SetCandidateNumber(0);
2291 AliTRDtrackerDebug::SetTrackNumber(0);
b1135f96 2292
2293 // delete ESD tracks in the array
2294 fTracksESD->Delete();
41702fec 2295 return nTracks;
e4f2f73d 2296}
2297
2298//____________________________________________________________________
4d6aee34 2299Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClonesArray * const esdTrackList)
e4f2f73d 2300{
41702fec 2301 //
2302 // Make tracks in one TRD stack.
2303 //
2304 // Parameters :
2305 // layer : Array of stack propagation layers containing clusters
2306 // esdTrackList : Array of ESD tracks found by the stand alone tracker.
2307 // On exit the tracks found in this stack are appended.
2308 //
2309 // Output :
2310 // Number of tracks found in this stack.
2311 //
2312 // Detailed description
2313 //
2314 // 1. Find the 3 most useful seeding chambers. See BuildSeedingConfigs() for details.
2315 // 2. Steer AliTRDtrackerV1::MakeSeeds() for 3 seeding layer configurations.
2316 // See AliTRDtrackerV1::MakeSeeds() for more details.
2317 // 3. Arrange track candidates in decreasing order of their quality
2318 // 4. Classify tracks in 5 categories according to:
2319 // a) number of layers crossed
2320 // b) track quality
2321 // 5. Sign clusters by tracks in decreasing order of track quality
2322 // 6. Build AliTRDtrack out of seeding tracklets
2323 // 7. Cook MC label
2324 // 8. Build ESD track and register it to the output list
2325 //
2326
4d6aee34 2327 AliTRDtrackingChamber *chamber = NULL;
2328 AliTRDtrackingChamber **ci = NULL;
41702fec 2329 AliTRDseedV1 sseed[kMaxTracksStack*6]; // to be initialized
2330 Int_t pars[4]; // MakeSeeds parameters
2331
2332 //Double_t alpha = AliTRDgeometry::GetAlpha();
2333 //Double_t shift = .5 * alpha;
2334 Int_t configs[kNConfigs];
2335
fac58f00 2336 // Purge used clusters from the containers
2337 ci = &stack[0];
2338 for(Int_t ic = kNPlanes; ic--; ci++){
2339 if(!(*ci)) continue;
2340 (*ci)->Update();
2341 }
2342
41702fec 2343 // Build initial seeding configurations
2344 Double_t quality = BuildSeedingConfigs(stack, configs);
d0177bb6 2345 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10 || AliTRDReconstructor::GetStreamLevel()>10){
41702fec 2346 AliInfo(Form("Plane config %d %d %d Quality %f"
2347 , configs[0], configs[1], configs[2], quality));
2348 }
d931f2aa 2349
41702fec 2350
2351 // Initialize contors
2352 Int_t ntracks, // number of TRD track candidates
2353 ntracks1, // number of registered TRD tracks/iter
2354 ntracks2 = 0; // number of all registered TRD tracks in stack
2355 fSieveSeeding = 0;
d931f2aa 2356
2357 // Get stack index
fac58f00 2358 Int_t ic = 0; ci = &stack[0];
2359 while(ic<kNPlanes && !(*ci)){ic++; ci++;}
2360 if(!(*ci)) return ntracks2;
2361 Int_t istack = fGeom->GetStack((*ci)->GetDetector());
d931f2aa 2362
41702fec 2363 do{
2364 // Loop over seeding configurations
2365 ntracks = 0; ntracks1 = 0;
0b559d95 2366 for (Int_t iconf = 0; iconf<fkRecoParam->GetNumberOfSeedConfigs(); iconf++) {
41702fec 2367 pars[0] = configs[iconf];
2368 pars[1] = ntracks;
d931f2aa 2369 pars[2] = istack;
41702fec 2370 ntracks = MakeSeeds(stack, &sseed[6*ntracks], pars);
6e39bde4 2371 //AliInfo(Form("Number of Tracks after iteration step %d: %d\n", iconf, ntracks));
41702fec 2372 if(ntracks == kMaxTracksStack) break;
2373 }
980d5a2a 2374 AliDebug(2, Form("Candidate TRD tracks %d in iteration %d.", ntracks, fSieveSeeding));
41702fec 2375 if(!ntracks) break;
2376
2377 // Sort the seeds according to their quality
41f024fb 2378 Int_t sort[kMaxTracksStack+1];
41702fec 2379 TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
68f9b6bd 2380 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 2){
2381 AliDebug(3, "Track candidates classification:");
2382 for (Int_t it(0); it < ntracks; it++) {
2383 Int_t jt(sort[it]);
2384 printf(" %2d idx[%d] Quality[%e]\n", it, jt, fTrackQuality[jt]);
2385 }
2386 }
41702fec 2387
2388 // Initialize number of tracks so far and logic switches
2389 Int_t ntracks0 = esdTrackList->GetEntriesFast();
2390 Bool_t signedTrack[kMaxTracksStack];
2391 Bool_t fakeTrack[kMaxTracksStack];
2392 for (Int_t i=0; i<ntracks; i++){
2393 signedTrack[i] = kFALSE;
2394 fakeTrack[i] = kFALSE;
2395 }
2396 //AliInfo("Selecting track candidates ...");
2397
2398 // Sieve clusters in decreasing order of track quality
68f9b6bd 2399 Int_t jSieve(0), rejectedCandidates(0);
41702fec 2400 do{
41702fec 2401 // Check track candidates
68f9b6bd 2402 rejectedCandidates=0;
41702fec 2403 for (Int_t itrack = 0; itrack < ntracks; itrack++) {
804bb02e 2404 Int_t trackIndex = sort[itrack];
2405 if (signedTrack[trackIndex] || fakeTrack[trackIndex]) continue;
41702fec 2406
804bb02e 2407 // Calculate track parameters from tracklets seeds
804bb02e 2408 Int_t ncl = 0;
2409 Int_t nused = 0;
2410 Int_t nlayers = 0;
2411 Int_t findable = 0;
2412 for (Int_t jLayer = 0; jLayer < kNPlanes; jLayer++) {
2413 Int_t jseed = kNPlanes*trackIndex+jLayer;
68f9b6bd 2414 sseed[jseed].UpdateUsed();
804bb02e 2415 if(!sseed[jseed].IsOK()) continue;
68f9b6bd 2416 // check if primary candidate
f29f13a6 2417 if (TMath::Abs(sseed[jseed].GetYref(0) / sseed[jseed].GetX0()) < 0.158) findable++;
68f9b6bd 2418 ncl += sseed[jseed].GetN();
804bb02e 2419 nused += sseed[jseed].GetNUsed();
2420 nlayers++;
804bb02e 2421 }
2422
f29f13a6 2423 // Filter duplicated tracks
2424 if (nused > 30){
68f9b6bd 2425 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
f29f13a6 2426 fakeTrack[trackIndex] = kTRUE;
2427 continue;
2428 }
5ef88e00 2429 if (ncl>0 && Float_t(nused)/ncl >= .25){
68f9b6bd 2430 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d] used/ncl[%f]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused, Float_t(nused)/ncl));
f29f13a6 2431 fakeTrack[trackIndex] = kTRUE;
2432 continue;
2433 }
41702fec 2434
68f9b6bd 2435 AliDebug(4, Form("Candidate[%d] Quality[%e] Tracklets[%d] Findable[%d] Ncl[%d] Nused[%d]", trackIndex, fTrackQuality[trackIndex], nlayers, findable, ncl, nused));
2436
f29f13a6 2437 // Classify tracks
2438 Bool_t skip = kFALSE;
2439 switch(jSieve){
68f9b6bd 2440 case 0: // select 6 tracklets primary tracks, good quality
2441 if(nlayers > findable || nlayers < kNPlanes) {skip = kTRUE; break;}
f29f13a6 2442 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2443 break;
2444
68f9b6bd 2445 case 1: // select shorter primary tracks, good quality
e7542a7e 2446 //if(findable<4){skip = kTRUE; break;}
f29f13a6 2447 if(nlayers < findable){skip = kTRUE; break;}
2448 if(TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -4.){skip = kTRUE; break;}
2449 break;
2450
68f9b6bd 2451 case 2: // select 6 tracklets secondary tracks
2452 if(nlayers < kNPlanes) { skip = kTRUE; break;}
f29f13a6 2453 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -6.0){skip = kTRUE; break;}
2454 break;
2455
68f9b6bd 2456 case 3: // select shorter tracks, good quality
2457 if (nlayers<4){skip = kTRUE; break;}
f29f13a6 2458 if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) < -5.){skip = kTRUE; break;}
2459 break;
2460
68f9b6bd 2461 case 4: // select anything with at least 4 tracklets
2462 if (nlayers<4){skip = kTRUE; break;}
f29f13a6 2463 //if (TMath::Log(1.E-9+fTrackQuality[trackIndex]) - nused/(nlayers-3.0) < -15.0){skip = kTRUE; break;}
2464 break;
2465 }
2466 if(skip){
68f9b6bd 2467 rejectedCandidates++;
5ef88e00 2468 AliDebug(4, Form("REJECTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
f29f13a6 2469 continue;
5ef88e00 2470 } else AliDebug(4, Form("ACCEPTED : %d idx[%d] quality[%e] tracklets[%d] usedClusters[%d]", itrack, trackIndex, fTrackQuality[trackIndex], nlayers, nused));
2471
f29f13a6 2472 signedTrack[trackIndex] = kTRUE;
2473
68f9b6bd 2474 AliTRDseedV1 *lseed =&sseed[trackIndex*kNPlanes];
2475 AliTRDtrackV1 *track = MakeTrack(lseed);
2476 if(!track){
2477 AliDebug(1, "Track building failed.");
2478 continue;
2479 } else {
2480 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 1){
2481 Int_t ich = 0; while(!(chamber = stack[ich])) ich++;
2482 AliDebug(2, Form("Track pt=%7.2fGeV/c SM[%2d] Done.", track->Pt(), fGeom->GetSector(chamber->GetDetector())));
2483 }
2484 }
f29f13a6 2485
9e85cb05 2486 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()){
eb2b4f91 2487 //AliInfo(Form("Track %d [%d] nlayers %d trackQuality = %e nused %d, yref = %3.3f", itrack, trackIndex, nlayers, fTrackQuality[trackIndex], nused, trackParams[1]));
f29f13a6 2488
f29f13a6 2489 AliTRDseedV1 *dseed[6];
b82b4de1 2490 for(Int_t iseed = AliTRDgeometry::kNlayer; iseed--;) dseed[iseed] = new AliTRDseedV1(lseed[iseed]);
f29f13a6 2491
2492 //Int_t eventNrInFile = esd->GetEventNumberInFile();
f29f13a6 2493 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2494 Int_t trackNumber = AliTRDtrackerDebug::GetTrackNumber();
2495 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
a2fbb6ec 2496 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
f29f13a6 2497 cstreamer << "Clusters2TracksStack"
68f9b6bd 2498 << "EventNumber=" << eventNumber
2499 << "TrackNumber=" << trackNumber
2500 << "CandidateNumber=" << candidateNumber
2501 << "Iter=" << fSieveSeeding
2502 << "Like=" << fTrackQuality[trackIndex]
2503 << "S0.=" << dseed[0]
2504 << "S1.=" << dseed[1]
2505 << "S2.=" << dseed[2]
2506 << "S3.=" << dseed[3]
2507 << "S4.=" << dseed[4]
2508 << "S5.=" << dseed[5]
2509 << "Ncl=" << ncl
2510 << "NLayers=" << nlayers
2511 << "Findable=" << findable
2512 << "NUsed=" << nused
f29f13a6 2513 << "\n";
2514 }
d877f55f 2515
68f9b6bd 2516
f29f13a6 2517 AliESDtrack *esdTrack = new ((*esdTrackList)[ntracks0++]) AliESDtrack();
2518 esdTrack->UpdateTrackParams(track, AliESDtrack::kTRDout);
2519 esdTrack->SetLabel(track->GetLabel());
2520 track->UpdateESDtrack(esdTrack);
2521 // write ESD-friends if neccessary
d0177bb6 2522 if (fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 0 || AliTRDReconstructor::GetStreamLevel()>0 ){
f29f13a6 2523 AliTRDtrackV1 *calibTrack = new AliTRDtrackV1(*track);
2524 calibTrack->SetOwner();
2525 esdTrack->AddCalibObject(calibTrack);
2526 }
2527 ntracks1++;
2528 AliTRDtrackerDebug::SetTrackNumber(AliTRDtrackerDebug::GetTrackNumber() + 1);
41702fec 2529 }
2530
2531 jSieve++;
68f9b6bd 2532 } while(jSieve<5 && rejectedCandidates); // end track candidates sieve
41702fec 2533 if(!ntracks1) break;
2534
2535 // increment counters
2536 ntracks2 += ntracks1;
4302c900 2537
4d6aee34 2538 if(fkReconstructor->IsHLT()) break;
41702fec 2539 fSieveSeeding++;
2540
2541 // Rebuild plane configurations and indices taking only unused clusters into account
2542 quality = BuildSeedingConfigs(stack, configs);
4d6aee34 2543 if(quality < 1.E-7) break; //fkReconstructor->GetRecoParam() ->GetPlaneQualityThreshold()) break;
41702fec 2544
2545 for(Int_t ip = 0; ip < kNPlanes; ip++){
2546 if(!(chamber = stack[ip])) continue;
c79857d5 2547 chamber->Build(fGeom);//Indices(fSieveSeeding);
41702fec 2548 }
2549
d0177bb6 2550 if(fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 10 || AliTRDReconstructor::GetStreamLevel()>10){
41702fec 2551 AliInfo(Form("Sieve level %d Plane config %d %d %d Quality %f", fSieveSeeding, configs[0], configs[1], configs[2], quality));
2552 }
2553 } while(fSieveSeeding<10); // end stack clusters sieve
2554
2555
2556
2557 //AliInfo(Form("Registered TRD tracks %d in stack %d.", ntracks2, pars[1]));
2558
2559 return ntracks2;
e4f2f73d 2560}
2561
2562//___________________________________________________________________
eb38ed55 2563Double_t AliTRDtrackerV1::BuildSeedingConfigs(AliTRDtrackingChamber **stack, Int_t *configs)
e4f2f73d 2564{
41702fec 2565 //
2566 // Assign probabilities to chambers according to their
2567 // capability of producing seeds.
2568 //
2569 // Parameters :
2570 //
2571 // layers : Array of stack propagation layers for all 6 chambers in one stack
2572 // configs : On exit array of configuration indexes (see GetSeedingConfig()
2573 // for details) in the decreasing order of their seeding probabilities.
2574 //
2575 // Output :
2576 //
2577 // Return top configuration quality
2578 //
2579 // Detailed description:
2580 //
2581 // To each chamber seeding configuration (see GetSeedingConfig() for
2582 // the list of all configurations) one defines 2 quality factors:
2583 // - an apriori topological quality (see GetSeedingConfig() for details) and
2584 // - a data quality based on the uniformity of the distribution of
2585 // clusters over the x range (time bins population). See CookChamberQA() for details.
2586 // The overall chamber quality is given by the product of this 2 contributions.
2587 //
2588
eb2b4f91 2589 Double_t chamberQ[kNPlanes];memset(chamberQ, 0, kNPlanes*sizeof(Double_t));
4d6aee34 2590 AliTRDtrackingChamber *chamber = NULL;
41702fec 2591 for(int iplane=0; iplane<kNPlanes; iplane++){
2592 if(!(chamber = stack[iplane])) continue;
2593 chamberQ[iplane] = (chamber = stack[iplane]) ? chamber->GetQuality() : 0.;
2594 }
2595
eb2b4f91 2596 Double_t tconfig[kNConfigs];memset(tconfig, 0, kNConfigs*sizeof(Double_t));
2597 Int_t planes[] = {0, 0, 0, 0};
41702fec 2598 for(int iconf=0; iconf<kNConfigs; iconf++){
2599 GetSeedingConfig(iconf, planes);
2600 tconfig[iconf] = fgTopologicQA[iconf];
2601 for(int iplane=0; iplane<4; iplane++) tconfig[iconf] *= chamberQ[planes[iplane]];
2602 }
2603
2604 TMath::Sort((Int_t)kNConfigs, tconfig, configs, kTRUE);
0b559d95 2605 // AliInfo(Form("q[%d] = %f", configs[0], tconfig[configs[0]]));
41702fec 2606 // AliInfo(Form("q[%d] = %f", configs[1], tconfig[configs[1]]));
2607 // AliInfo(Form("q[%d] = %f", configs[2], tconfig[configs[2]]));
2608
2609 return tconfig[configs[0]];
e4f2f73d 2610}
2611
2612//____________________________________________________________________
e17f4785 2613Int_t AliTRDtrackerV1::MakeSeeds(AliTRDtrackingChamber **stack, AliTRDseedV1 * const sseed, const Int_t * const ipar)
e4f2f73d 2614{
afa21247 2615//
2a3191bb 2616// Seed tracklets and build candidate TRD tracks. The procedure is used during barrel tracking to account for tracks which are
2617// either missed by TPC prolongation or conversions inside the TRD volume.
2618// For stand alone tracking the procedure is used to estimate all tracks measured by TRD.
afa21247 2619//
2620// Parameters :
2621// layers : Array of stack propagation layers containing clusters
2622// sseed : Array of empty tracklet seeds. On exit they are filled.
2623// ipar : Control parameters:
2624// ipar[0] -> seeding chambers configuration
2625// ipar[1] -> stack index
2626// ipar[2] -> number of track candidates found so far
2627//
2628// Output :
2629// Number of tracks candidates found.
2630//
2631// The following steps are performed:
2632// 1. Build seeding layers by collapsing all time bins from each of the four seeding chambers along the
2633// radial coordinate. See AliTRDtrackingChamber::GetSeedingLayer() for details. The chambers selection for seeding
2634// is described in AliTRDtrackerV1::Clusters2TracksStack().
2635// 2. Using the seeding clusters from the seeding layer (step 1) build combinatorics using the following algorithm:
2636// - for each seeding cluster in the lower seeding layer find
2637// - all seeding clusters in the upper seeding layer inside a road defined by a given phi angle. The angle
2638// is calculated on the minimum pt of tracks from vertex accesible to the stand alone tracker.
2639// - for each pair of two extreme seeding clusters select middle upper cluster using roads defined externally by the
2640// reco params
2641// - select last seeding cluster as the nearest to the linear approximation of the track described by the first three
2642// seeding clusters.
2643// The implementation of road calculation and cluster selection can be found in the functions AliTRDchamberTimeBin::BuildCond()
2644// and AliTRDchamberTimeBin::GetClusters().
2645// 3. Helix fit of the seeding clusters set. (see AliTRDtrackerFitter::FitRieman(AliTRDcluster**)). No tilt correction is
2646// performed at this level
2647// 4. Initialize seeding tracklets in the seeding chambers.
2648// 5. *Filter 0* Chi2 cut on the Y and Z directions. The threshold is set externally by the reco params.
2649// 6. Attach (true) clusters to seeding tracklets (see AliTRDseedV1::AttachClusters()) and fit tracklet (see
2650// AliTRDseedV1::Fit()). The number of used clusters used by current seeds should not exceed ... (25).
2651// 7. *Filter 1* Check if all 4 seeding tracklets are correctly constructed.
2652// 8. Helix fit of the clusters from the seeding tracklets with tilt correction. Refit tracklets using the new
2653// approximation of the track.
2654// 9. *Filter 2* Calculate likelihood of the track. (See AliTRDtrackerV1::CookLikelihood()). The following quantities are
2655// checked against the Riemann fit:
2656// - position resolution in y
2657// - angular resolution in the bending plane
2658// - likelihood of the number of clusters attached to the tracklet
2659// 10. Extrapolation of the helix fit to the other 2 chambers *non seeding* chambers:
2660// - Initialization of extrapolation tracklets with the fit parameters
2661// - Attach clusters to extrapolated tracklets
2662// - Helix fit of tracklets
2663// 11. Improve seeding tracklets quality by reassigning clusters based on the last parameters of the track
2664// See AliTRDtrackerV1::ImproveSeedQuality() for details.
2665// 12. Helix fit of all 6 seeding tracklets and chi2 calculation
2666// 13. Hyperplane fit and track quality calculation. See AliTRDtrackerFitter::FitHyperplane() for details.
2667// 14. Cooking labels for tracklets. Should be done only for MC
2668// 15. Register seeds.
2669//
2670// Authors:
2671// Marian Ivanov <M.Ivanov@gsi.de>
2672// Alexandru Bercuci <A.Bercuci@gsi.de>
2673// Markus Fasel <M.Fasel@gsi.de>
41702fec 2674
4d6aee34 2675 AliTRDtrackingChamber *chamber = NULL;
2676 AliTRDcluster *c[kNSeedPlanes] = {NULL, NULL, NULL, NULL}; // initilize seeding clusters
e17f4785 2677 AliTRDseedV1 *cseed = &sseed[0]; // initialize tracklets for first track
41702fec 2678 Int_t ncl, mcl; // working variable for looping over clusters
2679 Int_t index[AliTRDchamberTimeBin::kMaxClustersLayer], jndex[AliTRDchamberTimeBin::kMaxClustersLayer];
2680 // chi2 storage
2681 // chi2[0] = tracklet chi2 on the Z direction
2682 // chi2[1] = tracklet chi2 on the R direction
2683 Double_t chi2[4];
2684
afa21247 2685 // this should be data member of AliTRDtrack TODO
d2eba04b 2686// Double_t seedQuality[kMaxTracksStack];
41702fec 2687
2688 // unpack control parameters
2689 Int_t config = ipar[0];
2690 Int_t ntracks = ipar[1];
d931f2aa 2691 Int_t istack = ipar[2];
41702fec 2692 Int_t planes[kNSeedPlanes]; GetSeedingConfig(config, planes);
afa21247 2693 Int_t planesExt[kNPlanes-kNSeedPlanes]; GetExtrapolationConfig(config, planesExt);
be24510a 2694
2695
41702fec 2696 // Init chambers geometry
41702fec 2697 Double_t hL[kNPlanes]; // Tilting angle
2698 Float_t padlength[kNPlanes]; // pad lenghts
dd8059a8 2699 Float_t padwidth[kNPlanes]; // pad widths
4d6aee34 2700 AliTRDpadPlane *pp = NULL;
41702fec 2701 for(int iplane=0; iplane<kNPlanes; iplane++){
2702 pp = fGeom->GetPadPlane(iplane, istack);
bb79ccd5 2703 hL[iplane] = TMath::Tan(TMath::DegToRad()*pp->GetTiltingAngle());
41702fec 2704 padlength[iplane] = pp->GetLengthIPad();
dd8059a8 2705 padwidth[iplane] = pp->GetWidthIPad();
41702fec 2706 }
2707
eb2b4f91 2708 // Init anode wire position for chambers
e165b64b 2709 Double_t x0[kNPlanes], // anode wire position
eb2b4f91 2710 driftLength = .5*AliTRDgeometry::AmThick() - AliTRDgeometry::DrThick(); // drift length
4d6aee34 2711 TGeoHMatrix *matrix = NULL;
eb2b4f91 2712 Double_t loc[] = {AliTRDgeometry::AnodePos(), 0., 0.};
2713 Double_t glb[] = {0., 0., 0.};
2714 AliTRDtrackingChamber **cIter = &stack[0];
a3743898 2715 for(int iLayer=0; iLayer<kNPlanes; iLayer++,cIter++){
eb2b4f91 2716 if(!(*cIter)) continue;
e165b64b 2717 if(!(matrix = fGeom->GetClusterMatrix((*cIter)->GetDetector()))){
e165b64b 2718 x0[iLayer] = fgkX0[iLayer];
e7542a7e 2719 continue;
e165b64b 2720 }
eb2b4f91 2721 matrix->LocalToMaster(loc, glb);
2722 x0[iLayer] = glb[0];
2723 }
2724
980d5a2a 2725 AliDebug(2, Form("Making seeds Stack[%d] Config[%d] Tracks[%d]...", istack, config, ntracks));
41702fec 2726
d931f2aa 2727 // Build seeding layers
d611c74f 2728 ResetSeedTB();
41702fec 2729 Int_t nlayers = 0;
41702fec 2730 for(int isl=0; isl<kNSeedPlanes; isl++){
2731 if(!(chamber = stack[planes[isl]])) continue;
4d6aee34 2732 if(!chamber->GetSeedingLayer(fSeedTB[isl], fGeom, fkReconstructor)) continue;
41702fec 2733 nlayers++;
41702fec 2734 }
eb2b4f91 2735 if(nlayers < kNSeedPlanes) return ntracks;
41702fec 2736
2737
2738 // Start finding seeds
2739 Double_t cond0[4], cond1[4], cond2[4];
2740 Int_t icl = 0;
d611c74f 2741 while((c[3] = (*fSeedTB[3])[icl++])){
41702fec 2742 if(!c[3]) continue;
d611c74f 2743 fSeedTB[0]->BuildCond(c[3], cond0, 0);
2744 fSeedTB[0]->GetClusters(cond0, index, ncl);
41702fec 2745 //printf("Found c[3] candidates 0 %d\n", ncl);
2746 Int_t jcl = 0;
2747 while(jcl<ncl) {
d611c74f 2748 c[0] = (*fSeedTB[0])[index[jcl++]];
41702fec 2749 if(!c[0]) continue;
2750 Double_t dx = c[3]->GetX() - c[0]->GetX();
afa21247 2751 Double_t dzdx = (c[3]->GetZ() - c[0]->GetZ())/dx;
2752 Double_t dydx = (c[3]->GetY() - c[0]->GetY())/dx;
2753 fSeedTB[1]->BuildCond(c[0], cond1, 1, dzdx, dydx);
d611c74f 2754 fSeedTB[1]->GetClusters(cond1, jndex, mcl);
41702fec 2755 //printf("Found c[0] candidates 1 %d\n", mcl);
2756
2757 Int_t kcl = 0;
2758 while(kcl<mcl) {
d611c74f 2759 c[1] = (*fSeedTB[1])[jndex[kcl++]];
2760 if(!c[1]) continue;
afa21247 2761 fSeedTB[2]->BuildCond(c[1], cond2, 2, dzdx, dydx);
d611c74f 2762 c[2] = fSeedTB[2]->GetNearestCluster(cond2);
2763 //printf("Found c[1] candidate 2 %p\n", c[2]);
2764 if(!c[2]) continue;
980d5a2a 2765
2766 AliDebug(3, Form("Seeding clusters\n 0[%6.3f %6.3f %6.3f]\n 1[%6.3f %6.3f %6.3f]\n 2[%6.3f %6.3f %6.3f]\n 3[%6.3f %6.3f %6.3f].",
2767 c[0]->GetX(), c[0]->GetY(), c[0]->GetZ(),
2768 c[1]->GetX(), c[1]->GetY(), c[1]->GetZ(),
2769 c[2]->GetX(), c[2]->GetY(), c[2]->GetZ(),
2770 c[3]->GetX(), c[3]->GetY(), c[3]->GetZ()));
d611c74f 2771
804bb02e 2772 for (Int_t il = 0; il < kNPlanes; il++) cseed[il].Reset();
41702fec 2773
d611c74f 2774 FitRieman(c, chi2);
2775
d931f2aa 2776 AliTRDseedV1 *tseed = &cseed[0];
bb2db46c 2777 cIter = &stack[0];
2778 for(int iLayer=0; iLayer<kNPlanes; iLayer++, tseed++, cIter++){
2779 Int_t det = (*cIter) ? (*cIter)->GetDetector() : -1;
eb2b4f91 2780 tseed->SetDetector(det);
43d6ad34 2781 tseed->SetTilt(hL[iLayer]);
2782 tseed->SetPadLength(padlength[iLayer]);
dd8059a8 2783 tseed->SetPadWidth(padwidth[iLayer]);
4d6aee34 2784 tseed->SetReconstructor(fkReconstructor);
eb2b4f91 2785 tseed->SetX0(det<0 ? fR[iLayer]+driftLength : x0[iLayer]);
d611c74f 2786 tseed->Init(GetRiemanFitter());
f29f13a6 2787 tseed->SetStandAlone(kTRUE);
d611c74f 2788 }
2789
2790 Bool_t isFake = kFALSE;
d0177bb6 2791 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()) ||AliTRDReconstructor::GetStreamLevel()>=2 ){
d611c74f 2792 if (c[0]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2793 if (c[1]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2794 if (c[2]->GetLabel(0) != c[3]->GetLabel(0)) isFake = kTRUE;
2795
2796 Double_t xpos[4];
2797 for(Int_t l = 0; l < kNSeedPlanes; l++) xpos[l] = fSeedTB[l]->GetX();
2798 Float_t yref[4];
2799 for(int il=0; il<4; il++) yref[il] = cseed[planes[il]].GetYref(0);
2800 Int_t ll = c[3]->GetLabel(0);
2801 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2802 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2803 AliRieman *rim = GetRiemanFitter();
a2fbb6ec 2804 TTreeSRedirector &cs0 = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2805 cs0 << "MakeSeeds0"
2806 <<"EventNumber=" << eventNumber
2807 <<"CandidateNumber=" << candidateNumber
2808 <<"isFake=" << isFake
2809 <<"config=" << config
2810 <<"label=" << ll
2811 <<"chi2z=" << chi2[0]
2812 <<"chi2y=" << chi2[1]
2813 <<"Y2exp=" << cond2[0]
2814 <<"Z2exp=" << cond2[1]
2815 <<"X0=" << xpos[0] //layer[sLayer]->GetX()
2816 <<"X1=" << xpos[1] //layer[sLayer + 1]->GetX()
2817 <<"X2=" << xpos[2] //layer[sLayer + 2]->GetX()
2818 <<"X3=" << xpos[3] //layer[sLayer + 3]->GetX()
2819 <<"yref0=" << yref[0]
2820 <<"yref1=" << yref[1]
2821 <<"yref2=" << yref[2]
2822 <<"yref3=" << yref[3]
2823 <<"c0.=" << c[0]
2824 <<"c1.=" << c[1]
2825 <<"c2.=" << c[2]
2826 <<"c3.=" << c[3]
2827 <<"Seed0.=" << &cseed[planes[0]]
2828 <<"Seed1.=" << &cseed[planes[1]]
2829 <<"Seed2.=" << &cseed[planes[2]]
2830 <<"Seed3.=" << &cseed[planes[3]]
2831 <<"RiemanFitter.=" << rim
2832 <<"\n";
2833 }
9e85cb05 2834 if(chi2[0] > fkRecoParam->GetChi2Z()/*7./(3. - sLayer)*//*iter*/){
980d5a2a 2835 AliDebug(3, Form("Filter on chi2Z [%f].", chi2[0]));
d611c74f 2836 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2837 continue;
2838 }
9e85cb05 2839 if(chi2[1] > fkRecoParam->GetChi2Y()/*1./(3. - sLayer)*//*iter*/){
980d5a2a 2840 AliDebug(3, Form("Filter on chi2Y [%f].", chi2[1]));
d611c74f 2841 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2842 continue;
2843 }
2844 //AliInfo("Passed chi2 filter.");
2845
2846 // try attaching clusters to tracklets
6e39bde4 2847 Int_t mlayers = 0;
980d5a2a 2848 AliTRDcluster *cl = NULL;
be24510a 2849 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
d611c74f 2850 Int_t jLayer = planes[iLayer];
980d5a2a 2851 Int_t nNotInChamber = 0;
f29f13a6 2852 if(!cseed[jLayer].AttachClusters(stack[jLayer], kTRUE)) continue;
980d5a2a 2853 if(/*fkReconstructor->IsHLT()*/kFALSE){
2854 cseed[jLayer].UpdateUsed();
2855 if(!cseed[jLayer].IsOK()) continue;
2856 }else{
2857 cseed[jLayer].Fit();
2858 cseed[jLayer].UpdateUsed();
2859 cseed[jLayer].ResetClusterIter();
2860 while((cl = cseed[jLayer].NextCluster())){
2861 if(!cl->IsInChamber()) nNotInChamber++;
2862 }
2863 //printf("clusters[%d], used[%d], not in chamber[%d]\n", cseed[jLayer].GetN(), cseed[jLayer].GetNUsed(), nNotInChamber);
2864 if(cseed[jLayer].GetN() - (cseed[jLayer].GetNUsed() + nNotInChamber) < 5) continue; // checking for Cluster which are not in chamber is a much stronger restriction on real data
2865 }
d611c74f 2866 mlayers++;
2867 }
be24510a 2868
2869 if(mlayers < kNSeedPlanes){
980d5a2a 2870 AliDebug(2, Form("Found only %d tracklets out of %d. Skip.", mlayers, kNSeedPlanes));
be24510a 2871 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2872 continue;
2873 }
2874
2875 // temporary exit door for the HLT
4d6aee34 2876 if(fkReconstructor->IsHLT()){
be24510a 2877 // attach clusters to extrapolation chambers
2878 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2879 Int_t jLayer = planesExt[iLayer];
2880 if(!(chamber = stack[jLayer])) continue;
980d5a2a 2881 if(!cseed[jLayer].AttachClusters(chamber, kTRUE)) continue;
5f1ae1e7 2882 cseed[jLayer].Fit();
be24510a 2883 }
0b559d95 2884 //FitTiltedRiemanConstraint(&cseed[0], GetZ());
4302c900 2885 fTrackQuality[ntracks] = 1.; // dummy value
2886 ntracks++;
218ba867 2887 if(ntracks == kMaxTracksStack) return ntracks;
4302c900 2888 cseed += 6;
2889 continue;
2890 }
2891
be24510a 2892
f29f13a6 2893 // Update Seeds and calculate Likelihood
d611c74f 2894 // fit tracklets and cook likelihood
68f9b6bd 2895 Double_t chi2Vals[4];
2896 chi2Vals[0] = FitTiltedRieman(&cseed[0], kTRUE);
f29f13a6 2897 for(int iLayer=0; iLayer<kNSeedPlanes; iLayer++){
2898 Int_t jLayer = planes[iLayer];
2eb10c34 2899 cseed[jLayer].Fit(1);
f29f13a6 2900 }
91834b8d 2901 Double_t like = CookLikelihood(&cseed[0], planes); // to be checked
d611c74f 2902
9e85cb05 2903 if (TMath::Log(1.E-9 + like) < fkRecoParam->GetTrackLikelihood()){
980d5a2a 2904 AliDebug(3, Form("Filter on likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
d611c74f 2905 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
2906 continue;
2907 }
2908 //AliInfo(Form("Passed likelihood %f[%e].", TMath::Log(1.E-9 + like), like));
2909
d2eba04b 2910 // book preliminry results
2911 //seedQuality[ntracks] = like;
d611c74f 2912 fSeedLayer[ntracks] = config;/*sLayer;*/
2913
2914 // attach clusters to the extrapolation seeds
980d5a2a 2915 Int_t elayers(0);
be24510a 2916 for(int iLayer=0; iLayer<kNPlanes-kNSeedPlanes; iLayer++){
2917 Int_t jLayer = planesExt[iLayer];
d611c74f 2918 if(!(chamber = stack[jLayer])) continue;
d611c74f 2919
2920 // fit extrapolated seed
2921 if ((jLayer == 0) && !(cseed[1].IsOK())) continue;
2922 if ((jLayer == 5) && !(cseed[4].IsOK())) continue;
2923 AliTRDseedV1 pseed = cseed[jLayer];
f29f13a6 2924 if(!pseed.AttachClusters(chamber, kTRUE)) continue;
2eb10c34 2925 pseed.Fit(1);
d611c74f 2926 cseed[jLayer] = pseed;
68f9b6bd 2927 chi2Vals[0] = FitTiltedRieman(cseed, kTRUE);
2eb10c34 2928 cseed[jLayer].Fit(1);
980d5a2a 2929 elayers++;
d611c74f 2930 }
2931
2932 // AliInfo("Extrapolation done.");
2933 // Debug Stream containing all the 6 tracklets
d0177bb6 2934 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())||AliTRDReconstructor::GetStreamLevel()>=2){
a2fbb6ec 2935 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2936 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
2937 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2938 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2939 cstreamer << "MakeSeeds1"
2940 << "EventNumber=" << eventNumber
2941 << "CandidateNumber=" << candidateNumber
2942 << "S0.=" << &cseed[0]
2943 << "S1.=" << &cseed[1]
2944 << "S2.=" << &cseed[2]
2945 << "S3.=" << &cseed[3]
2946 << "S4.=" << &cseed[4]
2947 << "S5.=" << &cseed[5]
2948 << "FitterT.=" << tiltedRieman
2949 << "\n";
2950 }
2951
9e85cb05 2952 if(fkRecoParam->HasImproveTracklets()){
68f9b6bd 2953 if(!ImproveSeedQuality(stack, cseed, chi2Vals[0])){
980d5a2a 2954 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
68f9b6bd 2955 AliDebug(3, "ImproveSeedQuality() failed.");
980d5a2a 2956 }
d611c74f 2957 }
d611c74f 2958
68f9b6bd 2959 // do track fitting with vertex constraint
2960 if(fkRecoParam->IsVertexConstrained()) chi2Vals[1] = FitTiltedRiemanConstraint(&cseed[0], GetZ());
2961 else chi2Vals[1] = -1.;
2962 chi2Vals[2] = GetChi2Z(&cseed[0]);
2963 chi2Vals[3] = GetChi2Phi(&cseed[0]);
2964
2965 // calculate track quality
2966 fTrackQuality[ntracks] = CalculateTrackLikelihood(&chi2Vals[0]);
fac58f00 2967
d0177bb6 2968 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming()) ||AliTRDReconstructor::GetStreamLevel()>=2){
a2fbb6ec 2969 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
d611c74f 2970 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
2971 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
2972 TLinearFitter *fitterTC = GetTiltedRiemanFitterConstraint();
2973 TLinearFitter *fitterT = GetTiltedRiemanFitter();
91834b8d 2974 Int_t ncls = 0;
2975 for(Int_t iseed = 0; iseed < kNPlanes; iseed++){
2976 ncls += cseed[iseed].IsOK() ? cseed[iseed].GetN2() : 0;
2977 }
d611c74f 2978 cstreamer << "MakeSeeds2"
2979 << "EventNumber=" << eventNumber
2980 << "CandidateNumber=" << candidateNumber
2981 << "Chi2TR=" << chi2Vals[0]
2982 << "Chi2TC=" << chi2Vals[1]
2983 << "Nlayers=" << mlayers
91834b8d 2984 << "NClusters=" << ncls
d611c74f 2985 << "Like=" << like
2986 << "S0.=" << &cseed[0]
2987 << "S1.=" << &cseed[1]
2988 << "S2.=" << &cseed[2]
2989 << "S3.=" << &cseed[3]
2990 << "S4.=" << &cseed[4]
2991 << "S5.=" << &cseed[5]
d611c74f 2992 << "FitterT.=" << fitterT
2993 << "FitterTC.=" << fitterTC
2994 << "\n";
2995 }
68f9b6bd 2996 if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")){
2997 Double_t pt[]={0., 0.};
2998 for(Int_t il(0); il<kNPlanes; il++){
2999 if(!cseed[il].IsOK()) continue;
3000 pt[0] = GetBz()*kB2C/cseed[il].GetC();
3001 pt[1] = GetBz()*kB2C/cseed[il].GetC(1);
3002 break;
3003 }
3004 AliDebug(2, Form("Candidate[%2d] pt[%7.3f %7.3f] Q[%e]\n"
3005 " [0] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3006 " [1] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3007 " [2] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3008 " [3] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3009 " [4] x[%6.2f] n[%2d] nu[%d] OK[%c]\n"
3010 " [5] x[%6.2f] n[%2d] nu[%d] OK[%c]"
3011 , ntracks, pt[0], pt[1], fTrackQuality[ntracks]
3012 ,cseed[0].GetX(), cseed[0].GetN(), cseed[0].GetNUsed(), cseed[0].IsOK()?'y':'n'
3013 ,cseed[1].GetX(), cseed[1].GetN(), cseed[1].GetNUsed(), cseed[1].IsOK()?'y':'n'
3014 ,cseed[2].GetX(), cseed[2].GetN(), cseed[2].GetNUsed(), cseed[2].IsOK()?'y':'n'
3015 ,cseed[3].GetX(), cseed[3].GetN(), cseed[3].GetNUsed(), cseed[3].IsOK()?'y':'n'
3016 ,cseed[4].GetX(), cseed[4].GetN(), cseed[4].GetNUsed(), cseed[4].IsOK()?'y':'n'
3017 ,cseed[5].GetX(), cseed[5].GetN(), cseed[5].GetNUsed(), cseed[5].IsOK()?'y':'n'));
3018 }
d611c74f 3019 ntracks++;
3020 AliTRDtrackerDebug::SetCandidateNumber(AliTRDtrackerDebug::GetCandidateNumber() + 1);
3021 if(ntracks == kMaxTracksStack){
3022 AliWarning(Form("Number of seeds reached maximum allowed (%d) in stack.", kMaxTracksStack));
3023 return ntracks;
3024 }
3025 cseed += 6;
41702fec 3026 }
3027 }
3028 }
41702fec 3029
3030 return ntracks;
e4f2f73d 3031}
3032
3033//_____________________________________________________________________________
68f9b6bd 3034AliTRDtrackV1* AliTRDtrackerV1::MakeTrack(AliTRDseedV1 * const tracklet)
e4f2f73d 3035{
afa21247 3036//
3037// Build a TRD track out of tracklet candidates
3038//
3039// Parameters :
3040// seeds : array of tracklets
3041// params : array of track parameters as they are estimated by stand alone tracker. 7 elements.
3042// [0] - radial position of the track at reference point
3043// [1] - y position of the fit at [0]
3044// [2] - z position of the fit at [0]
3045// [3] - snp of the first tracklet
3046// [4] - tgl of the first tracklet
3047// [5] - curvature of the Riemann fit - 1/pt
3048// [6] - sector rotation angle
3049//
3050// Output :
3051// The TRD track.
3052//
3053// Initialize the TRD track based on the parameters of the fit and a parametric covariance matrix
3054// (diagonal with constant variance terms TODO - correct parameterization)
3055//
3056// In case of HLT just register the tracklets in the tracker and return values of the Riemann fit. For the
3057// offline case perform a full Kalman filter on the already found tracklets (see AliTRDtrackerV1::FollowBackProlongation()
3058// for details). Do also MC label calculation and PID if propagation successfully.
41702fec 3059
0b559d95 3060 if(fkReconstructor->IsHLT()) FitTiltedRiemanConstraint(tracklet, 0);
41702fec 3061 Double_t alpha = AliTRDgeometry::GetAlpha();
3062 Double_t shift = AliTRDgeometry::GetAlpha()/2.0;
41702fec 3063
68f9b6bd 3064 // find first good tracklet
3065 Int_t idx(0); while(idx<kNPlanes && !tracklet[idx].IsOK()) idx++;
3066 if(idx>2){ AliDebug(1, Form("Found suspect track start @ layer idx[%d]\n"
3067 " %c[0] x0[%f] n[%d] nu[%d] OK[%c]\n"
3068 " %c[1] x0[%f] n[%d] nu[%d] OK[%c]\n"
3069 " %c[2] x0[%f] n[%d] nu[%d] OK[%c]\n"
3070 " %c[3] x0[%f] n[%d] nu[%d] OK[%c]\n"
3071 " %c[4] x0[%f] n[%d] nu[%d] OK[%c]\n"
3072 " %c[5] x0[%f] n[%d] nu[%d] OK[%c]"
3073 ,idx
3074 ,idx==0?'*':' ', tracklet[0].GetX0(), tracklet[0].GetN(), tracklet[0].GetNUsed(), tracklet[0].IsOK()?'y':'n'
3075 ,idx==1?'*':' ', tracklet[1].GetX0(), tracklet[1].GetN(), tracklet[1].GetNUsed(), tracklet[1].IsOK()?'y':'n'
3076 ,idx==2?'*':' ', tracklet[2].GetX0(), tracklet[2].GetN(), tracklet[2].GetNUsed(), tracklet[2].IsOK()?'y':'n'
3077 ,idx==3?'*':' ', tracklet[3].GetX0(), tracklet[3].GetN(), tracklet[3].GetNUsed(), tracklet[3].IsOK()?'y':'n'
3078 ,idx==4?'*':' ', tracklet[4].GetX0(), tracklet[4].GetN(), tracklet[4].GetNUsed(), tracklet[4].IsOK()?'y':'n'
3079 ,idx==5?'*':' ', tracklet[5].GetX0(), tracklet[5].GetN(), tracklet[5].GetNUsed(), tracklet[5].IsOK()?'y':'n'));
3080 return NULL;
3081 }
3082
8def512c 3083 Double_t dx(5.);
3084 Double_t x(tracklet[idx].GetX0() - dx);
68f9b6bd 3085 // Build track parameters
3086 Double_t params[] = {
3087 tracklet[idx].GetYref(0) - dx*tracklet[idx].GetYref(1) // y
3088 ,tracklet[idx].GetZref(0) - dx*tracklet[idx].GetZref(1) // z
3089 ,TMath::Sin(TMath::ATan(tracklet[idx].GetYref(1))) // snp
3090 ,tracklet[idx].GetZref(1) / TMath::Sqrt(1. + tracklet[idx].GetYref(1) * tracklet[idx].GetYref(1)) // tgl
8def512c 3091 ,tracklet[idx].GetC(fkReconstructor->IsHLT()?1:0) // curvature -> 1/pt
68f9b6bd 3092 };
3093 Int_t sector(fGeom->GetSector(tracklet[idx].GetDetector()));
3094
3095 Double_t c[15];
afa21247 3096 c[ 0] = 0.2; // s^2_y
3097 c[ 1] = 0.0; c[ 2] = 2.0; // s^2_z
3098 c[ 3] = 0.0; c[ 4] = 0.0; c[ 5] = 0.02; // s^2_snp
3099 c[ 6] = 0.0; c[ 7] = 0.0; c[ 8] = 0.0; c[ 9] = 0.1; // s^2_tgl
68f9b6bd 3100 c[10] = 0.0; c[11] = 0.0; c[12] = 0.0; c[13] = 0.0; c[14] = params[4]*params[4]*0.01; // s^2_1/pt
3101
3102 AliTRDtrackV1 track(tracklet, params, c, x, sector*alpha+shift);
41702fec 3103
4d6aee34 3104 AliTRDseedV1 *ptrTracklet = NULL;
9887cc9f 3105
3106 // skip Kalman filter for HLT
5f1ae1e7 3107 if(/*fkReconstructor->IsHLT()*/kFALSE){
9887cc9f 3108 for (Int_t jLayer = 0; jLayer < AliTRDgeometry::kNlayer; jLayer++) {
3109 track.UnsetTracklet(jLayer);
68f9b6bd 3110 ptrTracklet = &tracklet[jLayer];
9887cc9f 3111 if(!ptrTracklet->IsOK()) continue;
5f1ae1e7 3112 if(TMath::Abs(ptrTracklet->GetYref(1) - ptrTracklet->GetYfit(1)) >= .2) continue; // check this condition with Marian
9887cc9f 3113 ptrTracklet = SetTracklet(ptrTracklet);
f29f13a6 3114 ptrTracklet->UseClusters();
91834b8d 3115 track.SetTracklet(ptrTracklet, fTracklets->GetEntriesFast()-1);
3116 }
d78d7df0 3117 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
799e38d7 3118 ptrTrack->CookPID();
5f1ae1e7 3119 ptrTrack->CookLabel(.9);
4d6aee34 3120 ptrTrack->SetReconstructor(fkReconstructor);
d78d7df0 3121 return ptrTrack;
91834b8d 3122 }
393fda1c 3123
b1135f96 3124 // prevent the error message in AliTracker::MeanMaterialBudget: "start point out of geometry"
68f9b6bd 3125 if(TMath::Abs(track.GetX()) + TMath::Abs(track.GetY()) + TMath::Abs(track.GetZ()) > 10000) return NULL;
17e0e535 3126
d20df6fc 3127 track.ResetCovariance(1);
e79f8eb0 3128 Int_t nc = TMath::Abs(FollowBackProlongation(track));
d0177bb6 3129 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 5 && fkReconstructor->IsDebugStreaming()) ||AliTRDReconstructor::GetStreamLevel()>5){
393fda1c 3130 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3131 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3132 Double_t p[5]; // Track Params for the Debug Stream
68f9b6bd 3133 track.GetExternalParameters(x, p);
a2fbb6ec 3134 TTreeSRedirector &cs = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
393fda1c 3135 cs << "MakeTrack"
3136 << "EventNumber=" << eventNumber
3137 << "CandidateNumber=" << candidateNumber
3138 << "nc=" << nc
68f9b6bd 3139 << "X=" << x
393fda1c 3140 << "Y=" << p[0]
3141 << "Z=" << p[1]
3142 << "snp=" << p[2]
3143 << "tnd=" << p[3]
3144 << "crv=" << p[4]
68f9b6bd 3145 << "Yin=" << params[0]
3146 << "Zin=" << params[1]
3147 << "snpin=" << params[2]
3148 << "tndin=" << params[3]
3149 << "crvin=" << params[4]
393fda1c 3150 << "track.=" << &track
3151 << "\n";
3152 }
68f9b6bd 3153 if (nc < 30){
3154 UnsetTrackletsTrack(&track);
3155 return NULL;
3156 }
d20df6fc 3157 AliTRDtrackV1 *ptrTrack = SetTrack(&track);
4d6aee34 3158 ptrTrack->SetReconstructor(fkReconstructor);
48f8adf3 3159 ptrTrack->CookLabel(.9);
68f9b6bd 3160 for(Int_t il(kNPlanes); il--;){
3161 if(!(ptrTracklet = ptrTrack->GetTracklet(il))) continue;
3162 ptrTracklet->UseClusters();
3163 }
3164
d20df6fc 3165 // computes PID for track
3166 ptrTrack->CookPID();
3167 // update calibration references using this track
48f8adf3 3168 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
e7542a7e 3169 if(!calibra){
3170 AliInfo("Could not get Calibra instance.");
3171 } else if(calibra->GetHisto2d()){
3172 calibra->UpdateHistogramsV1(ptrTrack);
48f8adf3 3173 }
d20df6fc 3174 return ptrTrack;
e4f2f73d 3175}
3176
0906e73e 3177
e4f2f73d 3178//____________________________________________________________________
68f9b6bd 3179Bool_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRDseedV1 *cseed, Double_t &chi2)
e4f2f73d 3180{
41702fec 3181 //
3182 // Sort tracklets according to "quality" and try to "improve" the first 4 worst
3183 //
3184 // Parameters :
3185 // layers : Array of propagation layers for a stack/supermodule
3186 // cseed : Array of 6 seeding tracklets which has to be improved
3187 //
f29f13a6 3188 // Output :
41702fec 3189 // cssed : Improved seeds
3190 //
3191 // Detailed description
3192 //
3193 // Iterative procedure in which new clusters are searched for each
3194 // tracklet seed such that the seed quality (see AliTRDseed::GetQuality())
3195 // can be maximized. If some optimization is found the old seeds are replaced.
3196 //
3197 // debug level: 7
3198 //
3199
3200 // make a local working copy
4d6aee34 3201 AliTRDtrackingChamber *chamber = NULL;
980d5a2a 3202 AliTRDseedV1 bseed[AliTRDgeometry::kNlayer];
3203
68f9b6bd 3204 Float_t quality(1.e3),
e7542a7e 3205 lQuality[AliTRDgeometry::kNlayer] = {1.e3, 1.e3, 1.e3, 1.e3, 1.e3, 1.e3};
980d5a2a 3206 Int_t rLayers(0);
3207 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;){
3208 bseed[jLayer] = cseed[jLayer];
3209 if(!bseed[jLayer].IsOK()) continue;
3210 rLayers++;
3211 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3212 quality += lQuality[jLayer];
3213 }
ce42378b 3214 if (rLayers > 0) {
3215 quality /= rLayers;
3216 }
68f9b6bd 3217 AliDebug(2, Form("Start N[%d] Q[%f] chi2[%f]", rLayers, quality, chi2));
41702fec 3218
3219 for (Int_t iter = 0; iter < 4; iter++) {
980d5a2a 3220 // Try better cluster set
3221 Int_t nLayers(0); Float_t qualitynew(0.);
41f024fb 3222 Int_t indexes[4*AliTRDgeometry::kNlayer];
980d5a2a 3223 TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
3224 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
3225 Int_t bLayer = indexes[jLayer];
3226 bseed[bLayer].Reset("c");
41702fec 3227 if(!(chamber = stack[bLayer])) continue;
980d5a2a 3228 if(!bseed[bLayer].AttachClusters(chamber, kTRUE)) continue;
2eb10c34 3229 bseed[bLayer].Fit(1);
980d5a2a 3230 if(!bseed[bLayer].IsOK()) continue;
3231 nLayers++;
3232 lQuality[jLayer] = bseed[jLayer].GetQuality(kTRUE);
3233 qualitynew += lQuality[jLayer];
41702fec 3234 }
980d5a2a 3235 if(rLayers > nLayers){
3236 AliDebug(1, Form("Lost %d tracklets while improving.", rLayers-nLayers));
68f9b6bd 3237 return iter>0?kTRUE:kFALSE;
980d5a2a 3238 } else rLayers=nLayers;
68f9b6bd 3239 qualitynew /= rLayers;
980d5a2a 3240
68f9b6bd 3241 if(qualitynew > quality){
3242 AliDebug(4, Form("Quality[%f] worsen in iter[%d] to ref[%f].", qualitynew, iter, quality));
3243 return iter>0?kTRUE:kFALSE;
980d5a2a 3244 } else quality = qualitynew;
3245
3246 // try improve track parameters
68f9b6bd 3247 Float_t chi2new = FitTiltedRieman(bseed, kTRUE);
980d5a2a 3248 if(chi2new > chi2){
68f9b6bd 3249 AliDebug(4, Form("Chi2[%f] worsen in iter[%d] to ref[%f].", chi2new, iter, chi2));
3250 return iter>0?kTRUE:kFALSE;
980d5a2a 3251 } else chi2 = chi2new;
3252
3253 // store better tracklets
68f9b6bd 3254 for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) cseed[jLayer]=bseed[jLayer];
3255 AliDebug(2, Form("Iter[%d] Q[%f] chi2[%f]", iter, quality, chi2));
980d5a2a 3256
41702fec 3257
d0177bb6 3258 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 7 && fkReconstructor->IsDebugStreaming())||AliTRDReconstructor::GetStreamLevel()>=7){
41702fec 3259 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3260 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
3261 TLinearFitter *tiltedRieman = GetTiltedRiemanFitter();
a2fbb6ec 3262 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3263 cstreamer << "ImproveSeedQuality"
980d5a2a 3264 << "EventNumber=" << eventNumber
3265 << "CandidateNumber=" << candidateNumber
3266 << "Iteration=" << iter
68f9b6bd 3267 << "S0.=" << &cseed[0]
3268 << "S1.=" << &cseed[1]
3269 << "S2.=" << &cseed[2]
3270 << "S3.=" << &cseed[3]
3271 << "S4.=" << &cseed[4]
3272 << "S5.=" << &cseed[5]
980d5a2a 3273 << "FitterT.=" << tiltedRieman
3274 << "\n";
41702fec 3275 }
3276 } // Loop: iter
68f9b6bd 3277
3278 // we are sure that at least 4 tracklets are OK !
3279 return kTRUE;
e4f2f73d 3280}
3281
eb38ed55 3282//_________________________________________________________________________
68f9b6bd 3283Double_t AliTRDtrackerV1::CalculateTrackLikelihood(Double_t *chi2){
41702fec 3284 //
3285 // Calculates the Track Likelihood value. This parameter serves as main quality criterion for
3286 // the track selection
3287 // The likelihood value containes:
3288 // - The chi2 values from the both fitters and the chi2 values in z-direction from a linear fit
3289 // - The Sum of the Parameter |slope_ref - slope_fit|/Sigma of the tracklets
3290 // For all Parameters an exponential dependency is used
3291 //
3292 // Parameters: - Array of tracklets (AliTRDseedV1) related to the track candidate
3293 // - Array of chi2 values:
3294 // * Non-Constrained Tilted Riemann fit
3295 // * Vertex-Constrained Tilted Riemann fit
3296 // * z-Direction from Linear fit
3297 // Output: - The calculated track likelihood
3298 //
3299 // debug level 2
3300 //
41702fec 3301
68f9b6bd 3302 // Non-constrained Tilted Riemann
3303 Double_t likeChi2TR = TMath::Exp(-chi2[0] * 0.0078);
3304 // Constrained Tilted Riemann
3305 Double_t likeChi2TC(1.);
3306 if(chi2[1]>0.){
3307 likeChi2TC = TMath::Exp(-chi2[1] * 0.677);
3308 Double_t r = likeChi2TC/likeChi2TR;
3309 if(r>1.e2){;} // -> a primary track use TC
3310 else if(r<1.e2) // -> a secondary track use TR
3311 likeChi2TC =1.;
3312 else{;} // -> test not conclusive
3313 }
3314 // Chi2 only on Z direction
3315 Double_t likeChi2Z = TMath::Exp(-chi2[2] * 0.14);
3316 // Chi2 angular resolution
3317 Double_t likeChi2Phi= TMath::Exp(-chi2[3] * 3.23);
3318
3319 Double_t trackLikelihood = likeChi2Z * likeChi2TR * likeChi2TC * likeChi2Phi;
3320
3321 AliDebug(2, Form("Likelihood [%e]\n"
3322 " Rieman : chi2[%f] likelihood[%6.2e]\n"
3323 " Vertex : chi2[%f] likelihood[%6.2e]\n"
3324 " Z : chi2[%f] likelihood[%6.2e]\n"
3325 " Phi : chi2[%f] likelihood[%6.2e]"
3326 , trackLikelihood
3327 , chi2[0], likeChi2TR
3328 , chi2[1], likeChi2TC
3329 , chi2[2], likeChi2Z
3330 , chi2[3], likeChi2Phi
3331 ));
41702fec 3332
d0177bb6 3333 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())||AliTRDReconstructor::GetStreamLevel()>=2){
41702fec 3334 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3335 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
a2fbb6ec 3336 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3337 cstreamer << "CalculateTrackLikelihood0"
3338 << "EventNumber=" << eventNumber
3339 << "CandidateNumber=" << candidateNumber
3340 << "LikeChi2Z=" << likeChi2Z
3341 << "LikeChi2TR=" << likeChi2TR
3342 << "LikeChi2TC=" << likeChi2TC
f29f13a6 3343 << "LikeChi2Phi=" << likeChi2Phi
41702fec 3344 << "TrackLikelihood=" << trackLikelihood
3345 << "\n";
3346 }
6e39bde4 3347
41702fec 3348 return trackLikelihood;
e4f2f73d 3349}
3350
3351//____________________________________________________________________
91834b8d 3352Double_t AliTRDtrackerV1::CookLikelihood(AliTRDseedV1 *cseed, Int_t planes[4])
e4f2f73d 3353{
41702fec 3354 //
3355 // Calculate the probability of this track candidate.
3356 //
3357 // Parameters :
3358 // cseeds : array of candidate tracklets
3359 // planes : array of seeding planes (see seeding configuration)
3360 // chi2 : chi2 values (on the Z and Y direction) from the rieman fit of the track.
3361 //
3362 // Output :
3363 // likelihood value
3364 //
3365 // Detailed description
3366 //
3367 // The track quality is estimated based on the following 4 criteria:
3368 // 1. precision of the rieman fit on the Y direction (likea)
3369 // 2. chi2 on the Y direction (likechi2y)
3370 // 3. chi2 on the Z direction (likechi2z)
3371 // 4. number of attached clusters compared to a reference value
3372 // (see AliTRDrecoParam::fkFindable) (likeN)
3373 //
3374 // The distributions for each type of probabilities are given below as of
3375 // (date). They have to be checked to assure consistency of estimation.
3376 //
3377
3378 // ratio of the total number of clusters/track which are expected to be found by the tracker.
91834b8d 3379 Double_t chi2y = GetChi2Y(&cseed[0]);
3380 Double_t chi2z = GetChi2Z(&cseed[0]);
3381
8ae98148 3382 Float_t nclusters = 0.;
41702fec 3383 Double_t sumda = 0.;
3384 for(UChar_t ilayer = 0; ilayer < 4; ilayer++){
3385 Int_t jlayer = planes[ilayer];
3386 nclusters += cseed[jlayer].GetN2();
e3cf3d02 3387 sumda += TMath::Abs(cseed[jlayer].GetYfit(1) - cseed[jlayer].GetYref(1));
41702fec 3388 }
8ae98148 3389 nclusters *= .25;
3390
9e85cb05 3391 Double_t likea = TMath::Exp(-sumda * fkRecoParam->GetPhiSlope());
41702fec 3392 Double_t likechi2y = 0.0000000001;
9e85cb05 3393 if (fkReconstructor->IsCosmic() || chi2y < fkRecoParam->GetChi2YCut()) likechi2y += TMath::Exp(-TMath::Sqrt(chi2y) * fkRecoParam->GetChi2YSlope());
3394 Double_t likechi2z = TMath::Exp(-chi2z * fkRecoParam->GetChi2ZSlope());
3395 Double_t likeN = TMath::Exp(-(fkRecoParam->GetNMeanClusters() - nclusters) / fkRecoParam->GetNSigmaClusters());
41702fec 3396 Double_t like = likea * likechi2y * likechi2z * likeN;
3397
d0177bb6 3398 if((fkRecoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 2 && fkReconstructor->IsDebugStreaming())||AliTRDReconstructor::GetStreamLevel()>=2){
41702fec 3399 Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
3400 Int_t candidateNumber = AliTRDtrackerDebug::GetCandidateNumber();
4d6aee34 3401 Int_t nTracklets = 0; Float_t meanNcls = 0;
91834b8d 3402 for(Int_t iseed=0; iseed < kNPlanes; iseed++){
3403 if(!cseed[iseed].IsOK()) continue;
3404 nTracklets++;
4d6aee34 3405 meanNcls += cseed[iseed].GetN2();
91834b8d 3406 }
4d6aee34 3407 if(nTracklets) meanNcls /= nTracklets;
41702fec 3408 // The Debug Stream contains the seed
a2fbb6ec 3409 TTreeSRedirector &cstreamer = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
41702fec 3410 cstreamer << "CookLikelihood"
3411 << "EventNumber=" << eventNumber
3412 << "CandidateNumber=" << candidateNumber
3413 << "tracklet0.=" << &cseed[0]
3414 << "tracklet1.=" << &cseed[1]
3415 << "tracklet2.=" << &cseed[2]
3416 << "tracklet3.=" << &cseed[3]
3417 << "tracklet4.=" << &cseed[4]
3418 << "tracklet5.=" << &cseed[5]
3419 << "sumda=" << sumda
91834b8d 3420 << "chi2y=" << chi2y
3421 << "chi2z=" << chi2z
41702fec 3422 << "likea=" << likea
3423 << "likechi2y=" << likechi2y
3424 << "likechi2z=" << likechi2z
3425 << "nclusters=" << nclusters
3426 << "likeN=" << likeN
3427 << "like=" << like
4d6aee34 3428 << "meanncls=" << meanNcls
41702fec 3429 << "\n";
3430 }
3431
3432 return like;
e4f2f73d 3433}
3434
e4f2f73d 3435//____________________________________________________________________
0906e73e 3436void AliTRDtrackerV1::GetSeedingConfig(Int_t iconfig, Int_t planes[4])
e4f2f73d 3437{
41702fec 3438 //
3439 // Map seeding configurations to detector planes.
3440 //
3441 // Parameters :
3442 // iconfig : configuration index
3443 // planes : member planes of this configuration. On input empty.
3444 //
3445 // Output :
3446 // planes : contains the planes which are defining the configuration
3447 //
3448 // Detailed description
3449 //
3450 // Here is the list of seeding planes configurations together with
3451 // their topological classification:
3452 //
3453 // 0 - 5432 TQ 0
3454 // 1 - 4321 TQ 0
3455 // 2 - 3210 TQ 0
3456 // 3 - 5321 TQ 1
3457 // 4 - 4210 TQ 1
3458 // 5 - 5431 TQ 1
3459 // 6 - 4320 TQ 1
3460 // 7 - 5430 TQ 2
3461 // 8 - 5210 TQ 2
3462 // 9 - 5421 TQ 3
3463 // 10 - 4310 TQ 3
3464 // 11 - 5410 TQ 4
3465 // 12 - 5420 TQ 5
3466 // 13 - 5320 TQ 5
3467 // 14 - 5310 TQ 5
3468 //
3469 // The topologic quality is modeled as follows:
3470 // 1. The general model is define by the equation:
3471 // p(conf) = exp(-conf/2)
3472 // 2. According to the topologic classification, configurations from the same
3473 // class are assigned the agerage value over the model values.
3474 // 3. Quality values are normalized.
3475 //
3476 // The topologic quality distribution as function of configuration is given below:
3477 //Begin_Html
3478 // <img src="gif/topologicQA.gif">
3479 //End_Html
3480 //
3481
3482 switch(iconfig){
3483 case 0: // 5432 TQ 0
3484 planes[0] = 2;
3485 planes[1] = 3;
3486 planes[2] = 4;
3487 planes[3] = 5;
3488 break;
3489 case 1: // 4321 TQ 0
3490 planes[0] = 1;
3491 planes[1] = 2;
3492 planes[2] = 3;
3493 planes[3] = 4;
3494 break;
3495 case 2: // 3210 TQ 0
3496 planes[0] = 0;
3497 planes[1] = 1;
3498 planes[2] = 2;
3499 planes[3] = 3;
3500 break;
3501 case 3: // 5321 TQ 1
3502 planes[0] = 1;
3503 planes[1] = 2;
3504 planes[2] = 3;
3505 planes[3] = 5;
3506 break;
3507 case 4: // 4210 TQ 1
3508 planes[0] = 0;
3509 planes[1] = 1;
3510 planes[2] = 2;
3511 planes[3] = 4;
3512 break;
3513 case 5: // 5431 TQ 1
3514 planes[0] = 1;
3515 planes[1] = 3;
3516 planes[2] = 4;
3517 planes[3] = 5;
3518 break;
3519 case 6: // 4320 TQ 1
3520 planes[0] = 0;
3521 planes[1] = 2;
3522 planes[2] = 3;
3523 planes[3] = 4;
3524 break;
3525 case 7: // 5430 TQ 2
3526 planes[0] = 0;
3527 planes[1] = 3;
3528 planes[2] = 4;
3529 planes[3] = 5;
3530 break;
3531 case 8: // 5210 TQ 2
3532 planes[0] = 0;
3533 planes[1] = 1;
3534 planes[2] = 2;
3535 planes[3] = 5;
3536 break;
3537 case 9: // 5421 TQ 3
3538 planes[0] = 1;
3539 planes[1] = 2;
3540 planes[2] = 4;
3541 planes[3] = 5;
3542 break;
3543 case 10: // 4310 TQ 3
3544 planes[0] = 0;
3545 planes[1] = 1;
3546 planes[2] = 3;
3547 planes[3] = 4;
3548 break;
3549 case 11: // 5410 TQ 4
3550 planes[0] = 0;
3551 planes[1] = 1;
3552 planes[2] = 4;
3553 planes[3] = 5;
3554 break;
3555 case 12: // 5420 TQ 5
3556 planes[0] = 0;
3557 planes[1] = 2;
3558 planes[2] = 4;
3559 planes[3] = 5;
3560 break;
3561 case 13: // 5320 TQ 5
3562 planes[0] = 0;
3563 planes[1] = 2;
3564 planes[2] = 3;
3565 planes[3] = 5;
3566 break;
3567 case 14: // 5310 TQ 5
3568 planes[0] = 0;
3569 planes[1] = 1;
3570 planes[2] = 3;
3571 planes[3] = 5;
3572 break;
3573 }
e4f2f73d 3574}
3575
3576//____________________________________________________________________
0906e73e 3577void AliTRDtrackerV1::GetExtrapolationConfig(Int_t iconfig, Int_t planes[2])
e4f2f73d 3578{
41702fec 3579 //
3580 // Returns the extrapolation planes for a seeding configuration.
3581 //
3582 // Parameters :
3583 // iconfig : configuration index
3584 // planes : planes which are not in this configuration. On input empty.
3585 //
3586 // Output :
3587 // planes : contains the planes which are not in the configuration
3588 //
3589 // Detailed description
3590 //
3591
3592 switch(iconfig){
3593 case 0: // 5432 TQ 0
3594 planes[0] = 1;
3595 planes[1] = 0;
3596 break;
3597 case 1: // 4321 TQ 0
3598 planes[0] = 5;
3599 planes[1] = 0;
3600 break;
3601 case 2: // 3210 TQ 0
3602 planes[0] = 4;
3603 planes[1] = 5;
3604 break;
3605 case 3: // 5321 TQ 1
3606 planes[0] = 4;
3607 planes[1] = 0;
3608 break;
3609 case 4: // 4210 TQ 1
3610 planes[0] = 5;
3611 planes[1] = 3;
3612 break;
3613 case 5: // 5431 TQ 1
3614 planes[0] = 2;
3615 planes[1] = 0;
3616 break;
3617 case 6: // 4320 TQ 1
3618 planes[0] = 5;
3619 planes[1] = 1;
3620 break;
3621 case 7: // 5430 TQ 2
3622 planes[0] = 2;
3623 planes[1] = 1;
3624 break;
3625 case 8: // 5210 TQ 2
3626 planes[0] = 4;
3627 planes[1] = 3;
3628 break;
3629 case 9: // 5421 TQ 3
3630 planes[0] = 3;
3631 planes[1] = 0;
3632 break;
3633 case 10: // 4310 TQ 3
3634 planes[0] = 5;
3635 planes[1] = 2;
3636 break;
3637 case 11: // 5410 TQ 4
3638 planes[0] = 3;
3639 planes[1] = 2;
3640 break;
3641 case 12: // 5420 TQ 5
3642 planes[0] = 3;
3643 planes[1] = 1;
3644 break;
3645 case 13: // 5320 TQ 5
3646 planes[0] = 4;
3647 planes[1] = 1;
3648 break;
3649 case 14: // 5310 TQ 5
3650 planes[0] = 4;
3651 planes[1] = 2;
3652 break;
3653 }
e4f2f73d 3654}
eb38ed55 3655
3656//____________________________________________________________________
3657AliCluster* AliTRDtrackerV1::GetCluster(Int_t idx) const
3658{
971a356b 3659 if(!fClusters) return NULL;
41702fec 3660 Int_t ncls = fClusters->GetEntriesFast();
4d6aee34 3661 return idx >= 0 && idx < ncls ? (AliCluster*)fClusters->UncheckedAt(idx) : NULL;
eb38ed55 3662}
3663
3b57a3f7 3664//____________________________________________________________________
3665AliTRDseedV1* AliTRDtrackerV1::GetTracklet(Int_t idx) const
3666{
971a356b 3667 if(!fTracklets) return NULL;
41702fec 3668 Int_t ntrklt = fTracklets->GetEntriesFast();
4d6aee34 3669 return idx >= 0 && idx < ntrklt ? (AliTRDseedV1*)fTracklets->UncheckedAt(idx) : NULL;
3b57a3f7 3670}
3671
3672//____________________________________________________________________
3673AliKalmanTrack* AliTRDtrackerV1::GetTrack(Int_t idx) const
3674{
971a356b 3675 if(!fTracks) return NULL;
41702fec 3676 Int_t ntrk = fTracks->GetEntriesFast();
4d6aee34 3677 return idx >= 0 && idx < ntrk ? (AliKalmanTrack*)fTracks->UncheckedAt(idx) : NULL;
3b57a3f7 3678}
3679
6e39bde4 3680
eb38ed55 3681
fac58f00 3682// //_____________________________________________________________________________
3683// Int_t AliTRDtrackerV1::Freq(Int_t n, const Int_t *inlist
3684// , Int_t *outlist, Bool_t down)
3685// {
3686// //
3687// // Sort eleements according occurancy
3688// // The size of output array has is 2*n
3689// //
3690//
3691// if (n <= 0) {
3692// return 0;
3693// }
3694//
3695// Int_t *sindexS = new Int_t[n]; // Temporary array for sorting
3696// Int_t *sindexF = new Int_t[2*n];
3697// for (Int_t i = 0; i < n; i++) {
3698// sindexF[i] = 0;
3699// }
3700//
3701// TMath::Sort(n,inlist,sindexS,down);
3702//
3703// Int_t last = inlist[sindexS[0]];
3704// Int_t val = last;
3705// sindexF[0] = 1;
3706// sindexF[0+n] = last;
3707// Int_t countPos = 0;
3708//
3709// // Find frequency
3710// for (Int_t i = 1; i < n; i++) {
3711// val = inlist[sindexS[i]];
3712// if (last == val) {
3713// sindexF[countPos]++;
3714// }
3715// else {
3716// countPos++;
3717// sindexF[countPos+n] = val;
3718// sindexF[countPos]++;
3719// last = val;
3720// }
3721// }
3722// if (last == val) {
3723// countPos++;
3724// }
3725//
3726// // Sort according frequency
3727// TMath::Sort(countPos,sindexF,sindexS,kTRUE);
3728//
3729// for (Int_t i = 0; i < countPos; i++) {
3730// outlist[2*i ] = sindexF[sindexS[i]+n];
3731// outlist[2*i+1] = sindexF[sindexS[i]];
3732// }
3733//
3734// delete [] sindexS;
3735// delete [] sindexF;
3736//
3737// return countPos;
3738//
3739// }
bb56afff 3740
06b32d95 3741
d611c74f 3742//____________________________________________________________________
3743void AliTRDtrackerV1::ResetSeedTB()
3744{
3745// reset buffer for seeding time bin layers. If the time bin
3746// layers are not allocated this function allocates them
3747
3748 for(Int_t isl=0; isl<kNSeedPlanes; isl++){
3749 if(!fSeedTB[isl]) fSeedTB[isl] = new AliTRDchamberTimeBin();
3750 else fSeedTB[isl]->Clear();
3751 }
3752}
3753
e3cf3d02 3754
3755//_____________________________________________________________________________
4d6aee34 3756Float_t AliTRDtrackerV1::GetChi2Y(const AliTRDseedV1 * const tracklets) const
e3cf3d02 3757{
3758 // Calculates normalized chi2 in y-direction
3759 // chi2 = Sum chi2 / n_tracklets
3760
3761 Double_t chi2 = 0.; Int_t n = 0;
3762 for(Int_t ipl = kNPlanes; ipl--;){
3763 if(!tracklets[ipl].IsOK()) continue;
3764 chi2 += tracklets[ipl].GetChi2Y();
3765 n++;
3766 }
3767 return n ? chi2/n : 0.;
3768}
3769
bb56afff 3770//_____________________________________________________________________________
4d6aee34 3771Float_t AliTRDtrackerV1::GetChi2Z(const AliTRDseedV1 *const tracklets) const
bb56afff 3772{
91834b8d 3773 // Calculates normalized chi2 in z-direction
e3cf3d02 3774 // chi2 = Sum chi2 / n_tracklets
41702fec 3775
e3cf3d02 3776 Double_t chi2 = 0; Int_t n = 0;
3777 for(Int_t ipl = kNPlanes; ipl--;){
41702fec 3778 if(!tracklets[ipl].IsOK()) continue;
e3cf3d02 3779 chi2 += tracklets[ipl].GetChi2Z();
3780 n++;
41702fec 3781 }
e3cf3d02 3782 return n ? chi2/n : 0.;
bb56afff 3783}
8acca6a3 3784
68f9b6bd 3785//_____________________________________________________________________________
3786Float_t AliTRDtrackerV1::GetChi2Phi(const AliTRDseedV1 *const tracklets) const
3787{
3788 // Calculates normalized chi2 for angular resolution
3789 // chi2 = Sum chi2 / n_tracklets
3790
3791 Double_t chi2 = 0; Int_t n = 0;
3792 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
3793 if(!tracklets[iLayer].IsOK()) continue;
3794 chi2 += tracklets[iLayer].GetChi2Phi();
3795 n++;
3796 }
3797 return n ? chi2/n: 0.;
3798}
3799
6e39bde4 3800//____________________________________________________________________
4d6aee34 3801Float_t AliTRDtrackerV1::CalculateReferenceX(const AliTRDseedV1 *const tracklets){
6e39bde4 3802 //
3803 // Calculates the reference x-position for the tilted Rieman fit defined as middle
3804 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
3805 // are taken into account
3806 //
3807 // Parameters: - Array of tracklets(AliTRDseedV1)
3808 //
3809 // Output: - The reference x-position(Float_t)
3810 // Only kept for compatibility with the old code
3811 //
3812 Int_t nDistances = 0;
3813 Float_t meanDistance = 0.;
3814 Int_t startIndex = 5;
3815 for(Int_t il =5; il > 0; il--){
3816 if(tracklets[il].IsOK() && tracklets[il -1].IsOK()){
3817 Float_t xdiff = tracklets[il].GetX0() - tracklets[il -1].GetX0();
3818 meanDistance += xdiff;
3819 nDistances++;
3820 }
3821 if(tracklets[il].IsOK()) startIndex = il;
3822 }
3823 if(tracklets[0].IsOK()) startIndex = 0;
3824 if(!nDistances){
3825 // We should normally never get here
3826 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
3827 Int_t iok = 0, idiff = 0;
3828 // This attempt is worse and should be avoided:
3829 // check for two chambers which are OK and repeat this without taking the mean value
3830 // Strategy avoids a division by 0;
3831 for(Int_t il = 5; il >= 0; il--){
3832 if(tracklets[il].IsOK()){
3833 xpos[iok] = tracklets[il].GetX0();
3834 iok++;
3835 startIndex = il;
3836 }
3837 if(iok) idiff++; // to get the right difference;
3838 if(iok > 1) break;
3839 }
3840 if(iok > 1){
3841 meanDistance = (xpos[0] - xpos[1])/idiff;
3842 }
3843 else{
3844 // we have do not even have 2 layers which are OK? The we do not need to fit at all
3845 return 331.;
3846 }
3847 }
3848 else{
3849 meanDistance /= nDistances;
3850 }
3851 return tracklets[startIndex].GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
3852}
3853
3854//_____________________________________________________________________________
4d6aee34 3855Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
6e39bde4 3856 //
3857 // Track Fitter Function using the new class implementation of
3858 // the Rieman fit
3859 //
3860 AliTRDtrackFitterRieman fitter;
3861 fitter.SetRiemanFitter(GetTiltedRiemanFitter());
3862 fitter.Reset();
3863 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) fitter.SetTracklet(il, &tracklets[il]);
3864 Double_t chi2 = fitter.Eval();
3865 // Update the tracklets
3866 Double_t cov[15]; Double_t x0;
3867 memset(cov, 0, sizeof(Double_t) * 15);
3868 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++){
3869 x0 = tracklets[il].GetX0();
3870 tracklets[il].SetYref(0, fitter.GetYat(x0));
3871 tracklets[il].SetZref(0, fitter.GetZat(x0));
3872 tracklets[il].SetYref(1, fitter.GetDyDxAt(x0));
3873 tracklets[il].SetZref(1, fitter.GetDzDx());
3874 tracklets[il].SetC(fitter.GetCurvature());
3875 fitter.GetCovAt(x0, cov);
3876 tracklets[il].SetCovRef(cov);
3877 tracklets[il].SetChi2(chi2);
3878 }
3879 return chi2;
3880}
3881
68f9b6bd 3882//____________________________________________________________________
3883void AliTRDtrackerV1::UnsetTrackletsTrack(const AliTRDtrackV1 * const track)
3884{
d8069611 3885// Remove tracklets from tracker list attached to "track"
68f9b6bd 3886 Int_t idx(-1);
3887 for(Int_t il(0); il<kNPlanes; il++){
3888 if((idx = track->GetTrackletIndex(il)) < 0) continue;
3889 delete (fTracklets->RemoveAt(idx));
3890 }
3891}
3892
3893
8acca6a3 3894///////////////////////////////////////////////////////
3895// //
3896// Resources of class AliTRDLeastSquare //
3897// //
3898///////////////////////////////////////////////////////
3899
3900//_____________________________________________________________________________
3901AliTRDtrackerV1::AliTRDLeastSquare::AliTRDLeastSquare(){
903326c1 3902//
3903// Constructor of the nested class AliTRDtrackFitterLeastSquare
3904//
3905// Fast solving linear regresion in 2D
0323ef61 3906// y=a + bx
903326c1 3907// The data members have the following meaning
0323ef61 3908// fParams[0] : a
3909// fParams[1] : b
903326c1 3910//
3911// fSums[0] : S
3912// fSums[1] : Sx
3913// fSums[2] : Sy
3914// fSums[3] : Sxy
3915// fSums[4] : Sxx
3916// fSums[5] : Syy
3917//
0323ef61 3918// fCovarianceMatrix[0] : s2a
3919// fCovarianceMatrix[1] : s2b
903326c1 3920// fCovarianceMatrix[2] : cov(ab)
3921
41702fec 3922 memset(fParams, 0, sizeof(Double_t) * 2);
341512a4 3923 memset(fSums, 0, sizeof(Double_t) * 6);
41702fec 3924 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
8acca6a3 3925
3926}
3927
3928//_____________________________________________________________________________
4d6aee34 3929void AliTRDtrackerV1::AliTRDLeastSquare::AddPoint(const Double_t *const x, Double_t y, Double_t sigmaY){
41702fec 3930 //
3931 // Adding Point to the fitter
3932 //
5f1ae1e7 3933
2ed81ab2 3934 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3935 weight *= weight;
4d6aee34 3936 const Double_t &xpt = *x;
41702fec 3937 // printf("Adding point x = %f, y = %f, sigma = %f\n", xpt, y, sigmaY);
3938 fSums[0] += weight;
3939 fSums[1] += weight * xpt;
3940 fSums[2] += weight * y;
3941 fSums[3] += weight * xpt * y;
3942 fSums[4] += weight * xpt * xpt;
3943 fSums[5] += weight * y * y;
8acca6a3 3944}
3945
3946//_____________________________________________________________________________
4d6aee34 3947void AliTRDtrackerV1::AliTRDLeastSquare::RemovePoint(const Double_t *const x, Double_t y, Double_t sigmaY){
41702fec 3948 //
3949 // Remove Point from the sample
3950 //
5f1ae1e7 3951
2ed81ab2 3952 Double_t weight = 1/(sigmaY > 1e-9 ? sigmaY : 1e-9);
3953 weight *= weight;
4d6aee34 3954 const Double_t &xpt = *x;
41702fec 3955 fSums[0] -= weight;
3956 fSums[1] -= weight * xpt;
3957 fSums[2] -= weight * y;
3958 fSums[3] -= weight * xpt * y;
3959 fSums[4] -= weight * xpt * xpt;
3960 fSums[5] -= weight * y * y;
8acca6a3 3961}
3962
3963//_____________________________________________________________________________
903326c1 3964Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
41702fec 3965 //
3966 // Evaluation of the fit:
3967 // Calculation of the parameters
3968 // Calculation of the covariance matrix
3969 //
3970
903326c1 3971 Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
d8069611 3972 if(TMath::Abs(det)<1.e-30) return kFALSE;
aec26713 3973
41702fec 3974 // for(Int_t isum = 0; isum < 5; isum++)
3975 // printf("fSums[%d] = %f\n", isum, fSums[isum]);
3976 // printf("denominator = %f\n", denominator);
903326c1 3977 fParams[0] = (fSums[2] * fSums[4] - fSums[1] * fSums[3])/det;
3978 fParams[1] = (fSums[0] * fSums[3] - fSums[1] * fSums[2])/det;
41702fec 3979 // printf("fParams[0] = %f, fParams[1] = %f\n", fParams[0], fParams[1]);
3980
3981 // Covariance matrix
0323ef61 3982 Double_t den = fSums[0]*fSums[4] - fSums[1]*fSums[1];
3983 fCovarianceMatrix[0] = fSums[4] / den;
3984 fCovarianceMatrix[1] = fSums[0] / den;
3985 fCovarianceMatrix[2] = -fSums[1] / den;
3986/* fCovarianceMatrix[0] = fSums[4] / fSums[0] - fSums[1] * fSums[1] / (fSums[0] * fSums[0]);
2ed81ab2 3987 fCovarianceMatrix[1] = fSums[5] / fSums[0] - fSums[2] * fSums[2] / (fSums[0] * fSums[0]);
0323ef61 3988 fCovarianceMatrix[2] = fSums[3] / fSums[0] - fSums[1] * fSums[2] / (fSums[0] * fSums[0]);*/
3989
3990
3991
903326c1 3992 return kTRUE;
8acca6a3 3993}
3994
46b6abd7 3995//_____________________________________________________________________________
4d6aee34 3996Double_t AliTRDtrackerV1::AliTRDLeastSquare::GetFunctionValue(const Double_t *const xpos) const {
41702fec 3997 //
3998 // Returns the Function value of the fitted function at a given x-position
3999 //
4000 return fParams[0] + fParams[1] * (*xpos);
46b6abd7 4001}
4002
4003//_____________________________________________________________________________
4004void AliTRDtrackerV1::AliTRDLeastSquare::GetCovarianceMatrix(Double_t *storage) const {
41702fec 4005 //
4006 // Copies the values of the covariance matrix into the storage
4007 //
4008 memcpy(storage, fCovarianceMatrix, sizeof(Double_t) * 3);
46b6abd7 4009}
4010
6e39bde4 4011//_____________________________________________________________________________
4012void AliTRDtrackerV1::AliTRDLeastSquare::Reset(){
4013 //
4014 // Reset the fitter
4015 //
4016 memset(fParams, 0, sizeof(Double_t) * 2);
4017 memset(fCovarianceMatrix, 0, sizeof(Double_t) * 3);
4018 memset(fSums, 0, sizeof(Double_t) * 6);
4019}
4020
4021///////////////////////////////////////////////////////
4022// //
4023// Resources of class AliTRDtrackFitterRieman //
4024// //
4025///////////////////////////////////////////////////////
4026
4027//_____________________________________________________________________________
4028AliTRDtrackerV1::AliTRDtrackFitterRieman::AliTRDtrackFitterRieman():
4029 fTrackFitter(NULL),
4030 fZfitter(NULL),
4031 fCovarPolY(NULL),
4032 fCovarPolZ(NULL),
4033 fXref(0.),
4034 fSysClusterError(0.)
4035{
4036 //
4037 // Default constructor
4038 //
4039 fZfitter = new AliTRDLeastSquare;
4040 fCovarPolY = new TMatrixD(3,3);
4041 fCovarPolZ = new TMatrixD(2,2);
4042 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * 6);
4043 memset(fParameters, 0, sizeof(Double_t) * 5);
4044 memset(fSumPolY, 0, sizeof(Double_t) * 5);
4045 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
4046}
4047
4048//_____________________________________________________________________________
4049AliTRDtrackerV1::AliTRDtrackFitterRieman::~AliTRDtrackFitterRieman(){
4050 //
4051 // Destructor
4052 //
4053 if(fZfitter) delete fZfitter;
4054 if(fCovarPolY) delete fCovarPolY;
4055 if(fCovarPolZ) delete fCovarPolZ;
4056}
4057
4058//_____________________________________________________________________________
4059void AliTRDtrackerV1::AliTRDtrackFitterRieman::Reset(){
4060 //
4061 // Reset the Fitter
4062 //
4063 if(fTrackFitter){
4064 fTrackFitter->StoreData(kTRUE);
4065 fTrackFitter->ClearPoints();
4066 }
4067 if(fZfitter){
4068 fZfitter->Reset();
4069 }
4070 fXref = 0.;
4071 memset(fTracklets, 0, sizeof(AliTRDseedV1 *) * AliTRDgeometry::kNlayer);
4072 memset(fParameters, 0, sizeof(Double_t) * 5);
4073 memset(fSumPolY, 0, sizeof(Double_t) * 5);
4074 memset(fSumPolZ, 0, sizeof(Double_t) * 2);
4075 for(Int_t irow = 0; irow < fCovarPolY->GetNrows(); irow++)
4076 for(Int_t icol = 0; icol < fCovarPolY->GetNcols(); icol++){
4077 (*fCovarPolY)(irow, icol) = 0.;
4078 if(irow < 2 && icol < 2)
4079 (*fCovarPolZ)(irow, icol) = 0.;
4080 }
4081}
4082
4083//_____________________________________________________________________________
4084void AliTRDtrackerV1::AliTRDtrackFitterRieman::SetTracklet(Int_t itr, AliTRDseedV1 *tracklet){
4085 //
4086 // Add tracklet into the fitter
4087 //
4088 if(itr >= AliTRDgeometry::kNlayer) return;
4089 fTracklets[itr] = tracklet;
4090}
4091
4092//_____________________________________________________________________________
4093Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::Eval(){
4094 //
4095 // Perform the fit
4096 // 1. Apply linear transformation and store points in the fitter
4097 // 2. Evaluate the fit
4098 // 3. Check if the result of the fit in z-direction is reasonable
4099 // if not
4100 // 3a. Fix the parameters 3 and 4 with the results of a simple least
4101 // square fit
4102 // 3b. Redo the fit with the fixed parameters
4103 // 4. Store fit results (parameters and errors)
4104 //
4105 if(!fTrackFitter){
4106 return 1e10;
4107 }
4108 fXref = CalculateReferenceX();
4109 for(Int_t il = 0; il < AliTRDgeometry::kNlayer; il++) UpdateFitters(fTracklets[il]);
4110 if(!fTrackFitter->GetNpoints()) return 1e10;
4111 // perform the fit
4112 fTrackFitter->Eval();
4113 fZfitter->Eval();
4114 fParameters[3] = fTrackFitter->GetParameter(3);
4115 fParameters[4] = fTrackFitter->GetParameter(4);
4116 if(!CheckAcceptable(fParameters[3], fParameters[4])) {
4117 fTrackFitter->FixParameter(3, fZfitter->GetFunctionValue(&fXref));
4118 fTrackFitter->FixParameter(4, fZfitter->GetFunctionParameter(1));
4119 fTrackFitter->Eval();
4120 fTrackFitter->ReleaseParameter(3);
4121 fTrackFitter->ReleaseParameter(4);
4122 fParameters[3] = fTrackFitter->GetParameter(3);
4123 fParameters[4] = fTrackFitter->GetParameter(4);
4124 }
4125 // Update the Fit Parameters and the errors
4126 fParameters[0] = fTrackFitter->GetParameter(0);
4127 fParameters[1] = fTrackFitter->GetParameter(1);
4128 fParameters[2] = fTrackFitter->GetParameter(2);
4129
4130 // Prepare Covariance estimation
4131 (*fCovarPolY)(0,0) = fSumPolY[0]; (*fCovarPolY)(1,1) = fSumPolY[2]; (*fCovarPolY)(2,2) = fSumPolY[4];
4132 (*fCovarPolY)(1,0) = (*fCovarPolY)(0,1) = fSumPolY[1];
4133 (*fCovarPolY)(2,0) = (*fCovarPolY)(0,2) = fSumPolY[2];
4134 (*fCovarPolY)(2,1) = (*fCovarPolY)(1,2) = fSumPolY[3];
4135 fCovarPolY->Invert();
4136 (*fCovarPolZ)(0,0) = fSumPolZ[0]; (*fCovarPolZ)(1,1) = fSumPolZ[2];
4137 (*fCovarPolZ)(1,0) = (*fCovarPolZ)(0,1) = fSumPolZ[1];
4138 fCovarPolZ->Invert();
4139 return fTrackFitter->GetChisquare() / fTrackFitter->GetNpoints();
4140}
4141
4142//_____________________________________________________________________________
33ab3872 4143void AliTRDtrackerV1::AliTRDtrackFitterRieman::UpdateFitters(const AliTRDseedV1 * const tracklet){
6e39bde4 4144 //
4145 // Does the transformations and updates the fitters
4146 // The following transformation is applied
4147 //
4148 AliTRDcluster *cl = NULL;
4149 Double_t x, y, z, dx, t, w, we, yerr, zerr;
4150 Double_t uvt[4];
4151 if(!tracklet || !tracklet->IsOK()) return;
4152 Double_t tilt = tracklet->GetTilt();
4153 for(Int_t itb = 0; itb < AliTRDseedV1::kNclusters; itb++){
4154 if(!(cl = tracklet->GetClusters(itb))) continue;
4155 if(!cl->IsInChamber()) continue;
4156 if (!tracklet->IsUsable(itb)) continue;
4157 x = cl->GetX();
4158 y = cl->GetY();
4159 z = cl->GetZ();
4160 dx = x - fXref;
4161 // Transformation
4162 t = 1./(x*x + y*y);
4163 uvt[0] = 2. * x * t;
4164 uvt[1] = t;
4165 uvt[2] = 2. * tilt * t;
4166 uvt[3] = 2. * tilt * dx * t;
4167 w = 2. * (y + tilt*z) * t;
4168 // error definition changes for the different calls
4169 we = 2. * t;
4170 we *= TMath::Sqrt(cl->GetSigmaY2()+tilt*tilt*cl->GetSigmaZ2());
4171 // Update sums for error calculation
4172 yerr = 1./(TMath::Sqrt(cl->GetSigmaY2()) + fSysClusterError);
4173 yerr *= yerr;
4174 zerr = 1./cl->GetSigmaZ2();
4175 for(Int_t ipol = 0; ipol < 5; ipol++){
4176 fSumPolY[ipol] += yerr;
4177 yerr *= x;
4178 if(ipol < 3){
4179 fSumPolZ[ipol] += zerr;
4180 zerr *= x;
4181 }
4182 }
4183 fTrackFitter->AddPoint(uvt, w, we);
4184 fZfitter->AddPoint(&x, z, static_cast<Double_t>(TMath::Sqrt(cl->GetSigmaZ2())));
4185 }
4186}
4187
4188//_____________________________________________________________________________
4189Bool_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CheckAcceptable(Double_t offset, Double_t slope){
4190 //
4191 // Check whether z-results are acceptable
4192 // Definition: Distance between tracklet fit and track fit has to be
4193 // less then half a padlength
4194 // Point of comparision is at the anode wire
4195 //
4196 Bool_t acceptablez = kTRUE;
4197 Double_t zref = 0.0;
4198 for (Int_t iLayer = 0; iLayer < kNPlanes; iLayer++) {
4199 if(!fTracklets[iLayer]->IsOK()) continue;
4200 zref = offset + slope * (fTracklets[iLayer]->GetX0() - fXref);
4201 if (TMath::Abs(fTracklets[iLayer]->GetZfit(0) - zref) > fTracklets[iLayer]->GetPadLength() * 0.5 + 1.0)
4202 acceptablez = kFALSE;
4203 }
4204 return acceptablez;
4205}
4206
4207//_____________________________________________________________________________
4208Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetYat(Double_t x) const {
4209 //
4210 // Calculate y position out of the track parameters
4211 // y: R^2 = (x - x0)^2 + (y - y0)^2
4212 // => y = y0 +/- Sqrt(R^2 - (x - x0)^2)
4213 // R = Sqrt() = 1/Curvature
4214 // => y = y0 +/- Sqrt(1/Curvature^2 - (x - x0)^2)
4215 //
4216 Double_t y = 0;
4217 Double_t disc = (x * fParameters[0] + fParameters[1]);
4218 disc = 1 - fParameters[0]*fParameters[2] + fParameters[1]*fParameters[1] - disc*disc;
4219 if (disc >= 0) {
4220 disc = TMath::Sqrt(disc);
4221 y = (1.0 - disc) / fParameters[0];
4222 }
4223 return y;
4224}
4225
4226//_____________________________________________________________________________
4227Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetZat(Double_t x) const {
4228 //
4229 // Return z position for a given x position
4230 // Simple linear function
4231 //
4232 return fParameters[3] + fParameters[4] * (x - fXref);
4233}
4234
4235//_____________________________________________________________________________
4236Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetDyDxAt(Double_t x) const {
4237 //
4238 // Calculate dydx at a given radial position out of the track parameters
4239 // dy: R^2 = (x - x0)^2 + (y - y0)^2
4240 // => y = +/- Sqrt(R^2 - (x - x0)^2) + y0
4241 // => dy/dx = (x - x0)/Sqrt(R^2 - (x - x0)^2)
4242 // Curvature: cr = 1/R = a/Sqrt(1 + b^2 - c*a)
4243 // => dy/dx = (x - x0)/(1/(cr^2) - (x - x0)^2)
4244 //
4245 Double_t x0 = -fParameters[1] / fParameters[0];
4246 Double_t curvature = GetCurvature();
4247 Double_t dy = 0;
4248 if (-fParameters[2] * fParameters[0] + fParameters[1] * fParameters[1] + 1 > 0) {
4249 if (1.0/(curvature * curvature) - (x - x0) * (x - x0) > 0.0) {
4250 Double_t yderiv = (x - x0) / TMath::Sqrt(1.0/(curvature * curvature) - (x - x0) * (x - x0));
4251 if (fParameters[0] < 0) yderiv *= -1.0;
4252 dy = yderiv;
4253 }
4254 }
4255 return dy;
4256}
4257
4258//_____________________________________________________________________________
4259Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCurvature() const {
4260 //
4261 // Calculate track curvature
4262 //
4263 //
4264 Double_t curvature = 1.0 + fParameters[1]*fParameters[1] - fParameters[2]*fParameters[0];
4265 if (curvature > 0.0)
4266 curvature = fParameters[0] / TMath::Sqrt(curvature);
4267 return curvature;
4268}
4269
4270//_____________________________________________________________________________
4271void AliTRDtrackerV1::AliTRDtrackFitterRieman::GetCovAt(Double_t x, Double_t *cov) const {
4272 //
4273 // Error Definition according to gauss error propagation
4274 //
4275 TMatrixD transform(3,3);
4276 transform(0,0) = transform(1,1) = transform(2,2) = 1;
4277 transform(0,1) = transform(1,2) = x;
4278 transform(0,2) = x*x;
4279 TMatrixD covariance(transform, TMatrixD::kMult, *fCovarPolY);
4280 covariance *= transform.T();
4281 cov[0] = covariance(0,0);
4282 TMatrixD transformZ(2,2);
4283 transformZ(0,0) = transformZ(1,1) = 1;
4284 transformZ(0,1) = x;
4285 TMatrixD covarZ(transformZ, TMatrixD::kMult, *fCovarPolZ);
4286 covarZ *= transformZ.T();
4287 cov[1] = covarZ(0,0);
4288 cov[2] = 0;
4289}
4290
4291//____________________________________________________________________
4292Double_t AliTRDtrackerV1::AliTRDtrackFitterRieman::CalculateReferenceX(){
4293 //
4294 // Calculates the reference x-position for the tilted Rieman fit defined as middle
4295 // of the stack (middle between layers 2 and 3). For the calculation all the tracklets
4296 // are taken into account
4297 //
4298 // Parameters: - Array of tracklets(AliTRDseedV1)
4299 //
4300 // Output: - The reference x-position(Float_t)
4301 //
4302 Int_t nDistances = 0;
4303 Float_t meanDistance = 0.;
4304 Int_t startIndex = 5;
4305 for(Int_t il =5; il > 0; il--){
4306 if(fTracklets[il]->IsOK() && fTracklets[il -1]->IsOK()){
4307 Float_t xdiff = fTracklets[il]->GetX0() - fTracklets[il -1]->GetX0();
4308 meanDistance += xdiff;
4309 nDistances++;
4310 }
4311 if(fTracklets[il]->IsOK()) startIndex = il;
4312 }
4313 if(fTracklets[0]->IsOK()) startIndex = 0;
4314 if(!nDistances){
4315 // We should normally never get here
4316 Float_t xpos[2]; memset(xpos, 0, sizeof(Float_t) * 2);
4317 Int_t iok = 0, idiff = 0;
4318 // This attempt is worse and should be avoided:
4319 // check for two chambers which are OK and repeat this without taking the mean value
4320 // Strategy avoids a division by 0;
4321 for(Int_t il = 5; il >= 0; il--){
4322 if(fTracklets[il]->IsOK()){
4323 xpos[iok] = fTracklets[il]->GetX0();
4324 iok++;
4325 startIndex = il;
4326 }
4327 if(iok) idiff++; // to get the right difference;
4328 if(iok > 1) break;
4329 }
4330 if(iok > 1){
4331 meanDistance = (xpos[0] - xpos[1])/idiff;
4332 }
4333 else{
4334 // we have do not even have 2 layers which are OK? The we do not need to fit at all
4335 return 331.;
4336 }
4337 }
4338 else{
4339 meanDistance /= nDistances;
4340 }
4341 return fTracklets[startIndex]->GetX0() + (2.5 - startIndex) * meanDistance - 0.5 * (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
4342}