]>
Commit | Line | Data |
---|---|---|
a1dde210 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
a1dde210 | 16 | #include "AliMagWrapCheb.h" |
0f5e1718 | 17 | #include "AliLog.h" |
da7cd221 | 18 | #include <TSystem.h> |
19 | #include <TArrayF.h> | |
20 | #include <TArrayI.h> | |
339fbe23 | 21 | #include <AliCheb3D.h> |
a1dde210 | 22 | |
23 | ClassImp(AliMagWrapCheb) | |
a1dde210 | 24 | |
da7cd221 | 25 | //__________________________________________________________________________________________ |
26 | AliMagWrapCheb::AliMagWrapCheb() : | |
1d18ebe0 | 27 | fNParamsSol(0),fNZSegSol(0),fNPSegSol(0),fNRSegSol(0), |
28 | fSegZSol(0),fSegPSol(0),fSegRSol(0), | |
29 | fBegSegPSol(0),fNSegPSol(0),fBegSegRSol(0),fNSegRSol(0),fSegIDSol(0),fMinZSol(1.e6),fMaxZSol(-1.e6),fParamsSol(0),fMaxRSol(0), | |
da7cd221 | 30 | // |
1d18ebe0 | 31 | fNParamsTPC(0),fNZSegTPC(0),fNPSegTPC(0),fNRSegTPC(0), |
32 | fSegZTPC(0),fSegPTPC(0),fSegRTPC(0), | |
33 | fBegSegPTPC(0),fNSegPTPC(0),fBegSegRTPC(0),fNSegRTPC(0),fSegIDTPC(0),fMinZTPC(1.e6),fMaxZTPC(-1.e6),fParamsTPC(0),fMaxRTPC(0), | |
47c3d315 | 34 | // |
35 | fNParamsTPCRat(0),fNZSegTPCRat(0),fNPSegTPCRat(0),fNRSegTPCRat(0), | |
36 | fSegZTPCRat(0),fSegPTPCRat(0),fSegRTPCRat(0), | |
37 | fBegSegPTPCRat(0),fNSegPTPCRat(0),fBegSegRTPCRat(0),fNSegRTPCRat(0),fSegIDTPCRat(0),fMinZTPCRat(1.e6),fMaxZTPCRat(-1.e6),fParamsTPCRat(0),fMaxRTPCRat(0), | |
da7cd221 | 38 | // |
1d18ebe0 | 39 | fNParamsDip(0),fNZSegDip(0),fNYSegDip(0),fNXSegDip(0), |
40 | fSegZDip(0),fSegYDip(0),fSegXDip(0), | |
41 | fBegSegYDip(0),fNSegYDip(0),fBegSegXDip(0),fNSegXDip(0),fSegIDDip(0),fMinZDip(1.e6),fMaxZDip(-1.e6),fParamsDip(0) | |
da7cd221 | 42 | // |
a1dde210 | 43 | { |
da7cd221 | 44 | // default constructor |
a1dde210 | 45 | } |
46 | ||
da7cd221 | 47 | //__________________________________________________________________________________________ |
48 | AliMagWrapCheb::AliMagWrapCheb(const AliMagWrapCheb& src) : | |
49 | TNamed(src), | |
1d18ebe0 | 50 | fNParamsSol(0),fNZSegSol(0),fNPSegSol(0),fNRSegSol(0), |
51 | fSegZSol(0),fSegPSol(0),fSegRSol(0), | |
52 | fBegSegPSol(0),fNSegPSol(0),fBegSegRSol(0),fNSegRSol(0),fSegIDSol(0),fMinZSol(1.e6),fMaxZSol(-1.e6),fParamsSol(0),fMaxRSol(0), | |
da7cd221 | 53 | // |
1d18ebe0 | 54 | fNParamsTPC(0),fNZSegTPC(0),fNPSegTPC(0),fNRSegTPC(0), |
55 | fSegZTPC(0),fSegPTPC(0),fSegRTPC(0), | |
56 | fBegSegPTPC(0),fNSegPTPC(0),fBegSegRTPC(0),fNSegRTPC(0),fSegIDTPC(0),fMinZTPC(1.e6),fMaxZTPC(-1.e6),fParamsTPC(0),fMaxRTPC(0), | |
47c3d315 | 57 | // |
58 | fNParamsTPCRat(0),fNZSegTPCRat(0),fNPSegTPCRat(0),fNRSegTPCRat(0), | |
59 | fSegZTPCRat(0),fSegPTPCRat(0),fSegRTPCRat(0), | |
60 | fBegSegPTPCRat(0),fNSegPTPCRat(0),fBegSegRTPCRat(0),fNSegRTPCRat(0),fSegIDTPCRat(0),fMinZTPCRat(1.e6),fMaxZTPCRat(-1.e6),fParamsTPCRat(0),fMaxRTPCRat(0), | |
da7cd221 | 61 | // |
1d18ebe0 | 62 | fNParamsDip(0),fNZSegDip(0),fNYSegDip(0),fNXSegDip(0), |
63 | fSegZDip(0),fSegYDip(0),fSegXDip(0), | |
64 | fBegSegYDip(0),fNSegYDip(0),fBegSegXDip(0),fNSegXDip(0),fSegIDDip(0),fMinZDip(1.e6),fMaxZDip(-1.e6),fParamsDip(0) | |
a1dde210 | 65 | { |
da7cd221 | 66 | // copy constructor |
67 | CopyFrom(src); | |
68 | } | |
69 | ||
70 | //__________________________________________________________________________________________ | |
71 | void AliMagWrapCheb::CopyFrom(const AliMagWrapCheb& src) | |
72 | { | |
73 | // copy method | |
74 | Clear(); | |
75 | SetName(src.GetName()); | |
76 | SetTitle(src.GetTitle()); | |
1d18ebe0 | 77 | // |
da7cd221 | 78 | fNParamsSol = src.fNParamsSol; |
1d18ebe0 | 79 | fNZSegSol = src.fNZSegSol; |
80 | fNPSegSol = src.fNPSegSol; | |
81 | fNRSegSol = src.fNRSegSol; | |
82 | fMinZSol = src.fMinZSol; | |
83 | fMaxZSol = src.fMaxZSol; | |
84 | fMaxRSol = src.fMaxRSol; | |
85 | if (src.fNParamsSol) { | |
86 | memcpy(fSegZSol = new Float_t[fNZSegSol], src.fSegZSol, sizeof(Float_t)*fNZSegSol); | |
87 | memcpy(fSegPSol = new Float_t[fNPSegSol], src.fSegPSol, sizeof(Float_t)*fNPSegSol); | |
88 | memcpy(fSegRSol = new Float_t[fNRSegSol], src.fSegRSol, sizeof(Float_t)*fNRSegSol); | |
89 | memcpy(fBegSegPSol= new Int_t[fNZSegSol], src.fBegSegPSol, sizeof(Int_t)*fNZSegSol); | |
90 | memcpy(fNSegPSol = new Int_t[fNZSegSol], src.fNSegPSol, sizeof(Int_t)*fNZSegSol); | |
91 | memcpy(fBegSegRSol= new Int_t[fNPSegSol], src.fBegSegRSol, sizeof(Int_t)*fNPSegSol); | |
92 | memcpy(fNSegRSol = new Int_t[fNPSegSol], src.fNSegRSol, sizeof(Int_t)*fNPSegSol); | |
93 | memcpy(fSegIDSol = new Int_t[fNRSegSol], src.fSegIDSol, sizeof(Int_t)*fNRSegSol); | |
94 | fParamsSol = new TObjArray(fNParamsSol); | |
95 | for (int i=0;i<fNParamsSol;i++) fParamsSol->AddAtAndExpand(new AliCheb3D(*src.GetParamSol(i)),i); | |
96 | } | |
a1dde210 | 97 | // |
1d18ebe0 | 98 | fNParamsTPC = src.fNParamsTPC; |
99 | fNZSegTPC = src.fNZSegTPC; | |
100 | fNPSegTPC = src.fNPSegTPC; | |
101 | fNRSegTPC = src.fNRSegTPC; | |
102 | fMinZTPC = src.fMinZTPC; | |
103 | fMaxZTPC = src.fMaxZTPC; | |
104 | fMaxRTPC = src.fMaxRTPC; | |
105 | if (src.fNParamsTPC) { | |
106 | memcpy(fSegZTPC = new Float_t[fNZSegTPC], src.fSegZTPC, sizeof(Float_t)*fNZSegTPC); | |
107 | memcpy(fSegPTPC = new Float_t[fNPSegTPC], src.fSegPTPC, sizeof(Float_t)*fNPSegTPC); | |
108 | memcpy(fSegRTPC = new Float_t[fNRSegTPC], src.fSegRTPC, sizeof(Float_t)*fNRSegTPC); | |
109 | memcpy(fBegSegPTPC= new Int_t[fNZSegTPC], src.fBegSegPTPC, sizeof(Int_t)*fNZSegTPC); | |
110 | memcpy(fNSegPTPC = new Int_t[fNZSegTPC], src.fNSegPTPC, sizeof(Int_t)*fNZSegTPC); | |
111 | memcpy(fBegSegRTPC= new Int_t[fNPSegTPC], src.fBegSegRTPC, sizeof(Int_t)*fNPSegTPC); | |
112 | memcpy(fNSegRTPC = new Int_t[fNPSegTPC], src.fNSegRTPC, sizeof(Int_t)*fNPSegTPC); | |
113 | memcpy(fSegIDTPC = new Int_t[fNRSegTPC], src.fSegIDTPC, sizeof(Int_t)*fNRSegTPC); | |
114 | fParamsTPC = new TObjArray(fNParamsTPC); | |
115 | for (int i=0;i<fNParamsTPC;i++) fParamsTPC->AddAtAndExpand(new AliCheb3D(*src.GetParamTPCInt(i)),i); | |
116 | } | |
117 | // | |
47c3d315 | 118 | fNParamsTPCRat = src.fNParamsTPCRat; |
119 | fNZSegTPCRat = src.fNZSegTPCRat; | |
120 | fNPSegTPCRat = src.fNPSegTPCRat; | |
121 | fNRSegTPCRat = src.fNRSegTPCRat; | |
122 | fMinZTPCRat = src.fMinZTPCRat; | |
123 | fMaxZTPCRat = src.fMaxZTPCRat; | |
124 | fMaxRTPCRat = src.fMaxRTPCRat; | |
125 | if (src.fNParamsTPCRat) { | |
126 | memcpy(fSegZTPCRat = new Float_t[fNZSegTPCRat], src.fSegZTPCRat, sizeof(Float_t)*fNZSegTPCRat); | |
127 | memcpy(fSegPTPCRat = new Float_t[fNPSegTPCRat], src.fSegPTPCRat, sizeof(Float_t)*fNPSegTPCRat); | |
128 | memcpy(fSegRTPCRat = new Float_t[fNRSegTPCRat], src.fSegRTPCRat, sizeof(Float_t)*fNRSegTPCRat); | |
129 | memcpy(fBegSegPTPCRat= new Int_t[fNZSegTPCRat], src.fBegSegPTPCRat, sizeof(Int_t)*fNZSegTPCRat); | |
130 | memcpy(fNSegPTPCRat = new Int_t[fNZSegTPCRat], src.fNSegPTPCRat, sizeof(Int_t)*fNZSegTPCRat); | |
131 | memcpy(fBegSegRTPCRat= new Int_t[fNPSegTPCRat], src.fBegSegRTPCRat, sizeof(Int_t)*fNPSegTPCRat); | |
132 | memcpy(fNSegRTPCRat = new Int_t[fNPSegTPCRat], src.fNSegRTPCRat, sizeof(Int_t)*fNPSegTPCRat); | |
133 | memcpy(fSegIDTPCRat = new Int_t[fNRSegTPCRat], src.fSegIDTPCRat, sizeof(Int_t)*fNRSegTPCRat); | |
134 | fParamsTPCRat = new TObjArray(fNParamsTPCRat); | |
135 | for (int i=0;i<fNParamsTPCRat;i++) fParamsTPCRat->AddAtAndExpand(new AliCheb3D(*src.GetParamTPCRatInt(i)),i); | |
136 | } | |
137 | // | |
1d18ebe0 | 138 | fNParamsDip = src.fNParamsDip; |
da7cd221 | 139 | fNZSegDip = src.fNZSegDip; |
140 | fNYSegDip = src.fNYSegDip; | |
141 | fNXSegDip = src.fNXSegDip; | |
da7cd221 | 142 | fMinZDip = src.fMinZDip; |
143 | fMaxZDip = src.fMaxZDip; | |
da7cd221 | 144 | if (src.fNParamsDip) { |
145 | memcpy(fSegZDip = new Float_t[fNZSegDip], src.fSegZDip, sizeof(Float_t)*fNZSegDip); | |
146 | memcpy(fSegYDip = new Float_t[fNYSegDip], src.fSegYDip, sizeof(Float_t)*fNYSegDip); | |
82d1e556 | 147 | memcpy(fSegXDip = new Float_t[fNXSegDip], src.fSegXDip, sizeof(Float_t)*fNXSegDip); |
da7cd221 | 148 | memcpy(fBegSegYDip= new Int_t[fNZSegDip], src.fBegSegYDip, sizeof(Int_t)*fNZSegDip); |
149 | memcpy(fNSegYDip = new Int_t[fNZSegDip], src.fNSegYDip, sizeof(Int_t)*fNZSegDip); | |
150 | memcpy(fBegSegXDip= new Int_t[fNYSegDip], src.fBegSegXDip, sizeof(Int_t)*fNYSegDip); | |
151 | memcpy(fNSegXDip = new Int_t[fNYSegDip], src.fNSegXDip, sizeof(Int_t)*fNYSegDip); | |
152 | memcpy(fSegIDDip = new Int_t[fNXSegDip], src.fSegIDDip, sizeof(Int_t)*fNXSegDip); | |
153 | fParamsDip = new TObjArray(fNParamsDip); | |
154 | for (int i=0;i<fNParamsDip;i++) fParamsDip->AddAtAndExpand(new AliCheb3D(*src.GetParamDip(i)),i); | |
a1dde210 | 155 | } |
156 | // | |
da7cd221 | 157 | } |
158 | ||
159 | //__________________________________________________________________________________________ | |
160 | AliMagWrapCheb& AliMagWrapCheb::operator=(const AliMagWrapCheb& rhs) | |
161 | { | |
162 | // assignment | |
163 | if (this != &rhs) { | |
164 | Clear(); | |
165 | CopyFrom(rhs); | |
a1dde210 | 166 | } |
da7cd221 | 167 | return *this; |
168 | // | |
a1dde210 | 169 | } |
170 | ||
da7cd221 | 171 | //__________________________________________________________________________________________ |
172 | void AliMagWrapCheb::Clear(const Option_t *) | |
173 | { | |
174 | // clear all dynamic parts | |
175 | if (fNParamsSol) { | |
d8d3669f | 176 | fParamsSol->SetOwner(kTRUE); |
1d18ebe0 | 177 | delete fParamsSol; fParamsSol = 0; |
178 | delete[] fSegZSol; fSegZSol = 0; | |
179 | delete[] fSegPSol; fSegPSol = 0; | |
180 | delete[] fSegRSol; fSegRSol = 0; | |
181 | delete[] fBegSegPSol; fBegSegPSol = 0; | |
182 | delete[] fNSegPSol; fNSegPSol = 0; | |
183 | delete[] fBegSegRSol; fBegSegRSol = 0; | |
184 | delete[] fNSegRSol; fNSegRSol = 0; | |
185 | delete[] fSegIDSol; fSegIDSol = 0; | |
da7cd221 | 186 | } |
1d18ebe0 | 187 | fNParamsSol = fNZSegSol = fNPSegSol = fNRSegSol = 0; |
188 | fMinZSol = 1e6; | |
189 | fMaxZSol = -1e6; | |
190 | fMaxRSol = 0; | |
da7cd221 | 191 | // |
1d18ebe0 | 192 | if (fNParamsTPC) { |
d8d3669f | 193 | fParamsTPC->SetOwner(kTRUE); |
1d18ebe0 | 194 | delete fParamsTPC; fParamsTPC = 0; |
195 | delete[] fSegZTPC; fSegZTPC = 0; | |
196 | delete[] fSegPTPC; fSegPTPC = 0; | |
197 | delete[] fSegRTPC; fSegRTPC = 0; | |
198 | delete[] fBegSegPTPC; fBegSegPTPC = 0; | |
199 | delete[] fNSegPTPC; fNSegPTPC = 0; | |
200 | delete[] fBegSegRTPC; fBegSegRTPC = 0; | |
201 | delete[] fNSegRTPC; fNSegRTPC = 0; | |
202 | delete[] fSegIDTPC; fSegIDTPC = 0; | |
da7cd221 | 203 | } |
1d18ebe0 | 204 | fNParamsTPC = fNZSegTPC = fNPSegTPC = fNRSegTPC = 0; |
205 | fMinZTPC = 1e6; | |
206 | fMaxZTPC = -1e6; | |
207 | fMaxRTPC = 0; | |
208 | // | |
47c3d315 | 209 | if (fNParamsTPCRat) { |
d8d3669f | 210 | fParamsTPCRat->SetOwner(kTRUE); |
47c3d315 | 211 | delete fParamsTPCRat; fParamsTPCRat = 0; |
212 | delete[] fSegZTPCRat; fSegZTPCRat = 0; | |
213 | delete[] fSegPTPCRat; fSegPTPCRat = 0; | |
214 | delete[] fSegRTPCRat; fSegRTPCRat = 0; | |
215 | delete[] fBegSegPTPCRat; fBegSegPTPCRat = 0; | |
216 | delete[] fNSegPTPCRat; fNSegPTPCRat = 0; | |
217 | delete[] fBegSegRTPCRat; fBegSegRTPCRat = 0; | |
218 | delete[] fNSegRTPCRat; fNSegRTPCRat = 0; | |
219 | delete[] fSegIDTPCRat; fSegIDTPCRat = 0; | |
220 | } | |
221 | fNParamsTPCRat = fNZSegTPCRat = fNPSegTPCRat = fNRSegTPCRat = 0; | |
222 | fMinZTPCRat = 1e6; | |
223 | fMaxZTPCRat = -1e6; | |
224 | fMaxRTPCRat = 0; | |
225 | // | |
da7cd221 | 226 | if (fNParamsDip) { |
d8d3669f | 227 | fParamsDip->SetOwner(kTRUE); |
1d18ebe0 | 228 | delete fParamsDip; fParamsDip = 0; |
229 | delete[] fSegZDip; fSegZDip = 0; | |
230 | delete[] fSegYDip; fSegYDip = 0; | |
231 | delete[] fSegXDip; fSegXDip = 0; | |
232 | delete[] fBegSegYDip; fBegSegYDip = 0; | |
233 | delete[] fNSegYDip; fNSegYDip = 0; | |
234 | delete[] fBegSegXDip; fBegSegXDip = 0; | |
235 | delete[] fNSegXDip; fNSegXDip = 0; | |
236 | delete[] fSegIDDip; fSegIDDip = 0; | |
da7cd221 | 237 | } |
1d18ebe0 | 238 | fNParamsDip = fNZSegDip = fNYSegDip = fNXSegDip = 0; |
239 | fMinZDip = 1e6; | |
240 | fMaxZDip = -1e6; | |
da7cd221 | 241 | // |
242 | } | |
a1dde210 | 243 | |
da7cd221 | 244 | //__________________________________________________________________________________________ |
db83d72f | 245 | void AliMagWrapCheb::Field(const Double_t *xyz, Double_t *b) const |
a1dde210 | 246 | { |
da7cd221 | 247 | // compute field in cartesian coordinates. If point is outside of the parameterized region |
248 | // get it at closest valid point | |
1d18ebe0 | 249 | Double_t rphiz[3]; |
da7cd221 | 250 | // |
251 | #ifndef _BRING_TO_BOUNDARY_ // exact matching to fitted volume is requested | |
1d18ebe0 | 252 | b[0] = b[1] = b[2] = 0; |
da7cd221 | 253 | #endif |
254 | // | |
1d18ebe0 | 255 | if (xyz[2]>fMinZSol) { |
256 | CartToCyl(xyz,rphiz); | |
257 | FieldCylSol(rphiz,b); | |
258 | // convert field to cartesian system | |
259 | CylToCartCylB(rphiz, b,b); | |
260 | return; | |
da7cd221 | 261 | } |
262 | // | |
1d18ebe0 | 263 | int iddip = FindDipSegment(xyz); |
264 | if (iddip<0) return; | |
265 | AliCheb3D* par = GetParamDip(iddip); | |
da7cd221 | 266 | #ifndef _BRING_TO_BOUNDARY_ |
1d18ebe0 | 267 | if (!par->IsInside(xyz)) return; |
da7cd221 | 268 | #endif |
1d18ebe0 | 269 | par->Eval(xyz,b); |
da7cd221 | 270 | // |
a1dde210 | 271 | } |
272 | ||
da7cd221 | 273 | //__________________________________________________________________________________________ |
db83d72f | 274 | Double_t AliMagWrapCheb::GetBz(const Double_t *xyz) const |
a1dde210 | 275 | { |
db83d72f | 276 | // compute Bz for the point in cartesian coordinates. If point is outside of the parameterized region |
da7cd221 | 277 | // get it at closest valid point |
1d18ebe0 | 278 | Double_t rphiz[3]; |
da7cd221 | 279 | // |
1d18ebe0 | 280 | if (xyz[2]>fMinZSol) { |
281 | CartToCyl(xyz,rphiz); | |
282 | return FieldCylSolBz(rphiz); | |
da7cd221 | 283 | } |
1d18ebe0 | 284 | // |
285 | int iddip = FindDipSegment(xyz); | |
286 | if (iddip<0) return 0.; | |
287 | AliCheb3D* par = GetParamDip(iddip); | |
9251fceb | 288 | #ifndef _BRING_TO_BOUNDARY_ |
1d18ebe0 | 289 | if (!par->IsInside(xyz)) return 0.; |
9251fceb | 290 | #endif |
1d18ebe0 | 291 | return par->Eval(xyz,2); |
db83d72f | 292 | } |
293 | ||
294 | ||
295 | //__________________________________________________________________________________________ | |
296 | void AliMagWrapCheb::Print(Option_t *) const | |
297 | { | |
298 | // print info | |
299 | printf("Alice magnetic field parameterized by Chebyshev polynomials\n"); | |
300 | printf("Segmentation for Solenoid (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZSol,fMaxZSol,fMaxRSol); | |
da7cd221 | 301 | // |
82d1e556 | 302 | if (fParamsSol) { |
303 | for (int i=0;i<fNParamsSol;i++) { | |
304 | printf("SOL%4d ",i); | |
305 | GetParamSol(i)->Print(); | |
306 | } | |
307 | } | |
da7cd221 | 308 | // |
1d18ebe0 | 309 | printf("Segmentation for TPC field integral (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZTPC,fMaxZTPC,fMaxRTPC); |
da7cd221 | 310 | // |
1d18ebe0 | 311 | if (fParamsTPC) { |
312 | for (int i=0;i<fNParamsTPC;i++) { | |
82d1e556 | 313 | printf("TPC%4d ",i); |
314 | GetParamTPCInt(i)->Print(); | |
315 | } | |
316 | } | |
317 | // | |
47c3d315 | 318 | printf("Segmentation for TPC field ratios integral (%+.2f<Z<%+.2f cm | R<%.2f cm)\n",fMinZTPCRat,fMaxZTPCRat,fMaxRTPCRat); |
319 | // | |
320 | if (fParamsTPCRat) { | |
321 | for (int i=0;i<fNParamsTPCRat;i++) { | |
322 | printf("TPCRat%4d ",i); | |
323 | GetParamTPCRatInt(i)->Print(); | |
324 | } | |
325 | } | |
326 | // | |
db83d72f | 327 | printf("Segmentation for Dipole (%+.2f<Z<%+.2f cm)\n",fMinZDip,fMaxZDip); |
82d1e556 | 328 | if (fParamsDip) { |
329 | for (int i=0;i<fNParamsDip;i++) { | |
330 | printf("DIP%4d ",i); | |
331 | GetParamDip(i)->Print(); | |
332 | } | |
333 | } | |
db83d72f | 334 | // |
db83d72f | 335 | } |
336 | ||
db83d72f | 337 | //__________________________________________________________________________________________________ |
1d18ebe0 | 338 | Int_t AliMagWrapCheb::FindDipSegment(const Double_t *xyz) const |
db83d72f | 339 | { |
340 | // find the segment containing point xyz. If it is outside find the closest segment | |
1d18ebe0 | 341 | if (!fNParamsDip) return -1; |
db83d72f | 342 | int xid,yid,zid = TMath::BinarySearch(fNZSegDip,fSegZDip,(Float_t)xyz[2]); // find zsegment |
db83d72f | 343 | // |
e27dc75a | 344 | Bool_t reCheck = kFALSE; |
345 | while(1) { | |
346 | int ysegBeg = fBegSegYDip[zid]; | |
347 | // | |
348 | for (yid=0;yid<fNSegYDip[zid];yid++) if (xyz[1]<fSegYDip[ysegBeg+yid]) break; | |
349 | if ( --yid < 0 ) yid = 0; | |
350 | yid += ysegBeg; | |
351 | // | |
352 | int xsegBeg = fBegSegXDip[yid]; | |
353 | for (xid=0;xid<fNSegXDip[yid];xid++) if (xyz[0]<fSegXDip[xsegBeg+xid]) break; | |
354 | // | |
355 | if ( --xid < 0) xid = 0; | |
356 | xid += xsegBeg; | |
357 | // | |
358 | // to make sure that due to the precision problems we did not pick the next Zbin | |
359 | if (!reCheck && (xyz[2] - fSegZDip[zid] < 3.e-5) && zid && | |
360 | !GetParamDip(fSegIDDip[xid])->IsInside(xyz)) { // check the previous Z bin | |
361 | zid--; | |
362 | reCheck = kTRUE; | |
363 | continue; | |
364 | } | |
365 | break; | |
366 | } | |
db83d72f | 367 | return fSegIDDip[xid]; |
a1dde210 | 368 | } |
369 | ||
1d18ebe0 | 370 | //__________________________________________________________________________________________________ |
371 | Int_t AliMagWrapCheb::FindSolSegment(const Double_t *rpz) const | |
372 | { | |
373 | // find the segment containing point xyz. If it is outside find the closest segment | |
374 | if (!fNParamsSol) return -1; | |
375 | int rid,pid,zid = TMath::BinarySearch(fNZSegSol,fSegZSol,(Float_t)rpz[2]); // find zsegment | |
1d18ebe0 | 376 | // |
e27dc75a | 377 | Bool_t reCheck = kFALSE; |
378 | while(1) { | |
379 | int psegBeg = fBegSegPSol[zid]; | |
380 | for (pid=0;pid<fNSegPSol[zid];pid++) if (rpz[1]<fSegPSol[psegBeg+pid]) break; | |
381 | if ( --pid < 0 ) pid = 0; | |
382 | pid += psegBeg; | |
383 | // | |
384 | int rsegBeg = fBegSegRSol[pid]; | |
385 | for (rid=0;rid<fNSegRSol[pid];rid++) if (rpz[0]<fSegRSol[rsegBeg+rid]) break; | |
386 | if ( --rid < 0) rid = 0; | |
387 | rid += rsegBeg; | |
388 | // | |
389 | // to make sure that due to the precision problems we did not pick the next Zbin | |
390 | if (!reCheck && (rpz[2] - fSegZSol[zid] < 3.e-5) && zid && | |
391 | !GetParamSol(fSegIDSol[rid])->IsInside(rpz)) { // check the previous Z bin | |
392 | zid--; | |
393 | reCheck = kTRUE; | |
394 | continue; | |
395 | } | |
396 | break; | |
397 | } | |
1d18ebe0 | 398 | return fSegIDSol[rid]; |
399 | } | |
400 | ||
401 | //__________________________________________________________________________________________________ | |
402 | Int_t AliMagWrapCheb::FindTPCSegment(const Double_t *rpz) const | |
403 | { | |
404 | // find the segment containing point xyz. If it is outside find the closest segment | |
405 | if (!fNParamsTPC) return -1; | |
406 | int rid,pid,zid = TMath::BinarySearch(fNZSegTPC,fSegZTPC,(Float_t)rpz[2]); // find zsegment | |
1d18ebe0 | 407 | // |
e27dc75a | 408 | Bool_t reCheck = kFALSE; |
409 | while(1) { | |
410 | int psegBeg = fBegSegPTPC[zid]; | |
411 | // | |
412 | for (pid=0;pid<fNSegPTPC[zid];pid++) if (rpz[1]<fSegPTPC[psegBeg+pid]) break; | |
413 | if ( --pid < 0 ) pid = 0; | |
414 | pid += psegBeg; | |
415 | // | |
416 | int rsegBeg = fBegSegRTPC[pid]; | |
417 | for (rid=0;rid<fNSegRTPC[pid];rid++) if (rpz[0]<fSegRTPC[rsegBeg+rid]) break; | |
418 | if ( --rid < 0) rid = 0; | |
419 | rid += rsegBeg; | |
420 | // | |
421 | // to make sure that due to the precision problems we did not pick the next Zbin | |
3f6a4b9c | 422 | if (!reCheck && (rpz[2] - fSegZTPC[zid] < 3.e-5) && zid && |
423 | !GetParamTPCInt(fSegIDTPC[rid])->IsInside(rpz)) { // check the previous Z bin | |
e27dc75a | 424 | zid--; |
425 | reCheck = kTRUE; | |
426 | continue; | |
427 | } | |
428 | break; | |
429 | } | |
1d18ebe0 | 430 | return fSegIDTPC[rid]; |
431 | } | |
432 | ||
47c3d315 | 433 | //__________________________________________________________________________________________________ |
434 | Int_t AliMagWrapCheb::FindTPCRatSegment(const Double_t *rpz) const | |
435 | { | |
436 | // find the segment containing point xyz. If it is outside find the closest segment | |
437 | if (!fNParamsTPCRat) return -1; | |
438 | int rid,pid,zid = TMath::BinarySearch(fNZSegTPCRat,fSegZTPCRat,(Float_t)rpz[2]); // find zsegment | |
439 | // | |
440 | Bool_t reCheck = kFALSE; | |
441 | while(1) { | |
442 | int psegBeg = fBegSegPTPCRat[zid]; | |
443 | // | |
444 | for (pid=0;pid<fNSegPTPCRat[zid];pid++) if (rpz[1]<fSegPTPCRat[psegBeg+pid]) break; | |
445 | if ( --pid < 0 ) pid = 0; | |
446 | pid += psegBeg; | |
447 | // | |
448 | int rsegBeg = fBegSegRTPCRat[pid]; | |
449 | for (rid=0;rid<fNSegRTPCRat[pid];rid++) if (rpz[0]<fSegRTPCRat[rsegBeg+rid]) break; | |
450 | if ( --rid < 0) rid = 0; | |
451 | rid += rsegBeg; | |
452 | // | |
453 | // to make sure that due to the precision problems we did not pick the next Zbin | |
3f6a4b9c | 454 | if (!reCheck && (rpz[2] - fSegZTPCRat[zid] < 3.e-5) && zid && |
455 | !GetParamTPCRatInt(fSegIDTPCRat[rid])->IsInside(rpz)) { // check the previous Z bin | |
47c3d315 | 456 | zid--; |
457 | reCheck = kTRUE; | |
458 | continue; | |
459 | } | |
460 | break; | |
461 | } | |
462 | return fSegIDTPCRat[rid]; | |
463 | } | |
464 | ||
1d18ebe0 | 465 | |
da7cd221 | 466 | //__________________________________________________________________________________________ |
db83d72f | 467 | void AliMagWrapCheb::GetTPCInt(const Double_t *xyz, Double_t *b) const |
a1dde210 | 468 | { |
da7cd221 | 469 | // compute TPC region field integral in cartesian coordinates. |
470 | // If point is outside of the parameterized region get it at closeset valid point | |
db83d72f | 471 | static Double_t rphiz[3]; |
da7cd221 | 472 | // |
473 | // TPCInt region | |
474 | // convert coordinates to cyl system | |
475 | CartToCyl(xyz,rphiz); | |
476 | #ifndef _BRING_TO_BOUNDARY_ | |
477 | if ( (rphiz[2]>GetMaxZTPCInt()||rphiz[2]<GetMinZTPCInt()) || | |
478 | rphiz[0]>GetMaxRTPCInt()) {for (int i=3;i--;) b[i]=0; return;} | |
479 | #endif | |
480 | // | |
481 | GetTPCIntCyl(rphiz,b); | |
482 | // | |
483 | // convert field to cartesian system | |
484 | CylToCartCylB(rphiz, b,b); | |
485 | // | |
486 | } | |
487 | ||
47c3d315 | 488 | //__________________________________________________________________________________________ |
489 | void AliMagWrapCheb::GetTPCRatInt(const Double_t *xyz, Double_t *b) const | |
490 | { | |
491 | // compute TPCRat region field integral in cartesian coordinates. | |
492 | // If point is outside of the parameterized region get it at closeset valid point | |
493 | static Double_t rphiz[3]; | |
494 | // | |
495 | // TPCRatInt region | |
496 | // convert coordinates to cyl system | |
497 | CartToCyl(xyz,rphiz); | |
498 | #ifndef _BRING_TO_BOUNDARY_ | |
499 | if ( (rphiz[2]>GetMaxZTPCRatInt()||rphiz[2]<GetMinZTPCRatInt()) || | |
500 | rphiz[0]>GetMaxRTPCRatInt()) {for (int i=3;i--;) b[i]=0; return;} | |
501 | #endif | |
502 | // | |
503 | GetTPCRatIntCyl(rphiz,b); | |
504 | // | |
505 | // convert field to cartesian system | |
506 | CylToCartCylB(rphiz, b,b); | |
507 | // | |
508 | } | |
509 | ||
da7cd221 | 510 | //__________________________________________________________________________________________ |
db83d72f | 511 | void AliMagWrapCheb::FieldCylSol(const Double_t *rphiz, Double_t *b) const |
da7cd221 | 512 | { |
513 | // compute Solenoid field in Cylindircal coordinates | |
514 | // note: if the point is outside the volume get the field in closest parameterized point | |
1d18ebe0 | 515 | int id = FindSolSegment(rphiz); |
516 | if (id<0) return; | |
517 | AliCheb3D* par = GetParamSol(id); | |
518 | #ifndef _BRING_TO_BOUNDARY_ // exact matching to fitted volume is requested | |
519 | if (!par->IsInside(rphiz)) return; | |
520 | #endif | |
521 | par->Eval(rphiz,b); | |
522 | return; | |
da7cd221 | 523 | // |
524 | } | |
525 | ||
526 | //__________________________________________________________________________________________ | |
db83d72f | 527 | Double_t AliMagWrapCheb::FieldCylSolBz(const Double_t *rphiz) const |
da7cd221 | 528 | { |
529 | // compute Solenoid field in Cylindircal coordinates | |
530 | // note: if the point is outside the volume get the field in closest parameterized point | |
1d18ebe0 | 531 | int id = FindSolSegment(rphiz); |
532 | if (id<0) return 0.; | |
533 | AliCheb3D* par = GetParamSol(id); | |
534 | #ifndef _BRING_TO_BOUNDARY_ | |
535 | return par->IsInside(rphiz) ? par->Eval(rphiz,2) : 0; | |
c8f37c50 | 536 | #else |
1d18ebe0 | 537 | return par->Eval(rphiz,2); |
c8f37c50 | 538 | #endif |
a1dde210 | 539 | // |
a1dde210 | 540 | } |
541 | ||
da7cd221 | 542 | //__________________________________________________________________________________________ |
db83d72f | 543 | void AliMagWrapCheb::GetTPCIntCyl(const Double_t *rphiz, Double_t *b) const |
a1dde210 | 544 | { |
da7cd221 | 545 | // compute field integral in TPC region in Cylindircal coordinates |
546 | // note: the check for the point being inside the parameterized region is done outside | |
1d18ebe0 | 547 | int id = FindTPCSegment(rphiz); |
548 | if (id<0) { | |
549 | b[0] = b[1] = b[2] = 0; | |
550 | return; | |
551 | } | |
0f5e1718 | 552 | if (id>=fNParamsTPC) { |
553 | AliError(Form("Wrong TPCParam segment %d",id)); | |
554 | b[0] = b[1] = b[2] = 0; | |
555 | return; | |
556 | } | |
1d18ebe0 | 557 | AliCheb3D* par = GetParamTPCInt(id); |
47c3d315 | 558 | if (par->IsInside(rphiz)) { |
559 | par->Eval(rphiz,b); | |
560 | return; | |
561 | } | |
562 | b[0] = b[1] = b[2] = 0; | |
563 | return; | |
564 | // | |
565 | } | |
566 | ||
567 | //__________________________________________________________________________________________ | |
568 | void AliMagWrapCheb::GetTPCRatIntCyl(const Double_t *rphiz, Double_t *b) const | |
569 | { | |
570 | // compute field integral in TPCRat region in Cylindircal coordinates | |
571 | // note: the check for the point being inside the parameterized region is done outside | |
572 | int id = FindTPCRatSegment(rphiz); | |
573 | if (id<0) { | |
574 | b[0] = b[1] = b[2] = 0; | |
575 | return; | |
576 | } | |
0f5e1718 | 577 | if (id>=fNParamsTPCRat) { |
578 | AliError(Form("Wrong TPCRatParam segment %d",id)); | |
579 | b[0] = b[1] = b[2] = 0; | |
580 | return; | |
581 | } | |
47c3d315 | 582 | AliCheb3D* par = GetParamTPCRatInt(id); |
583 | if (par->IsInside(rphiz)) { | |
584 | par->Eval(rphiz,b); | |
585 | return; | |
586 | } | |
1d18ebe0 | 587 | b[0] = b[1] = b[2] = 0; |
588 | return; | |
da7cd221 | 589 | // |
a1dde210 | 590 | } |
591 | ||
da7cd221 | 592 | |
da7cd221 | 593 | #ifdef _INC_CREATION_ALICHEB3D_ |
594 | //_______________________________________________ | |
595 | void AliMagWrapCheb::LoadData(const char* inpfile) | |
596 | { | |
597 | // read coefficients data from the text file | |
598 | // | |
599 | TString strf = inpfile; | |
600 | gSystem->ExpandPathName(strf); | |
601 | FILE* stream = fopen(strf,"r"); | |
602 | if (!stream) { | |
603 | printf("Did not find input file %s\n",strf.Data()); | |
604 | return; | |
605 | } | |
606 | // | |
607 | TString buffs; | |
608 | AliCheb3DCalc::ReadLine(buffs,stream); | |
609 | if (!buffs.BeginsWith("START")) { | |
610 | Error("LoadData","Expected: \"START <name>\", found \"%s\"\nStop\n",buffs.Data()); | |
611 | exit(1); | |
612 | } | |
613 | if (buffs.First(' ')>0) SetName(buffs.Data()+buffs.First(' ')+1); | |
614 | // | |
615 | // Solenoid part ----------------------------------------------------------- | |
616 | AliCheb3DCalc::ReadLine(buffs,stream); | |
617 | if (!buffs.BeginsWith("START SOLENOID")) { | |
618 | Error("LoadData","Expected: \"START SOLENOID\", found \"%s\"\nStop\n",buffs.Data()); | |
619 | exit(1); | |
620 | } | |
621 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
622 | int nparSol = buffs.Atoi(); | |
623 | // | |
624 | for (int ip=0;ip<nparSol;ip++) { | |
625 | AliCheb3D* cheb = new AliCheb3D(); | |
626 | cheb->LoadData(stream); | |
627 | AddParamSol(cheb); | |
628 | } | |
629 | // | |
630 | AliCheb3DCalc::ReadLine(buffs,stream); | |
631 | if (!buffs.BeginsWith("END SOLENOID")) { | |
632 | Error("LoadData","Expected \"END SOLENOID\", found \"%s\"\nStop\n",buffs.Data()); | |
633 | exit(1); | |
634 | } | |
635 | // | |
636 | // TPCInt part ----------------------------------------------------------- | |
637 | AliCheb3DCalc::ReadLine(buffs,stream); | |
638 | if (!buffs.BeginsWith("START TPCINT")) { | |
639 | Error("LoadData","Expected: \"START TPCINT\", found \"%s\"\nStop\n",buffs.Data()); | |
640 | exit(1); | |
641 | } | |
642 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
643 | int nparTPCInt = buffs.Atoi(); | |
644 | // | |
645 | for (int ip=0;ip<nparTPCInt;ip++) { | |
646 | AliCheb3D* cheb = new AliCheb3D(); | |
647 | cheb->LoadData(stream); | |
648 | AddParamTPCInt(cheb); | |
649 | } | |
650 | // | |
651 | AliCheb3DCalc::ReadLine(buffs,stream); | |
652 | if (!buffs.BeginsWith("END TPCINT")) { | |
653 | Error("LoadData","Expected \"END TPCINT\", found \"%s\"\nStop\n",buffs.Data()); | |
654 | exit(1); | |
655 | } | |
656 | // | |
47c3d315 | 657 | // TPCRatInt part ----------------------------------------------------------- |
658 | AliCheb3DCalc::ReadLine(buffs,stream); | |
659 | if (!buffs.BeginsWith("START TPCRatINT")) { | |
660 | Error("LoadData","Expected: \"START TPCRatINT\", found \"%s\"\nStop\n",buffs.Data()); | |
661 | exit(1); | |
662 | } | |
663 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
664 | int nparTPCRatInt = buffs.Atoi(); | |
665 | // | |
666 | for (int ip=0;ip<nparTPCRatInt;ip++) { | |
667 | AliCheb3D* cheb = new AliCheb3D(); | |
668 | cheb->LoadData(stream); | |
669 | AddParamTPCRatInt(cheb); | |
670 | } | |
671 | // | |
672 | AliCheb3DCalc::ReadLine(buffs,stream); | |
673 | if (!buffs.BeginsWith("END TPCRatINT")) { | |
674 | Error("LoadData","Expected \"END TPCRatINT\", found \"%s\"\nStop\n",buffs.Data()); | |
675 | exit(1); | |
676 | } | |
677 | // | |
da7cd221 | 678 | // Dipole part ----------------------------------------------------------- |
679 | AliCheb3DCalc::ReadLine(buffs,stream); | |
680 | if (!buffs.BeginsWith("START DIPOLE")) { | |
681 | Error("LoadData","Expected: \"START DIPOLE\", found \"%s\"\nStop\n",buffs.Data()); | |
682 | exit(1); | |
683 | } | |
684 | AliCheb3DCalc::ReadLine(buffs,stream); // nparam | |
685 | int nparDip = buffs.Atoi(); | |
686 | // | |
687 | for (int ip=0;ip<nparDip;ip++) { | |
688 | AliCheb3D* cheb = new AliCheb3D(); | |
689 | cheb->LoadData(stream); | |
690 | AddParamDip(cheb); | |
691 | } | |
692 | // | |
693 | AliCheb3DCalc::ReadLine(buffs,stream); | |
694 | if (!buffs.BeginsWith("END DIPOLE")) { | |
695 | Error("LoadData","Expected \"END DIPOLE\", found \"%s\"\nStop\n",GetName(),buffs.Data()); | |
696 | exit(1); | |
697 | } | |
698 | // | |
699 | AliCheb3DCalc::ReadLine(buffs,stream); | |
700 | if (!buffs.BeginsWith("END") || !buffs.Contains(GetName())) { | |
701 | Error("LoadData","Expected: \"END %s\", found \"%s\"\nStop\n",GetName(),buffs.Data()); | |
702 | exit(1); | |
703 | } | |
704 | // | |
705 | // --------------------------------------------------------------------------- | |
706 | fclose(stream); | |
707 | BuildTableSol(); | |
da7cd221 | 708 | BuildTableDip(); |
1d18ebe0 | 709 | BuildTableTPCInt(); |
47c3d315 | 710 | BuildTableTPCRatInt(); |
1d18ebe0 | 711 | // |
da7cd221 | 712 | printf("Loaded magnetic field \"%s\" from %s\n",GetName(),strf.Data()); |
713 | // | |
714 | } | |
1d18ebe0 | 715 | |
716 | //__________________________________________________________________________________________ | |
717 | void AliMagWrapCheb::BuildTableSol() | |
718 | { | |
339fbe23 | 719 | // build lookup table |
1d18ebe0 | 720 | BuildTable(fNParamsSol,fParamsSol, |
721 | fNZSegSol,fNPSegSol,fNRSegSol, | |
722 | fMinZSol,fMaxZSol, | |
723 | &fSegZSol,&fSegPSol,&fSegRSol, | |
724 | &fBegSegPSol,&fNSegPSol, | |
725 | &fBegSegRSol,&fNSegRSol, | |
726 | &fSegIDSol); | |
727 | } | |
728 | ||
729 | //__________________________________________________________________________________________ | |
730 | void AliMagWrapCheb::BuildTableDip() | |
731 | { | |
339fbe23 | 732 | // build lookup table |
1d18ebe0 | 733 | BuildTable(fNParamsDip,fParamsDip, |
734 | fNZSegDip,fNYSegDip,fNXSegDip, | |
735 | fMinZDip,fMaxZDip, | |
736 | &fSegZDip,&fSegYDip,&fSegXDip, | |
737 | &fBegSegYDip,&fNSegYDip, | |
738 | &fBegSegXDip,&fNSegXDip, | |
739 | &fSegIDDip); | |
740 | } | |
741 | ||
742 | //__________________________________________________________________________________________ | |
743 | void AliMagWrapCheb::BuildTableTPCInt() | |
744 | { | |
339fbe23 | 745 | // build lookup table |
1d18ebe0 | 746 | BuildTable(fNParamsTPC,fParamsTPC, |
747 | fNZSegTPC,fNPSegTPC,fNRSegTPC, | |
748 | fMinZTPC,fMaxZTPC, | |
749 | &fSegZTPC,&fSegPTPC,&fSegRTPC, | |
750 | &fBegSegPTPC,&fNSegPTPC, | |
751 | &fBegSegRTPC,&fNSegRTPC, | |
752 | &fSegIDTPC); | |
753 | } | |
754 | ||
47c3d315 | 755 | //__________________________________________________________________________________________ |
756 | void AliMagWrapCheb::BuildTableTPCRatInt() | |
757 | { | |
339fbe23 | 758 | // build lookup table |
47c3d315 | 759 | BuildTable(fNParamsTPCRat,fParamsTPCRat, |
760 | fNZSegTPCRat,fNPSegTPCRat,fNRSegTPCRat, | |
761 | fMinZTPCRat,fMaxZTPCRat, | |
762 | &fSegZTPCRat,&fSegPTPCRat,&fSegRTPCRat, | |
763 | &fBegSegPTPCRat,&fNSegPTPCRat, | |
764 | &fBegSegRTPCRat,&fNSegRTPCRat, | |
765 | &fSegIDTPCRat); | |
766 | } | |
767 | ||
da7cd221 | 768 | #endif |
ff66b122 | 769 | |
da7cd221 | 770 | //_______________________________________________ |
771 | #ifdef _INC_CREATION_ALICHEB3D_ | |
772 | ||
773 | //__________________________________________________________________________________________ | |
774 | AliMagWrapCheb::AliMagWrapCheb(const char* inputFile) : | |
1d18ebe0 | 775 | fNParamsSol(0),fNZSegSol(0),fNPSegSol(0),fNRSegSol(0), |
776 | fSegZSol(0),fSegPSol(0),fSegRSol(0), | |
777 | fBegSegPSol(0),fNSegPSol(0),fBegSegRSol(0),fNSegRSol(0),fSegIDSol(0),fMinZSol(1.e6),fMaxZSol(-1.e6),fParamsSol(0),fMaxRSol(0), | |
da7cd221 | 778 | // |
1d18ebe0 | 779 | fNParamsTPC(0),fNZSegTPC(0),fNPSegTPC(0),fNRSegTPC(0), |
780 | fSegZTPC(0),fSegPTPC(0),fSegRTPC(0), | |
781 | fBegSegPTPC(0),fNSegPTPC(0),fBegSegRTPC(0),fNSegRTPC(0),fSegIDTPC(0),fMinZTPC(1.e6),fMaxZTPC(-1.e6),fParamsTPC(0),fMaxRTPC(0), | |
47c3d315 | 782 | // |
783 | fNParamsTPCRat(0),fNZSegTPCRat(0),fNPSegTPCRat(0),fNRSegTPCRat(0), | |
784 | fSegZTPCRat(0),fSegPTPCRat(0),fSegRTPCRat(0), | |
785 | fBegSegPTPCRat(0),fNSegPTPCRat(0),fBegSegRTPCRat(0),fNSegRTPCRat(0),fSegIDTPCRat(0),fMinZTPCRat(1.e6),fMaxZTPCRat(-1.e6),fParamsTPCRat(0),fMaxRTPCRat(0), | |
da7cd221 | 786 | // |
1d18ebe0 | 787 | fNParamsDip(0),fNZSegDip(0),fNYSegDip(0),fNXSegDip(0), |
788 | fSegZDip(0),fSegYDip(0),fSegXDip(0), | |
789 | fBegSegYDip(0),fNSegYDip(0),fBegSegXDip(0),fNSegXDip(0),fSegIDDip(0),fMinZDip(1.e6),fMaxZDip(-1.e6),fParamsDip(0) | |
da7cd221 | 790 | // |
791 | { | |
792 | // construct from coeffs from the text file | |
793 | LoadData(inputFile); | |
794 | } | |
795 | ||
796 | //__________________________________________________________________________________________ | |
797 | void AliMagWrapCheb::AddParamSol(const AliCheb3D* param) | |
798 | { | |
799 | // adds new parameterization piece for Sol | |
800 | // NOTE: pieces must be added strictly in increasing R then increasing Z order | |
801 | // | |
802 | if (!fParamsSol) fParamsSol = new TObjArray(); | |
803 | fParamsSol->Add( (AliCheb3D*)param ); | |
804 | fNParamsSol++; | |
1d18ebe0 | 805 | if (fMaxRSol<param->GetBoundMax(0)) fMaxRSol = param->GetBoundMax(0); |
da7cd221 | 806 | // |
807 | } | |
808 | ||
809 | //__________________________________________________________________________________________ | |
810 | void AliMagWrapCheb::AddParamTPCInt(const AliCheb3D* param) | |
811 | { | |
812 | // adds new parameterization piece for TPCInt | |
813 | // NOTE: pieces must be added strictly in increasing R then increasing Z order | |
814 | // | |
1d18ebe0 | 815 | if (!fParamsTPC) fParamsTPC = new TObjArray(); |
816 | fParamsTPC->Add( (AliCheb3D*)param); | |
817 | fNParamsTPC++; | |
818 | if (fMaxRTPC<param->GetBoundMax(0)) fMaxRTPC = param->GetBoundMax(0); | |
da7cd221 | 819 | // |
820 | } | |
821 | ||
47c3d315 | 822 | //__________________________________________________________________________________________ |
823 | void AliMagWrapCheb::AddParamTPCRatInt(const AliCheb3D* param) | |
824 | { | |
825 | // adds new parameterization piece for TPCRatInt | |
826 | // NOTE: pieces must be added strictly in increasing R then increasing Z order | |
827 | // | |
828 | if (!fParamsTPCRat) fParamsTPCRat = new TObjArray(); | |
829 | fParamsTPCRat->Add( (AliCheb3D*)param); | |
830 | fNParamsTPCRat++; | |
831 | if (fMaxRTPCRat<param->GetBoundMax(0)) fMaxRTPCRat = param->GetBoundMax(0); | |
832 | // | |
833 | } | |
834 | ||
da7cd221 | 835 | //__________________________________________________________________________________________ |
836 | void AliMagWrapCheb::AddParamDip(const AliCheb3D* param) | |
a1dde210 | 837 | { |
da7cd221 | 838 | // adds new parameterization piece for Dipole |
a1dde210 | 839 | // |
da7cd221 | 840 | if (!fParamsDip) fParamsDip = new TObjArray(); |
841 | fParamsDip->Add( (AliCheb3D*)param); | |
842 | fNParamsDip++; | |
843 | // | |
844 | } | |
845 | ||
846 | //__________________________________________________________________________________________ | |
847 | void AliMagWrapCheb::ResetTPCInt() | |
848 | { | |
849 | // clean TPC field integral (used for update) | |
1d18ebe0 | 850 | if (fNParamsTPC) { |
851 | delete fParamsTPC; fParamsTPC = 0; | |
852 | delete[] fSegZTPC; fSegZTPC = 0; | |
853 | delete[] fSegPTPC; fSegPTPC = 0; | |
854 | delete[] fSegRTPC; fSegRTPC = 0; | |
855 | delete[] fBegSegPTPC; fBegSegPTPC = 0; | |
856 | delete[] fNSegPTPC; fNSegPTPC = 0; | |
857 | delete[] fBegSegRTPC; fBegSegRTPC = 0; | |
858 | delete[] fNSegRTPC; fNSegRTPC = 0; | |
859 | delete[] fSegIDTPC; fSegIDTPC = 0; | |
860 | } | |
861 | fNParamsTPC = fNZSegTPC = fNPSegTPC = fNRSegTPC = 0; | |
862 | fMinZTPC = 1e6; | |
863 | fMaxZTPC = -1e6; | |
864 | fMaxRTPC = 0; | |
865 | // | |
866 | } | |
867 | ||
47c3d315 | 868 | //__________________________________________________________________________________________ |
869 | void AliMagWrapCheb::ResetTPCRatInt() | |
870 | { | |
871 | // clean TPCRat field integral (used for update) | |
872 | if (fNParamsTPCRat) { | |
873 | delete fParamsTPCRat; fParamsTPCRat = 0; | |
874 | delete[] fSegZTPCRat; fSegZTPCRat = 0; | |
875 | delete[] fSegPTPCRat; fSegPTPCRat = 0; | |
876 | delete[] fSegRTPCRat; fSegRTPCRat = 0; | |
877 | delete[] fBegSegPTPCRat; fBegSegPTPCRat = 0; | |
878 | delete[] fNSegPTPCRat; fNSegPTPCRat = 0; | |
879 | delete[] fBegSegRTPCRat; fBegSegRTPCRat = 0; | |
880 | delete[] fNSegRTPCRat; fNSegRTPCRat = 0; | |
881 | delete[] fSegIDTPCRat; fSegIDTPCRat = 0; | |
882 | } | |
883 | fNParamsTPCRat = fNZSegTPCRat = fNPSegTPCRat = fNRSegTPCRat = 0; | |
884 | fMinZTPCRat = 1e6; | |
885 | fMaxZTPCRat = -1e6; | |
886 | fMaxRTPCRat = 0; | |
887 | // | |
888 | } | |
889 | ||
1d18ebe0 | 890 | |
891 | //__________________________________________________ | |
892 | void AliMagWrapCheb::BuildTable(Int_t npar,TObjArray *parArr, Int_t &nZSeg, Int_t &nYSeg, Int_t &nXSeg, | |
893 | Float_t &minZ,Float_t &maxZ, | |
894 | Float_t **segZ,Float_t **segY,Float_t **segX, | |
895 | Int_t **begSegY,Int_t **nSegY, | |
896 | Int_t **begSegX,Int_t **nSegX, | |
897 | Int_t **segID) | |
898 | { | |
899 | // build lookup table for dipole | |
900 | // | |
901 | if (npar<1) return; | |
902 | TArrayF segYArr,segXArr; | |
903 | TArrayI begSegYDipArr,begSegXDipArr; | |
904 | TArrayI nSegYDipArr,nSegXDipArr; | |
905 | TArrayI segIDArr; | |
906 | float *tmpSegZ,*tmpSegY,*tmpSegX; | |
907 | // | |
908 | // create segmentation in Z | |
909 | nZSeg = SegmentDimension(&tmpSegZ, parArr, npar, 2, 1,-1, 1,-1, 1,-1) - 1; | |
910 | nYSeg = 0; | |
911 | nXSeg = 0; | |
912 | // | |
913 | // for each Z slice create segmentation in Y | |
914 | begSegYDipArr.Set(nZSeg); | |
915 | nSegYDipArr.Set(nZSeg); | |
916 | float xyz[3]; | |
917 | for (int iz=0;iz<nZSeg;iz++) { | |
918 | printf("\nZSegment#%d %+e : %+e\n",iz,tmpSegZ[iz],tmpSegZ[iz+1]); | |
919 | int ny = SegmentDimension(&tmpSegY, parArr, npar, 1, | |
920 | 1,-1, 1,-1, tmpSegZ[iz],tmpSegZ[iz+1]) - 1; | |
921 | segYArr.Set(ny + nYSeg); | |
922 | for (int iy=0;iy<ny;iy++) segYArr[nYSeg+iy] = tmpSegY[iy]; | |
923 | begSegYDipArr[iz] = nYSeg; | |
924 | nSegYDipArr[iz] = ny; | |
925 | printf(" Found %d YSegments, to start from %d\n",ny, begSegYDipArr[iz]); | |
926 | // | |
927 | // for each slice in Z and Y create segmentation in X | |
928 | begSegXDipArr.Set(nYSeg+ny); | |
929 | nSegXDipArr.Set(nYSeg+ny); | |
930 | xyz[2] = (tmpSegZ[iz]+tmpSegZ[iz+1])/2.; // mean Z of this segment | |
931 | // | |
932 | for (int iy=0;iy<ny;iy++) { | |
933 | int isg = nYSeg+iy; | |
934 | printf("\n YSegment#%d %+e : %+e\n",iy, tmpSegY[iy],tmpSegY[iy+1]); | |
935 | int nx = SegmentDimension(&tmpSegX, parArr, npar, 0, | |
936 | 1,-1, tmpSegY[iy],tmpSegY[iy+1], tmpSegZ[iz],tmpSegZ[iz+1]) - 1; | |
937 | // | |
938 | segXArr.Set(nx + nXSeg); | |
939 | for (int ix=0;ix<nx;ix++) segXArr[nXSeg+ix] = tmpSegX[ix]; | |
940 | begSegXDipArr[isg] = nXSeg; | |
941 | nSegXDipArr[isg] = nx; | |
942 | printf(" Found %d XSegments, to start from %d\n",nx, begSegXDipArr[isg]); | |
943 | // | |
944 | segIDArr.Set(nXSeg+nx); | |
945 | // | |
946 | // find corresponding params | |
947 | xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment | |
948 | // | |
949 | for (int ix=0;ix<nx;ix++) { | |
950 | xyz[0] = (tmpSegX[ix]+tmpSegX[ix+1])/2.; // mean X of this segment | |
951 | for (int ipar=0;ipar<npar;ipar++) { | |
952 | AliCheb3D* cheb = (AliCheb3D*) parArr->At(ipar); | |
953 | if (!cheb->IsInside(xyz)) continue; | |
954 | segIDArr[nXSeg+ix] = ipar; | |
955 | break; | |
956 | } | |
957 | } | |
958 | nXSeg += nx; | |
959 | // | |
960 | delete[] tmpSegX; | |
961 | } | |
962 | delete[] tmpSegY; | |
963 | nYSeg += ny; | |
964 | } | |
965 | // | |
966 | minZ = tmpSegZ[0]; | |
967 | maxZ = tmpSegZ[nZSeg]; | |
968 | (*segZ) = new Float_t[nZSeg]; | |
969 | for (int i=nZSeg;i--;) (*segZ)[i] = tmpSegZ[i]; | |
970 | delete[] tmpSegZ; | |
971 | // | |
972 | (*segY) = new Float_t[nYSeg]; | |
973 | (*segX) = new Float_t[nXSeg]; | |
974 | (*begSegY) = new Int_t[nZSeg]; | |
975 | (*nSegY) = new Int_t[nZSeg]; | |
976 | (*begSegX) = new Int_t[nYSeg]; | |
977 | (*nSegX) = new Int_t[nYSeg]; | |
978 | (*segID) = new Int_t[nXSeg]; | |
979 | // | |
980 | for (int i=nYSeg;i--;) (*segY)[i] = segYArr[i]; | |
981 | for (int i=nXSeg;i--;) (*segX)[i] = segXArr[i]; | |
982 | for (int i=nZSeg;i--;) {(*begSegY)[i] = begSegYDipArr[i]; (*nSegY)[i] = nSegYDipArr[i];} | |
983 | for (int i=nYSeg;i--;) {(*begSegX)[i] = begSegXDipArr[i]; (*nSegX)[i] = nSegXDipArr[i];} | |
984 | for (int i=nXSeg;i--;) {(*segID)[i] = segIDArr[i];} | |
da7cd221 | 985 | // |
986 | } | |
987 | ||
1d18ebe0 | 988 | /* |
da7cd221 | 989 | //__________________________________________________ |
990 | void AliMagWrapCheb::BuildTableDip() | |
991 | { | |
992 | // build lookup table for dipole | |
993 | // | |
82d1e556 | 994 | if (fNParamsDip<1) return; |
da7cd221 | 995 | TArrayF segY,segX; |
996 | TArrayI begSegYDip,begSegXDip; | |
997 | TArrayI nsegYDip,nsegXDip; | |
998 | TArrayI segID; | |
999 | float *tmpSegZ,*tmpSegY,*tmpSegX; | |
1000 | // | |
1001 | // create segmentation in Z | |
1d18ebe0 | 1002 | fNZSegDip = SegmentDimension(&tmpSegZ, fParamsDip, fNParamsDip, 2, 1,-1, 1,-1, 1,-1) - 1; |
da7cd221 | 1003 | fNYSegDip = 0; |
1004 | fNXSegDip = 0; | |
1005 | // | |
1006 | // for each Z slice create segmentation in Y | |
1007 | begSegYDip.Set(fNZSegDip); | |
1008 | nsegYDip.Set(fNZSegDip); | |
1009 | float xyz[3]; | |
1010 | for (int iz=0;iz<fNZSegDip;iz++) { | |
1011 | printf("\nZSegment#%d %+e : %+e\n",iz,tmpSegZ[iz],tmpSegZ[iz+1]); | |
1d18ebe0 | 1012 | int ny = SegmentDimension(&tmpSegY, fParamsDip, fNParamsDip, 1, |
da7cd221 | 1013 | 1,-1, 1,-1, tmpSegZ[iz],tmpSegZ[iz+1]) - 1; |
1014 | segY.Set(ny + fNYSegDip); | |
1015 | for (int iy=0;iy<ny;iy++) segY[fNYSegDip+iy] = tmpSegY[iy]; | |
1016 | begSegYDip[iz] = fNYSegDip; | |
1017 | nsegYDip[iz] = ny; | |
1018 | printf(" Found %d YSegments, to start from %d\n",ny, begSegYDip[iz]); | |
1019 | // | |
1020 | // for each slice in Z and Y create segmentation in X | |
1021 | begSegXDip.Set(fNYSegDip+ny); | |
1022 | nsegXDip.Set(fNYSegDip+ny); | |
1023 | xyz[2] = (tmpSegZ[iz]+tmpSegZ[iz+1])/2.; // mean Z of this segment | |
1024 | // | |
1025 | for (int iy=0;iy<ny;iy++) { | |
1026 | int isg = fNYSegDip+iy; | |
1027 | printf("\n YSegment#%d %+e : %+e\n",iy, tmpSegY[iy],tmpSegY[iy+1]); | |
1d18ebe0 | 1028 | int nx = SegmentDimension(&tmpSegX, fParamsDip, fNParamsDip, 0, |
1029 | 1,-1, tmpSegY[iy],tmpSegY[iy+1], tmpSegZ[iz],tmpSegZ[iz+1]) - 1; | |
da7cd221 | 1030 | // |
1031 | segX.Set(nx + fNXSegDip); | |
1032 | for (int ix=0;ix<nx;ix++) segX[fNXSegDip+ix] = tmpSegX[ix]; | |
1033 | begSegXDip[isg] = fNXSegDip; | |
1034 | nsegXDip[isg] = nx; | |
1035 | printf(" Found %d XSegments, to start from %d\n",nx, begSegXDip[isg]); | |
1036 | // | |
1037 | segID.Set(fNXSegDip+nx); | |
1038 | // | |
1039 | // find corresponding params | |
1040 | xyz[1] = (tmpSegY[iy]+tmpSegY[iy+1])/2.; // mean Y of this segment | |
1041 | // | |
1042 | for (int ix=0;ix<nx;ix++) { | |
1043 | xyz[0] = (tmpSegX[ix]+tmpSegX[ix+1])/2.; // mean X of this segment | |
1044 | for (int ipar=0;ipar<fNParamsDip;ipar++) { | |
1045 | AliCheb3D* cheb = (AliCheb3D*) fParamsDip->At(ipar); | |
1046 | if (!cheb->IsInside(xyz)) continue; | |
1047 | segID[fNXSegDip+ix] = ipar; | |
1048 | break; | |
95d9681f | 1049 | } |
da7cd221 | 1050 | } |
1051 | fNXSegDip += nx; | |
1052 | // | |
1053 | delete[] tmpSegX; | |
5de97576 | 1054 | } |
da7cd221 | 1055 | delete[] tmpSegY; |
1056 | fNYSegDip += ny; | |
1057 | } | |
1058 | // | |
1059 | fMinZDip = tmpSegZ[0]; | |
1060 | fMaxZDip = tmpSegZ[fNZSegDip]; | |
1061 | fSegZDip = new Float_t[fNZSegDip]; | |
1062 | for (int i=fNZSegDip;i--;) fSegZDip[i] = tmpSegZ[i]; | |
1063 | delete[] tmpSegZ; | |
1064 | // | |
1065 | fSegYDip = new Float_t[fNYSegDip]; | |
1066 | fSegXDip = new Float_t[fNXSegDip]; | |
1067 | fBegSegYDip = new Int_t[fNZSegDip]; | |
1068 | fNSegYDip = new Int_t[fNZSegDip]; | |
1069 | fBegSegXDip = new Int_t[fNYSegDip]; | |
1070 | fNSegXDip = new Int_t[fNYSegDip]; | |
1071 | fSegIDDip = new Int_t[fNXSegDip]; | |
1072 | // | |
1073 | for (int i=fNYSegDip;i--;) fSegYDip[i] = segY[i]; | |
1074 | for (int i=fNXSegDip;i--;) fSegXDip[i] = segX[i]; | |
1075 | for (int i=fNZSegDip;i--;) {fBegSegYDip[i] = begSegYDip[i]; fNSegYDip[i] = nsegYDip[i];} | |
1076 | for (int i=fNYSegDip;i--;) {fBegSegXDip[i] = begSegXDip[i]; fNSegXDip[i] = nsegXDip[i];} | |
1077 | for (int i=fNXSegDip;i--;) {fSegIDDip[i] = segID[i];} | |
1078 | // | |
a1dde210 | 1079 | } |
1d18ebe0 | 1080 | */ |
a1dde210 | 1081 | |
1d18ebe0 | 1082 | //________________________________________________________________ |
da7cd221 | 1083 | void AliMagWrapCheb::SaveData(const char* outfile) const |
1084 | { | |
1085 | // writes coefficients data to output text file | |
1086 | TString strf = outfile; | |
1087 | gSystem->ExpandPathName(strf); | |
1088 | FILE* stream = fopen(strf,"w+"); | |
1089 | // | |
1090 | // Sol part --------------------------------------------------------- | |
1091 | fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName()); | |
1092 | fprintf(stream,"START SOLENOID\n#Number of pieces\n%d\n",fNParamsSol); | |
1093 | for (int ip=0;ip<fNParamsSol;ip++) GetParamSol(ip)->SaveData(stream); | |
1094 | fprintf(stream,"#\nEND SOLENOID\n"); | |
1095 | // | |
1096 | // TPCInt part --------------------------------------------------------- | |
1097 | fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName()); | |
1d18ebe0 | 1098 | fprintf(stream,"START TPCINT\n#Number of pieces\n%d\n",fNParamsTPC); |
1099 | for (int ip=0;ip<fNParamsTPC;ip++) GetParamTPCInt(ip)->SaveData(stream); | |
da7cd221 | 1100 | fprintf(stream,"#\nEND TPCINT\n"); |
1101 | // | |
47c3d315 | 1102 | // TPCRatInt part --------------------------------------------------------- |
1103 | fprintf(stream,"# Set of Chebyshev parameterizations for ALICE magnetic field\nSTART %s\n",GetName()); | |
1104 | fprintf(stream,"START TPCRatINT\n#Number of pieces\n%d\n",fNParamsTPCRat); | |
1105 | for (int ip=0;ip<fNParamsTPCRat;ip++) GetParamTPCRatInt(ip)->SaveData(stream); | |
1106 | fprintf(stream,"#\nEND TPCRatINT\n"); | |
1107 | // | |
da7cd221 | 1108 | // Dip part --------------------------------------------------------- |
1109 | fprintf(stream,"START DIPOLE\n#Number of pieces\n%d\n",fNParamsDip); | |
1110 | for (int ip=0;ip<fNParamsDip;ip++) GetParamDip(ip)->SaveData(stream); | |
1111 | fprintf(stream,"#\nEND DIPOLE\n"); | |
1112 | // | |
1113 | fprintf(stream,"#\nEND %s\n",GetName()); | |
1114 | // | |
1115 | fclose(stream); | |
1116 | // | |
1117 | } | |
1118 | ||
1d18ebe0 | 1119 | Int_t AliMagWrapCheb::SegmentDimension(float** seg,const TObjArray* par,int npar, int dim, |
da7cd221 | 1120 | float xmn,float xmx,float ymn,float ymx,float zmn,float zmx) |
1121 | { | |
1122 | // find all boundaries in deimension dim for boxes in given region. | |
1123 | // if mn>mx for given projection the check is not done for it. | |
1124 | float *tmpC = new float[2*npar]; | |
1125 | int *tmpInd = new int[2*npar]; | |
1126 | int nseg0 = 0; | |
1127 | for (int ip=0;ip<npar;ip++) { | |
1128 | AliCheb3D* cheb = (AliCheb3D*) par->At(ip); | |
1129 | if (xmn<xmx && (cheb->GetBoundMin(0)>(xmx+xmn)/2 || cheb->GetBoundMax(0)<(xmn+xmx)/2)) continue; | |
1130 | if (ymn<ymx && (cheb->GetBoundMin(1)>(ymx+ymn)/2 || cheb->GetBoundMax(1)<(ymn+ymx)/2)) continue; | |
1131 | if (zmn<zmx && (cheb->GetBoundMin(2)>(zmx+zmn)/2 || cheb->GetBoundMax(2)<(zmn+zmx)/2)) continue; | |
1132 | // | |
1133 | tmpC[nseg0++] = cheb->GetBoundMin(dim); | |
1134 | tmpC[nseg0++] = cheb->GetBoundMax(dim); | |
1135 | } | |
1136 | // range Dim's boundaries in increasing order | |
1137 | TMath::Sort(nseg0,tmpC,tmpInd,kFALSE); | |
1138 | // count number of really different Z's | |
1139 | int nseg = 0; | |
1140 | float cprev = -1e6; | |
1141 | for (int ip=0;ip<nseg0;ip++) { | |
1142 | if (TMath::Abs(cprev-tmpC[ tmpInd[ip] ])>1e-4) { | |
1143 | cprev = tmpC[ tmpInd[ip] ]; | |
1144 | nseg++; | |
1145 | } | |
1146 | else tmpInd[ip] = -1; // supress redundant Z | |
1147 | } | |
1148 | // | |
1149 | *seg = new float[nseg]; // create final Z segmenations | |
1150 | nseg = 0; | |
1151 | for (int ip=0;ip<nseg0;ip++) if (tmpInd[ip]>=0) (*seg)[nseg++] = tmpC[ tmpInd[ip] ]; | |
1152 | // | |
1153 | delete[] tmpC; | |
1154 | delete[] tmpInd; | |
1155 | return nseg; | |
1156 | } | |
1157 | ||
1158 | #endif | |
1159 |