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