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"
33 #include "AliTRDtrackerV1.h"
37 //_____________________________________________________________________________
38 AliTRDseed::AliTRDseed()
59 // Default constructor
62 for (Int_t i = 0; i < knTimebins; i++) {
63 fX[i] = 0; // x position
64 fY[i] = 0; // y position
65 fZ[i] = 0; // z position
66 fIndexes[i] = 0; // Indexes
67 fClusters[i] = 0x0; // Clusters
68 fUsable[i] = 0; // Indication - usable cluster
71 for (Int_t i = 0; i < 2; i++) {
72 fYref[i] = 0; // Reference y
73 fZref[i] = 0; // Reference z
74 fYfit[i] = 0; // Y fit position +derivation
75 fYfitR[i] = 0; // Y fit position +derivation
76 fZfit[i] = 0; // Z fit position
77 fZfitR[i] = 0; // Z fit position
78 fLabels[i] = 0; // Labels
83 //_____________________________________________________________________________
84 AliTRDseed::AliTRDseed(const AliTRDseed &s)
87 ,fPadLength(s.fPadLength)
108 for (Int_t i = 0; i < knTimebins; i++) {
109 fX[i] = s.fX[i]; // x position
110 fY[i] = s.fY[i]; // y position
111 fZ[i] = s.fZ[i]; // z position
112 fIndexes[i] = s.fIndexes[i]; // Indexes
113 fClusters[i] = s.fClusters[i]; // Clusters
114 fUsable[i] = s.fUsable[i]; // Indication - usable cluster
117 for (Int_t i = 0; i < 2; i++) {
118 fYref[i] = s.fYref[i]; // Reference y
119 fZref[i] = s.fZref[i]; // Reference z
120 fYfit[i] = s.fYfit[i]; // Y fit position +derivation
121 fYfitR[i] = s.fYfitR[i]; // Y fit position +derivation
122 fZfit[i] = s.fZfit[i]; // Z fit position
123 fZfitR[i] = s.fZfitR[i]; // Z fit position
124 fLabels[i] = s.fLabels[i]; // Labels
129 //_____________________________________________________________________________
130 void AliTRDseed::Copy(TObject &o) const
132 //printf("AliTRDseed::Copy()\n");
134 AliTRDseed &seed = (AliTRDseed &)o;
137 seed.fPadLength = fPadLength;
139 seed.fSigmaY = fSigmaY;
140 seed.fSigmaY2 = fSigmaY2;
141 seed.fMeanz = fMeanz;
142 seed.fZProb = fZProb;
145 seed.fNUsed = fNUsed;
147 seed.fNChange = fNChange;
148 seed.fMPads = fMPads;
152 seed.fChi2Z = fChi2Z;
153 for (Int_t i = 0; i < knTimebins; i++) {
157 seed.fIndexes[i] = fIndexes[i];
158 seed.fClusters[i] = fClusters[i];
159 seed.fUsable[i] = fUsable[i];
162 for (Int_t i = 0; i < 2; i++) {
163 seed.fYref[i] = fYref[i];
164 seed.fZref[i] = fZref[i];
165 seed.fYfit[i] = fYfit[i];
166 seed.fYfitR[i] = fYfitR[i];
167 seed.fZfit[i] = fZfit[i];
168 seed.fZfitR[i] = fZfitR[i];
169 seed.fLabels[i] = fLabels[i];
176 //_____________________________________________________________________________
177 void AliTRDseed::Reset()
183 for (Int_t i = 0; i < knTimebins; i++) {
184 fX[i] = 0; // X position
185 fY[i] = 0; // Y position
186 fZ[i] = 0; // Z position
187 fIndexes[i] = 0; // Indexes
188 fClusters[i] = 0x0; // Clusters
192 for (Int_t i = 0; i < 2; i++) {
193 fYref[i] = 0; // Reference y
194 fZref[i] = 0; // Reference z
195 fYfit[i] = 0; // Y fit position +derivation
196 fYfitR[i] = 0; // Y fit position +derivation
197 fZfit[i] = 0; // Z fit position
198 fZfitR[i] = 0; // Z fit position
199 fLabels[i] = -1; // Labels
201 fSigmaY = 0; // "Robust" sigma in y
202 fSigmaY2 = 0; // "Robust" sigma in y
203 fMeanz = 0; // Mean vaue of z
204 fZProb = 0; // Max probbable z
206 fN = 0; // Number of associated clusters
207 fN2 = 0; // Number of not crossed
208 fNUsed = 0; // Number of used clusters
209 fNChange = 0; // Change z counter
213 //_____________________________________________________________________________
214 void AliTRDseed::CookLabels()
217 // Cook 2 labels for seed
224 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
225 if (!fClusters[i]) continue;
226 for (Int_t ilab = 0; ilab < 3; ilab++) {
227 if (fClusters[i]->GetLabel(ilab) >= 0) {
228 labels[nlab] = fClusters[i]->GetLabel(ilab);
234 Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
243 //_____________________________________________________________________________
244 void AliTRDseed::UseClusters()
250 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
251 if (!fClusters[i]) continue;
252 if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
257 //_____________________________________________________________________________
258 void AliTRDseed::Update()
266 // linear fit on the y direction with respect to the reference direction.
267 // The residuals for each x (x = xc - x0) are deduced from:
269 // the tilting correction is written :
270 // y = yc + h*(zc-zt) (2)
271 // yt = y0+dy/dx*x (3)
272 // zt = z0+dz/dx*x (4)
273 // from (1),(2),(3) and (4)
274 // dy = yc - y0 - (dy/dx + h*dz/dx)*x + h*(zc-z0)
275 // the last term introduces the correction on y direction due to tilting pads. There are 2 ways to account for this:
276 // 1. use tilting correction for calculating the y
277 // 2. neglect tilting correction here and account for it in the error parametrization of the tracklet.
279 const Float_t kRatio = 0.8;
280 const Int_t kClmin = 5;
281 const Float_t kmaxtan = 2;
283 if (TMath::Abs(fYref[1]) > kmaxtan){
284 //printf("Exit: Abs(fYref[1]) = %3.3f, kmaxtan = %3.3f\n", TMath::Abs(fYref[1]), kmaxtan);
285 return; // Track inclined too much
288 Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
289 Float_t ycrosscor = fPadLength * fTilt * 0.5; // Y correction for crossing
300 // Buffering: Leave it constant fot Performance issues
301 Int_t zints[knTimebins]; // Histograming of the z coordinate
302 // Get 1 and second max probable coodinates in z
303 Int_t zouts[2*knTimebins];
304 Float_t allowedz[knTimebins]; // Allowed z for given time bin
305 Float_t yres[knTimebins]; // Residuals from reference
306 //Float_t anglecor = fTilt * fZref[1]; // Correction to the angle
311 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
313 if (!fClusters[i]) continue;
314 if(!fClusters[i]->IsInChamber()) continue;
316 //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] + fTilt*(fZ[i] - fZref[0]);
317 yres[i] = fY[i] - fTilt*(fZ[i] - (fZref[0] - fX[i]*fZref[1]));
318 zints[fN] = Int_t(fZ[i]);
323 //printf("Exit fN < kClmin: fN = %d\n", fN);
326 Int_t nz = AliTRDtracker::Freq(fN, zints, zouts, kFALSE);
328 if (nz <= 1) zouts[3] = 0;
329 if (zouts[1] + zouts[3] < kClmin) {
330 //printf("Exit zouts[1] = %d, zouts[3] = %d\n",zouts[1],zouts[3]);
334 // Z distance bigger than pad - length
335 if (TMath::Abs(zouts[0]-zouts[2]) > 12.0) zouts[3] = 0;
337 Int_t breaktime = -1;
338 Bool_t mbefore = kFALSE;
339 Int_t cumul[knTimebins][2];
340 Int_t counts[2] = { 0, 0 };
345 // Find the break time allowing one chage on pad-rows
346 // with maximal number of accepted clusters
349 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
350 cumul[i][0] = counts[0];
351 cumul[i][1] = counts[1];
352 if (TMath::Abs(fZ[i]-zouts[0]) < 2) counts[0]++;
353 if (TMath::Abs(fZ[i]-zouts[2]) < 2) counts[1]++;
356 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
357 Int_t after = cumul[AliTRDtrackerV1::GetNTimeBins()][0] - cumul[i][0];
358 Int_t before = cumul[i][1];
359 if (after + before > maxcount) {
360 maxcount = after + before;
364 after = cumul[AliTRDtrackerV1::GetNTimeBins()-1][1] - cumul[i][1];
365 before = cumul[i][0];
366 if (after + before > maxcount) {
367 maxcount = after + before;
377 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
378 if (i > breaktime) allowedz[i] = mbefore ? zouts[2] : zouts[0];
379 if (i <= breaktime) allowedz[i] = (!mbefore) ? zouts[2] : zouts[0];
382 if (((allowedz[0] > allowedz[AliTRDtrackerV1::GetNTimeBins()]) && (fZref[1] < 0)) ||
383 ((allowedz[0] < allowedz[AliTRDtrackerV1::GetNTimeBins()]) && (fZref[1] > 0))) {
385 // Tracklet z-direction not in correspondance with track z direction
388 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
389 allowedz[i] = zouts[0]; // Only longest taken
395 // Cross pad -row tracklet - take the step change into account
397 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
398 if (!fClusters[i]) continue;
399 if(!fClusters[i]->IsInChamber()) continue;
400 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
402 //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] /*+ fTilt*(fZ[i] - fZref[0])*/;
403 yres[i] = fY[i] - fTilt*(fZ[i] - (fZref[0] - fX[i]*fZref[1]));
404 /* if (TMath::Abs(fZ[i] - fZProb) > 2) {
405 if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
406 if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
411 Double_t yres2[knTimebins];
414 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
415 if (!fClusters[i]) continue;
416 if(!fClusters[i]->IsInChamber()) continue;
417 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
418 yres2[fN2] = yres[i];
422 //printf("Exit fN2 < kClmin: fN2 = %d\n", fN2);
426 AliMathBase::EvaluateUni(fN2,yres2,mean,sigma, Int_t(fN2*kRatio-2.));
427 if (sigma < sigmaexp * 0.8) {
445 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
448 if (!fClusters[i]) continue;
449 if (!fClusters[i]->IsInChamber()) continue;
450 if (TMath::Abs(fZ[i] - allowedz[i]) > 2){fClusters[i] = 0x0; continue;}
451 if (TMath::Abs(yres[i] - mean) > 4.0 * sigma){fClusters[i] = 0x0; continue;}
454 fMPads += fClusters[i]->GetNPads();
455 Float_t weight = 1.0;
456 if (fClusters[i]->GetNPads() > 4) weight = 0.5;
457 if (fClusters[i]->GetNPads() > 5) weight = 0.2;
461 //printf("x = %7.3f dy = %7.3f fit %7.3f\n", x, yres[i], fY[i]-yres[i]);
465 sumwx2 += x*x * weight;
466 sumwy += weight * yres[i];
467 sumwxy += weight * (yres[i]) * x;
468 sumwz += weight * fZ[i];
469 sumwxz += weight * fZ[i] * x;
474 //printf("Exit fN2 < kClmin(2): fN2 = %d\n",fN2);
478 fMeanz = sumwz / sumw;
479 Float_t correction = 0;
481 // Tracklet on boundary
482 if (fMeanz < fZProb) correction = ycrosscor;
483 if (fMeanz > fZProb) correction = -ycrosscor;
486 Double_t det = sumw * sumwx2 - sumwx * sumwx;
487 fYfitR[0] = (sumwx2 * sumwy - sumwx * sumwxy) / det;
488 fYfitR[1] = (sumw * sumwxy - sumwx * sumwy) / det;
491 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
492 if (!fUsable[i]) continue;
493 Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
494 fSigmaY2 += delta*delta;
496 fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
497 // TEMPORARY UNTIL covariance properly calculated
498 fSigmaY2 = TMath::Max(fSigmaY2, Float_t(.1));
500 fZfitR[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
501 fZfitR[1] = (sumw * sumwxz - sumwx * sumwz) / det;
502 fZfit[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
503 fZfit[1] = (sumw * sumwxz - sumwx * sumwz) / det;
504 // fYfitR[0] += fYref[0] + correction;
505 // fYfitR[1] += fYref[1];
506 fYfit[0] = fYfitR[0];
507 fYfit[1] = -fYfitR[1];
509 //printf("y0 = %7.3f tgy = %7.3f z0 = %7.3f tgz = %7.3f \n", fYfitR[0], fYfitR[1], fZfitR[0], fZfitR[1]);
515 //_____________________________________________________________________________
516 void AliTRDseed::UpdateUsed()
523 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
524 if (!fClusters[i]) continue;
525 if(!fUsable[i]) continue;
526 if ((fClusters[i]->IsUsed())) fNUsed++;
531 //_____________________________________________________________________________
532 Float_t AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror)
535 // Fit the Rieman tilt
538 // Fitting with tilting pads - kz not fixed
539 TLinearFitter fitterT2(4,"hyp4");
540 fitterT2.StoreData(kTRUE);
542 Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
545 fitterT2.ClearPoints();
547 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
549 if (!cseed[iLayer].IsOK()) continue;
550 Double_t tilt = cseed[iLayer].fTilt;
552 for (Int_t itime = 0; itime < AliTRDtrackerV1::GetNTimeBins()+1; itime++) {
554 if (!cseed[iLayer].fUsable[itime]) continue;
555 // x relative to the midle chamber
556 Double_t x = cseed[iLayer].fX[itime] + cseed[iLayer].fX0 - xref2;
557 Double_t y = cseed[iLayer].fY[itime];
558 Double_t z = cseed[iLayer].fZ[itime];
564 Double_t x2 = cseed[iLayer].fX[itime] + cseed[iLayer].fX0; // Global x
565 Double_t t = 1.0 / (x2*x2 + y*y);
567 uvt[0] = 2.0 * x2 * uvt[1];
568 uvt[2] = 2.0 * tilt * uvt[1];
569 uvt[3] = 2.0 * tilt *uvt[1] * x;
570 uvt[4] = 2.0 * (y + tilt * z) * uvt[1];
572 Double_t error = 2.0 * uvt[1];
574 error *= cseed[iLayer].fSigmaY;
577 error *= 0.2; //Default error
579 fitterT2.AddPoint(uvt,uvt[4],error);
587 Double_t rpolz0 = fitterT2.GetParameter(3);
588 Double_t rpolz1 = fitterT2.GetParameter(4);
591 // Linear fitter - not possible to make boundaries
592 // non accept non possible z and dzdx combination
594 Bool_t acceptablez = kTRUE;
595 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
596 if (!cseed[iLayer].IsOK()) continue;
597 Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
598 if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) acceptablez = kFALSE;
601 Double_t zmf = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
602 Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
603 fitterT2.FixParameter(3,zmf);
604 fitterT2.FixParameter(4,dzmf);
606 fitterT2.ReleaseParameter(3);
607 fitterT2.ReleaseParameter(4);
608 rpolz0 = fitterT2.GetParameter(3);
609 rpolz1 = fitterT2.GetParameter(4);
612 Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);
614 params[0] = fitterT2.GetParameter(0);
615 params[1] = fitterT2.GetParameter(1);
616 params[2] = fitterT2.GetParameter(2);
617 Double_t curvature = 1.0 + params[1] * params[1] - params[2] * params[0];
620 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
621 Double_t x = cseed[iLayer].fX0;
628 Double_t res2 = (x * params[0] + params[1]);
630 res2 = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
632 res2 = TMath::Sqrt(res2);
633 y = (1.0 - res2) / params[0];
637 Double_t x0 = -params[1] / params[0];
638 if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
639 Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1);
640 if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
641 Double_t res = (x - x0) / TMath::Sqrt((1./rm1-(x-x0))*(1./rm1+(x-x0)));
642 if (params[0] < 0) res *= -1.0;
646 z = rpolz0 + rpolz1 * (x - xref2);
648 cseed[iLayer].fYref[0] = y;
649 cseed[iLayer].fYref[1] = dy;
650 cseed[iLayer].fZref[0] = z;
651 cseed[iLayer].fZref[1] = dz;
652 cseed[iLayer].fC = curvature;