]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliMagWrapCheb.h
speed up with binary search
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliMagWrapCheb.h
CommitLineData
da7cd221 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 //
db83d72f 8// Field(double* xyz, double* bxyz); //
da7cd221 9// For cylindrical coordinates/components: //
db83d72f 10// FieldCyl(double* rphiz, double* brphiz) //
da7cd221 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: //
db83d72f 28// GetTPCInt(double* xyz, double* bxyz); for Cartesian frame //
da7cd221 29// or //
db83d72f 30// GetTPCIntCyl(Double_t *rphiz, Double_t *b); for Cylindrical frame //
da7cd221 31// //
32// //
33// The units are kiloGauss and cm. //
34// //
35///////////////////////////////////////////////////////////////////////////////////
36
a1dde210 37#ifndef ALIMAGWRAPCHEB_H
38#define ALIMAGWRAPCHEB_H
a1dde210 39
da7cd221 40#include <TMath.h>
41#include <TNamed.h>
339fbe23 42#include <TObjArray.h>
d33b1e3a 43#include <TStopwatch.h>
8947c207 44#include "AliCheb3D.h"
a1dde210 45
d33b1e3a 46#ifndef _MAGCHEB_CACHE_
47#define _MAGCHEB_CACHE_ // use to spead up, but then Field calls are not thread safe
48#endif
49
da7cd221 50class TSystem;
51class TArrayF;
52class TArrayI;
a1dde210 53
da7cd221 54class AliMagWrapCheb: public TNamed
a1dde210 55{
da7cd221 56 public:
a1dde210 57 AliMagWrapCheb();
da7cd221 58 AliMagWrapCheb(const AliMagWrapCheb& src);
59 ~AliMagWrapCheb() {Clear();}
60 //
61 void CopyFrom(const AliMagWrapCheb& src);
62 AliMagWrapCheb& operator=(const AliMagWrapCheb& rhs);
63 virtual void Clear(const Option_t * = "");
64 //
65 Int_t GetNParamsSol() const {return fNParamsSol;}
1d18ebe0 66 Int_t GetNSegZSol() const {return fNZSegSol;}
67 Float_t* GetSegZSol() const {return fSegZSol;}
da7cd221 68 //
1d18ebe0 69 Int_t GetNParamsTPCInt() const {return fNParamsTPC;}
70 Int_t GetNSegZTPCInt() const {return fNZSegTPC;}
da7cd221 71 //
47c3d315 72 Int_t GetNParamsTPCRatInt() const {return fNParamsTPCRat;}
73 Int_t GetNSegZTPCRatInt() const {return fNZSegTPCRat;}
74 //
da7cd221 75 Int_t GetNParamsDip() const {return fNParamsDip;}
76 Int_t GetNSegZDip() const {return fNZSegDip;}
77 //
9251fceb 78 Float_t GetMaxZ() const {return GetMaxZSol();}
79 Float_t GetMinZ() const {return fParamsDip ? GetMinZDip() : GetMinZSol();}
da7cd221 80 //
81 Float_t GetMinZSol() const {return fMinZSol;}
82 Float_t GetMaxZSol() const {return fMaxZSol;}
83 Float_t GetMaxRSol() const {return fMaxRSol;}
84 //
85 Float_t GetMinZDip() const {return fMinZDip;}
86 Float_t GetMaxZDip() const {return fMaxZDip;}
87 //
1d18ebe0 88 Float_t GetMinZTPCInt() const {return fMinZTPC;}
89 Float_t GetMaxZTPCInt() const {return fMaxZTPC;}
90 Float_t GetMaxRTPCInt() const {return fMaxRTPC;}
da7cd221 91 //
47c3d315 92 Float_t GetMinZTPCRatInt() const {return fMinZTPCRat;}
93 Float_t GetMaxZTPCRatInt() const {return fMaxZTPCRat;}
94 Float_t GetMaxRTPCRatInt() const {return fMaxRTPCRat;}
95 //
da7cd221 96 AliCheb3D* GetParamSol(Int_t ipar) const {return (AliCheb3D*)fParamsSol->UncheckedAt(ipar);}
47c3d315 97 AliCheb3D* GetParamTPCRatInt(Int_t ipar) const {return (AliCheb3D*)fParamsTPCRat->UncheckedAt(ipar);}
1d18ebe0 98 AliCheb3D* GetParamTPCInt(Int_t ipar) const {return (AliCheb3D*)fParamsTPC->UncheckedAt(ipar);}
da7cd221 99 AliCheb3D* GetParamDip(Int_t ipar) const {return (AliCheb3D*)fParamsDip->UncheckedAt(ipar);}
100 //
101 virtual void Print(Option_t * = "") const;
102 //
db83d72f 103 virtual void Field(const Double_t *xyz, Double_t *b) const;
104 Double_t GetBz(const Double_t *xyz) const;
da7cd221 105 //
47c3d315 106 void FieldCyl(const Double_t *rphiz, Double_t *b) const;
db83d72f 107 void GetTPCInt(const Double_t *xyz, Double_t *b) const;
108 void GetTPCIntCyl(const Double_t *rphiz, Double_t *b) const;
47c3d315 109 void GetTPCRatInt(const Double_t *xyz, Double_t *b) const;
110 void GetTPCRatIntCyl(const Double_t *rphiz, Double_t *b) const;
da7cd221 111 //
1d18ebe0 112 Int_t FindSolSegment(const Double_t *xyz) const;
113 Int_t FindTPCSegment(const Double_t *xyz) const;
47c3d315 114 Int_t FindTPCRatSegment(const Double_t *xyz) const;
db83d72f 115 Int_t FindDipSegment(const Double_t *xyz) const;
116 static void CylToCartCylB(const Double_t *rphiz, const Double_t *brphiz,Double_t *bxyz);
117 static void CylToCartCartB(const Double_t *xyz, const Double_t *brphiz,Double_t *bxyz);
118 static void CartToCylCartB(const Double_t *xyz, const Double_t *bxyz, Double_t *brphiz);
119 static void CartToCylCylB(const Double_t *rphiz, const Double_t *bxyz, Double_t *brphiz);
120 static void CartToCyl(const Double_t *xyz, Double_t *rphiz);
121 static void CylToCart(const Double_t *rphiz,Double_t *xyz);
da7cd221 122 //
123#ifdef _INC_CREATION_ALICHEB3D_ // see AliCheb3D.h for explanation
124 void LoadData(const char* inpfile);
125 //
126 AliMagWrapCheb(const char* inputFile);
db83d72f 127 void SaveData(const char* outfile) const;
1d18ebe0 128 Int_t SegmentDimension(Float_t** seg,const TObjArray* par,int npar, int dim,
129 Float_t xmn,Float_t xmx,Float_t ymn,Float_t ymx,Float_t zmn,Float_t zmx);
da7cd221 130 //
131 void AddParamSol(const AliCheb3D* param);
132 void AddParamTPCInt(const AliCheb3D* param);
47c3d315 133 void AddParamTPCRatInt(const AliCheb3D* param);
da7cd221 134 void AddParamDip(const AliCheb3D* param);
1d18ebe0 135 void BuildTable(Int_t npar,TObjArray *parArr, Int_t &nZSeg, Int_t &nYSeg, Int_t &nXSeg,
136 Float_t &minZ,Float_t &maxZ,Float_t **segZ,Float_t **segY,Float_t **segX,
137 Int_t **begSegY,Int_t **nSegY,Int_t **begSegX,Int_t **nSegX,Int_t **segID);
da7cd221 138 void BuildTableSol();
1d18ebe0 139 void BuildTableDip();
da7cd221 140 void BuildTableTPCInt();
47c3d315 141 void BuildTableTPCRatInt();
da7cd221 142 void ResetTPCInt();
47c3d315 143 void ResetTPCRatInt();
8947c207 144 void ResetSol();
145 void ResetDip();
da7cd221 146 //
147 //
148#endif
a1dde210 149 //
150 protected:
db83d72f 151 void FieldCylSol(const Double_t *rphiz, Double_t *b) const;
152 Double_t FieldCylSolBz(const Double_t *rphiz) const;
da7cd221 153 //
154 protected:
155 //
1d18ebe0 156 Int_t fNParamsSol; // Total number of parameterization pieces for solenoid
157 Int_t fNZSegSol; // number of distinct Z segments in Solenoid
158 Int_t fNPSegSol; // number of distinct P segments in Solenoid
159 Int_t fNRSegSol; // number of distinct R segments in Solenoid
160 Float_t* fSegZSol; //[fNZSegSol] coordinates of distinct Z segments in Solenoid
161 Float_t* fSegPSol; //[fNPSegSol] coordinated of P segments for each Zsegment in Solenoid
162 Float_t* fSegRSol; //[fNRSegSol] coordinated of R segments for each Psegment in Solenoid
163 Int_t* fBegSegPSol; //[fNPSegSol] beginning of P segments array for each Z segment
164 Int_t* fNSegPSol; //[fNZSegSol] number of P segments for each Z segment
165 Int_t* fBegSegRSol; //[fNPSegSol] beginning of R segments array for each P segment
166 Int_t* fNSegRSol; //[fNPSegSol] number of R segments for each P segment
167 Int_t* fSegIDSol; //[fNRSegSol] ID of the solenoid parameterization for given RPZ segment
168 Float_t fMinZSol; // Min Z of Solenoid parameterization
169 Float_t fMaxZSol; // Max Z of Solenoid parameterization
170 TObjArray* fParamsSol; // Parameterization pieces for Solenoid field
171 Float_t fMaxRSol; // max raduis for Solenoid field
172 //
173 Int_t fNParamsTPC; // Total number of parameterization pieces for TPCint
174 Int_t fNZSegTPC; // number of distinct Z segments in TPCint
175 Int_t fNPSegTPC; // number of distinct P segments in TPCint
176 Int_t fNRSegTPC; // number of distinct R segments in TPCint
177 Float_t* fSegZTPC; //[fNZSegTPC] coordinates of distinct Z segments in TPCint
178 Float_t* fSegPTPC; //[fNPSegTPC] coordinated of P segments for each Zsegment in TPCint
179 Float_t* fSegRTPC; //[fNRSegTPC] coordinated of R segments for each Psegment in TPCint
180 Int_t* fBegSegPTPC; //[fNPSegTPC] beginning of P segments array for each Z segment
181 Int_t* fNSegPTPC; //[fNZSegTPC] number of P segments for each Z segment
182 Int_t* fBegSegRTPC; //[fNPSegTPC] beginning of R segments array for each P segment
183 Int_t* fNSegRTPC; //[fNPSegTPC] number of R segments for each P segment
184 Int_t* fSegIDTPC; //[fNRSegTPC] ID of the TPCint parameterization for given RPZ segment
185 Float_t fMinZTPC; // Min Z of TPCint parameterization
186 Float_t fMaxZTPC; // Max Z of TPCint parameterization
187 TObjArray* fParamsTPC; // Parameterization pieces for TPCint field
188 Float_t fMaxRTPC; // max raduis for Solenoid field integral in TPC
da7cd221 189 //
47c3d315 190 Int_t fNParamsTPCRat; // Total number of parameterization pieces for tr.field to Bz integrals in TPC region
191 Int_t fNZSegTPCRat; // number of distinct Z segments in TpcRatInt
192 Int_t fNPSegTPCRat; // number of distinct P segments in TpcRatInt
193 Int_t fNRSegTPCRat; // number of distinct R segments in TpcRatInt
194 Float_t* fSegZTPCRat; //[fNZSegTPCRat] coordinates of distinct Z segments in TpcRatInt
195 Float_t* fSegPTPCRat; //[fNPSegTPCRat] coordinated of P segments for each Zsegment in TpcRatInt
196 Float_t* fSegRTPCRat; //[fNRSegTPCRat] coordinated of R segments for each Psegment in TpcRatInt
197 Int_t* fBegSegPTPCRat; //[fNPSegTPCRat] beginning of P segments array for each Z segment
198 Int_t* fNSegPTPCRat; //[fNZSegTPCRat] number of P segments for each Z segment
199 Int_t* fBegSegRTPCRat; //[fNPSegTPCRat] beginning of R segments array for each P segment
200 Int_t* fNSegRTPCRat; //[fNPSegTPCRat] number of R segments for each P segment
201 Int_t* fSegIDTPCRat; //[fNRSegTPCRat] ID of the TpcRatInt parameterization for given RPZ segment
202 Float_t fMinZTPCRat; // Min Z of TpcRatInt parameterization
203 Float_t fMaxZTPCRat; // Max Z of TpcRatInt parameterization
204 TObjArray* fParamsTPCRat; // Parameterization pieces for TpcRatInt field
205 Float_t fMaxRTPCRat; // max raduis for Solenoid field ratios integral in TPC
206 //
da7cd221 207 Int_t fNParamsDip; // Total number of parameterization pieces for dipole
208 Int_t fNZSegDip; // number of distinct Z segments in Dipole
209 Int_t fNYSegDip; // number of distinct Y segments in Dipole
210 Int_t fNXSegDip; // number of distinct X segments in Dipole
da7cd221 211 Float_t* fSegZDip; //[fNZSegDip] coordinates of distinct Z segments in Dipole
212 Float_t* fSegYDip; //[fNYSegDip] coordinated of Y segments for each Zsegment in Dipole
213 Float_t* fSegXDip; //[fNXSegDip] coordinated of X segments for each Ysegment in Dipole
da7cd221 214 Int_t* fBegSegYDip; //[fNZSegDip] beginning of Y segments array for each Z segment
215 Int_t* fNSegYDip; //[fNZSegDip] number of Y segments for each Z segment
216 Int_t* fBegSegXDip; //[fNYSegDip] beginning of X segments array for each Y segment
217 Int_t* fNSegXDip; //[fNYSegDip] number of X segments for each Y segment
218 Int_t* fSegIDDip; //[fNXSegDip] ID of the dipole parameterization for given XYZ segment
da7cd221 219 Float_t fMinZDip; // Min Z of Dipole parameterization
220 Float_t fMaxZDip; // Max Z of Dipole parameterization
da7cd221 221 TObjArray* fParamsDip; // Parameterization pieces for Dipole field
da7cd221 222 //
d33b1e3a 223#ifdef _MAGCHEB_CACHE_
11aa2294 224 mutable AliCheb3D* fCacheSol; //! last used solenoid patch
225 mutable AliCheb3D* fCacheDip; //! last used dipole patch
226 mutable AliCheb3D* fCacheTPCInt; //! last used patch for TPC integral
227 mutable AliCheb3D* fCacheTPCRat; //! last used patch for TPC normalized integral
d33b1e3a 228#endif
11aa2294 229 //
230 ClassDef(AliMagWrapCheb,8) // Wrapper class for the set of Chebishev parameterizations of Alice mag.field
da7cd221 231 //
232 };
233
234
da7cd221 235//__________________________________________________________________________________________
236inline void AliMagWrapCheb::FieldCyl(const Double_t *rphiz, Double_t *b) const
237{
238 // compute field in Cylindircal coordinates
239 // if (rphiz[2]<GetMinZSol() || rphiz[2]>GetMaxZSol() || rphiz[0]>GetMaxRSol()) {for (int i=3;i--;) b[i]=0; return;}
1d18ebe0 240 b[0] = b[1] = b[2] = 0;
da7cd221 241 FieldCylSol(rphiz,b);
242}
243
244//__________________________________________________________________________________________________
db83d72f 245inline void AliMagWrapCheb::CylToCartCylB(const Double_t *rphiz, const Double_t *brphiz,Double_t *bxyz)
da7cd221 246{
247 // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
db83d72f 248 Double_t btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
249 Double_t psiPLUSphi = TMath::ATan2(brphiz[1],brphiz[0]) + rphiz[1];
da7cd221 250 bxyz[0] = btr*TMath::Cos(psiPLUSphi);
251 bxyz[1] = btr*TMath::Sin(psiPLUSphi);
252 bxyz[2] = brphiz[2];
253 //
254}
255
256//__________________________________________________________________________________________________
db83d72f 257inline void AliMagWrapCheb::CylToCartCartB(const Double_t* xyz, const Double_t *brphiz, Double_t *bxyz)
da7cd221 258{
259 // convert field in cylindrical coordinates to cartesian system, point is in cart.system
db83d72f 260 Double_t btr = TMath::Sqrt(brphiz[0]*brphiz[0]+brphiz[1]*brphiz[1]);
261 Double_t phiPLUSpsi = TMath::ATan2(xyz[1],xyz[0]) + TMath::ATan2(brphiz[1],brphiz[0]);
da7cd221 262 bxyz[0] = btr*TMath::Cos(phiPLUSpsi);
263 bxyz[1] = btr*TMath::Sin(phiPLUSpsi);
264 bxyz[2] = brphiz[2];
265 //
266}
267
268//__________________________________________________________________________________________________
db83d72f 269inline void AliMagWrapCheb::CartToCylCartB(const Double_t *xyz, const Double_t *bxyz, Double_t *brphiz)
da7cd221 270{
271 // convert field in cylindrical coordinates to cartesian system, poin is in cart.system
db83d72f 272 Double_t btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
273 Double_t psiMINphi = TMath::ATan2(bxyz[1],bxyz[0]) - TMath::ATan2(xyz[1],xyz[0]);
da7cd221 274 //
275 brphiz[0] = btr*TMath::Cos(psiMINphi);
276 brphiz[1] = btr*TMath::Sin(psiMINphi);
277 brphiz[2] = bxyz[2];
278 //
279}
280
281//__________________________________________________________________________________________________
db83d72f 282inline void AliMagWrapCheb::CartToCylCylB(const Double_t *rphiz, const Double_t *bxyz, Double_t *brphiz)
da7cd221 283{
284 // convert field in cylindrical coordinates to cartesian system, point is in cyl.system
db83d72f 285 Double_t btr = TMath::Sqrt(bxyz[0]*bxyz[0]+bxyz[1]*bxyz[1]);
286 Double_t psiMINphi = TMath::ATan2(bxyz[1],bxyz[0]) - rphiz[1];
da7cd221 287 brphiz[0] = btr*TMath::Cos(psiMINphi);
288 brphiz[1] = btr*TMath::Sin(psiMINphi);
289 brphiz[2] = bxyz[2];
290 //
291}
a1dde210 292
da7cd221 293//__________________________________________________________________________________________________
db83d72f 294inline void AliMagWrapCheb::CartToCyl(const Double_t *xyz, Double_t *rphiz)
da7cd221 295{
296 rphiz[0] = TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
297 rphiz[1] = TMath::ATan2(xyz[1],xyz[0]);
298 rphiz[2] = xyz[2];
299}
300
301//__________________________________________________________________________________________________
db83d72f 302inline void AliMagWrapCheb::CylToCart(const Double_t *rphiz, Double_t *xyz)
da7cd221 303{
304 xyz[0] = rphiz[0]*TMath::Cos(rphiz[1]);
305 xyz[1] = rphiz[0]*TMath::Sin(rphiz[1]);
306 xyz[2] = rphiz[2];
307}
308
a1dde210 309#endif