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 TRD track seed //
23 // Alex Bercuci <A.Bercuci@gsi.de> //
24 // Markus Fasel <M.Fasel@gsi.de> //
26 ////////////////////////////////////////////////////////////////////////////
29 #include "TLinearFitter.h"
32 #include "AliMathBase.h"
34 #include "AliTRDseedV1.h"
35 #include "AliTRDcluster.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDstackLayer.h"
38 #include "AliTRDrecoParam.h"
42 ClassImp(AliTRDseedV1)
44 //____________________________________________________________________
45 AliTRDseedV1::AliTRDseedV1(Int_t layer, AliTRDrecoParam *p)
57 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
58 fTimeBins = cal->GetNumberOfTimeBins();
62 //____________________________________________________________________
63 AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref, Bool_t owner)
64 :AliTRDseed((AliTRDseed&)ref)
66 ,fTimeBins(ref.fTimeBins)
68 ,fRecoParam(ref.fRecoParam)
71 // Copy Constructor performing a deep copy
77 for(int ic=0; ic<fTimeBins; ic++){
78 if(!fClusters[ic]) continue;
79 fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
86 //____________________________________________________________________
87 AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref)
90 // Assignment Operator using the copy function
101 //____________________________________________________________________
102 AliTRDseedV1::~AliTRDseedV1()
105 // Destructor. The RecoParam object belongs to the underlying tracker.
108 //AliInfo(Form("fOwner[%s]", fOwner?"YES":"NO"));
110 if(fOwner) delete [] fClusters;
113 //____________________________________________________________________
114 void AliTRDseedV1::Copy(TObject &ref) const
121 AliTRDseedV1 &target = (AliTRDseedV1 &)ref;
123 target.fLayer = fLayer;
124 target.fTimeBins = fTimeBins;
125 target.fRecoParam = fRecoParam;
126 AliTRDseed::Copy(target);
129 //____________________________________________________________________
130 Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
133 // Returns a quality measurement of the current seed
136 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
137 return .5 * (18.0 - fN2)
138 + 10.* TMath::Abs(fYfit[1] - fYref[1])
139 + 5.* TMath::Abs(fYfit[0] - fYref[0] + zcorr)
140 + 2. * TMath::Abs(fMeanz - fZref[0]) / fPadLength;
143 //____________________________________________________________________
144 Bool_t AliTRDseedV1::AttachClustersIter(AliTRDstackLayer *layer
150 // Iterative process to register clusters to the seed.
151 // In iteration 0 we try only one pad-row and if quality not
152 // sufficient we try 2 pad-rows (about 5% of tracks cross 2 pad-rows)
156 AliError("Seed can not be used without a valid RecoParam.");
161 Double_t kroady = fRecoParam->GetRoad1y();
162 Double_t kroadz = fPadLength * .5 + 1.;
164 // initialize configuration parameters
165 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
166 Int_t niter = kZcorr ? 1 : 2;
171 for (Int_t iter = 0; iter < niter; iter++) {
172 //AliInfo(Form("iter = %i", iter));
174 for (Int_t iTime = 0; iTime < fTimeBins; iTime++) {
175 // define searching configuration
176 Double_t dxlayer = layer[iTime].GetX() - fX0;
179 //Try 2 pad-rows in second iteration
181 zexp = fZref[0] + fZref[1] * dxlayer - zcorr;
182 if (zexp > c->GetZ()) zexp = c->GetZ() + fPadLength*0.5;
183 if (zexp < c->GetZ()) zexp = c->GetZ() - fPadLength*0.5;
185 } else zexp = fZref[0];
186 yexp = fYref[0] + fYref[1] * dxlayer - zcorr;
188 // printf("xexp = %3.3f ,yexp = %3.3f, zexp = %3.3f\n",layer[iTime].GetX(),yexp,zexp);
189 // printf("layer[%i].GetNClusters() = %i\n", iTime, layer[iTime].GetNClusters());
190 Int_t index = layer[iTime].SearchNearestCluster(yexp, zexp, kroady, kroadz);
191 // for(Int_t iclk = 0; iclk < layer[iTime].GetNClusters(); iclk++){
192 // AliTRDcluster *testcl = layer[iTime].GetCluster(iclk);
193 // printf("Cluster %i: x = %3.3f, y = %3.3f, z = %3.3f\n",iclk,testcl->GetX(), testcl->GetY(), testcl->GetZ());
195 // printf("Index = %i\n",index);
196 if (index < 0) continue;
199 AliTRDcluster *cl = (AliTRDcluster*) layer[iTime].GetCluster(index);
201 //printf("Cluster %i(0x%x): x = %3.3f, y = %3.3f, z = %3.3f\n", index, cl, cl->GetX(), cl->GetY(), cl->GetZ());
203 Int_t GlobalIndex = layer[iTime].GetGlobalIndex(index);
204 fIndexes[iTime] = GlobalIndex;
205 fClusters[iTime] = cl;
207 fY[iTime] = cl->GetY();
208 fZ[iTime] = cl->GetZ();
215 // Int_t nclusters = 0;
216 // Float_t fD[iter] = 0.;
217 // for(int ic=0; ic<fTimeBins+1; ic++){
218 // AliTRDcluster *ci = fClusters[ic];
220 // for(int jc=ic+1; jc<fTimeBins+1; jc++){
221 // AliTRDcluster *cj = fClusters[jc];
223 // fD[iter] += TMath::Sqrt((ci->GetY()-cj->GetY())*(ci->GetY()-cj->GetY())+
224 // (ci->GetZ()-cj->GetZ())*(ci->GetZ()-cj->GetZ()));
228 // if(nclusters) fD[iter] /= float(nclusters);
231 AliTRDseed::Update();
234 tquality = GetQuality(kZcorr);
235 if(tquality < quality) break;
236 else quality = tquality;
240 if (!IsOK()) return kFALSE;
247 //____________________________________________________________________
248 Bool_t AliTRDseedV1::AttachClustersProj(AliTRDstackLayer *layer
249 , Float_t /*quality*/
254 // Projective algorithm to attach clusters to seeding tracklets
260 // Detailed description
261 // 1. Collapse x coordinate for the full detector plane
262 // 2. truncated mean on y (r-phi) direction
264 // 4. truncated mean on z direction
270 AliError("Seed can not be used without a valid RecoParam.");
274 const Int_t knTimeBins = 35;
275 const Int_t kClusterCandidates = 2 * knTimeBins;
278 Double_t kroady = fRecoParam->GetRoad1y();
279 Double_t kroadz = fPadLength * 1.5 + 1.;
280 // correction to y for the tilting angle
281 Float_t zcorr = kZcorr ? fTilt * (fZProb - fZref[0]) : 0.;
284 AliTRDcluster *clusters[kClusterCandidates];
285 Double_t cond[4], yexp[knTimeBins], zexp[knTimeBins],
286 yres[kClusterCandidates], zres[kClusterCandidates];
287 Int_t ncl, *index = 0x0, tboundary[knTimeBins];
289 // Do cluster projection
290 Int_t nYclusters = 0; Bool_t kEXIT = kFALSE;
291 for (Int_t iTime = 0; iTime < fTimeBins; iTime++) {
292 fX[iTime] = layer[iTime].GetX() - fX0;
293 zexp[iTime] = fZref[0] + fZref[1] * fX[iTime];
294 yexp[iTime] = fYref[0] + fYref[1] * fX[iTime] - zcorr;
296 // build condition and process clusters
297 cond[0] = yexp[iTime] - kroady; cond[1] = yexp[iTime] + kroady;
298 cond[2] = zexp[iTime] - kroadz; cond[3] = zexp[iTime] + kroadz;
299 layer[iTime].GetClusters(cond, index, ncl);
300 for(Int_t ic = 0; ic<ncl; ic++){
301 c = layer[iTime].GetCluster(index[ic]);
302 clusters[nYclusters] = c;
303 yres[nYclusters++] = c->GetY() - yexp[iTime];
304 if(nYclusters >= kClusterCandidates) {
305 AliWarning(Form("Cluster candidates reached limit %d. Some may be lost.", kClusterCandidates));
310 tboundary[iTime] = nYclusters;
314 // Evaluate truncated mean on the y direction
315 Double_t mean, sigma;
316 AliMathBase::EvaluateUni(nYclusters, yres, mean, sigma, Int_t(nYclusters*.8)-2);
317 //purge cluster candidates
318 Int_t nZclusters = 0;
319 for(Int_t ic = 0; ic<nYclusters; ic++){
320 if(yres[ic] - mean > 4. * sigma){
324 zres[nZclusters++] = clusters[ic]->GetZ() - zexp[clusters[ic]->GetLocalTimeBin()];
327 // Evaluate truncated mean on the z direction
328 AliMathBase::EvaluateUni(nZclusters, zres, mean, sigma, Int_t(nZclusters*.8)-2);
329 //purge cluster candidates
330 for(Int_t ic = 0; ic<nZclusters; ic++){
331 if(zres[ic] - mean > 4. * sigma){
338 // Select only one cluster/TimeBin
339 Int_t lastCluster = 0;
341 for (Int_t iTime = 0; iTime < fTimeBins; iTime++) {
342 ncl = tboundary[iTime] - lastCluster;
345 c = clusters[lastCluster];
347 Float_t dold = 9999.; Int_t iptr = lastCluster;
348 for(int ic=lastCluster; ic<tboundary[iTime]; ic++){
349 if(!clusters[ic]) continue;
350 Float_t y = yexp[iTime] - clusters[ic]->GetY();
351 Float_t z = zexp[iTime] - clusters[ic]->GetZ();
352 Float_t d = y * y + z * z;
353 if(d > dold) continue;
359 //Int_t GlobalIndex = layer[iTime].GetGlobalIndex(index);
360 //fIndexes[iTime] = GlobalIndex;
361 fClusters[iTime] = c;
362 fY[iTime] = c->GetY();
363 fZ[iTime] = c->GetZ();
364 lastCluster = tboundary[iTime];
368 // number of minimum numbers of clusters expected for the tracklet
369 Int_t kClmin = Int_t(fRecoParam->GetFindableClusters()*fTimeBins);
371 AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
375 AliTRDseed::Update();
377 // // fit tracklet and update clusters
378 // if(!FitTracklet()) return kFALSE;
383 //____________________________________________________________________
384 Bool_t AliTRDseedV1::FitTracklet()
387 // Linear fit of the tracklet
392 // True if successful
394 // Detailed description
395 // 2. Check if tracklet crosses pad row boundary
396 // 1. Calculate residuals in the y (r-phi) direction
397 // 3. Do a Least Square Fit to the data
400 //Float_t sigmaexp = 0.05 + TMath::Abs(fYref[1] * 0.25); // Expected r.m.s in y direction
401 Float_t ycrosscor = fPadLength * fTilt * 0.5; // Y correction for crossing
402 Float_t anglecor = fTilt * fZref[1]; // Correction to the angle
404 // calculate residuals
405 const Int_t knTimeBins = 35;
406 Float_t yres[knTimeBins]; // y (r-phi) residuals
407 Int_t zint[knTimeBins], // Histograming of the z coordinate
408 zout[2*knTimeBins];//
411 for (Int_t iTime = 0; iTime < fTimeBins; iTime++) {
412 if (!fClusters[iTime]) continue;
413 yres[iTime] = fY[iTime] - fYref[0] - (fYref[1] + anglecor) * fX[iTime];
414 zint[fN++] = Int_t(fZ[iTime]);
417 // calculate pad row boundary crosses
418 Int_t kClmin = Int_t(fRecoParam->GetFindableClusters()*fTimeBins);
419 Int_t nz = AliMathBase::Freq(fN, zint, zout, kFALSE);
421 if(nz <= 1) zout[3] = 0;
422 if(zout[1] + zout[3] < kClmin) {
423 AliWarning(Form("Not enough clusters to fit the cross boundary tracklet %d [%d].", zout[1]+zout[3], kClmin));
426 // Z distance bigger than pad - length
427 if (TMath::Abs(zout[0]-zout[2]) > fPadLength) zout[3]=0;
440 for(int iTime=0; iTime<fTimeBins; iTime++){
441 fUsable[iTime] = kFALSE;
442 if (!fClusters[iTime]) continue;
443 npads = fClusters[iTime]->GetNPads();
445 fUsable[iTime] = kTRUE;
448 Float_t weight = 1.0;
449 if(npads > 5) weight = 0.2;
450 else if(npads > 4) weight = 0.5;
452 sumwx += fX[iTime] * weight;
453 sumwx2 += fX[iTime] * fX[iTime] * weight;
454 sumwy += weight * yres[iTime];
455 sumwxy += weight * yres[iTime] * fX[iTime];
456 sumwz += weight * fZ[iTime];
457 sumwxz += weight * fZ[iTime] * fX[iTime];
460 AliWarning(Form("Not enough clusters to fit the tracklet %d [%d].", fN2, kClmin));
464 fMeanz = sumwz / sumw;
467 // Tracklet on boundary
468 Float_t correction = 0;
470 if (fMeanz < fZProb) correction = ycrosscor;
471 if (fMeanz > fZProb) correction = -ycrosscor;
474 Double_t det = sumw * sumwx2 - sumwx * sumwx;
475 fYfitR[0] = (sumwx2 * sumwy - sumwx * sumwxy) / det;
476 fYfitR[1] = (sumw * sumwxy - sumwx * sumwy) / det;
479 for (Int_t i = 0; i < fTimeBins+1; i++) {
480 if (!fUsable[i]) continue;
481 Float_t delta = yres[i] - fYfitR[0] - fYfitR[1] * fX[i];
482 fSigmaY2 += delta*delta;
484 fSigmaY2 = TMath::Sqrt(fSigmaY2 / Float_t(fN2-2));
486 fZfitR[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
487 fZfitR[1] = (sumw * sumwxz - sumwx * sumwz) / det;
488 fZfit[0] = (sumwx2 * sumwz - sumwx * sumwxz) / det;
489 fZfit[1] = (sumw * sumwxz - sumwx * sumwz) / det;
490 fYfitR[0] += fYref[0] + correction;
491 fYfitR[1] += fYref[1];
492 fYfit[0] = fYfitR[0];
493 fYfit[1] = fYfitR[1];
498 //_____________________________________________________________________________
499 Float_t AliTRDseedV1::FitRiemanTilt(AliTRDseedV1 *cseed, Bool_t terror)
502 // Fit the Rieman tilt
505 // Fitting with tilting pads - kz not fixed
506 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
507 Int_t nTimeBins = cal->GetNumberOfTimeBins();
508 TLinearFitter fitterT2(4,"hyp4");
509 fitterT2.StoreData(kTRUE);
510 Float_t xref2 = (cseed[2].fX0 + cseed[3].fX0) * 0.5; // Reference x0 for z
513 fitterT2.ClearPoints();
515 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
516 // printf("\nLayer %d\n", iLayer);
517 // cseed[iLayer].Print();
518 if (!cseed[iLayer].IsOK()) continue;
519 Double_t tilt = cseed[iLayer].fTilt;
521 for (Int_t itime = 0; itime < nTimeBins+1; itime++) {
522 // printf("\ttime %d\n", 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 // printf("\tadd point :\n");
549 // for(int i=0; i<5; i++) printf("%f ", uvt[i]);
551 fitterT2.AddPoint(uvt,uvt[4],error);
558 Double_t rpolz0 = fitterT2.GetParameter(3);
559 Double_t rpolz1 = fitterT2.GetParameter(4);
562 // Linear fitter - not possible to make boundaries
563 // non accept non possible z and dzdx combination
565 Bool_t acceptablez = kTRUE;
566 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
567 if (cseed[iLayer].IsOK()) {
568 Double_t zT2 = rpolz0 + rpolz1 * (cseed[iLayer].fX0 - xref2);
569 if (TMath::Abs(cseed[iLayer].fZProb - zT2) > cseed[iLayer].fPadLength * 0.5 + 1.0) {
570 acceptablez = kFALSE;
575 Double_t zmf = cseed[2].fZref[0] + cseed[2].fZref[1] * (xref2 - cseed[2].fX0);
576 Double_t dzmf = (cseed[2].fZref[1] + cseed[3].fZref[1]) * 0.5;
577 fitterT2.FixParameter(3,zmf);
578 fitterT2.FixParameter(4,dzmf);
580 fitterT2.ReleaseParameter(3);
581 fitterT2.ReleaseParameter(4);
582 rpolz0 = fitterT2.GetParameter(3);
583 rpolz1 = fitterT2.GetParameter(4);
586 Double_t chi2TR = fitterT2.GetChisquare() / Float_t(npointsT);
588 params[0] = fitterT2.GetParameter(0);
589 params[1] = fitterT2.GetParameter(1);
590 params[2] = fitterT2.GetParameter(2);
591 Double_t curvature = 1.0 + params[1] * params[1] - params[2] * params[0];
593 for (Int_t iLayer = 0; iLayer < 6; iLayer++) {
595 Double_t x = cseed[iLayer].fX0;
602 Double_t res2 = (x * params[0] + params[1]);
604 res2 = 1.0 - params[2]*params[0] + params[1]*params[1] - res2;
606 res2 = TMath::Sqrt(res2);
607 y = (1.0 - res2) / params[0];
611 Double_t x0 = -params[1] / params[0];
612 if (-params[2]*params[0] + params[1]*params[1] + 1 > 0) {
613 Double_t rm1 = params[0] / TMath::Sqrt(-params[2]*params[0] + params[1]*params[1] + 1);
614 if (1.0/(rm1*rm1) - (x-x0) * (x-x0) > 0.0) {
615 Double_t res = (x - x0) / TMath::Sqrt(1.0 / (rm1*rm1) - (x-x0)*(x-x0));
616 if (params[0] < 0) res *= -1.0;
620 z = rpolz0 + rpolz1 * (x - xref2);
622 cseed[iLayer].fYref[0] = y;
623 cseed[iLayer].fYref[1] = dy;
624 cseed[iLayer].fZref[0] = z;
625 cseed[iLayer].fZref[1] = dz;
626 cseed[iLayer].fC = curvature;
634 //___________________________________________________________________
635 void AliTRDseedV1::Print()
638 // Printing the seedstatus
641 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
642 Int_t nTimeBins = cal->GetNumberOfTimeBins();
644 printf("Seed status :\n");
645 printf(" fTilt = %f\n", fTilt);
646 printf(" fPadLength = %f\n", fPadLength);
647 printf(" fX0 = %f\n", fX0);
648 for(int ic=0; ic<nTimeBins; ic++) {
649 const Char_t *isUsable = fUsable[ic]?"Yes":"No";
650 printf(" %d X[%f] Y[%f] Z[%f] Indexes[%d] clusters[%#x] usable[%s]\n"
656 , ((Int_t) fClusters[ic])
660 printf(" fYref[0] =%f fYref[1] =%f\n", fYref[0], fYref[1]);
661 printf(" fZref[0] =%f fZref[1] =%f\n", fZref[0], fZref[1]);
662 printf(" fYfit[0] =%f fYfit[1] =%f\n", fYfit[0], fYfit[1]);
663 printf(" fYfitR[0]=%f fYfitR[1]=%f\n", fYfitR[0], fYfitR[1]);
664 printf(" fZfit[0] =%f fZfit[1] =%f\n", fZfit[0], fZfit[1]);
665 printf(" fZfitR[0]=%f fZfitR[1]=%f\n", fZfitR[0], fZfitR[1]);
666 printf(" fSigmaY =%f\n", fSigmaY);
667 printf(" fSigmaY2=%f\n", fSigmaY2);
668 printf(" fMeanz =%f\n", fMeanz);
669 printf(" fZProb =%f\n", fZProb);
670 printf(" fLabels[0]=%d fLabels[1]=%d\n", fLabels[0], fLabels[1]);
671 printf(" fN =%d\n", fN);
672 printf(" fN2 =%d (>8 isOK)\n",fN2);
673 printf(" fNUsed =%d\n", fNUsed);
674 printf(" fFreq =%d\n", fFreq);
675 printf(" fNChange=%d\n", fNChange);
676 printf(" fMPads =%f\n", fMPads);
678 printf(" fC =%f\n", fC);
679 printf(" fCC =%f\n",fCC);
680 printf(" fChi2 =%f\n", fChi2);
681 printf(" fChi2Z =%f\n", fChi2Z);