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