]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDseedV1.h
1. Bug fix - double deletion, crash only in some fraction of cases
[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
e44586fb 71 };
7c3eecb8 72 enum ETRDtrackletError {
73 kAttachClFound = 1 // not enough clusters found
74 ,kAttachRow // found row < 0
6ad5e6b2 75 ,kAttachMultipleCl // multiple clusters attached to time bin
7c3eecb8 76 ,kAttachClAttach // not enough clusters attached
77 };
e44586fb 78
ae4e8b84 79 AliTRDseedV1(Int_t det = -1);
e44586fb 80 ~AliTRDseedV1();
81 AliTRDseedV1(const AliTRDseedV1 &ref);
82 AliTRDseedV1& operator=(const AliTRDseedV1 &ref);
83
4d6aee34 84 Bool_t AttachClusters(AliTRDtrackingChamber *const chamber, Bool_t tilt = kFALSE);
203967fc 85 void Bootstrap(const AliTRDReconstructor *rec);
e3cf3d02 86 void Calibrate();
203967fc 87 void CookdEdx(Int_t nslices);
e3cf3d02 88 void CookLabels();
3e778975 89 Bool_t CookPID();
b72f4eaf 90 Bool_t Fit(Bool_t tilt=kFALSE, Bool_t zcorr=kFALSE);
203967fc 91 Bool_t Init(AliTRDtrackV1 *track);
e44586fb 92 inline void Init(const AliRieman *fit);
203967fc 93 Bool_t IsEqual(const TObject *inTracklet) const;
e3cf3d02 94 Bool_t IsCalibrated() const { return TestBit(kCalib);}
e44586fb 95 Bool_t IsOwner() const { return TestBit(kOwner);}
f29f13a6 96 Bool_t IsKink() const { return TestBit(kKink);}
e20bef2b 97 Bool_t HasPID() const { return TestBit(kPID);}
3e778975 98 Bool_t IsOK() const { return GetN() > 4 && GetNUsed() < 4;}
e44586fb 99 Bool_t IsRowCross() const { return TestBit(kRowCross);}
f29f13a6 100 Bool_t IsUsable(Int_t i) const { return fClusters[i] && !fClusters[i]->IsUsed();}
101 Bool_t IsStandAlone() const { return TestBit(kStandAlone);}
e44586fb 102
e3cf3d02 103 Float_t GetC() const { return fC; }
104 Float_t GetChi2() const { return fChi2; }
105 inline Float_t GetChi2Z() const;
106 inline Float_t GetChi2Y() const;
f29f13a6 107 inline Float_t GetChi2Phi() const;
e44586fb 108 void GetCovAt(Double_t x, Double_t *cov) const;
d937ad7a 109 void GetCovXY(Double_t *cov) const { memcpy(cov, &fCov[0], 3*sizeof(Double_t));}
16cca13f 110 void GetCovRef(Double_t *cov) const { memcpy(cov, &fRefCov, 7*sizeof(Double_t));}
4d6aee34 111 static Double_t GetCovSqrt(const Double_t * const c, Double_t *d);
112 static Double_t GetCovInv(const Double_t * const c, Double_t *d);
7c3eecb8 113 UChar_t GetErrorMsg() const { return fErrorMsg;}
203967fc 114 Float_t GetdX() const { return fdX;}
4d6aee34 115 const Float_t* GetdEdx() const { return &fdEdx[0];}
116 Float_t GetdQdl(Int_t ic, Float_t *dx=NULL) const;
3e778975 117 Float_t GetdYdX() const { return fYfit[1]; }
118 Float_t GetdZdX() const { return fZref[1]; }
119 Int_t GetdY() const { return Int_t(GetY()/0.014);}
203967fc 120 Int_t GetDetector() const { return fDet;}
e3cf3d02 121 void GetCalibParam(Float_t &exb, Float_t &vd, Float_t &t0, Float_t &s2, Float_t &dl, Float_t &dt) const {
122 exb = fExB; vd = fVD; t0 = fT0; s2 = fS2PRF; dl = fDiffL; dt = fDiffT;}
4d6aee34 123 AliTRDcluster* GetClusters(Int_t i) const { return i<0 || i>=kNclusters ? NULL: fClusters[i];}
f301a656 124 static TLinearFitter* GetFitterY();
125 static TLinearFitter* GetFitterZ();
8d2bec9e 126 Int_t GetIndexes(Int_t i) const{ return i<0 || i>=kNclusters ? -1 : fIndexes[i];}
e3cf3d02 127 Int_t GetLabels(Int_t i) const { return fLabels[i];}
4d6aee34 128 Float_t GetMomentum(Float_t *err = NULL) const;
980d5a2a 129 Int_t GetN() const { return (Int_t)fN&kMask;}
3e778975 130 Int_t GetN2() const { return GetN();}
980d5a2a 131 Int_t GetNUsed() const { return Int_t((fN>>kNbits)&kMask);}
132 Int_t GetNShared() const { return Int_t(((fN>>kNbits)>>kNbits)&kMask);}
e44586fb 133 Float_t GetQuality(Bool_t kZcorr) const;
dd8059a8 134 Float_t GetPadLength() const { return fPad[0];}
135 Float_t GetPadWidth() const { return fPad[1];}
ae4e8b84 136 Int_t GetPlane() const { return AliTRDgeometry::GetLayer(fDet); }
137
3e778975 138 Float_t* GetProbability(Bool_t force=kFALSE);
b25a5e9e 139 Float_t GetPt() const { return fPt; }
3e778975 140 inline Double_t GetPID(Int_t is=-1) const;
e3cf3d02 141 Float_t GetS2Y() const { return fS2Y;}
142 Float_t GetS2Z() const { return fS2Z;}
143 Float_t GetSigmaY() const { return fS2Y > 0. ? TMath::Sqrt(fS2Y) : 0.2;}
144 Float_t GetSnp() const { return fYref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
1fd9389f 145 Float_t GetTgl() const { return fZref[1]/TMath::Sqrt(1+fYref[1]*fYref[1]);}
dd8059a8 146 Float_t GetTilt() const { return fPad[2];}
3e778975 147 UInt_t GetTrackletWord() const { return 0;}
b72f4eaf 148 UShort_t GetVolumeId() const;
e3cf3d02 149 Float_t GetX0() const { return fX0;}
150 Float_t GetX() const { return fX0 - fX;}
5a7a515d 151 Float_t GetY() const { return fYfit[0] - fYfit[1] * fX;}
b1957d3c 152 Double_t GetYat(Double_t x) const { return fYfit[0] - fYfit[1] * (fX0-x);}
1fd9389f 153 Float_t GetYfit(Int_t id) const { return fYfit[id];}
154 Float_t GetYref(Int_t id) const { return fYref[id];}
155 Float_t GetZ() const { return fZfit[0] - fZfit[1] * fX;}
b1957d3c 156 Double_t GetZat(Double_t x) const { return fZfit[0] - fZfit[1] * (fX0-x);}
1fd9389f 157 Float_t GetZfit(Int_t id) const { return fZfit[id];}
158 Float_t GetZref(Int_t id) const { return fZref[id];}
159 Int_t GetYbin() const { return Int_t(GetY()/0.016);}
160 Int_t GetZbin() const { return Int_t(GetZ()/fPad[0]);}
e3cf3d02 161
ae4e8b84 162 inline AliTRDcluster* NextCluster();
71ea19a3 163 inline AliTRDcluster* PrevCluster();
e44586fb 164 void Print(Option_t *o = "") const;
71ea19a3 165 inline void ResetClusterIter(Bool_t forward = kTRUE);
980d5a2a 166 void Reset(Option_t *opt="");
ae4e8b84 167
1fd9389f 168 void SetC(Float_t c) { fC = c;}
169 void SetChi2(Float_t chi2) { fChi2 = chi2;}
16cca13f 170 inline void SetCovRef(const Double_t *cov);
7c3eecb8 171 void SetErrorMsg(Int_t err) { fErrorMsg = err;}
e3cf3d02 172 void SetIndexes(Int_t i, Int_t idx) { fIndexes[i] = idx; }
173 void SetLabels(Int_t *lbls) { memcpy(fLabels, lbls, 3*sizeof(Int_t)); }
e20bef2b 174 void SetKink(Bool_t k = kTRUE){ SetBit(kKink, k);}
175 void SetPID(Bool_t k = kTRUE) { SetBit(kPID, k);}
f29f13a6 176 void SetStandAlone(Bool_t st) { SetBit(kStandAlone, st); }
b25a5e9e 177 void SetPt(Double_t pt) { fPt = pt;}
29b87567 178 void SetOwner();
eb2b4f91 179 void SetPadPlane(AliTRDpadPlane *p);
dd8059a8 180 void SetPadLength(Float_t l) { fPad[0] = l;}
181 void SetPadWidth(Float_t w) { fPad[1] = w;}
cbe97468 182 void SetTilt(Float_t tilt) { fPad[2] = tilt; }
203967fc 183 void SetDetector(Int_t d) { fDet = d; }
bee2b41e 184 void SetDX(Float_t inDX) { fdX = inDX;}
4d6aee34 185 void SetReconstructor(const AliTRDReconstructor *rec) {fkReconstructor = rec;}
e3cf3d02 186 void SetX0(Float_t x0) { fX0 = x0; }
187 void SetYref(Int_t i, Float_t y) { fYref[i] = y;}
188 void SetZref(Int_t i, Float_t z) { fZref[i] = z;}
f29f13a6 189// void SetUsabilityMap(Long_t um) { fUsable = um; }
16cca13f 190 void Update(const AliTRDtrackV1* trk);
e3cf3d02 191 void UpdateUsed();
192 void UseClusters();
e4f2f73d 193
d937ad7a 194protected:
3e778975 195 void Copy(TObject &ref) const;
e4f2f73d 196
e44586fb 197private:
3e778975 198 inline void SetN(Int_t n);
199 inline void SetNUsed(Int_t n);
200 inline void SetNShared(Int_t n);
201
4d6aee34 202 const AliTRDReconstructor *fkReconstructor;//! local reconstructor
e3cf3d02 203 AliTRDcluster **fClusterIter; //! clusters iterator
8d2bec9e 204 Int_t fIndexes[kNclusters]; //! Indexes
e3cf3d02 205 Float_t fExB; //! tg(a_L) @ tracklet location
206 Float_t fVD; //! drift velocity @ tracklet location
207 Float_t fT0; //! time 0 @ tracklet location
208 Float_t fS2PRF; //! sigma^2 PRF for xd->0 and phi=a_L
209 Float_t fDiffL; //! longitudinal diffusion coefficient
210 Float_t fDiffT; //! transversal diffusion coefficient
71ea19a3 211 Char_t fClusterIdx; //! clusters iterator
7c3eecb8 212 UChar_t fErrorMsg; // processing error
6ad5e6b2 213 UInt_t fN; // number of clusters attached/used/shared
e3cf3d02 214 Short_t fDet; // TRD detector
8d2bec9e 215 AliTRDcluster *fClusters[kNclusters]; // Clusters
dd8059a8 216 Float_t fPad[3]; // local pad definition : length/width/tilt
1fd9389f 217 Float_t fYref[2]; // Reference y, dydx
218 Float_t fZref[2]; // Reference z, dz/dx
219 Float_t fYfit[2]; // Fit y, dy/dx
220 Float_t fZfit[2]; // Fit z
16cca13f 221 Float_t fPt; // Pt estimate @ tracklet [GeV/c]
e44586fb 222 Float_t fdX; // length of time bin
e3cf3d02 223 Float_t fX0; // anode wire position
224 Float_t fX; // radial position of the tracklet
225 Float_t fY; // r-phi position of the tracklet
226 Float_t fZ; // z position of the tracklet
227 Float_t fS2Y; // estimated resolution in the r-phi direction
228 Float_t fS2Z; // estimated resolution in the z direction
229 Float_t fC; // Curvature
230 Float_t fChi2; // Global chi2
8d2bec9e 231 Float_t fdEdx[kNslices]; // dE/dx measurements for tracklet
1fd9389f 232 Float_t fProb[AliPID::kSPECIES]; // PID probabilities
e3cf3d02 233 Int_t fLabels[3]; // most frequent MC labels and total number of different labels
16cca13f 234 Double_t fRefCov[7]; // covariance matrix of the track in the yz plane + the rest of the diagonal elements
d937ad7a 235 Double_t fCov[3]; // covariance matrix of the tracklet in the xy plane
4d6aee34 236 static TLinearFitter *fgFitterY; // Linear Fitter for tracklet fit in xy-plane
237 static TLinearFitter *fgFitterZ; // Linear Fitter for tracklet fit in xz-plane
e4f2f73d 238
7c3eecb8 239 ClassDef(AliTRDseedV1, 8) // The offline TRD tracklet
e4f2f73d 240};
241
242//____________________________________________________________
e3cf3d02 243inline Float_t AliTRDseedV1::GetChi2Z() const
e4f2f73d 244{
e3cf3d02 245 Double_t dz = fZref[0]-fZfit[0]; dz*=dz;
246 Double_t cov[3]; GetCovAt(fX, cov);
247 Double_t s2 = fRefCov[2]+cov[2];
248 return s2 > 0. ? dz/s2 : 0.;
e4f2f73d 249}
250
251//____________________________________________________________
e3cf3d02 252inline Float_t AliTRDseedV1::GetChi2Y() const
e4f2f73d 253{
e3cf3d02 254 Double_t dy = fYref[0]-fYfit[0]; dy*=dy;
255 Double_t cov[3]; GetCovAt(fX, cov);
256 Double_t s2 = fRefCov[0]+cov[0];
257 return s2 > 0. ? dy/s2 : 0.;
e4f2f73d 258}
259
f29f13a6 260//____________________________________________________________
261inline Float_t AliTRDseedV1::GetChi2Phi() const
262{
263 Double_t dphi = fYref[1]-fYfit[1]; dphi*=dphi;
264 Double_t cov[3]; GetCovAt(fX, cov);
265 Double_t s2 = fRefCov[2]+cov[2];
266 return s2 > 0. ? dphi/s2 : 0.;
267}
268
16cca13f 269
270
3e778975 271//____________________________________________________________
272inline Double_t AliTRDseedV1::GetPID(Int_t is) const
273{
274 if(is<0) return fProb[AliPID::kElectron];
275 if(is<AliPID::kSPECIES) return fProb[is];
276 return 0.;
277}
278
e4f2f73d 279//____________________________________________________________
0906e73e 280inline void AliTRDseedV1::Init(const AliRieman *rieman)
e4f2f73d 281{
e44586fb 282 fZref[0] = rieman->GetZat(fX0);
283 fZref[1] = rieman->GetDZat(fX0);
284 fYref[0] = rieman->GetYat(fX0);
285 fYref[1] = rieman->GetDYat(fX0);
4d6aee34 286 if(fkReconstructor && fkReconstructor->IsHLT()){
d07eec70 287 fRefCov[0] = 1;
288 fRefCov[2] = 10;
289 }else{
290 fRefCov[0] = rieman->GetErrY(fX0);
291 fRefCov[2] = rieman->GetErrZ(fX0);
292 }
55ef6967 293 fC = rieman->GetC();
294 fChi2 = rieman->GetChi2();
e4f2f73d 295}
296
ae4e8b84 297//____________________________________________________________
298inline AliTRDcluster* AliTRDseedV1::NextCluster()
299{
71ea19a3 300// Mimic the usage of STL iterators.
301// Forward iterator
302
ae4e8b84 303 fClusterIdx++; fClusterIter++;
8d2bec9e 304 while(fClusterIdx < kNclusters){
71ea19a3 305 if(!(*fClusterIter)){
306 fClusterIdx++;
307 fClusterIter++;
308 continue;
309 }
310 return *fClusterIter;
311 }
4d6aee34 312 return NULL;
71ea19a3 313}
314
315//____________________________________________________________
316inline AliTRDcluster* AliTRDseedV1::PrevCluster()
317{
318// Mimic the usage of STL iterators.
319// Backward iterator
320
321 fClusterIdx--; fClusterIter--;
322 while(fClusterIdx >= 0){
323 if(!(*fClusterIter)){
324 fClusterIdx--;
325 fClusterIter--;
326 continue;
327 }
328 return *fClusterIter;
329 }
4d6aee34 330 return NULL;
71ea19a3 331}
332
333//____________________________________________________________
334inline void AliTRDseedV1::ResetClusterIter(Bool_t forward)
335{
336// Mimic the usage of STL iterators.
337// Facilitate the usage of NextCluster for forward like
338// iterator (kTRUE) and PrevCluster for backward like iterator (kFALSE)
339
340 if(forward){
341 fClusterIter = &fClusters[0]; fClusterIter--;
342 fClusterIdx=-1;
343 } else {
8d2bec9e 344 fClusterIter = &fClusters[kNclusters-1]; fClusterIter++;
345 fClusterIdx=kNclusters;
71ea19a3 346 }
ae4e8b84 347}
348
16cca13f 349//____________________________________________________________
350inline void AliTRDseedV1::SetCovRef(const Double_t *cov)
351{
352// Copy some "important" covariance matrix elements
353// var(y)
354// cov(y,z) var(z)
355// var(snp)
356// var(tgl)
357// cov(tgl, 1/pt) var(1/pt)
358
359 memcpy(&fRefCov[0], cov, 3*sizeof(Double_t)); // yz full covariance
360 fRefCov[3] = cov[ 5]; // snp variance
361 fRefCov[4] = cov[ 9]; // tgl variance
362 fRefCov[5] = cov[13]; // cov(tgl, 1/pt)
363 fRefCov[6] = cov[14]; // 1/pt variance
364}
365
366
3e778975 367//____________________________________________________________
368inline void AliTRDseedV1::SetN(Int_t n)
369{
6ad5e6b2 370 if(n<0 || n>kNclusters) return;
980d5a2a 371 fN &= ~kMask;
372 fN |= (n&kMask);
3e778975 373}
374
375//____________________________________________________________
376inline void AliTRDseedV1::SetNUsed(Int_t n)
377{
6ad5e6b2 378 if(n<0 || n>kNclusters) return;
980d5a2a 379 UInt_t mask(kMask<<kNbits);
6ad5e6b2 380 fN &= ~mask;
980d5a2a 381 n=n<<kNbits; fN |= (n&mask);
3e778975 382}
383
384//____________________________________________________________
385inline void AliTRDseedV1::SetNShared(Int_t n)
386{
6ad5e6b2 387 if(n<0 || n>kNclusters) return;
980d5a2a 388 UInt_t mask((kMask<<kNbits)<<kNbits);
6ad5e6b2 389 fN &= ~mask;
980d5a2a 390 n = (n<<kNbits)<<kNbits; fN|=(n&mask);
3e778975 391}
392
393
e4f2f73d 394#endif
395
47d5d320 396
6e49cfdb 397