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