]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliMagFCM.cxx
Coding conventions (Annalisa)
[u/mrichter/AliRoot.git] / STEER / AliMagFCM.cxx
CommitLineData
aee8290b 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
acd84897 16/* $Id$ */
e2afb3b6 17
5d8718b8 18//-----------------------------------------------------------------------
19// Class for Alice magnetic field with constant mesh
20// Used in the configuration macros (macros/Config.C, etc.)
21// Author:
22//-----------------------------------------------------------------------
0742d588 23
fb17acd4 24#include "TSystem.h"
88cb7938 25
65fb704d 26#include "TVector.h"
aee8290b 27
594d8990 28#include "AliLog.h"
aee8290b 29#include "AliMagFCM.h"
aee8290b 30
31ClassImp(AliMagFCM)
32
e2afb3b6 33//_______________________________________________________________________
34AliMagFCM::AliMagFCM():
35 fXbeg(0),
36 fYbeg(0),
37 fZbeg(0),
38 fXdel(0),
39 fYdel(0),
40 fZdel(0),
41 fSolenoid(0),
42 fXdeli(0),
43 fYdeli(0),
44 fZdeli(0),
45 fXn(0),
46 fYn(0),
47 fZn(0),
48 fB(0)
49{
50 //
51 // Standard constructor
52 //
53 fType = kConMesh;
54 fMap = 2;
55 SetSolenoidField();
56}
57
58//_______________________________________________________________________
d0f1ee3b 59AliMagFCM::AliMagFCM(const char *name, const char *title, Int_t integ,
60 Float_t factor, Float_t fmax):
57754f18 61 AliMagFC(name,title,integ,factor,fmax),
e2afb3b6 62 fXbeg(0),
63 fYbeg(0),
64 fZbeg(0),
65 fXdel(0),
66 fYdel(0),
67 fZdel(0),
68 fSolenoid(0),
69 fXdeli(0),
70 fYdeli(0),
71 fZdeli(0),
72 fXn(0),
73 fYn(0),
74 fZn(0),
75 fB(0)
aee8290b 76{
77 //
78 // Standard constructor
79 //
80 fType = kConMesh;
d8408e76 81 fMap = 2;
4cc8933f 82 SetSolenoidField();
83
594d8990 84 AliDebug(1, Form(
85 "Constant Mesh Field %s created: map= %d, factor= %f, file= %s",
86 fName.Data(), fMap, factor,fTitle.Data()));
aee8290b 87}
88
e2afb3b6 89//_______________________________________________________________________
90AliMagFCM::AliMagFCM(const AliMagFCM &magf):
57754f18 91 AliMagFC(magf),
e2afb3b6 92 fXbeg(0),
93 fYbeg(0),
94 fZbeg(0),
95 fXdel(0),
96 fYdel(0),
97 fZdel(0),
98 fSolenoid(0),
99 fXdeli(0),
100 fYdeli(0),
101 fZdeli(0),
102 fXn(0),
103 fYn(0),
104 fZn(0),
105 fB(0)
aee8290b 106{
107 //
108 // Copy constructor
109 //
110 magf.Copy(*this);
111}
112
e2afb3b6 113//_______________________________________________________________________
6f3038e9 114void AliMagFCM::Field(Float_t *x, Float_t *b) const
aee8290b 115{
116 //
117 // Method to calculate the magnetic field
118 //
119 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
120 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
121 const Double_t kone=1;
122 Int_t ix, iy, iz;
123
124 // --- find the position in the grid ---
125
126 b[0]=b[1]=b[2]=0;
57754f18 127
128
129 if(-700 < -x[2] && -x[2] < fZbeg && x[0] * x[0] +(x[1]+30)*(x[1]+30) < 560*560) {
130 b[2]= fSolenoid;
aee8290b 131 } else {
57754f18 132 // The field map used here was calculated in a coordinate system where the muon arm is at z > 0
133 // Transfom x -> -x and z -> -z
134 Float_t xm = - x[0];
135 Float_t ym = x[1];
136 Float_t zm = - x[2];
137
138 Bool_t infield=(fZbeg <= zm && zm < fZbeg+fZdel*(fZn-1)
139 && ( fXbeg <= TMath::Abs(xm) && TMath::Abs(xm) < fXbeg+fXdel*(fXn-1) )
140 && ( fYbeg <= TMath::Abs(ym) && TMath::Abs(ym) < fYbeg+fYdel*(fYn-1) ));
aee8290b 141 if(infield) {
57754f18 142 xl[0]=TMath::Abs(xm)-fXbeg;
143 xl[1]=TMath::Abs(ym)-fYbeg;
144 xl[2]=zm-fZbeg;
aee8290b 145
146 // --- start with x
147
148 hix=xl[0]*fXdeli;
149 ratx=hix-int(hix);
150 ix=int(hix);
151
152 hiy=xl[1]*fYdeli;
153 raty=hiy-int(hiy);
154 iy=int(hiy);
155
156 hiz=xl[2]*fZdeli;
157 ratz=hiz-int(hiz);
158 iz=int(hiz);
159
160 if(fMap==2) {
161 // ... simple interpolation
162 ratx1=kone-ratx;
163 raty1=kone-raty;
164 ratz1=kone-ratz;
165 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
166 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
167 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
168 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
169 bhz = blyhz *raty1+bhyhz *raty;
170 blz = blylz *raty1+bhylz *raty;
171 b[0] = blz *ratz1+bhz *ratz;
172 //
173 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
174 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
175 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
176 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
177 bhz = blyhz *raty1+bhyhz *raty;
178 blz = blylz *raty1+bhylz *raty;
179 b[1] = blz *ratz1+bhz *ratz;
180 //
181 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
182 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
183 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
184 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
185 bhz = blyhz *raty1+bhyhz *raty;
186 blz = blylz *raty1+bhylz *raty;
187 b[2] = blz *ratz1+bhz *ratz;
188 //printf("ratx,raty,ratz,b[0],b[1],b[2] %f %f %f %f %f %f\n",
189 //ratx,raty,ratz,b[0],b[1],b[2]);
190 //
191 // ... use the dipole symmetry
57754f18 192 if (xm*ym < 0) b[1]=-b[1];
193 if (xm<0) b[2]=-b[2];
194 b[0] = -b[0];
195 b[2] = -b[2];
196
aee8290b 197 } else {
594d8990 198 AliError(Form("Invalid field map for constant mesh %d",fMap));
aee8290b 199 }
200 } else {
d95ea23f 201//This is the ZDC part
57754f18 202 ZDCField(x,b);
aee8290b 203 }
d95ea23f 204
57754f18 205 if(fFactor!=1) {
206 b[0]*=fFactor;
207 b[1]*=fFactor;
208 b[2]*=fFactor;
d95ea23f 209 }
aee8290b 210 }
aee8290b 211}
212
e2afb3b6 213//_______________________________________________________________________
aee8290b 214void AliMagFCM::ReadField()
215{
216 //
217 // Method to read the magnetic field map from file
218 //
219 FILE *magfile;
220 Int_t ix, iy, iz, ipx, ipy, ipz;
221 Float_t bx, by, bz;
222 char *fname;
594d8990 223 AliDebug(1,Form("Reading Magnetic Field %s from file %s",fName.Data(),fTitle.Data()));
aee8290b 224 fname = gSystem->ExpandPathName(fTitle.Data());
225 magfile=fopen(fname,"r");
226 delete [] fname;
227 if (magfile) {
228 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
229 &fXn, &fYn, &fZn, &fXdel, &fYdel, &fZdel, &fXbeg, &fYbeg, &fZbeg);
594d8990 230 AliDebug(2,Form("fXn %d, fYn %d, fZn %d, fXdel %f, fYdel %f, fZdel %f, fXbeg %f, fYbeg %f, fZbeg %f",
231 fXn, fYn, fZn, fXdel, fYdel, fZdel, fXbeg, fYbeg, fZbeg));
aee8290b 232 fXdeli=1./fXdel;
233 fYdeli=1./fYdel;
234 fZdeli=1./fZdel;
235 fB = new TVector(3*fXn*fYn*fZn);
236 for (iz=0; iz<fZn; iz++) {
237 ipz=iz*3*(fXn*fYn);
238 for (iy=0; iy<fYn; iy++) {
239 ipy=ipz+iy*3*fXn;
240 for (ix=0; ix<fXn; ix++) {
241 ipx=ipy+ix*3;
242 fscanf(magfile,"%f %f %f",&bz,&by,&bx);
243 (*fB)(ipx+2)=bz;
244 (*fB)(ipx+1)=by;
245 (*fB)(ipx )=bx;
246 }
247 }
248 }
249 } else {
594d8990 250 AliFatal(Form("File %s not found !",fTitle.Data()));
aee8290b 251 }
252}
253
e2afb3b6 254//_______________________________________________________________________
6c4904c2 255void AliMagFCM::Copy(TObject & /* magf */) const
aee8290b 256{
257 //
8918e700 258 // Copy *this onto magf -- Not implemented
aee8290b 259 //
594d8990 260 AliFatal("Not implemented!");
aee8290b 261}
262