]>
Commit | Line | Data |
---|---|---|
94685752 | 1 | /* |
2 | ||
3 | Class AliTPCtransformation: | |
4 | Should represent general non linear transformation. Currently tune for TPConly. | |
5 | To be used: | |
6 | 1. Simulation-Digitization | |
7 | 2. Reconstruction - AliTPCTransform | |
8 | 3. Calibration/Alignment (KalmanFilter, Milipedde) | |
9 | 4. Set of transformation to be stored/retrieved as OCDB entry | |
10 | ||
11 | Base functionality: | |
12 | ||
13 | 1. Double_t GetDeltaXYZ(Int_t coord, Int_t volID, Double_t param, Double_t x, Double_t y, Double_t z) | |
14 | Get correction - return the delta of coordinate coord dx or dy or dz for given volID for point at point (x,y,z) | |
15 | All coordinates are global | |
16 | ||
17 | 2. The transformation should work only for given volIDs and detector IDs | |
18 | Currently Bitmask is used for filtering | |
19 | ||
20 | ||
21 | ||
22 | */ | |
23 | ||
24 | #include <string.h> | |
25 | #include "TRandom.h" | |
26 | #include "TMath.h" | |
27 | #include "TBits.h" | |
28 | #include "TFormula.h" | |
29 | #include "TF1.h" | |
30 | #include "TLinearFitter.h" | |
31 | #include "TFile.h" | |
32 | #include "TObjString.h" | |
33 | ||
34 | #include "TTreeStream.h" | |
35 | #include "AliTrackPointArray.h" | |
36 | #include "AliLog.h" | |
37 | #include "AliTPCTransformation.h" | |
38 | ||
39 | ClassImp(AliTPCTransformation) | |
40 | ||
41 | ||
42 | AliTPCTransformation::GenFuncG AliTPCTransformation::fgFormulas[10000]; | |
43 | TObjArray* AliTPCTransformation::fgFormulasName = new TObjArray(10000); | |
44 | ||
45 | ||
46 | void AliTPCTransformation::RegisterFormula(const char * name, GenFuncG formula){ | |
47 | // | |
48 | // Add Formula to the list of formulas | |
49 | // | |
50 | Int_t last= fgFormulasName->GetEntries(); | |
51 | fgFormulasName->AddLast(new TObjString(name)); | |
52 | fgFormulas[last]=formula; | |
53 | } | |
54 | ||
55 | Int_t AliTPCTransformation::BuildBasicFormulas(){ | |
56 | // | |
57 | //build list of basic formulas | |
58 | // | |
59 | RegisterFormula("TPCscalingRPol",(GenFuncG)(AliTPCTransformation::TPCscalingRPol)); | |
60 | RegisterFormula("TPCscalingZDr",(GenFuncG)(AliTPCTransformation::TPCscalingZDr)); | |
61 | RegisterFormula("TPCscalingPhiLocal",(GenFuncG)(AliTPCTransformation::TPCscalingPhiLocal)); | |
62 | return 0; | |
63 | } | |
64 | ||
65 | AliTPCTransformation::GenFuncG AliTPCTransformation::FindFormula(const char * name){ | |
66 | // | |
67 | // find formula - if registered | |
68 | // | |
69 | if (fgFormulasName->FindObject(name)==0) return 0; | |
70 | Int_t entries = fgFormulasName->GetEntries(); | |
71 | for (Int_t i=0;i<entries;i++){ | |
72 | if (strcmp(fgFormulasName->At(i)->GetName(), name)==0){ | |
73 | return fgFormulas[i]; | |
74 | } | |
75 | } | |
76 | return 0; | |
77 | } | |
78 | ||
79 | Double_t AliTPCTransformation::Eval(const char * name, const Double_t*x,const Double_t*par){ | |
80 | // | |
81 | // Only for test purposes - very slow | |
82 | // | |
83 | GenFuncG fun = FindFormula(name); | |
84 | if (!fun) return 0; | |
85 | return fun(x,par); | |
86 | } | |
87 | ||
88 | ||
89 | AliTPCTransformation::AliTPCTransformation(): | |
90 | TNamed(), | |
91 | fNameX(0), // x formula name | |
92 | fNameY(0), // y formula name | |
93 | fNameZ(0), // z formula name | |
94 | // | |
95 | fBitMask(0), // bitmaps - transformation only for specified volID | |
96 | fCoordSystem(0), // coord system of output deltas | |
97 | fParam(0), // free parameter of transformation | |
98 | fSigma(0), // uncertainty of the parameter | |
99 | fFixedParam(0), // fixed parameters of tranformation | |
100 | // | |
101 | fInit(kFALSE), // initialization flag - set to kTRUE if corresponding formulas found | |
102 | fFormulaX(0), // x formula - pointer to the function | |
103 | fFormulaY(0), // y formula - pointer to the function | |
104 | fFormulaZ(0) // z formula - pointer to the function | |
105 | // | |
106 | { | |
107 | // | |
108 | // default constructor | |
109 | // | |
110 | } | |
111 | ||
112 | ||
113 | ||
114 | AliTPCTransformation::AliTPCTransformation(const char *name, TBits *mask, const char *fx, const char *fy, const char *fz, Int_t coordSystem,Double_t param, Double_t sigma, TVectorD *fixedParams): | |
115 | TNamed(name,name), | |
116 | fNameX(0), // x formula name | |
117 | fNameY(0), // y formula name | |
118 | fNameZ(0), // z formula name | |
119 | fBitMask(mask), // bitmaps - transformation only for specified volID | |
120 | fCoordSystem(coordSystem), // coordinate system of output deltas | |
121 | fParam(param), // free parameter of transformation | |
122 | fSigma(sigma), | |
123 | fFixedParam(0), // fixed parameters of tranformation | |
124 | // | |
125 | fInit(kFALSE), // initialization flag - set to kTRUE if corresponding formulas found | |
126 | fFormulaX(0), // x formula - pointer to the function | |
127 | fFormulaY(0), // y formula - pointer to the function | |
128 | fFormulaZ(0) // z formula - pointer to the function | |
129 | { | |
130 | // | |
131 | // non default constructor | |
132 | // | |
133 | if (fx) fNameX= new TString(fx); | |
134 | if (fy) fNameY= new TString(fy); | |
135 | if (fz) fNameZ= new TString(fz); | |
136 | if (fixedParams) fFixedParam = new TVectorD(*fixedParams); | |
137 | if (!fFixedParam) fFixedParam = new TVectorD(1); | |
138 | Init(); | |
139 | } | |
140 | ||
141 | ||
142 | ||
143 | Bool_t AliTPCTransformation::Init(){ | |
144 | // | |
145 | // associate formulas with pointer to the function | |
146 | // | |
147 | Bool_t isOK=kTRUE; | |
148 | if (fNameX) { | |
149 | fFormulaX=FindFormula(fNameX->Data()); | |
150 | if (fFormulaX==0) isOK=kFALSE; | |
151 | } | |
152 | if (fNameY) { | |
153 | fFormulaY=FindFormula(fNameY->Data()); | |
154 | if (fFormulaY==0) isOK=kFALSE; | |
155 | } | |
156 | if (fNameZ) { | |
157 | fFormulaZ=FindFormula(fNameZ->Data()); | |
158 | if (!fFormulaZ) isOK=kFALSE; | |
159 | } | |
160 | return isOK; | |
161 | } | |
162 | ||
163 | TBits * AliTPCTransformation::BitsSide(Bool_t aside){ | |
164 | // | |
165 | TBits * bits = new TBits(72); | |
166 | for (Int_t i=0; i<72;i++){ | |
167 | if (i%36<18 && aside) (*bits)[i]=kTRUE; | |
168 | if (i%36<18 && (!aside)) (*bits)[i]=kFALSE; | |
169 | if (i%36>=18 && aside) (*bits)[i]=kFALSE; | |
170 | if (i%36>=18 && (!aside)) (*bits)[i]=kTRUE; | |
171 | } | |
172 | return bits; | |
173 | } | |
174 | ||
175 | TBits * AliTPCTransformation::BitsAll(){ | |
176 | // | |
177 | // | |
178 | // | |
179 | TBits * bits = new TBits(72); | |
180 | for (Int_t i=0; i<72;i++){ | |
181 | (*bits)[i]=kTRUE; | |
182 | } | |
183 | return bits; | |
184 | } | |
185 | ||
186 | Double_t AliTPCTransformation::GetDeltaXYZ(Int_t coord, Int_t volID, Double_t param, Double_t x, Double_t y, Double_t z){ | |
187 | // | |
188 | // | |
189 | // | |
190 | if (fBitMask && (!(*fBitMask)[volID])) return 0; | |
191 | Double_t xyz[4]={x,y,z, param}; | |
192 | if (fCoordSystem==0){ | |
193 | // cartezian system | |
194 | if (coord==0 && fFormulaX) return fFormulaX(xyz,fFixedParam->GetMatrixArray()); | |
195 | if (coord==1 && fFormulaY) return fFormulaY(xyz,fFixedParam->GetMatrixArray()); | |
196 | if (coord==2 && fFormulaY) return fFormulaY(xyz,fFixedParam->GetMatrixArray()); | |
197 | } | |
198 | if (fCoordSystem==1){ | |
199 | // cylindrical system | |
200 | if (coord==2) { | |
201 | if (fFormulaZ==0) return 0; | |
202 | return fFormulaZ(xyz,fFixedParam->GetMatrixArray()); | |
203 | } | |
204 | Double_t rrphiz[3]={0,0,0}; | |
205 | if (fFormulaX) rrphiz[0] = fFormulaX(xyz,fFixedParam->GetMatrixArray()); | |
206 | if (fFormulaY) rrphiz[1] = fFormulaY(xyz,fFixedParam->GetMatrixArray()); | |
207 | Double_t alpha = TMath::ATan2(y,x); | |
208 | Double_t ca = TMath::Cos(alpha); | |
209 | Double_t sa = TMath::Sin(alpha); | |
210 | if (coord==0) return ca*rrphiz[0]-sa*rrphiz[1]; | |
211 | if (coord==1) return sa*rrphiz[0]+ca*rrphiz[1]; | |
212 | } | |
213 | return 0; | |
214 | } | |
215 | ||
216 | Double_t AliTPCTransformation::TPCscalingRPol(Double_t *xyz, Double_t * param){ | |
217 | // | |
218 | // Scaling and shift of TPC radius | |
219 | // xyz[0..2] - global xyz of point | |
220 | // xyz[3] - scale parameter | |
221 | Double_t radius = 0.5 - TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1])/250.; | |
222 | Double_t driftM = 0.5 - TMath::Abs(xyz[2]/250.); | |
223 | Double_t deltaR = TMath::Power(radius,param[0])*TMath::Power(driftM,param[1]); | |
224 | return deltaR*xyz[3]; | |
225 | } | |
226 | ||
227 | ||
228 | Double_t AliTPCTransformation::TPCscalingZDr(Double_t *xyz, Double_t * param){ | |
229 | // | |
230 | // | |
231 | // Scaling and shift of TPC radius | |
232 | // xyz[0..2] - global xyz of point | |
233 | // xyz[3] - scale parameter | |
234 | Double_t driftP = TMath::Power(1. - TMath::Abs(xyz[2]/250.), param[0]); | |
235 | Double_t deltaZ = (xyz[2]>0) ? -driftP : driftP; | |
236 | return deltaZ*xyz[3]; | |
237 | } | |
238 | ||
239 | Double_t AliTPCTransformation::TPCscalingPhiLocal(Double_t *xyz, Double_t * param){ | |
240 | // | |
241 | // | |
242 | // Scaling if the local y -phi | |
243 | // xyz[0..2] - global xyz of point | |
244 | // xyz[3] - scale parameter | |
245 | Double_t alpha = TMath::ATan2(xyz[1],xyz[0]); | |
246 | Double_t sector = TMath::Nint(9*alpha/TMath::Pi()-0.5); | |
247 | Double_t localAlpha = (alpha-(sector+0.5)*TMath::Pi()/9.); | |
248 | Double_t radius = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1])/250.; | |
249 | Double_t deltaAlpha = TMath::Power(9*localAlpha*radius/TMath::Pi(),param[0]); | |
250 | return deltaAlpha*xyz[3]; | |
251 | } | |
252 | ||
253 |