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 2002/02/26 16:13:07 morsch
19 Correction in streamer.
21 Revision 1.2 2002/02/22 14:00:20 morsch
22 Protection against replication of fieldmap data in gAlice.
24 Revision 1.1 2002/02/14 11:41:28 morsch
25 Magnetic field map for ALICE for L3+muon spectrometer stored in 3 seperate
31 // Author: Andreas Morsch <andreas.morsch@cern.ch>
35 #include "AliFieldMap.h"
40 //________________________________________
41 AliFieldMap::AliFieldMap()
44 // Standard constructor
50 AliFieldMap::AliFieldMap(const char *name, const char *title)
54 // Standard constructor
61 AliFieldMap::~AliFieldMap()
69 //________________________________________
70 AliFieldMap::AliFieldMap(const AliFieldMap &map)
78 //________________________________________
79 void AliFieldMap::ReadField()
82 // Method to read the magnetic field map from file
85 // FILE* endf = fopen("end.table", "r");
86 // FILE* out = fopen("out", "w");
88 Int_t ix, iy, iz, ipx, ipy, ipz;
91 printf("%s: Reading Magnetic Field Map %s from file %s\n",
92 ClassName(),fName.Data(),fTitle.Data());
94 fname = gSystem->ExpandPathName(fTitle.Data());
95 magfile = fopen(fname,"r");
98 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
99 &fXn, &fYn, &fZn, &fXbeg, &fYbeg, &fZbeg, &fXdel, &fYdel, &fZdel);
104 fXend = fXbeg + (fXn-1)*fXdel;
105 fYend = fYbeg + (fYn-1)*fYdel;
106 fZend = fZbeg + (fZn-1)*fZdel;
108 Int_t nDim = fXn*fYn*fZn;
112 fB = new TVector(3*nDim);
114 for (ix = 0; ix < fXn; ix++) {
116 for (iy = 0; iy < fYn; iy++) {
118 for (iz = 0; iz < fZn; iz++) {
122 // fscanf(endf,"%f %f %f", &bx,&by,&bz);
123 } else if (iz > -1) {
124 fscanf(magfile," %f %f %f", &bx, &by, &bz);
129 // fscanf(magfile,"%f %f %f %f %f %f %f ",
130 // &x, &y, &z, &bx,&by,&bz, &b);
131 // fprintf(out, "%15.8e %15.8e %15.8e \n", bx, by, bz);
133 (*fB)(ipz+2) = 10.*bz;
134 (*fB)(ipz+1) = 10.*by;
135 (*fB)(ipz ) = 10.*bx;
141 // this part for interpolation between z = 700 and 720 cm to get
144 for (ix = 0; ix < fXn; ix++) {
146 for (iy = 0; iy < fYn; iy++) {
148 Float_t bxx = (Bx(ix,iy,0) + Bx(ix,iy,2))/2.;
149 Float_t byy = (By(ix,iy,0) + By(ix,iy,2))/2.;
150 Float_t bzz = (Bz(ix,iy,0) + Bz(ix,iy,2))/2.;
159 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
164 void AliFieldMap::Field(Float_t *x, Float_t *b)
167 // Use simple interpolation to obtain field at point x
169 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
170 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
171 const Double_t kone=1;
176 xl[0]=TMath::Abs(x[0])-fXbeg;
177 xl[1]=TMath::Abs(x[1])-fYbeg;
196 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
197 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
198 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
199 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
200 bhz = blyhz *raty1+bhyhz *raty;
201 blz = blylz *raty1+bhylz *raty;
202 b[0] = blz *ratz1+bhz *ratz;
204 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
205 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
206 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
207 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
208 bhz = blyhz *raty1+bhyhz *raty;
209 blz = blylz *raty1+bhylz *raty;
210 b[1] = blz *ratz1+bhz *ratz;
212 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
213 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
214 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
215 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
216 bhz = blyhz *raty1+bhyhz *raty;
217 blz = blylz *raty1+bhylz *raty;
218 b[2] = blz *ratz1+bhz *ratz;
221 //________________________________________
222 void AliFieldMap::Copy(AliFieldMap & /* magf */) const
225 // Copy *this onto magf -- Not implemented
227 Fatal("Copy","Not implemented!\n");
230 //________________________________________
231 AliFieldMap & AliFieldMap::operator =(const AliFieldMap &magf)
237 void AliFieldMap::Streamer(TBuffer &R__b)
239 // Stream an object of class AliFieldMap.
242 if (R__b.IsReading()) {
243 AliFieldMap::Class()->ReadBuffer(R__b, this);
249 AliFieldMap::Class()->WriteBuffer(R__b, this);
250 if (!fWriteEnable) fB = save;