1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 #include "AliMagWrapCheb.h"
21 ClassImp(AliMagWrapCheb)
23 //__________________________________________________________________________________________
24 AliMagWrapCheb::AliMagWrapCheb() :
73 // default constructor
76 //__________________________________________________________________________________________
77 AliMagWrapCheb::AliMagWrapCheb(const AliMagWrapCheb& src) :
130 //__________________________________________________________________________________________
131 void AliMagWrapCheb::CopyFrom(const AliMagWrapCheb& src)
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;
143 fNZSegDip = src.fNZSegDip;
144 fNYSegDip = src.fNYSegDip;
145 fNXSegDip = src.fNXSegDip;
147 fMinZSol = src.fMinZSol;
148 fMaxZSol = src.fMaxZSol;
149 fMaxRSol = src.fMaxRSol;
151 fMinZDip = src.fMinZDip;
152 fMaxZDip = src.fMaxZDip;
154 fMinZTPCInt = src.fMinZTPCInt;
155 fMaxZTPCInt = src.fMaxZTPCInt;
156 fMaxRTPCInt = src.fMaxRTPCInt;
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);
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);
170 memcpy(fSegXDip = new Float_t[fNXSegDip], src.fSegZDip, sizeof(Float_t)*fNXSegDip);
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);
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);
191 //__________________________________________________________________________________________
192 AliMagWrapCheb& AliMagWrapCheb::operator=(const AliMagWrapCheb& rhs)
203 //__________________________________________________________________________________________
204 void AliMagWrapCheb::Clear(const Option_t *)
206 // clear all dynamic parts
215 if (fNParamsTPCInt) {
216 delete fParamsTPCInt;
217 delete[] fSegZTPCInt;
218 delete[] fSegRTPCInt;
219 delete[] fNSegRTPCInt;
220 delete[] fSegZIdTPCInt;
228 delete[] fBegSegYDip;
230 delete[] fBegSegXDip;
234 fNParamsSol = fNParamsTPCInt = fNParamsDip = fNZSegDip = fNYSegDip = fNXSegDip = 0;
235 fNSegZSol = fNSegZTPCInt = 0;
236 fMinZSol = fMinZDip = fMinZTPCInt = 1e6;
237 fMaxZSol = fMaxZDip = fMaxZTPCInt = fMaxRSol = fMaxRTPCInt = -1e6;
241 //__________________________________________________________________________________________
242 void AliMagWrapCheb::Field(const Double_t *xyz, Double_t *b) const
244 // compute field in cartesian coordinates. If point is outside of the parameterized region
245 // get it at closest valid point
246 static Double_t rphiz[3];
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;}
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;
259 GetParamDip(FindDipSegment(xyz))->Eval(xyz,b); return;
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;}
269 FieldCylSol(rphiz,b);
271 // convert field to cartesian system
272 CylToCartCylB(rphiz, b,b);
276 //__________________________________________________________________________________________
277 Double_t AliMagWrapCheb::GetBz(const Double_t *xyz) const
279 // compute Bz for the point in cartesian coordinates. If point is outside of the parameterized region
280 // get it at closest valid point
281 static Double_t rphiz[3];
283 #ifndef _BRING_TO_BOUNDARY_ // exact matching to fitted volume is requested
284 if ( !(xyz[2]>=GetMinZSol()&&xyz[2]<=GetMaxZSol()) &&
285 !(xyz[2]>=GetMinZDip()&&xyz[2]<=GetMaxZDip()) ) return 0.;
288 if (xyz[2]<fMaxZDip) { // dipole part?
289 #ifndef _BRING_TO_BOUNDARY_
290 AliCheb3D* par = GetParamDip(FindDipSegment(xyz));
291 if (par->IsInside(xyz)) return par->Eval(xyz,2);
294 return GetParamDip(FindDipSegment(xyz))->Eval(xyz,2);
297 // Sol region: convert coordinates to cyl system
298 CartToCyl(xyz,rphiz);
299 #ifndef _BRING_TO_BOUNDARY_
300 if (rphiz[0]>GetMaxRSol()) return 0.;
303 return FieldCylSolBz(rphiz);
307 //__________________________________________________________________________________________
308 void AliMagWrapCheb::Print(Option_t *) const
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);
314 if (fParamsSol) fParamsSol->Print();
316 for (int iz=0;iz<fNSegZSol;iz++) {
317 AliCheb3D* param = GetParamSol( fSegZIdSol[iz] );
318 printf("*** Z Segment %2d (%+7.2f<Z<%+7.2f)\t***\n",iz,param->GetBoundMin(2),param->GetBoundMax(2));
319 for (int ir=0;ir<fNSegRSol[iz];ir++) {
320 param = GetParamSol( fSegZIdSol[iz]+ir );
321 printf(" R Segment %2d (%+7.2f<R<%+7.2f, Precision: %.1e) (ID=%2d)\n",ir, param->GetBoundMin(0),
322 param->GetBoundMax(0),param->GetPrecision(),fSegZIdSol[iz]+ir);
327 printf("Segmentation for TPC field integral (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZTPCInt,fMaxZTPCInt,fMaxRTPCInt);
329 if (fParamsTPCInt) fParamsTPCInt->Print();
331 for (int iz=0;iz<fNSegZTPCInt;iz++) {
332 AliCheb3D* param = GetParamTPCInt( fSegZIdTPCInt[iz] );
333 printf("*** Z Segment %2d (%+7.2f<Z<%+7.2f)\t***\n",iz,param->GetBoundMin(2),param->GetBoundMax(2));
334 for (int ir=0;ir<fNSegRTPCInt[iz];ir++) {
335 param = GetParamTPCInt( fSegZIdTPCInt[iz]+ir );
336 printf(" R Segment %2d (%+7.2f<R<%+7.2f, Precision: %.1e) (ID=%2d)\n",ir, param->GetBoundMin(0),
337 param->GetBoundMax(0),param->GetPrecision(),fSegZIdTPCInt[iz]+ir);
342 printf("Segmentation for Dipole (%+.2f<Z<%+.2f cm)\n",fMinZDip,fMaxZDip);
343 if (fParamsDip) fParamsDip->Print();
350 //__________________________________________________________________________________________________
351 Int_t AliMagWrapCheb::FindDipSegment(const Double_t *xyz) const
353 // find the segment containing point xyz. If it is outside find the closest segment
354 int xid,yid,zid = TMath::BinarySearch(fNZSegDip,fSegZDip,(Float_t)xyz[2]); // find zsegment
355 int ysegBeg = fBegSegYDip[zid];
357 for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break;
358 if ( --yid < 0 ) yid = 0;
361 int xsegBeg = fBegSegXDip[yid];
362 for (xid=0;xid<fNSegXDip[yid];xid++) if (xyz[0]<fSegXDip[xsegBeg+xid]) break;
363 if ( --xid < 0) xid = 0;
366 return fSegIDDip[xid];
369 //__________________________________________________________________________________________
370 void AliMagWrapCheb::GetTPCInt(const Double_t *xyz, Double_t *b) const
372 // compute TPC region field integral in cartesian coordinates.
373 // If point is outside of the parameterized region get it at closeset valid point
374 static Double_t rphiz[3];
377 // convert coordinates to cyl system
378 CartToCyl(xyz,rphiz);
379 #ifndef _BRING_TO_BOUNDARY_
380 if ( (rphiz[2]>GetMaxZTPCInt()||rphiz[2]<GetMinZTPCInt()) ||
381 rphiz[0]>GetMaxRTPCInt()) {for (int i=3;i--;) b[i]=0; return;}
384 GetTPCIntCyl(rphiz,b);
386 // convert field to cartesian system
387 CylToCartCylB(rphiz, b,b);
391 //__________________________________________________________________________________________
392 void AliMagWrapCheb::FieldCylSol(const Double_t *rphiz, Double_t *b) const
394 // compute Solenoid field in Cylindircal coordinates
395 // note: if the point is outside the volume get the field in closest parameterized point
397 while (rphiz[2]>fSegZSol[SolZId] && SolZId<fNSegZSol-1) ++SolZId; // find Z segment
398 int SolRId = fSegZIdSol[SolZId]; // first R segment for this Z
399 int SolRMax = SolRId + fNSegRSol[SolZId];
400 while (rphiz[0]>fSegRSol[SolRId] && SolRId<SolRMax-1) ++SolRId; // find R segment
401 GetParamSol( SolRId )->Eval(rphiz,b);
405 //__________________________________________________________________________________________
406 Double_t AliMagWrapCheb::FieldCylSolBz(const Double_t *rphiz) const
408 // compute Solenoid field in Cylindircal coordinates
409 // note: if the point is outside the volume get the field in closest parameterized point
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 return GetParamSol( SolRId )->Eval(rphiz,2);
419 //__________________________________________________________________________________________
420 void AliMagWrapCheb::GetTPCIntCyl(const Double_t *rphiz, Double_t *b) const
422 // compute field integral in TPC region in Cylindircal coordinates
423 // note: the check for the point being inside the parameterized region is done outside
425 while (rphiz[2]>fSegZTPCInt[tpcIntZId] && tpcIntZId<fNSegZTPCInt) ++tpcIntZId; // find Z segment
426 int tpcIntRId = fSegZIdTPCInt[tpcIntZId]; // first R segment for this Z
427 int tpcIntRIdMax = tpcIntRId + fNSegRTPCInt[tpcIntZId];
428 while (rphiz[0]>fSegRTPCInt[tpcIntRId] && tpcIntRId<tpcIntRIdMax) ++tpcIntRId; // find R segment
429 GetParamTPCInt( tpcIntRId )->Eval(rphiz,b);
434 #ifdef _INC_CREATION_ALICHEB3D_
435 //_______________________________________________
436 void AliMagWrapCheb::LoadData(const char* inpfile)
438 // read coefficients data from the text file
440 TString strf = inpfile;
441 gSystem->ExpandPathName(strf);
442 FILE* stream = fopen(strf,"r");
444 printf("Did not find input file %s\n",strf.Data());
449 AliCheb3DCalc::ReadLine(buffs,stream);
450 if (!buffs.BeginsWith("START")) {
451 Error("LoadData","Expected: \"START <name>\", found \"%s\"\nStop\n",buffs.Data());
454 if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1);
456 // Solenoid part -----------------------------------------------------------
457 AliCheb3DCalc::ReadLine(buffs,stream);
458 if (!buffs.BeginsWith("START SOLENOID")) {
459 Error("LoadData","Expected: \"START SOLENOID\", found \"%s\"\nStop\n",buffs.Data());
462 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
463 int nparSol = buffs.Atoi();
465 for (int ip=0;ip<nparSol;ip++) {
466 AliCheb3D* cheb = new AliCheb3D();
467 cheb->LoadData(stream);
471 AliCheb3DCalc::ReadLine(buffs,stream);
472 if (!buffs.BeginsWith("END SOLENOID")) {
473 Error("LoadData","Expected \"END SOLENOID\", found \"%s\"\nStop\n",buffs.Data());
477 // TPCInt part -----------------------------------------------------------
478 AliCheb3DCalc::ReadLine(buffs,stream);
479 if (!buffs.BeginsWith("START TPCINT")) {
480 Error("LoadData","Expected: \"START TPCINT\", found \"%s\"\nStop\n",buffs.Data());
483 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
484 int nparTPCInt = buffs.Atoi();
486 for (int ip=0;ip<nparTPCInt;ip++) {
487 AliCheb3D* cheb = new AliCheb3D();
488 cheb->LoadData(stream);
489 AddParamTPCInt(cheb);
492 AliCheb3DCalc::ReadLine(buffs,stream);
493 if (!buffs.BeginsWith("END TPCINT")) {
494 Error("LoadData","Expected \"END TPCINT\", found \"%s\"\nStop\n",buffs.Data());
498 // Dipole part -----------------------------------------------------------
499 AliCheb3DCalc::ReadLine(buffs,stream);
500 if (!buffs.BeginsWith("START DIPOLE")) {
501 Error("LoadData","Expected: \"START DIPOLE\", found \"%s\"\nStop\n",buffs.Data());
504 AliCheb3DCalc::ReadLine(buffs,stream); // nparam
505 int nparDip = buffs.Atoi();
507 for (int ip=0;ip<nparDip;ip++) {
508 AliCheb3D* cheb = new AliCheb3D();
509 cheb->LoadData(stream);
513 AliCheb3DCalc::ReadLine(buffs,stream);
514 if (!buffs.BeginsWith("END DIPOLE")) {
515 Error("LoadData","Expected \"END DIPOLE\", found \"%s\"\nStop\n",GetName(),buffs.Data());
519 AliCheb3DCalc::ReadLine(buffs,stream);
520 if (!buffs.BeginsWith("END") || !buffs.Contains(GetName())) {
521 Error("LoadData","Expected: \"END %s\", found \"%s\"\nStop\n",GetName(),buffs.Data());
525 // ---------------------------------------------------------------------------
530 printf("Loaded magnetic field \"%s\" from %s\n",GetName(),strf.Data());
535 //_______________________________________________
536 #ifdef _INC_CREATION_ALICHEB3D_
538 //__________________________________________________________________________________________
539 AliMagWrapCheb::AliMagWrapCheb(const char* inputFile) :
589 // construct from coeffs from the text file
593 //__________________________________________________________________________________________
594 void AliMagWrapCheb::AddParamSol(const AliCheb3D* param)
596 // adds new parameterization piece for Sol
597 // NOTE: pieces must be added strictly in increasing R then increasing Z order
599 if (!fParamsSol) fParamsSol = new TObjArray();
600 fParamsSol->Add( (AliCheb3D*)param );
605 //__________________________________________________________________________________________
606 void AliMagWrapCheb::AddParamTPCInt(const AliCheb3D* param)
608 // adds new parameterization piece for TPCInt
609 // NOTE: pieces must be added strictly in increasing R then increasing Z order
611 if (!fParamsTPCInt) fParamsTPCInt = new TObjArray();
612 fParamsTPCInt->Add( (AliCheb3D*)param);
617 //__________________________________________________________________________________________
618 void AliMagWrapCheb::AddParamDip(const AliCheb3D* param)
620 // adds new parameterization piece for Dipole
622 if (!fParamsDip) fParamsDip = new TObjArray();
623 fParamsDip->Add( (AliCheb3D*)param);
628 //__________________________________________________________________________________________
629 void AliMagWrapCheb::ResetTPCInt()
631 // clean TPC field integral (used for update)
632 if (!fNParamsTPCInt) return;
633 delete fParamsTPCInt;
634 delete[] fSegZTPCInt;
635 delete[] fSegRTPCInt;
636 delete[] fNSegRTPCInt;
637 delete[] fSegZIdTPCInt;
652 //__________________________________________________
653 void AliMagWrapCheb::BuildTableDip()
655 // build lookup table for dipole
658 TArrayI begSegYDip,begSegXDip;
659 TArrayI nsegYDip,nsegXDip;
661 float *tmpSegZ,*tmpSegY,*tmpSegX;
663 // create segmentation in Z
664 fNZSegDip = SegmentDipDimension(&tmpSegZ, fParamsDip, fNParamsDip, 2, 1,-1, 1,-1, 1,-1) - 1;
668 // for each Z slice create segmentation in Y
669 begSegYDip.Set(fNZSegDip);
670 nsegYDip.Set(fNZSegDip);
672 for (int iz=0;iz<fNZSegDip;iz++) {
673 printf("\nZSegment#%d %+e : %+e\n",iz,tmpSegZ[iz],tmpSegZ[iz+1]);
674 int ny = SegmentDipDimension(&tmpSegY, fParamsDip, fNParamsDip, 1,
675 1,-1, 1,-1, tmpSegZ[iz],tmpSegZ[iz+1]) - 1;
676 segY.Set(ny + fNYSegDip);
677 for (int iy=0;iy<ny;iy++) segY[fNYSegDip+iy] = tmpSegY[iy];
678 begSegYDip[iz] = fNYSegDip;
680 printf(" Found %d YSegments, to start from %d\n",ny, begSegYDip[iz]);
682 // for each slice in Z and Y create segmentation in X
683 begSegXDip.Set(fNYSegDip+ny);
684 nsegXDip.Set(fNYSegDip+ny);
685 xyz[2] = (tmpSegZ[iz]+tmpSegZ[iz+1])/2.; // mean Z of this segment
687 for (int iy=0;iy<ny;iy++) {
688 int isg = fNYSegDip+iy;
689 printf("\n YSegment#%d %+e : %+e\n",iy, tmpSegY[iy],tmpSegY[iy+1]);
690 int nx = SegmentDipDimension(&tmpSegX, fParamsDip, fNParamsDip, 0,
691 1,-1, tmpSegY[iy],tmpSegY[iy+1], tmpSegZ[iz],tmpSegZ[iz+1]) - 1;
693 segX.Set(nx + fNXSegDip);
694 for (int ix=0;ix<nx;ix++) segX[fNXSegDip+ix] = tmpSegX[ix];
695 begSegXDip[isg] = fNXSegDip;
697 printf(" Found %d XSegments, to start from %d\n",nx, begSegXDip[isg]);
699 segID.Set(fNXSegDip+nx);
701 // find corresponding params
702 xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment
704 for (int ix=0;ix<nx;ix++) {
705 xyz[0] = (tmpSegX[ix]+tmpSegX[ix+1])/2.; // mean X of this segment
706 for (int ipar=0;ipar<fNParamsDip;ipar++) {
707 AliCheb3D* cheb = (AliCheb3D*) fParamsDip->At(ipar);
708 if (!cheb->IsInside(xyz)) continue;
709 segID[fNXSegDip+ix] = ipar;
721 fMinZDip = tmpSegZ[0];
722 fMaxZDip = tmpSegZ[fNZSegDip];
723 fSegZDip = new Float_t[fNZSegDip];
724 for (int i=fNZSegDip;i--;) fSegZDip[i] = tmpSegZ[i];
727 fSegYDip = new Float_t[fNYSegDip];
728 fSegXDip = new Float_t[fNXSegDip];
729 fBegSegYDip = new Int_t[fNZSegDip];
730 fNSegYDip = new Int_t[fNZSegDip];
731 fBegSegXDip = new Int_t[fNYSegDip];
732 fNSegXDip = new Int_t[fNYSegDip];
733 fSegIDDip = new Int_t[fNXSegDip];
735 for (int i=fNYSegDip;i--;) fSegYDip[i] = segY[i];
736 for (int i=fNXSegDip;i--;) fSegXDip[i] = segX[i];
737 for (int i=fNZSegDip;i--;) {fBegSegYDip[i] = begSegYDip[i]; fNSegYDip[i] = nsegYDip[i];}
738 for (int i=fNYSegDip;i--;) {fBegSegXDip[i] = begSegXDip[i]; fNSegXDip[i] = nsegXDip[i];}
739 for (int i=fNXSegDip;i--;) {fSegIDDip[i] = segID[i];}
743 //__________________________________________________________________________________________
744 void AliMagWrapCheb::BuildTableSol()
746 // build the indexes for each parameterization of Solenoid
748 const float kSafety=0.001;
750 if (fNParamsSol<1) return;
753 fSegRSol = new Float_t[fNParamsSol];
754 float *tmpbufF = new float[fNParamsSol+1];
755 int *tmpbufI = new int[fNParamsSol+1];
756 int *tmpbufI1 = new int[fNParamsSol+1];
758 // count number of Z slices and number of R slices in each Z slice
759 for (int ip=0;ip<fNParamsSol;ip++) {
760 if (ip==0 || (GetParamSol(ip)->GetBoundMax(2)-GetParamSol(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice
761 tmpbufF[fNSegZSol] = GetParamSol(ip)->GetBoundMax(2); //
762 tmpbufI[fNSegZSol] = 0;
763 tmpbufI1[fNSegZSol++] = ip;
765 fSegRSol[ip] = GetParamSol(ip)->GetBoundMax(0); // upper R
766 tmpbufI[fNSegZSol-1]++;
767 if (fMaxRSol<fSegRSol[ip]) fMaxRSol = fSegRSol[ip];
770 fSegZSol = new Float_t[fNSegZSol];
771 fSegZIdSol = new Int_t[fNSegZSol];
772 fNSegRSol = new Int_t[fNSegZSol];
773 for (int iz=0;iz<fNSegZSol;iz++) {
774 fSegZSol[iz] = tmpbufF[iz];
775 fNSegRSol[iz] = tmpbufI[iz];
776 fSegZIdSol[iz] = tmpbufI1[iz];
779 fMinZSol = GetParamSol(0)->GetBoundMin(2);
780 fMaxZSol = GetParamSol(fNParamsSol-1)->GetBoundMax(2);
789 //__________________________________________________________________________________________
790 void AliMagWrapCheb::BuildTableTPCInt()
792 // build the indexes for each parameterization of TPC field integral
794 const float kSafety=0.001;
796 if (fNParamsTPCInt<1) return;
798 fSegRTPCInt = new Float_t[fNParamsTPCInt];
799 float *tmpbufF = new float[fNParamsTPCInt+1];
800 int *tmpbufI = new int[fNParamsTPCInt+1];
801 int *tmpbufI1 = new int[fNParamsTPCInt+1];
803 // count number of Z slices and number of R slices in each Z slice
804 for (int ip=0;ip<fNParamsTPCInt;ip++) {
805 if (ip==0 || (GetParamTPCInt(ip)->GetBoundMax(2)-GetParamTPCInt(ip-1)->GetBoundMax(2))>kSafety) { // new Z slice
806 tmpbufF[fNSegZTPCInt] = GetParamTPCInt(ip)->GetBoundMax(2); //
807 tmpbufI[fNSegZTPCInt] = 0;
808 tmpbufI1[fNSegZTPCInt++] = ip;
810 fSegRTPCInt[ip] = GetParamTPCInt(ip)->GetBoundMax(0); // upper R
811 tmpbufI[fNSegZTPCInt-1]++;
814 fSegZTPCInt = new Float_t[fNSegZTPCInt];
815 fSegZIdTPCInt = new Int_t[fNSegZTPCInt];
816 fNSegRTPCInt = new Int_t[fNSegZTPCInt];
817 for (int iz=0;iz<fNSegZTPCInt;iz++) {
818 fSegZTPCInt[iz] = tmpbufF[iz];
819 fNSegRTPCInt[iz] = tmpbufI[iz];
820 fSegZIdTPCInt[iz] = tmpbufI1[iz];
823 fMinZTPCInt = GetParamTPCInt(0)->GetBoundMin(2);
824 fMaxZTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(2);
825 fMaxRTPCInt = GetParamTPCInt(fNParamsTPCInt-1)->GetBoundMax(0);
834 void AliMagWrapCheb::SaveData(const char* outfile) const
836 // writes coefficients data to output text file
837 TString strf = outfile;
838 gSystem->ExpandPathName(strf);
839 FILE* stream = fopen(strf,"w+");
841 // Sol part ---------------------------------------------------------
842 fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName());
843 fprintf(stream,"START SOLENOID\n#Number of pieces\n%d\n",fNParamsSol);
844 for (int ip=0;ip<fNParamsSol;ip++) GetParamSol(ip)->SaveData(stream);
845 fprintf(stream,"#\nEND SOLENOID\n");
847 // TPCInt part ---------------------------------------------------------
848 fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName());
849 fprintf(stream,"START TPCINT\n#Number of pieces\n%d\n",fNParamsTPCInt);
850 for (int ip=0;ip<fNParamsTPCInt;ip++) GetParamTPCInt(ip)->SaveData(stream);
851 fprintf(stream,"#\nEND TPCINT\n");
853 // Dip part ---------------------------------------------------------
854 fprintf(stream,"START DIPOLE\n#Number of pieces\n%d\n",fNParamsDip);
855 for (int ip=0;ip<fNParamsDip;ip++) GetParamDip(ip)->SaveData(stream);
856 fprintf(stream,"#\nEND DIPOLE\n");
858 fprintf(stream,"#\nEND %s\n",GetName());
864 Int_t AliMagWrapCheb::SegmentDipDimension(float** seg,const TObjArray* par,int npar, int dim,
865 float xmn,float xmx,float ymn,float ymx,float zmn,float zmx)
867 // find all boundaries in deimension dim for boxes in given region.
868 // if mn>mx for given projection the check is not done for it.
869 float *tmpC = new float[2*npar];
870 int *tmpInd = new int[2*npar];
872 for (int ip=0;ip<npar;ip++) {
873 AliCheb3D* cheb = (AliCheb3D*) par->At(ip);
874 if (xmn<xmx && (cheb->GetBoundMin(0)>(xmx+xmn)/2 || cheb->GetBoundMax(0)<(xmn+xmx)/2)) continue;
875 if (ymn<ymx && (cheb->GetBoundMin(1)>(ymx+ymn)/2 || cheb->GetBoundMax(1)<(ymn+ymx)/2)) continue;
876 if (zmn<zmx && (cheb->GetBoundMin(2)>(zmx+zmn)/2 || cheb->GetBoundMax(2)<(zmn+zmx)/2)) continue;
878 tmpC[nseg0++] = cheb->GetBoundMin(dim);
879 tmpC[nseg0++] = cheb->GetBoundMax(dim);
881 // range Dim's boundaries in increasing order
882 TMath::Sort(nseg0,tmpC,tmpInd,kFALSE);
883 // count number of really different Z's
886 for (int ip=0;ip<nseg0;ip++) {
887 if (TMath::Abs(cprev-tmpC[ tmpInd[ip] ])>1e-4) {
888 cprev = tmpC[ tmpInd[ip] ];
891 else tmpInd[ip] = -1; // supress redundant Z
894 *seg = new float[nseg]; // create final Z segmenations
896 for (int ip=0;ip<nseg0;ip++) if (tmpInd[ip]>=0) (*seg)[nseg++] = tmpC[ tmpInd[ip] ];