1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------
20 // Class to handle the field
21 // I/O and interpolation
22 // of the field map to return the value
23 // of the magnetic field in an arbitrary position
24 // Author: Andreas Morsch <andreas.morsch@cern.ch>
26 //-----------------------------------------------------------------------
33 #include "AliFieldMap.h"
37 //_______________________________________________________________________
38 AliFieldMap::AliFieldMap():
58 // Standard constructor
63 //_______________________________________________________________________
64 AliFieldMap::AliFieldMap(const char *name, const char *title):
85 // Standard constructor
91 //_______________________________________________________________________
92 AliFieldMap::~AliFieldMap()
100 //_______________________________________________________________________
101 AliFieldMap::AliFieldMap(const AliFieldMap &map):
127 //_______________________________________________________________________
128 void AliFieldMap::ReadField()
131 // Method to read the magnetic field map from file
134 // FILE* endf = fopen("end.table", "r");
135 // FILE* out = fopen("out", "w");
137 Int_t ix, iy, iz, ipx, ipy, ipz;
140 AliInfo(Form("Reading Magnetic Field Map %s from file %s",
141 fName.Data(),fTitle.Data()));
143 fname = gSystem->ExpandPathName(fTitle.Data());
144 magfile = fopen(fname,"r");
147 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
148 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
153 fXend = fXbeg + (fXn-1)*fXdel;
154 fYend = fYbeg + (fYn-1)*fYdel;
155 fZend = fZbeg + (fZn-1)*fZdel;
157 Int_t nDim = fXn*fYn*fZn;
161 fB = new TVector(3*nDim);
163 for (ix = 0; ix < fXn; ix++) {
165 for (iy = 0; iy < fYn; iy++) {
167 for (iz = 0; iz < fZn; iz++) {
171 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
172 } else if (iz > -1) {
173 fscanf(magfile," %f %f %f", &bx, &by, &bz);
178 // fscanf(magfile,"%f %f %f %f %f %f %f ",
179 // &x, &y, &z, &bx,&by,&bz, &b);
180 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
182 (*fB)(ipz+2) = 10.*bz;
183 (*fB)(ipz+1) = 10.*by;
184 (*fB)(ipz ) = 10.*bx;
190 // this part for interpolation between z = 700 and 720 cm to get
193 for (ix = 0; ix < fXn; ix++) {
195 for (iy = 0; iy < fYn; iy++) {
197 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
198 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
199 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
208 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
213 //_______________________________________________________________________
214 void AliFieldMap::Field(float *x, float *b) const
217 // Use simple interpolation to obtain field at point x
219 float ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
220 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
226 xl[0] = x[0] - fXbeg;
227 xl[1] = x[1] - fYbeg;
228 xl[2] = x[2] - fZbeg;
230 hix=TMath::Max(0.,TMath::Min(xl[0]*fXdeli,fXn-1.0001));
234 hiy=TMath::Max(0.,TMath::Min(xl[1]*fYdeli,fYn-1.0001));
238 hiz=TMath::Max(0.,TMath::Min(xl[2]*fZdeli,fZn-1.0001));
248 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
249 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
250 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
251 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
252 bhz = blyhz *raty1+bhyhz *raty;
253 blz = blylz *raty1+bhylz *raty;
254 b[0] = blz *ratz1+bhz *ratz;
256 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
257 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
258 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
259 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
260 bhz = blyhz *raty1+bhyhz *raty;
261 blz = blylz *raty1+bhylz *raty;
262 b[1] = blz *ratz1+bhz *ratz;
264 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
265 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
266 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
267 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
268 bhz = blyhz *raty1+bhyhz *raty;
269 blz = blylz *raty1+bhylz *raty;
270 b[2] = blz *ratz1+bhz *ratz;
273 //_______________________________________________________________________
274 void AliFieldMap::Field(double *x, double *b) const
277 // Use simple interpolation to obtain field at point x
279 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
280 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
281 const Double_t kone=1;
286 xl[0] = x[0] - fXbeg;
287 xl[1] = x[1] - fYbeg;
288 xl[2] = x[2] - fZbeg;
290 hix=TMath::Max(0.,TMath::Min(xl[0]*fXdeli,fXn-1.0001));
294 hiy=TMath::Max(0.,TMath::Min(xl[1]*fYdeli,fYn-1.0001));
298 hiz=TMath::Max(0.,TMath::Min(xl[2]*fZdeli,fZn-1.0001));
308 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
309 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
310 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
311 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
312 bhz = blyhz *raty1+bhyhz *raty;
313 blz = blylz *raty1+bhylz *raty;
314 b[0] = blz *ratz1+bhz *ratz;
316 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
317 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
318 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
319 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
320 bhz = blyhz *raty1+bhyhz *raty;
321 blz = blylz *raty1+bhylz *raty;
322 b[1] = blz *ratz1+bhz *ratz;
324 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
325 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
326 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
327 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
328 bhz = blyhz *raty1+bhyhz *raty;
329 blz = blylz *raty1+bhylz *raty;
330 b[2] = blz *ratz1+bhz *ratz;
333 //_______________________________________________________________________
334 void AliFieldMap::Copy(TObject & /* magf */) const
337 // Copy *this onto magf -- Not implemented
339 AliFatal("Not implemented!");
342 //_______________________________________________________________________
343 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
349 //_______________________________________________________________________
350 void AliFieldMap::Streamer(TBuffer &R__b)
352 // Stream an object of class AliFieldMap.
355 if (R__b.IsReading()) {
356 AliFieldMap::Class()->ReadBuffer(R__b, this);
362 AliFieldMap::Class()->WriteBuffer(R__b, this);
363 if (!fWriteEnable) fB = save;