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 //-----------------------------------------------------------------------
19 // Class to read the magnetic field map and to calculate
20 // the magnetic field in a given point. For the moment uses a simple
21 // linear interpolation between the nodes of a rectangular grid
22 // Author: Andreas Morsch <andreas.morsch@cern.ch>
23 //-----------------------------------------------------------------------
28 #include "AliFieldMap.h"
32 //_______________________________________________________________________
33 AliFieldMap::AliFieldMap():
53 // Standard constructor
58 //_______________________________________________________________________
59 AliFieldMap::AliFieldMap(const char *name, const char *title):
80 // Standard constructor
86 //_______________________________________________________________________
87 AliFieldMap::~AliFieldMap()
95 //_______________________________________________________________________
96 AliFieldMap::AliFieldMap(const AliFieldMap &map):
122 //_______________________________________________________________________
123 void AliFieldMap::ReadField()
126 // Method to read the magnetic field map from file
129 // FILE* endf = fopen("end.table", "r");
130 // FILE* out = fopen("out", "w");
132 Int_t ix, iy, iz, ipx, ipy, ipz;
135 printf("%s: Reading Magnetic Field Map %s from file %s\n",
136 ClassName(),fName.Data(),fTitle.Data());
138 fname = gSystem->ExpandPathName(fTitle.Data());
139 magfile = fopen(fname,"r");
142 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
143 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
148 fXend = fXbeg + (fXn-1)*fXdel;
149 fYend = fYbeg + (fYn-1)*fYdel;
150 fZend = fZbeg + (fZn-1)*fZdel;
152 Int_t nDim = fXn*fYn*fZn;
156 fB = new TVector(3*nDim);
158 for (ix = 0; ix < fXn; ix++) {
160 for (iy = 0; iy < fYn; iy++) {
162 for (iz = 0; iz < fZn; iz++) {
166 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
167 } else if (iz > -1) {
168 fscanf(magfile," %f %f %f", &bx, &by, &bz);
173 // fscanf(magfile,"%f %f %f %f %f %f %f ",
174 // &x, &y, &z, &bx,&by,&bz, &b);
175 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
177 (*fB)(ipz+2) = 10.*bz;
178 (*fB)(ipz+1) = 10.*by;
179 (*fB)(ipz ) = 10.*bx;
185 // this part for interpolation between z = 700 and 720 cm to get
188 for (ix = 0; ix < fXn; ix++) {
190 for (iy = 0; iy < fYn; iy++) {
192 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
193 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
194 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
203 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
208 //_______________________________________________________________________
209 // void AliFieldMap::Field(Float_t *x, Float_t *b)
212 // // Use simple interpolation to obtain field at point x
214 // Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
215 // bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
216 // const Double_t kone=1;
221 // xl[0]=TMath::Abs(x[0])-fXbeg;
222 // xl[1]=TMath::Abs(x[1])-fYbeg;
226 // ratx=hix-int(hix);
230 // raty=hiy-int(hiy);
234 // ratz=hiz-int(hiz);
241 // bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
242 // bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
243 // blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
244 // blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
245 // bhz = blyhz *raty1+bhyhz *raty;
246 // blz = blylz *raty1+bhylz *raty;
247 // b[0] = blz *ratz1+bhz *ratz;
249 // bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
250 // bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
251 // blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
252 // blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
253 // bhz = blyhz *raty1+bhyhz *raty;
254 // blz = blylz *raty1+bhylz *raty;
255 // b[1] = blz *ratz1+bhz *ratz;
257 // bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
258 // bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
259 // blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
260 // blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
261 // bhz = blyhz *raty1+bhyhz *raty;
262 // blz = blylz *raty1+bhylz *raty;
263 // b[2] = blz *ratz1+bhz *ratz;
265 //_______________________________________________________________________
266 void AliFieldMap::Field(Float_t *x, Float_t *b)
269 // Use simple interpolation to obtain field at point x
270 // Faster version which uses direct access to the TVector
271 // instead of Bx(...), By(...), Bz(...) interfaces.
272 // The interpolation is done first in Z (4 points),
273 // then in Y (2 points), and finally in X direction (one point).
275 Double_t h=(x[2]-fZbeg)*fZdeli;
276 Int_t i=int(h); // ix
277 register Int_t index=i;
279 Double_t ratz1=1-ratz;
281 h=(TMath::Abs(x[1])-fYbeg)*fYdeli;
285 Double_t raty1=1-raty;
287 h=(TMath::Abs(x[0])-fXbeg)*fXdeli;
290 index*=3; //index now points to the beginning of the field data (ix,iy,iz)
292 Double_t ratx1=1-ratx;
294 // The way we retrive data from fB should be optimized
295 // with respect to the CPU cache
297 Float_t bx00=(*fB)[index++]*ratz1;
298 Float_t by00=(*fB)[index++]*ratz1;
299 Float_t bz00=(*fB)[index++]*ratz1;
300 bx00+=(*fB)[index++]*ratz;
301 by00+=(*fB)[index++]*ratz;
302 bz00+=(*fB)[index]*ratz;
306 Float_t bx01=(*fB)[index++]*ratz1;
307 Float_t by01=(*fB)[index++]*ratz1;
308 Float_t bz01=(*fB)[index++]*ratz1;
309 bx01+=(*fB)[index++]*ratz;
310 by01+=(*fB)[index++]*ratz;
311 bz01+=(*fB)[index]*ratz;
313 index+=(3*fYn*fZn-5);
315 Float_t bx11=(*fB)[index++]*ratz1;
316 Float_t by11=(*fB)[index++]*ratz1;
317 Float_t bz11=(*fB)[index++]*ratz1;
318 bx11+=(*fB)[index++]*ratz;
319 by11+=(*fB)[index++]*ratz;
320 bz11+=(*fB)[index]*ratz;
324 Float_t bx10=(*fB)[index++]*ratz1;
325 Float_t by10=(*fB)[index++]*ratz1;
326 Float_t bz10=(*fB)[index++]*ratz1;
327 bx10+=(*fB)[index++]*ratz;
328 by10+=(*fB)[index++]*ratz;
329 bz10+=(*fB)[index]*ratz;
331 b[0]= (bx00*raty1+bx01*raty)*ratx1 +(bx10*raty1+bx11*raty)*ratx;
332 b[1]= (by00*raty1+by01*raty)*ratx1 +(by10*raty1+by11*raty)*ratx;
333 b[2]= (bz00*raty1+bz01*raty)*ratx1 +(bz10*raty1+bz11*raty)*ratx;
336 //_______________________________________________________________________
337 void AliFieldMap::Copy(AliFieldMap & /* magf */) const
340 // Copy *this onto magf -- Not implemented
342 Fatal("Copy","Not implemented!\n");
345 //_______________________________________________________________________
346 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
352 //_______________________________________________________________________
353 void AliFieldMap::Streamer(TBuffer &R__b)
355 // Stream an object of class AliFieldMap.
358 if (R__b.IsReading()) {
359 AliFieldMap::Class()->ReadBuffer(R__b, this);
365 AliFieldMap::Class()->WriteBuffer(R__b, this);
366 if (!fWriteEnable) fB = save;