]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagWrapCheb.h
Moved old AliMagFCheb to AliMagF, small fixes/optimizations in field classes
[u/mrichter/AliRoot.git] / STEER / AliMagWrapCheb.h
1
2 // Author: ruben.shahoyan@cern.ch   20/03/2007
3
4 ///////////////////////////////////////////////////////////////////////////////////
5 //                                                                               //
6 //  Wrapper for the set of mag.field parameterizations by Chebyshev polinomials  //
7 //  To obtain the field in cartesian coordinates/components use                  //
8 //    Field(double* xyz, double* bxyz);                                          //
9 //  For cylindrical coordinates/components:                                      //
10 //    FieldCyl(double* rphiz, double* brphiz)                                    //
11 //                                                                               //
12 //  The solenoid part is parameterized in the volume  R<500, -550<Z<550 cm       //
13 //                                                                               //
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)                //
17 //                                                                               //
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.                              //
25 //                                                                               //
26 //  To obtain the field integral in the TPC region from given point to nearest   //
27 //  cathod plane (+- 250 cm) use:                                                //
28 //  GetTPCInt(double* xyz, double* bxyz);  for Cartesian frame                   //
29 //  or                                                                           //
30 //  GetTPCIntCyl(Double_t *rphiz, Double_t *b); for Cylindrical frame            //
31 //                                                                               //
32 //                                                                               //
33 //  The units are kiloGauss and cm.                                              //
34 //                                                                               //
35 ///////////////////////////////////////////////////////////////////////////////////
36
37 #ifndef ALIMAGWRAPCHEB_H
38 #define ALIMAGWRAPCHEB_H
39
40 #include <TMath.h>
41 #include <TNamed.h>
42 #include "AliCheb3D.h"
43
44 class TSystem;
45 class TArrayF;
46 class TArrayI;
47
48 class AliMagWrapCheb: public TNamed
49 {
50  public:
51   AliMagWrapCheb();
52   AliMagWrapCheb(const AliMagWrapCheb& src);
53   ~AliMagWrapCheb() {Clear();}
54   //
55   void       CopyFrom(const AliMagWrapCheb& src);
56   AliMagWrapCheb& operator=(const AliMagWrapCheb& rhs);
57   virtual void Clear(const Option_t * = "");
58   //
59   Int_t      GetNParamsSol()                              const {return fNParamsSol;}
60   Int_t      GetNSegZSol()                                const {return fNSegZSol;}
61   Float_t*   GetSegZSol() const {return fSegZSol;}
62   //
63   Int_t      GetNParamsTPCInt()                           const {return fNParamsTPCInt;}
64   Int_t      GetNSegZTPCInt()                             const {return fNSegZTPCInt;}
65   //
66   Int_t      GetNParamsDip()                              const {return fNParamsDip;}
67   Int_t      GetNSegZDip()                                const {return fNZSegDip;}
68   //
69   //
70   Float_t    GetMinZSol()                                 const {return fMinZSol;}
71   Float_t    GetMaxZSol()                                 const {return fMaxZSol;}
72   Float_t    GetMaxRSol()                                 const {return fMaxRSol;}
73   //
74   Float_t    GetMinZDip()                                 const {return fMinZDip;}
75   Float_t    GetMaxZDip()                                 const {return fMaxZDip;}
76   //
77   Float_t    GetMinZTPCInt()                              const {return fMinZTPCInt;}
78   Float_t    GetMaxZTPCInt()                              const {return fMaxZTPCInt;}
79   Float_t    GetMaxRTPCInt()                              const {return fMaxRTPCInt;}
80   //
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);}
84   //
85   virtual void Print(Option_t * = "")                     const;
86   //
87   virtual void Field(const Double_t *xyz, Double_t *b)    const;
88   Double_t     GetBz(const Double_t *xyz)                 const;
89   //
90   void FieldCyl(const Double_t *rphiz, Double_t  *b)      const;
91   void GetTPCInt(const Double_t *xyz, Double_t *b)        const;
92   void GetTPCIntCyl(const Double_t *rphiz, Double_t *b)   const;
93   //
94   Int_t       FindDipSegment(const Double_t *xyz)         const; 
95   static void CylToCartCylB(const Double_t *rphiz, const Double_t *brphiz,Double_t *bxyz);
96   static void CylToCartCartB(const Double_t *xyz,  const Double_t *brphiz,Double_t *bxyz);
97   static void CartToCylCartB(const Double_t *xyz,  const Double_t *bxyz,  Double_t *brphiz);
98   static void CartToCylCylB(const Double_t *rphiz, const Double_t *bxyz,  Double_t *brphiz);
99   static void CartToCyl(const Double_t *xyz,  Double_t *rphiz);
100   static void CylToCart(const Double_t *rphiz,Double_t *xyz);
101   //
102 #ifdef  _INC_CREATION_ALICHEB3D_                          // see AliCheb3D.h for explanation
103   void         LoadData(const char* inpfile);
104   //
105   AliMagWrapCheb(const char* inputFile);
106   void       SaveData(const char* outfile)                const;
107   Int_t      SegmentDipDimension(Float_t** seg,const TObjArray* par,int npar, int dim, 
108                                  Float_t xmn,Float_t xmx,Float_t ymn,Float_t ymx,Float_t zmn,Float_t zmx);
109   //
110   void       AddParamSol(const AliCheb3D* param);
111   void       AddParamTPCInt(const AliCheb3D* param);
112   void       AddParamDip(const AliCheb3D* param);
113   void       BuildTableDip();
114   void       BuildTableSol();
115   void       BuildTableTPCInt();
116   void       ResetTPCInt();
117   //
118   //
119 #endif
120   //
121  protected:
122   void     FieldCylSol(const Double_t *rphiz, Double_t *b)    const;
123   Double_t FieldCylSolBz(const Double_t *rphiz)               const;
124   //
125  protected:
126   //
127   Int_t      fNParamsSol;            // Total number of parameterization pieces for Sol 
128   Int_t      fNSegZSol;              // Number of segments in Z for Solenoid field
129   //
130   Int_t      fNParamsTPCInt;         // Total number of parameterization pieces for TPC field integral 
131   Int_t      fNSegZTPCInt;           // Number of segments in Z for TPC field integral
132   //
133   Int_t      fNParamsDip;            // Total number of parameterization pieces for dipole 
134   Int_t      fNZSegDip;              // number of distinct Z segments in Dipole
135   Int_t      fNYSegDip;              // number of distinct Y segments in Dipole
136   Int_t      fNXSegDip;              // number of distinct X segments in Dipole
137   //
138   Float_t*   fSegZSol;               //[fNSegZSol]      upper boundaries of Z segments
139   Float_t*   fSegRSol;               //[fNParamsSol]    upper boundaries of R segments
140   //
141   Float_t*   fSegZTPCInt;            //[fNSegZTPCInt]    upper boundaries of Z segments
142   Float_t*   fSegRTPCInt;            //[fNParamsTPCInt]  upper boundaries of R segments
143   //
144   Float_t*   fSegZDip;               //[fNZSegDip] coordinates of distinct Z segments in Dipole
145   Float_t*   fSegYDip;               //[fNYSegDip] coordinated of Y segments for each Zsegment in Dipole
146   Float_t*   fSegXDip;               //[fNXSegDip] coordinated of X segments for each Ysegment in Dipole
147   //
148   Int_t*     fNSegRSol;              //[fNSegZSol]      number of R segments for each Z segment
149   Int_t*     fSegZIdSol;             //[fNSegZSol]      Id of the first R segment of each Z segment in the fSegRSol...
150   //
151   Int_t*     fNSegRTPCInt;           //[fNSegZTPCInt]   number of R segments for each Z segment
152   Int_t*     fSegZIdTPCInt;          //[fNSegZTPCInt]   Id of the first R segment of each Z segment in the fSegRTPCInt...
153   //
154   Int_t*     fBegSegYDip;            //[fNZSegDip] beginning of Y segments array for each Z segment
155   Int_t*     fNSegYDip;              //[fNZSegDip] number of Y segments for each Z segment
156   Int_t*     fBegSegXDip;            //[fNYSegDip] beginning of X segments array for each Y segment
157   Int_t*     fNSegXDip;              //[fNYSegDip] number of X segments for each Y segment
158   Int_t*     fSegIDDip;              //[fNXSegDip] ID of the dipole parameterization for given XYZ segment
159   //
160   Float_t    fMinZSol;               // Min Z of Sol parameterization (in CYL. coordinates)
161   Float_t    fMaxZSol;               // Max Z of Sol parameterization (in CYL. coordinates)
162   Float_t    fMaxRSol;               // Max R of Sol parameterization (in CYL. coordinates)
163   //
164   Float_t    fMinZDip;               // Min Z of Dipole parameterization
165   Float_t    fMaxZDip;               // Max Z of Dipole parameterization
166   //
167   Float_t    fMinZTPCInt;            // Min Z of TPCInt parameterization (in CYL. coordinates)
168   Float_t    fMaxZTPCInt;            // Max Z of TPCInt parameterization (in CYL. coordinates)
169   Float_t    fMaxRTPCInt;            // Max R of TPCInt parameterization (in CYL. coordinates)
170   // 
171   TObjArray* fParamsSol;             // Parameterization pieces for Solenoid field
172   TObjArray* fParamsDip;             // Parameterization pieces for Dipole field
173   TObjArray* fParamsTPCInt;          // Parameterization pieces for Solenoid field integrals in TPC region
174   //
175   ClassDef(AliMagWrapCheb,4)         // Wrapper class for the set of Chebishev parameterizations of Alice mag.field
176   //
177  };
178
179
180 //__________________________________________________________________________________________
181 inline void AliMagWrapCheb::FieldCyl(const Double_t *rphiz, Double_t *b) const
182 {
183   // compute field in Cylindircal coordinates
184   //  if (rphiz[2]<GetMinZSol() || rphiz[2]>GetMaxZSol() || rphiz[0]>GetMaxRSol()) {for (int i=3;i--;) b[i]=0; return;}
185   FieldCylSol(rphiz,b);
186 }
187
188 //__________________________________________________________________________________________________
189 inline void AliMagWrapCheb::CylToCartCylB(const Double_t *rphiz, const Double_t *brphiz,Double_t *bxyz)
190 {
191   // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
192   Double_t btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
193   Double_t psiPLUSphi = TMath::ATan2(brphiz[1],brphiz[0]) + rphiz[1];
194   bxyz[0] = btr*TMath::Cos(psiPLUSphi);
195   bxyz[1] = btr*TMath::Sin(psiPLUSphi);
196   bxyz[2] = brphiz[2];
197   //
198 }
199
200 //__________________________________________________________________________________________________
201 inline void AliMagWrapCheb::CylToCartCartB(const Double_t* xyz, const Double_t *brphiz, Double_t *bxyz)
202 {
203   // convert field in cylindrical coordinates to cartesian system, point is in cart.system
204   Double_t btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
205   Double_t phiPLUSpsi = TMath::ATan2(xyz[1],xyz[0]) +  TMath::ATan2(brphiz[1],brphiz[0]);
206   bxyz[0] = btr*TMath::Cos(phiPLUSpsi);
207   bxyz[1] = btr*TMath::Sin(phiPLUSpsi);
208   bxyz[2] = brphiz[2];
209   //
210 }
211
212 //__________________________________________________________________________________________________
213 inline void AliMagWrapCheb::CartToCylCartB(const Double_t *xyz, const Double_t *bxyz, Double_t *brphiz)
214 {
215   // convert field in cylindrical coordinates to cartesian system, poin is in cart.system
216   Double_t btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
217   Double_t psiMINphi = TMath::ATan2(bxyz[1],bxyz[0]) - TMath::ATan2(xyz[1],xyz[0]);
218   //
219   brphiz[0] = btr*TMath::Cos(psiMINphi);
220   brphiz[1] = btr*TMath::Sin(psiMINphi);
221   brphiz[2] = bxyz[2];
222   //
223 }
224
225 //__________________________________________________________________________________________________
226 inline void AliMagWrapCheb::CartToCylCylB(const Double_t *rphiz, const Double_t *bxyz, Double_t *brphiz)
227 {
228   // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
229   Double_t btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
230   Double_t psiMINphi =  TMath::ATan2(bxyz[1],bxyz[0]) - rphiz[1];
231   brphiz[0] = btr*TMath::Cos(psiMINphi);
232   brphiz[1] = btr*TMath::Sin(psiMINphi);
233   brphiz[2] = bxyz[2];
234   //
235 }
236
237 //__________________________________________________________________________________________________
238 inline void AliMagWrapCheb::CartToCyl(const Double_t *xyz, Double_t *rphiz)
239 {
240   rphiz[0] = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
241   rphiz[1] = TMath::ATan2(xyz[1],xyz[0]);
242   rphiz[2] = xyz[2];
243 }
244
245 //__________________________________________________________________________________________________
246 inline void AliMagWrapCheb::CylToCart(const Double_t *rphiz, Double_t *xyz)
247 {
248   xyz[0] = rphiz[0]*TMath::Cos(rphiz[1]);
249   xyz[1] = rphiz[0]*TMath::Sin(rphiz[1]);
250   xyz[2] = rphiz[2];
251 }
252
253 #endif