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