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