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