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