1 ///////////////////////////////////////////////////////////////////////////////////
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) //
9 // The solenoid part is parameterized in the volume R<500, -550<Z<550 cm //
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) //
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. //
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 //
27 // GetTPCIntCyl(Float_t *rphiz, Float_t *b); for Cylindrical frame //
30 // The units are kiloGauss and cm. //
32 ///////////////////////////////////////////////////////////////////////////////////
34 #include "AliMagFCheb.h"
38 //__________________________________________________________________________________________
39 AliMagFCheb::AliMagFCheb() :
89 //__________________________________________________________________________________________
90 AliMagFCheb::AliMagFCheb(const AliMagFCheb& src) :
143 //__________________________________________________________________________________________
144 void AliMagFCheb::CopyFrom(const AliMagFCheb& src)
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;
155 fNZSegDip = src.fNZSegDip;
156 fNYSegDip = src.fNYSegDip;
157 fNXSegDip = src.fNXSegDip;
159 fMinZSol = src.fMinZSol;
160 fMaxZSol = src.fMaxZSol;
161 fMaxRSol = src.fMaxRSol;
163 fMinZDip = src.fMinZDip;
164 fMaxZDip = src.fMaxZDip;
166 fMinZTPCInt = src.fMinZTPCInt;
167 fMaxZTPCInt = src.fMaxZTPCInt;
168 fMaxRTPCInt = src.fMaxRTPCInt;
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);
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);
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);
203 //__________________________________________________________________________________________
204 AliMagFCheb& AliMagFCheb::operator=(const AliMagFCheb& rhs)
214 //__________________________________________________________________________________________
215 void AliMagFCheb::Clear(Option_t *)
225 if (fNParamsTPCInt) {
226 delete fParamsTPCInt;
227 delete[] fSegZTPCInt;
228 delete[] fSegRTPCInt;
229 delete[] fNSegRTPCInt;
230 delete[] fSegZIdTPCInt;
238 delete[] fBegSegYDip;
240 delete[] fBegSegXDip;
244 fNParamsSol = fNParamsTPCInt = fNParamsDip = fNZSegDip = fNYSegDip = fNXSegDip = 0;
245 fNSegZSol = fNSegZTPCInt = 0;
246 fMinZSol = fMinZDip = fMinZTPCInt = 1e6;
247 fMaxZSol = fMaxZDip = fMaxZTPCInt = fMaxRSol = fMaxRTPCInt = -1e6;
251 //__________________________________________________________________________________________
252 void AliMagFCheb::Field(Float_t *xyz, Float_t *b) const
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];
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;}
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;
269 GetParamDip(FindDipSegment(xyz))->Eval(xyz,b); return;
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;}
279 FieldCylSol(rphiz,b);
281 // convert field to cartesian system
282 CylToCartCylB(rphiz, b,b);
286 //__________________________________________________________________________________________
287 void AliMagFCheb::GetTPCInt(Float_t *xyz, Float_t *b) const
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];
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;}
301 GetTPCIntCyl(rphiz,b);
303 // convert field to cartesian system
304 CylToCartCylB(rphiz, b,b);
308 //__________________________________________________________________________________________
309 void AliMagFCheb::FieldCylSol(Float_t *rphiz, Float_t *b) const
311 // compute Solenoid field in Cylindircal coordinates
312 // note: if the point is outside the volume get the field in closest parameterized point
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);
324 //__________________________________________________________________________________________
325 void AliMagFCheb::GetTPCIntCyl(Float_t *rphiz, Float_t *b) const
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
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);
341 //__________________________________________________________________________________________
342 void AliMagFCheb::Print(Option_t *) const
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);
347 if (fParamsSol) fParamsSol->Print();
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);
360 printf("Segmentation for TPC field integral (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZTPCInt,fMaxZTPCInt,fMaxRTPCInt);
362 if (fParamsTPCInt) fParamsTPCInt->Print();
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);
375 printf("Segmentation for Dipole (%+.2f<Z<%+.2f cm)\n",fMinZDip,fMaxZDip);
376 if (fParamsDip) fParamsDip->Print();
382 //_______________________________________________
383 void AliMagFCheb::LoadData(const char* inpfile)
385 // read coefficients data from the text file
387 TString strf = inpfile;
388 gSystem->ExpandPathName(strf);
389 FILE* stream = fopen(strf,"r");
391 printf("Did not find input file %s\n",strf.Data());
396 AliCheb3DCalc::ReadLine(buffs,stream);
397 if (!buffs.BeginsWith("START")) {
398 Error("LoadData","Expected: \"START <name>\", found \"%s\"\nStop\n",buffs.Data());
401 if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1);
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());
409 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
410 int nparSol = buffs.Atoi();
412 for (int ip=0;ip<nparSol;ip++) {
413 AliCheb3D* cheb = new AliCheb3D();
414 cheb->LoadData(stream);
418 AliCheb3DCalc::ReadLine(buffs,stream);
419 if (!buffs.BeginsWith("END SOLENOID")) {
420 Error("LoadData","Expected \"END SOLENOID\", found \"%s\"\nStop\n",buffs.Data());
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());
430 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
431 int nparTPCInt = buffs.Atoi();
433 for (int ip=0;ip<nparTPCInt;ip++) {
434 AliCheb3D* cheb = new AliCheb3D();
435 cheb->LoadData(stream);
436 AddParamTPCInt(cheb);
439 AliCheb3DCalc::ReadLine(buffs,stream);
440 if (!buffs.BeginsWith("END TPCINT")) {
441 Error("LoadData","Expected \"END TPCINT\", found \"%s\"\nStop\n",buffs.Data());
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());
451 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
452 int nparDip = buffs.Atoi();
454 for (int ip=0;ip<nparDip;ip++) {
455 AliCheb3D* cheb = new AliCheb3D();
456 cheb->LoadData(stream);
460 AliCheb3DCalc::ReadLine(buffs,stream);
461 if (!buffs.BeginsWith("END DIPOLE")) {
462 Error("LoadData","Expected \"END DIPOLE\", found \"%s\"\nStop\n",GetName(),buffs.Data());
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());
472 // ---------------------------------------------------------------------------
477 printf("Loaded magnetic field \"%s\" from %s\n",GetName(),strf.Data());
481 //_________________________________________________________________________
482 Int_t AliMagFCheb::FindDipSegment(float *xyz) const
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];
488 for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break;
489 if ( --yid < 0 ) yid = 0;
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;
497 return fSegIDDip[xid];
500 //_______________________________________________
501 #ifdef _INC_CREATION_ALICHEB3D_
504 //__________________________________________________________________________________________
505 AliMagFCheb::AliMagFCheb(const char* inputFile) :
558 //__________________________________________________________________________________________
559 void AliMagFCheb::AddParamSol(AliCheb3D* param)
561 // adds new parameterization piece for Sol
562 // NOTE: pieces must be added strictly in increasing R then increasing Z order
564 if (!fParamsSol) fParamsSol = new TObjArray();
565 fParamsSol->Add(param);
570 //__________________________________________________________________________________________
571 void AliMagFCheb::AddParamTPCInt(AliCheb3D* param)
573 // adds new parameterization piece for TPCInt
574 // NOTE: pieces must be added strictly in increasing R then increasing Z order
576 if (!fParamsTPCInt) fParamsTPCInt = new TObjArray();
577 fParamsTPCInt->Add(param);
582 //__________________________________________________________________________________________
583 void AliMagFCheb::AddParamDip(AliCheb3D* param)
585 // adds new parameterization piece for Dipole
587 if (!fParamsDip) fParamsDip = new TObjArray();
588 fParamsDip->Add(param);
593 //__________________________________________________________________________________________
594 void AliMagFCheb::ResetTPCInt()
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;
617 //__________________________________________________
618 void AliMagFCheb::BuildTableDip()
622 TArrayI begSegYDip,begSegXDip;
623 TArrayI nsegYDip,nsegXDip;
625 float *tmpSegZ,*tmpSegY,*tmpSegX;
627 // create segmentation in Z
628 fNZSegDip = SegmentDipDimension(&tmpSegZ, fParamsDip, fNParamsDip, 2, 1,-1, 1,-1, 1,-1) - 1;
632 // for each Z slice create segmentation in Y
633 begSegYDip.Set(fNZSegDip);
634 nsegYDip.Set(fNZSegDip);
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;
644 printf(" Found %d YSegments, to start from %d\n",ny, begSegYDip[iz]);
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
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;
657 segX.Set(nx + fNXSegDip);
658 for (int ix=0;ix<nx;ix++) segX[fNXSegDip+ix] = tmpSegX[ix];
659 begSegXDip[isg] = fNXSegDip;
661 printf(" Found %d XSegments, to start from %d\n",nx, begSegXDip[isg]);
663 segID.Set(fNXSegDip+nx);
665 // find corresponding params
666 xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment
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;
685 fMinZDip = tmpSegZ[0];
686 fMaxZDip = tmpSegZ[fNZSegDip];
687 fSegZDip = new Float_t[fNZSegDip];
688 for (int i=fNZSegDip;i--;) fSegZDip[i] = tmpSegZ[i];
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];
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];}
707 //__________________________________________________________________________________________
708 void AliMagFCheb::BuildTableSol()
710 // build the indexes for each parameterization of Solenoid
712 const float kSafety=0.001;
714 if (fNParamsSol<1) return;
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];
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;
727 fSegRSol[ip] = GetParamSol(ip)->GetBoundMax(0); // upper R
728 tmpbufI[fNSegZSol-1]++;
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];
740 fMinZSol = GetParamSol(0)->GetBoundMin(2);
741 fMaxZSol = GetParamSol(fNParamsSol-1)->GetBoundMax(2);
742 fMaxRSol = GetParamSol(fNParamsSol-1)->GetBoundMax(0);
751 //__________________________________________________________________________________________
752 void AliMagFCheb::BuildTableTPCInt()
754 // build the indexes for each parameterization of TPC field integral
756 const float kSafety=0.001;
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];
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;
771 fSegRTPCInt[ip] = GetParamTPCInt(ip)->GetBoundMax(0); // upper R
772 tmpbufI[fNSegZTPCInt-1]++;
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];
784 fMinZTPCInt = GetParamTPCInt(0)->GetBoundMin(2);
785 fMaxZTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(2);
786 fMaxRTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(0);
795 void AliMagFCheb::SaveData(const char* outfile) const
797 // writes coefficients data to output text file
798 TString strf = outfile;
799 gSystem->ExpandPathName(strf);
800 FILE* stream = fopen(strf,"w+");
802 // Sol part ---------------------------------------------------------
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");
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");
814 // Dip part ---------------------------------------------------------
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");
819 fprintf(stream,"#\nEND %s\n",GetName());
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)
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];
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;
839 tmpC[nseg0++] = cheb->GetBoundMin(dim);
840 tmpC[nseg0++] = cheb->GetBoundMax(dim);
842 // range Dim's boundaries in increasing order
843 TMath::Sort(nseg0,tmpC,tmpInd,kFALSE);
844 // count number of really different Z's
847 for (int ip=0;ip<nseg0;ip++) {
848 if (TMath::Abs(cprev-tmpC[ tmpInd[ip] ])>1e-4) {
849 cprev = tmpC[ tmpInd[ip] ];
852 else tmpInd[ip] = -1; // supress redundant Z
855 *seg = new float[nseg]; // create final Z segmenations
857 for (int ip=0;ip<nseg0;ip++) if (tmpInd[ip]>=0) (*seg)[nseg++] = tmpC[ tmpInd[ip] ];