1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // The seed of a local TRD track //
22 ///////////////////////////////////////////////////////////////////////////////
25 #include "TLinearFitter.h"
27 #include "AliMathBase.h"
29 #include "AliTRDseed.h"
30 #include "AliTRDcalibDB.h"
31 #include "AliTRDcluster.h"
32 #include "AliTRDtracker.h"
36 Int_t AliTRDseed::fgTimeBins = 0;
38 //_____________________________________________________________________________
39 AliTRDseed::AliTRDseed()
62 // Default constructor
65 for (Int_t i = 0; i < knTimebins; i++) {
66 fX[i] = 0; // x position
67 fY[i] = 0; // y position
68 fZ[i] = 0; // z position
69 fIndexes[i] = 0; // Indexes
70 fClusters[i] = 0x0; // Clusters
71 fUsable[i] = 0; // Indication - usable cluster
74 for (Int_t i = 0; i < 2; i++) {
75 fYref[i] = 0; // Reference y
76 fZref[i] = 0; // Reference z
77 fYfit[i] = 0; // Y fit position +derivation
78 fYfitR[i] = 0; // Y fit position +derivation
79 fZfit[i] = 0; // Z fit position
80 fZfitR[i] = 0; // Z fit position
81 fLabels[i] = 0; // Labels
86 //_____________________________________________________________________________
87 AliTRDseed::AliTRDseed(const AliTRDseed &s)
89 ,fTimeBinsRange(s.fTimeBinsRange)
90 ,fTimeBin0(s.fTimeBin0)
92 ,fPadLength(s.fPadLength)
102 ,fNChange(s.fNChange)
113 for (Int_t i = 0; i < knTimebins; i++) {
114 fX[i] = s.fX[i]; // x position
115 fY[i] = s.fY[i]; // y position
116 fZ[i] = s.fZ[i]; // z position
117 fIndexes[i] = s.fIndexes[i]; // Indexes
118 fClusters[i] = s.fClusters[i]; // Clusters
119 fUsable[i] = s.fUsable[i]; // Indication - usable cluster
122 for (Int_t i = 0; i < 2; i++) {
123 fYref[i] = s.fYref[i]; // Reference y
124 fZref[i] = s.fZref[i]; // Reference z
125 fYfit[i] = s.fYfit[i]; // Y fit position +derivation
126 fYfitR[i] = s.fYfitR[i]; // Y fit position +derivation
127 fZfit[i] = s.fZfit[i]; // Z fit position
128 fZfitR[i] = s.fZfitR[i]; // Z fit position
129 fLabels[i] = s.fLabels[i]; // Labels
134 //_____________________________________________________________________________
135 void AliTRDseed::Copy(TObject &o) const
137 //printf("AliTRDseed::Copy()\n");
139 AliTRDseed &seed = (AliTRDseed &)o;
141 seed.fTimeBinsRange = fTimeBinsRange;
142 seed.fTimeBin0 = fTimeBin0;
144 seed.fPadLength = fPadLength;
146 seed.fSigmaY = fSigmaY;
147 seed.fSigmaY2 = fSigmaY2;
148 seed.fMeanz = fMeanz;
149 seed.fZProb = fZProb;
152 seed.fNUsed = fNUsed;
154 seed.fNChange = fNChange;
155 seed.fMPads = fMPads;
159 seed.fChi2Z = fChi2Z;
160 for (Int_t i = 0; i < knTimebins; i++) {
164 seed.fIndexes[i] = fIndexes[i];
165 seed.fClusters[i] = fClusters[i];
166 seed.fUsable[i] = fUsable[i];
169 for (Int_t i = 0; i < 2; i++) {
170 seed.fYref[i] = fYref[i];
171 seed.fZref[i] = fZref[i];
172 seed.fYfit[i] = fYfit[i];
173 seed.fYfitR[i] = fYfitR[i];
174 seed.fZfit[i] = fZfit[i];
175 seed.fZfitR[i] = fZfitR[i];
176 seed.fLabels[i] = fLabels[i];
183 //_____________________________________________________________________________
184 void AliTRDseed::Reset()
190 for (Int_t i = 0; i < knTimebins; i++) {
191 fX[i] = 0; // X position
192 fY[i] = 0; // Y position
193 fZ[i] = 0; // Z position
194 fIndexes[i] = 0; // Indexes
195 fClusters[i] = 0x0; // Clusters
199 for (Int_t i = 0; i < 2; i++) {
200 fYref[i] = 0; // Reference y
201 fZref[i] = 0; // Reference z
202 fYfit[i] = 0; // Y fit position +derivation
203 fYfitR[i] = 0; // Y fit position +derivation
204 fZfit[i] = 0; // Z fit position
205 fZfitR[i] = 0; // Z fit position
206 fLabels[i] = -1; // Labels
208 fSigmaY = 0; // "Robust" sigma in y
209 fSigmaY2 = 0; // "Robust" sigma in y
210 fMeanz = 0; // Mean vaue of z
211 fZProb = 0; // Max probbable z
213 fN = 0; // Number of associated clusters
214 fN2 = 0; // Number of not crossed
215 fNUsed = 0; // Number of used clusters
216 fNChange = 0; // Change z counter
220 //_____________________________________________________________________________
221 void AliTRDseed::CookLabels()
224 // Cook 2 labels for seed
231 for (Int_t i = 0; i < fgTimeBins+1; i++) {
232 if (!fClusters[i]) continue;
233 for (Int_t ilab = 0; ilab < 3; ilab++) {
234 if (fClusters[i]->GetLabel(ilab) >= 0) {
235 labels[nlab] = fClusters[i]->GetLabel(ilab);
241 Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
250 //_____________________________________________________________________________
251 void AliTRDseed::UseClusters()
257 for (Int_t i = 0; i < fgTimeBins+1; i++) {
258 if (!fClusters[i]) continue;
259 if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
264 //_____________________________________________________________________________
265 void AliTRDseed::Update()
272 // linear fit on the y direction
273 // dy|x = (yc|x - dz|x*tg(tilt)) - (y0 + dy/dx|x * x )
274 // dz|x = zc|x - (z0 + dz/dx|x)
276 const Float_t kRatio = 0.8;
277 const Int_t kClmin = 5;
278 const Float_t kmaxtan = 2;
281 if (TMath::Abs(fYref[1]) > kmaxtan){
282 //printf("Exit: Abs(fYref[1]) = %3.3f, kmaxtan = %3.3f\n", TMath::Abs(fYref[1]), kmaxtan);
283 return; // Track inclined too much
286 Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
287 Float_t ycrosscor = fPadLength * fTilt * 0.5; // Y correction for crossing
298 // Buffering: Leave it constant fot Performance issues
299 Int_t zints[knTimebins]; // Histograming of the z coordinate
300 // Get 1 and second max probable coodinates in z
301 Int_t zouts[2*knTimebins];
302 Float_t allowedz[knTimebins]; // Allowed z for given time bin
303 Float_t yres[knTimebins]; // Residuals from reference
304 Float_t anglecor = fTilt * fZref[1]; // Correction to the angle
309 for (Int_t i = 0; i < fTimeBinsRange; i++) {
311 if (!fClusters[i]) continue;
312 yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i]; // Residual y
313 zints[fN] = Int_t(fZ[i]);
318 //printf("Exit fN < kClmin: fN = %d\n", fN);
321 Int_t nz = AliTRDtracker::Freq(fN,zints,zouts,kFALSE);
323 if (nz <= 1) zouts[3] = 0;
324 if (zouts[1] + zouts[3] < kClmin) {
325 //printf("Exit zouts[1] = %d, zouts[3] = %d\n",zouts[1],zouts[3]);
329 // Z distance bigger than pad - length
330 if (TMath::Abs(zouts[0]-zouts[2]) > 12.0) {
334 Int_t breaktime = -1;
335 Bool_t mbefore = kFALSE;
336 Int_t cumul[knTimebins][2];
337 Int_t counts[2] = { 0, 0 };
342 // Find the break time allowing one chage on pad-rows
343 // with maximal numebr of accepted clusters
346 for (Int_t i = 0; i < fTimeBinsRange; i++) {
347 cumul[i][0] = counts[0];
348 cumul[i][1] = counts[1];
349 if (TMath::Abs(fZ[i]-zouts[0]) < 2) counts[0]++;
350 if (TMath::Abs(fZ[i]-zouts[2]) < 2) counts[1]++;
353 for (Int_t i = 0; i < fTimeBinsRange; i++) {
354 Int_t after = cumul[fTimeBinsRange][0] - cumul[i][0];
355 Int_t before = cumul[i][1];
356 if (after + before > maxcount) {
357 maxcount = after + before;
361 after = cumul[fTimeBinsRange-1][1] - cumul[i][1];
362 before = cumul[i][0];
363 if (after + before > maxcount) {
364 maxcount = after + before;
374 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
375 if (i > breaktime) allowedz[i] = mbefore ? zouts[2] : zouts[0];
376 if (i <= breaktime) allowedz[i] = (!mbefore) ? zouts[2] : zouts[0];
379 if (((allowedz[0] > allowedz[fTimeBinsRange]) && (fZref[1] < 0)) ||
380 ((allowedz[0] < allowedz[fTimeBinsRange]) && (fZref[1] > 0))) {
382 // Tracklet z-direction not in correspondance with track z direction
385 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
386 allowedz[i] = zouts[0]; // Only longest taken
392 // Cross pad -row tracklet - take the step change into account
394 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
395 if (!fClusters[i]) continue;
396 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
397 yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i]; // Residual y
398 if (TMath::Abs(fZ[i] - fZProb) > 2) {
399 if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
400 if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
405 Double_t yres2[knTimebins];
408 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
409 if (!fClusters[i]) continue;
410 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
411 yres2[fN2] = yres[i];
415 //printf("Exit fN2 < kClmin: fN2 = %d\n", fN2);
419 AliMathBase::EvaluateUni(fN2,yres2,mean,sigma, Int_t(fN2*kRatio-2.));
420 if (sigma < sigmaexp * 0.8) {
438 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
441 if (!fClusters[i]) continue;
442 if (TMath::Abs(fZ[i] - allowedz[i]) > 2){fClusters[i] = 0x0; continue;}
443 if (TMath::Abs(yres[i] - mean) > 4.0 * sigma){fClusters[i] = 0x0; continue;}
446 fMPads += fClusters[i]->GetNPads();
447 Float_t weight = 1.0;
448 if (fClusters[i]->GetNPads() > 4) weight = 0.5;
449 if (fClusters[i]->GetNPads() > 5) weight = 0.2;
453 //printf("x = %7.3f dy = %7.3f fit %7.3f\n", x, yres[i], fY[i]-yres[i]);
457 sumwx2 += x*x * weight;
458 sumwy += weight * yres[i];
459 sumwxy += weight * (yres[i]) * x;
460 sumwz += weight * fZ[i];
461 sumwxz += weight * fZ[i] * x;
466 //printf("Exit fN2 < kClmin(2): fN2 = %d\n",fN2);
470 fMeanz = sumwz / sumw;
471 Float_t correction = 0;
473 // Tracklet on boundary
474 if (fMeanz < fZProb) correction = ycrosscor;
475 if (fMeanz > fZProb) correction = -ycrosscor;
478 Double_t det = sumw * sumwx2 - sumwx * sumwx;
479 fYfitR[0] = (sumwx2 * sumwy - sumwx * sumwxy) / det;
480 fYfitR[1] = (sumw * sumwxy - sumwx * sumwy) / det;
483 for (Int_t i = 0; i < fTimeBinsRange+1; i++) {
484 if (!fUsable[i]) continue;
485 Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
486 fSigmaY2 += delta*delta;
488 fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
489 // TEMPORARY UNTIL covariance properly calculated
490 fSigmaY2 = TMath::Max(fSigmaY2, Float_t(.1));
492 fZfitR[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
493 fZfitR[1] = (sumw * sumwxz - sumwx * sumwz) / det;
494 fZfit[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
495 fZfit[1] = (sumw * sumwxz - sumwx * sumwz) / det;
496 fYfitR[0] += fYref[0] + correction;
497 fYfitR[1] += fYref[1];
498 fYfit[0] = fYfitR[0];
499 fYfit[1] = fYfitR[1];
501 //printf("y0 = %7.3f tgy = %7.3f z0 = %7.3f tgz = %7.3f \n", fYfitR[0], fYfitR[1], fZfitR[0], fZfitR[1]);
507 //_____________________________________________________________________________
508 void AliTRDseed::UpdateUsed()
515 for (Int_t i = 0; i < fgTimeBins; i++) {
516 if (!fClusters[i]) continue;
517 if(!fUsable[i]) continue;
518 if ((fClusters[i]->IsUsed())) fNUsed++;
523 //_____________________________________________________________________________
524 Float_t AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror)
527 // Fit the Rieman tilt
530 // Fitting with tilting pads - kz not fixed
531 TLinearFitter fitterT2(4,"hyp4");
532 fitterT2.StoreData(kTRUE);
534 Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
537 fitterT2.ClearPoints();
539 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
541 if (!cseed[iLayer].IsOK()) continue;
542 Double_t tilt = cseed[iLayer].fTilt;
544 for (Int_t itime = 0; itime < fgTimeBins+1; itime++) {
546 if (!cseed[iLayer].fUsable[itime]) continue;
547 // x relative to the midle chamber
548 Double_t x = cseed[iLayer].fX[itime] + cseed[iLayer].fX0 - xref2;
549 Double_t y = cseed[iLayer].fY[itime];
550 Double_t z = cseed[iLayer].fZ[itime];
556 Double_t x2 = cseed[iLayer].fX[itime] + cseed[iLayer].fX0; // Global x
557 Double_t t = 1.0 / (x2*x2 + y*y);
559 uvt[0] = 2.0 * x2 * uvt[1];
560 uvt[2] = 2.0 * tilt * uvt[1];
561 uvt[3] = 2.0 * tilt *uvt[1] * x;
562 uvt[4] = 2.0 * (y + tilt * z) * uvt[1];
564 Double_t error = 2.0 * uvt[1];
566 error *= cseed[iLayer].fSigmaY;
569 error *= 0.2; //Default error
571 fitterT2.AddPoint(uvt,uvt[4],error);
579 Double_t rpolz0 = fitterT2.GetParameter(3);
580 Double_t rpolz1 = fitterT2.GetParameter(4);
583 // Linear fitter - not possible to make boundaries
584 // non accept non possible z and dzdx combination
586 Bool_t acceptablez = kTRUE;
587 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
588 if (!cseed[iLayer].IsOK()) continue;
589 Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
590 if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) acceptablez = kFALSE;
593 Double_t zmf = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
594 Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
595 fitterT2.FixParameter(3,zmf);
596 fitterT2.FixParameter(4,dzmf);
598 fitterT2.ReleaseParameter(3);
599 fitterT2.ReleaseParameter(4);
600 rpolz0 = fitterT2.GetParameter(3);
601 rpolz1 = fitterT2.GetParameter(4);
604 Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);
606 params[0] = fitterT2.GetParameter(0);
607 params[1] = fitterT2.GetParameter(1);
608 params[2] = fitterT2.GetParameter(2);
609 Double_t curvature = 1.0 + params[1] * params[1] - params[2] * params[0];
612 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
613 Double_t x = cseed[iLayer].fX0;
620 Double_t res2 = (x * params[0] + params[1]);
622 res2 = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
624 res2 = TMath::Sqrt(res2);
625 y = (1.0 - res2) / params[0];
629 Double_t x0 = -params[1] / params[0];
630 if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
631 Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1);
632 if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
633 Double_t res = (x - x0) / TMath::Sqrt(1.0 / (rm1*rm1) - (x-x0)*(x-x0));
634 if (params[0] < 0) res *= -1.0;
638 z = rpolz0 + rpolz1 * (x - xref2);
640 cseed[iLayer].fYref[0] = y;
641 cseed[iLayer].fYref[1] = dy;
642 cseed[iLayer].fZref[0] = z;
643 cseed[iLayer].fZref[1] = dz;
644 cseed[iLayer].fC = curvature;