]>
Commit | Line | Data |
---|---|---|
0eea9d4d | 1 | /////////////////////////////////////////////////////////////////////////////////// |
2 | // // | |
3 | // Wrapper for the set of mag.field parameterizations by Chebyshev polinomials // | |
4 | // To obtain the field in cartesian coordinates/components use // | |
5 | // Field(float* xyz, float* bxyz); // | |
6 | // For cylindrical coordinates/components: // | |
7 | // FieldCyl(float* rphiz, float* brphiz) // | |
8 | // // | |
d28e407c | 9 | // The solenoid part is parameterized in the volume R<500, -550<Z<550 cm // |
0eea9d4d | 10 | // // |
11 | // The region R<423 cm, -343.3<Z<481.3 for 30kA and -343.3<Z<481.3 for 12kA // | |
12 | // is parameterized using measured data while outside the Tosca calculation // | |
13 | // is used (matched to data on the boundary of the measurements) // | |
14 | // // | |
d28e407c | 15 | // Two options are possible: // |
16 | // 1) _BRING_TO_BOUNDARY_ is defined in the AliCheb3D: // | |
17 | // If the querried point is outside of the validity region then the field // | |
18 | // at the closest point on the fitted surface is returned. // | |
19 | // 2) _BRING_TO_BOUNDARY_ is not defined in the AliCheb3D: // | |
20 | // If the querried point is outside of the validity region the return // | |
21 | // value for the field components are set to 0. // | |
22 | // // | |
23 | // To obtain the field integral in the TPC region from given point to nearest // | |
24 | // cathod plane (+- 250 cm) use: // | |
25 | // GetTPCInt(float* xyz, float* bxyz); for Cartesian frame // | |
26 | // or // | |
27 | // GetTPCIntCyl(Float_t *rphiz, Float_t *b); for Cylindrical frame // | |
28 | // // | |
29 | // // | |
30 | // The units are kiloGauss and cm. // | |
0eea9d4d | 31 | // // |
32 | /////////////////////////////////////////////////////////////////////////////////// | |
33 | ||
34 | #include "AliMagFCheb.h" | |
35 | ||
36 | ClassImp(AliMagFCheb) | |
37 | ||
0eea9d4d | 38 | //__________________________________________________________________________________________ |
d28e407c | 39 | AliMagFCheb::AliMagFCheb() : |
40 | fNParamsSol(0), | |
41 | fNSegZSol(0), | |
42 | fNParamsTPCInt(0), | |
43 | fNSegZTPCInt(0), | |
44 | fNParamsDip(0), | |
45 | // | |
46 | fNZSegDip(0), | |
47 | fNYSegDip(0), | |
48 | fNXSegDip(0), | |
49 | // | |
50 | fSegZSol(0), | |
51 | fSegRSol(0), | |
52 | // | |
53 | fSegZTPCInt(0), | |
54 | fSegRTPCInt(0), | |
55 | // | |
56 | fSegZDip(0), | |
57 | fSegYDip(0), | |
58 | fSegXDip(0), | |
59 | // | |
60 | fNSegRSol(0), | |
61 | fSegZIdSol(0), | |
62 | // | |
63 | fNSegRTPCInt(0), | |
64 | fSegZIdTPCInt(0), | |
65 | // | |
66 | fBegSegYDip(0), | |
67 | fNSegYDip(0), | |
68 | fBegSegXDip(0), | |
69 | fNSegXDip(0), | |
70 | fSegIDDip(0), | |
71 | // | |
72 | fMinZSol(1e6), | |
73 | fMaxZSol(-1e6), | |
74 | fMaxRSol(-1e6), | |
75 | // | |
76 | fMinZDip(1e6), | |
77 | fMaxZDip(-1e6), | |
78 | // | |
79 | fMinZTPCInt(1e6), | |
80 | fMaxZTPCInt(-1e6), | |
81 | fMaxRTPCInt(-1e6), | |
82 | // | |
83 | fParamsSol(0), | |
84 | fParamsDip(0), | |
85 | fParamsTPCInt(0) | |
86 | // | |
87 | {} | |
0bc7b414 | 88 | |
d28e407c | 89 | //__________________________________________________________________________________________ |
90 | AliMagFCheb::AliMagFCheb(const AliMagFCheb& src) : | |
91 | TNamed(src), | |
92 | fNParamsSol(0), | |
93 | fNSegZSol(0), | |
94 | fNParamsTPCInt(0), | |
95 | fNSegZTPCInt(0), | |
96 | fNParamsDip(0), | |
97 | // | |
98 | fNZSegDip(0), | |
99 | fNYSegDip(0), | |
100 | fNXSegDip(0), | |
101 | // | |
102 | fSegZSol(0), | |
103 | fSegRSol(0), | |
104 | // | |
105 | fSegZTPCInt(0), | |
106 | fSegRTPCInt(0), | |
107 | // | |
108 | fSegZDip(0), | |
109 | fSegYDip(0), | |
110 | fSegXDip(0), | |
111 | // | |
112 | fNSegRSol(0), | |
113 | fSegZIdSol(0), | |
114 | // | |
115 | fNSegRTPCInt(0), | |
116 | fSegZIdTPCInt(0), | |
117 | // | |
118 | fBegSegYDip(0), | |
119 | fNSegYDip(0), | |
120 | fBegSegXDip(0), | |
121 | fNSegXDip(0), | |
122 | fSegIDDip(0), | |
123 | // | |
124 | fMinZSol(1e6), | |
125 | fMaxZSol(-1e6), | |
126 | fMaxRSol(-1e6), | |
127 | // | |
128 | fMinZDip(1e6), | |
129 | fMaxZDip(-1e6), | |
130 | // | |
131 | fMinZTPCInt(1e6), | |
132 | fMaxZTPCInt(-1e6), | |
133 | fMaxRTPCInt(-1e6), | |
134 | // | |
135 | fParamsSol(0), | |
136 | fParamsDip(0), | |
137 | fParamsTPCInt(0) | |
0eea9d4d | 138 | { |
d28e407c | 139 | CopyFrom(src); |
140 | // | |
0eea9d4d | 141 | } |
142 | ||
c437b1a5 | 143 | //__________________________________________________________________________________________ |
d28e407c | 144 | void AliMagFCheb::CopyFrom(const AliMagFCheb& src) |
145 | { | |
146 | Clear(); | |
147 | SetName(src.GetName()); | |
148 | SetTitle(src.GetTitle()); | |
149 | fNParamsSol = src.fNParamsSol; | |
150 | fNSegZSol = src.fNSegZSol; | |
151 | fNParamsTPCInt = src.fNParamsTPCInt; | |
152 | fNSegZTPCInt = src.fNSegZTPCInt; | |
153 | fNParamsDip = src.fNParamsDip; | |
154 | // | |
155 | fNZSegDip = src.fNZSegDip; | |
156 | fNYSegDip = src.fNYSegDip; | |
157 | fNXSegDip = src.fNXSegDip; | |
158 | // | |
159 | fMinZSol = src.fMinZSol; | |
160 | fMaxZSol = src.fMaxZSol; | |
161 | fMaxRSol = src.fMaxRSol; | |
162 | // | |
163 | fMinZDip = src.fMinZDip; | |
164 | fMaxZDip = src.fMaxZDip; | |
165 | // | |
166 | fMinZTPCInt = src.fMinZTPCInt; | |
167 | fMaxZTPCInt = src.fMaxZTPCInt; | |
168 | fMaxRTPCInt = src.fMaxRTPCInt; | |
169 | // | |
170 | if (src.fNParamsSol) { | |
171 | memcpy(fSegZSol = new Float_t[fNSegZSol], src.fSegZSol, sizeof(Float_t)*fNSegZSol); | |
172 | memcpy(fSegRSol = new Float_t[fNParamsSol], src.fSegRSol, sizeof(Float_t)*fNParamsSol); | |
173 | memcpy(fNSegRSol = new Int_t[fNSegZSol], src.fNSegRSol, sizeof(Int_t)*fNSegZSol); | |
174 | memcpy(fSegZIdSol= new Int_t[fNSegZSol], src.fSegZIdSol, sizeof(Int_t)*fNSegZSol); | |
175 | fParamsSol = new TObjArray(fNParamsSol); | |
176 | for (int i=0;i<fNParamsSol;i++) fParamsSol->AddAtAndExpand(new AliCheb3D(*src.GetParamSol(i)),i); | |
c437b1a5 | 177 | } |
d28e407c | 178 | // |
179 | if (src.fNParamsDip) { | |
180 | memcpy(fSegZDip = new Float_t[fNZSegDip], src.fSegZDip, sizeof(Float_t)*fNZSegDip); | |
181 | memcpy(fSegYDip = new Float_t[fNYSegDip], src.fSegYDip, sizeof(Float_t)*fNYSegDip); | |
182 | memcpy(fSegXDip = new Float_t[fNXSegDip], src.fSegZDip, sizeof(Float_t)*fNXSegDip); | |
183 | memcpy(fBegSegYDip= new Int_t[fNZSegDip], src.fBegSegYDip, sizeof(Int_t)*fNZSegDip); | |
184 | memcpy(fNSegYDip = new Int_t[fNZSegDip], src.fNSegYDip, sizeof(Int_t)*fNZSegDip); | |
185 | memcpy(fBegSegXDip= new Int_t[fNYSegDip], src.fBegSegXDip, sizeof(Int_t)*fNYSegDip); | |
186 | memcpy(fNSegXDip = new Int_t[fNYSegDip], src.fNSegXDip, sizeof(Int_t)*fNYSegDip); | |
187 | memcpy(fSegIDDip = new Int_t[fNXSegDip], src.fSegIDDip, sizeof(Int_t)*fNXSegDip); | |
188 | fParamsDip = new TObjArray(fNParamsDip); | |
189 | for (int i=0;i<fNParamsDip;i++) fParamsDip->AddAtAndExpand(new AliCheb3D(*src.GetParamDip(i)),i); | |
c437b1a5 | 190 | } |
d28e407c | 191 | // |
192 | if (src.fNParamsTPCInt) { | |
193 | memcpy(fSegZTPCInt = new Float_t[fNSegZTPCInt], src.fSegZTPCInt, sizeof(Float_t)*fNSegZTPCInt); | |
194 | memcpy(fSegRTPCInt = new Float_t[fNParamsTPCInt], src.fSegRTPCInt, sizeof(Float_t)*fNParamsTPCInt); | |
195 | memcpy(fNSegRTPCInt = new Int_t[fNSegZTPCInt], src.fNSegRTPCInt, sizeof(Int_t)*fNSegZTPCInt); | |
196 | memcpy(fSegZIdTPCInt= new Int_t[fNSegZTPCInt], src.fSegZIdTPCInt, sizeof(Int_t)*fNSegZTPCInt); | |
197 | fParamsTPCInt = new TObjArray(fNParamsTPCInt); | |
198 | for (int i=0;i<fNParamsTPCInt;i++) fParamsTPCInt->AddAtAndExpand(new AliCheb3D(*src.GetParamTPCInt(i)),i); | |
c437b1a5 | 199 | } |
0bc7b414 | 200 | // |
0bc7b414 | 201 | } |
202 | ||
d28e407c | 203 | //__________________________________________________________________________________________ |
c437b1a5 | 204 | AliMagFCheb& AliMagFCheb::operator=(const AliMagFCheb& rhs) |
0bc7b414 | 205 | { |
d28e407c | 206 | if (this != &rhs) { |
207 | Clear(); | |
208 | CopyFrom(rhs); | |
209 | } | |
210 | return *this; | |
211 | // | |
0bc7b414 | 212 | } |
213 | ||
0eea9d4d | 214 | //__________________________________________________________________________________________ |
d28e407c | 215 | void AliMagFCheb::Clear(Option_t *) |
0eea9d4d | 216 | { |
217 | if (fNParamsSol) { | |
d28e407c | 218 | delete fParamsSol; |
0eea9d4d | 219 | delete[] fSegZSol; |
220 | delete[] fSegRSol; | |
221 | delete[] fNSegRSol; | |
222 | delete[] fSegZIdSol; | |
223 | } | |
224 | // | |
d28e407c | 225 | if (fNParamsTPCInt) { |
226 | delete fParamsTPCInt; | |
227 | delete[] fSegZTPCInt; | |
228 | delete[] fSegRTPCInt; | |
229 | delete[] fNSegRTPCInt; | |
230 | delete[] fSegZIdTPCInt; | |
231 | } | |
232 | // | |
0eea9d4d | 233 | if (fNParamsDip) { |
d28e407c | 234 | delete fParamsDip; |
235 | delete[] fSegZDip; | |
236 | delete[] fSegYDip; | |
237 | delete[] fSegXDip; | |
238 | delete[] fBegSegYDip; | |
239 | delete[] fNSegYDip; | |
240 | delete[] fBegSegXDip; | |
241 | delete[] fNSegXDip; | |
242 | delete[] fSegIDDip; | |
0eea9d4d | 243 | } |
d28e407c | 244 | fNParamsSol = fNParamsTPCInt = fNParamsDip = fNZSegDip = fNYSegDip = fNXSegDip = 0; |
245 | fNSegZSol = fNSegZTPCInt = 0; | |
246 | fMinZSol = fMinZDip = fMinZTPCInt = 1e6; | |
247 | fMaxZSol = fMaxZDip = fMaxZTPCInt = fMaxRSol = fMaxRTPCInt = -1e6; | |
248 | // | |
0eea9d4d | 249 | } |
250 | ||
251 | //__________________________________________________________________________________________ | |
d28e407c | 252 | void AliMagFCheb::Field(Float_t *xyz, Float_t *b) const |
0eea9d4d | 253 | { |
d28e407c | 254 | // compute field in cartesian coordinates. If point is outside of the parameterized region |
255 | // get it at closest valid point | |
256 | static float rphiz[3]; | |
257 | // | |
258 | #ifndef _BRING_TO_BOUNDARY_ // exact matching to fitted volume is requested | |
259 | if ( !(xyz[2]>=GetMinZSol()&&xyz[2]<=GetMaxZSol()) && | |
260 | !(xyz[2]>=GetMinZDip()&&xyz[2]<=GetMaxZDip()) ) {for (int i=3;i--;) b[i]=0; return;} | |
261 | #endif | |
262 | // | |
263 | if (xyz[2]<fMaxZDip) { // dipole part? | |
264 | #ifndef _BRING_TO_BOUNDARY_ | |
265 | AliCheb3D* par = GetParamDip(FindDipSegment(xyz)); | |
266 | if (par->IsInside(xyz)) {par->Eval(xyz,b); return;} | |
267 | for (int i=3;i--;) b[i]=0; return; | |
268 | #else | |
269 | GetParamDip(FindDipSegment(xyz))->Eval(xyz,b); return; | |
270 | #endif | |
271 | } | |
272 | // | |
273 | // Sol region: convert coordinates to cyl system | |
274 | CartToCyl(xyz,rphiz); | |
275 | #ifndef _BRING_TO_BOUNDARY_ | |
276 | if (rphiz[0]>GetMaxRSol()) {for (int i=3;i--;) b[i]=0; return;} | |
277 | #endif | |
278 | // | |
279 | FieldCylSol(rphiz,b); | |
280 | // | |
281 | // convert field to cartesian system | |
282 | CylToCartCylB(rphiz, b,b); | |
283 | // | |
284 | } | |
285 | ||
286 | //__________________________________________________________________________________________ | |
287 | void AliMagFCheb::GetTPCInt(Float_t *xyz, Float_t *b) const | |
288 | { | |
289 | // compute TPC region field integral in cartesian coordinates. | |
290 | // If point is outside of the parameterized region get it at closeset valid point | |
291 | static float rphiz[3]; | |
292 | // | |
293 | // TPCInt region | |
294 | // convert coordinates to cyl system | |
295 | CartToCyl(xyz,rphiz); | |
296 | #ifndef _BRING_TO_BOUNDARY_ | |
297 | if ( (rphiz[2]>GetMaxZTPCInt()||rphiz[2]<GetMinZTPCInt()) || | |
298 | rphiz[0]>GetMaxRTPCInt()) {for (int i=3;i--;) b[i]=0; return;} | |
299 | #endif | |
300 | // | |
301 | GetTPCIntCyl(rphiz,b); | |
302 | // | |
303 | // convert field to cartesian system | |
304 | CylToCartCylB(rphiz, b,b); | |
305 | // | |
306 | } | |
307 | ||
308 | //__________________________________________________________________________________________ | |
309 | void AliMagFCheb::FieldCylSol(Float_t *rphiz, Float_t *b) const | |
310 | { | |
311 | // compute Solenoid field in Cylindircal coordinates | |
312 | // note: if the point is outside the volume get the field in closest parameterized point | |
313 | float &r = rphiz[0]; | |
314 | float &z = rphiz[2]; | |
315 | int SolZId = 0; | |
316 | while (z>fSegZSol[SolZId] && SolZId<fNSegZSol) ++SolZId; // find Z segment | |
317 | int SolRId = fSegZIdSol[SolZId]; // first R segment for this Z | |
318 | int SolRMax = SolRId + fNSegRSol[SolZId]; | |
319 | while (r>fSegRSol[SolRId] && SolRId<SolRMax) ++SolRId; // find R segment | |
320 | GetParamSol( SolRId )->Eval(rphiz,b); | |
321 | // | |
322 | } | |
323 | ||
324 | //__________________________________________________________________________________________ | |
325 | void AliMagFCheb::GetTPCIntCyl(Float_t *rphiz, Float_t *b) const | |
326 | { | |
327 | // compute field integral in TPC region in Cylindircal coordinates | |
328 | // note: the check for the point being inside the parameterized region is done outside | |
329 | float &r = rphiz[0]; | |
330 | float &z = rphiz[2]; | |
331 | int TPCIntZId = 0; | |
332 | while (z>fSegZTPCInt[TPCIntZId] && TPCIntZId<fNSegZTPCInt) ++TPCIntZId; // find Z segment | |
333 | int TPCIntRId = fSegZIdTPCInt[TPCIntZId]; // first R segment for this Z | |
334 | int TPCIntRIdMax = TPCIntRId + fNSegRTPCInt[TPCIntZId]; | |
335 | while (r>fSegRTPCInt[TPCIntRId] && TPCIntRId<TPCIntRIdMax) ++TPCIntRId; // find R segment | |
336 | GetParamTPCInt( TPCIntRId )->Eval(rphiz,b); | |
337 | // | |
338 | } | |
339 | ||
340 | ||
341 | //__________________________________________________________________________________________ | |
342 | void AliMagFCheb::Print(Option_t *) const | |
343 | { | |
344 | printf("Alice magnetic field parameterized by Chebyshev polynomials\n"); | |
345 | printf("Segmentation for Solenoid (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZSol,fMaxZSol,fMaxRSol); | |
346 | // | |
347 | if (fParamsSol) fParamsSol->Print(); | |
348 | /* | |
349 | for (int iz=0;iz<fNSegZSol;iz++) { | |
350 | AliCheb3D* param = GetParamSol( fSegZIdSol[iz] ); | |
351 | printf("*** Z Segment %2d (%+7.2f<Z<%+7.2f)\t***\n",iz,param->GetBoundMin(2),param->GetBoundMax(2)); | |
352 | for (int ir=0;ir<fNSegRSol[iz];ir++) { | |
353 | param = GetParamSol( fSegZIdSol[iz]+ir ); | |
354 | printf(" R Segment %2d (%+7.2f<R<%+7.2f, Precision: %.1e) (ID=%2d)\n",ir, param->GetBoundMin(0), | |
355 | param->GetBoundMax(0),param->GetPrecision(),fSegZIdSol[iz]+ir); | |
356 | } | |
357 | } | |
358 | */ | |
359 | // | |
360 | printf("Segmentation for TPC field integral (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZTPCInt,fMaxZTPCInt,fMaxRTPCInt); | |
361 | // | |
362 | if (fParamsTPCInt) fParamsTPCInt->Print(); | |
363 | /* | |
364 | for (int iz=0;iz<fNSegZTPCInt;iz++) { | |
365 | AliCheb3D* param = GetParamTPCInt( fSegZIdTPCInt[iz] ); | |
366 | printf("*** Z Segment %2d (%+7.2f<Z<%+7.2f)\t***\n",iz,param->GetBoundMin(2),param->GetBoundMax(2)); | |
367 | for (int ir=0;ir<fNSegRTPCInt[iz];ir++) { | |
368 | param = GetParamTPCInt( fSegZIdTPCInt[iz]+ir ); | |
369 | printf(" R Segment %2d (%+7.2f<R<%+7.2f, Precision: %.1e) (ID=%2d)\n",ir, param->GetBoundMin(0), | |
370 | param->GetBoundMax(0),param->GetPrecision(),fSegZIdTPCInt[iz]+ir); | |
371 | } | |
372 | } | |
373 | */ | |
374 | // | |
375 | printf("Segmentation for Dipole (%+.2f<Z<%+.2f cm)\n",fMinZDip,fMaxZDip); | |
376 | if (fParamsDip) fParamsDip->Print(); | |
377 | // | |
378 | ||
379 | ||
380 | } | |
381 | ||
382 | //_______________________________________________ | |
383 | void AliMagFCheb::LoadData(const char* inpfile) | |
384 | { | |
385 | // read coefficients data from the text file | |
386 | // | |
387 | TString strf = inpfile; | |
388 | gSystem->ExpandPathName(strf); | |
389 | FILE* stream = fopen(strf,"r"); | |
390 | if (!stream) { | |
391 | printf("Did not find input file %s\n",strf.Data()); | |
392 | return; | |
393 | } | |
394 | // | |
395 | TString buffs; | |
396 | AliCheb3DCalc::ReadLine(buffs,stream); | |
397 | if (!buffs.BeginsWith("START")) { | |
398 | Error("LoadData","Expected: \"START <name>\", found \"%s\"\nStop\n",buffs.Data()); | |
399 | exit(1); | |
400 | } | |
401 | if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1); | |
402 | // | |
403 | // Solenoid part ----------------------------------------------------------- | |
404 | AliCheb3DCalc::ReadLine(buffs,stream); | |
405 | if (!buffs.BeginsWith("START SOLENOID")) { | |
406 | Error("LoadData","Expected: \"START SOLENOID\", found \"%s\"\nStop\n",buffs.Data()); | |
407 | exit(1); | |
408 | } | |
409 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
410 | int nparSol = buffs.Atoi(); | |
411 | // | |
412 | for (int ip=0;ip<nparSol;ip++) { | |
413 | AliCheb3D* cheb = new AliCheb3D(); | |
414 | cheb->LoadData(stream); | |
415 | AddParamSol(cheb); | |
416 | } | |
417 | // | |
418 | AliCheb3DCalc::ReadLine(buffs,stream); | |
419 | if (!buffs.BeginsWith("END SOLENOID")) { | |
420 | Error("LoadData","Expected \"END SOLENOID\", found \"%s\"\nStop\n",buffs.Data()); | |
421 | exit(1); | |
422 | } | |
423 | // | |
424 | // TPCInt part ----------------------------------------------------------- | |
425 | AliCheb3DCalc::ReadLine(buffs,stream); | |
426 | if (!buffs.BeginsWith("START TPCINT")) { | |
427 | Error("LoadData","Expected: \"START TPCINT\", found \"%s\"\nStop\n",buffs.Data()); | |
428 | exit(1); | |
429 | } | |
430 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
431 | int nparTPCInt = buffs.Atoi(); | |
432 | // | |
433 | for (int ip=0;ip<nparTPCInt;ip++) { | |
434 | AliCheb3D* cheb = new AliCheb3D(); | |
435 | cheb->LoadData(stream); | |
436 | AddParamTPCInt(cheb); | |
437 | } | |
438 | // | |
439 | AliCheb3DCalc::ReadLine(buffs,stream); | |
440 | if (!buffs.BeginsWith("END TPCINT")) { | |
441 | Error("LoadData","Expected \"END TPCINT\", found \"%s\"\nStop\n",buffs.Data()); | |
442 | exit(1); | |
443 | } | |
444 | // | |
445 | // Dipole part ----------------------------------------------------------- | |
446 | AliCheb3DCalc::ReadLine(buffs,stream); | |
447 | if (!buffs.BeginsWith("START DIPOLE")) { | |
448 | Error("LoadData","Expected: \"START DIPOLE\", found \"%s\"\nStop\n",buffs.Data()); | |
449 | exit(1); | |
450 | } | |
451 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
452 | int nparDip = buffs.Atoi(); | |
453 | // | |
454 | for (int ip=0;ip<nparDip;ip++) { | |
455 | AliCheb3D* cheb = new AliCheb3D(); | |
456 | cheb->LoadData(stream); | |
457 | AddParamDip(cheb); | |
458 | } | |
0eea9d4d | 459 | // |
d28e407c | 460 | AliCheb3DCalc::ReadLine(buffs,stream); |
461 | if (!buffs.BeginsWith("END DIPOLE")) { | |
462 | Error("LoadData","Expected \"END DIPOLE\", found \"%s\"\nStop\n",GetName(),buffs.Data()); | |
463 | exit(1); | |
464 | } | |
465 | // | |
466 | AliCheb3DCalc::ReadLine(buffs,stream); | |
467 | if (!buffs.BeginsWith("END") || !buffs.Contains(GetName())) { | |
468 | Error("LoadData","Expected: \"END %s\", found \"%s\"\nStop\n",GetName(),buffs.Data()); | |
469 | exit(1); | |
470 | } | |
471 | // | |
472 | // --------------------------------------------------------------------------- | |
473 | fclose(stream); | |
474 | BuildTableSol(); | |
475 | BuildTableTPCInt(); | |
476 | BuildTableDip(); | |
477 | printf("Loaded magnetic field \"%s\" from %s\n",GetName(),strf.Data()); | |
0eea9d4d | 478 | // |
d28e407c | 479 | } |
480 | ||
481 | //_________________________________________________________________________ | |
482 | Int_t AliMagFCheb::FindDipSegment(float *xyz) const | |
483 | { | |
484 | // find the segment containing point xyz. If it is outside find the closest segment | |
485 | int xid,yid,zid = TMath::BinarySearch(fNZSegDip,fSegZDip,xyz[2]); // find zsegment | |
486 | int ysegBeg = fBegSegYDip[zid]; | |
0eea9d4d | 487 | // |
d28e407c | 488 | for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break; |
489 | if ( --yid < 0 ) yid = 0; | |
490 | yid += ysegBeg; | |
0eea9d4d | 491 | // |
d28e407c | 492 | int xsegBeg = fBegSegXDip[yid]; |
493 | for (xid=0;xid<fNSegXDip[yid];xid++) if (xyz[0]<fSegXDip[xsegBeg+xid]) break; | |
494 | if ( --xid < 0) xid = 0; | |
495 | xid += xsegBeg; | |
0eea9d4d | 496 | // |
d28e407c | 497 | return fSegIDDip[xid]; |
498 | } | |
499 | ||
500 | //_______________________________________________ | |
501 | #ifdef _INC_CREATION_ALICHEB3D_ | |
502 | ||
503 | ||
504 | //__________________________________________________________________________________________ | |
505 | AliMagFCheb::AliMagFCheb(const char* inputFile) : | |
506 | fNParamsSol(0), | |
507 | fNSegZSol(0), | |
508 | fNParamsTPCInt(0), | |
509 | fNSegZTPCInt(0), | |
510 | fNParamsDip(0), | |
511 | // | |
512 | fNZSegDip(0), | |
513 | fNYSegDip(0), | |
514 | fNXSegDip(0), | |
515 | // | |
516 | fSegZSol(0), | |
517 | fSegRSol(0), | |
518 | // | |
519 | fSegZTPCInt(0), | |
520 | fSegRTPCInt(0), | |
521 | // | |
522 | fSegZDip(0), | |
523 | fSegYDip(0), | |
524 | fSegXDip(0), | |
525 | // | |
526 | fNSegRSol(0), | |
527 | fSegZIdSol(0), | |
528 | // | |
529 | fNSegRTPCInt(0), | |
530 | fSegZIdTPCInt(0), | |
531 | // | |
532 | fBegSegYDip(0), | |
533 | fNSegYDip(0), | |
534 | fBegSegXDip(0), | |
535 | fNSegXDip(0), | |
536 | fSegIDDip(0), | |
537 | // | |
538 | fMinZSol(0), | |
539 | fMaxZSol(0), | |
540 | fMaxRSol(0), | |
541 | // | |
542 | fMinZDip(0), | |
543 | fMaxZDip(0), | |
544 | // | |
545 | fMinZTPCInt(0), | |
546 | fMaxZTPCInt(0), | |
547 | fMaxRTPCInt(0), | |
548 | // | |
549 | fParamsSol(0), | |
550 | fParamsDip(0), | |
551 | fParamsTPCInt(0) | |
552 | // | |
553 | // | |
554 | { | |
555 | LoadData(inputFile); | |
0eea9d4d | 556 | } |
557 | ||
558 | //__________________________________________________________________________________________ | |
559 | void AliMagFCheb::AddParamSol(AliCheb3D* param) | |
560 | { | |
561 | // adds new parameterization piece for Sol | |
562 | // NOTE: pieces must be added strictly in increasing R then increasing Z order | |
563 | // | |
564 | if (!fParamsSol) fParamsSol = new TObjArray(); | |
565 | fParamsSol->Add(param); | |
566 | fNParamsSol++; | |
567 | // | |
568 | } | |
569 | ||
d28e407c | 570 | //__________________________________________________________________________________________ |
571 | void AliMagFCheb::AddParamTPCInt(AliCheb3D* param) | |
572 | { | |
573 | // adds new parameterization piece for TPCInt | |
574 | // NOTE: pieces must be added strictly in increasing R then increasing Z order | |
575 | // | |
576 | if (!fParamsTPCInt) fParamsTPCInt = new TObjArray(); | |
577 | fParamsTPCInt->Add(param); | |
578 | fNParamsTPCInt++; | |
579 | // | |
580 | } | |
581 | ||
0eea9d4d | 582 | //__________________________________________________________________________________________ |
583 | void AliMagFCheb::AddParamDip(AliCheb3D* param) | |
584 | { | |
585 | // adds new parameterization piece for Dipole | |
586 | // | |
587 | if (!fParamsDip) fParamsDip = new TObjArray(); | |
588 | fParamsDip->Add(param); | |
589 | fNParamsDip++; | |
590 | // | |
591 | } | |
592 | ||
d28e407c | 593 | //__________________________________________________________________________________________ |
594 | void AliMagFCheb::ResetTPCInt() | |
595 | { | |
596 | // clean TPC field integral (used for update) | |
597 | if (!fNParamsTPCInt) return; | |
598 | delete fParamsTPCInt; | |
599 | delete[] fSegZTPCInt; | |
600 | delete[] fSegRTPCInt; | |
601 | delete[] fNSegRTPCInt; | |
602 | delete[] fSegZIdTPCInt; | |
603 | // | |
604 | fNParamsTPCInt = 0; | |
605 | fNSegZTPCInt = 0; | |
606 | fSegZTPCInt = 0; | |
607 | fSegRTPCInt = 0; | |
608 | fNSegRTPCInt = 0; | |
609 | fSegZIdTPCInt = 0; | |
610 | fMinZTPCInt = 0; | |
611 | fMaxZTPCInt = 0; | |
612 | fMaxRTPCInt = 0; | |
613 | fParamsTPCInt = 0; | |
614 | // | |
615 | } | |
616 | ||
617 | //__________________________________________________ | |
618 | void AliMagFCheb::BuildTableDip() | |
619 | { | |
620 | // | |
621 | TArrayF segY,segX; | |
622 | TArrayI begSegYDip,begSegXDip; | |
623 | TArrayI nsegYDip,nsegXDip; | |
624 | TArrayI segID; | |
625 | float *tmpSegZ,*tmpSegY,*tmpSegX; | |
626 | // | |
627 | // create segmentation in Z | |
628 | fNZSegDip = SegmentDipDimension(&tmpSegZ, fParamsDip, fNParamsDip, 2, 1,-1, 1,-1, 1,-1) - 1; | |
629 | fNYSegDip = 0; | |
630 | fNXSegDip = 0; | |
631 | // | |
632 | // for each Z slice create segmentation in Y | |
633 | begSegYDip.Set(fNZSegDip); | |
634 | nsegYDip.Set(fNZSegDip); | |
635 | float xyz[3]; | |
636 | for (int iz=0;iz<fNZSegDip;iz++) { | |
637 | printf("\nZSegment#%d %+e : %+e\n",iz,tmpSegZ[iz],tmpSegZ[iz+1]); | |
638 | int ny = SegmentDipDimension(&tmpSegY, fParamsDip, fNParamsDip, 1, | |
639 | 1,-1, 1,-1, tmpSegZ[iz],tmpSegZ[iz+1]) - 1; | |
640 | segY.Set(ny + fNYSegDip); | |
641 | for (int iy=0;iy<ny;iy++) segY[fNYSegDip+iy] = tmpSegY[iy]; | |
642 | begSegYDip[iz] = fNYSegDip; | |
643 | nsegYDip[iz] = ny; | |
644 | printf(" Found %d YSegments, to start from %d\n",ny, begSegYDip[iz]); | |
645 | // | |
646 | // for each slice in Z and Y create segmentation in X | |
647 | begSegXDip.Set(fNYSegDip+ny); | |
648 | nsegXDip.Set(fNYSegDip+ny); | |
649 | xyz[2] = (tmpSegZ[iz]+tmpSegZ[iz+1])/2.; // mean Z of this segment | |
650 | // | |
651 | for (int iy=0;iy<ny;iy++) { | |
652 | int isg = fNYSegDip+iy; | |
653 | printf("\n YSegment#%d %+e : %+e\n",iy, tmpSegY[iy],tmpSegY[iy+1]); | |
654 | int nx = SegmentDipDimension(&tmpSegX, fParamsDip, fNParamsDip, 0, | |
655 | 1,-1, tmpSegY[iy],tmpSegY[iy+1], tmpSegZ[iz],tmpSegZ[iz+1]) - 1; | |
656 | // | |
657 | segX.Set(nx + fNXSegDip); | |
658 | for (int ix=0;ix<nx;ix++) segX[fNXSegDip+ix] = tmpSegX[ix]; | |
659 | begSegXDip[isg] = fNXSegDip; | |
660 | nsegXDip[isg] = nx; | |
661 | printf(" Found %d XSegments, to start from %d\n",nx, begSegXDip[isg]); | |
662 | // | |
663 | segID.Set(fNXSegDip+nx); | |
664 | // | |
665 | // find corresponding params | |
666 | xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment | |
667 | // | |
668 | for (int ix=0;ix<nx;ix++) { | |
669 | xyz[0] = (tmpSegX[ix]+tmpSegX[ix+1])/2.; // mean X of this segment | |
670 | for (int ipar=0;ipar<fNParamsDip;ipar++) { | |
671 | AliCheb3D* cheb = (AliCheb3D*) fParamsDip->At(ipar); | |
672 | if (!cheb->IsInside(xyz)) continue; | |
673 | segID[fNXSegDip+ix] = ipar; | |
674 | break; | |
675 | } | |
676 | } | |
677 | fNXSegDip += nx; | |
678 | // | |
679 | delete[] tmpSegX; | |
680 | } | |
681 | delete[] tmpSegY; | |
682 | fNYSegDip += ny; | |
683 | } | |
684 | // | |
685 | fMinZDip = tmpSegZ[0]; | |
686 | fMaxZDip = tmpSegZ[fNZSegDip]; | |
687 | fSegZDip = new Float_t[fNZSegDip]; | |
688 | for (int i=fNZSegDip;i--;) fSegZDip[i] = tmpSegZ[i]; | |
689 | delete[] tmpSegZ; | |
690 | // | |
691 | fSegYDip = new Float_t[fNYSegDip]; | |
692 | fSegXDip = new Float_t[fNXSegDip]; | |
693 | fBegSegYDip = new Int_t[fNZSegDip]; | |
694 | fNSegYDip = new Int_t[fNZSegDip]; | |
695 | fBegSegXDip = new Int_t[fNYSegDip]; | |
696 | fNSegXDip = new Int_t[fNYSegDip]; | |
697 | fSegIDDip = new Int_t[fNXSegDip]; | |
698 | // | |
699 | for (int i=fNYSegDip;i--;) fSegYDip[i] = segY[i]; | |
700 | for (int i=fNXSegDip;i--;) fSegXDip[i] = segX[i]; | |
701 | for (int i=fNZSegDip;i--;) {fBegSegYDip[i] = begSegYDip[i]; fNSegYDip[i] = nsegYDip[i];} | |
702 | for (int i=fNYSegDip;i--;) {fBegSegXDip[i] = begSegXDip[i]; fNSegXDip[i] = nsegXDip[i];} | |
703 | for (int i=fNXSegDip;i--;) {fSegIDDip[i] = segID[i];} | |
704 | // | |
705 | } | |
706 | ||
0eea9d4d | 707 | //__________________________________________________________________________________________ |
708 | void AliMagFCheb::BuildTableSol() | |
709 | { | |
710 | // build the indexes for each parameterization of Solenoid | |
711 | // | |
712 | const float kSafety=0.001; | |
713 | // | |
d28e407c | 714 | if (fNParamsSol<1) return; |
0eea9d4d | 715 | fSegRSol = new Float_t[fNParamsSol]; |
716 | float *tmpbufF = new float[fNParamsSol+1]; | |
717 | int *tmpbufI = new int[fNParamsSol+1]; | |
718 | int *tmpbufI1 = new int[fNParamsSol+1]; | |
719 | // | |
720 | // count number of Z slices and number of R slices in each Z slice | |
721 | for (int ip=0;ip<fNParamsSol;ip++) { | |
722 | if (ip==0 || (GetParamSol(ip)->GetBoundMax(2)-GetParamSol(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice | |
723 | tmpbufF[fNSegZSol] = GetParamSol(ip)->GetBoundMax(2); // | |
724 | tmpbufI[fNSegZSol] = 0; | |
725 | tmpbufI1[fNSegZSol++] = ip; | |
726 | } | |
727 | fSegRSol[ip] = GetParamSol(ip)->GetBoundMax(0); // upper R | |
728 | tmpbufI[fNSegZSol-1]++; | |
729 | } | |
730 | // | |
731 | fSegZSol = new Float_t[fNSegZSol]; | |
732 | fSegZIdSol = new Int_t[fNSegZSol]; | |
733 | fNSegRSol = new Int_t[fNSegZSol]; | |
734 | for (int iz=0;iz<fNSegZSol;iz++) { | |
735 | fSegZSol[iz] = tmpbufF[iz]; | |
736 | fNSegRSol[iz] = tmpbufI[iz]; | |
737 | fSegZIdSol[iz] = tmpbufI1[iz]; | |
738 | } | |
739 | // | |
740 | fMinZSol = GetParamSol(0)->GetBoundMin(2); | |
741 | fMaxZSol = GetParamSol(fNParamsSol-1)->GetBoundMax(2); | |
742 | fMaxRSol = GetParamSol(fNParamsSol-1)->GetBoundMax(0); | |
743 | // | |
744 | delete[] tmpbufF; | |
745 | delete[] tmpbufI; | |
746 | delete[] tmpbufI1; | |
747 | // | |
748 | // | |
749 | } | |
750 | ||
751 | //__________________________________________________________________________________________ | |
d28e407c | 752 | void AliMagFCheb::BuildTableTPCInt() |
0eea9d4d | 753 | { |
d28e407c | 754 | // build the indexes for each parameterization of TPC field integral |
0eea9d4d | 755 | // |
d28e407c | 756 | const float kSafety=0.001; |
0eea9d4d | 757 | // |
d28e407c | 758 | if (fNParamsTPCInt<1) return; |
759 | fSegRTPCInt = new Float_t[fNParamsTPCInt]; | |
760 | float *tmpbufF = new float[fNParamsTPCInt+1]; | |
761 | int *tmpbufI = new int[fNParamsTPCInt+1]; | |
762 | int *tmpbufI1 = new int[fNParamsTPCInt+1]; | |
0eea9d4d | 763 | // |
d28e407c | 764 | // count number of Z slices and number of R slices in each Z slice |
765 | for (int ip=0;ip<fNParamsTPCInt;ip++) { | |
766 | if (ip==0 || (GetParamTPCInt(ip)->GetBoundMax(2)-GetParamTPCInt(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice | |
767 | tmpbufF[fNSegZTPCInt] = GetParamTPCInt(ip)->GetBoundMax(2); // | |
768 | tmpbufI[fNSegZTPCInt] = 0; | |
769 | tmpbufI1[fNSegZTPCInt++] = ip; | |
770 | } | |
771 | fSegRTPCInt[ip] = GetParamTPCInt(ip)->GetBoundMax(0); // upper R | |
772 | tmpbufI[fNSegZTPCInt-1]++; | |
773 | } | |
0eea9d4d | 774 | // |
d28e407c | 775 | fSegZTPCInt = new Float_t[fNSegZTPCInt]; |
776 | fSegZIdTPCInt = new Int_t[fNSegZTPCInt]; | |
777 | fNSegRTPCInt = new Int_t[fNSegZTPCInt]; | |
778 | for (int iz=0;iz<fNSegZTPCInt;iz++) { | |
779 | fSegZTPCInt[iz] = tmpbufF[iz]; | |
780 | fNSegRTPCInt[iz] = tmpbufI[iz]; | |
781 | fSegZIdTPCInt[iz] = tmpbufI1[iz]; | |
782 | } | |
783 | // | |
784 | fMinZTPCInt = GetParamTPCInt(0)->GetBoundMin(2); | |
785 | fMaxZTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(2); | |
786 | fMaxRTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(0); | |
787 | // | |
788 | delete[] tmpbufF; | |
789 | delete[] tmpbufI; | |
790 | delete[] tmpbufI1; | |
0eea9d4d | 791 | // |
0eea9d4d | 792 | // |
0eea9d4d | 793 | } |
794 | ||
0eea9d4d | 795 | void AliMagFCheb::SaveData(const char* outfile) const |
796 | { | |
797 | // writes coefficients data to output text file | |
798 | TString strf = outfile; | |
799 | gSystem->ExpandPathName(strf); | |
800 | FILE* stream = fopen(strf,"w+"); | |
801 | // | |
d28e407c | 802 | // Sol part --------------------------------------------------------- |
0eea9d4d | 803 | fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName()); |
804 | fprintf(stream,"START SOLENOID\n#Number of pieces\n%d\n",fNParamsSol); | |
805 | for (int ip=0;ip<fNParamsSol;ip++) GetParamSol(ip)->SaveData(stream); | |
806 | fprintf(stream,"#\nEND SOLENOID\n"); | |
807 | // | |
d28e407c | 808 | // TPCInt part --------------------------------------------------------- |
809 | fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName()); | |
810 | fprintf(stream,"START TPCINT\n#Number of pieces\n%d\n",fNParamsTPCInt); | |
811 | for (int ip=0;ip<fNParamsTPCInt;ip++) GetParamTPCInt(ip)->SaveData(stream); | |
812 | fprintf(stream,"#\nEND TPCINT\n"); | |
813 | // | |
814 | // Dip part --------------------------------------------------------- | |
0eea9d4d | 815 | fprintf(stream,"START DIPOLE\n#Number of pieces\n%d\n",fNParamsDip); |
816 | for (int ip=0;ip<fNParamsDip;ip++) GetParamDip(ip)->SaveData(stream); | |
817 | fprintf(stream,"#\nEND DIPOLE\n"); | |
818 | // | |
819 | fprintf(stream,"#\nEND %s\n",GetName()); | |
820 | // | |
821 | fclose(stream); | |
822 | // | |
823 | } | |
0eea9d4d | 824 | |
d28e407c | 825 | Int_t AliMagFCheb::SegmentDipDimension(float** seg,const TObjArray* par,int npar, int dim, |
826 | float xmn,float xmx,float ymn,float ymx,float zmn,float zmx) | |
0eea9d4d | 827 | { |
d28e407c | 828 | // find all boundaries in deimension dim for boxes in given region. |
829 | // if mn>mx for given projection the check is not done for it. | |
830 | float *tmpC = new float[2*npar]; | |
831 | int *tmpInd = new int[2*npar]; | |
832 | int nseg0 = 0; | |
833 | for (int ip=0;ip<npar;ip++) { | |
834 | AliCheb3D* cheb = (AliCheb3D*) par->At(ip); | |
835 | if (xmn<xmx && (cheb->GetBoundMin(0)>(xmx+xmn)/2 || cheb->GetBoundMax(0)<(xmn+xmx)/2)) continue; | |
836 | if (ymn<ymx && (cheb->GetBoundMin(1)>(ymx+ymn)/2 || cheb->GetBoundMax(1)<(ymn+ymx)/2)) continue; | |
837 | if (zmn<zmx && (cheb->GetBoundMin(2)>(zmx+zmn)/2 || cheb->GetBoundMax(2)<(zmn+zmx)/2)) continue; | |
838 | // | |
839 | tmpC[nseg0++] = cheb->GetBoundMin(dim); | |
840 | tmpC[nseg0++] = cheb->GetBoundMax(dim); | |
0eea9d4d | 841 | } |
d28e407c | 842 | // range Dim's boundaries in increasing order |
843 | TMath::Sort(nseg0,tmpC,tmpInd,kFALSE); | |
844 | // count number of really different Z's | |
845 | int nseg = 0; | |
846 | float cprev = -1e6; | |
847 | for (int ip=0;ip<nseg0;ip++) { | |
848 | if (TMath::Abs(cprev-tmpC[ tmpInd[ip] ])>1e-4) { | |
849 | cprev = tmpC[ tmpInd[ip] ]; | |
850 | nseg++; | |
851 | } | |
852 | else tmpInd[ip] = -1; // supress redundant Z | |
0eea9d4d | 853 | } |
d28e407c | 854 | // |
855 | *seg = new float[nseg]; // create final Z segmenations | |
856 | nseg = 0; | |
857 | for (int ip=0;ip<nseg0;ip++) if (tmpInd[ip]>=0) (*seg)[nseg++] = tmpC[ tmpInd[ip] ]; | |
858 | // | |
859 | delete[] tmpC; | |
860 | delete[] tmpInd; | |
861 | return nseg; | |
0eea9d4d | 862 | } |
d28e407c | 863 | |
864 | #endif | |
865 |