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 "AliTRDcluster.h"
31 #include "AliTRDtracker.h"
32 #include "AliTRDtrackerV1.h"
36 //_____________________________________________________________________________
37 AliTRDseed::AliTRDseed()
58 // Default constructor
61 for (Int_t i = 0; i < knTimebins; i++) {
62 fX[i] = 0; // x position
63 fY[i] = 0; // y position
64 fZ[i] = 0; // z position
65 fIndexes[i] = 0; // Indexes
66 fClusters[i] = NULL; // Clusters
67 fUsable[i] = 0; // Indication - usable cluster
70 for (Int_t i = 0; i < 2; i++) {
71 fYref[i] = 0; // Reference y
72 fZref[i] = 0; // Reference z
73 fYfit[i] = 0; // Y fit position +derivation
74 fYfitR[i] = 0; // Y fit position +derivation
75 fZfit[i] = 0; // Z fit position
76 fZfitR[i] = 0; // Z fit position
77 fLabels[i] = 0; // Labels
82 //_____________________________________________________________________________
83 AliTRDseed::AliTRDseed(const AliTRDseed &s)
86 ,fPadLength(s.fPadLength)
107 for (Int_t i = 0; i < knTimebins; i++) {
108 fX[i] = s.fX[i]; // x position
109 fY[i] = s.fY[i]; // y position
110 fZ[i] = s.fZ[i]; // z position
111 fIndexes[i] = s.fIndexes[i]; // Indexes
112 fClusters[i] = s.fClusters[i]; // Clusters
113 fUsable[i] = s.fUsable[i]; // Indication - usable cluster
116 for (Int_t i = 0; i < 2; i++) {
117 fYref[i] = s.fYref[i]; // Reference y
118 fZref[i] = s.fZref[i]; // Reference z
119 fYfit[i] = s.fYfit[i]; // Y fit position +derivation
120 fYfitR[i] = s.fYfitR[i]; // Y fit position +derivation
121 fZfit[i] = s.fZfit[i]; // Z fit position
122 fZfitR[i] = s.fZfitR[i]; // Z fit position
123 fLabels[i] = s.fLabels[i]; // Labels
128 //_____________________________________________________________________________
129 AliTRDseed &AliTRDseed::operator=(const AliTRDseed &s)
132 // Assignment operator
136 ((AliTRDseed &) s).Copy(*this);
143 //_____________________________________________________________________________
144 void AliTRDseed::Copy(TObject &o) const
146 //printf("AliTRDseed::Copy()\n");
148 AliTRDseed &seed = (AliTRDseed &)o;
151 seed.fPadLength = fPadLength;
153 seed.fSigmaY = fSigmaY;
154 seed.fSigmaY2 = fSigmaY2;
155 seed.fMeanz = fMeanz;
156 seed.fZProb = fZProb;
159 seed.fNUsed = fNUsed;
161 seed.fNChange = fNChange;
162 seed.fMPads = fMPads;
166 seed.fChi2Z = fChi2Z;
167 for (Int_t i = 0; i < knTimebins; i++) {
171 seed.fIndexes[i] = fIndexes[i];
172 seed.fClusters[i] = fClusters[i];
173 seed.fUsable[i] = fUsable[i];
176 for (Int_t i = 0; i < 2; i++) {
177 seed.fYref[i] = fYref[i];
178 seed.fZref[i] = fZref[i];
179 seed.fYfit[i] = fYfit[i];
180 seed.fYfitR[i] = fYfitR[i];
181 seed.fZfit[i] = fZfit[i];
182 seed.fZfitR[i] = fZfitR[i];
183 seed.fLabels[i] = fLabels[i];
190 //_____________________________________________________________________________
191 void AliTRDseed::Reset()
197 for (Int_t i = 0; i < knTimebins; i++) {
198 fX[i] = 0; // X position
199 fY[i] = 0; // Y position
200 fZ[i] = 0; // Z position
201 fIndexes[i] = 0; // Indexes
202 fClusters[i] = NULL; // Clusters
206 for (Int_t i = 0; i < 2; i++) {
207 fYref[i] = 0; // Reference y
208 fZref[i] = 0; // Reference z
209 fYfit[i] = 0; // Y fit position +derivation
210 fYfitR[i] = 0; // Y fit position +derivation
211 fZfit[i] = 0; // Z fit position
212 fZfitR[i] = 0; // Z fit position
213 fLabels[i] = -1; // Labels
215 fSigmaY = 0; // "Robust" sigma in y
216 fSigmaY2 = 0; // "Robust" sigma in y
217 fMeanz = 0; // Mean vaue of z
218 fZProb = 0; // Max probbable z
220 fN = 0; // Number of associated clusters
221 fN2 = 0; // Number of not crossed
222 fNUsed = 0; // Number of used clusters
223 fNChange = 0; // Change z counter
227 //_____________________________________________________________________________
228 void AliTRDseed::CookLabels()
231 // Cook 2 labels for seed
238 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
239 if (!fClusters[i]) continue;
240 for (Int_t ilab = 0; ilab < 3; ilab++) {
241 if (fClusters[i]->GetLabel(ilab) >= 0) {
242 labels[nlab] = fClusters[i]->GetLabel(ilab);
248 Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
257 //_____________________________________________________________________________
258 void AliTRDseed::UseClusters()
264 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
265 if (!fClusters[i]) continue;
266 if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
271 //_____________________________________________________________________________
272 void AliTRDseed::Update()
280 // linear fit on the y direction with respect to the reference direction.
281 // The residuals for each x (x = xc - x0) are deduced from:
283 // the tilting correction is written :
284 // y = yc + h*(zc-zt) (2)
285 // yt = y0+dy/dx*x (3)
286 // zt = z0+dz/dx*x (4)
287 // from (1),(2),(3) and (4)
288 // dy = yc - y0 - (dy/dx + h*dz/dx)*x + h*(zc-z0)
289 // the last term introduces the correction on y direction due to tilting pads. There are 2 ways to account for this:
290 // 1. use tilting correction for calculating the y
291 // 2. neglect tilting correction here and account for it in the error parametrization of the tracklet.
293 const Float_t kRatio = 0.8;
294 const Int_t kClmin = 5;
295 const Float_t kmaxtan = 2;
297 if (TMath::Abs(fYref[1]) > kmaxtan){
298 //printf("Exit: Abs(fYref[1]) = %3.3f, kmaxtan = %3.3f\n", TMath::Abs(fYref[1]), kmaxtan);
299 return; // Track inclined too much
302 Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
303 Float_t ycrosscor = fPadLength * fTilt * 0.5; // Y correction for crossing
314 // Buffering: Leave it constant fot Performance issues
315 Int_t zints[knTimebins]; // Histograming of the z coordinate
316 // Get 1 and second max probable coodinates in z
317 Int_t zouts[2*knTimebins];
318 Float_t allowedz[knTimebins]; // Allowed z for given time bin
319 Float_t yres[knTimebins]; // Residuals from reference
320 //Float_t anglecor = fTilt * fZref[1]; // Correction to the angle
325 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
327 if (!fClusters[i]) continue;
328 if(!fClusters[i]->IsInChamber()) continue;
330 //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] + fTilt*(fZ[i] - fZref[0]);
331 yres[i] = fY[i] - fTilt*(fZ[i] - (fZref[0] - fX[i]*fZref[1]));
332 zints[fN] = Int_t(fZ[i]);
337 //printf("Exit fN < kClmin: fN = %d\n", fN);
340 Int_t nz = AliTRDtracker::Freq(fN, zints, zouts, kFALSE);
342 if (nz <= 1) zouts[3] = 0;
343 if (zouts[1] + zouts[3] < kClmin) {
344 //printf("Exit zouts[1] = %d, zouts[3] = %d\n",zouts[1],zouts[3]);
348 // Z distance bigger than pad - length
349 if (TMath::Abs(zouts[0]-zouts[2]) > 12.0) zouts[3] = 0;
351 Int_t breaktime = -1;
352 Bool_t mbefore = kFALSE;
353 Int_t cumul[knTimebins][2];
354 Int_t counts[2] = { 0, 0 };
359 // Find the break time allowing one chage on pad-rows
360 // with maximal number of accepted clusters
363 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
364 cumul[i][0] = counts[0];
365 cumul[i][1] = counts[1];
366 if (TMath::Abs(fZ[i]-zouts[0]) < 2) counts[0]++;
367 if (TMath::Abs(fZ[i]-zouts[2]) < 2) counts[1]++;
370 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
371 Int_t after = cumul[AliTRDtrackerV1::GetNTimeBins()][0] - cumul[i][0];
372 Int_t before = cumul[i][1];
373 if (after + before > maxcount) {
374 maxcount = after + before;
378 after = cumul[AliTRDtrackerV1::GetNTimeBins()-1][1] - cumul[i][1];
379 before = cumul[i][0];
380 if (after + before > maxcount) {
381 maxcount = after + before;
391 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
392 if (i > breaktime) allowedz[i] = mbefore ? zouts[2] : zouts[0];
393 if (i <= breaktime) allowedz[i] = (!mbefore) ? zouts[2] : zouts[0];
396 if (((allowedz[0] > allowedz[AliTRDtrackerV1::GetNTimeBins()]) && (fZref[1] < 0)) ||
397 ((allowedz[0] < allowedz[AliTRDtrackerV1::GetNTimeBins()]) && (fZref[1] > 0))) {
399 // Tracklet z-direction not in correspondance with track z direction
402 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
403 allowedz[i] = zouts[0]; // Only longest taken
409 // Cross pad -row tracklet - take the step change into account
411 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
412 if (!fClusters[i]) continue;
413 if(!fClusters[i]->IsInChamber()) continue;
414 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
416 //yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i] /*+ fTilt*(fZ[i] - fZref[0])*/;
417 yres[i] = fY[i] - fTilt*(fZ[i] - (fZref[0] - fX[i]*fZref[1]));
418 /* if (TMath::Abs(fZ[i] - fZProb) > 2) {
419 if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
420 if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
425 Double_t yres2[knTimebins];
428 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
429 if (!fClusters[i]) continue;
430 if(!fClusters[i]->IsInChamber()) continue;
431 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
432 yres2[fN2] = yres[i];
436 //printf("Exit fN2 < kClmin: fN2 = %d\n", fN2);
440 AliMathBase::EvaluateUni(fN2,yres2,mean,sigma, Int_t(fN2*kRatio-2.));
441 if (sigma < sigmaexp * 0.8) {
459 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
462 if (!fClusters[i]) continue;
463 if (!fClusters[i]->IsInChamber()) continue;
464 if (TMath::Abs(fZ[i] - allowedz[i]) > 2){fClusters[i] = NULL; continue;}
465 if (TMath::Abs(yres[i] - mean) > 4.0 * sigma){fClusters[i] = NULL; continue;}
468 fMPads += fClusters[i]->GetNPads();
469 Float_t weight = 1.0;
470 if (fClusters[i]->GetNPads() > 4) weight = 0.5;
471 if (fClusters[i]->GetNPads() > 5) weight = 0.2;
475 //printf("x = %7.3f dy = %7.3f fit %7.3f\n", x, yres[i], fY[i]-yres[i]);
479 sumwx2 += x*x * weight;
480 sumwy += weight * yres[i];
481 sumwxy += weight * (yres[i]) * x;
482 sumwz += weight * fZ[i];
483 sumwxz += weight * fZ[i] * x;
488 //printf("Exit fN2 < kClmin(2): fN2 = %d\n",fN2);
492 fMeanz = sumwz / sumw;
493 Float_t correction = 0;
495 // Tracklet on boundary
496 if (fMeanz < fZProb) correction = ycrosscor;
497 if (fMeanz > fZProb) correction = -ycrosscor;
500 Double_t det = sumw * sumwx2 - sumwx * sumwx;
501 fYfitR[0] = (sumwx2 * sumwy - sumwx * sumwxy) / det;
502 fYfitR[1] = (sumw * sumwxy - sumwx * sumwy) / det;
505 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins()+1; i++) {
506 if (!fUsable[i]) continue;
507 Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
508 fSigmaY2 += delta*delta;
510 fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
511 // TEMPORARY UNTIL covariance properly calculated
512 fSigmaY2 = TMath::Max(fSigmaY2, Float_t(.1));
514 fZfitR[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
515 fZfitR[1] = (sumw * sumwxz - sumwx * sumwz) / det;
516 fZfit[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
517 fZfit[1] = (sumw * sumwxz - sumwx * sumwz) / det;
518 // fYfitR[0] += fYref[0] + correction;
519 // fYfitR[1] += fYref[1];
520 fYfit[0] = fYfitR[0];
521 fYfit[1] = -fYfitR[1];
523 //printf("y0 = %7.3f tgy = %7.3f z0 = %7.3f tgz = %7.3f \n", fYfitR[0], fYfitR[1], fZfitR[0], fZfitR[1]);
529 //_____________________________________________________________________________
530 void AliTRDseed::UpdateUsed()
537 for (Int_t i = 0; i < AliTRDtrackerV1::GetNTimeBins(); i++) {
538 if (!fClusters[i]) continue;
539 if(!fUsable[i]) continue;
540 if ((fClusters[i]->IsUsed())) fNUsed++;
545 //_____________________________________________________________________________
546 Float_t AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror)
549 // Fit the Rieman tilt
552 // Fitting with tilting pads - kz not fixed
553 TLinearFitter fitterT2(4,"hyp4");
554 fitterT2.StoreData(kTRUE);
556 Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
559 fitterT2.ClearPoints();
561 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
563 if (!cseed[iLayer].IsOK()) continue;
564 Double_t tilt = cseed[iLayer].fTilt;
566 for (Int_t itime = 0; itime < AliTRDtrackerV1::GetNTimeBins()+1; itime++) {
568 if (!cseed[iLayer].fUsable[itime]) continue;
569 // x relative to the midle chamber
570 Double_t x = cseed[iLayer].fX[itime] + cseed[iLayer].fX0 - xref2;
571 Double_t y = cseed[iLayer].fY[itime];
572 Double_t z = cseed[iLayer].fZ[itime];
578 Double_t x2 = cseed[iLayer].fX[itime] + cseed[iLayer].fX0; // Global x
579 Double_t t = 1.0 / (x2*x2 + y*y);
581 uvt[0] = 2.0 * x2 * uvt[1];
582 uvt[2] = 2.0 * tilt * uvt[1];
583 uvt[3] = 2.0 * tilt *uvt[1] * x;
584 uvt[4] = 2.0 * (y + tilt * z) * uvt[1];
586 Double_t error = 2.0 * uvt[1];
588 error *= cseed[iLayer].fSigmaY;
591 error *= 0.2; //Default error
593 fitterT2.AddPoint(uvt,uvt[4],error);
601 Double_t rpolz0 = fitterT2.GetParameter(3);
602 Double_t rpolz1 = fitterT2.GetParameter(4);
605 // Linear fitter - not possible to make boundaries
606 // non accept non possible z and dzdx combination
608 Bool_t acceptablez = kTRUE;
609 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
610 if (!cseed[iLayer].IsOK()) continue;
611 Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
612 if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) acceptablez = kFALSE;
615 Double_t zmf = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
616 Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
617 fitterT2.FixParameter(3,zmf);
618 fitterT2.FixParameter(4,dzmf);
620 fitterT2.ReleaseParameter(3);
621 fitterT2.ReleaseParameter(4);
622 rpolz0 = fitterT2.GetParameter(3);
623 rpolz1 = fitterT2.GetParameter(4);
626 Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);
628 params[0] = fitterT2.GetParameter(0);
629 params[1] = fitterT2.GetParameter(1);
630 params[2] = fitterT2.GetParameter(2);
631 Double_t curvature = 1.0 + params[1] * params[1] - params[2] * params[0];
634 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
635 Double_t x = cseed[iLayer].fX0;
642 Double_t res2 = (x * params[0] + params[1]);
644 res2 = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
646 res2 = TMath::Sqrt(res2);
647 y = (1.0 - res2) / params[0];
651 Double_t x0 = -params[1] / params[0];
652 if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
653 Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1);
654 if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
655 Double_t res = (x - x0) / TMath::Sqrt((1./rm1-(x-x0))*(1./rm1+(x-x0)));
656 if (params[0] < 0) res *= -1.0;
660 z = rpolz0 + rpolz1 * (x - xref2);
662 cseed[iLayer].fYref[0] = y;
663 cseed[iLayer].fYref[1] = dy;
664 cseed[iLayer].fZref[0] = z;
665 cseed[iLayer].fZref[1] = dz;
666 cseed[iLayer].fC = curvature;