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 offline tracklet
22 // The running horse of the TRD reconstruction. The following tasks are preformed:
23 // 1. Clusters attachment to tracks based on prior information stored at tracklet level (see AttachClusters)
24 // 2. Clusters position recalculation based on track information (see GetClusterXY and Fit)
25 // 3. Cluster error parametrization recalculation (see Fit)
26 // 4. Linear track approximation (Fit)
27 // 5. Optimal position (including z estimate for pad row cross tracklets) and covariance matrix of the track fit inside one TRD chamber (Fit)
28 // 6. Tilt pad correction and systematic effects (GetCovAt)
29 // 7. dEdx calculation (CookdEdx)
30 // 8. PID probabilities estimation (CookPID)
33 // Alex Bercuci <A.Bercuci@gsi.de> //
34 // Markus Fasel <M.Fasel@gsi.de> //
36 ////////////////////////////////////////////////////////////////////////////
39 #include "TTreeStream.h"
40 #include "TGraphErrors.h"
43 #include "AliMathBase.h"
44 #include "AliRieman.h"
45 #include "AliCDBManager.h"
47 #include "AliTRDReconstructor.h"
48 #include "AliTRDpadPlane.h"
49 #include "AliTRDtransform.h"
50 #include "AliTRDcluster.h"
51 #include "AliTRDseedV1.h"
52 #include "AliTRDtrackV1.h"
53 #include "AliTRDcalibDB.h"
54 #include "AliTRDchamberTimeBin.h"
55 #include "AliTRDtrackingChamber.h"
56 #include "AliTRDtrackerV1.h"
57 #include "AliTRDrecoParam.h"
58 #include "AliTRDCommonParam.h"
59 #include "AliTRDtrackletOflHelper.h"
61 #include "Cal/AliTRDCalTrkAttach.h"
62 #include "Cal/AliTRDCalPID.h"
63 #include "Cal/AliTRDCalROC.h"
64 #include "Cal/AliTRDCalDet.h"
68 ClassImp(AliTRDseedV1)
70 //____________________________________________________________________
71 AliTRDseedV1::AliTRDseedV1(Int_t det)
73 ,fkReconstructor(NULL)
98 memset(fIndexes,0xFF,kNclusters*sizeof(fIndexes[0]));
99 memset(fClusters, 0, kNclusters*sizeof(AliTRDcluster*));
100 memset(fPad, 0, 4*sizeof(Float_t));
101 fYref[0] = 0.; fYref[1] = 0.;
102 fZref[0] = 0.; fZref[1] = 0.;
103 fYfit[0] = 0.; fYfit[1] = 0.;
104 fZfit[0] = 0.; fZfit[1] = 0.;
105 memset(fdEdx, 0, kNslices*sizeof(Float_t));
106 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = -1.;
107 fLabels[0]=-1; fLabels[1]=-1; // most freq MC labels
108 fLabels[2]=0; // number of different labels for tracklet
109 memset(fRefCov, 0, 7*sizeof(Double_t));
110 // stand alone curvature
111 fC[0] = 0.; fC[1] = 0.;
112 // covariance matrix [diagonal]
113 // default sy = 200um and sz = 2.3 cm
114 fCov[0] = 4.e-4; fCov[1] = 0.; fCov[2] = 5.3;
115 SetStandAlone(kFALSE);
118 //____________________________________________________________________
119 AliTRDseedV1::AliTRDseedV1(const AliTRDseedV1 &ref)
120 :AliTRDtrackletBase((AliTRDtrackletBase&)ref)
121 ,fkReconstructor(NULL)
144 // Copy Constructor performing a deep copy
149 SetBit(kOwner, kFALSE);
150 SetStandAlone(ref.IsStandAlone());
154 //____________________________________________________________________
155 AliTRDseedV1& AliTRDseedV1::operator=(const AliTRDseedV1 &ref)
158 // Assignment Operator using the copy function
164 SetBit(kOwner, kFALSE);
169 //____________________________________________________________________
170 AliTRDseedV1::~AliTRDseedV1()
173 // Destructor. The RecoParam object belongs to the underlying tracker.
176 //printf("I-AliTRDseedV1::~AliTRDseedV1() : Owner[%s]\n", IsOwner()?"YES":"NO");
179 for(int itb=0; itb<kNclusters; itb++){
180 if(!fClusters[itb]) continue;
181 //AliInfo(Form("deleting c %p @ %d", fClusters[itb], itb));
182 delete fClusters[itb];
183 fClusters[itb] = NULL;
188 //____________________________________________________________________
189 void AliTRDseedV1::Copy(TObject &ref) const
196 AliTRDseedV1 &target = (AliTRDseedV1 &)ref;
198 target.fkReconstructor = fkReconstructor;
199 target.fClusterIter = NULL;
203 target.fS2PRF = fS2PRF;
204 target.fDiffL = fDiffL;
205 target.fDiffT = fDiffT;
206 target.fClusterIdx = 0;
207 target.fErrorMsg = fErrorMsg;
218 target.fChi2 = fChi2;
220 memcpy(target.fIndexes, fIndexes, kNclusters*sizeof(Int_t));
221 memcpy(target.fClusters, fClusters, kNclusters*sizeof(AliTRDcluster*));
222 memcpy(target.fPad, fPad, 4*sizeof(Float_t));
223 target.fYref[0] = fYref[0]; target.fYref[1] = fYref[1];
224 target.fZref[0] = fZref[0]; target.fZref[1] = fZref[1];
225 target.fYfit[0] = fYfit[0]; target.fYfit[1] = fYfit[1];
226 target.fZfit[0] = fZfit[0]; target.fZfit[1] = fZfit[1];
227 memcpy(target.fdEdx, fdEdx, kNslices*sizeof(Float_t));
228 memcpy(target.fProb, fProb, AliPID::kSPECIES*sizeof(Float_t));
229 memcpy(target.fLabels, fLabels, 3*sizeof(Int_t));
230 memcpy(target.fRefCov, fRefCov, 7*sizeof(Double_t));
231 target.fC[0] = fC[0]; target.fC[1] = fC[1];
232 memcpy(target.fCov, fCov, 3*sizeof(Double_t));
238 //____________________________________________________________
239 void AliTRDseedV1::Init(const AliRieman *rieman)
241 // Initialize this tracklet using the riemann fit information
244 fZref[0] = rieman->GetZat(fX0);
245 fZref[1] = rieman->GetDZat(fX0);
246 fYref[0] = rieman->GetYat(fX0);
247 fYref[1] = rieman->GetDYat(fX0);
248 if(fkReconstructor && fkReconstructor->IsHLT()){
252 fRefCov[0] = rieman->GetErrY(fX0);
253 fRefCov[2] = rieman->GetErrZ(fX0);
255 fC[0] = rieman->GetC();
256 fChi2 = rieman->GetChi2();
260 //____________________________________________________________
261 Bool_t AliTRDseedV1::Init(AliTRDtrackV1 *track)
263 // Initialize this tracklet using the track information
266 // track - the TRD track used to initialize the tracklet
268 // Detailed description
269 // The function sets the starting point and direction of the
270 // tracklet according to the information from the TRD track.
273 // The TRD track has to be propagated to the beginning of the
274 // chamber where the tracklet will be constructed
278 if(!track->GetProlongation(fX0, y, z)) return kFALSE;
284 //_____________________________________________________________________________
285 void AliTRDseedV1::Reset(Option_t *opt)
288 // Reset seed. If option opt="c" is given only cluster arrays are cleared.
290 for(Int_t ic=kNclusters; ic--;) fIndexes[ic] = -1;
291 memset(fClusters, 0, kNclusters*sizeof(AliTRDcluster*));
292 fN=0; SetBit(kRowCross, kFALSE);
293 if(strcmp(opt, "c")==0) return;
295 fExB=0.;fVD=0.;fT0=0.;fS2PRF=0.;
301 fdX=0.;fX0=0.; fX=0.; fY=0.; fZ=0.;
306 memset(fPad, 0, 4*sizeof(Float_t));
307 fYref[0] = 0.; fYref[1] = 0.;
308 fZref[0] = 0.; fZref[1] = 0.;
309 fYfit[0] = 0.; fYfit[1] = 0.;
310 fZfit[0] = 0.; fZfit[1] = 0.;
311 memset(fdEdx, 0, kNslices*sizeof(Float_t));
312 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fProb[ispec] = -1.;
313 fLabels[0]=-1; fLabels[1]=-1; // most freq MC labels
314 fLabels[2]=0; // number of different labels for tracklet
315 memset(fRefCov, 0, 7*sizeof(Double_t));
316 // covariance matrix [diagonal]
317 // default sy = 200um and sz = 2.3 cm
318 fCov[0] = 4.e-4; fCov[1] = 0.; fCov[2] = 5.3;
321 //____________________________________________________________________
322 void AliTRDseedV1::Update(const AliTRDtrackV1 *trk)
324 // update tracklet reference position from the TRD track
326 Double_t fSnp = trk->GetSnp();
327 Double_t fTgl = trk->GetTgl();
329 Double_t norm =1./TMath::Sqrt((1.-fSnp)*(1.+fSnp));
330 fYref[1] = fSnp*norm;
331 fZref[1] = fTgl*norm;
332 SetCovRef(trk->GetCovariance());
334 Double_t dx = trk->GetX() - fX0;
335 fYref[0] = trk->GetY() - dx*fYref[1];
336 fZref[0] = trk->GetZ() - dx*fZref[1];
339 //_____________________________________________________________________________
340 void AliTRDseedV1::UpdateUsed()
343 // Calculate number of used clusers in the tracklet
346 Int_t nused = 0, nshared = 0;
347 for (Int_t i = kNclusters; i--; ) {
348 if (!fClusters[i]) continue;
349 if(fClusters[i]->IsUsed()){
351 } else if(fClusters[i]->IsShared()){
352 if(IsStandAlone()) nused++;
360 //_____________________________________________________________________________
361 void AliTRDseedV1::UseClusters()
366 // In stand alone mode:
367 // Clusters which are marked as used or shared from another track are
368 // removed from the tracklet
371 // - Clusters which are used by another track become shared
372 // - Clusters which are attached to a kink track become shared
374 AliTRDcluster **c = &fClusters[0];
375 for (Int_t ic=kNclusters; ic--; c++) {
378 if((*c)->IsShared() || (*c)->IsUsed()){
379 if((*c)->IsShared()) SetNShared(GetNShared()-1);
380 else SetNUsed(GetNUsed()-1);
387 if((*c)->IsUsed() || IsKink()){
398 //____________________________________________________________________
399 void AliTRDseedV1::CookdEdx(Int_t nslices)
401 // Calculates average dE/dx for all slices and store them in the internal array fdEdx.
404 // nslices : number of slices for which dE/dx should be calculated
406 // store results in the internal array fdEdx. This can be accessed with the method
407 // AliTRDseedV1::GetdEdx()
409 // Detailed description
410 // Calculates average dE/dx for all slices. Depending on the PID methode
411 // the number of slices can be 3 (LQ) or 8(NN).
412 // The calculation of dQ/dl are done using the tracklet fit results (see AliTRDseedV1::GetdQdl(Int_t))
414 // The following effects are included in the calculation:
415 // 1. calibration values for t0 and vdrift (using x coordinate to calculate slice)
416 // 2. cluster sharing (optional see AliTRDrecoParam::SetClusterSharing())
420 memset(fdEdx, 0, kNslices*sizeof(Float_t));
421 const Double_t kDriftLength = (.5 * AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick());
423 AliTRDcluster *c(NULL);
424 for(int ic=0; ic<AliTRDtrackerV1::GetNTimeBins(); ic++){
425 if(!(c = fClusters[ic]) && !(c = fClusters[ic+kNtb])) continue;
426 Float_t dx = TMath::Abs(fX0 - c->GetX());
428 // Filter clusters for dE/dx calculation
430 // 1.consider calibration effects for slice determination
432 if(dx<kDriftLength){ // TODO should be replaced by c->IsInChamber()
433 slice = Int_t(dx * nslices / kDriftLength);
434 } else slice = c->GetX() < fX0 ? nslices-1 : 0;
437 // 2. take sharing into account
438 Float_t w = /*c->IsShared() ? .5 :*/ 1.;
440 // 3. take into account large clusters TODO
441 //w *= c->GetNPads() > 3 ? .8 : 1.;
444 fdEdx[slice] += w * GetdQdl(ic); //fdQdl[ic];
445 } // End of loop over clusters
448 //_____________________________________________________________________________
449 void AliTRDseedV1::CookLabels()
452 // Cook 2 labels for seed
458 for (Int_t i = 0; i < kNclusters; i++) {
459 if (!fClusters[i]) continue;
460 for (Int_t ilab = 0; ilab < 3; ilab++) {
461 if (fClusters[i]->GetLabel(ilab) >= 0) {
462 labels[nlab] = fClusters[i]->GetLabel(ilab);
468 fLabels[2] = AliMathBase::Freq(nlab,labels,out,kTRUE);
470 if ((fLabels[2] > 1) && (out[3] > 1)) fLabels[1] = out[2];
473 //____________________________________________________________
474 Float_t AliTRDseedV1::GetAnodeWireOffset(Float_t zt)
476 // Find position inside the amplification cell for reading drift velocity map
478 Float_t d = fPad[3] - zt;
480 AliError(Form("Fail AnodeWireOffset calculation z0[%+7.2f] zt[%+7.2f] d[%+7.2f].", fPad[3], zt, d));
483 d -= ((Int_t)(2 * d)) / 2.0;
484 if(d > 0.25) d = 0.5 - d;
489 //____________________________________________________________________
490 Float_t AliTRDseedV1::GetCharge(Bool_t useOutliers) const
492 // Computes total charge attached to tracklet. If "useOutliers" is set clusters
493 // which are not in chamber are also used (default false)
495 AliTRDcluster *c(NULL); Float_t qt(0.);
496 for(int ic=0; ic<kNclusters; ic++){
497 if(!(c=fClusters[ic])) continue;
498 if(c->IsInChamber() && !useOutliers) continue;
499 qt += TMath::Abs(c->GetQ());
504 //____________________________________________________________________
505 Bool_t AliTRDseedV1::GetEstimatedCrossPoint(Float_t &x, Float_t &z) const
507 // Algorithm to estimate cross point in the x-z plane for pad row cross tracklets.
508 // Returns true in case of success.
509 if(!IsRowCross()) return kFALSE;
512 AliTRDcluster *c(NULL);
513 // Find radial range for first row
514 Float_t x1[] = {0., 1.e3};
515 for(int ic=0; ic<kNtb; ic++){
516 if(!(c=fClusters[ic])) continue;
517 if(!c->IsInChamber()) continue;
518 if(c->GetX() <= x1[1]) x1[1] = c->GetX();
519 if(c->GetX() >= x1[0]) x1[0] = c->GetX();
522 if((x1[0] - x1[1])<1.e-5) return kFALSE;
524 // Find radial range for second row
526 Float_t x2[] = {0., 1.e3};
527 for(int ic=kNtb; ic<kNclusters; ic++){
528 if(!(c=fClusters[ic])) continue;
529 if(!c->IsInChamber()) continue;
530 if(c->GetX() <= x2[1]) x2[1] = c->GetX();
531 if(c->GetX() >= x2[0]) x2[0] = c->GetX();
538 if((x2[0] - x2[1])<1.e-5) return kFALSE;
540 // Find intersection of the 2 radial regions
541 x = 0.5*((x1[0]+x1[1] > x2[0]+x2[1]) ? (x1[1]+x2[0]) : (x1[0]+x2[1]));
545 //____________________________________________________________________
546 Float_t AliTRDseedV1::GetdQdl() const
548 // Calculate total charge / tracklet length for 1D PID
550 Float_t Q = GetCharge(kTRUE);
551 return Q/TMath::Sqrt(1. + fYref[1]*fYref[1] + fZref[1]*fZref[1]);
554 //____________________________________________________________________
555 Float_t AliTRDseedV1::GetdQdl(Int_t ic, Float_t *dl) const
557 // Using the linear approximation of the track inside one TRD chamber (TRD tracklet)
558 // the charge per unit length can be written as:
560 // #frac{dq}{dl} = #frac{q_{c}}{dx * #sqrt{1 + #(){#frac{dy}{dx}}^{2}_{fit} + #(){#frac{dz}{dx}}^{2}_{ref}}}
562 // where qc is the total charge collected in the current time bin and dx is the length
564 // The following correction are applied :
565 // - charge : pad row cross corrections
566 // [diffusion and TRF assymetry] TODO
567 // - dx : anisochronity, track inclination - see Fit and AliTRDcluster::GetXloc()
568 // and AliTRDcluster::GetYloc() for the effects taken into account
571 //<img src="TRD/trackletDQDT.gif">
573 // In the picture the energy loss measured on the tracklet as a function of drift time [left] and respectively
574 // drift length [right] for different particle species is displayed.
575 // Author : Alex Bercuci <A.Bercuci@gsi.de>
578 // check whether both clusters are inside the chamber
579 Bool_t hasClusterInChamber = kFALSE;
580 if(fClusters[ic] && fClusters[ic]->IsInChamber()){
581 hasClusterInChamber = kTRUE;
582 dq += TMath::Abs(fClusters[ic]->GetQ());
584 if(fClusters[ic+kNtb] && fClusters[ic+kNtb]->IsInChamber()){
585 hasClusterInChamber = kTRUE;
586 dq += TMath::Abs(fClusters[ic+kNtb]->GetQ());
588 if(!hasClusterInChamber) return 0.;
589 if(dq<1.e-3) return 0.;
592 if(ic-1>=0 && ic+1<kNtb){
593 Float_t x2(0.), x1(0.);
594 // try to estimate upper radial position (find the cluster which is inside the chamber)
595 if(fClusters[ic-1] && fClusters[ic-1]->IsInChamber()) x2 = fClusters[ic-1]->GetX();
596 else if(fClusters[ic-1+kNtb] && fClusters[ic-1+kNtb]->IsInChamber()) x2 = fClusters[ic-1+kNtb]->GetX();
597 else if(fClusters[ic] && fClusters[ic]->IsInChamber()) x2 = fClusters[ic]->GetX()+fdX;
598 else x2 = fClusters[ic+kNtb]->GetX()+fdX;
599 // try to estimate lower radial position (find the cluster which is inside the chamber)
600 if(fClusters[ic+1] && fClusters[ic+1]->IsInChamber()) x1 = fClusters[ic+1]->GetX();
601 else if(fClusters[ic+1+kNtb] && fClusters[ic+1+kNtb]->IsInChamber()) x1 = fClusters[ic+1+kNtb]->GetX();
602 else if(fClusters[ic] && fClusters[ic]->IsInChamber()) x1 = fClusters[ic]->GetX()-fdX;
603 else x1 = fClusters[ic+kNtb]->GetX()-fdX;
607 dx *= TMath::Sqrt(1. + fYfit[1]*fYfit[1] + fZref[1]*fZref[1]);
609 if(dx>1.e-9) return dq/dx;
613 //____________________________________________________________
614 Float_t AliTRDseedV1::GetMomentum(Float_t *err) const
616 // Returns momentum of the track after update with the current tracklet as:
618 // p=#frac{1}{1/p_{t}} #sqrt{1+tgl^{2}}
620 // and optionally the momentum error (if err is not null).
621 // The estimated variance of the momentum is given by:
623 // #sigma_{p}^{2} = (#frac{dp}{dp_{t}})^{2} #sigma_{p_{t}}^{2}+(#frac{dp}{dtgl})^{2} #sigma_{tgl}^{2}+2#frac{dp}{dp_{t}}#frac{dp}{dtgl} cov(tgl,1/p_{t})
625 // which can be simplified to
627 // #sigma_{p}^{2} = p^{2}p_{t}^{4}tgl^{2}#sigma_{tgl}^{2}-2p^{2}p_{t}^{3}tgl cov(tgl,1/p_{t})+p^{2}p_{t}^{2}#sigma_{1/p_{t}}^{2}
631 Double_t p = fPt*TMath::Sqrt(1.+fZref[1]*fZref[1]);
633 Double_t tgl2 = fZref[1]*fZref[1];
634 Double_t pt2 = fPt*fPt;
637 p2*tgl2*pt2*pt2*fRefCov[4]
638 -2.*p2*fZref[1]*fPt*pt2*fRefCov[5]
640 (*err) = TMath::Sqrt(s2);
646 //____________________________________________________________________
647 Int_t AliTRDseedV1::GetTBoccupancy() const
649 // Returns no. of TB occupied by clusters
652 for(int ic(0); ic<kNtb; ic++){
653 if(!fClusters[ic] && !fClusters[ic+kNtb]) continue;
659 //____________________________________________________________________
660 Int_t AliTRDseedV1::GetTBcross() const
662 // Returns no. of TB occupied by 2 clusters for pad row cross tracklets
664 if(!IsRowCross()) return 0;
666 for(int ic(0); ic<kNtb; ic++){
667 if(fClusters[ic] && fClusters[ic+kNtb]) n++;
672 //____________________________________________________________________
673 Float_t* AliTRDseedV1::GetProbability(Bool_t force)
675 if(!force) return &fProb[0];
676 if(!CookPID()) return NULL;
680 //____________________________________________________________
681 Bool_t AliTRDseedV1::CookPID()
683 // Fill probability array for tracklet from the DB.
688 // returns pointer to the probability array and NULL if missing DB access
690 // Retrieve PID probabilities for e+-, mu+-, K+-, pi+- and p+- from the DB according to tracklet information:
691 // - estimated momentum at tracklet reference point
692 // - dE/dx measurements
695 // According to the steering settings specified in the reconstruction one of the following methods are used
696 // - Neural Network [default] - option "nn"
697 // - 2D Likelihood - option "!nn"
699 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
701 AliError("No access to calibration data");
705 if (!fkReconstructor) {
706 AliError("Reconstructor not set.");
710 // Retrieve the CDB container class with the parametric detector response
711 const AliTRDCalPID *pd = calibration->GetPIDObject(fkReconstructor->GetPIDMethod());
713 AliError("No access to AliTRDCalPID object");
717 // calculate tracklet length TO DO
718 Float_t length = (AliTRDgeometry::AmThick() + AliTRDgeometry::DrThick())/ TMath::Sqrt((1.0 - GetSnp()*GetSnp()) / (1.0 + GetTgl()*GetTgl()));
721 CookdEdx(AliTRDCalPID::kNSlicesNN);
722 AliDebug(4, Form("p=%6.4f[GeV/c] dEdx{%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f} l=%4.2f[cm]", GetMomentum(), fdEdx[0], fdEdx[1], fdEdx[2], fdEdx[3], fdEdx[4], fdEdx[5], fdEdx[6], fdEdx[7], length));
724 // Sets the a priori probabilities
725 Bool_t kPIDNN(fkReconstructor->GetPIDMethod()==AliTRDpidUtil::kNN);
726 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++)
727 fProb[ispec] = pd->GetProbability(ispec, GetMomentum(), &fdEdx[0], length, kPIDNN?GetPlane():fkReconstructor->GetRecoParam()->GetPIDLQslices());
732 //____________________________________________________________________
733 Float_t AliTRDseedV1::GetQuality(Bool_t kZcorr) const
736 // Returns a quality measurement of the current seed
739 Float_t zcorr = kZcorr ? GetTilt() * (fZfit[0] - fZref[0]) : 0.;
741 .5 * TMath::Abs(18.0 - GetN())
742 + 10.* TMath::Abs(fYfit[1] - fYref[1])
743 + 5. * TMath::Abs(fYfit[0] - fYref[0] + zcorr)
744 + 2. * TMath::Abs(fZfit[0] - fZref[0]) / GetPadLength();
747 //____________________________________________________________________
748 void AliTRDseedV1::GetCovAt(Double_t x, Double_t *cov) const
750 // Computes covariance in the y-z plane at radial point x (in tracking coordinates)
751 // and returns the results in the preallocated array cov[3] as :
758 // For the linear transformation
762 // The error propagation has the general form
764 // C_{Y} = T_{x} C_{X} T_{x}^{T}
766 // We apply this formula 2 times. First to calculate the covariance of the tracklet
767 // at point x we consider:
769 // T_{x} = (1 x); X=(y0 dy/dx); C_{X}=#(){#splitline{Var(y0) Cov(y0, dy/dx)}{Cov(y0, dy/dx) Var(dy/dx)}}
771 // and secondly to take into account the tilt angle
773 // T_{#alpha} = #(){#splitline{cos(#alpha) __ sin(#alpha)}{-sin(#alpha) __ cos(#alpha)}}; X=(y z); C_{X}=#(){#splitline{Var(y) 0}{0 Var(z)}}
776 // using simple trigonometrics one can write for this last case
778 // C_{Y}=#frac{1}{1+tg^{2}#alpha} #(){#splitline{(#sigma_{y}^{2}+tg^{2}#alpha#sigma_{z}^{2}) __ tg#alpha(#sigma_{z}^{2}-#sigma_{y}^{2})}{tg#alpha(#sigma_{z}^{2}-#sigma_{y}^{2}) __ (#sigma_{z}^{2}+tg^{2}#alpha#sigma_{y}^{2})}}
780 // which can be aproximated for small alphas (2 deg) with
782 // C_{Y}=#(){#splitline{#sigma_{y}^{2} __ (#sigma_{z}^{2}-#sigma_{y}^{2})tg#alpha}{((#sigma_{z}^{2}-#sigma_{y}^{2})tg#alpha __ #sigma_{z}^{2}}}
785 // before applying the tilt rotation we also apply systematic uncertainties to the tracklet
786 // position which can be tunned from outside via the AliTRDrecoParam::SetSysCovMatrix(). They might
787 // account for extra misalignment/miscalibration uncertainties.
790 // Alex Bercuci <A.Bercuci@gsi.de>
791 // Date : Jan 8th 2009
796 Double_t sy2 = fCov[0] +2.*xr*fCov[1] + xr*xr*fCov[2];
798 //GetPadLength()*GetPadLength()/12.;
800 // insert systematic uncertainties
802 Double_t sys[15]; memset(sys, 0, 15*sizeof(Double_t));
803 fkReconstructor->GetRecoParam()->GetSysCovMatrix(sys);
808 // rotate covariance matrix if no RC
810 Double_t t2 = GetTilt()*GetTilt();
811 Double_t correction = 1./(1. + t2);
812 cov[0] = (sy2+t2*sz2)*correction;
813 cov[1] = GetTilt()*(sz2 - sy2)*correction;
814 cov[2] = (t2*sy2+sz2)*correction;
816 cov[0] = sy2; cov[1] = 0.; cov[2] = sy2;
819 AliDebug(4, Form("C(%6.1f %+6.3f %6.1f) RC[%c]", 1.e4*TMath::Sqrt(cov[0]), cov[1], 1.e4*TMath::Sqrt(cov[2]), IsRowCross()?'y':'n'));
822 //____________________________________________________________
823 Int_t AliTRDseedV1::GetCovSqrt(const Double_t * const c, Double_t *d)
825 // Helper function to calculate the square root of the covariance matrix.
826 // The input matrix is stored in the vector c and the result in the vector d.
827 // Both arrays have to be initialized by the user with at least 3 elements. Return negative in case of failure.
829 // For calculating the square root of the symmetric matrix c
830 // the following relation is used:
832 // C^{1/2} = VD^{1/2}V^{-1}
834 // with V being the matrix with the n eigenvectors as columns.
835 // In case C is symmetric the followings are true:
836 // - matrix D is diagonal with the diagonal given by the eigenvalues of C
839 // Author A.Bercuci <A.Bercuci@gsi.de>
842 const Double_t kZero(1.e-20);
843 Double_t l[2], // eigenvalues
844 v[3]; // eigenvectors
845 // the secular equation and its solution :
846 // (c[0]-L)(c[2]-L)-c[1]^2 = 0
847 // L^2 - L*Tr(c)+DET(c) = 0
848 // L12 = [Tr(c) +- sqrt(Tr(c)^2-4*DET(c))]/2
849 Double_t tr = c[0]+c[2], // trace
850 det = c[0]*c[2]-c[1]*c[1]; // determinant
851 if(TMath::Abs(det)<kZero) return 1;
852 Double_t dd = TMath::Sqrt(tr*tr - 4*det);
853 l[0] = .5*(tr + dd*(c[0]>c[2]?-1.:1.));
854 l[1] = .5*(tr + dd*(c[0]>c[2]?1.:-1.));
855 if(l[0]<kZero || l[1]<kZero) return 2;
859 Double_t den = (l[0]-c[0])*(l[0]-c[0])+c[1]*c[1];
860 if(den<kZero){ // almost diagonal
861 v[0] = TMath::Sign(0., c[1]);
862 v[1] = TMath::Sign(1., (l[0]-c[0]));
863 v[2] = TMath::Sign(0., c[1]*(l[0]-c[0])*(l[1]-c[2]));
865 Double_t tmp = 1./TMath::Sqrt(den);
867 v[1] = (l[0]-c[0])*tmp;
868 if(TMath::Abs(l[1]-c[2])<kZero) v[2] = TMath::Sign(v[0]*(l[0]-c[0])/kZero, (l[1]-c[2]));
869 else v[2] = v[0]*(l[0]-c[0])/(l[1]-c[2]);
872 l[0] = TMath::Sqrt(l[0]); l[1] = TMath::Sqrt(l[1]);
873 d[0] = v[0]*v[0]*l[0]+v[1]*v[1]*l[1];
874 d[1] = v[0]*v[1]*l[0]+v[1]*v[2]*l[1];
875 d[2] = v[1]*v[1]*l[0]+v[2]*v[2]*l[1];
880 //____________________________________________________________
881 Double_t AliTRDseedV1::GetCovInv(const Double_t * const c, Double_t *d)
883 // Helper function to calculate the inverse of the covariance matrix.
884 // The input matrix is stored in the vector c and the result in the vector d.
885 // Both arrays have to be initialized by the user with at least 3 elements
886 // The return value is the determinant or 0 in case of singularity.
888 // Author A.Bercuci <A.Bercuci@gsi.de>
891 Double_t det = c[0]*c[2] - c[1]*c[1];
892 if(TMath::Abs(det)<1.e-20) return 0.;
893 Double_t invDet = 1./det;
900 //____________________________________________________________________
901 UShort_t AliTRDseedV1::GetVolumeId() const
903 // Returns geometry volume id by delegation
905 for(Int_t ic(0);ic<kNclusters; ic++){
906 if(fClusters[ic]) return fClusters[ic]->GetVolumeId();
912 //____________________________________________________________________
913 void AliTRDseedV1::Calibrate()
915 // Retrieve calibration and position parameters from OCDB.
916 // The following information are used
918 // - column and row position of first attached cluster. If no clusters are attached
919 // to the tracklet a random central chamber position (c=70, r=7) will be used.
921 // The following information is cached in the tracklet
922 // t0 (trigger delay)
925 // omega*tau = tg(a_L)
926 // diffusion coefficients (longitudinal and transversal)
929 // Alex Bercuci <A.Bercuci@gsi.de>
930 // Date : Jan 8th 2009
933 AliCDBManager *cdb = AliCDBManager::Instance();
934 if(cdb->GetRun() < 0){
935 AliError("OCDB manager not properly initialized");
939 AliTRDcalibDB *calib = AliTRDcalibDB::Instance();
940 AliTRDCalROC *vdROC = calib->GetVdriftROC(fDet),
941 *t0ROC = calib->GetT0ROC(fDet);;
942 const AliTRDCalDet *vdDet = calib->GetVdriftDet();
943 const AliTRDCalDet *t0Det = calib->GetT0Det();
945 Int_t col = 70, row = 7;
946 AliTRDcluster **c = &fClusters[0];
949 while (ic<kNclusters && !(*c)){ic++; c++;}
951 col = (*c)->GetPadCol();
952 row = (*c)->GetPadRow();
956 fT0 = (t0Det->GetValue(fDet) + t0ROC->GetValue(col,row)) / AliTRDCommonParam::Instance()->GetSamplingFrequency();
957 fVD = vdDet->GetValue(fDet) * vdROC->GetValue(col, row);
958 fS2PRF = calib->GetPRFWidth(fDet, col, row); fS2PRF *= fS2PRF;
959 fExB = AliTRDCommonParam::Instance()->GetOmegaTau(fVD);
960 AliTRDCommonParam::Instance()->GetDiffCoeff(fDiffL,
962 AliDebug(4, Form("Calibration params for Det[%3d] Col[%3d] Row[%2d]\n t0[%f] vd[%f] s2PRF[%f] ExB[%f] Dl[%f] Dt[%f]", fDet, col, row, fT0, fVD, fS2PRF, fExB, fDiffL, fDiffT));
965 SetBit(kCalib, kTRUE);
968 //____________________________________________________________________
969 void AliTRDseedV1::SetOwner()
971 //AliInfo(Form("own [%s] fOwner[%s]", own?"YES":"NO", fOwner?"YES":"NO"));
973 if(TestBit(kOwner)) return;
974 for(int ic=0; ic<kNclusters; ic++){
975 if(!fClusters[ic]) continue;
976 fClusters[ic] = new AliTRDcluster(*fClusters[ic]);
981 //____________________________________________________________
982 void AliTRDseedV1::SetPadPlane(AliTRDpadPlane * const p)
984 // Shortcut method to initialize pad geometry.
985 fPad[0] = p->GetLengthIPad();
986 fPad[1] = p->GetWidthIPad();
987 fPad[2] = TMath::Tan(TMath::DegToRad()*p->GetTiltingAngle());
988 fPad[3] = p->GetRow0() + p->GetAnodeWireOffset();
993 //____________________________________________________________________
994 Bool_t AliTRDseedV1::AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt, Bool_t chgPos, Int_t ev)
997 // Projective algorithm to attach clusters to seeding tracklets. The following steps are performed :
998 // 1. Collapse x coordinate for the full detector plane
999 // 2. truncated mean on y (r-phi) direction
1000 // 3. purge clusters
1001 // 4. truncated mean on z direction
1002 // 5. purge clusters
1005 // - chamber : pointer to tracking chamber container used to search the tracklet
1006 // - tilt : switch for tilt correction during road building [default true]
1008 // - true : if tracklet found successfully. Failure can happend because of the following:
1010 // Detailed description
1012 // We start up by defining the track direction in the xy plane and roads. The roads are calculated based
1013 // on tracking information (variance in the r-phi direction) and estimated variance of the standard
1014 // clusters (see AliTRDcluster::SetSigmaY2()) corrected for tilt (see GetCovAt()). From this the road is
1016 // r_{y} = 3*#sqrt{12*(#sigma^{2}_{Trk}(y) + #frac{#sigma^{2}_{cl}(y) + tg^{2}(#alpha_{L})#sigma^{2}_{cl}(z)}{1+tg^{2}(#alpha_{L})})}
1017 // r_{z} = 1.5*L_{pad}
1020 // Author : Alexandru Bercuci <A.Bercuci@gsi.de>
1021 // Debug : level = 2 for calibration
1022 // level = 3 for visualization in the track SR
1023 // level = 4 for full visualization including digit level
1025 const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam(); //the dynamic cast in GetRecoParam is slow, so caching the pointer to it
1028 AliError("Tracklets can not be used without a valid RecoParam.");
1031 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1033 AliError("No access to calibration data");
1036 // Retrieve the CDB container class with the parametric likelihood
1037 const AliTRDCalTrkAttach *attach = calibration->GetAttachObject();
1039 AliError("No usable AttachClusters calib object.");
1043 // Initialize reco params for this tracklet
1044 // 1. first time bin in the drift region
1046 Int_t kClmin = Int_t(recoParam->GetFindableClusters()*AliTRDtrackerV1::GetNTimeBins());
1049 Double_t sysCov[5]; recoParam->GetSysCovMatrix(sysCov);
1050 Double_t s2yTrk= fRefCov[0],
1052 s2zCl = GetPadLength()*GetPadLength()/12.,
1053 syRef = TMath::Sqrt(s2yTrk),
1054 t2 = GetTilt()*GetTilt();
1056 const Double_t kroady = 3.; //recoParam->GetRoad1y();
1057 const Double_t kroadz = GetPadLength() * recoParam->GetRoadzMultiplicator() + 1.;
1058 // define probing cluster (the perfect cluster) and default calibration
1059 Short_t sig[] = {0, 0, 10, 30, 10, 0,0};
1060 AliTRDcluster cp(fDet, 6, 75, 0, sig, 0);
1061 if(fkReconstructor->IsHLT()) cp.SetRPhiMethod(AliTRDcluster::kCOG);
1062 if(!IsCalibrated()) Calibrate();
1064 Int_t kroadyShift(0);
1065 Float_t bz(AliTrackerBase::GetBz());
1066 if(TMath::Abs(bz)>2.){
1067 if(bz<0.) kroadyShift = chgPos ? +1 : -1;
1068 else kroadyShift = chgPos ? -1 : +1;
1070 AliDebug(4, Form("\n syTrk[cm]=%4.2f dydxTrk[deg]=%+6.2f rs[%d] Chg[%c] rY[cm]=%4.2f rZ[cm]=%5.2f TC[%c]", syRef, TMath::ATan(fYref[1])*TMath::RadToDeg(), kroadyShift, chgPos?'+':'-', kroady, kroadz, tilt?'y':'n'));
1071 Double_t phiTrk(TMath::ATan(fYref[1])),
1072 thtTrk(TMath::ATan(fZref[1]));
1074 // working variables
1075 const Int_t kNrows = 16;
1076 const Int_t kNcls = 3*kNclusters; // buffer size
1077 TObjArray clst[kNrows];
1078 Bool_t blst[kNrows][kNcls];
1083 xres[kNrows][kNcls], yres[kNrows][kNcls], zres[kNrows][kNcls], s2y[kNrows][kNcls];
1084 Int_t idxs[kNrows][kNcls], ncl[kNrows], ncls = 0;
1085 memset(ncl, 0, kNrows*sizeof(Int_t));
1086 memset(zc, 0, kNrows*sizeof(Double_t));
1087 memset(idxs, 0, kNrows*kNcls*sizeof(Int_t));
1088 memset(xres, 0, kNrows*kNcls*sizeof(Double_t));
1089 memset(yres, 0, kNrows*kNcls*sizeof(Double_t));
1090 memset(zres, 0, kNrows*kNcls*sizeof(Double_t));
1091 memset(s2y, 0, kNrows*kNcls*sizeof(Double_t));
1092 memset(blst, 0, kNrows*kNcls*sizeof(Bool_t)); //this is 8 times faster to memset than "memset(clst, 0, kNrows*kNcls*sizeof(AliTRDcluster*))"
1094 Double_t roady(0.), s2Mean(0.), sMean(0.); Int_t ns2Mean(0);
1096 // Do cluster projection and pick up cluster candidates
1097 AliTRDcluster *c(NULL);
1098 AliTRDchamberTimeBin *layer(NULL);
1099 Bool_t kBUFFER = kFALSE;
1100 for (Int_t it = 0; it < kNtb; it++) {
1101 if(!(layer = chamber->GetTB(it))) continue;
1102 if(!Int_t(*layer)) continue;
1103 // get track projection at layers position
1104 dx = fX0 - layer->GetX();
1105 yt = fYref[0] - fYref[1] * dx;
1106 zt = fZref[0] - fZref[1] * dx;
1107 // get standard cluster error corrected for tilt if selected
1108 cp.SetLocalTimeBin(it);
1109 cp.SetSigmaY2(0.02, fDiffT, fExB, dx, -1./*zt*/, fYref[1]);
1110 s2yCl = cp.GetSigmaY2() + sysCov[0]; if(!tilt) s2yCl = (s2yCl + t2*s2zCl)/(1.+t2);
1111 if(TMath::Abs(it-12)<7){ s2Mean += cp.GetSigmaY2(); ns2Mean++;}
1112 // get estimated road in r-phi direction
1113 roady = TMath::Min(3.*TMath::Sqrt(12.*(s2yTrk + s2yCl)), kroady);
1115 AliDebug(5, Form("\n"
1116 " %2d xd[cm]=%6.3f yt[cm]=%7.2f zt[cm]=%8.2f\n"
1117 " syTrk[um]=%6.2f syCl[um]=%6.2f syClTlt[um]=%6.2f\n"
1120 , 1.e4*TMath::Sqrt(s2yTrk), 1.e4*TMath::Sqrt(cp.GetSigmaY2()+sysCov[0]), 1.e4*TMath::Sqrt(s2yCl)
1123 // get clusters from layer
1124 cond[0] = yt/*+0.5*kroadyShift*kroady*/; cond[2] = roady;
1125 cond[1] = zt; cond[3] = kroadz;
1126 Int_t n=0, idx[6]; layer->GetClusters(cond, idx, n, 6);
1127 for(Int_t ic = n; ic--;){
1128 c = (*layer)[idx[ic]];
1129 dx = fX0 - c->GetX();
1130 yt = fYref[0] - fYref[1] * dx;
1131 zt = fZref[0] - fZref[1] * dx;
1132 dz = zt - c->GetZ();
1133 dy = yt - (c->GetY() + (tilt ? (GetTilt() * dz) : 0.));
1134 Int_t r = c->GetPadRow();
1135 clst[r].AddAtAndExpand(c, ncl[r]);
1136 blst[r][ncl[r]] = kTRUE;
1137 idxs[r][ncl[r]] = idx[ic];
1138 zres[r][ncl[r]] = dz/GetPadLength();
1139 yres[r][ncl[r]] = dy;
1140 xres[r][ncl[r]] = dx;
1142 // TODO temporary solution to avoid divercences in error parametrization
1143 s2y[r][ncl[r]] = TMath::Min(c->GetSigmaY2()+sysCov[0], 0.025);
1144 AliDebug(5, Form(" -> dy[cm]=%+7.4f yc[cm]=%7.2f row[%d] idx[%2d]", dy, c->GetY(), r, ncl[r]));
1147 if(ncl[r] >= kNcls) {
1148 AliWarning(Form("Cluster candidates row[%d] reached buffer limit[%d]. Some may be lost.", r, kNcls));
1156 AliDebug(1, Form("CLUSTERS FOUND %d LESS THAN THRESHOLD %d.", ncls, kClmin));
1157 SetErrorMsg(kAttachClFound);
1158 for(Int_t ir(kNrows);ir--;) clst[ir].Clear();
1162 AliDebug(1, Form("CLUSTERS IN TimeBins %d LESS THAN THRESHOLD %d.", ns2Mean, kTBmin));
1163 SetErrorMsg(kAttachClFound);
1164 for(Int_t ir(kNrows);ir--;) clst[ir].Clear();
1167 s2Mean /= ns2Mean; sMean = TMath::Sqrt(s2Mean);
1168 //Double_t sRef(TMath::Sqrt(s2Mean+s2yTrk)); // reference error parameterization
1170 // organize row candidates
1171 Int_t idxRow[kNrows], nrc(0); Double_t zresRow[kNrows];
1172 for(Int_t ir(0); ir<kNrows; ir++){
1173 idxRow[ir]=-1; zresRow[ir] = 999.;
1174 if(!ncl[ir]) continue;
1175 // get mean z resolution
1176 dz = 0.; for(Int_t ic = ncl[ir]; ic--;) dz += zres[ir][ic]; dz/=ncl[ir];
1178 idxRow[nrc] = ir; zresRow[nrc] = TMath::Abs(dz); nrc++;
1180 AliDebug(4, Form("Found %d clusters in %d rows. Sorting ...", ncls, nrc));
1182 // sort row candidates
1185 if(zresRow[0]>zresRow[1]){ // swap
1186 Int_t itmp=idxRow[1]; idxRow[1] = idxRow[0]; idxRow[0] = itmp;
1187 Double_t dtmp=zresRow[1]; zresRow[1] = zresRow[0]; zresRow[0] = dtmp;
1189 if(TMath::Abs(idxRow[1] - idxRow[0]) != 1){
1190 SetErrorMsg(kAttachRowGap);
1191 AliDebug(2, Form("Rows attached not continuous. Select first candidate.\n"
1192 " row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f",
1193 idxRow[0], ncl[idxRow[0]], zresRow[0], idxRow[1], idxRow[1]<0?0:ncl[idxRow[1]], zresRow[1]));
1194 nrc=1; idxRow[1] = -1; zresRow[1] = 999.;
1198 TMath::Sort(nrc, zresRow, idx0, kFALSE);
1199 nrc = 3; // select only maximum first 3 candidates
1200 Int_t iatmp[] = {-1, -1, -1}; Double_t datmp[] = {999., 999., 999.};
1201 for(Int_t irc(0); irc<nrc; irc++){
1202 iatmp[irc] = idxRow[idx0[irc]];
1203 datmp[irc] = zresRow[idx0[irc]];
1205 idxRow[0] = iatmp[0]; zresRow[0] = datmp[0];
1206 idxRow[1] = iatmp[1]; zresRow[1] = datmp[1];
1207 idxRow[2] = iatmp[2]; zresRow[2] = datmp[2]; // temporary
1208 if(TMath::Abs(idxRow[1] - idxRow[0]) != 1){
1209 SetErrorMsg(kAttachRowGap);
1210 AliDebug(2, Form("Rows attached not continuous. Turn on selection.\n"
1211 "row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f\n"
1212 "row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f\n"
1213 "row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f",
1214 idxRow[0], ncl[idxRow[0]], zresRow[0],
1215 idxRow[1], ncl[idxRow[1]], zresRow[1],
1216 idxRow[2], ncl[idxRow[2]], zresRow[2]));
1217 if(TMath::Abs(idxRow[0] - idxRow[2]) == 1){ // select second candidate
1218 AliDebug(2, "Solved ! Remove second candidate.");
1220 idxRow[1] = idxRow[2]; zresRow[1] = zresRow[2]; // swap
1221 idxRow[2] = -1; zresRow[2] = 999.; // remove
1222 } else if(TMath::Abs(idxRow[1] - idxRow[2]) == 1){
1223 if(ncl[idxRow[1]]+ncl[idxRow[2]] > ncl[idxRow[0]]){
1224 AliDebug(2, "Solved ! Remove first candidate.");
1226 idxRow[0] = idxRow[1]; zresRow[0] = zresRow[1]; // swap
1227 idxRow[1] = idxRow[2]; zresRow[1] = zresRow[2]; // swap
1229 AliDebug(2, "Solved ! Remove second and third candidate.");
1231 idxRow[1] = -1; zresRow[1] = 999.; // remove
1232 idxRow[2] = -1; zresRow[2] = 999.; // remove
1235 AliDebug(2, "Unsolved !!! Remove second and third candidate.");
1237 idxRow[1] = -1; zresRow[1] = 999.; // remove
1238 idxRow[2] = -1; zresRow[2] = 999.; // remove
1240 } else { // remove temporary candidate
1242 idxRow[2] = -1; zresRow[2] = 999.;
1246 AliDebug(4, Form("Sorted row candidates:\n"
1247 " row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f row[%2d] Ncl[%2d] <dz>[cm]=%+8.2f"
1248 , idxRow[0], ncl[idxRow[0]], zresRow[0], idxRow[1], idxRow[1]<0?0:ncl[idxRow[1]], zresRow[1]));
1250 // initialize debug streamer
1251 TTreeSRedirector *pstreamer(NULL);
1252 if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1254 // save config. for calibration
1255 TVectorD vdy[2], vdx[2], vs2[2];
1256 for(Int_t jr(0); jr<nrc; jr++){
1257 Int_t ir(idxRow[jr]);
1258 vdx[jr].ResizeTo(ncl[ir]); vdy[jr].ResizeTo(ncl[ir]); vs2[jr].ResizeTo(ncl[ir]);
1259 for(Int_t ic(ncl[ir]); ic--;){
1260 vdx[jr](ic) = xres[ir][ic];
1261 vdy[jr](ic) = yres[ir][ic];
1262 vs2[jr](ic) = s2y[ir][ic];
1265 (*pstreamer) << "AttachClusters4"
1266 << "r0=" << idxRow[0]
1267 << "dz0=" << zresRow[0]
1268 << "dx0=" << &vdx[0]
1269 << "dy0=" << &vdy[0]
1270 << "s20=" << &vs2[0]
1271 << "r1=" << idxRow[1]
1272 << "dz1=" << zresRow[1]
1273 << "dx1=" << &vdx[1]
1274 << "dy1=" << &vdy[1]
1275 << "s21=" << &vs2[1]
1277 vdx[0].Clear(); vdy[0].Clear(); vs2[0].Clear();
1278 vdx[1].Clear(); vdy[1].Clear(); vs2[1].Clear();
1279 if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 4){
1280 Int_t idx(idxRow[1]);
1282 for(Int_t ir(0); ir<kNrows; ir++){
1283 if(clst[ir].GetEntries()>0) continue;
1288 (*pstreamer) << "AttachClusters5"
1289 << "c0.=" << &clst[idxRow[0]]
1290 << "c1.=" << &clst[idx]
1295 //=======================================================================================
1296 // Analyse cluster topology
1297 Double_t f[kNcls], // likelihood factors for segments
1298 r[2][kNcls], // d(dydx) of tracklet candidate with respect to track
1299 xm[2][kNcls], // mean <x>
1300 ym[2][kNcls], // mean <y>
1301 sm[2][kNcls], // mean <s_y>
1302 s[2][kNcls], // sigma_y
1303 p[2][kNcls], // prob of Gauss
1304 q[2][kNcls]; // charge/segment
1305 memset(f, 0, kNcls*sizeof(Double_t));
1306 Int_t index[2][kNcls], n[2][kNcls];
1307 memset(n, 0, 2*kNcls*sizeof(Int_t));
1308 Int_t mts(0), nts[2] = {0, 0}; // no of tracklet segments in row
1309 AliTRDpadPlane *pp(AliTRDtransform::Geometry().GetPadPlane(fDet));
1310 AliTRDtrackletOflHelper helper;
1311 Int_t lyDet(AliTRDgeometry::GetLayer(fDet));
1312 for(Int_t jr(0), n0(0); jr<nrc; jr++){
1313 Int_t ir(idxRow[jr]);
1314 // cluster segmentation
1315 Bool_t kInit(kFALSE);
1317 n0 = helper.Init(pp, &clst[ir]); kInit = kTRUE;
1318 if(!n0 || (helper.ClassifyTopology() == AliTRDtrackletOflHelper::kNormal)){
1319 nts[jr] = 1; memset(index[jr], 0, ncl[ir]*sizeof(Int_t));
1324 nts[jr] = AliTRDtrackletOflHelper::Segmentation(ncl[ir], xres[ir], yres[ir], index[jr]);
1325 for(Int_t ic(ncl[ir]);ic--;) n[jr][index[jr][ic]]++;
1329 // tracklet segment processing
1330 for(Int_t its(0); its<nts[jr]; its++){
1331 if(n[jr][its]<=2) { // don't touch small segments
1332 xm[jr][its] = 0.;ym[jr][its] = 0.;sm[jr][its] = 0.;
1333 for(Int_t ic(ncl[ir]); ic--;){
1334 if(its != index[jr][ic]) continue;
1335 ym[jr][its] += yres[ir][ic];
1336 xm[jr][its] += xres[ir][ic];
1337 sm[jr][its] += TMath::Sqrt(s2y[ir][ic]);
1339 if(n[jr][its]==2){ xm[jr][its] *= 0.5; ym[jr][its] *= 0.5; sm[jr][its] *= 0.5;}
1340 xm[jr][its]= fX0 - xm[jr][its];
1348 // for longer tracklet segments
1349 if(!kInit) n0 = helper.Init(pp, &clst[ir], index[jr], its);
1350 Int_t n1 = helper.GetRMS(r[jr][its], ym[jr][its], s[jr][its], fX0/*xm[jr][its]*/);
1351 p[jr][its] = Double_t(n1)/n0;
1352 sm[jr][its] = helper.GetSyMean();
1353 q[jr][its] = helper.GetQ()/TMath::Sqrt(1. + fYref[1]*fYref[1] + fZref[1]*fZref[1]);
1355 Double_t dxm= fX0 - xm[jr][its];
1356 yt = fYref[0] - fYref[1]*dxm;
1357 zt = fZref[0] - fZref[1]*dxm;
1358 // correct tracklet fit for tilt
1359 ym[jr][its]+= GetTilt()*(zt - zc[ir]);
1360 r[jr][its] += GetTilt() * fZref[1];
1361 // correct tracklet fit for track position/inclination
1362 ym[jr][its] = yt - ym[jr][its];
1363 r[jr][its] = (r[jr][its] - fYref[1])/(1+r[jr][its]*fYref[1]);
1364 // report inclination in radians
1365 r[jr][its] = TMath::ATan(r[jr][its]);
1366 if(jr) continue; // calculate only for first row likelihoods
1368 f[its] = attach->CookLikelihood(chgPos, lyDet, fPt, phiTrk, n[jr][its], ym[jr][its]/*sRef*/, r[jr][its]*TMath::RadToDeg(), s[jr][its]/sm[jr][its]);
1371 AliDebug(4, Form(" Tracklet candidates: row[%2d] = %2d row[%2d] = %2d:", idxRow[0], nts[0], idxRow[1], nts[1]));
1372 if(AliLog::GetDebugLevel("TRD", "AliTRDseedV1")>3){
1373 for(Int_t jr(0); jr<nrc; jr++){
1374 Int_t ir(idxRow[jr]);
1375 for(Int_t its(0); its<nts[jr]; its++){
1376 printf(" segId[%2d] row[%2d] Ncl[%2d] x[cm]=%7.2f dz[pu]=%4.2f dy[mm]=%+7.3f r[deg]=%+6.2f p[%%]=%6.2f s[um]=%7.2f\n",
1377 its, ir, n[jr][its], xm[jr][its], zresRow[jr], 1.e1*ym[jr][its], r[jr][its]*TMath::RadToDeg(), 100.*p[jr][its], 1.e4*s[jr][its]);
1381 if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 2 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1383 // save config. for calibration
1384 TVectorD vidx, vn, vx, vy, vr, vs, vsm, vp, vf;
1385 vidx.ResizeTo(ncl[idxRow[0]]+(idxRow[1]<0?0:ncl[idxRow[1]]));
1394 for(Int_t jr(0), jts(0), jc(0); jr<nrc; jr++){
1395 Int_t ir(idxRow[jr]);
1396 for(Int_t its(0); its<nts[jr]; its++, jts++){
1397 vn[jts] = n[jr][its];
1398 vx[jts] = xm[jr][its];
1399 vy[jts] = ym[jr][its];
1400 vr[jts] = r[jr][its];
1401 vs[jts] = s[jr][its];
1402 vsm[jts]= sm[jr][its];
1403 vp[jts] = p[jr][its];
1404 vf[jts] = jr?-1.:f[its];
1406 for(Int_t ic(0); ic<ncl[ir]; ic++, jc++) vidx[jc] = index[jr][ic];
1408 (*pstreamer) << "AttachClusters3"
1421 //=========================================================
1422 // Get seed tracklet segment
1423 Int_t idx2[kNcls]; memset(idx2, 0, kNcls*sizeof(Int_t)); // seeding indexing
1424 if(nts[0]>1) TMath::Sort(nts[0], f, idx2);
1425 Int_t is(idx2[0]); // seed index
1426 Int_t idxTrklt[kNcls],
1429 Double_t fTrklt(f[is]),
1437 memset(idxTrklt, 0, kNcls*sizeof(Int_t));
1438 // check seed idx2[0] exit if not found
1440 AliDebug(1, Form("Seed seg[%d] row[%2d] n[%2d] f[%f]<0.01.", is, idxRow[0], n[0][is], f[is]));
1441 SetErrorMsg(kAttachClAttach);
1442 if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1445 if(IsKink()) SETBIT(stat, 1);
1446 if(IsStandAlone()) SETBIT(stat, 2);
1447 if(IsRowCross()) SETBIT(stat, 3);
1448 SETBIT(stat, 4); // set error bit
1449 TVectorD vidx; vidx.ResizeTo(1); vidx[0] = is;
1450 (*pstreamer) << "AttachClusters2"
1456 << "y0=" << fYref[0]
1457 << "z0=" << fZref[0]
1461 << "s2Trk=" << s2yTrk
1462 << "s2Cl=" << s2Mean
1477 AliDebug(2, Form("Seed seg[%d] row[%2d] n[%2d] dy[%f] r[%+5.2f] s[%+5.2f] f[%5.3f] q[%6.2f]", is, idxRow[0], n[0][is], ym[0][is], r[0][is]*TMath::RadToDeg(), s[0][is]/sm[0][is], f[is], q[0][is]));
1479 // save seeding segment in the helper
1480 idxTrklt[kts++] = is;
1481 helper.Init(pp, &clst[idxRow[0]], index[0], is);
1482 AliTRDtrackletOflHelper test; // helper to test segment expantion
1483 Float_t rcLikelihood(0.); SetBit(kRowCross, kFALSE);
1484 Double_t dyRez[kNcls]; Int_t idx3[kNcls];
1486 //=========================================================
1487 // Define filter parameters from OCDB
1488 Int_t kNSgmDy[2]; attach->GetNsgmDy(kNSgmDy[0], kNSgmDy[1]);
1489 Float_t kLikeMinRelDecrease[2]; attach->GetLikeMinRelDecrease(kLikeMinRelDecrease[0], kLikeMinRelDecrease[1]);
1490 Float_t kRClikeLimit(attach->GetRClikeLimit());
1492 //=========================================================
1493 // Try attaching next segments from first row (if any)
1495 Int_t jr(0), ir(idxRow[jr]);
1496 // organize secondary sgms. in decreasing order of their distance from seed
1497 memset(dyRez, 0, nts[jr]*sizeof(Double_t));
1498 for(Int_t jts(1); jts<nts[jr]; jts++) {
1499 Int_t its(idx2[jts]);
1500 Double_t rot(TMath::Tan(r[0][is]));
1501 dyRez[its] = TMath::Abs(ym[0][is] - ym[jr][its] + rot*(xm[0][is]-xm[jr][its]));
1503 TMath::Sort(nts[jr], dyRez, idx3, kFALSE);
1504 for (Int_t jts(1); jts<nts[jr]; jts++) {
1505 Int_t its(idx3[jts]);
1506 if(dyRez[its] > kNSgmDy[jr]*smTrklt){
1507 AliDebug(2, Form("Reject seg[%d] row[%2d] n[%2d] dy[%f] > %d*s[%f].", its, idxRow[jr], n[jr][its], dyRez[its], kNSgmDy[jr], kNSgmDy[jr]*smTrklt));
1512 Int_t n0 = test.Expand(&clst[ir], index[jr], its);
1513 Double_t rt, dyt, st, xt, smt, pt, qt, ft;
1514 Int_t n1 = test.GetRMS(rt, dyt, st, fX0/*xt*/);
1515 pt = Double_t(n1)/n0;
1516 smt = test.GetSyMean();
1517 qt = test.GetQ()/TMath::Sqrt(1. + fYref[1]*fYref[1] + fZref[1]*fZref[1]);
1520 Double_t dxm= fX0 - xt;
1521 yt = fYref[0] - fYref[1]*dxm;
1522 zt = fZref[0] - fZref[1]*dxm;
1523 // correct tracklet fit for tilt
1524 dyt+= GetTilt()*(zt - zc[idxRow[0]]);
1525 rt += GetTilt() * fZref[1];
1526 // correct tracklet fit for track position/inclination
1528 rt = (rt - fYref[1])/(1+rt*fYref[1]);
1529 // report inclination in radians
1530 rt = TMath::ATan(rt);
1532 ft = (n0>=2) ? attach->CookLikelihood(chgPos, lyDet, fPt, phiTrk, n0, dyt/*sRef*/, rt*TMath::RadToDeg(), st/smt) : 0.;
1533 Bool_t kAccept(ft>=fTrklt*(1.-kLikeMinRelDecrease[jr]));
1535 AliDebug(2, Form("%s seg[%d] row[%2d] n[%2d] dy[%f] r[%+5.2f] s[%+5.2f] f[%f] < %4.2f*F[%f].",
1536 (kAccept?"Adding":"Reject"), its, idxRow[jr], n0, dyt, rt*TMath::RadToDeg(), st/smt, ft, 1.-kLikeMinRelDecrease[jr], fTrklt*(1.-kLikeMinRelDecrease[jr])));
1538 idxTrklt[kts++] = its;
1548 helper.Expand(&clst[ir], index[jr], its);
1553 //=========================================================
1554 // Try attaching next segments from second row (if any)
1555 if(nts[1] && (rcLikelihood = zresRow[0]/zresRow[1]) > kRClikeLimit){
1556 // organize secondaries in decreasing order of their distance from seed
1557 Int_t jr(1), ir(idxRow[jr]);
1558 memset(dyRez, 0, nts[jr]*sizeof(Double_t));
1559 Double_t rot(TMath::Tan(r[0][is]));
1560 for(Int_t jts(0); jts<nts[jr]; jts++) {
1561 dyRez[jts] = TMath::Abs(ym[0][is] - ym[jr][jts] + rot*(xm[0][is]-xm[jr][jts]));
1563 TMath::Sort(nts[jr], dyRez, idx3, kFALSE);
1564 for (Int_t jts(0); jts<nts[jr]; jts++) {
1565 Int_t its(idx3[jts]);
1566 if(dyRez[its] > kNSgmDy[jr]*smTrklt){
1567 AliDebug(2, Form("Reject seg[%d] row[%2d] n[%2d] dy[%f] > %d*s[%f].", its, idxRow[jr], n[jr][its], dyRez[its], kNSgmDy[jr], kNSgmDy[jr]*smTrklt));
1572 Int_t n0 = test.Expand(&clst[ir], index[jr], its);
1573 Double_t rt, dyt, st, xt, smt, pt, qt, ft;
1574 Int_t n1 = test.GetRMS(rt, dyt, st, fX0/*xt*/);
1575 pt = Double_t(n1)/n0;
1576 smt = test.GetSyMean();
1577 qt = test.GetQ()/TMath::Sqrt(1. + fYref[1]*fYref[1] + fZref[1]*fZref[1]);
1580 Double_t dxm= fX0 - xt;
1581 yt = fYref[0] - fYref[1]*dxm;
1582 zt = fZref[0] - fZref[1]*dxm;
1583 // correct tracklet fit for tilt
1584 dyt+= GetTilt()*(zt - zc[idxRow[0]]);
1585 rt += GetTilt() * fZref[1];
1586 // correct tracklet fit for track position/inclination
1588 rt = (rt - fYref[1])/(1+rt*fYref[1]);
1589 // report inclination in radians
1590 rt = TMath::ATan(rt);
1592 ft = (n0>=2) ? attach->CookLikelihood(chgPos, lyDet, fPt, phiTrk, n0, dyt/*sRef*/, rt*TMath::RadToDeg(), st/smt) : 0.;
1593 Bool_t kAccept(ft>=fTrklt*(1.-kLikeMinRelDecrease[jr]));
1595 AliDebug(2, Form("%s seg[%d] row[%2d] n[%2d] dy[%f] r[%+5.2f] s[%+5.2f] f[%f] < %4.2f*F[%f].",
1596 (kAccept?"Adding":"Reject"), its, idxRow[jr], n0, dyt, rt*TMath::RadToDeg(), st/smt, ft, 1.-kLikeMinRelDecrease[jr], fTrklt*(1.-kLikeMinRelDecrease[jr])));
1598 idxTrklt[kts++] = its;
1608 helper.Expand(&clst[ir], index[jr], its);
1609 SetBit(kRowCross, kTRUE); // mark pad row crossing
1613 // clear local copy of clusters
1614 for(Int_t ir(0); ir<kNrows; ir++) clst[ir].Clear();
1616 if(!pstreamer && recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 1 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
1619 if(IsKink()) SETBIT(stat, 1);
1620 if(IsStandAlone()) SETBIT(stat, 2);
1621 if(IsRowCross()) SETBIT(stat, 3);
1622 TVectorD vidx; vidx.ResizeTo(kts);
1623 for(Int_t its(0); its<kts; its++) vidx[its] = idxTrklt[its];
1624 (*pstreamer) << "AttachClusters2"
1630 << "y0=" << fYref[0]
1631 << "z0=" << fZref[0]
1635 << "s2Trk=" << s2yTrk
1636 << "s2Cl=" << s2Mean
1651 //=========================================================
1653 Int_t nselected(0), nc(0);
1654 TObjArray *selected(helper.GetClusters());
1655 if(!selected || !(nselected = selected->GetEntriesFast())){
1656 AliError("Cluster candidates missing !!!");
1657 SetErrorMsg(kAttachClAttach);
1660 for(Int_t ic(0); ic<nselected; ic++){
1661 if(!(c = (AliTRDcluster*)selected->At(ic))) continue;
1662 Int_t it(c->GetPadTime()),
1663 jr(Int_t(helper.GetRow() != c->GetPadRow())),
1666 AliDebug(1, Form("Multiple clusters/tb for D[%03d] Tb[%02d] Row[%2d]", fDet, it, c->GetPadRow()));
1667 continue; // already booked
1669 // TODO proper indexing of clusters !!
1670 fIndexes[idx] = chamber->GetTB(it)->GetGlobalIndex(idxs[idxRow[jr]][ic]);
1674 AliDebug(2, Form("Clusters Found[%2d] Attached[%2d] RC[%c]", nselected, nc, IsRowCross()?'y':'n'));
1676 // number of minimum numbers of clusters expected for the tracklet
1678 AliDebug(1, Form("NOT ENOUGH CLUSTERS %d ATTACHED TO THE TRACKLET [min %d] FROM FOUND %d.", nc, kClmin, ncls));
1679 SetErrorMsg(kAttachClAttach);
1684 // Load calibration parameters for this tracklet
1687 // calculate dx for time bins in the drift region (calibration aware)
1688 Float_t x[2] = {0.,0.}; Int_t tb[2]={0,0};
1689 for (Int_t it = t0, irp=0; irp<2 && it < AliTRDtrackerV1::GetNTimeBins(); it++) {
1690 if(!fClusters[it]) continue;
1691 x[irp] = fClusters[it]->GetX();
1692 tb[irp] = fClusters[it]->GetLocalTimeBin();
1695 Int_t dtb = tb[1] - tb[0];
1696 fdX = dtb ? (x[0] - x[1]) / dtb : 0.15;
1700 //____________________________________________________________
1701 void AliTRDseedV1::Bootstrap(const AliTRDReconstructor *rec)
1703 // Fill in all derived information. It has to be called after recovery from file or HLT.
1704 // The primitive data are
1705 // - list of clusters
1706 // - detector (as the detector will be removed from clusters)
1707 // - position of anode wire (fX0) - temporary
1708 // - track reference position and direction
1709 // - momentum of the track
1710 // - time bin length [cm]
1712 // A.Bercuci <A.Bercuci@gsi.de> Oct 30th 2008
1714 fkReconstructor = rec;
1716 SetPadPlane(g.GetPadPlane(fDet));
1718 //fSnp = fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);
1720 Int_t n = 0, nshare = 0, nused = 0;
1721 AliTRDcluster **cit = &fClusters[0];
1722 for(Int_t ic = kNclusters; ic--; cit++){
1725 if((*cit)->IsShared()) nshare++;
1726 if((*cit)->IsUsed()) nused++;
1728 SetN(n); SetNUsed(nused); SetNShared(nshare);
1735 //____________________________________________________________________
1736 Bool_t AliTRDseedV1::Fit(UChar_t opt)
1739 // Linear fit of the clusters attached to the tracklet
1742 // - opt : switch for tilt pad correction of cluster y position. Options are
1743 // 0 no correction [default]
1744 // 1 full tilt correction [dz/dx and z0]
1745 // 2 pseudo tilt correction [dz/dx from pad-chamber geometry]
1748 // True if successful
1750 // Detailed description
1752 // Fit in the xy plane
1754 // The fit is performed to estimate the y position of the tracklet and the track
1755 // angle in the bending plane. The clusters are represented in the chamber coordinate
1756 // system (with respect to the anode wire - see AliTRDtrackerV1::FollowBackProlongation()
1757 // on how this is set). The x and y position of the cluster and also their variances
1758 // are known from clusterizer level (see AliTRDcluster::GetXloc(), AliTRDcluster::GetYloc(),
1759 // AliTRDcluster::GetSX() and AliTRDcluster::GetSY()).
1760 // If gaussian approximation is used to calculate y coordinate of the cluster the position
1761 // is recalculated taking into account the track angle. The general formula to calculate the
1762 // error of cluster position in the gaussian approximation taking into account diffusion and track
1763 // inclination is given for TRD by:
1765 // #sigma^{2}_{y} = #sigma^{2}_{PRF} + #frac{x#delta_{t}^{2}}{(1+tg(#alpha_{L}))^{2}} + #frac{x^{2}tg^{2}(#phi-#alpha_{L})tg^{2}(#alpha_{L})}{12}
1768 // Since errors are calculated only in the y directions, radial errors (x direction) are mapped to y
1769 // by projection i.e.
1771 // #sigma_{x|y} = tg(#phi) #sigma_{x}
1773 // and also by the lorentz angle correction
1775 // Fit in the xz plane
1777 // The "fit" is performed to estimate the radial position (x direction) where pad row cross happens.
1778 // If no pad row crossing the z position is taken from geometry and radial position is taken from the xy
1781 // There are two methods to estimate the radial position of the pad row cross:
1782 // 1. leading cluster radial position : Here the lower part of the tracklet is considered and the last
1783 // cluster registered (at radial x0) on this segment is chosen to mark the pad row crossing. The error
1784 // of the z estimate is given by :
1786 // #sigma_{z} = tg(#theta) #Delta x_{x_{0}}/12
1788 // The systematic errors for this estimation are generated by the following sources:
1789 // - no charge sharing between pad rows is considered (sharp cross)
1790 // - missing cluster at row cross (noise peak-up, under-threshold signal etc.).
1792 // 2. charge fit over the crossing point : Here the full energy deposit along the tracklet is considered
1793 // to estimate the position of the crossing by a fit in the qx plane. The errors in the q directions are
1794 // parameterized as s_q = q^2. The systematic errors for this estimation are generated by the following sources:
1795 // - no general model for the qx dependence
1796 // - physical fluctuations of the charge deposit
1797 // - gain calibration dependence
1799 // Estimation of the radial position of the tracklet
1801 // For pad row cross the radial position is taken from the xz fit (see above). Otherwise it is taken as the
1802 // interpolation point of the tracklet i.e. the point where the error in y of the fit is minimum. The error
1803 // in the y direction of the tracklet is (see AliTRDseedV1::GetCovAt()):
1805 // #sigma_{y} = #sigma^{2}_{y_{0}} + 2xcov(y_{0}, dy/dx) + #sigma^{2}_{dy/dx}
1807 // and thus the radial position is:
1809 // x = - cov(y_{0}, dy/dx)/#sigma^{2}_{dy/dx}
1812 // Estimation of tracklet position error
1814 // The error in y direction is the error of the linear fit at the radial position of the tracklet while in the z
1815 // direction is given by the cluster error or pad row cross error. In case of no pad row cross this is given by:
1817 // #sigma_{y} = #sigma^{2}_{y_{0}} - 2cov^{2}(y_{0}, dy/dx)/#sigma^{2}_{dy/dx} + #sigma^{2}_{dy/dx}
1818 // #sigma_{z} = Pad_{length}/12
1820 // For pad row cross the full error is calculated at the radial position of the crossing (see above) and the error
1821 // in z by the width of the crossing region - being a matter of parameterization.
1823 // #sigma_{z} = tg(#theta) #Delta x_{x_{0}}/12
1825 // In case of no tilt correction (default in the barrel tracking) the tilt is taken into account by the rotation of
1826 // the covariance matrix. See AliTRDseedV1::GetCovAt() for details.
1829 // A.Bercuci <A.Bercuci@gsi.de>
1831 if(!fkReconstructor){
1832 AliError("The tracklet needs the reconstruction setup. Please initialize by SetReconstructor().");
1835 if(!IsCalibrated()) Calibrate();
1837 AliWarning(Form("Option [%d] outside range [0, 2]. Using default",opt));
1841 const Int_t kClmin = 8;
1842 const Float_t kScalePulls = 10.; // factor to scale y pulls - NOT UNDERSTOOD
1843 // get track direction
1844 Double_t y0 = fYref[0];
1845 Double_t dydx = fYref[1];
1846 Double_t z0 = fZref[0];
1847 Double_t dzdx = fZref[1];
1849 AliTRDtrackerV1::AliTRDLeastSquare fitterY;
1850 AliTRDtrackerV1::AliTRDLeastSquare fitterZ;
1852 // book cluster information
1853 Double_t qc[kNclusters], xc[kNclusters], yc[kNclusters], zc[kNclusters], sy[kNclusters];
1855 Bool_t tilt(opt==1) // full tilt correction
1856 ,pseudo(opt==2) // pseudo tilt correction
1857 ,rc(IsRowCross()) // row cross candidate
1858 ,kDZDX(IsPrimary());// switch dzdx calculation for barrel primary tracks
1859 Int_t n(0); // clusters used in fit
1860 AliTRDcluster *c(NULL), *cc(NULL), **jc = &fClusters[0];
1861 const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam(); //the dynamic cast in GetRecoParam is slow, so caching the pointer to it
1863 const Char_t *tcName[]={"NONE", "FULL", "HALF"};
1864 AliDebug(2, Form("Options : TC[%s] dzdx[%c]", tcName[opt], kDZDX?'Y':'N'));
1867 for (Int_t ic=0; ic<kNclusters; ic++, ++jc) {
1868 xc[ic] = -1.; yc[ic] = 999.; zc[ic] = 999.; sy[ic] = 0.;
1869 if(!(c = (*jc))) continue;
1870 if(!c->IsInChamber()) continue;
1871 // compute pseudo tilt correction
1873 fZfit[0] = c->GetZ();
1875 for(Int_t kc=AliTRDseedV1::kNtb; kc<AliTRDseedV1::kNclusters; kc++){
1876 if(!(cc=fClusters[kc])) continue;
1877 if(!cc->IsInChamber()) continue;
1878 fZfit[0] += cc->GetZ(); fZfit[0] *= 0.5;
1882 fZfit[1] = fZfit[0]/fX0;
1884 fZfit[0] += fZfit[1]*0.5*AliTRDgeometry::CdrHght();
1885 fZfit[1] = fZfit[0]/fX0;
1891 if(c->GetNPads()>4) w = .5;
1892 if(c->GetNPads()>5) w = .2;
1895 qc[n] = TMath::Abs(c->GetQ());
1896 // pad row of leading
1898 xc[n] = fX0 - c->GetX();
1900 // Recalculate cluster error based on tracking information
1901 c->SetSigmaY2(fS2PRF, fDiffT, fExB, xc[n], -1./*zcorr?zt:-1.*/, dydx);
1902 c->SetSigmaZ2(fPad[0]*fPad[0]/12.); // for HLT
1903 sy[n] = TMath::Sqrt(c->GetSigmaY2());
1905 yc[n] = recoParam->UseGAUS() ?
1906 c->GetYloc(y0, sy[n], GetPadWidth()): c->GetY();
1909 //optional r-phi correction
1910 //printf(" n[%2d] yc[%7.5f] ", n, yc[n]);
1911 Float_t correction(0.);
1912 if(tilt) correction = fPad[2]*(xc[n]*dzdx + zc[n] - z0);
1913 else if(pseudo) correction = fPad[2]*(xc[n]*fZfit[1] + zc[n]-fZfit[0]);
1915 //printf("corr(%s%s)[%7.5f] yc1[%7.5f]\n", (tilt?"TC":""), (zcorr?"PC":""), correction, yc[n]);
1917 AliDebug(5, Form(" tb[%2d] dx[%6.3f] y[%6.2f+-%6.3f]", c->GetLocalTimeBin(), xc[n], yc[n], sy[n]));
1918 fitterY.AddPoint(&xc[n], yc[n], sy[n]);
1919 if(rc) fitterZ.AddPoint(&xc[n], qc[n]*(ic<kNtb?1.:-1.), 1.);
1925 AliDebug(1, Form("Not enough clusters to fit. Clusters: Attached[%d] Fit[%d].", GetN(), n));
1926 SetErrorMsg(kFitCl);
1930 if(!fitterY.Eval()){
1931 AliDebug(1, "Fit Y failed.");
1932 SetErrorMsg(kFitFailedY);
1935 fYfit[0] = fitterY.GetFunctionParameter(0);
1936 fYfit[1] = -fitterY.GetFunctionParameter(1);
1939 fitterY.GetCovarianceMatrix(p);
1940 fCov[0] = kScalePulls*p[1]; // variance of y0
1941 fCov[1] = kScalePulls*p[2]; // covariance of y0, dydx
1942 fCov[2] = kScalePulls*p[0]; // variance of dydx
1943 // the ref radial position is set at the minimum of
1944 // the y variance of the tracklet
1945 fX = -fCov[1]/fCov[2];
1946 fS2Y = fCov[0] +2.*fX*fCov[1] + fX*fX*fCov[2];
1948 Float_t xs=fX+.5*AliTRDgeometry::CamHght();
1949 if(xs < 0. || xs > AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght()){
1950 AliDebug(1, Form("Ref radial position ouside chamber x[%5.2f].", fX));
1951 SetErrorMsg(kFitFailedY);
1955 /* // THE LEADING CLUSTER METHOD for z fit
1957 Int_t ic=n=kNclusters-1; jc = &fClusters[ic];
1958 AliTRDcluster *c0 =0x0, **kc = &fClusters[kNtb-1];
1959 for(; ic>kNtb; ic--, --jc, --kc){
1960 if((c0 = (*kc)) && c0->IsInChamber() && (xMin>c0->GetX())) xMin = c0->GetX();
1961 if(!(c = (*jc))) continue;
1962 if(!c->IsInChamber()) continue;
1963 zc[kNclusters-1] = c->GetZ();
1964 fX = fX0 - c->GetX();
1966 fZfit[0] = .5*(zc[0]+zc[kNclusters-1]); fZfit[1] = 0.;
1967 // Error parameterization
1968 fS2Z = fdX*fZref[1];
1969 fS2Z *= fS2Z; fS2Z *= 0.2887; // 1/sqrt(12)*/
1972 if(opt!=1 && IsRowCross()){
1973 if(!fitterZ.Eval()) SetErrorMsg(kFitFailedZ);
1974 if(!HasError(kFitFailedZ) && TMath::Abs(fitterZ.GetFunctionParameter(1))>1.e-10){
1975 // TODO - one has to recalculate xy fit based on
1976 // better knowledge of z position
1977 // Double_t x = -fitterZ.GetFunctionParameter(0)/fitterZ.GetFunctionParameter(1);
1978 // Double_t z0 = .5*(zc[0]+zc[n-1]);
1979 // fZfit[0] = z0 + fZfit[1]*x;
1980 // fZfit[1] = fZfit[0]/fX0;
1981 // redo fit on xy plane
1983 // temporary external error parameterization
1984 fS2Z = 0.05+0.4*TMath::Abs(fZref[1]); fS2Z *= fS2Z;
1985 // TODO correct formula
1986 //fS2Z = sigma_x*TMath::Abs(fZref[1]);
1988 //fZfit[0] = zc[0] + dzdx*0.5*AliTRDgeometry::CdrHght();
1989 fS2Z = GetPadLength()*GetPadLength()/12.;
1995 //____________________________________________________________________
1996 Bool_t AliTRDseedV1::FitRobust(Bool_t chg)
1999 // Linear fit of the clusters attached to the tracklet
2002 // A.Bercuci <A.Bercuci@gsi.de>
2004 TTreeSRedirector *pstreamer(NULL);
2005 const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam(); if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) > 3 && fkReconstructor->IsDebugStreaming()) pstreamer = fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
2007 // factor to scale y pulls.
2008 // ideally if error parametrization correct this is 1.
2009 //Float_t lyScaler = 1./(AliTRDgeometry::GetLayer(fDet)+1.);
2010 Float_t kScalePulls = 1.;
2011 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
2013 AliWarning("No access to calibration data");
2015 // Retrieve the CDB container class with the parametric likelihood
2016 const AliTRDCalTrkAttach *attach = calibration->GetAttachObject();
2018 AliWarning("No usable AttachClusters calib object.");
2020 kScalePulls = attach->GetScaleCov();//*lyScaler;
2023 Double_t xc[kNclusters], yc[kNclusters], sy[kNclusters];
2024 Int_t n(0), // clusters used in fit
2025 row[]={-1, 0}; // pad row spanned by the tracklet
2026 AliTRDcluster *c(NULL), **jc = &fClusters[0];
2027 for(Int_t ic=0; ic<kNtb; ic++, ++jc) {
2028 if(!(c = (*jc))) continue;
2029 if(!c->IsInChamber()) continue;
2031 fZfit[0] = c->GetZ();
2033 row[0] = c->GetPadRow();
2037 sy[n] = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
2040 Double_t corr = fPad[2]*fPad[0];
2042 for(Int_t ic=kNtb; ic<kNclusters; ic++, ++jc) {
2043 if(!(c = (*jc))) continue;
2044 if(!c->IsInChamber()) continue;
2045 if(row[1]==0) row[1] = c->GetPadRow() - row[0];
2047 yc[n] = c->GetY() + corr*row[1];
2048 sy[n] = c->GetSigmaY2()>0?(TMath::Min(TMath::Sqrt(c->GetSigmaY2()), 0.08)):0.08;
2052 Double_t par[3] = {0.,0.,fX0}, cov[3];
2053 if(!AliTRDtrackletOflHelper::Fit(n, xc, yc, sy, par, 1.5, cov)){
2054 AliDebug(1, Form("Tracklet fit failed D[%03d].", fDet));
2055 SetErrorMsg(kFitCl);
2061 fCov[0] = kScalePulls*cov[0]; // variance of y0
2062 fCov[1] = kScalePulls*cov[2]; // covariance of y0, dydx
2063 fCov[2] = kScalePulls*cov[1]; // variance of dydx
2064 // the ref radial position is set at the minimum of
2065 // the y variance of the tracklet
2066 fX = 0.;//-fCov[1]/fCov[2];
2067 // check radial position
2068 Float_t xs=fX+.5*AliTRDgeometry::CamHght();
2069 if(xs < 0. || xs > AliTRDgeometry::CamHght()+AliTRDgeometry::CdrHght()){
2070 AliDebug(1, Form("Ref radial position x[%5.2f] ouside D[%3d].", fX, fDet));
2071 SetErrorMsg(kFitFailedY);
2074 fS2Y = fCov[0] + fX*fCov[1];
2075 fS2Z = fPad[0]*fPad[0]/12.;
2076 AliDebug(2, Form("[I] x[cm]=%6.2f y[cm]=%+5.2f z[cm]=%+6.2f dydx[deg]=%+5.2f sy[um]=%6.2f sz[cm]=%6.2f", GetX(), GetY(), GetZ(), TMath::ATan(fYfit[1])*TMath::RadToDeg(), TMath::Sqrt(fS2Y)*1.e4, TMath::Sqrt(fS2Z)));
2079 if(!GetEstimatedCrossPoint(x,z)){
2080 AliDebug(2, Form("Failed(I) getting crossing point D[%03d].", fDet));
2081 SetErrorMsg(kFitFailedY);
2087 fS2Z = 0.05+0.4*TMath::Abs(fZfit[1]); fS2Z *= fS2Z;
2089 AliDebug(2, Form("s2y[%f] s2z[%f]", fS2Y, fS2Z));
2090 AliDebug(2, Form("[II] x[cm]=%6.2f y[cm]=%+5.2f z[cm]=%+6.2f dydx[deg]=%+5.2f sy[um]=%6.2f sz[um]=%6.2f dzdx[deg]=%+5.2f", GetX(), GetY(), GetZ(), TMath::ATan(fYfit[1])*TMath::RadToDeg(), TMath::Sqrt(fS2Y)*1.e4, TMath::Sqrt(fS2Z)*1.e4, TMath::ATan(fZfit[1])*TMath::RadToDeg()));
2096 yt = fYref[0]-fX*fYref[1];
2098 TVectorD vcov(3); vcov[0]=cov[0];vcov[1]=cov[1];vcov[2]=cov[2];
2099 Double_t sm(0.), chi2(0.), tmp, dy[kNclusters];
2100 for(Int_t ic(0); ic<n; ic++){
2102 dy[ic] = yc[ic]-(fYfit[0]+(xc[ic]-fX0)*fYfit[1]); tmp = dy[ic]/sy[ic];
2105 sm /= n; chi2 = TMath::Sqrt(chi2);
2106 Double_t m(0.), s(0.);
2107 AliMathBase::EvaluateUni(n, dy, m, s, 0);
2108 (*pstreamer) << "FitRobust4"
2109 << "stat=" << status
2114 << "y0=" << fYfit[0]
2117 << "dydx=" << fYfit[1]
2120 << "dydxt="<< fYref[1]
2130 //___________________________________________________________________
2131 void AliTRDseedV1::Print(Option_t *o) const
2134 // Printing the seedstatus
2137 AliInfo(Form("Det[%3d] X0[%7.2f] Pad{L[%5.2f] W[%5.2f] Tilt[%+6.2f]}", fDet, fX0, GetPadLength(), GetPadWidth(), GetTilt()));
2138 AliInfo(Form("N[%2d] Nused[%2d] Nshared[%2d] [%d]", GetN(), GetNUsed(), GetNShared(), fN));
2139 AliInfo(Form("FLAGS : RC[%c] Kink[%c] SA[%c]", IsRowCross()?'y':'n', IsKink()?'y':'n', IsStandAlone()?'y':'n'));
2140 AliInfo(Form("CALIB PARAMS : T0[%5.2f] Vd[%5.2f] s2PRF[%5.2f] ExB[%5.2f] Dl[%5.2f] Dt[%5.2f]", fT0, fVD, fS2PRF, fExB, fDiffL, fDiffT));
2142 Double_t cov[3], x=GetX();
2144 AliInfo(" | x[cm] | y[cm] | z[cm] | dydx | dzdx |");
2145 AliInfo(Form("Fit | %7.2f | %7.2f+-%7.2f | %7.2f+-%7.2f| %5.2f | ----- |", x, GetY(), TMath::Sqrt(cov[0]), GetZ(), TMath::Sqrt(cov[2]), fYfit[1]));
2146 AliInfo(Form("Ref | %7.2f | %7.2f+-%7.2f | %7.2f+-%7.2f| %5.2f | %5.2f |", x, fYref[0]-fX*fYref[1], TMath::Sqrt(fRefCov[0]), fZref[0]-fX*fYref[1], TMath::Sqrt(fRefCov[2]), fYref[1], fZref[1]));
2147 AliInfo(Form("P / Pt [GeV/c] = %f / %f", GetMomentum(), fPt));
2148 if(IsStandAlone()) AliInfo(Form("C Rieman / Vertex [1/cm] = %f / %f", fC[0], fC[1]));
2149 AliInfo(Form("dEdx [a.u.] = %f / %f / %f / %f / %f/ %f / %f / %f", fdEdx[0], fdEdx[1], fdEdx[2], fdEdx[3], fdEdx[4], fdEdx[5], fdEdx[6], fdEdx[7]));
2150 AliInfo(Form("PID = %5.3f / %5.3f / %5.3f / %5.3f / %5.3f", fProb[0], fProb[1], fProb[2], fProb[3], fProb[4]));
2152 if(strcmp(o, "a")!=0) return;
2154 AliTRDcluster* const* jc = &fClusters[0];
2155 for(int ic=0; ic<kNclusters; ic++, jc++) {
2156 if(!(*jc)) continue;
2162 //___________________________________________________________________
2163 Bool_t AliTRDseedV1::IsEqual(const TObject *o) const
2165 // Checks if current instance of the class has the same essential members
2168 if(!o) return kFALSE;
2169 const AliTRDseedV1 *inTracklet = dynamic_cast<const AliTRDseedV1*>(o);
2170 if(!inTracklet) return kFALSE;
2172 for (Int_t i = 0; i < 2; i++){
2173 if ( fYref[i] != inTracklet->fYref[i] ) return kFALSE;
2174 if ( fZref[i] != inTracklet->fZref[i] ) return kFALSE;
2177 if ( TMath::Abs(fS2Y - inTracklet->fS2Y)>1.e-10 ) return kFALSE;
2178 if ( TMath::Abs(GetTilt() - inTracklet->GetTilt())>1.e-10 ) return kFALSE;
2179 if ( TMath::Abs(GetPadLength() - inTracklet->GetPadLength())>1.e-10 ) return kFALSE;
2181 for (Int_t i = 0; i < kNclusters; i++){
2182 // if ( fX[i] != inTracklet->GetX(i) ) return kFALSE;
2183 // if ( fY[i] != inTracklet->GetY(i) ) return kFALSE;
2184 // if ( fZ[i] != inTracklet->GetZ(i) ) return kFALSE;
2185 if ( fIndexes[i] != inTracklet->fIndexes[i] ) return kFALSE;
2187 // if ( fUsable != inTracklet->fUsable ) return kFALSE;
2189 for (Int_t i=0; i < 2; i++){
2190 if ( fYfit[i] != inTracklet->fYfit[i] ) return kFALSE;
2191 if ( fZfit[i] != inTracklet->fZfit[i] ) return kFALSE;
2192 if ( fLabels[i] != inTracklet->fLabels[i] ) return kFALSE;
2195 /* if ( fMeanz != inTracklet->GetMeanz() ) return kFALSE;
2196 if ( fZProb != inTracklet->GetZProb() ) return kFALSE;*/
2197 if ( fN != inTracklet->fN ) return kFALSE;
2198 //if ( fNUsed != inTracklet->fNUsed ) return kFALSE;
2199 //if ( fFreq != inTracklet->GetFreq() ) return kFALSE;
2200 //if ( fNChange != inTracklet->GetNChange() ) return kFALSE;
2202 if ( TMath::Abs(fC[0] - inTracklet->fC[0])>1.e-10 ) return kFALSE;
2203 //if ( fCC != inTracklet->GetCC() ) return kFALSE;
2204 if ( TMath::Abs(fChi2 - inTracklet->fChi2)>1.e-10 ) return kFALSE;
2205 // if ( fChi2Z != inTracklet->GetChi2Z() ) return kFALSE;
2207 if ( fDet != inTracklet->fDet ) return kFALSE;
2208 if ( TMath::Abs(fPt - inTracklet->fPt)>1.e-10 ) return kFALSE;
2209 if ( TMath::Abs(fdX - inTracklet->fdX)>1.e-10 ) return kFALSE;
2211 for (Int_t iCluster = 0; iCluster < kNclusters; iCluster++){
2212 AliTRDcluster *curCluster = fClusters[iCluster];
2213 AliTRDcluster *inCluster = inTracklet->fClusters[iCluster];
2214 if (curCluster && inCluster){
2215 if (! curCluster->IsEqual(inCluster) ) {
2216 curCluster->Print();
2221 // if one cluster exists, and corresponding
2222 // in other tracklet doesn't - return kFALSE
2223 if(curCluster || inCluster) return kFALSE;