2 // Author: ruben.shahoyan@cern.ch 20/03/2007
4 ///////////////////////////////////////////////////////////////////////////////////
6 // Wrapper for the set of mag.field parameterizations by Chebyshev polinomials //
7 // To obtain the field in cartesian coordinates/components use //
8 // Field(float* xyz, float* bxyz); //
9 // For cylindrical coordinates/components: //
10 // FieldCyl(float* rphiz, float* brphiz) //
12 // The solenoid part is parameterized in the volume R<500, -550<Z<550 cm //
14 // The region R<423 cm, -343.3<Z<481.3 for 30kA and -343.3<Z<481.3 for 12kA //
15 // is parameterized using measured data while outside the Tosca calculation //
16 // is used (matched to data on the boundary of the measurements) //
18 // Two options are possible: //
19 // 1) _BRING_TO_BOUNDARY_ is defined in the AliCheb3D: //
20 // If the querried point is outside of the validity region then the field //
21 // at the closest point on the fitted surface is returned. //
22 // 2) _BRING_TO_BOUNDARY_ is not defined in the AliCheb3D: //
23 // If the querried point is outside of the validity region the return //
24 // value for the field components are set to 0. //
26 // To obtain the field integral in the TPC region from given point to nearest //
27 // cathod plane (+- 250 cm) use: //
28 // GetTPCInt(float* xyz, float* bxyz); for Cartesian frame //
30 // GetTPCIntCyl(Float_t *rphiz, Float_t *b); for Cylindrical frame //
33 // The units are kiloGauss and cm. //
35 ///////////////////////////////////////////////////////////////////////////////////
37 #ifndef ALIMAGWRAPCHEB_H
38 #define ALIMAGWRAPCHEB_H
42 #include "AliCheb3D.h"
48 class AliMagWrapCheb: public TNamed
52 AliMagWrapCheb(const AliMagWrapCheb& src);
53 ~AliMagWrapCheb() {Clear();}
55 void CopyFrom(const AliMagWrapCheb& src);
56 AliMagWrapCheb& operator=(const AliMagWrapCheb& rhs);
57 virtual void Clear(const Option_t * = "");
59 Int_t GetNParamsSol() const {return fNParamsSol;}
60 Int_t GetNSegZSol() const {return fNSegZSol;}
61 Float_t* GetSegZSol() const {return fSegZSol;}
63 Int_t GetNParamsTPCInt() const {return fNParamsTPCInt;}
64 Int_t GetNSegZTPCInt() const {return fNSegZTPCInt;}
66 Int_t GetNParamsDip() const {return fNParamsDip;}
67 Int_t GetNSegZDip() const {return fNZSegDip;}
70 Float_t GetMinZSol() const {return fMinZSol;}
71 Float_t GetMaxZSol() const {return fMaxZSol;}
72 Float_t GetMaxRSol() const {return fMaxRSol;}
74 Float_t GetMinZDip() const {return fMinZDip;}
75 Float_t GetMaxZDip() const {return fMaxZDip;}
77 Float_t GetMinZTPCInt() const {return fMinZTPCInt;}
78 Float_t GetMaxZTPCInt() const {return fMaxZTPCInt;}
79 Float_t GetMaxRTPCInt() const {return fMaxRTPCInt;}
81 AliCheb3D* GetParamSol(Int_t ipar) const {return (AliCheb3D*)fParamsSol->UncheckedAt(ipar);}
82 AliCheb3D* GetParamTPCInt(Int_t ipar) const {return (AliCheb3D*)fParamsTPCInt->UncheckedAt(ipar);}
83 AliCheb3D* GetParamDip(Int_t ipar) const {return (AliCheb3D*)fParamsDip->UncheckedAt(ipar);}
85 virtual void Print(Option_t * = "") const;
87 virtual void Field(const Float_t *xyz, Float_t *b) const;
88 virtual void Field(const Double_t *xyz, Double_t *b) const;
90 virtual void FieldCyl(const Float_t *rphiz, Float_t *b) const;
91 virtual void FieldCyl(const Double_t *rphiz, Double_t *b) const;
93 virtual void GetTPCInt(const Float_t *xyz, Float_t *b) const;
94 virtual void GetTPCIntCyl(const Float_t *rphiz, Float_t *b) const;
97 Int_t FindDipSegment(const T *xyz) const;
100 static void CylToCartCylB(const T *rphiz, const T *brphiz,T *bxyz);
102 static void CylToCartCartB(const T *xyz, const T *brphiz,T *bxyz);
104 static void CartToCylCartB(const T *xyz, const T *bxyz, T *brphiz);
106 static void CartToCylCylB(const T *rphiz, const T *bxyz, T *brphiz);
108 static void CartToCyl(const T *xyz, T *rphiz);
110 static void CylToCart(const T *rphiz,T *xyz);
112 #ifdef _INC_CREATION_ALICHEB3D_ // see AliCheb3D.h for explanation
113 void LoadData(const char* inpfile);
115 AliMagWrapCheb(const char* inputFile);
116 void SaveData(const char* outfile) const;
117 Int_t SegmentDipDimension(Float_t** seg,const TObjArray* par,int npar, int dim,
118 Float_t xmn,Float_t xmx,Float_t ymn,Float_t ymx,Float_t zmn,Float_t zmx);
120 void AddParamSol(const AliCheb3D* param);
121 void AddParamTPCInt(const AliCheb3D* param);
122 void AddParamDip(const AliCheb3D* param);
123 void BuildTableDip();
124 void BuildTableSol();
125 void BuildTableTPCInt();
132 virtual void FieldCylSol(const Float_t *rphiz, Float_t *b) const;
133 virtual void FieldCylSol(const Double_t *rphiz, Double_t *b) const;
137 Int_t fNParamsSol; // Total number of parameterization pieces for Sol
138 Int_t fNSegZSol; // Number of segments in Z for Solenoid field
140 Int_t fNParamsTPCInt; // Total number of parameterization pieces for TPC field integral
141 Int_t fNSegZTPCInt; // Number of segments in Z for TPC field integral
143 Int_t fNParamsDip; // Total number of parameterization pieces for dipole
144 Int_t fNZSegDip; // number of distinct Z segments in Dipole
145 Int_t fNYSegDip; // number of distinct Y segments in Dipole
146 Int_t fNXSegDip; // number of distinct X segments in Dipole
148 Float_t* fSegZSol; //[fNSegZSol] upper boundaries of Z segments
149 Float_t* fSegRSol; //[fNParamsSol] upper boundaries of R segments
151 Float_t* fSegZTPCInt; //[fNSegZTPCInt] upper boundaries of Z segments
152 Float_t* fSegRTPCInt; //[fNParamsTPCInt] upper boundaries of R segments
154 Float_t* fSegZDip; //[fNZSegDip] coordinates of distinct Z segments in Dipole
155 Float_t* fSegYDip; //[fNYSegDip] coordinated of Y segments for each Zsegment in Dipole
156 Float_t* fSegXDip; //[fNXSegDip] coordinated of X segments for each Ysegment in Dipole
158 Int_t* fNSegRSol; //[fNSegZSol] number of R segments for each Z segment
159 Int_t* fSegZIdSol; //[fNSegZSol] Id of the first R segment of each Z segment in the fSegRSol...
161 Int_t* fNSegRTPCInt; //[fNSegZTPCInt] number of R segments for each Z segment
162 Int_t* fSegZIdTPCInt; //[fNSegZTPCInt] Id of the first R segment of each Z segment in the fSegRTPCInt...
164 Int_t* fBegSegYDip; //[fNZSegDip] beginning of Y segments array for each Z segment
165 Int_t* fNSegYDip; //[fNZSegDip] number of Y segments for each Z segment
166 Int_t* fBegSegXDip; //[fNYSegDip] beginning of X segments array for each Y segment
167 Int_t* fNSegXDip; //[fNYSegDip] number of X segments for each Y segment
168 Int_t* fSegIDDip; //[fNXSegDip] ID of the dipole parameterization for given XYZ segment
170 Float_t fMinZSol; // Min Z of Sol parameterization (in CYL. coordinates)
171 Float_t fMaxZSol; // Max Z of Sol parameterization (in CYL. coordinates)
172 Float_t fMaxRSol; // Max R of Sol parameterization (in CYL. coordinates)
174 Float_t fMinZDip; // Min Z of Dipole parameterization
175 Float_t fMaxZDip; // Max Z of Dipole parameterization
177 Float_t fMinZTPCInt; // Min Z of TPCInt parameterization (in CYL. coordinates)
178 Float_t fMaxZTPCInt; // Max Z of TPCInt parameterization (in CYL. coordinates)
179 Float_t fMaxRTPCInt; // Max R of TPCInt parameterization (in CYL. coordinates)
181 TObjArray* fParamsSol; // Parameterization pieces for Solenoid field
182 TObjArray* fParamsDip; // Parameterization pieces for Dipole field
183 TObjArray* fParamsTPCInt; // Parameterization pieces for Solenoid field integrals in TPC region
185 ClassDef(AliMagWrapCheb,3) // Wrapper class for the set of Chebishev parameterizations of Alice mag.field
190 //__________________________________________________________________________________________
191 inline void AliMagWrapCheb::FieldCyl(const Float_t *rphiz, Float_t *b) const
193 // compute field in Cylindircal coordinates
194 // if (rphiz[2]<GetMinZSol() || rphiz[2]>GetMaxZSol() || rphiz[0]>GetMaxRSol()) {for (int i=3;i--;) b[i]=0; return;}
195 FieldCylSol(rphiz,b);
199 //__________________________________________________________________________________________
200 inline void AliMagWrapCheb::FieldCyl(const Double_t *rphiz, Double_t *b) const
202 // compute field in Cylindircal coordinates
203 // if (rphiz[2]<GetMinZSol() || rphiz[2]>GetMaxZSol() || rphiz[0]>GetMaxRSol()) {for (int i=3;i--;) b[i]=0; return;}
204 FieldCylSol(rphiz,b);
207 //__________________________________________________________________________________________________
209 inline void AliMagWrapCheb::CylToCartCylB(const T *rphiz, const T *brphiz,T *bxyz)
211 // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
212 T btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
213 T psiPLUSphi = TMath::ATan2(brphiz[1],brphiz[0]) + rphiz[1];
214 bxyz[0] = btr*TMath::Cos(psiPLUSphi);
215 bxyz[1] = btr*TMath::Sin(psiPLUSphi);
220 //__________________________________________________________________________________________________
222 inline void AliMagWrapCheb::CylToCartCartB(const T *xyz, const T *brphiz, T *bxyz)
224 // convert field in cylindrical coordinates to cartesian system, point is in cart.system
225 T btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
226 T phiPLUSpsi = TMath::ATan2(xyz[1],xyz[0]) + TMath::ATan2(brphiz[1],brphiz[0]);
227 bxyz[0] = btr*TMath::Cos(phiPLUSpsi);
228 bxyz[1] = btr*TMath::Sin(phiPLUSpsi);
233 //__________________________________________________________________________________________________
235 inline void AliMagWrapCheb::CartToCylCartB(const T *xyz, const T *bxyz, T *brphiz)
237 // convert field in cylindrical coordinates to cartesian system, poin is in cart.system
238 T btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
239 T psiMINphi = TMath::ATan2(bxyz[1],bxyz[0]) - TMath::ATan2(xyz[1],xyz[0]);
241 brphiz[0] = btr*TMath::Cos(psiMINphi);
242 brphiz[1] = btr*TMath::Sin(psiMINphi);
247 //__________________________________________________________________________________________________
249 inline void AliMagWrapCheb::CartToCylCylB(const T *rphiz, const T *bxyz, T *brphiz)
251 // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
252 T btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
253 T psiMINphi = TMath::ATan2(bxyz[1],bxyz[0]) - rphiz[1];
254 brphiz[0] = btr*TMath::Cos(psiMINphi);
255 brphiz[1] = btr*TMath::Sin(psiMINphi);
260 //__________________________________________________________________________________________________
262 inline void AliMagWrapCheb::CartToCyl(const T *xyz,T *rphiz)
264 rphiz[0] = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
265 rphiz[1] = TMath::ATan2(xyz[1],xyz[0]);
269 //__________________________________________________________________________________________________
271 inline void AliMagWrapCheb::CylToCart(const T *rphiz, T *xyz)
273 xyz[0] = rphiz[0]*TMath::Cos(rphiz[1]);
274 xyz[1] = rphiz[0]*TMath::Sin(rphiz[1]);
278 //__________________________________________________________________________________________________
280 Int_t AliMagWrapCheb::FindDipSegment(const T *xyz) const
282 // find the segment containing point xyz. If it is outside find the closest segment
283 int xid,yid,zid = TMath::BinarySearch(fNZSegDip,fSegZDip,(Float_t)xyz[2]); // find zsegment
284 int ysegBeg = fBegSegYDip[zid];
286 for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break;
287 if ( --yid < 0 ) yid = 0;
290 int xsegBeg = fBegSegXDip[yid];
291 for (xid=0;xid<fNSegXDip[yid];xid++) if (xyz[0]<fSegXDip[xsegBeg+xid]) break;
292 if ( --xid < 0) xid = 0;
295 return fSegIDDip[xid];