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 "AliTRDseed.h"
28 #include "AliTRDcluster.h"
29 #include "AliTRDtracker.h"
33 //_____________________________________________________________________________
34 AliTRDseed::AliTRDseed()
55 // Default constructor
58 for (Int_t i = 0; i < 25; i++) {
59 fX[i] = 0; // x position
60 fY[i] = 0; // y position
61 fZ[i] = 0; // z position
62 fIndexes[i] = 0; // Indexes
63 fClusters[i] = 0x0; // Clusters
64 fUsable[i] = 0; // Indication - usable cluster
67 for (Int_t i = 0; i < 2; i++) {
68 fYref[i] = 0; // Reference y
69 fZref[i] = 0; // Reference z
70 fYfit[i] = 0; // Y fit position +derivation
71 fYfitR[i] = 0; // Y fit position +derivation
72 fZfit[i] = 0; // Z fit position
73 fZfitR[i] = 0; // Z fit position
74 fLabels[i] = 0; // Labels
79 //_____________________________________________________________________________
80 AliTRDseed::AliTRDseed(const AliTRDseed &s)
104 for (Int_t i = 0; i < 25; i++) {
105 fX[i] = 0; // x position
106 fY[i] = 0; // y position
107 fZ[i] = 0; // z position
108 fIndexes[i] = 0; // Indexes
109 fClusters[i] = 0x0; // Clusters
110 fUsable[i] = 0; // Indication - usable cluster
113 for (Int_t i = 0; i < 2; i++) {
114 fYref[i] = 0; // Reference y
115 fZref[i] = 0; // Reference z
116 fYfit[i] = 0; // Y fit position +derivation
117 fYfitR[i] = 0; // Y fit position +derivation
118 fZfit[i] = 0; // Z fit position
119 fZfitR[i] = 0; // Z fit position
120 fLabels[i] = 0; // Labels
125 //_____________________________________________________________________________
126 void AliTRDseed::Reset()
132 for (Int_t i = 0; i < 25; i++) {
133 fX[i] = 0; // X position
134 fY[i] = 0; // Y position
135 fZ[i] = 0; // Z position
136 fIndexes[i] = 0; // Indexes
137 fClusters[i] = 0; // Clusters
141 for (Int_t i = 0; i < 2; i++) {
142 fYref[i] = 0; // Reference y
143 fZref[i] = 0; // Reference z
144 fYfit[i] = 0; // Y fit position +derivation
145 fYfitR[i] = 0; // Y fit position +derivation
146 fZfit[i] = 0; // Z fit position
147 fZfitR[i] = 0; // Z fit position
148 fLabels[i] = -1; // Labels
150 fSigmaY = 0; // "Robust" sigma in y
151 fSigmaY2 = 0; // "Robust" sigma in y
152 fMeanz = 0; // Mean vaue of z
153 fZProb = 0; // Max probbable z
155 fN = 0; // Number of associated clusters
156 fN2 = 0; // Number of not crossed
157 fNUsed = 0; // Number of used clusters
158 fNChange = 0; // Change z counter
162 //_____________________________________________________________________________
163 void AliTRDseed::CookLabels()
166 // Cook 2 labels for seed
173 for (Int_t i = 0; i < 25; i++) {
174 if (!fClusters[i]) continue;
175 for (Int_t ilab = 0; ilab < 3; ilab++) {
176 if (fClusters[i]->GetLabel(ilab) >= 0) {
177 labels[nlab] = fClusters[i]->GetLabel(ilab);
183 Int_t nlab2 = AliTRDtracker::Freq(nlab,labels,out,kTRUE);
192 //_____________________________________________________________________________
193 void AliTRDseed::UseClusters()
199 for (Int_t i = 0; i < 25; i++) {
200 if (!fClusters[i]) continue;
201 if (!(fClusters[i]->IsUsed())) fClusters[i]->Use();
206 //_____________________________________________________________________________
207 void AliTRDseed::Update()
213 const Float_t kRatio = 0.8;
214 const Int_t kClmin = 6;
215 const Float_t kmaxtan = 2;
217 if (TMath::Abs(fYref[1]) > kmaxtan) return; // Track inclined too much
219 Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
220 Float_t ycrosscor = fPadLength * fTilt * 0.5; // Y correction for crossing
231 Int_t zints[25]; // Histograming of the z coordinate
232 // Get 1 and second max probable coodinates in z
234 Float_t allowedz[25]; // Allowed z for given time bin
235 Float_t yres[25]; // Residuals from reference
236 Float_t anglecor = fTilt * fZref[1]; // Correction to the angle
241 for (Int_t i = 0; i < 25; i++) {
243 if (!fClusters[i]) continue;
244 yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i]; // Residual y
245 zints[fN] = Int_t(fZ[i]);
249 if (fN < kClmin) return;
250 Int_t nz = AliTRDtracker::Freq(fN,zints,zouts,kFALSE);
252 if (nz <= 1) zouts[3] = 0;
253 if (zouts[1] + zouts[3] < kClmin) return;
255 // Z distance bigger than pad - length
256 if (TMath::Abs(zouts[0]-zouts[2]) > 12.0) {
260 Int_t breaktime = -1;
261 Bool_t mbefore = kFALSE;
263 Int_t counts[2] = { 0, 0 };
268 // Find the break time allowing one chage on pad-rows
269 // with maximal numebr of accepted clusters
272 for (Int_t i = 0; i < 25; i++) {
273 cumul[i][0] = counts[0];
274 cumul[i][1] = counts[1];
275 if (TMath::Abs(fZ[i]-zouts[0]) < 2) counts[0]++;
276 if (TMath::Abs(fZ[i]-zouts[2]) < 2) counts[1]++;
279 for (Int_t i = 0; i < 24; i++) {
280 Int_t after = cumul[24][0] - cumul[i][0];
281 Int_t before = cumul[i][1];
282 if (after + before > maxcount) {
283 maxcount = after + before;
287 after = cumul[24][1] - cumul[i][1];
288 before = cumul[i][0];
289 if (after + before > maxcount) {
290 maxcount = after + before;
300 for (Int_t i = 0; i < 25; i++) {
301 if (i > breaktime) allowedz[i] = mbefore ? zouts[2] : zouts[0];
302 if (i <= breaktime) allowedz[i] = (!mbefore) ? zouts[2] : zouts[0];
305 if (((allowedz[0] > allowedz[24]) && (fZref[1] < 0)) ||
306 ((allowedz[0] < allowedz[24]) && (fZref[1] > 0))) {
308 // Tracklet z-direction not in correspondance with track z direction
311 for (Int_t i = 0; i < 25; i++) {
312 allowedz[i] = zouts[0]; // Only longest taken
318 // Cross pad -row tracklet - take the step change into account
320 for (Int_t i = 0; i < 25; i++) {
321 if (!fClusters[i]) continue;
322 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
323 yres[i] = fY[i] - fYref[0] - (fYref[1] + anglecor) * fX[i]; // Residual y
324 if (TMath::Abs(fZ[i] - fZProb) > 2) {
325 if (fZ[i] > fZProb) yres[i] += fTilt * fPadLength;
326 if (fZ[i] < fZProb) yres[i] -= fTilt * fPadLength;
334 for (Int_t i = 0; i < 25; i++) {
335 if (!fClusters[i]) continue;
336 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
337 yres2[fN2] = yres[i];
344 EvaluateUni(fN2,yres2,mean,sigma,Int_t(fN2*kRatio-2));
345 if (sigma < sigmaexp * 0.8) {
363 for (Int_t i = 0; i < 25; i++) {
366 if (!fClusters[i]) continue;
367 if (TMath::Abs(fZ[i] - allowedz[i]) > 2) continue;
368 if (TMath::Abs(yres[i] - mean) > 4.0 * sigma) continue;
371 fMPads += fClusters[i]->GetNPads();
372 Float_t weight = 1.0;
373 if (fClusters[i]->GetNPads() > 4) weight = 0.5;
374 if (fClusters[i]->GetNPads() > 5) weight = 0.2;
379 sumwx2 += x*x * weight;
380 sumwy += weight * yres[i];
381 sumwxy += weight * (yres[i]) * x;
382 sumwz += weight * fZ[i];
383 sumwxz += weight * fZ[i] * x;
391 fMeanz = sumwz / sumw;
392 Float_t correction = 0;
394 // Tracklet on boundary
395 if (fMeanz < fZProb) correction = ycrosscor;
396 if (fMeanz > fZProb) correction = -ycrosscor;
399 Double_t det = sumw * sumwx2 - sumwx * sumwx;
400 fYfitR[0] = (sumwx2 * sumwy - sumwx * sumwxy) / det;
401 fYfitR[1] = (sumw * sumwxy - sumwx * sumwy) / det;
404 for (Int_t i = 0; i < 25; i++) {
405 if (!fUsable[i]) continue;
406 Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
407 fSigmaY2 += delta*delta;
409 fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
411 fZfitR[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
412 fZfitR[1] = (sumw * sumwxz - sumwx * sumwz) / det;
413 fZfit[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
414 fZfit[1] = (sumw * sumwxz - sumwx * sumwz) / det;
415 fYfitR[0] += fYref[0] + correction;
416 fYfitR[1] += fYref[1];
417 fYfit[0] = fYfitR[0];
418 fYfit[1] = fYfitR[1];
424 //_____________________________________________________________________________
425 void AliTRDseed::UpdateUsed()
432 for (Int_t i = 0; i < 25; i++) {
433 if (!fClusters[i]) continue;
434 if ((fClusters[i]->IsUsed())) fNUsed++;
439 //_____________________________________________________________________________
440 void AliTRDseed::EvaluateUni(Int_t nvectors, Double_t *data, Double_t &mean
441 , Double_t &sigma, Int_t hh)
444 // Robust estimator in 1D case MI version
446 // For the univariate case
447 // estimates of location and scatter are returned in mean and sigma parameters
448 // the algorithm works on the same principle as in multivariate case -
449 // it finds a subset of size hh with smallest sigma, and then returns mean and
450 // sigma of this subset
454 hh = (nvectors + 2) / 2;
457 Double_t faclts[] = { 2.6477, 2.5092, 2.3826, 2.2662, 2.1587
458 , 2.0589, 1.9660, 1.879, 1.7973, 1.7203
460 Int_t *index = new Int_t[nvectors];
461 TMath::Sort(nvectors, data, index, kFALSE);
463 Int_t nquant = TMath::Min(Int_t(Double_t(((hh * 1.0 / nvectors) - 0.5) * 40)) + 1,11);
464 Double_t factor = faclts[nquant-1];
467 Double_t sumx2 = 0.0;
468 Int_t bestindex = -1;
469 Double_t bestmean = 0.0;
470 Double_t bestsigma = data[index[nvectors-1]] - data[index[0]]; // Maximal possible sigma
471 for (Int_t i = 0; i < hh; i++) {
472 sumx += data[index[i]];
473 sumx2 += data[index[i]]*data[index[i]];
476 Double_t norm = 1.0 / Double_t(hh);
477 Double_t norm2 = 1.0 / Double_t(hh - 1);
478 for (Int_t i = hh; i < nvectors; i++) {
480 Double_t cmean = sumx*norm;
481 Double_t csigma = (sumx2 - hh*cmean*cmean) * norm2;
482 if (csigma < bestsigma) {
488 sumx += data[index[i]] - data[index[i-hh]];
489 sumx2 += data[index[i]]*data[index[i]] - data[index[i-hh]]*data[index[i-hh]];
493 Double_t bstd = factor * TMath::Sqrt(TMath::Abs(bestsigma));
501 //_____________________________________________________________________________
502 Float_t AliTRDseed::FitRiemanTilt(AliTRDseed * cseed, Bool_t terror)
505 // Fit the Rieman tilt
508 // Fitting with tilting pads - kz not fixed
509 TLinearFitter fitterT2(4,"hyp4");
510 fitterT2.StoreData(kTRUE);
511 Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
514 fitterT2.ClearPoints();
516 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
518 if (!cseed[iLayer].IsOK()) continue;
519 Double_t tilt = cseed[iLayer].fTilt;
521 for (Int_t itime = 0; itime < 25; itime++) {
523 if (!cseed[iLayer].fUsable[itime]) continue;
524 // x relative to the midle chamber
525 Double_t x = cseed[iLayer].fX[itime] + cseed[iLayer].fX0 - xref2;
526 Double_t y = cseed[iLayer].fY[itime];
527 Double_t z = cseed[iLayer].fZ[itime];
533 Double_t x2 = cseed[iLayer].fX[itime] + cseed[iLayer].fX0; // Global x
534 Double_t t = 1.0 / (x2*x2 + y*y);
536 uvt[0] = 2.0 * x2 * uvt[1];
537 uvt[2] = 2.0 * tilt * uvt[1];
538 uvt[3] = 2.0 * tilt *uvt[1] * x;
539 uvt[4] = 2.0 * (y + tilt * z) * uvt[1];
541 Double_t error = 2.0 * uvt[1];
543 error *= cseed[iLayer].fSigmaY;
546 error *= 0.2; //Default error
548 fitterT2.AddPoint(uvt,uvt[4],error);
556 Double_t rpolz0 = fitterT2.GetParameter(3);
557 Double_t rpolz1 = fitterT2.GetParameter(4);
560 // Linear fitter - not possible to make boundaries
561 // non accept non possible z and dzdx combination
563 Bool_t acceptablez = kTRUE;
564 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
565 if (cseed[iLayer].IsOK()) {
566 Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
567 if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) {
568 acceptablez = kFALSE;
573 Double_t zmf = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
574 Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
575 fitterT2.FixParameter(3,zmf);
576 fitterT2.FixParameter(4,dzmf);
578 fitterT2.ReleaseParameter(3);
579 fitterT2.ReleaseParameter(4);
580 rpolz0 = fitterT2.GetParameter(3);
581 rpolz1 = fitterT2.GetParameter(4);
584 Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);
586 params[0] = fitterT2.GetParameter(0);
587 params[1] = fitterT2.GetParameter(1);
588 params[2] = fitterT2.GetParameter(2);
589 Double_t curvature = 1.0 + params[1] * params[1] - params[2] * params[0];
591 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
593 Double_t x = cseed[iLayer].fX0;
600 Double_t res2 = (x * params[0] + params[1]);
602 res2 = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
604 res2 = TMath::Sqrt(res2);
605 y = (1.0 - res2) / params[0];
609 Double_t x0 = -params[1] / params[0];
610 if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
611 Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1);
612 if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
613 Double_t res = (x - x0) / TMath::Sqrt(1.0 / (rm1*rm1) - (x-x0)*(x-x0));
614 if (params[0] < 0) res *= -1.0;
618 z = rpolz0 + rpolz1 * (x - xref2);
620 cseed[iLayer].fYref[0] = y;
621 cseed[iLayer].fYref[1] = dy;
622 cseed[iLayer].fZref[0] = z;
623 cseed[iLayer].fZref[1] = dz;
624 cseed[iLayer].fC = curvature;