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