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 Revision 1.3.6.1 2002/07/24 10:08:13 alibrary
21 Revision 1.4 2002/07/10 15:06:22 morsch
22 Initialize TVector* save.
24 Revision 1.3 2002/02/26 16:13:07 morsch
25 Correction in streamer.
27 Revision 1.2 2002/02/22 14:00:20 morsch
28 Protection against replication of fieldmap data in gAlice.
30 Revision 1.1 2002/02/14 11:41:28 morsch
31 Magnetic field map for ALICE for L3+muon spectrometer stored in 3 seperate
37 // Author: Andreas Morsch <andreas.morsch@cern.ch>
41 #include "AliFieldMap.h"
46 //________________________________________
47 AliFieldMap::AliFieldMap()
50 // Standard constructor
56 AliFieldMap::AliFieldMap(const char *name, const char *title)
60 // Standard constructor
67 AliFieldMap::~AliFieldMap()
75 //________________________________________
76 AliFieldMap::AliFieldMap(const AliFieldMap &map)
84 //________________________________________
85 void AliFieldMap::ReadField()
88 // Method to read the magnetic field map from file
91 // FILE* endf = fopen("end.table", "r");
92 // FILE* out = fopen("out", "w");
94 Int_t ix, iy, iz, ipx, ipy, ipz;
97 printf("%s: Reading Magnetic Field Map %s from file %s\n",
98 ClassName(),fName.Data(),fTitle.Data());
100 fname = gSystem->ExpandPathName(fTitle.Data());
101 magfile = fopen(fname,"r");
104 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
105 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
110 fXend = fXbeg + (fXn-1)*fXdel;
111 fYend = fYbeg + (fYn-1)*fYdel;
112 fZend = fZbeg + (fZn-1)*fZdel;
114 Int_t nDim = fXn*fYn*fZn;
118 fB = new TVector(3*nDim);
120 for (ix = 0; ix < fXn; ix++) {
122 for (iy = 0; iy < fYn; iy++) {
124 for (iz = 0; iz < fZn; iz++) {
128 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
129 } else if (iz > -1) {
130 fscanf(magfile," %f %f %f", &bx, &by, &bz);
135 // fscanf(magfile,"%f %f %f %f %f %f %f ",
136 // &x, &y, &z, &bx,&by,&bz, &b);
137 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
139 (*fB)(ipz+2) = 10.*bz;
140 (*fB)(ipz+1) = 10.*by;
141 (*fB)(ipz ) = 10.*bx;
147 // this part for interpolation between z = 700 and 720 cm to get
150 for (ix = 0; ix < fXn; ix++) {
152 for (iy = 0; iy < fYn; iy++) {
154 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
155 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
156 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
165 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
170 void AliFieldMap::Field(Float_t *x, Float_t *b)
173 // Use simple interpolation to obtain field at point x
175 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
176 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
177 const Double_t kone=1;
182 xl[0]=TMath::Abs(x[0])-fXbeg;
183 xl[1]=TMath::Abs(x[1])-fYbeg;
202 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
203 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
204 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
205 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
206 bhz = blyhz *raty1+bhyhz *raty;
207 blz = blylz *raty1+bhylz *raty;
208 b[0] = blz *ratz1+bhz *ratz;
210 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
211 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
212 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
213 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
214 bhz = blyhz *raty1+bhyhz *raty;
215 blz = blylz *raty1+bhylz *raty;
216 b[1] = blz *ratz1+bhz *ratz;
218 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
219 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
220 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
221 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
222 bhz = blyhz *raty1+bhyhz *raty;
223 blz = blylz *raty1+bhylz *raty;
224 b[2] = blz *ratz1+bhz *ratz;
227 //________________________________________
228 void AliFieldMap::Copy(AliFieldMap & /* magf */) const
231 // Copy *this onto magf -- Not implemented
233 Fatal("Copy","Not implemented!\n");
236 //________________________________________
237 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
243 void AliFieldMap::Streamer(TBuffer &R__b)
245 // Stream an object of class AliFieldMap.
248 if (R__b.IsReading()) {
249 AliFieldMap::Class()->ReadBuffer(R__b, this);
255 AliFieldMap::Class()->WriteBuffer(R__b, this);
256 if (!fWriteEnable) fB = save;