]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliMagFCM.cxx
More comments for documentation.
[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
16/*
17$Log$
cf6abd21 18Revision 1.8 2001/05/28 14:10:35 morsch
19SetSolenoidField method to set the L3 field strength. 2 kG is default.
20
4cc8933f 21Revision 1.7 2001/05/16 14:57:22 alibrary
22New files for folders and Stack
23
9e1a0ddb 24Revision 1.6 2000/12/18 10:44:01 morsch
25Possibility to set field map by passing pointer to objet of type AliMagF via
26SetField().
27Example:
28gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
29
d8408e76 30Revision 1.5 2000/12/01 11:20:27 alibrary
31Corrector dipole removed from ZDC
32
006cb30c 33Revision 1.4 2000/11/30 07:12:49 alibrary
34Introducing new Rndm and QA classes
35
65fb704d 36Revision 1.3 2000/11/10 18:09:55 fca
37New field map for the ZDC
38
d95ea23f 39Revision 1.2 2000/07/12 08:56:25 fca
40Coding convention correction and warning removal
41
8918e700 42Revision 1.1 2000/07/11 18:24:59 fca
43Coding convention corrections + few minor bug fixes
44
aee8290b 45*/
65fb704d 46#include "TVector.h"
aee8290b 47
48#include "AliMagFCM.h"
49#include "TSystem.h"
50
51ClassImp(AliMagFCM)
52
53//________________________________________
54AliMagFCM::AliMagFCM(const char *name, const char *title, const Int_t integ,
d8408e76 55 const Float_t factor, const Float_t fmax)
56 : AliMagF(name,title,integ,factor,fmax)
aee8290b 57{
58 //
59 // Standard constructor
60 //
cf6abd21 61 fB=0;
aee8290b 62 fType = kConMesh;
d8408e76 63 fMap = 2;
4cc8933f 64 SetSolenoidField();
65
9e1a0ddb 66 if(fDebug>-1) printf("%s: Constant Mesh Field %s created: map= %d, factor= %f, file= %s\n",
67 ClassName(),fName.Data(), fMap, factor,fTitle.Data());
4cc8933f 68
aee8290b 69}
70
71//________________________________________
72AliMagFCM::AliMagFCM(const AliMagFCM &magf)
73{
74 //
75 // Copy constructor
76 //
77 magf.Copy(*this);
78}
79
80//________________________________________
81void AliMagFCM::Field(Float_t *x, Float_t *b)
82{
83 //
84 // Method to calculate the magnetic field
85 //
86 Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1,
87 bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
88 const Double_t kone=1;
89 Int_t ix, iy, iz;
90
91 // --- find the position in the grid ---
92
93 b[0]=b[1]=b[2]=0;
94 if(-700<x[2] && x[2]<fZbeg && x[0]*x[0]+(x[1]+30)*(x[1]+30) < 560*560) {
4cc8933f 95 b[2]= fSolenoid;
aee8290b 96 } else {
97 Bool_t infield=(fZbeg<=x[2] && x[2]<fZbeg+fZdel*(fZn-1)
98 && ( fXbeg <= TMath::Abs(x[0]) && TMath::Abs(x[0]) < fXbeg+fXdel*(fXn-1) )
99 && ( fYbeg <= TMath::Abs(x[1]) && TMath::Abs(x[1]) < fYbeg+fYdel*(fYn-1) ));
100 if(infield) {
101 xl[0]=TMath::Abs(x[0])-fXbeg;
102 xl[1]=TMath::Abs(x[1])-fYbeg;
103 xl[2]=x[2]-fZbeg;
104
105 // --- start with x
106
107 hix=xl[0]*fXdeli;
108 ratx=hix-int(hix);
109 ix=int(hix);
110
111 hiy=xl[1]*fYdeli;
112 raty=hiy-int(hiy);
113 iy=int(hiy);
114
115 hiz=xl[2]*fZdeli;
116 ratz=hiz-int(hiz);
117 iz=int(hiz);
118
119 if(fMap==2) {
120 // ... simple interpolation
121 ratx1=kone-ratx;
122 raty1=kone-raty;
123 ratz1=kone-ratz;
124 bhyhz = Bx(ix ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
125 bhylz = Bx(ix ,iy+1,iz )*ratx1+Bx(ix+1,iy+1,iz )*ratx;
126 blyhz = Bx(ix ,iy ,iz+1)*ratx1+Bx(ix+1,iy ,iz+1)*ratx;
127 blylz = Bx(ix ,iy ,iz )*ratx1+Bx(ix+1,iy ,iz )*ratx;
128 bhz = blyhz *raty1+bhyhz *raty;
129 blz = blylz *raty1+bhylz *raty;
130 b[0] = blz *ratz1+bhz *ratz;
131 //
132 bhyhz = By(ix ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
133 bhylz = By(ix ,iy+1,iz )*ratx1+By(ix+1,iy+1,iz )*ratx;
134 blyhz = By(ix ,iy ,iz+1)*ratx1+By(ix+1,iy ,iz+1)*ratx;
135 blylz = By(ix ,iy ,iz )*ratx1+By(ix+1,iy ,iz )*ratx;
136 bhz = blyhz *raty1+bhyhz *raty;
137 blz = blylz *raty1+bhylz *raty;
138 b[1] = blz *ratz1+bhz *ratz;
139 //
140 bhyhz = Bz(ix ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
141 bhylz = Bz(ix ,iy+1,iz )*ratx1+Bz(ix+1,iy+1,iz )*ratx;
142 blyhz = Bz(ix ,iy ,iz+1)*ratx1+Bz(ix+1,iy ,iz+1)*ratx;
143 blylz = Bz(ix ,iy ,iz )*ratx1+Bz(ix+1,iy ,iz )*ratx;
144 bhz = blyhz *raty1+bhyhz *raty;
145 blz = blylz *raty1+bhylz *raty;
146 b[2] = blz *ratz1+bhz *ratz;
147 //printf("ratx,raty,ratz,b[0],b[1],b[2] %f %f %f %f %f %f\n",
148 //ratx,raty,ratz,b[0],b[1],b[2]);
149 //
150 // ... use the dipole symmetry
151 if (x[0]*x[1] < 0) b[1]=-b[1];
152 if (x[0]<0) b[2]=-b[2];
153 } else {
154 printf("Invalid field map for constant mesh %d\n",fMap);
155 }
156 } else {
d95ea23f 157//This is the ZDC part
158 Float_t rad2=x[0]*x[0]+x[1]*x[1];
006cb30c 159 if(x[2]>kCORBEG2 && x[2]<kCOREND2){
d95ea23f 160 if(rad2<kCOR2RA2){
161 b[0] = kFCORN2;
162 }
163 }
164 else if(x[2]>kZ1BEG && x[2]<kZ1END){
165 if(rad2<kZ1RA2){
166 b[0] = -kG1*x[1];
167 b[1] = -kG1*x[0];
168 }
169 }
170 else if(x[2]>kZ2BEG && x[2]<kZ2END){
171 if(rad2<kZ2RA2){
172 b[0] = kG1*x[1];
173 b[1] = kG1*x[0];
174 }
175 }
176 else if(x[2]>kZ3BEG && x[2]<kZ3END){
177 if(rad2<kZ3RA2){
178 b[0] = kG1*x[1];
179 b[1] = kG1*x[0];
180 }
181 }
182 else if(x[2]>kZ4BEG && x[2]<kZ4END){
183 if(rad2<kZ4RA2){
184 b[0] = -kG1*x[1];
185 b[1] = -kG1*x[0];
186 }
187 }
188 else if(x[2]>kD1BEG && x[2]<kD1END){
189 if(rad2<kD1RA2){
190 b[1] = -kFDIP;
191 }
192 }
193 else if(x[2]>kD2BEG && x[2]<kD2END){
194 if(((x[0]-kXCEN1D2)*(x[0]-kXCEN1D2)+(x[1]-kYCEN1D2)*(x[1]-kYCEN1D2))<kD2RA2
195 || ((x[0]-kXCEN2D2)*(x[0]-kXCEN2D2)+(x[1]-kYCEN2D2)*(x[1]-kYCEN2D2))<kD2RA2){
196 b[1] = kFDIP;
aee8290b 197 }
198 }
d95ea23f 199
200 }
aee8290b 201 }
202 if(fFactor!=1) {
203 b[0]*=fFactor;
204 b[1]*=fFactor;
205 b[2]*=fFactor;
206 }
207}
208
209//________________________________________
210void AliMagFCM::ReadField()
211{
212 //
213 // Method to read the magnetic field map from file
214 //
215 FILE *magfile;
216 Int_t ix, iy, iz, ipx, ipy, ipz;
217 Float_t bx, by, bz;
218 char *fname;
9e1a0ddb 219 if(fDebug) printf("%s: Reading Magnetic Field %s from file %s\n",ClassName(),fName.Data(),fTitle.Data());
aee8290b 220 fname = gSystem->ExpandPathName(fTitle.Data());
221 magfile=fopen(fname,"r");
222 delete [] fname;
223 if (magfile) {
224 fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
225 &fXn, &fYn, &fZn, &fXdel, &fYdel, &fZdel, &fXbeg, &fYbeg, &fZbeg);
9e1a0ddb 226 if(fDebug>1) printf("%s: fXn %d, fYn %d, fZn %d, fXdel %f, fYdel %f, fZdel %f, fXbeg %f, fYbeg %f, fZbeg %f\n",
227 ClassName(),fXn, fYn, fZn, fXdel, fYdel, fZdel, fXbeg, fYbeg, fZbeg);
aee8290b 228 fXdeli=1./fXdel;
229 fYdeli=1./fYdel;
230 fZdeli=1./fZdel;
231 fB = new TVector(3*fXn*fYn*fZn);
232 for (iz=0; iz<fZn; iz++) {
233 ipz=iz*3*(fXn*fYn);
234 for (iy=0; iy<fYn; iy++) {
235 ipy=ipz+iy*3*fXn;
236 for (ix=0; ix<fXn; ix++) {
237 ipx=ipy+ix*3;
238 fscanf(magfile,"%f %f %f",&bz,&by,&bx);
239 (*fB)(ipx+2)=bz;
240 (*fB)(ipx+1)=by;
241 (*fB)(ipx )=bx;
242 }
243 }
244 }
245 } else {
9e1a0ddb 246 printf("%s: File %s not found !\n",ClassName(),fTitle.Data());
aee8290b 247 exit(1);
248 }
249}
250
251//________________________________________
8918e700 252void AliMagFCM::Copy(AliMagFCM & /* magf */) const
aee8290b 253{
254 //
8918e700 255 // Copy *this onto magf -- Not implemented
aee8290b 256 //
257 Fatal("Copy","Not implemented!\n");
258}
259
260//________________________________________
261AliMagFCM & AliMagFCM::operator =(const AliMagFCM &magf)
262{
263 magf.Copy(*this);
264 return *this;
265}