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 //-----------------------------------------------------------------------
32 #include "AliFieldMap.h"
36 //_______________________________________________________________________
37 AliFieldMap::AliFieldMap():
57 // Standard constructor
62 //_______________________________________________________________________
63 AliFieldMap::AliFieldMap(const char *name, const char *title):
84 // Standard constructor
90 //_______________________________________________________________________
91 AliFieldMap::~AliFieldMap()
99 //_______________________________________________________________________
100 AliFieldMap::AliFieldMap(const AliFieldMap &map):
126 //_______________________________________________________________________
127 void AliFieldMap::ReadField()
130 // Method to read the magnetic field map from file
133 // FILE* endf = fopen("end.table", "r");
134 // FILE* out = fopen("out", "w");
136 Int_t ix, iy, iz, ipx, ipy, ipz;
139 AliInfo(Form("Reading Magnetic Field Map %s from file %s",
140 fName.Data(),fTitle.Data()));
142 fname = gSystem->ExpandPathName(fTitle.Data());
143 magfile = fopen(fname,"r");
146 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
147 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
152 fXend = fXbeg + (fXn-1)*fXdel;
153 fYend = fYbeg + (fYn-1)*fYdel;
154 fZend = fZbeg + (fZn-1)*fZdel;
156 Int_t nDim = fXn*fYn*fZn;
160 fB = new TVector(3*nDim);
162 for (ix = 0; ix < fXn; ix++) {
164 for (iy = 0; iy < fYn; iy++) {
166 for (iz = 0; iz < fZn; iz++) {
170 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
171 } else if (iz > -1) {
172 fscanf(magfile," %f %f %f", &bx, &by, &bz);
177 // fscanf(magfile,"%f %f %f %f %f %f %f ",
178 // &x, &y, &z, &bx,&by,&bz, &b);
179 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
181 (*fB)(ipz+2) = 10.*bz;
182 (*fB)(ipz+1) = 10.*by;
183 (*fB)(ipz ) = 10.*bx;
189 // this part for interpolation between z = 700 and 720 cm to get
192 for (ix = 0; ix < fXn; ix++) {
194 for (iy = 0; iy < fYn; iy++) {
196 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
197 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
198 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
207 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
212 //_______________________________________________________________________
213 void AliFieldMap::Field(Float_t *x, Float_t *b) const
216 // Use simple interpolation to obtain field at point x
218 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
219 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
220 const Double_t kone=1;
225 xl[0] = x[0] - fXbeg;
226 xl[1] = x[1] - fYbeg;
227 xl[2] = x[2] - fZbeg;
229 hix=TMath::Max(0.,TMath::Min(xl[0]*fXdeli,fXn-1.0001));
233 hiy=TMath::Max(0.,TMath::Min(xl[1]*fYdeli,fYn-1.0001));
237 hiz=TMath::Max(0.,TMath::Min(xl[2]*fZdeli,fZn-1.0001));
247 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
248 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
249 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
250 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
251 bhz = blyhz *raty1+bhyhz *raty;
252 blz = blylz *raty1+bhylz *raty;
253 b[0] = blz *ratz1+bhz *ratz;
255 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
256 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
257 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
258 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
259 bhz = blyhz *raty1+bhyhz *raty;
260 blz = blylz *raty1+bhylz *raty;
261 b[1] = blz *ratz1+bhz *ratz;
263 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
264 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
265 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
266 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
267 bhz = blyhz *raty1+bhyhz *raty;
268 blz = blylz *raty1+bhylz *raty;
269 b[2] = blz *ratz1+bhz *ratz;
272 //_______________________________________________________________________
273 void AliFieldMap::Copy(TObject & /* magf */) const
276 // Copy *this onto magf -- Not implemented
278 AliFatal("Not implemented!");
281 //_______________________________________________________________________
282 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
288 //_______________________________________________________________________
289 void AliFieldMap::Streamer(TBuffer &R__b)
291 // Stream an object of class AliFieldMap.
294 if (R__b.IsReading()) {
295 AliFieldMap::Class()->ReadBuffer(R__b, this);
301 AliFieldMap::Class()->WriteBuffer(R__b, this);
302 if (!fWriteEnable) fB = save;