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