Line data Source code
1 : #ifndef ALITPCCHEBCORR_H
2 : #define ALITPCCHEBCORR_H
3 :
4 :
5 : /*****************************************************************************
6 : * Wrapper for 2D->ND Chebishev parameterizations in TPC volume *
7 : * *
8 : * Creation requires *
9 : * 1) Optional number of patches in Z direction and Z limits *
10 : * 2) Optional number of patches per sector *
11 : * Once the constructor is called and optional parameters are set, use *
12 : * Parameterize(stFun_t fun,int dimOut,const int np[2],const float* prec) *
13 : * or *
14 : * Parameterize(stFun_t fun,int dimOut,const int np[][2],const float* prec) *
15 : * methods, where *
16 : * 1) fun: user function with signature *
17 : * void (*fun)(int row, float* tz,float* valND) *
18 : * where row is 0-158, tz is x2y within the sector corrdinates and *
19 : * valND is returned ND-dim. array of values to parameterize. *
20 : * The function should memorize internally selected sector when called as *
21 : * fun(sector,0,0) *
22 : * 2) dimOut: dimensionality of the output *
23 : * 3) np: number of training points to use in each input dimension, *
24 : * common for all output dimensions (np[2]) or for unique *
25 : * for each output dimension (np[dimOut][2]) *
26 : * 4) optional array prec[dimOut] with requested absolute tolerances *
27 : * *
28 : * Author: ruben.shahoyan@cern.ch *
29 : *****************************************************************************/
30 :
31 : #include <TNamed.h>
32 : #include <time.h>
33 : #include "AliCheb2DStack.h"
34 : #include "AliLog.h"
35 : class TGraph;
36 : class TH1F;
37 : class TBits;
38 :
39 : class AliTPCChebCorr : public TNamed
40 : {
41 : public:
42 : enum {kFieldAny, kFieldPos, kFieldNeg, kFieldZero};
43 : enum {kNSectors=18,kNSectorsIROC=2*kNSectors,kNRows=159,kNRowsIROC=63,kMaxIROCSector=kNSectorsIROC-1};
44 : enum {kParamDone=BIT(14) // parameterization done
45 : ,kUseParF=BIT(15) // if ON - internal FLOAT representation, otherwise - SHORT
46 : ,kUseZ2R=BIT(16) // 2nd dimension parameterizes Z/R
47 : ,kTimeDependent=BIT(17) // flag to signal time-dependent objects to follow
48 : ,kFirst=BIT(18) // first map in the array (marked on fly)
49 : ,kLast=BIT(19) // last map in the array (marked on fly)
50 : };
51 : //
52 : public:
53 : //
54 : AliTPCChebCorr();
55 : AliTPCChebCorr(const char* name, const char* title, int nps=1,int nzs=1, float zmaxAbs=250, float deadZone=1.5, const float *xi=0);
56 : virtual ~AliTPCChebCorr();
57 0 : Int_t GetFieldType() const {return fFieldType;}
58 0 : void SetFieldType(Char_t t=kFieldAny) {fFieldType = t;}
59 : void Parameterize(stFun_t fun,int dimOut,const int np[2], const float *prec=0);
60 : void Parameterize(stFun_t fun,int dimOut,const int np[][2], const float *prec=0);
61 : void SetBinning(int nps=1,int nzs=1, float zmxAbs=250);
62 0 : Bool_t GetUseFloatPrec() const {return TestBit(kUseParF);}
63 0 : Bool_t GetUseShortPrec() const {return !TestBit(kUseParF);}
64 0 : Bool_t SetUseFloatPrec(Bool_t v) {SetBit(kUseParF,v); return v;}
65 0 : Bool_t GetUseZ2R() const {return TestBit(kUseZ2R);}
66 0 : void SetUseZ2R(Bool_t v=kTRUE) {SetBit(kUseZ2R,v);}
67 0 : Bool_t GetTimeDependent() const {return TestBit(kTimeDependent);}
68 0 : void SetTimeDependent(Bool_t v=kTRUE) {SetBit(kTimeDependent,v);}
69 0 : Bool_t IsFirst() const {return TestBit(kFirst);}
70 0 : void SetFirst(Bool_t v=kTRUE) {SetBit(kFirst,v);}
71 0 : Bool_t IsLast() const {return TestBit(kLast);}
72 0 : void SetLast(Bool_t v=kTRUE) {SetBit(kLast,v);}
73 :
74 0 : Float_t GetZMin() const {return -fZMaxAbs;}
75 0 : Float_t GetZMax() const {return fZMaxAbs;}
76 0 : Int_t GetNStacksZ() const {return fNStacksZ;}
77 0 : Int_t GetNStacksSector() const {return fNStacksSect;}
78 0 : Int_t GetNRows() const {return fNRows;}
79 0 : Float_t GetDeadZone() const {return fDeadZone;}
80 : //
81 : const AliCheb2DStack* GetParam(int id) const;
82 : const AliCheb2DStack* GetParam(int sector, float y2x, float z) const;
83 : //
84 0 : time_t GetTimeStampStart() const {return fTimeStampStart;}
85 0 : time_t GetTimeStampEnd() const {return fTimeStampEnd;}
86 0 : time_t GetTimeStampCenter() const {return (fTimeStampStart+fTimeStampEnd)/2;}
87 0 : void SetTimeStampStart(time_t t=0) {fTimeStampStart = t;}
88 0 : void SetTimeStampEnd(time_t t=0xffffffff) {fTimeStampEnd = t;}
89 : //
90 : void Print(const Option_t* opt="") const;
91 : void Eval(int sector, int row, float y2x, float z,float *corr) const;
92 : void Eval(int sector, int row, float tz[2], float *corr) const;
93 : Float_t Eval(int sector, int row, float y2x, float z, int dimOut) const;
94 : Float_t Eval(int sector, int row, float tz[2], int dimOut) const;
95 : Bool_t IsRowMasked(int sector72,int row) const;
96 : Int_t GetNMaskedRows(int sector72, TBits* masked=0) const;
97 : void Init();
98 : Int_t GetDimOut() const;
99 0 : static float GetMaxY2X() {return fgkY2XHSpan;}
100 0 : static const float* GetPadRowX() {return fgkPadRowX;}
101 : //
102 0 : TH1F* GetTracksRate() const {return fTracksRate;}
103 0 : void SetTracksRate(TH1F* hrate) {fTracksRate = hrate;}
104 : Double_t GetLuminosityCOG(TGraph* lumi, time_t tmin=-1, time_t tmax=-1) const;
105 : //
106 : Int_t GetRun() const;
107 0 : void SetRun(int run) {fRun = run;}
108 0 : virtual Bool_t IsCorrection() const {return kTRUE;}
109 0 : virtual Bool_t IsDistortion() const {return kFALSE;}
110 : //
111 : protected:
112 : //
113 0 : int GetParID(int iz,int isect,int istack) const {return (iz*kNSectors+isect)*fNStacksSect+istack;}
114 : //
115 : protected:
116 : Bool_t fOnFlyInitDone; //! flag that on-the-fly init was done
117 : Char_t fFieldType; // info about the field type
118 : Int_t fRun; // run number used extract this map
119 : Int_t fNRows; // number of slices along the radius (e.g. rows)
120 : Int_t fNStacksSect; // number of stacks per sector in phi
121 : Int_t fNStacksZSect; // number of stacks per sector (side) in Z
122 : Int_t fNStacksZ; // number of stacks in Z
123 : Int_t fNStacks; // total number of stacks
124 : Float_t fZMaxAbs; // zmax abs
125 : //
126 : time_t fTimeStampStart; // time stamp for start of validity
127 : time_t fTimeStampEnd; // time stamp for end of validity
128 : //
129 : // precalculated parameters
130 : Float_t fZScaleI; // 1/Zspan of single stack
131 : Float_t fY2XScaleI; // 1/Y2Xspan of single stack
132 : //
133 : Float_t fDeadZone; // dead zone in cm
134 : Float_t* fRowXI; //[fNRows] // 1/X of each row is dead zone to be used
135 : //
136 : AliCheb2DStack** fParams; //[fNStacks] set of AliCheb2DStack parameterizations
137 : //
138 : TH1F* fTracksRate; // used tracks rate
139 : //
140 : static const float fgkY2XHSpan; // half span of sector
141 : static const float fgkPadRowX[]; // nominal rows
142 : static const char* fgkFieldTypeName[]; // names of field types
143 : protected:
144 : //
145 : AliTPCChebCorr(const AliTPCChebCorr& src); // dummy
146 : AliTPCChebCorr& operator=(const AliTPCChebCorr& rhs); // dummy
147 : //
148 24 : ClassDef(AliTPCChebCorr,8)
149 : };
150 :
151 : //_________________________________________________________________
152 : inline const AliCheb2DStack* AliTPCChebCorr::GetParam(int id) const
153 : {
154 0 : if (!fParams) return 0;
155 0 : if (!fOnFlyInitDone) AliError("Attention: evalulation may be wrong: the object need to be initialized by Init()");
156 0 : return (const AliCheb2DStack*) fParams[id];
157 0 : }
158 :
159 : //_________________________________________________________________
160 : inline const AliCheb2DStack* AliTPCChebCorr::GetParam(int sector, float y2x, float z) const
161 : {
162 : // Find appropriate param. Sector is in ROC0-71 conventions
163 0 : int iz = (z+fZMaxAbs)*fZScaleI, side = (sector/kNSectors)&0x1;
164 : // correct for eventual Z calculated in wrong ROC
165 0 : if (side) {if (iz>=fNStacksZSect) iz = fNStacksZSect-1;} // C side
166 0 : else {if (iz<fNStacksZSect) iz = fNStacksZSect;} // A side
167 0 : if (iz<0) iz=0; else if (iz>=fNStacksZ) iz=fNStacksZ-1;
168 0 : int is = (y2x+fgkY2XHSpan)*fY2XScaleI;
169 0 : if (is<0) is=0; else if (is>=fNStacksSect) is=fNStacksSect-1;
170 0 : return GetParam(GetParID(iz,sector%kNSectors,is));
171 : //
172 : }
173 :
174 : //____________________________________________________________________
175 : inline void AliTPCChebCorr::Eval(int sector, int row, float y2x, float z, float *corr) const
176 : {
177 : // Calculate correction for point with x,y,z sector corrdinates
178 : // Sector/row is in 0-71 ROC convention, to check Zs outlying from the sector
179 0 : if (sector>kMaxIROCSector) row += kNRowsIROC; // we are in OROC
180 0 : float tz[2] = {y2x,z}; // params use row, Y/X, Z
181 0 : const AliCheb2DStack* par = GetParam(sector,y2x,z);
182 0 : if (par) par->Eval(row, tz, corr);
183 : //
184 0 : }
185 :
186 : //____________________________________________________________________
187 : inline void AliTPCChebCorr::Eval(int sector, int row, float tz[2], float *corr) const
188 : {
189 : // Calculate correction for point with x,y,z sector corrdinates
190 : // Sector is in 0-71 ROC convention, to check Zs outlying from the sector
191 0 : if (sector>kMaxIROCSector) row += kNRowsIROC; // we are in OROC
192 0 : const AliCheb2DStack* par = GetParam(sector,tz[0],tz[1]);
193 0 : if (par) par->Eval(row, tz, corr);
194 : //
195 0 : }
196 :
197 : //____________________________________________________________________
198 : inline Float_t AliTPCChebCorr::Eval(int sector, int row, float y2x, float z, int dimOut) const
199 : {
200 : // Calculate dimOut-th correction for point with x,y,z sector corrdinates
201 : // Sector/row is in 0-71 ROC convention, to check Zs outlying from the sector
202 0 : if (sector>kMaxIROCSector) row += kNRowsIROC; // we are in OROC
203 0 : float tz[2] = {y2x,z}; // params use row, Y/X, Z
204 0 : const AliCheb2DStack* par = GetParam(sector,y2x,z);
205 0 : return par ? par->Eval(row, dimOut, tz) : 0;
206 : //
207 0 : }
208 :
209 : //____________________________________________________________________
210 : inline Float_t AliTPCChebCorr::Eval(int sector, int row, float tz[2], int dimOut) const
211 : {
212 : // Calculate correction for point with x,y,z sector corrdinates
213 : // Sector is in 0-71 ROC convention, to check Zs outlying from the sector
214 0 : if (sector>kMaxIROCSector) row += kNRowsIROC; // we are in OROC
215 0 : const AliCheb2DStack* par = GetParam(sector,tz[0],tz[1]);
216 0 : return par ? par->Eval(row, dimOut, tz) : 0;
217 : //
218 : }
219 :
220 :
221 : #endif
|