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