]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDseedV1.h
Bug fix (Alessandro)
[u/mrichter/AliRoot.git] / TRD / AliTRDseedV1.h
CommitLineData
e4f2f73d 1#ifndef ALITRDSEEDV1_H
2#define ALITRDSEEDV1_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
e44586fb 4* See cxx source for full Copyright notice */
e4f2f73d 5
6/* $Id$ */
7
8////////////////////////////////////////////////////////////////////////////
9// //
ee8fb199 10// \class AliTRDseedV1
11// \brief The TRD offline tracklet
12// \author Alexandru Bercuci
e4f2f73d 13// //
14////////////////////////////////////////////////////////////////////////////
15
3e778975 16#ifndef ALITRDTRACKLETBASE_H
17#include "AliTRDtrackletBase.h"
e3cf3d02 18#endif
19
20#ifndef ROOT_TMath
21#include "TMath.h"
e4f2f73d 22#endif
23
ae4e8b84 24#ifndef ALITRDGEOMETRY_H
25#include "AliTRDgeometry.h"
26#endif
27
0906e73e 28#ifndef ALIPID_H
29#include "AliPID.h"
30#endif
31
e4f2f73d 32#ifndef ALIRIEMAN_H
33#include "AliRieman.h"
34#endif
35
f29f13a6 36#ifndef ALITRDCLUSTER_H
37#include "AliTRDcluster.h"
38#endif
39
d07eec70 40#include "AliTRDReconstructor.h"
41
e4f2f73d 42class TTreeSRedirector;
f301a656 43class TLinearFitter;
e4f2f73d 44
45class AliRieman;
46
eb38ed55 47class AliTRDtrackingChamber;
f3d3af1b 48class AliTRDtrackV1;
eb2b4f91 49class AliTRDpadPlane;
3e778975 50class AliTRDseedV1 : public AliTRDtrackletBase
51{
3044dfe5 52 friend class AliHLTTRDTracklet;
53
e3cf3d02 54public:
55 enum ETRDtrackletBuffers {
980d5a2a 56 kNbits = 6 // bits to store number of clusters
57 ,kMask = 0x3f // bit mask
58 ,kNtb = 31 // max clusters/pad row
8d2bec9e 59 ,kNclusters = 2*kNtb // max number of clusters/tracklet
60 ,kNslices = 10 // max dEdx slices
e44586fb 61 };
e3cf3d02 62
2e2915e7 63 // bits from 0-13 are reserved by ROOT (see TObject.h)
e3cf3d02 64 enum ETRDtrackletStatus {
f29f13a6 65 kOwner = BIT(14) // owner of its clusters
66 ,kRowCross = BIT(15) // pad row cross tracklet
e20bef2b 67 ,kPID = BIT(16) // PID contributor
68 ,kCalib = BIT(17) // calibrated tracklet
69 ,kKink = BIT(18) // kink prolongation tracklet
1fd9389f 70 ,kStandAlone = BIT(19) // tracklet build during stand alone track finding
2eb10c34 71 ,kPrimary = BIT(20) // tracklet from a primary track candidate
e44586fb 72 };
2eb10c34 73
74 enum ETRDtrackletError { // up to 8 bits
75 kAttachClFound = 0 // not enough clusters found
76 ,kAttachRowGap = 1 // found gap attached rows
77 ,kAttachRow = 2 // found 3 rows
78 ,kAttachMultipleCl= 3// multiple clusters attached to time bin
79 ,kAttachClAttach= 4 // not enough clusters attached
80 ,kFitCl = 5 // not enough clusters for fit
81 ,kFitFailedY = 6 // fit failed in XY plane failed
82 ,kFitFailedZ = 7 // fit in the QZ plane failed
7c3eecb8 83 };
e44586fb 84
ae4e8b84 85 AliTRDseedV1(Int_t det = -1);
e44586fb 86 ~AliTRDseedV1();
87 AliTRDseedV1(const AliTRDseedV1 &ref);
88 AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
89
4d6aee34 90 Bool_t AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt = kFALSE);
203967fc 91 void Bootstrap(const AliTRDReconstructor *rec);
e3cf3d02 92 void Calibrate();
203967fc 93 void CookdEdx(Int_t nslices);
e3cf3d02 94 void CookLabels();
3e778975 95 Bool_t CookPID();
2eb10c34 96 Bool_t Fit(UChar_t opt=0);
203967fc 97 Bool_t Init(AliTRDtrackV1 *track);
e44586fb 98 inline void Init(const AliRieman *fit);
203967fc 99 Bool_t IsEqual(const TObject *inTracklet) const;
e3cf3d02 100 Bool_t IsCalibrated() const { return TestBit(kCalib);}
e44586fb 101 Bool_t IsOwner() const { return TestBit(kOwner);}
f29f13a6 102 Bool_t IsKink() const { return TestBit(kKink);}
2eb10c34 103 Bool_t IsPrimary() const { return TestBit(kPrimary);}
e20bef2b 104 Bool_t HasPID() const { return TestBit(kPID);}
2eb10c34 105 Bool_t HasError(ETRDtrackletError err) const
106 { return TESTBIT(fErrorMsg, err);}
3e778975 107 Bool_t IsOK() const { return GetN() > 4 && GetNUsed() < 4;}
e44586fb 108 Bool_t IsRowCross() const { return TestBit(kRowCross);}
f29f13a6 109 Bool_t IsUsable(Int_t i) const { return fClusters[i] && !fClusters[i]->IsUsed();}
110 Bool_t IsStandAlone() const { return TestBit(kStandAlone);}
e44586fb 111
2eb10c34 112 Float_t GetAnodeWireOffset(Float_t zt);
68f9b6bd 113 Float_t GetC(Int_t typ=0) const { return fC[typ]; }
e3cf3d02 114 Float_t GetChi2() const { return fChi2; }
115 inline Float_t GetChi2Z() const;
116 inline Float_t GetChi2Y() const;
f29f13a6 117 inline Float_t GetChi2Phi() const;
e44586fb 118 void GetCovAt(Double_t x, Double_t *cov) const;
d937ad7a 119 void GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
16cca13f 120 void GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov, 7*sizeof(Double_t));}
66765e8e 121 static Int_t GetCovSqrt(const Double_t * const c, Double_t *d);
4d6aee34 122 static Double_t GetCovInv(const Double_t * const c, Double_t *d);
7c3eecb8 123 UChar_t GetErrorMsg() const { return fErrorMsg;}
203967fc 124 Float_t GetdX() const { return fdX;}
4d6aee34 125 const Float_t* GetdEdx() const { return &fdEdx[0];}
126 Float_t GetdQdl(Int_t ic, Float_t *dx=NULL) const;
2eb10c34 127 Float_t GetdYdX() const { return fYfit[1];}
128 Float_t GetdZdX() const { return fZfit[1];}
3e778975 129 Int_t GetdY() const { return Int_t(GetY()/0.014);}
203967fc 130 Int_t GetDetector() const { return fDet;}
e3cf3d02 131 void GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const {
132 exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
4d6aee34 133 AliTRDcluster* GetClusters(Int_t i) const { return i<0 || i>=kNclusters ? NULL: fClusters[i];}
8d2bec9e 134 Int_t GetIndexes(Int_t i) const{ return i<0 || i>=kNclusters ? -1 : fIndexes[i];}
e3cf3d02 135 Int_t GetLabels(Int_t i) const { return fLabels[i];}
4d6aee34 136 Float_t GetMomentum(Float_t *err = NULL) const;
980d5a2a 137 Int_t GetN() const { return (Int_t)fN&kMask;}
3e778975 138 Int_t GetN2() const { return GetN();}
980d5a2a 139 Int_t GetNUsed() const { return Int_t((fN>>kNbits)&kMask);}
140 Int_t GetNShared() const { return Int_t(((fN>>kNbits)>>kNbits)&kMask);}
b453ef55 141 Float_t GetOccupancyTB() const;
e44586fb 142 Float_t GetQuality(Bool_t kZcorr) const;
dd8059a8 143 Float_t GetPadLength() const { return fPad[0];}
144 Float_t GetPadWidth() const { return fPad[1];}
ae4e8b84 145 Int_t GetPlane() const { return AliTRDgeometry::GetLayer(fDet); }
146
3e778975 147 Float_t* GetProbability(Bool_t force=kFALSE);
b25a5e9e 148 Float_t GetPt() const { return fPt; }
3e778975 149 inline Double_t GetPID(Int_t is=-1) const;
e3cf3d02 150 Float_t GetS2Y() const { return fS2Y;}
151 Float_t GetS2Z() const { return fS2Z;}
152 Float_t GetSigmaY() const { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
153 Float_t GetSnp() const { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
1fd9389f 154 Float_t GetTgl() const { return fZref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
dd8059a8 155 Float_t GetTilt() const { return fPad[2];}
3e778975 156 UInt_t GetTrackletWord() const { return 0;}
b72f4eaf 157 UShort_t GetVolumeId() const;
e3cf3d02 158 Float_t GetX0() const { return fX0;}
159 Float_t GetX() const { return fX0 - fX;}
5a7a515d 160 Float_t GetY() const { return fYfit[0] - fYfit[1] * fX;}
b1957d3c 161 Double_t GetYat(Double_t x) const { return fYfit[0] - fYfit[1] * (fX0-x);}
1fd9389f 162 Float_t GetYfit(Int_t id) const { return fYfit[id];}
163 Float_t GetYref(Int_t id) const { return fYref[id];}
164 Float_t GetZ() const { return fZfit[0] - fZfit[1] * fX;}
b1957d3c 165 Double_t GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
1fd9389f 166 Float_t GetZfit(Int_t id) const { return fZfit[id];}
167 Float_t GetZref(Int_t id) const { return fZref[id];}
168 Int_t GetYbin() const { return Int_t(GetY()/0.016);}
169 Int_t GetZbin() const { return Int_t(GetZ()/fPad[0]);}
e3cf3d02 170
ae4e8b84 171 inline AliTRDcluster* NextCluster();
71ea19a3 172 inline AliTRDcluster* PrevCluster();
e44586fb 173 void Print(Option_t *o = "") const;
71ea19a3 174 inline void ResetClusterIter(Bool_t forward = kTRUE);
980d5a2a 175 void Reset(Option_t *opt="");
ae4e8b84 176
68f9b6bd 177 void SetC(Float_t c, Int_t typ=0) { fC[typ] = c;}
1fd9389f 178 void SetChi2(Float_t chi2) { fChi2 = chi2;}
16cca13f 179 inline void SetCovRef(const Double_t *cov);
2eb10c34 180 void SetErrorMsg(ETRDtrackletError err) { SETBIT(fErrorMsg, err);}
e3cf3d02 181 void SetIndexes(Int_t i, Int_t idx) { fIndexes[i] = idx; }
182 void SetLabels(Int_t *lbls) { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
e20bef2b 183 void SetKink(Bool_t k = kTRUE){ SetBit(kKink, k);}
2eb10c34 184 void SetPrimary(Bool_t k = kTRUE){ SetBit(kPrimary, k);}
e20bef2b 185 void SetPID(Bool_t k = kTRUE) { SetBit(kPID, k);}
f29f13a6 186 void SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
b25a5e9e 187 void SetPt(Double_t pt) { fPt = pt;}
29b87567 188 void SetOwner();
eb2b4f91 189 void SetPadPlane(AliTRDpadPlane *p);
dd8059a8 190 void SetPadLength(Float_t l) { fPad[0] = l;}
191 void SetPadWidth(Float_t w) { fPad[1] = w;}
cbe97468 192 void SetTilt(Float_t tilt) { fPad[2] = tilt; }
203967fc 193 void SetDetector(Int_t d) { fDet = d; }
bee2b41e 194 void SetDX(Float_t inDX) { fdX = inDX;}
4d6aee34 195 void SetReconstructor(const AliTRDReconstructor *rec) {fkReconstructor = rec;}
e3cf3d02 196 void SetX0(Float_t x0) { fX0 = x0; }
197 void SetYref(Int_t i, Float_t y) { fYref[i] = y;}
198 void SetZref(Int_t i, Float_t z) { fZref[i] = z;}
f29f13a6 199// void SetUsabilityMap(Long_t um) { fUsable = um; }
16cca13f 200 void Update(const AliTRDtrackV1* trk);
e3cf3d02 201 void UpdateUsed();
202 void UseClusters();
e4f2f73d 203
d937ad7a 204protected:
3e778975 205 void Copy(TObject &ref) const;
e4f2f73d 206
e44586fb 207private:
3e778975 208 inline void SetN(Int_t n);
209 inline void SetNUsed(Int_t n);
210 inline void SetNShared(Int_t n);
560e5c05 211 inline void Swap(Int_t &n1, Int_t &n2);
212 inline void Swap(Double_t &d1, Double_t &d2);
3e778975 213
4d6aee34 214 const AliTRDReconstructor *fkReconstructor;//! local reconstructor
e3cf3d02 215 AliTRDcluster **fClusterIter; //! clusters iterator
8d2bec9e 216 Int_t fIndexes[kNclusters]; //! Indexes
0323ef61 217 Float_t fExB; // tg(a_L) @ tracklet location
218 Float_t fVD; // drift velocity @ tracklet location
219 Float_t fT0; // time 0 @ tracklet location
220 Float_t fS2PRF; // sigma^2 PRF for xd->0 and phi=a_L
221 Float_t fDiffL; // longitudinal diffusion coefficient
222 Float_t fDiffT; // transversal diffusion coefficient
71ea19a3 223 Char_t fClusterIdx; //! clusters iterator
7c3eecb8 224 UChar_t fErrorMsg; // processing error
6ad5e6b2 225 UInt_t fN; // number of clusters attached/used/shared
e3cf3d02 226 Short_t fDet; // TRD detector
8d2bec9e 227 AliTRDcluster *fClusters[kNclusters]; // Clusters
2eb10c34 228 Float_t fPad[4]; // local pad definition : length/width/tilt/anode wire offset
1fd9389f 229 Float_t fYref[2]; // Reference y, dydx
230 Float_t fZref[2]; // Reference z, dz/dx
231 Float_t fYfit[2]; // Fit y, dy/dx
232 Float_t fZfit[2]; // Fit z
16cca13f 233 Float_t fPt; // Pt estimate @ tracklet [GeV/c]
e44586fb 234 Float_t fdX; // length of time bin
e3cf3d02 235 Float_t fX0; // anode wire position
236 Float_t fX; // radial position of the tracklet
237 Float_t fY; // r-phi position of the tracklet
238 Float_t fZ; // z position of the tracklet
239 Float_t fS2Y; // estimated resolution in the r-phi direction
240 Float_t fS2Z; // estimated resolution in the z direction
68f9b6bd 241 Float_t fC[2]; // Curvature for standalone [0] rieman [1] vertex constrained
e3cf3d02 242 Float_t fChi2; // Global chi2
8d2bec9e 243 Float_t fdEdx[kNslices]; // dE/dx measurements for tracklet
1fd9389f 244 Float_t fProb[AliPID::kSPECIES]; // PID probabilities
e3cf3d02 245 Int_t fLabels[3]; // most frequent MC labels and total number of different labels
16cca13f 246 Double_t fRefCov[7]; // covariance matrix of the track in the yz plane + the rest of the diagonal elements
d937ad7a 247 Double_t fCov[3]; // covariance matrix of the tracklet in the xy plane
e4f2f73d 248
206d8e80 249 ClassDef(AliTRDseedV1, 11) // The offline TRD tracklet
e4f2f73d 250};
251
252//____________________________________________________________
e3cf3d02 253inline Float_t AliTRDseedV1::GetChi2Z() const
e4f2f73d 254{
e3cf3d02 255 Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
256 Double_t cov[3]; GetCovAt(fX, cov);
257 Double_t s2 = fRefCov[2]+cov[2];
258 return s2 > 0. ? dz/s2 : 0.;
e4f2f73d 259}
260
261//____________________________________________________________
e3cf3d02 262inline Float_t AliTRDseedV1::GetChi2Y() const
e4f2f73d 263{
e3cf3d02 264 Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
265 Double_t cov[3]; GetCovAt(fX, cov);
266 Double_t s2 = fRefCov[0]+cov[0];
267 return s2 > 0. ? dy/s2 : 0.;
e4f2f73d 268}
269
f29f13a6 270//____________________________________________________________
271inline Float_t AliTRDseedV1::GetChi2Phi() const
272{
273 Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
274 Double_t cov[3]; GetCovAt(fX, cov);
275 Double_t s2 = fRefCov[2]+cov[2];
276 return s2 > 0. ? dphi/s2 : 0.;
277}
278
16cca13f 279
280
3e778975 281//____________________________________________________________
282inline Double_t AliTRDseedV1::GetPID(Int_t is) const
283{
284 if(is<0) return fProb[AliPID::kElectron];
285 if(is<AliPID::kSPECIES) return fProb[is];
286 return 0.;
287}
288
e4f2f73d 289//____________________________________________________________
0906e73e 290inline void AliTRDseedV1::Init(const AliRieman *rieman)
e4f2f73d 291{
e44586fb 292 fZref[0] = rieman->GetZat(fX0);
293 fZref[1] = rieman->GetDZat(fX0);
294 fYref[0] = rieman->GetYat(fX0);
295 fYref[1] = rieman->GetDYat(fX0);
4d6aee34 296 if(fkReconstructor && fkReconstructor->IsHLT()){
d07eec70 297 fRefCov[0] = 1;
298 fRefCov[2] = 10;
299 }else{
300 fRefCov[0] = rieman->GetErrY(fX0);
301 fRefCov[2] = rieman->GetErrZ(fX0);
302 }
68f9b6bd 303 fC[0] = rieman->GetC();
55ef6967 304 fChi2 = rieman->GetChi2();
e4f2f73d 305}
306
ae4e8b84 307//____________________________________________________________
308inline AliTRDcluster* AliTRDseedV1::NextCluster()
309{
71ea19a3 310// Mimic the usage of STL iterators.
311// Forward iterator
312
ae4e8b84 313 fClusterIdx++; fClusterIter++;
8d2bec9e 314 while(fClusterIdx < kNclusters){
71ea19a3 315 if(!(*fClusterIter)){
316 fClusterIdx++;
317 fClusterIter++;
318 continue;
319 }
320 return *fClusterIter;
321 }
4d6aee34 322 return NULL;
71ea19a3 323}
324
325//____________________________________________________________
326inline AliTRDcluster* AliTRDseedV1::PrevCluster()
327{
328// Mimic the usage of STL iterators.
329// Backward iterator
330
331 fClusterIdx--; fClusterIter--;
332 while(fClusterIdx >= 0){
333 if(!(*fClusterIter)){
334 fClusterIdx--;
335 fClusterIter--;
336 continue;
337 }
338 return *fClusterIter;
339 }
4d6aee34 340 return NULL;
71ea19a3 341}
342
343//____________________________________________________________
344inline void AliTRDseedV1::ResetClusterIter(Bool_t forward)
345{
346// Mimic the usage of STL iterators.
347// Facilitate the usage of NextCluster for forward like
348// iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
349
350 if(forward){
351 fClusterIter = &fClusters[0]; fClusterIter--;
352 fClusterIdx=-1;
353 } else {
8d2bec9e 354 fClusterIter = &fClusters[kNclusters-1]; fClusterIter++;
355 fClusterIdx=kNclusters;
71ea19a3 356 }
ae4e8b84 357}
358
16cca13f 359//____________________________________________________________
360inline void AliTRDseedV1::SetCovRef(const Double_t *cov)
361{
362// Copy some "important" covariance matrix elements
363// var(y)
364// cov(y,z) var(z)
365// var(snp)
366// var(tgl)
367// cov(tgl, 1/pt) var(1/pt)
368
369 memcpy(&fRefCov[0], cov, 3*sizeof(Double_t)); // yz full covariance
370 fRefCov[3] = cov[ 5]; // snp variance
371 fRefCov[4] = cov[ 9]; // tgl variance
372 fRefCov[5] = cov[13]; // cov(tgl, 1/pt)
373 fRefCov[6] = cov[14]; // 1/pt variance
374}
375
376
3e778975 377//____________________________________________________________
378inline void AliTRDseedV1::SetN(Int_t n)
379{
6ad5e6b2 380 if(n<0 || n>kNclusters) return;
980d5a2a 381 fN &= ~kMask;
382 fN |= (n&kMask);
3e778975 383}
384
385//____________________________________________________________
386inline void AliTRDseedV1::SetNUsed(Int_t n)
387{
6ad5e6b2 388 if(n<0 || n>kNclusters) return;
980d5a2a 389 UInt_t mask(kMask<<kNbits);
6ad5e6b2 390 fN &= ~mask;
980d5a2a 391 n=n<<kNbits; fN |= (n&mask);
3e778975 392}
393
394//____________________________________________________________
395inline void AliTRDseedV1::SetNShared(Int_t n)
396{
6ad5e6b2 397 if(n<0 || n>kNclusters) return;
980d5a2a 398 UInt_t mask((kMask<<kNbits)<<kNbits);
6ad5e6b2 399 fN &= ~mask;
980d5a2a 400 n = (n<<kNbits)<<kNbits; fN|=(n&mask);
3e778975 401}
402
560e5c05 403//____________________________________________________________
404inline void AliTRDseedV1::Swap(Int_t &n1, Int_t &n2)
405{
406// swap values of n1 with n2
407 Int_t tmp(n1);
408 n1=n2; n2=tmp;
409}
410
411//____________________________________________________________
412inline void AliTRDseedV1::Swap(Double_t &d1, Double_t &d2)
413{
414// swap values of d1 with d2
415 Double_t tmp(d1);
416 d1=d2; d2=tmp;
417}
418
3e778975 419
e4f2f73d 420#endif
421
47d5d320 422
6e49cfdb 423