e4f2f73d |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
3 | * * |
4 | * Author: The ALICE Off-line Project. * |
5 | * Contributors are mentioned in the code where appropriate. * |
6 | * * |
7 | * Permission to use, copy, modify and distribute this software and its * |
8 | * documentation strictly for non-commercial purposes is hereby granted * |
9 | * without fee, provided that the above copyright notice appears in all * |
10 | * copies and that both the copyright notice and this permission notice * |
11 | * appear in the supporting documentation. The authors make no claims * |
12 | * about the suitability of this software for any purpose. It is * |
13 | * provided "as is" without express or implied warranty. * |
14 | **************************************************************************/ |
15 | |
16 | /* $Id$ */ |
17 | |
18 | //////////////////////////////////////////////////////////////////////////// |
19 | // // |
20 | // The TRD track seed // |
21 | // // |
22 | // Authors: // |
23 | // Alex Bercuci <A.Bercuci@gsi.de> // |
24 | // Markus Fasel <M.Fasel@gsi.de> // |
25 | // // |
26 | //////////////////////////////////////////////////////////////////////////// |
27 | |
28 | #include "TMath.h" |
29 | #include "TLinearFitter.h" |
eb38ed55 |
30 | #include "TClonesArray.h" // tmp |
31 | #include <TTreeStream.h> |
e4f2f73d |
32 | |
33 | #include "AliLog.h" |
34 | #include "AliMathBase.h" |
35 | |
e4f2f73d |
36 | #include "AliTRDcluster.h" |
f3d3af1b |
37 | #include "AliTRDseedV1.h" |
38 | #include "AliTRDtrackV1.h" |
e4f2f73d |
39 | #include "AliTRDcalibDB.h" |
eb38ed55 |
40 | #include "AliTRDchamberTimeBin.h" |
41 | #include "AliTRDtrackingChamber.h" |
42 | #include "AliTRDtrackerV1.h" |
43 | #include "AliTRDReconstructor.h" |
e4f2f73d |
44 | #include "AliTRDrecoParam.h" |
0906e73e |
45 | #include "AliTRDgeometry.h" |
46 | #include "Cal/AliTRDCalPID.h" |
e4f2f73d |
47 | |
e4f2f73d |
48 | ClassImp(AliTRDseedV1) |
49 | |
50 | //____________________________________________________________________ |
eb38ed55 |
51 | AliTRDseedV1::AliTRDseedV1(Int_t plane) |
e4f2f73d |
52 | :AliTRDseed() |
3a039a31 |
53 | ,fReconstructor(0x0) |
eb38ed55 |
54 | ,fPlane(plane) |
0906e73e |
55 | ,fMom(0.) |
bcb6fb78 |
56 | ,fSnp(0.) |
57 | ,fTgl(0.) |
58 | ,fdX(0.) |
e4f2f73d |
59 | { |
60 | // |
61 | // Constructor |
62 | // |
6e49cfdb |
63 | //printf("AliTRDseedV1::AliTRDseedV1()\n"); |
e44586fb |
64 | |
0906e73e |
65 | for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = 0.; |
0906e73e |
66 | for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = -1.; |
e4f2f73d |
67 | } |
68 | |
69 | //____________________________________________________________________ |
0906e73e |
70 | AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref) |
e4f2f73d |
71 | :AliTRDseed((AliTRDseed&)ref) |
43d6ad34 |
72 | ,fReconstructor(ref.fReconstructor) |
0906e73e |
73 | ,fPlane(ref.fPlane) |
0906e73e |
74 | ,fMom(ref.fMom) |
bcb6fb78 |
75 | ,fSnp(ref.fSnp) |
76 | ,fTgl(ref.fTgl) |
77 | ,fdX(ref.fdX) |
e4f2f73d |
78 | { |
79 | // |
80 | // Copy Constructor performing a deep copy |
81 | // |
82 | |
6e49cfdb |
83 | //printf("AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &)\n"); |
0906e73e |
84 | for(int islice=0; islice < knSlices; islice++) fdEdx[islice] = ref.fdEdx[islice]; |
0906e73e |
85 | for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = ref.fProb[ispec]; |
fbb2ea06 |
86 | } |
d9950a5a |
87 | |
0906e73e |
88 | |
e4f2f73d |
89 | //____________________________________________________________________ |
90 | AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref) |
91 | { |
92 | // |
93 | // Assignment Operator using the copy function |
94 | // |
95 | |
e4f2f73d |
96 | if(this != &ref){ |
97 | ref.Copy(*this); |
98 | } |
99 | return *this; |
100 | |
101 | } |
102 | |
103 | //____________________________________________________________________ |
104 | AliTRDseedV1::~AliTRDseedV1() |
105 | { |
106 | // |
107 | // Destructor. The RecoParam object belongs to the underlying tracker. |
108 | // |
109 | |
6e49cfdb |
110 | //printf("I-AliTRDseedV1::~AliTRDseedV1() : Owner[%s]\n", IsOwner()?"YES":"NO"); |
e4f2f73d |
111 | |
47d5d320 |
112 | if(IsOwner()) |
0906e73e |
113 | for(int itb=0; itb<knTimebins; itb++){ |
114 | if(!fClusters[itb]) continue; |
115 | //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb)); |
116 | delete fClusters[itb]; |
117 | fClusters[itb] = 0x0; |
118 | } |
e4f2f73d |
119 | } |
120 | |
121 | //____________________________________________________________________ |
122 | void AliTRDseedV1::Copy(TObject &ref) const |
123 | { |
124 | // |
125 | // Copy function |
126 | // |
127 | |
128 | //AliInfo(""); |
129 | AliTRDseedV1 &target = (AliTRDseedV1 &)ref; |
43d6ad34 |
130 | |
0906e73e |
131 | target.fPlane = fPlane; |
132 | target.fMom = fMom; |
bcb6fb78 |
133 | target.fSnp = fSnp; |
134 | target.fTgl = fTgl; |
135 | target.fdX = fdX; |
43d6ad34 |
136 | target.fReconstructor = fReconstructor; |
0906e73e |
137 | |
138 | for(int islice=0; islice < knSlices; islice++) target.fdEdx[islice] = fdEdx[islice]; |
0906e73e |
139 | for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) target.fProb[ispec] = fProb[ispec]; |
140 | |
e4f2f73d |
141 | AliTRDseed::Copy(target); |
142 | } |
143 | |
0906e73e |
144 | |
145 | //____________________________________________________________ |
f3d3af1b |
146 | Bool_t AliTRDseedV1::Init(AliTRDtrackV1 *track) |
0906e73e |
147 | { |
148 | // Initialize this tracklet using the track information |
149 | // |
150 | // Parameters: |
151 | // track - the TRD track used to initialize the tracklet |
152 | // |
153 | // Detailed description |
154 | // The function sets the starting point and direction of the |
155 | // tracklet according to the information from the TRD track. |
156 | // |
157 | // Caution |
158 | // The TRD track has to be propagated to the beginning of the |
159 | // chamber where the tracklet will be constructed |
160 | // |
161 | |
162 | Double_t y, z; |
51863bc0 |
163 | if(!track->GetProlongation(fX0, y, z)) return kFALSE; |
0906e73e |
164 | fYref[0] = y; |
33f721e9 |
165 | fYref[1] = track->GetSnp()/(1. - track->GetSnp()*track->GetSnp()); |
0906e73e |
166 | fZref[0] = z; |
33f721e9 |
167 | fZref[1] = track->GetTgl(); |
0906e73e |
168 | |
169 | //printf("Tracklet ref x[%7.3f] y[%7.3f] z[%7.3f], snp[%f] tgl[%f]\n", fX0, fYref[0], fZref[0], track->GetSnp(), track->GetTgl()); |
51863bc0 |
170 | return kTRUE; |
0906e73e |
171 | } |
172 | |
bcb6fb78 |
173 | |
174 | //____________________________________________________________________ |
175 | void AliTRDseedV1::CookdEdx(Int_t nslices) |
176 | { |
177 | // Calculates average dE/dx for all slices and store them in the internal array fdEdx. |
178 | // |
179 | // Parameters: |
180 | // nslices : number of slices for which dE/dx should be calculated |
181 | // Output: |
182 | // store results in the internal array fdEdx. This can be accessed with the method |
183 | // AliTRDseedV1::GetdEdx() |
184 | // |
185 | // Detailed description |
186 | // Calculates average dE/dx for all slices. Depending on the PID methode |
187 | // the number of slices can be 3 (LQ) or 8(NN). |
188 | // The calculation of dQ/dl are done using the tracklet fit results (see AliTRDseedV1::GetdQdl(Int_t)) i.e. |
189 | // |
190 | // dQ/dl = qc/(dx * sqrt(1 + dy/dx^2 + dz/dx^2)) |
191 | // |
192 | // The following effects are included in the calculation: |
193 | // 1. calibration values for t0 and vdrift (using x coordinate to calculate slice) |
194 | // 2. cluster sharing (optional see AliTRDrecoParam::SetClusterSharing()) |
195 | // 3. cluster size |
196 | // |
197 | |
198 | Int_t nclusters[knSlices]; |
199 | for(int i=0; i<knSlices; i++){ |
200 | fdEdx[i] = 0.; |
201 | nclusters[i] = 0; |
202 | } |
203 | Float_t clength = (/*.5 * */AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick()); |
204 | |
205 | AliTRDcluster *cluster = 0x0; |
2985ffcb |
206 | for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){ |
bcb6fb78 |
207 | if(!(cluster = fClusters[ic])) continue; |
208 | Float_t x = cluster->GetX(); |
209 | |
210 | // Filter clusters for dE/dx calculation |
211 | |
212 | // 1.consider calibration effects for slice determination |
213 | Int_t slice; |
214 | if(cluster->IsInChamber()) slice = Int_t(TMath::Abs(fX0 - x) * nslices / clength); |
215 | else slice = x < fX0 ? 0 : nslices-1; |
216 | |
217 | // 2. take sharing into account |
218 | Float_t w = cluster->IsShared() ? .5 : 1.; |
219 | |
220 | // 3. take into account large clusters TODO |
221 | //w *= c->GetNPads() > 3 ? .8 : 1.; |
222 | |
223 | //CHECK !!! |
224 | fdEdx[slice] += w * GetdQdl(ic); //fdQdl[ic]; |
225 | nclusters[slice]++; |
226 | } // End of loop over clusters |
227 | |
3a039a31 |
228 | if(fReconstructor->GetPIDMethod() == AliTRDReconstructor::kLQPID){ |
b83573da |
229 | // calculate mean charge per slice (only LQ PID) |
230 | for(int is=0; is<nslices; is++){ |
231 | if(nclusters[is]) fdEdx[is] /= nclusters[is]; |
232 | } |
233 | } |
bcb6fb78 |
234 | } |
235 | |
b83573da |
236 | |
bcb6fb78 |
237 | //____________________________________________________________________ |
238 | Float_t AliTRDseedV1::GetdQdl(Int_t ic) const |
239 | { |
10f75631 |
240 | return fClusters[ic] ? TMath::Abs(fClusters[ic]->GetQ()) /fdX / TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]) : 0.; |
bcb6fb78 |
241 | } |
242 | |
0906e73e |
243 | //____________________________________________________________________ |
244 | Double_t* AliTRDseedV1::GetProbability() |
245 | { |
246 | // Fill probability array for tracklet from the DB. |
247 | // |
248 | // Parameters |
249 | // |
250 | // Output |
251 | // returns pointer to the probability array and 0x0 if missing DB access |
252 | // |
253 | // Detailed description |
254 | |
255 | |
256 | // retrive calibration db |
257 | AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); |
258 | if (!calibration) { |
259 | AliError("No access to calibration data"); |
260 | return 0x0; |
261 | } |
262 | |
3a039a31 |
263 | if (!fReconstructor) { |
264 | AliError("Reconstructor not set."); |
4ba1d6ae |
265 | return 0x0; |
266 | } |
267 | |
0906e73e |
268 | // Retrieve the CDB container class with the parametric detector response |
3a039a31 |
269 | const AliTRDCalPID *pd = calibration->GetPIDObject(fReconstructor->GetPIDMethod()); |
0906e73e |
270 | if (!pd) { |
271 | AliError("No access to AliTRDCalPID object"); |
272 | return 0x0; |
273 | } |
3a039a31 |
274 | //AliInfo(Form("Method[%d] : %s", fReconstructor->GetRecoParam() ->GetPIDMethod(), pd->IsA()->GetName())); |
10f75631 |
275 | |
0906e73e |
276 | // calculate tracklet length TO DO |
277 | Float_t length = (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick()); |
278 | /// TMath::Sqrt((1.0 - fSnp[iPlane]*fSnp[iPlane]) / (1.0 + fTgl[iPlane]*fTgl[iPlane])); |
279 | |
280 | //calculate dE/dx |
3a039a31 |
281 | CookdEdx(fReconstructor->GetNdEdxSlices()); |
0906e73e |
282 | |
283 | // Sets the a priori probabilities |
284 | for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) { |
285 | fProb[ispec] = pd->GetProbability(ispec, fMom, &fdEdx[0], length, fPlane); |
286 | } |
287 | |
288 | return &fProb[0]; |
289 | } |
290 | |
e4f2f73d |
291 | //____________________________________________________________________ |
292 | Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const |
293 | { |
294 | // |
295 | // Returns a quality measurement of the current seed |
296 | // |
297 | |
298 | Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.; |
eb38ed55 |
299 | return |
300 | .5 * TMath::Abs(18.0 - fN2) |
e4f2f73d |
301 | + 10.* TMath::Abs(fYfit[1] - fYref[1]) |
eb38ed55 |
302 | + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr) |
e4f2f73d |
303 | + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength; |
304 | } |
305 | |
0906e73e |
306 | //____________________________________________________________________ |
307 | void AliTRDseedV1::GetCovAt(Double_t /*x*/, Double_t *cov) const |
308 | { |
309 | // Computes covariance in the y-z plane at radial point x |
310 | |
eb38ed55 |
311 | Int_t ic = 0; while (!fClusters[ic]) ic++; |
312 | AliTRDcalibDB *fCalib = AliTRDcalibDB::Instance(); |
313 | Double_t exB = fCalib->GetOmegaTau(fCalib->GetVdriftAverage(fClusters[ic]->GetDetector()), -AliTracker::GetBz()*0.1); |
314 | |
315 | Double_t sy2 = fSigmaY2*fSigmaY2 + .2*(fYfit[1]-exB)*(fYfit[1]-exB); |
0906e73e |
316 | Double_t sz2 = fPadLength/12.; |
317 | |
eb38ed55 |
318 | |
0906e73e |
319 | //printf("Yfit[1] %f sy20 %f SigmaY2 %f\n", fYfit[1], sy20, fSigmaY2); |
320 | |
321 | cov[0] = sy2; |
322 | cov[1] = fTilt*(sy2-sz2); |
323 | cov[2] = sz2; |
3a039a31 |
324 | |
325 | // insert systematic uncertainties calibration and misalignment |
326 | Double_t sys[15]; |
327 | fReconstructor->GetRecoParam()->GetSysCovMatrix(sys); |
328 | cov[0] += (sys[0]*sys[0]); |
329 | cov[2] += (sys[1]*sys[1]); |
0906e73e |
330 | } |
331 | |
0906e73e |
332 | |
333 | //____________________________________________________________________ |
334 | void AliTRDseedV1::SetOwner(Bool_t own) |
335 | { |
336 | //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO")); |
337 | |
338 | if(own){ |
339 | for(int ic=0; ic<knTimebins; ic++){ |
340 | if(!fClusters[ic]) continue; |
341 | fClusters[ic] = new AliTRDcluster(*fClusters[ic]); |
342 | } |
e44586fb |
343 | SetBit(kOwner); |
0906e73e |
344 | } else { |
47d5d320 |
345 | if(IsOwner()){ |
0906e73e |
346 | for(int ic=0; ic<knTimebins; ic++){ |
347 | if(!fClusters[ic]) continue; |
348 | delete fClusters[ic]; |
349 | //fClusters[ic] = tracker->GetClusters(index) TODO |
350 | } |
351 | } |
e44586fb |
352 | SetBit(kOwner, kFALSE); |
0906e73e |
353 | } |
354 | } |
355 | |
e4f2f73d |
356 | //____________________________________________________________________ |
eb38ed55 |
357 | Bool_t AliTRDseedV1::AttachClustersIter(AliTRDtrackingChamber *chamber, Float_t quality, Bool_t kZcorr, AliTRDcluster *c) |
e4f2f73d |
358 | { |
359 | // |
360 | // Iterative process to register clusters to the seed. |
361 | // In iteration 0 we try only one pad-row and if quality not |
362 | // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows) |
363 | // |
eb38ed55 |
364 | // debug level 7 |
365 | // |
e4f2f73d |
366 | |
3a039a31 |
367 | if(!fReconstructor->GetRecoParam() ){ |
e4f2f73d |
368 | AliError("Seed can not be used without a valid RecoParam."); |
369 | return kFALSE; |
370 | } |
0906e73e |
371 | |
eb38ed55 |
372 | AliTRDchamberTimeBin *layer = 0x0; |
3a039a31 |
373 | if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7 && c){ |
eb38ed55 |
374 | TClonesArray clusters("AliTRDcluster", 24); |
375 | clusters.SetOwner(kTRUE); |
376 | AliTRDcluster *cc = 0x0; |
377 | Int_t det=-1, ncl, ncls = 0; |
2985ffcb |
378 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
eb38ed55 |
379 | if(!(layer = chamber->GetTB(iTime))) continue; |
380 | if(!(ncl = Int_t(*layer))) continue; |
381 | for(int ic=0; ic<ncl; ic++){ |
382 | cc = (*layer)[ic]; |
383 | det = cc->GetDetector(); |
384 | new(clusters[ncls++]) AliTRDcluster(*cc); |
385 | } |
386 | } |
387 | AliInfo(Form("N clusters[%d] = %d", fPlane, ncls)); |
388 | |
389 | Int_t ref = c ? 1 : 0; |
390 | TTreeSRedirector &cstreamer = *AliTRDtrackerV1::DebugStreamer(); |
391 | cstreamer << "AttachClustersIter" |
392 | << "det=" << det |
393 | << "ref=" << ref |
394 | << "clusters.=" << &clusters |
395 | << "tracklet.=" << this |
396 | << "cl.=" << c |
397 | << "\n"; |
398 | } |
0906e73e |
399 | |
e4f2f73d |
400 | Float_t tquality; |
3a039a31 |
401 | Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y(); |
e4f2f73d |
402 | Double_t kroadz = fPadLength * .5 + 1.; |
403 | |
404 | // initialize configuration parameters |
405 | Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.; |
406 | Int_t niter = kZcorr ? 1 : 2; |
407 | |
408 | Double_t yexp, zexp; |
409 | Int_t ncl = 0; |
410 | // start seed update |
411 | for (Int_t iter = 0; iter < niter; iter++) { |
e4f2f73d |
412 | ncl = 0; |
2985ffcb |
413 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
eb38ed55 |
414 | if(!(layer = chamber->GetTB(iTime))) continue; |
415 | if(!Int_t(*layer)) continue; |
416 | |
e4f2f73d |
417 | // define searching configuration |
eb38ed55 |
418 | Double_t dxlayer = layer->GetX() - fX0; |
e4f2f73d |
419 | if(c){ |
420 | zexp = c->GetZ(); |
421 | //Try 2 pad-rows in second iteration |
422 | if (iter > 0) { |
423 | zexp = fZref[0] + fZref[1] * dxlayer - zcorr; |
424 | if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5; |
425 | if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5; |
426 | } |
eb38ed55 |
427 | } else zexp = fZref[0] + (kZcorr ? fZref[1] * dxlayer : 0.); |
e4f2f73d |
428 | yexp = fYref[0] + fYref[1] * dxlayer - zcorr; |
bcb6fb78 |
429 | |
430 | // Get and register cluster |
eb38ed55 |
431 | Int_t index = layer->SearchNearestCluster(yexp, zexp, kroady, kroadz); |
e4f2f73d |
432 | if (index < 0) continue; |
eb38ed55 |
433 | AliTRDcluster *cl = (*layer)[index]; |
e4f2f73d |
434 | |
eb38ed55 |
435 | fIndexes[iTime] = layer->GetGlobalIndex(index); |
e4f2f73d |
436 | fClusters[iTime] = cl; |
e4f2f73d |
437 | fY[iTime] = cl->GetY(); |
438 | fZ[iTime] = cl->GetZ(); |
e4f2f73d |
439 | ncl++; |
440 | } |
3a039a31 |
441 | if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d ncl [%d] = %d", iter, fPlane, ncl)); |
bcb6fb78 |
442 | |
eb38ed55 |
443 | if(ncl>1){ |
bcb6fb78 |
444 | // calculate length of the time bin (calibration aware) |
445 | Int_t irp = 0; Float_t x[2]; Int_t tb[2]; |
2985ffcb |
446 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
bcb6fb78 |
447 | if(!fClusters[iTime]) continue; |
448 | x[irp] = fClusters[iTime]->GetX(); |
449 | tb[irp] = iTime; |
450 | irp++; |
451 | if(irp==2) break; |
452 | } |
453 | fdX = (x[1] - x[0]) / (tb[0] - tb[1]); |
454 | |
455 | // update X0 from the clusters (calibration/alignment aware) |
2985ffcb |
456 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
eb38ed55 |
457 | if(!(layer = chamber->GetTB(iTime))) continue; |
458 | if(!layer->IsT0()) continue; |
bcb6fb78 |
459 | if(fClusters[iTime]){ |
460 | fX0 = fClusters[iTime]->GetX(); |
461 | break; |
462 | } else { // we have to infere the position of the anode wire from the other clusters |
2985ffcb |
463 | for (Int_t jTime = iTime+1; jTime < AliTRDtrackerV1::GetNTimeBins(); jTime++) { |
bcb6fb78 |
464 | if(!fClusters[jTime]) continue; |
465 | fX0 = fClusters[jTime]->GetX() + fdX * (jTime - iTime); |
466 | } |
467 | break; |
468 | } |
469 | } |
470 | |
471 | // update YZ reference point |
472 | // TODO |
473 | |
474 | // update x reference positions (calibration/alignment aware) |
2985ffcb |
475 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
bcb6fb78 |
476 | if(!fClusters[iTime]) continue; |
477 | fX[iTime] = fClusters[iTime]->GetX() - fX0; |
478 | } |
479 | |
480 | AliTRDseed::Update(); |
481 | } |
3a039a31 |
482 | if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker)>=7) AliInfo(Form("iter = %d nclFit [%d] = %d", iter, fPlane, fN2)); |
bcb6fb78 |
483 | |
e4f2f73d |
484 | if(IsOK()){ |
485 | tquality = GetQuality(kZcorr); |
486 | if(tquality < quality) break; |
487 | else quality = tquality; |
488 | } |
489 | kroadz *= 2.; |
490 | } // Loop: iter |
491 | if (!IsOK()) return kFALSE; |
492 | |
493 | CookLabels(); |
494 | UpdateUsed(); |
495 | return kTRUE; |
496 | } |
497 | |
498 | //____________________________________________________________________ |
eb38ed55 |
499 | Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *chamber |
0906e73e |
500 | ,Bool_t kZcorr) |
e4f2f73d |
501 | { |
502 | // |
503 | // Projective algorithm to attach clusters to seeding tracklets |
504 | // |
505 | // Parameters |
506 | // |
507 | // Output |
508 | // |
509 | // Detailed description |
510 | // 1. Collapse x coordinate for the full detector plane |
511 | // 2. truncated mean on y (r-phi) direction |
512 | // 3. purge clusters |
513 | // 4. truncated mean on z direction |
514 | // 5. purge clusters |
515 | // 6. fit tracklet |
516 | // |
517 | |
3a039a31 |
518 | if(!fReconstructor->GetRecoParam() ){ |
e4f2f73d |
519 | AliError("Seed can not be used without a valid RecoParam."); |
520 | return kFALSE; |
521 | } |
522 | |
0906e73e |
523 | const Int_t kClusterCandidates = 2 * knTimebins; |
e4f2f73d |
524 | |
525 | //define roads |
3a039a31 |
526 | Double_t kroady = fReconstructor->GetRecoParam() ->GetRoad1y(); |
e4f2f73d |
527 | Double_t kroadz = fPadLength * 1.5 + 1.; |
528 | // correction to y for the tilting angle |
529 | Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.; |
530 | |
531 | // working variables |
532 | AliTRDcluster *clusters[kClusterCandidates]; |
0906e73e |
533 | Double_t cond[4], yexp[knTimebins], zexp[knTimebins], |
e4f2f73d |
534 | yres[kClusterCandidates], zres[kClusterCandidates]; |
0906e73e |
535 | Int_t ncl, *index = 0x0, tboundary[knTimebins]; |
e4f2f73d |
536 | |
537 | // Do cluster projection |
eb38ed55 |
538 | AliTRDchamberTimeBin *layer = 0x0; |
e4f2f73d |
539 | Int_t nYclusters = 0; Bool_t kEXIT = kFALSE; |
2985ffcb |
540 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
eb38ed55 |
541 | if(!(layer = chamber->GetTB(iTime))) continue; |
542 | if(!Int_t(*layer)) continue; |
543 | |
544 | fX[iTime] = layer->GetX() - fX0; |
e4f2f73d |
545 | zexp[iTime] = fZref[0] + fZref[1] * fX[iTime]; |
546 | yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr; |
547 | |
548 | // build condition and process clusters |
549 | cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady; |
550 | cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz; |
eb38ed55 |
551 | layer->GetClusters(cond, index, ncl); |
e4f2f73d |
552 | for(Int_t ic = 0; ic<ncl; ic++){ |
eb38ed55 |
553 | AliTRDcluster *c = layer->GetCluster(index[ic]); |
e4f2f73d |
554 | clusters[nYclusters] = c; |
555 | yres[nYclusters++] = c->GetY() - yexp[iTime]; |
556 | if(nYclusters >= kClusterCandidates) { |
557 | AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates)); |
558 | kEXIT = kTRUE; |
559 | break; |
560 | } |
561 | } |
562 | tboundary[iTime] = nYclusters; |
563 | if(kEXIT) break; |
564 | } |
565 | |
566 | // Evaluate truncated mean on the y direction |
567 | Double_t mean, sigma; |
568 | AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2); |
eb38ed55 |
569 | // purge cluster candidates |
e4f2f73d |
570 | Int_t nZclusters = 0; |
571 | for(Int_t ic = 0; ic<nYclusters; ic++){ |
572 | if(yres[ic] - mean > 4. * sigma){ |
573 | clusters[ic] = 0x0; |
574 | continue; |
575 | } |
576 | zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()]; |
577 | } |
578 | |
579 | // Evaluate truncated mean on the z direction |
580 | AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2); |
eb38ed55 |
581 | // purge cluster candidates |
e4f2f73d |
582 | for(Int_t ic = 0; ic<nZclusters; ic++){ |
583 | if(zres[ic] - mean > 4. * sigma){ |
584 | clusters[ic] = 0x0; |
585 | continue; |
586 | } |
587 | } |
588 | |
589 | |
590 | // Select only one cluster/TimeBin |
591 | Int_t lastCluster = 0; |
592 | fN2 = 0; |
2985ffcb |
593 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
e4f2f73d |
594 | ncl = tboundary[iTime] - lastCluster; |
595 | if(!ncl) continue; |
eb38ed55 |
596 | Int_t iptr = lastCluster; |
597 | if(ncl > 1){ |
598 | Float_t dold = 9999.; |
e4f2f73d |
599 | for(int ic=lastCluster; ic<tboundary[iTime]; ic++){ |
600 | if(!clusters[ic]) continue; |
601 | Float_t y = yexp[iTime] - clusters[ic]->GetY(); |
602 | Float_t z = zexp[iTime] - clusters[ic]->GetZ(); |
603 | Float_t d = y * y + z * z; |
604 | if(d > dold) continue; |
605 | dold = d; |
606 | iptr = ic; |
607 | } |
e4f2f73d |
608 | } |
eb38ed55 |
609 | fIndexes[iTime] = chamber->GetTB(iTime)->GetGlobalIndex(iptr); |
610 | fClusters[iTime] = clusters[iptr]; |
611 | fY[iTime] = clusters[iptr]->GetY(); |
612 | fZ[iTime] = clusters[iptr]->GetZ(); |
0906e73e |
613 | lastCluster = tboundary[iTime]; |
e4f2f73d |
614 | fN2++; |
615 | } |
616 | |
617 | // number of minimum numbers of clusters expected for the tracklet |
3a039a31 |
618 | Int_t kClmin = Int_t(fReconstructor->GetRecoParam() ->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins()); |
e4f2f73d |
619 | if (fN2 < kClmin){ |
620 | AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin)); |
621 | fN2 = 0; |
622 | return kFALSE; |
623 | } |
0906e73e |
624 | |
625 | // update used clusters |
626 | fNUsed = 0; |
2985ffcb |
627 | for (Int_t iTime = 0; iTime < AliTRDtrackerV1::GetNTimeBins(); iTime++) { |
0906e73e |
628 | if(!fClusters[iTime]) continue; |
629 | if((fClusters[iTime]->IsUsed())) fNUsed++; |
630 | } |
631 | |
632 | if (fN2-fNUsed < kClmin){ |
633 | AliWarning(Form("Too many clusters already in use %d (from %d).", fNUsed, fN2)); |
634 | fN2 = 0; |
635 | return kFALSE; |
636 | } |
e4f2f73d |
637 | |
e4f2f73d |
638 | return kTRUE; |
639 | } |
640 | |
641 | //____________________________________________________________________ |
0906e73e |
642 | Bool_t AliTRDseedV1::Fit() |
e4f2f73d |
643 | { |
644 | // |
645 | // Linear fit of the tracklet |
646 | // |
647 | // Parameters : |
648 | // |
649 | // Output : |
650 | // True if successful |
651 | // |
652 | // Detailed description |
653 | // 2. Check if tracklet crosses pad row boundary |
654 | // 1. Calculate residuals in the y (r-phi) direction |
655 | // 3. Do a Least Square Fit to the data |
656 | // |
657 | |
47d5d320 |
658 | const Int_t kClmin = 8; |
659 | const Int_t kNtb = AliTRDtrackerV1::GetNTimeBins(); |
8acca6a3 |
660 | AliTRDtrackerV1::AliTRDLeastSquare fitterY, fitterZ; |
47d5d320 |
661 | |
662 | // convertion factor from square to gauss distribution for sigma |
663 | Double_t convert = 1./TMath::Sqrt(12.); |
664 | |
665 | // book cluster information |
8acca6a3 |
666 | Double_t xc[knTimebins+1], yc[knTimebins], zc[knTimebins+1], sy[knTimebins], sz[knTimebins+1]; |
47d5d320 |
667 | Int_t zRow[knTimebins]; |
668 | AliTRDcluster *c = 0x0; |
669 | Int_t nc = 0; |
670 | for (Int_t ic=0; ic<kNtb; ic++) { |
671 | zRow[ic] = -1; |
672 | xc[ic] = -1.; |
673 | yc[ic] = 999.; |
674 | zc[ic] = 999.; |
675 | sy[ic] = 0.; |
676 | sz[ic] = 0.; |
677 | if(!(c = fClusters[ic])) continue; |
678 | if(!c->IsInChamber()) continue; |
679 | Float_t w = 1.; |
680 | if(c->GetNPads()>4) w = .5; |
681 | if(c->GetNPads()>5) w = .2; |
682 | zRow[nc] = c->GetPadRow(); |
683 | xc[nc] = fX0 - c->GetX(); |
684 | yc[nc] = c->GetY(); |
685 | zc[nc] = c->GetZ(); |
686 | sy[ic] = w; // all clusters have the same sigma |
687 | sz[ic] = fPadLength*convert; |
8acca6a3 |
688 | fitterZ.AddPoint(&xc[ic], zc[ic], sz[ic]); |
47d5d320 |
689 | nc++; |
690 | } |
691 | // to few clusters |
692 | if (nc < kClmin) return kFALSE; |
693 | |
e4f2f73d |
694 | |
47d5d320 |
695 | Int_t zN[2*35]; |
696 | Int_t nz = AliTRDtrackerV1::Freq(nc, zRow, zN, kFALSE); |
697 | // more than one pad row crossing |
698 | if(nz>2) return kFALSE; |
e4f2f73d |
699 | |
47d5d320 |
700 | // estimate reference parameter at average x |
701 | Double_t y0 = fYref[0]; |
702 | Double_t dydx = fYref[1]; |
703 | Double_t dzdx = fZref[1]; |
704 | zc[nc] = fZref[0]; |
705 | |
706 | // determine z offset of the fit |
707 | Int_t nchanges = 0, nCross = 0; |
708 | if(nz==2){ // tracklet is crossing pad row |
709 | // Find the break time allowing one chage on pad-rows |
710 | // with maximal number of accepted clusters |
711 | Int_t padRef = zRow[0]; |
712 | for (Int_t ic=1; ic<nc; ic++) { |
713 | if(zRow[ic] == padRef) continue; |
714 | |
715 | // debug |
716 | if(zRow[ic-1] == zRow[ic]){ |
717 | printf("ERROR in pad row change!!!\n"); |
718 | } |
719 | |
720 | // evaluate parameters of the crossing point |
721 | Float_t sx = (xc[ic-1] - xc[ic])*convert; |
722 | xc[nc] = .5 * (xc[ic-1] + xc[ic]); |
723 | zc[nc] = .5 * (zc[ic-1] + zc[ic]); |
724 | sz[nc] = TMath::Max(dzdx * sx, .01); |
725 | dzdx = zc[ic-1] > zc[ic] ? 1. : -1.; |
726 | padRef = zRow[ic]; |
727 | nCross = ic; |
728 | nchanges++; |
729 | } |
e4f2f73d |
730 | } |
731 | |
47d5d320 |
732 | // condition on nCross and reset nchanges TODO |
733 | |
47d5d320 |
734 | if(nchanges==1){ |
735 | if(dzdx * fZref[1] < 0.){ |
736 | AliInfo("tracklet direction does not correspond to the track direction. TODO."); |
737 | } |
e44586fb |
738 | SetBit(kRowCross, kTRUE); // mark pad row crossing |
47d5d320 |
739 | fCross[0] = xc[nc]; fCross[2] = zc[nc]; fCross[3] = sz[nc]; |
8acca6a3 |
740 | fitterZ.AddPoint(&xc[nc], zc[nc], sz[nc]); |
741 | fitterZ.Eval(); |
742 | dzdx = fZref[1]; // we don't trust Parameter[1] ??; |
743 | zc[nc] = fitterZ.GetFunctionParameter(0); |
47d5d320 |
744 | } else if(nchanges > 1){ // debug |
745 | AliInfo("ERROR in n changes!!!"); |
e4f2f73d |
746 | return kFALSE; |
747 | } |
47d5d320 |
748 | |
749 | |
750 | // estimate deviation from reference direction |
751 | dzdx *= fTilt; |
752 | for (Int_t ic=0; ic<nc; ic++) { |
753 | yc[ic] -= y0 + xc[ic]*(dydx + dzdx) + fTilt * (zc[ic] - zc[nc]); |
8acca6a3 |
754 | fitterY.AddPoint(&xc[ic], yc[ic], sy[ic]); |
e4f2f73d |
755 | } |
8acca6a3 |
756 | fitterY.Eval(); |
757 | fYfit[0] = y0+fitterY.GetFunctionParameter(0); |
758 | fYfit[1] = dydx+fitterY.GetFunctionParameter(1); |
47d5d320 |
759 | if(nchanges) fCross[1] = fYfit[0] + fCross[0] * fYfit[1]; |
e4f2f73d |
760 | |
47d5d320 |
761 | // printf("\nnz = %d\n", nz); |
762 | // for(int ic=0; ic<35; ic++) printf("%d row[%d]\n", ic, zRow[ic]); |
763 | // |
764 | // for(int ic=0; ic<nz; ic++) printf("%d n[%d]\n", ic, zN[ic]); |
e4f2f73d |
765 | |
766 | return kTRUE; |
767 | } |
768 | |
47d5d320 |
769 | //___________________________________________________________________ |
770 | void AliTRDseedV1::Draw(Option_t*) |
771 | { |
772 | } |
e4f2f73d |
773 | |
774 | //___________________________________________________________________ |
47d5d320 |
775 | void AliTRDseedV1::Print(Option_t*) const |
e4f2f73d |
776 | { |
777 | // |
778 | // Printing the seedstatus |
779 | // |
780 | |
e4f2f73d |
781 | printf("Seed status :\n"); |
782 | printf(" fTilt = %f\n", fTilt); |
783 | printf(" fPadLength = %f\n", fPadLength); |
784 | printf(" fX0 = %f\n", fX0); |
2985ffcb |
785 | for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++) { |
e4f2f73d |
786 | const Char_t *isUsable = fUsable[ic]?"Yes":"No"; |
0906e73e |
787 | printf(" %d X[%f] Y[%f] Z[%f] Indexes[%d] clusters[%p] usable[%s]\n" |
e4f2f73d |
788 | , ic |
789 | , fX[ic] |
790 | , fY[ic] |
791 | , fZ[ic] |
792 | , fIndexes[ic] |
0906e73e |
793 | , ((void*) fClusters[ic]) |
e4f2f73d |
794 | , isUsable); |
795 | } |
796 | |
797 | printf(" fYref[0] =%f fYref[1] =%f\n", fYref[0], fYref[1]); |
798 | printf(" fZref[0] =%f fZref[1] =%f\n", fZref[0], fZref[1]); |
799 | printf(" fYfit[0] =%f fYfit[1] =%f\n", fYfit[0], fYfit[1]); |
800 | printf(" fYfitR[0]=%f fYfitR[1]=%f\n", fYfitR[0], fYfitR[1]); |
801 | printf(" fZfit[0] =%f fZfit[1] =%f\n", fZfit[0], fZfit[1]); |
802 | printf(" fZfitR[0]=%f fZfitR[1]=%f\n", fZfitR[0], fZfitR[1]); |
803 | printf(" fSigmaY =%f\n", fSigmaY); |
804 | printf(" fSigmaY2=%f\n", fSigmaY2); |
805 | printf(" fMeanz =%f\n", fMeanz); |
806 | printf(" fZProb =%f\n", fZProb); |
807 | printf(" fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]); |
808 | printf(" fN =%d\n", fN); |
809 | printf(" fN2 =%d (>8 isOK)\n",fN2); |
810 | printf(" fNUsed =%d\n", fNUsed); |
811 | printf(" fFreq =%d\n", fFreq); |
812 | printf(" fNChange=%d\n", fNChange); |
813 | printf(" fMPads =%f\n", fMPads); |
814 | |
815 | printf(" fC =%f\n", fC); |
816 | printf(" fCC =%f\n",fCC); |
817 | printf(" fChi2 =%f\n", fChi2); |
818 | printf(" fChi2Z =%f\n", fChi2Z); |
e4f2f73d |
819 | } |
47d5d320 |
820 | |