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