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