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 // Author: Andreas Morsch <andreas.morsch@cern.ch>
22 //-----------------------------------------------------------------------
27 #include "AliFieldMap.h"
31 //_______________________________________________________________________
32 AliFieldMap::AliFieldMap():
52 // Standard constructor
57 //_______________________________________________________________________
58 AliFieldMap::AliFieldMap(const char *name, const char *title):
79 // Standard constructor
85 //_______________________________________________________________________
86 AliFieldMap::~AliFieldMap()
94 //_______________________________________________________________________
95 AliFieldMap::AliFieldMap(const AliFieldMap &map):
121 //_______________________________________________________________________
122 void AliFieldMap::ReadField()
125 // Method to read the magnetic field map from file
128 // FILE* endf = fopen("end.table", "r");
129 // FILE* out = fopen("out", "w");
131 Int_t ix, iy, iz, ipx, ipy, ipz;
134 printf("%s: Reading Magnetic Field Map %s from file %s\n",
135 ClassName(),fName.Data(),fTitle.Data());
137 fname = gSystem->ExpandPathName(fTitle.Data());
138 magfile = fopen(fname,"r");
141 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
142 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
147 fXend = fXbeg + (fXn-1)*fXdel;
148 fYend = fYbeg + (fYn-1)*fYdel;
149 fZend = fZbeg + (fZn-1)*fZdel;
151 Int_t nDim = fXn*fYn*fZn;
155 fB = new TVector(3*nDim);
157 for (ix = 0; ix < fXn; ix++) {
159 for (iy = 0; iy < fYn; iy++) {
161 for (iz = 0; iz < fZn; iz++) {
165 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
166 } else if (iz > -1) {
167 fscanf(magfile," %f %f %f", &bx, &by, &bz);
172 // fscanf(magfile,"%f %f %f %f %f %f %f ",
173 // &x, &y, &z, &bx,&by,&bz, &b);
174 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
176 (*fB)(ipz+2) = 10.*bz;
177 (*fB)(ipz+1) = 10.*by;
178 (*fB)(ipz ) = 10.*bx;
184 // this part for interpolation between z = 700 and 720 cm to get
187 for (ix = 0; ix < fXn; ix++) {
189 for (iy = 0; iy < fYn; iy++) {
191 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
192 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
193 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
202 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
207 //_______________________________________________________________________
208 void AliFieldMap::Field(Float_t *x, Float_t *b)
211 // Use simple interpolation to obtain field at point x
213 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
214 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
215 const Double_t kone=1;
220 xl[0]=TMath::Abs(x[0])-fXbeg;
221 xl[1]=TMath::Abs(x[1])-fYbeg;
240 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
241 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
242 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
243 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
244 bhz = blyhz *raty1+bhyhz *raty;
245 blz = blylz *raty1+bhylz *raty;
246 b[0] = blz *ratz1+bhz *ratz;
248 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
249 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
250 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
251 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
252 bhz = blyhz *raty1+bhyhz *raty;
253 blz = blylz *raty1+bhylz *raty;
254 b[1] = blz *ratz1+bhz *ratz;
256 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
257 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
258 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
259 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
260 bhz = blyhz *raty1+bhyhz *raty;
261 blz = blylz *raty1+bhylz *raty;
262 b[2] = blz *ratz1+bhz *ratz;
265 //_______________________________________________________________________
266 void AliFieldMap::Copy(AliFieldMap & /* magf */) const
269 // Copy *this onto magf -- Not implemented
271 Fatal("Copy","Not implemented!\n");
274 //_______________________________________________________________________
275 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
281 //_______________________________________________________________________
282 void AliFieldMap::Streamer(TBuffer &R__b)
284 // Stream an object of class AliFieldMap.
287 if (R__b.IsReading()) {
288 AliFieldMap::Class()->ReadBuffer(R__b, this);
294 AliFieldMap::Class()->WriteBuffer(R__b, this);
295 if (!fWriteEnable) fB = save;