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-1) ++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-1) ++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();
381 #ifdef _INC_CREATION_ALICHEB3D_
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());
482 //_________________________________________________________________________
483 Int_t AliMagFCheb::FindDipSegment(float *xyz) const
485 // find the segment containing point xyz. If it is outside find the closest segment
486 int xid,yid,zid = TMath::BinarySearch(fNZSegDip,fSegZDip,xyz[2]); // find zsegment
487 int ysegBeg = fBegSegYDip[zid];
489 for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break;
490 if ( --yid < 0 ) yid = 0;
493 int xsegBeg = fBegSegXDip[yid];
494 for (xid=0;xid<fNSegXDip[yid];xid++) if (xyz[0]<fSegXDip[xsegBeg+xid]) break;
495 if ( --xid < 0) xid = 0;
498 return fSegIDDip[xid];
501 //_______________________________________________
502 #ifdef _INC_CREATION_ALICHEB3D_
505 //__________________________________________________________________________________________
506 AliMagFCheb::AliMagFCheb(const char* inputFile) :
559 //__________________________________________________________________________________________
560 void AliMagFCheb::AddParamSol(AliCheb3D* param)
562 // adds new parameterization piece for Sol
563 // NOTE: pieces must be added strictly in increasing R then increasing Z order
565 if (!fParamsSol) fParamsSol = new TObjArray();
566 fParamsSol->Add(param);
571 //__________________________________________________________________________________________
572 void AliMagFCheb::AddParamTPCInt(AliCheb3D* param)
574 // adds new parameterization piece for TPCInt
575 // NOTE: pieces must be added strictly in increasing R then increasing Z order
577 if (!fParamsTPCInt) fParamsTPCInt = new TObjArray();
578 fParamsTPCInt->Add(param);
583 //__________________________________________________________________________________________
584 void AliMagFCheb::AddParamDip(AliCheb3D* param)
586 // adds new parameterization piece for Dipole
588 if (!fParamsDip) fParamsDip = new TObjArray();
589 fParamsDip->Add(param);
594 //__________________________________________________________________________________________
595 void AliMagFCheb::ResetTPCInt()
597 // clean TPC field integral (used for update)
598 if (!fNParamsTPCInt) return;
599 delete fParamsTPCInt;
600 delete[] fSegZTPCInt;
601 delete[] fSegRTPCInt;
602 delete[] fNSegRTPCInt;
603 delete[] fSegZIdTPCInt;
618 //__________________________________________________
619 void AliMagFCheb::BuildTableDip()
623 TArrayI begSegYDip,begSegXDip;
624 TArrayI nsegYDip,nsegXDip;
626 float *tmpSegZ,*tmpSegY,*tmpSegX;
628 // create segmentation in Z
629 fNZSegDip = SegmentDipDimension(&tmpSegZ, fParamsDip, fNParamsDip, 2, 1,-1, 1,-1, 1,-1) - 1;
633 // for each Z slice create segmentation in Y
634 begSegYDip.Set(fNZSegDip);
635 nsegYDip.Set(fNZSegDip);
637 for (int iz=0;iz<fNZSegDip;iz++) {
638 printf("\nZSegment#%d %+e : %+e\n",iz,tmpSegZ[iz],tmpSegZ[iz+1]);
639 int ny = SegmentDipDimension(&tmpSegY, fParamsDip, fNParamsDip, 1,
640 1,-1, 1,-1, tmpSegZ[iz],tmpSegZ[iz+1]) - 1;
641 segY.Set(ny + fNYSegDip);
642 for (int iy=0;iy<ny;iy++) segY[fNYSegDip+iy] = tmpSegY[iy];
643 begSegYDip[iz] = fNYSegDip;
645 printf(" Found %d YSegments, to start from %d\n",ny, begSegYDip[iz]);
647 // for each slice in Z and Y create segmentation in X
648 begSegXDip.Set(fNYSegDip+ny);
649 nsegXDip.Set(fNYSegDip+ny);
650 xyz[2] = (tmpSegZ[iz]+tmpSegZ[iz+1])/2.; // mean Z of this segment
652 for (int iy=0;iy<ny;iy++) {
653 int isg = fNYSegDip+iy;
654 printf("\n YSegment#%d %+e : %+e\n",iy, tmpSegY[iy],tmpSegY[iy+1]);
655 int nx = SegmentDipDimension(&tmpSegX, fParamsDip, fNParamsDip, 0,
656 1,-1, tmpSegY[iy],tmpSegY[iy+1], tmpSegZ[iz],tmpSegZ[iz+1]) - 1;
658 segX.Set(nx + fNXSegDip);
659 for (int ix=0;ix<nx;ix++) segX[fNXSegDip+ix] = tmpSegX[ix];
660 begSegXDip[isg] = fNXSegDip;
662 printf(" Found %d XSegments, to start from %d\n",nx, begSegXDip[isg]);
664 segID.Set(fNXSegDip+nx);
666 // find corresponding params
667 xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment
669 for (int ix=0;ix<nx;ix++) {
670 xyz[0] = (tmpSegX[ix]+tmpSegX[ix+1])/2.; // mean X of this segment
671 for (int ipar=0;ipar<fNParamsDip;ipar++) {
672 AliCheb3D* cheb = (AliCheb3D*) fParamsDip->At(ipar);
673 if (!cheb->IsInside(xyz)) continue;
674 segID[fNXSegDip+ix] = ipar;
686 fMinZDip = tmpSegZ[0];
687 fMaxZDip = tmpSegZ[fNZSegDip];
688 fSegZDip = new Float_t[fNZSegDip];
689 for (int i=fNZSegDip;i--;) fSegZDip[i] = tmpSegZ[i];
692 fSegYDip = new Float_t[fNYSegDip];
693 fSegXDip = new Float_t[fNXSegDip];
694 fBegSegYDip = new Int_t[fNZSegDip];
695 fNSegYDip = new Int_t[fNZSegDip];
696 fBegSegXDip = new Int_t[fNYSegDip];
697 fNSegXDip = new Int_t[fNYSegDip];
698 fSegIDDip = new Int_t[fNXSegDip];
700 for (int i=fNYSegDip;i--;) fSegYDip[i] = segY[i];
701 for (int i=fNXSegDip;i--;) fSegXDip[i] = segX[i];
702 for (int i=fNZSegDip;i--;) {fBegSegYDip[i] = begSegYDip[i]; fNSegYDip[i] = nsegYDip[i];}
703 for (int i=fNYSegDip;i--;) {fBegSegXDip[i] = begSegXDip[i]; fNSegXDip[i] = nsegXDip[i];}
704 for (int i=fNXSegDip;i--;) {fSegIDDip[i] = segID[i];}
708 //__________________________________________________________________________________________
709 void AliMagFCheb::BuildTableSol()
711 // build the indexes for each parameterization of Solenoid
713 const float kSafety=0.001;
715 if (fNParamsSol<1) return;
716 fSegRSol = new Float_t[fNParamsSol];
717 float *tmpbufF = new float[fNParamsSol+1];
718 int *tmpbufI = new int[fNParamsSol+1];
719 int *tmpbufI1 = new int[fNParamsSol+1];
721 // count number of Z slices and number of R slices in each Z slice
722 for (int ip=0;ip<fNParamsSol;ip++) {
723 if (ip==0 || (GetParamSol(ip)->GetBoundMax(2)-GetParamSol(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice
724 tmpbufF[fNSegZSol] = GetParamSol(ip)->GetBoundMax(2); //
725 tmpbufI[fNSegZSol] = 0;
726 tmpbufI1[fNSegZSol++] = ip;
728 fSegRSol[ip] = GetParamSol(ip)->GetBoundMax(0); // upper R
729 tmpbufI[fNSegZSol-1]++;
732 fSegZSol = new Float_t[fNSegZSol];
733 fSegZIdSol = new Int_t[fNSegZSol];
734 fNSegRSol = new Int_t[fNSegZSol];
735 for (int iz=0;iz<fNSegZSol;iz++) {
736 fSegZSol[iz] = tmpbufF[iz];
737 fNSegRSol[iz] = tmpbufI[iz];
738 fSegZIdSol[iz] = tmpbufI1[iz];
741 fMinZSol = GetParamSol(0)->GetBoundMin(2);
742 fMaxZSol = GetParamSol(fNParamsSol-1)->GetBoundMax(2);
743 fMaxRSol = GetParamSol(fNParamsSol-1)->GetBoundMax(0);
752 //__________________________________________________________________________________________
753 void AliMagFCheb::BuildTableTPCInt()
755 // build the indexes for each parameterization of TPC field integral
757 const float kSafety=0.001;
759 if (fNParamsTPCInt<1) return;
760 fSegRTPCInt = new Float_t[fNParamsTPCInt];
761 float *tmpbufF = new float[fNParamsTPCInt+1];
762 int *tmpbufI = new int[fNParamsTPCInt+1];
763 int *tmpbufI1 = new int[fNParamsTPCInt+1];
765 // count number of Z slices and number of R slices in each Z slice
766 for (int ip=0;ip<fNParamsTPCInt;ip++) {
767 if (ip==0 || (GetParamTPCInt(ip)->GetBoundMax(2)-GetParamTPCInt(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice
768 tmpbufF[fNSegZTPCInt] = GetParamTPCInt(ip)->GetBoundMax(2); //
769 tmpbufI[fNSegZTPCInt] = 0;
770 tmpbufI1[fNSegZTPCInt++] = ip;
772 fSegRTPCInt[ip] = GetParamTPCInt(ip)->GetBoundMax(0); // upper R
773 tmpbufI[fNSegZTPCInt-1]++;
776 fSegZTPCInt = new Float_t[fNSegZTPCInt];
777 fSegZIdTPCInt = new Int_t[fNSegZTPCInt];
778 fNSegRTPCInt = new Int_t[fNSegZTPCInt];
779 for (int iz=0;iz<fNSegZTPCInt;iz++) {
780 fSegZTPCInt[iz] = tmpbufF[iz];
781 fNSegRTPCInt[iz] = tmpbufI[iz];
782 fSegZIdTPCInt[iz] = tmpbufI1[iz];
785 fMinZTPCInt = GetParamTPCInt(0)->GetBoundMin(2);
786 fMaxZTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(2);
787 fMaxRTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(0);
796 void AliMagFCheb::SaveData(const char* outfile) const
798 // writes coefficients data to output text file
799 TString strf = outfile;
800 gSystem->ExpandPathName(strf);
801 FILE* stream = fopen(strf,"w+");
803 // Sol part ---------------------------------------------------------
804 fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName());
805 fprintf(stream,"START SOLENOID\n#Number of pieces\n%d\n",fNParamsSol);
806 for (int ip=0;ip<fNParamsSol;ip++) GetParamSol(ip)->SaveData(stream);
807 fprintf(stream,"#\nEND SOLENOID\n");
809 // TPCInt part ---------------------------------------------------------
810 fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName());
811 fprintf(stream,"START TPCINT\n#Number of pieces\n%d\n",fNParamsTPCInt);
812 for (int ip=0;ip<fNParamsTPCInt;ip++) GetParamTPCInt(ip)->SaveData(stream);
813 fprintf(stream,"#\nEND TPCINT\n");
815 // Dip part ---------------------------------------------------------
816 fprintf(stream,"START DIPOLE\n#Number of pieces\n%d\n",fNParamsDip);
817 for (int ip=0;ip<fNParamsDip;ip++) GetParamDip(ip)->SaveData(stream);
818 fprintf(stream,"#\nEND DIPOLE\n");
820 fprintf(stream,"#\nEND %s\n",GetName());
826 Int_t AliMagFCheb::SegmentDipDimension(float** seg,const TObjArray* par,int npar, int dim,
827 float xmn,float xmx,float ymn,float ymx,float zmn,float zmx)
829 // find all boundaries in deimension dim for boxes in given region.
830 // if mn>mx for given projection the check is not done for it.
831 float *tmpC = new float[2*npar];
832 int *tmpInd = new int[2*npar];
834 for (int ip=0;ip<npar;ip++) {
835 AliCheb3D* cheb = (AliCheb3D*) par->At(ip);
836 if (xmn<xmx && (cheb->GetBoundMin(0)>(xmx+xmn)/2 || cheb->GetBoundMax(0)<(xmn+xmx)/2)) continue;
837 if (ymn<ymx && (cheb->GetBoundMin(1)>(ymx+ymn)/2 || cheb->GetBoundMax(1)<(ymn+ymx)/2)) continue;
838 if (zmn<zmx && (cheb->GetBoundMin(2)>(zmx+zmn)/2 || cheb->GetBoundMax(2)<(zmn+zmx)/2)) continue;
840 tmpC[nseg0++] = cheb->GetBoundMin(dim);
841 tmpC[nseg0++] = cheb->GetBoundMax(dim);
843 // range Dim's boundaries in increasing order
844 TMath::Sort(nseg0,tmpC,tmpInd,kFALSE);
845 // count number of really different Z's
848 for (int ip=0;ip<nseg0;ip++) {
849 if (TMath::Abs(cprev-tmpC[ tmpInd[ip] ])>1e-4) {
850 cprev = tmpC[ tmpInd[ip] ];
853 else tmpInd[ip] = -1; // supress redundant Z
856 *seg = new float[nseg]; // create final Z segmenations
858 for (int ip=0;ip<nseg0;ip++) if (tmpInd[ip]>=0) (*seg)[nseg++] = tmpC[ tmpInd[ip] ];