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