3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
6 /* $Id: AliTRDseedV1.h 60233 2013-01-10 09:04:08Z abercuci $ */
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 #ifndef ALITRDCLUSTER_H
34 #include "AliTRDcluster.h"
38 class TTreeSRedirector;
43 class AliTRDReconstructor;
44 class AliTRDtrackingChamber;
47 class AliTRDseedV1 : public AliTRDtrackletBase
49 friend class AliHLTTRDTracklet; // wrapper for HLT
52 enum ETRDtrackletBuffers {
53 kNbits = 6 // bits to store number of clusters
54 ,kMask = 0x3f // bit mask
55 ,kNtb = 31 // max clusters/pad row
56 ,kNclusters = 2*kNtb // max number of clusters/tracklet
57 ,kNdEdxSlices= 8 // dEdx slices allocated in reconstruction
60 // bits from 0-13 are reserved by ROOT (see TObject.h)
61 enum ETRDtrackletStatus {
62 kOwner = BIT(14) // owner of its clusters
63 ,kRowCross = BIT(15) // pad row cross tracklet
64 ,kChmbGood = BIT(16) // status of the detector from calibration view point
65 ,kCalib = BIT(17) // calibrated tracklet
66 ,kKink = BIT(18) // kink prolongation tracklet
67 ,kStandAlone = BIT(19) // tracklet build during stand alone track finding
68 ,kPrimary = BIT(20) // tracklet from a primary track candidate
71 enum ETRDtrackletError { // up to 8 bits
72 kAttachClFound = 0 // not enough clusters found
73 ,kAttachRowGap = 1 // found gap attached rows
74 ,kAttachRow = 2 // found 3 rows
75 ,kAttachMultipleCl= 3// multiple clusters attached to time bin
76 ,kAttachClAttach= 4 // not enough clusters attached
77 ,kFitCl = 5 // not enough clusters for fit
78 ,kFitFailedY = 6 // fit failed in XY plane failed
79 ,kFitFailedZ = 7 // fit in the QZ plane failed
82 AliTRDseedV1(Int_t det = -1);
84 AliTRDseedV1(const AliTRDseedV1 &ref);
85 AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
87 Bool_t AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt = kFALSE, Bool_t ChgPlus=kTRUE, Int_t ev=-1);
88 void Bootstrap(const AliTRDReconstructor *rec);
90 void CookdEdx(Int_t nslices);
93 Bool_t Fit(UChar_t opt=0); // OBSOLETE
94 Bool_t FitRobust(AliTRDpadPlane *pp, Int_t opt=0);
95 Double_t EstimatedCrossPoint(AliTRDpadPlane *pp);
96 Bool_t Init(const AliTRDtrackV1 *track);
97 void Init(const AliRieman *fit);
98 Bool_t IsEqual(const TObject *inTracklet) const;
99 Bool_t IsCalibrated() const { return TestBit(kCalib);}
100 Bool_t IsChmbGood() const { return TestBit(kChmbGood);}
101 Bool_t IsOwner() const { return TestBit(kOwner);}
102 Bool_t IsKink() const { return TestBit(kKink);}
103 Bool_t IsPrimary() const { return TestBit(kPrimary);}
104 Bool_t HasError(ETRDtrackletError err) const
105 { return TESTBIT(fErrorMsg, err);}
106 Bool_t IsOK() const { return GetN() > 4 && GetNUsed() < 4;}
107 Bool_t IsRowCross() const { return TestBit(kRowCross);}
108 Bool_t IsUsable(Int_t i) const { return fClusters[i] && !fClusters[i]->IsUsed();}
109 Bool_t IsStandAlone() const { return TestBit(kStandAlone);}
111 Float_t GetAnodeWireOffset(Float_t zt);
112 Float_t GetC(Int_t typ=0) const { return fC[typ]; }
113 Float_t GetCharge(Bool_t useOutliers=kFALSE) const;
114 Float_t GetChi2() const { return fChi2; }
115 inline Float_t GetChi2Z() const;
116 inline Float_t GetChi2Y() const;
117 inline Float_t GetChi2Phi() const;
118 void GetCovAt(Double_t x, Double_t *cov) const;
119 void GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
120 void GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov, 7*sizeof(Double_t));}
121 static Int_t GetCovSqrt(const Double_t * const c, Double_t *d);
122 static Double_t GetCovInv(const Double_t * const c, Double_t *d);
123 UChar_t GetErrorMsg() const { return fErrorMsg;}
124 Float_t GetdX() const { return fdX;}
125 const Float_t* GetdEdx() const { return &fdEdx[0];}
126 Float_t GetQperTB(Int_t tb) const;
127 Float_t GetdQdl() const;
128 Float_t GetdQdl(Int_t ic, Float_t *dx=NULL) const;
129 Float_t GetdYdX() const { return fYfit[1];}
130 Float_t GetdZdX() const { return fZfit[1];}
131 Int_t GetdY() const { return Int_t(GetY()/0.014);}
132 Int_t GetDetector() const { return fDet;}
133 Int_t GetChargeGaps(Float_t sz[kNtb], Float_t pos[kNtb], Int_t ntb[kNtb]) const;
134 void GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const {
135 exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
136 AliTRDcluster* GetClusters(Int_t i) const { return i<0 || i>=kNclusters ? NULL: fClusters[i];}
137 Int_t GetIndexes(Int_t i) const{ return i<0 || i>=kNclusters ? -1 : fIndexes[i];}
138 Int_t GetLabels(Int_t i) const { return fLabels[i];}
139 Float_t GetLocalZ() const { return fZfit[0] - fZfit[1] * fX;}
140 Float_t GetLocalY() const { return fYfit[0] - fYfit[1] * fX;}
141 Float_t GetMomentum(Float_t *err = NULL) const;
142 Int_t GetN() const { return (Int_t)fN&kMask;}
143 Int_t GetN2() const { return GetN();}
144 Int_t GetNUsed() const { return Int_t((fN>>kNbits)&kMask);}
145 Int_t GetNShared() const { return Int_t(((fN>>kNbits)>>kNbits)&kMask);}
146 Int_t GetTBoccupancy() const;
147 Int_t GetTBcross() const;
148 Float_t GetQuality(Bool_t kZcorr) const;
149 Float_t GetPadLength() const { return fPad[0];}
150 Float_t GetPadWidth() const { return fPad[1];}
151 Int_t GetPlane() const { return AliTRDgeometry::GetLayer(fDet); }
153 Float_t* GetProbability(Bool_t force=kFALSE);
154 Float_t GetPt() const { return fPt; }
155 inline Double_t GetPID(Int_t is=-1) const;
156 Float_t GetS2Y() const { return fS2Y;}
157 Float_t GetS2Z() const { return fS2Z;}
158 Float_t GetSigmaY() const { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
159 Float_t GetSnp() const { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
160 Float_t GetTgl() const { return fZref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
161 Float_t GetTilt() const { return fPad[2];}
162 UInt_t GetTrackletWord() const { return 0;}
163 UShort_t GetVolumeId() const;
164 Float_t GetX0() const { return fX0;}
165 Float_t GetX() const { return fX0 - fX;}
166 Float_t GetY() const { return TMath::Abs(fY)<1.e-15?GetLocalY():fY;/*fYfit[0] - fYfit[1] * fX;*/}
167 Double_t GetYat(Double_t x) const { return fY/*fit[0]*/ - fYfit[1] * (fX0-x);}
168 Float_t GetYfit(Int_t id) const { return fYfit[id];}
169 Float_t GetYref(Int_t id) const { return fYref[id];}
170 Float_t GetYref() const { return fYref[0] - fYref[1] *fX;}
171 Float_t GetZ() const { return TMath::Abs(fZ)<1.e-15?GetLocalZ():fZ;/*fZfit[0] - fZfit[1] * fX;*/}
172 Double_t GetZat(Double_t x) const { return fZ/*fit[0]*/ - fZfit[1] * (fX0-x);}
173 Float_t GetZfit(Int_t id) const { return fZfit[id];}
174 Float_t GetZref(Int_t id) const { return fZref[id];}
175 Float_t GetZref() const { return fZref[0] - fZref[1] *fX;}
176 Int_t GetYbin() const { return Int_t(GetY()/0.016);}
177 Int_t GetZbin() const { return Int_t(GetZ()/fPad[0]);}
179 inline AliTRDcluster* NextCluster();
180 inline AliTRDcluster* PrevCluster();
181 void Print(Option_t *o = "") const;
182 inline void ResetClusterIter(Bool_t forward = kTRUE);
183 void Reset(Option_t *opt="");
185 void SetC(Float_t c, Int_t typ=0) { fC[typ] = c;}
186 void SetChmbGood(Bool_t k = kTRUE){ SetBit(kChmbGood, k);}
187 void SetChi2(Float_t chi2) { fChi2 = chi2;}
188 inline void SetCovRef(const Double_t *cov);
189 void SetErrorMsg(ETRDtrackletError err) { SETBIT(fErrorMsg, err);}
190 void SetIndexes(Int_t i, Int_t idx) { fIndexes[i] = idx; }
191 void SetLabels(Int_t *lbls) { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
192 void SetKink(Bool_t k = kTRUE){ SetBit(kKink, k);}
193 void SetPrimary(Bool_t k = kTRUE){ SetBit(kPrimary, k);}
194 void SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
195 void SetPt(Double_t pt) { fPt = pt;}
197 void SetPadPlane(AliTRDpadPlane * const p);
198 void SetPadLength(Float_t l) { fPad[0] = l;}
199 void SetPadWidth(Float_t w) { fPad[1] = w;}
200 void SetTilt(Float_t tilt) { fPad[2] = tilt; }
201 void SetDetector(Int_t d) { fDet = d; }
202 void SetDX(Float_t inDX) { fdX = inDX;}
203 void SetReconstructor(const AliTRDReconstructor *rec) {fkReconstructor = rec;}
204 void SetX0(Float_t x0) { fX0 = x0; }
205 void SetXYZ(TGeoHMatrix *mDet);
206 void SetYref(Int_t i, Float_t y) { if(i==0||i==1) fYref[i] = y;}
207 void SetZref(Int_t i, Float_t z) { if(i==0||i==1) fZref[i] = z;}
208 // void SetUsabilityMap(Long_t um) { fUsable = um; }
209 void Update(const AliTRDtrackV1* trk);
214 void Copy(TObject &ref) const;
217 inline void SetN(Int_t n);
218 inline void SetNUsed(Int_t n);
219 inline void SetNShared(Int_t n);
220 inline void Swap(Int_t &n1, Int_t &n2) const;
221 inline void Swap(Double_t &d1, Double_t &d2) const;
223 const AliTRDReconstructor *fkReconstructor;//! local reconstructor
224 AliTRDcluster **fClusterIter; //! clusters iterator
225 Int_t fIndexes[kNclusters]; //! Indexes
226 Float_t fExB; // tg(a_L) @ tracklet location
227 Float_t fVD; // drift velocity @ tracklet location
228 Float_t fT0; // time 0 @ tracklet location
229 Float_t fS2PRF; // sigma^2 PRF for xd->0 and phi=a_L
230 Float_t fDiffL; // longitudinal diffusion coefficient
231 Float_t fDiffT; // transversal diffusion coefficient
232 Char_t fClusterIdx; //! clusters iterator
233 UChar_t fErrorMsg; // processing error
234 UInt_t fN; // number of clusters attached/used/shared
235 Short_t fDet; // TRD detector
236 AliTRDcluster *fClusters[kNclusters]; // Clusters
237 Float_t fPad[4]; // local pad definition : length/width/tilt/anode wire offset
238 Float_t fYref[2]; // Reference y, dydx
239 Float_t fZref[2]; // Reference z, dz/dx
240 Float_t fYfit[2]; // Fit :: chamber local y, dy/dx
241 Float_t fZfit[2]; // Fit :: chamber local z, dz/dx
242 Float_t fPt; // Pt estimate @ tracklet [GeV/c]
243 Float_t fdX; // length of time bin
244 Float_t fX0; // anode wire position in TrackingCoordinates (alignment included)
245 Float_t fX; // local radial offset from anode wire where tracklet position is estimated
246 Float_t fY; // r-phi position of the tracklet in TrackingCoordinates (alignment included)
247 Float_t fZ; // z position of the tracklet in TrackingCoordinates (alignment included)
248 Float_t fS2Y; // estimated resolution in the r-phi direction
249 Float_t fS2Z; // estimated resolution in the z direction
250 Float_t fC[2]; // Curvature for standalone [0] rieman [1] vertex constrained
251 Float_t fChi2; // Global chi2
252 Float_t fdEdx[kNdEdxSlices]; // dE/dx measurements for tracklet
253 Float_t fProb[AliPID::kSPECIES]; // PID probabilities
254 Int_t fLabels[3]; // most frequent MC labels and total number of different labels
255 Double_t fRefCov[7]; // covariance matrix of the track in the yz plane + the rest of the diagonal elements
256 Double_t fCov[3]; // covariance matrix of the tracklet in the xy plane
258 ClassDef(AliTRDseedV1, 13) // The offline TRD tracklet
261 //____________________________________________________________
262 inline Float_t AliTRDseedV1::GetChi2Z() const
264 Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
265 Double_t cov[3]; GetCovAt(fX, cov);
266 Double_t s2 = fRefCov[2]+cov[2];
267 return s2 > 0. ? dz/s2 : 0.;
270 //____________________________________________________________
271 inline Float_t AliTRDseedV1::GetChi2Y() const
273 Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
274 Double_t cov[3]; GetCovAt(fX, cov);
275 Double_t s2 = fRefCov[0]+cov[0];
276 return s2 > 0. ? dy/s2 : 0.;
279 //____________________________________________________________
280 inline Float_t AliTRDseedV1::GetChi2Phi() const
282 Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
283 Double_t cov[3]; GetCovAt(fX, cov);
284 Double_t s2 = fRefCov[2]+cov[2];
285 return s2 > 0. ? dphi/s2 : 0.;
290 //____________________________________________________________
291 inline Double_t AliTRDseedV1::GetPID(Int_t is) const
293 if(is<0) return fProb[AliPID::kElectron];
294 if(is<AliPID::kSPECIES) return fProb[is];
298 //____________________________________________________________
299 inline AliTRDcluster* AliTRDseedV1::NextCluster()
301 // Mimic the usage of STL iterators.
304 fClusterIdx++; fClusterIter++;
305 while(fClusterIdx < kNclusters){
306 if(!(*fClusterIter)){
311 return *fClusterIter;
316 //____________________________________________________________
317 inline AliTRDcluster* AliTRDseedV1::PrevCluster()
319 // Mimic the usage of STL iterators.
322 fClusterIdx--; fClusterIter--;
323 while(fClusterIdx >= 0){
324 if(!(*fClusterIter)){
329 return *fClusterIter;
334 //____________________________________________________________
335 inline void AliTRDseedV1::ResetClusterIter(Bool_t forward)
337 // Mimic the usage of STL iterators.
338 // Facilitate the usage of NextCluster for forward like
339 // iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
342 fClusterIter = &fClusters[0]; fClusterIter--;
345 fClusterIter = &fClusters[kNclusters-1]; fClusterIter++;
346 fClusterIdx=kNclusters;
350 //____________________________________________________________
351 inline void AliTRDseedV1::SetCovRef(const Double_t *cov)
353 // Copy some "important" covariance matrix elements
358 // cov(tgl, 1/pt) var(1/pt)
360 memcpy(&fRefCov[0], cov, 3*sizeof(Double_t)); // yz full covariance
361 fRefCov[3] = cov[ 5]; // snp variance
362 fRefCov[4] = cov[ 9]; // tgl variance
363 fRefCov[5] = cov[13]; // cov(tgl, 1/pt)
364 fRefCov[6] = cov[14]; // 1/pt variance
368 //____________________________________________________________
369 inline void AliTRDseedV1::SetN(Int_t n)
371 if(n<0 || n>kNclusters) return;
376 //____________________________________________________________
377 inline void AliTRDseedV1::SetNUsed(Int_t n)
379 if(n<0 || n>kNclusters) return;
380 UInt_t mask(kMask<<kNbits);
382 n=n<<kNbits; fN |= (n&mask);
385 //____________________________________________________________
386 inline void AliTRDseedV1::SetNShared(Int_t n)
388 if(n<0 || n>kNclusters) return;
389 UInt_t mask((kMask<<kNbits)<<kNbits);
391 n = (n<<kNbits)<<kNbits; fN|=(n&mask);
394 //____________________________________________________________
395 inline void AliTRDseedV1::Swap(Int_t &n1, Int_t &n2) const
397 // swap values of n1 with n2
402 //____________________________________________________________
403 inline void AliTRDseedV1::Swap(Double_t &d1, Double_t &d2) const
405 // swap values of d1 with d2