]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/ESD/AliMultiplicity.h
Merge branch 'TPCdev' into master
[u/mrichter/AliRoot.git] / STEER / ESD / AliMultiplicity.h
1 #ifndef ALIMULTIPLICITY_H
2 #define ALIMULTIPLICITY_H
3
4 #include <TBits.h>
5 #include <TMath.h>
6 #include "AliVMultiplicity.h"
7 class AliRefArray;
8
9 ////////////////////////////////////////////////////////
10 ////   Class containing multiplicity information      //
11 ////   to stored in the ESD                           //
12 ////////////////////////////////////////////////////////
13
14 class AliMultiplicity : public AliVMultiplicity {
15
16  public:
17   //
18   AliMultiplicity();               // default constructor
19   AliMultiplicity(Int_t ntr,Float_t *th, Float_t *ph, Float_t *dth, Float_t *dph, Int_t *labels,
20          Int_t* labelsL2, Int_t ns, Float_t *ts, Float_t *ps, Int_t *labelss, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOrFiredChips);
21   AliMultiplicity(Int_t ntr, Int_t ns, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOr);
22   AliMultiplicity(const AliMultiplicity& m);
23   AliMultiplicity& operator=(const AliMultiplicity& m);
24   virtual void Copy(TObject &obj) const;
25   virtual void Clear(Option_t* opt="");
26   virtual ~AliMultiplicity();
27   // methods to access tracklet information
28   Bool_t  GetMultTrackRefs()                  const {return TestBit(kMultTrackRefs);}
29   void    SetMultTrackRefs(Bool_t v)                {SetBit(kMultTrackRefs,v);}
30   Bool_t  GetScaleDThetaBySin2T()             const {return TestBit(kScaleDThtbySin2);}
31   void    SetScaleDThetaBySin2T(Bool_t v)           {SetBit(kScaleDThtbySin2,v);}
32   //
33   // methods supported on AliVMultiplicity level >>>
34   //
35   virtual  Int_t    GetNumberOfTracklets() const {return fNtracks;}
36   virtual  Double_t GetTheta(Int_t i)      const { 
37     if(i>=0 && i<fNtracks) return fTh[i];
38     Error("GetTheta","Invalid track number %d",i); return -9999.;
39   }
40   virtual  Double_t GetPhi(Int_t i)        const { 
41     if(i>=0 && i<fNtracks) return fPhi[i];
42     Error("GetPhi","Invalid track number %d",i); return -9999.;
43   }
44   virtual Double_t GetDeltaPhi(Int_t i)    const {
45     if(i>=0 && i<fNtracks) return fDeltPhi[i];
46     Error("GetDeltaPhi","Invalid track number %d",i); return -9999.;
47   }
48   virtual Int_t GetLabel(Int_t i, Int_t layer) const;
49   virtual void  SetLabel(Int_t i, Int_t layer, Int_t label);
50   //
51   // array getters
52   virtual Double_t* GetTheta()       const {return (Double_t*)fTh;}
53   virtual Double_t* GetPhi()         const {return (Double_t*)fPhi;}
54   virtual Double_t* GetDeltPhi()     const {return (Double_t*)fDeltPhi;}
55   virtual Int_t*    GetLabels()      const {return (Int_t*)fLabels;}  
56   virtual Int_t*    GetLabels2()     const {return (Int_t*)fLabelsL2;}
57   //
58   virtual void Print(Option_t *opt="") const;
59   //
60   // methods supported on AliVMultiplicity level <<<
61   //
62   Double_t GetDeltaTheta(Int_t i)          const {
63     if(fDeltTh && i>=0 && i<fNtracks) return fDeltTh[i];
64     Error("GetDeltaTheta","DeltaTheta not available in data or Invalid track number %d(max %d)",i, fNtracks); return -9999.;
65   }
66
67   Double_t  CalcDist(Int_t it)  const;
68   Float_t GetThetaAll(int icl, int lr) const;
69   Float_t GetPhiAll(int icl, int lr) const;
70   Int_t   GetLabelAll(int icl, int lr) const;
71
72   Int_t GetLabelSingle(Int_t i) const;
73   Int_t GetLabelSingleLr(Int_t i, Int_t layer) const;
74   void  SetLabelSingle(Int_t i, Int_t label);
75
76   Bool_t FreeClustersTracklet(Int_t i, Int_t mode) const;
77   Bool_t FreeSingleCluster(Int_t i, Int_t mode)    const;
78   
79   // methods to access single cluster information
80   Int_t SetNumberOfSingleClustersSPD2(Int_t n) {return fNsingleSPD2 = n;}
81   Int_t GetNumberOfSingleClusters() const {return fNsingle;}
82   Int_t GetNumberOfSingleClustersLr(Int_t lr) const;
83   Bool_t AreSPD2SinglesStored()         const {return TestBit(kSPD2Sng);}
84   void   SetSPD2SinglesStored(Bool_t v=kTRUE) {return SetBit(kSPD2Sng,v);}
85
86   Double_t GetThetaSingle(Int_t i) const { 
87     if(i>=0 && i<fNsingle) return fThsingle[i];
88     Error("GetThetaSingle","Invalid cluster number %d",i); return -9999.;
89   }
90
91   Double_t GetThetaSingleLr(Int_t i, Int_t lr) const { 
92     if (lr==1) {
93       if (!AreSPD2SinglesStored()) {Error("GetThetaSingle","Invalid cluster number %d for lr %d",i,lr); return -9999.;}
94       else i += GetNumberOfSingleClustersLr(0);
95     }
96     if(i>=0 && i<fNsingle) return fThsingle[i];
97     Error("GetThetaSingle","Invalid cluster number %d",i); return -9999.;
98   }
99   
100   Double_t GetPhiSingle(Int_t i) const { 
101     if(i>=0 && i<fNsingle) return fPhisingle[i];
102     Error("GetPhisingle","Invalid cluster number %d",i); return -9999.;
103   }
104   
105   Double_t GetPhiSingleLr(Int_t i, Int_t lr) const { 
106     if (lr==1) {
107       if (!AreSPD2SinglesStored()) {Error("GetPhiSingle","Invalid cluster number %d for lr %d",i,lr); return -9999.;}
108       else i += GetNumberOfSingleClustersLr(0);
109     }
110     if(i>=0 && i<fNsingle) return fPhisingle[i];
111     Error("GetPhisingle","Invalid cluster number %d",i); return -9999.;
112   }
113
114   Short_t GetNumberOfFiredChips(Int_t layer) const { return fFiredChips[layer]; }
115   void SetFiredChips(Int_t layer, Short_t firedChips) { fFiredChips[layer] = firedChips; }
116
117   UInt_t GetNumberOfITSClusters(Int_t layer) const { return layer<6 ? fITSClusters[layer] : 0; }
118   UInt_t GetNumberOfITSClusters(Int_t layMin, Int_t layMax) const ;
119   void SetITSClusters(Int_t layer, UInt_t clusters) { fITSClusters[layer] = clusters; }
120
121   void   SetFastOrFiredChips(UInt_t chipKey){fFastOrFiredChips.SetBitNumber(chipKey);}
122   const TBits & GetFastOrFiredChips() const {return fFastOrFiredChips;}
123   Bool_t TestFastOrFiredChips(UInt_t chipKey) const {return fFastOrFiredChips.TestBitNumber(chipKey);}
124
125   void   SetFiredChipMap(TBits & firedChips){fClusterFiredChips = firedChips;}
126   void   SetFiredChipMap(UInt_t chipKey){fClusterFiredChips.SetBitNumber(chipKey);}
127   const TBits & GetFiredChipMap() const {return fClusterFiredChips;}
128   Bool_t TestFiredChipMap(UInt_t chipKey) const {return fClusterFiredChips.TestBitNumber(chipKey);}
129
130   Bool_t GetTrackletTrackIDs(Int_t i, Int_t mode, Int_t &spd1, Int_t &spd2) const;
131   Int_t  GetTrackletTrackIDsLay(Int_t lr,Int_t i, Int_t mode, UInt_t* refs, UInt_t maxRef) const;
132   Bool_t GetSingleClusterTrackID(Int_t i, Int_t mode, Int_t &tr) const;
133   Int_t  GetSingleClusterTrackIDs(Int_t i, Int_t mode, UInt_t* refs, UInt_t maxRef) const;
134
135   // array getters
136   Double_t* GetDeltTheta()   const {return (Double_t*)fDeltTh;}
137   Double_t* GetThetaSingle() const {return (Double_t*)fThsingle;}
138   Double_t* GetPhiSingle()   const {return (Double_t*)fPhisingle;}
139   Int_t*    GetLabelsSingle()      const {return (Int_t*)fLabelssingle;} 
140
141   void AttachTracklet2TrackRefs(AliRefArray* l1t1,AliRefArray* l1t2,AliRefArray* l2t1,AliRefArray* l2t2) {
142     fTCl2Tracks[0][0] = l1t1; fTCl2Tracks[0][1] = l1t2; fTCl2Tracks[1][0] = l2t1; fTCl2Tracks[1][1] = l2t2; 
143   }
144   void AttachCluster2TrackRefs(AliRefArray* l1t1,AliRefArray* l1t2) {
145     fSCl2Tracks[0] = l1t1; fSCl2Tracks[1] = l1t2;
146   }
147   void SetTrackletData(Int_t id, const Float_t* tlet, UInt_t trSPD1=0, UInt_t trSPD2=0);
148   void SetSingleClusterData(Int_t id, const Float_t* scl,UInt_t tr=0);
149   void CompactBits();
150   //
151   void    SetDPhiWindow2(Float_t v=-1)            {fDPhiWindow2 = v;}
152   void    SetDThetaWindow2(Float_t v=-1)          {fDThetaWindow2 = v;}
153   void    SetDPhiShift(Float_t v=-1)              {fDPhiShift = v;}
154   void    SetNStdDev(Float_t v=1)                 {fNStdDev = v;}
155   //
156   Float_t GetDPhiWindow2()                  const {return fDPhiWindow2;}
157   Float_t GetDThetaWindow2()                const {return fDThetaWindow2;}
158   Float_t GetDPhiShift()                    const {return fDPhiShift;}
159   Float_t GetNStdDev()                      const {return fNStdDev;}
160
161   //
162   protected:
163   void Duplicate(const AliMultiplicity &m);  // used by copy ctr.
164
165   Int_t fNtracks;            // Number of tracklets
166   Int_t fNsingle;            // Number of clusters on SPD layer 1 and 2 (if storage of spd2 singles requested), not associated with a tracklet on otherSPD 
167   Int_t fNsingleSPD2;        // Number of clusters on SPD layer 2 not associated (if stored)
168   //
169   Float_t fDPhiWindow2;      // sigma^2 in dphi used in reco
170   Float_t fDThetaWindow2;    // sigma^2 in dtheta used in reco
171   Float_t fDPhiShift;        // bending shift used
172   Float_t fNStdDev;          // number of standard deviations kept
173   //
174   Int_t *fLabels;            //[fNtracks] array with labels of cluster in L1 used for tracklet
175   Int_t *fLabelsL2;          //[fNtracks] array with labels of cluster in L2 used for tracklet
176   UInt_t* fUsedClusS;        //[fNsingle] id+1 of the tracks using cluster, coded as (TPC/ITS+ITS_SA)+(ITS_SA_PURE<<16) !!! Outphased for multiple refs
177   ULong64_t* fUsedClusT;     //[fNtracks] id+1 of the tracks using clusters, coded as (TPC/ITS+ITS_SA)+(ITS_SA_PURE<<16) for SPD1 and SPD2 in low and high parts
178   AliRefArray *fTCl2Tracks[2][2]; // container with multiple tracklet_cluster->track references
179   AliRefArray *fSCl2Tracks[2];    // container with multiple single_cluster->track references
180   Double32_t *fTh;           //[fNtracks] array with theta values
181   Double32_t *fPhi;          //[fNtracks] array with phi values
182   Double32_t *fDeltTh;       //[fNtracks] array with delta theta values
183   Double32_t *fDeltPhi;      //[fNtracks] array with delta phi values
184   Double32_t *fThsingle;     //[fNsingle] array with theta values of L1 clusters
185   Double32_t *fPhisingle;    //[fNsingle] array with phi values of L1 clusters
186   Int_t *fLabelssingle;      //[fNsingle] array with labels of clusters in L1 not used for tracklets 
187   Short_t fFiredChips[2];    // Number of fired chips in the two SPD layers
188   UInt_t fITSClusters[6];    // Number of ITS cluster per layer
189   TBits fFastOrFiredChips;   // Map of FastOr fired chips
190   TBits fClusterFiredChips;  // Map of fired chips (= at least one cluster)
191
192   ClassDef(AliMultiplicity,20);
193 };
194
195 inline Int_t AliMultiplicity::GetLabel(Int_t i, Int_t layer) const
196 {
197     if(i>=0 && i<fNtracks) {
198         if (layer == 0) {
199             return fLabels[i];
200         } else if (layer == 1) {
201             if (fLabelsL2) {
202                 return fLabelsL2[i];
203             } else {
204                 Warning("GetLabel", "No information for layer 2 available !");
205                 return -9999;
206             }
207         } else {
208             Error("GetLabel","Invalid layer number %d",layer); return -9999;
209         }
210     } else {
211         Error("GetLabel","Invalid track number %d",i); return -9999;
212     }
213     return -9999;
214 }
215
216 inline Int_t AliMultiplicity::GetLabelSingle(Int_t i) const 
217 {
218     if(i>=0 && i<fNsingle) {
219       return fLabelssingle[i];
220     } else {
221         Error("GetLabelSingle","Invalid cluster number %d",i); return -9999;
222     }
223     return -9999;
224 }
225
226
227 inline Double_t AliMultiplicity::CalcDist(Int_t i) const
228 {
229   // calculate eliptical distance. theta is the angle of cl1, dtheta = tht(cl1)-tht(cl2)
230   if (i<0 && i>=fNtracks) return -1;
231   if (fDPhiWindow2<1E-9 || fDThetaWindow2<1E-9) return -1; // not stored
232   double dphi   = TMath::Abs(fDeltPhi[i]) - fDPhiShift;
233   double dtheta = fDeltTh[i];
234   if (GetScaleDThetaBySin2T()) {
235     double sinTI = TMath::Sin(fTh[i]-dtheta/2);
236     sinTI *= sinTI;
237     dtheta /= sinTI>1.e-6 ? sinTI : 1.e-6;
238   }
239   return dphi*dphi/fDPhiWindow2 + dtheta*dtheta/fDThetaWindow2;
240 }
241
242 inline Int_t AliMultiplicity::GetNumberOfSingleClustersLr(Int_t lr) const
243 {
244   // return number of singles at given layer
245   if (lr==0) return fNsingle - fNsingleSPD2;
246   return AreSPD2SinglesStored() ? fNsingleSPD2 : -1;
247 }
248
249
250
251 #endif