3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 ////////////////////////////////////////////////////////////////////////////
10 // \class AliTRDseedV1
11 // \brief The TRD offline tracklet
12 // \author Alexandru Bercuci
14 ////////////////////////////////////////////////////////////////////////////
16 #ifndef ALITRDTRACKLETBASE_H
17 #include "AliTRDtrackletBase.h"
24 #ifndef ALITRDGEOMETRY_H
25 #include "AliTRDgeometry.h"
33 #include "AliRieman.h"
36 #ifndef ALITRDCLUSTER_H
37 #include "AliTRDcluster.h"
40 #include "AliTRDReconstructor.h"
42 class TTreeSRedirector;
47 class AliTRDtrackingChamber;
50 class AliTRDseedV1 : public AliTRDtrackletBase
52 friend class AliHLTTRDTracklet;
55 enum ETRDtrackletBuffers {
56 kNbits = 6 // bits to store number of clusters
57 ,kMask = 0x3f // bit mask
58 ,kNtb = 31 // max clusters/pad row
59 ,kNclusters = 2*kNtb // max number of clusters/tracklet
60 ,kNslices = 10 // max dEdx slices
63 // bits from 0-13 are reserved by ROOT (see TObject.h)
64 enum ETRDtrackletStatus {
65 kOwner = BIT(14) // owner of its clusters
66 ,kRowCross = BIT(15) // pad row cross tracklet
67 ,kPID = BIT(16) // PID contributor
68 ,kCalib = BIT(17) // calibrated tracklet
69 ,kKink = BIT(18) // kink prolongation tracklet
70 ,kStandAlone = BIT(19) // tracklet build during stand alone track finding
72 enum ETRDtrackletError {
73 kAttachClFound = 1 // not enough clusters found
74 ,kAttachRowGap // found gap attached rows
75 ,kAttachRow // found 3 rows
76 ,kAttachMultipleCl // multiple clusters attached to time bin
77 ,kAttachClAttach // not enough clusters attached
80 AliTRDseedV1(Int_t det = -1);
82 AliTRDseedV1(const AliTRDseedV1 &ref);
83 AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
85 Bool_t AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt = kFALSE);
86 void Bootstrap(const AliTRDReconstructor *rec);
88 void CookdEdx(Int_t nslices);
91 Bool_t Fit(Bool_t tilt=kFALSE, Bool_t zcorr=kFALSE);
92 Bool_t Init(AliTRDtrackV1 *track);
93 inline void Init(const AliRieman *fit);
94 Bool_t IsEqual(const TObject *inTracklet) const;
95 Bool_t IsCalibrated() const { return TestBit(kCalib);}
96 Bool_t IsOwner() const { return TestBit(kOwner);}
97 Bool_t IsKink() const { return TestBit(kKink);}
98 Bool_t HasPID() const { return TestBit(kPID);}
99 Bool_t IsOK() const { return GetN() > 4 && GetNUsed() < 4;}
100 Bool_t IsRowCross() const { return TestBit(kRowCross);}
101 Bool_t IsUsable(Int_t i) const { return fClusters[i] && !fClusters[i]->IsUsed();}
102 Bool_t IsStandAlone() const { return TestBit(kStandAlone);}
104 Float_t GetC() const { return fC; }
105 Float_t GetChi2() const { return fChi2; }
106 inline Float_t GetChi2Z() const;
107 inline Float_t GetChi2Y() const;
108 inline Float_t GetChi2Phi() const;
109 void GetCovAt(Double_t x, Double_t *cov) const;
110 void GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
111 void GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov, 7*sizeof(Double_t));}
112 static Double_t GetCovSqrt(const Double_t * const c, Double_t *d);
113 static Double_t GetCovInv(const Double_t * const c, Double_t *d);
114 UChar_t GetErrorMsg() const { return fErrorMsg;}
115 Float_t GetdX() const { return fdX;}
116 const Float_t* GetdEdx() const { return &fdEdx[0];}
117 Float_t GetdQdl(Int_t ic, Float_t *dx=NULL) const;
118 Float_t GetdYdX() const { return fYfit[1]; }
119 Float_t GetdZdX() const { return fZref[1]; }
120 Int_t GetdY() const { return Int_t(GetY()/0.014);}
121 Int_t GetDetector() const { return fDet;}
122 void GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const {
123 exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
124 AliTRDcluster* GetClusters(Int_t i) const { return i<0 || i>=kNclusters ? NULL: fClusters[i];}
125 static TLinearFitter* GetFitterY();
126 static TLinearFitter* GetFitterZ();
127 Int_t GetIndexes(Int_t i) const{ return i<0 || i>=kNclusters ? -1 : fIndexes[i];}
128 Int_t GetLabels(Int_t i) const { return fLabels[i];}
129 Float_t GetMomentum(Float_t *err = NULL) const;
130 Int_t GetN() const { return (Int_t)fN&kMask;}
131 Int_t GetN2() const { return GetN();}
132 Int_t GetNUsed() const { return Int_t((fN>>kNbits)&kMask);}
133 Int_t GetNShared() const { return Int_t(((fN>>kNbits)>>kNbits)&kMask);}
134 Float_t GetQuality(Bool_t kZcorr) const;
135 Float_t GetPadLength() const { return fPad[0];}
136 Float_t GetPadWidth() const { return fPad[1];}
137 Int_t GetPlane() const { return AliTRDgeometry::GetLayer(fDet); }
139 Float_t* GetProbability(Bool_t force=kFALSE);
140 Float_t GetPt() const { return fPt; }
141 inline Double_t GetPID(Int_t is=-1) const;
142 Float_t GetS2Y() const { return fS2Y;}
143 Float_t GetS2Z() const { return fS2Z;}
144 Float_t GetSigmaY() const { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
145 Float_t GetSnp() const { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
146 Float_t GetTgl() const { return fZref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
147 Float_t GetTilt() const { return fPad[2];}
148 UInt_t GetTrackletWord() const { return 0;}
149 UShort_t GetVolumeId() const;
150 Float_t GetX0() const { return fX0;}
151 Float_t GetX() const { return fX0 - fX;}
152 Float_t GetY() const { return fYfit[0] - fYfit[1] * fX;}
153 Double_t GetYat(Double_t x) const { return fYfit[0] - fYfit[1] * (fX0-x);}
154 Float_t GetYfit(Int_t id) const { return fYfit[id];}
155 Float_t GetYref(Int_t id) const { return fYref[id];}
156 Float_t GetZ() const { return fZfit[0] - fZfit[1] * fX;}
157 Double_t GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
158 Float_t GetZfit(Int_t id) const { return fZfit[id];}
159 Float_t GetZref(Int_t id) const { return fZref[id];}
160 Int_t GetYbin() const { return Int_t(GetY()/0.016);}
161 Int_t GetZbin() const { return Int_t(GetZ()/fPad[0]);}
163 inline AliTRDcluster* NextCluster();
164 inline AliTRDcluster* PrevCluster();
165 void Print(Option_t *o = "") const;
166 inline void ResetClusterIter(Bool_t forward = kTRUE);
167 void Reset(Option_t *opt="");
169 void SetC(Float_t c) { fC = c;}
170 void SetChi2(Float_t chi2) { fChi2 = chi2;}
171 inline void SetCovRef(const Double_t *cov);
172 void SetErrorMsg(Int_t err) { fErrorMsg = err;}
173 void SetIndexes(Int_t i, Int_t idx) { fIndexes[i] = idx; }
174 void SetLabels(Int_t *lbls) { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
175 void SetKink(Bool_t k = kTRUE){ SetBit(kKink, k);}
176 void SetPID(Bool_t k = kTRUE) { SetBit(kPID, k);}
177 void SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
178 void SetPt(Double_t pt) { fPt = pt;}
180 void SetPadPlane(AliTRDpadPlane *p);
181 void SetPadLength(Float_t l) { fPad[0] = l;}
182 void SetPadWidth(Float_t w) { fPad[1] = w;}
183 void SetTilt(Float_t tilt) { fPad[2] = tilt; }
184 void SetDetector(Int_t d) { fDet = d; }
185 void SetDX(Float_t inDX) { fdX = inDX;}
186 void SetReconstructor(const AliTRDReconstructor *rec) {fkReconstructor = rec;}
187 void SetX0(Float_t x0) { fX0 = x0; }
188 void SetYref(Int_t i, Float_t y) { fYref[i] = y;}
189 void SetZref(Int_t i, Float_t z) { fZref[i] = z;}
190 // void SetUsabilityMap(Long_t um) { fUsable = um; }
191 void Update(const AliTRDtrackV1* trk);
196 void Copy(TObject &ref) const;
199 inline void SetN(Int_t n);
200 inline void SetNUsed(Int_t n);
201 inline void SetNShared(Int_t n);
202 inline void Swap(Int_t &n1, Int_t &n2);
203 inline void Swap(Double_t &d1, Double_t &d2);
205 const AliTRDReconstructor *fkReconstructor;//! local reconstructor
206 AliTRDcluster **fClusterIter; //! clusters iterator
207 Int_t fIndexes[kNclusters]; //! Indexes
208 Float_t fExB; //! tg(a_L) @ tracklet location
209 Float_t fVD; //! drift velocity @ tracklet location
210 Float_t fT0; //! time 0 @ tracklet location
211 Float_t fS2PRF; //! sigma^2 PRF for xd->0 and phi=a_L
212 Float_t fDiffL; //! longitudinal diffusion coefficient
213 Float_t fDiffT; //! transversal diffusion coefficient
214 Char_t fClusterIdx; //! clusters iterator
215 UChar_t fErrorMsg; // processing error
216 UInt_t fN; // number of clusters attached/used/shared
217 Short_t fDet; // TRD detector
218 AliTRDcluster *fClusters[kNclusters]; // Clusters
219 Float_t fPad[3]; // local pad definition : length/width/tilt
220 Float_t fYref[2]; // Reference y, dydx
221 Float_t fZref[2]; // Reference z, dz/dx
222 Float_t fYfit[2]; // Fit y, dy/dx
223 Float_t fZfit[2]; // Fit z
224 Float_t fPt; // Pt estimate @ tracklet [GeV/c]
225 Float_t fdX; // length of time bin
226 Float_t fX0; // anode wire position
227 Float_t fX; // radial position of the tracklet
228 Float_t fY; // r-phi position of the tracklet
229 Float_t fZ; // z position of the tracklet
230 Float_t fS2Y; // estimated resolution in the r-phi direction
231 Float_t fS2Z; // estimated resolution in the z direction
232 Float_t fC; // Curvature
233 Float_t fChi2; // Global chi2
234 Float_t fdEdx[kNslices]; // dE/dx measurements for tracklet
235 Float_t fProb[AliPID::kSPECIES]; // PID probabilities
236 Int_t fLabels[3]; // most frequent MC labels and total number of different labels
237 Double_t fRefCov[7]; // covariance matrix of the track in the yz plane + the rest of the diagonal elements
238 Double_t fCov[3]; // covariance matrix of the tracklet in the xy plane
239 static TLinearFitter *fgFitterY; // Linear Fitter for tracklet fit in xy-plane
240 static TLinearFitter *fgFitterZ; // Linear Fitter for tracklet fit in xz-plane
242 ClassDef(AliTRDseedV1, 8) // The offline TRD tracklet
245 //____________________________________________________________
246 inline Float_t AliTRDseedV1::GetChi2Z() const
248 Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
249 Double_t cov[3]; GetCovAt(fX, cov);
250 Double_t s2 = fRefCov[2]+cov[2];
251 return s2 > 0. ? dz/s2 : 0.;
254 //____________________________________________________________
255 inline Float_t AliTRDseedV1::GetChi2Y() const
257 Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
258 Double_t cov[3]; GetCovAt(fX, cov);
259 Double_t s2 = fRefCov[0]+cov[0];
260 return s2 > 0. ? dy/s2 : 0.;
263 //____________________________________________________________
264 inline Float_t AliTRDseedV1::GetChi2Phi() const
266 Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
267 Double_t cov[3]; GetCovAt(fX, cov);
268 Double_t s2 = fRefCov[2]+cov[2];
269 return s2 > 0. ? dphi/s2 : 0.;
274 //____________________________________________________________
275 inline Double_t AliTRDseedV1::GetPID(Int_t is) const
277 if(is<0) return fProb[AliPID::kElectron];
278 if(is<AliPID::kSPECIES) return fProb[is];
282 //____________________________________________________________
283 inline void AliTRDseedV1::Init(const AliRieman *rieman)
285 fZref[0] = rieman->GetZat(fX0);
286 fZref[1] = rieman->GetDZat(fX0);
287 fYref[0] = rieman->GetYat(fX0);
288 fYref[1] = rieman->GetDYat(fX0);
289 if(fkReconstructor && fkReconstructor->IsHLT()){
293 fRefCov[0] = rieman->GetErrY(fX0);
294 fRefCov[2] = rieman->GetErrZ(fX0);
297 fChi2 = rieman->GetChi2();
300 //____________________________________________________________
301 inline AliTRDcluster* AliTRDseedV1::NextCluster()
303 // Mimic the usage of STL iterators.
306 fClusterIdx++; fClusterIter++;
307 while(fClusterIdx < kNclusters){
308 if(!(*fClusterIter)){
313 return *fClusterIter;
318 //____________________________________________________________
319 inline AliTRDcluster* AliTRDseedV1::PrevCluster()
321 // Mimic the usage of STL iterators.
324 fClusterIdx--; fClusterIter--;
325 while(fClusterIdx >= 0){
326 if(!(*fClusterIter)){
331 return *fClusterIter;
336 //____________________________________________________________
337 inline void AliTRDseedV1::ResetClusterIter(Bool_t forward)
339 // Mimic the usage of STL iterators.
340 // Facilitate the usage of NextCluster for forward like
341 // iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
344 fClusterIter = &fClusters[0]; fClusterIter--;
347 fClusterIter = &fClusters[kNclusters-1]; fClusterIter++;
348 fClusterIdx=kNclusters;
352 //____________________________________________________________
353 inline void AliTRDseedV1::SetCovRef(const Double_t *cov)
355 // Copy some "important" covariance matrix elements
360 // cov(tgl, 1/pt) var(1/pt)
362 memcpy(&fRefCov[0], cov, 3*sizeof(Double_t)); // yz full covariance
363 fRefCov[3] = cov[ 5]; // snp variance
364 fRefCov[4] = cov[ 9]; // tgl variance
365 fRefCov[5] = cov[13]; // cov(tgl, 1/pt)
366 fRefCov[6] = cov[14]; // 1/pt variance
370 //____________________________________________________________
371 inline void AliTRDseedV1::SetN(Int_t n)
373 if(n<0 || n>kNclusters) return;
378 //____________________________________________________________
379 inline void AliTRDseedV1::SetNUsed(Int_t n)
381 if(n<0 || n>kNclusters) return;
382 UInt_t mask(kMask<<kNbits);
384 n=n<<kNbits; fN |= (n&mask);
387 //____________________________________________________________
388 inline void AliTRDseedV1::SetNShared(Int_t n)
390 if(n<0 || n>kNclusters) return;
391 UInt_t mask((kMask<<kNbits)<<kNbits);
393 n = (n<<kNbits)<<kNbits; fN|=(n&mask);
396 //____________________________________________________________
397 inline void AliTRDseedV1::Swap(Int_t &n1, Int_t &n2)
399 // swap values of n1 with n2
404 //____________________________________________________________
405 inline void AliTRDseedV1::Swap(Double_t &d1, Double_t &d2)
407 // swap values of d1 with d2