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 //-----------------------------------------------------------------------
30 #include "AliFieldMap.h"
34 //_______________________________________________________________________
35 AliFieldMap::AliFieldMap():
55 // Standard constructor
60 //_______________________________________________________________________
61 AliFieldMap::AliFieldMap(const char *name, const char *title):
82 // Standard constructor
88 //_______________________________________________________________________
89 AliFieldMap::~AliFieldMap()
97 //_______________________________________________________________________
98 AliFieldMap::AliFieldMap(const AliFieldMap &map):
124 //_______________________________________________________________________
125 void AliFieldMap::ReadField()
128 // Method to read the magnetic field map from file
131 // FILE* endf = fopen("end.table", "r");
132 // FILE* out = fopen("out", "w");
134 Int_t ix, iy, iz, ipx, ipy, ipz;
137 printf("%s: Reading Magnetic Field Map %s from file %s\n",
138 ClassName(),fName.Data(),fTitle.Data());
140 fname = gSystem->ExpandPathName(fTitle.Data());
141 magfile = fopen(fname,"r");
144 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
145 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
150 fXend = fXbeg + (fXn-1)*fXdel;
151 fYend = fYbeg + (fYn-1)*fYdel;
152 fZend = fZbeg + (fZn-1)*fZdel;
154 Int_t nDim = fXn*fYn*fZn;
158 fB = new TVector(3*nDim);
160 for (ix = 0; ix < fXn; ix++) {
162 for (iy = 0; iy < fYn; iy++) {
164 for (iz = 0; iz < fZn; iz++) {
168 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
169 } else if (iz > -1) {
170 fscanf(magfile," %f %f %f", &bx, &by, &bz);
175 // fscanf(magfile,"%f %f %f %f %f %f %f ",
176 // &x, &y, &z, &bx,&by,&bz, &b);
177 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
179 (*fB)(ipz+2) = 10.*bz;
180 (*fB)(ipz+1) = 10.*by;
181 (*fB)(ipz ) = 10.*bx;
187 // this part for interpolation between z = 700 and 720 cm to get
190 for (ix = 0; ix < fXn; ix++) {
192 for (iy = 0; iy < fYn; iy++) {
194 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
195 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
196 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
205 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
210 //_______________________________________________________________________
211 void AliFieldMap::Field(Float_t *x, Float_t *b) const
214 // Use simple interpolation to obtain field at point x
216 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
217 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
218 const Double_t kone=1;
223 xl[0]=TMath::Abs(x[0])-fXbeg;
224 xl[1]=TMath::Abs(x[1])-fYbeg;
245 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
246 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
247 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
248 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
249 bhz = blyhz *raty1+bhyhz *raty;
250 blz = blylz *raty1+bhylz *raty;
251 b[0] = blz *ratz1+bhz *ratz;
253 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
254 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
255 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
256 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
257 bhz = blyhz *raty1+bhyhz *raty;
258 blz = blylz *raty1+bhylz *raty;
259 b[1] = blz *ratz1+bhz *ratz;
261 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
262 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
263 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
264 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
265 bhz = blyhz *raty1+bhyhz *raty;
266 blz = blylz *raty1+bhylz *raty;
267 b[2] = blz *ratz1+bhz *ratz;
270 //_______________________________________________________________________
271 void AliFieldMap::Copy(TObject & /* magf */) const
274 // Copy *this onto magf -- Not implemented
276 Fatal("Copy","Not implemented!\n");
279 //_______________________________________________________________________
280 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
286 //_______________________________________________________________________
287 void AliFieldMap::Streamer(TBuffer &R__b)
289 // Stream an object of class AliFieldMap.
292 if (R__b.IsReading()) {
293 AliFieldMap::Class()->ReadBuffer(R__b, this);
299 AliFieldMap::Class()->WriteBuffer(R__b, this);
300 if (!fWriteEnable) fB = save;