]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMagF.cxx
Introduction of the Copyright and cvs Log
[u/mrichter/AliRoot.git] / STEER / AliMagF.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
21 #include "AliMagF.h"
22 #include "TSystem.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25
26 //ZDC part -------------------------------------------------------------------
27
28   static const Float_t G1=20.03;
29   static const Float_t FDIP=-37.34;
30   static const Float_t FDIMU=6.;
31   static const Float_t FCORN=11.72;
32 //
33 // ZBEG       Beginning of the inner triplet
34 // D1BEG      Beginning of separator dipole 1
35 // D2BEG      Beginning of separator dipole 2
36 // CORBEG     Corrector dipole beginning (because of dimuon arm)
37 //
38   static const Float_t CORBEG=1920,COREND=CORBEG+190, CORRA2=4.5*4.5;
39 //
40   static const Float_t ZBEG=2300;
41   static const Float_t Z1BEG=ZBEG+   0,Z1END=Z1BEG+630,Z1RA2=3.5*3.5;
42   static const Float_t Z2BEG=ZBEG+ 880,Z2END=Z2BEG+550,Z2RA2=3.5*3.5;
43   static const Float_t Z3BEG=ZBEG+1530,Z3END=Z3BEG+550,Z3RA2=3.5*3.5;
44   static const Float_t Z4BEG=ZBEG+2430,Z4END=Z4BEG+630,Z4RA2=3.5*3.5;
45   static const Float_t D1BEG=5843.5   ,D1END=D1BEG+945,D1RA2=4.5*4.5;
46   static const Float_t D2BEG=12113.2  ,D2END=D2BEG+945,D2RA2=4.5*.5;
47
48 //ZDC part -------------------------------------------------------------------
49
50 ClassImp(AliMagF)
51
52 //________________________________________
53 AliMagF::AliMagF(const char *name, const char *title, const Int_t integ, const Int_t map, 
54                  const Float_t factor, const Float_t fmax)
55   : TNamed(name,title)
56 {
57   fMap = map;
58   fType = Undef;
59   fInteg = integ;
60   fFactor = factor;
61   fMax = fmax;
62 }
63
64 //________________________________________
65 void AliMagF::Field(Float_t*, Float_t *b)
66 {
67   printf("Undefined MagF Field called, returning 0\n");
68   b[0]=b[1]=b[2]=0;
69 }
70       
71 ClassImp(AliMagFC)
72
73 //________________________________________
74 AliMagFC::AliMagFC(const char *name, const char *title, const Int_t integ, const Int_t map, 
75                  const Float_t factor, const Float_t fmax)
76   : AliMagF(name,title,integ,map,factor,fmax)
77 {
78   printf("Constant Field %s created: map= %d, factor= %f\n",fName.Data(),map,factor);
79   fType = Const;
80 }
81
82 //________________________________________
83 void AliMagFC::Field(Float_t *x, Float_t *b)
84 {
85   b[0]=b[1]=b[2]=0;
86   if(fMap==1) {
87     if(TMath::Abs(x[2])<700 && x[0]*x[0]+(x[1]+30)*(x[1]+30) < 560*560) {
88       b[2]=2;
89     } else {
90       if ( 725 <= x[2] && x[2] <= 1225 ) {
91         Float_t dz = TMath::Abs(975-x[2])*0.01;
92         b[0]=(1-0.1*dz*dz)*7;
93       }
94       else {
95 //This is the ZDC part
96         Float_t rad2=x[0]*x[0]+x[1]*x[1];
97         if(rad2<D2RA2) {
98           if(x[2]>D2BEG) {
99             
100 //    Separator Dipole D2
101             if(x[2]<D2END) b[1]=FDIP;
102           } else if(x[2]>D1BEG) {
103             
104 //    Separator Dipole D1
105             if(x[2]<D1END) b[1]=-FDIP;
106           }
107           if(rad2<CORRA2) {
108
109 //    First quadrupole of inner triplet de-focussing in x-direction
110 //    Inner triplet
111             if(x[2]>Z4BEG) {
112               if(x[2]<Z4END) {
113               
114 //    2430 <-> 3060
115                 b[0]=-G1*x[1];
116                 b[1]=-G1*x[0];
117               }
118             } else if(x[2]>Z3BEG) {
119               if(x[2]<Z3END) {
120
121 //    1530 <-> 2080
122                 b[0]=G1*x[1];
123                 b[1]=G1*x[0];
124               }
125             } else if(x[2]>Z2BEG) {
126               if(x[2]<Z2END) {
127               
128 //    890 <-> 1430
129                 b[0]=G1*x[1];
130                 b[1]=G1*x[0];
131               }
132             } else if(x[2]>Z1BEG) {
133               if(x[2]<Z1END) {
134
135 //    0 <->  630
136                 b[0]=-G1*x[1];
137                 b[1]=-G1*x[0];
138               }
139             } else if(x[2]>CORBEG) {
140               if(x[2]<COREND) {
141 //    Corrector dipole (because of dimuon arm)
142                 b[0]=FCORN;
143               }
144             }
145           }
146         }
147       }
148     }
149   } else {
150     printf("Invalid field map for constant field %d\n",fMap);
151     exit(1);
152   }
153 }
154     
155 ClassImp(AliMagFCM)
156
157 //________________________________________
158 AliMagFCM::AliMagFCM(const char *name, const char *title, const Int_t integ, const Int_t map, 
159                  const Float_t factor, const Float_t fmax)
160   : AliMagF(name,title,integ,map,factor,fmax)
161 {
162   fType = ConMesh;
163   printf("Constant Mesh Field %s created: map= %d, factor= %f, file= %s\n",fName.Data(),map,factor,fTitle.Data());
164 }
165
166 //________________________________________
167 void AliMagFCM::Field(Float_t *x, Float_t *b)
168 {
169   Double_t ratx, raty, ratz, hix, hiy, hiz, ratx1, raty1, ratz1, 
170     bhyhz, bhylz, blyhz, blylz, bhz, blz, xl[3];
171   const Double_t one=1;
172   Int_t ix, iy, iz;
173     
174   // --- find the position in the grid ---
175
176   b[0]=b[1]=b[2]=0;
177   if(-700<x[2] && x[2]<fZbeg && x[0]*x[0]+(x[1]+30)*(x[1]+30) < 560*560) {
178     b[2]=2;
179   } else  {
180     Bool_t infield=(fZbeg<=x[2] && x[2]<fZbeg+fZdel*(fZn-1)
181        &&  ( fXbeg <= TMath::Abs(x[0]) && TMath::Abs(x[0]) < fXbeg+fXdel*(fXn-1) )
182        &&  ( fYbeg <= TMath::Abs(x[1]) && TMath::Abs(x[1]) < fYbeg+fYdel*(fYn-1) ));
183       if(infield) {
184       xl[0]=TMath::Abs(x[0])-fXbeg;
185       xl[1]=TMath::Abs(x[1])-fYbeg;
186       xl[2]=x[2]-fZbeg;
187       
188     // --- start with x
189     
190       hix=xl[0]*fXdeli;
191       ratx=hix-int(hix);
192       ix=int(hix);
193       
194       hiy=xl[1]*fYdeli;
195       raty=hiy-int(hiy);
196       iy=int(hiy);
197       
198       hiz=xl[2]*fZdeli;
199       ratz=hiz-int(hiz);
200       iz=int(hiz);
201     
202       if(fMap==2) {
203       // ... simple interpolation
204         ratx1=one-ratx;
205         raty1=one-raty;
206         ratz1=one-ratz;
207         bhyhz = Bx(ix  ,iy+1,iz+1)*ratx1+Bx(ix+1,iy+1,iz+1)*ratx;
208         bhylz = Bx(ix  ,iy+1,iz  )*ratx1+Bx(ix+1,iy+1,iz  )*ratx;
209         blyhz = Bx(ix  ,iy  ,iz+1)*ratx1+Bx(ix+1,iy  ,iz+1)*ratx;
210         blylz = Bx(ix  ,iy  ,iz  )*ratx1+Bx(ix+1,iy  ,iz  )*ratx;
211         bhz   = blyhz             *raty1+bhyhz             *raty;
212         blz   = blylz             *raty1+bhylz             *raty;
213         b[0]  = blz               *ratz1+bhz               *ratz;
214         //
215         bhyhz = By(ix  ,iy+1,iz+1)*ratx1+By(ix+1,iy+1,iz+1)*ratx;
216         bhylz = By(ix  ,iy+1,iz  )*ratx1+By(ix+1,iy+1,iz  )*ratx;
217         blyhz = By(ix  ,iy  ,iz+1)*ratx1+By(ix+1,iy  ,iz+1)*ratx;
218         blylz = By(ix  ,iy  ,iz  )*ratx1+By(ix+1,iy  ,iz  )*ratx;
219         bhz   = blyhz             *raty1+bhyhz             *raty;
220         blz   = blylz             *raty1+bhylz             *raty;
221         b[1]  = blz               *ratz1+bhz               *ratz;
222         //
223         bhyhz = Bz(ix  ,iy+1,iz+1)*ratx1+Bz(ix+1,iy+1,iz+1)*ratx;
224         bhylz = Bz(ix  ,iy+1,iz  )*ratx1+Bz(ix+1,iy+1,iz  )*ratx;
225         blyhz = Bz(ix  ,iy  ,iz+1)*ratx1+Bz(ix+1,iy  ,iz+1)*ratx;
226         blylz = Bz(ix  ,iy  ,iz  )*ratx1+Bz(ix+1,iy  ,iz  )*ratx;
227         bhz   = blyhz             *raty1+bhyhz             *raty;
228         blz   = blylz             *raty1+bhylz             *raty;
229         b[2]  = blz               *ratz1+bhz               *ratz;
230       //printf("ratx,raty,ratz,b[0],b[1],b[2] %f %f %f %f %f %f\n",
231       //ratx,raty,ratz,b[0],b[1],b[2]);
232       //
233     // ... use the dipole symmetry
234         if (x[0]*x[1] < 0) b[1]=-b[1];
235         if (x[0]<0) b[2]=-b[2];
236       } else {
237         printf("Invalid field map for constant mesh %d\n",fMap);
238       }
239     } else {
240 //This is the ZDC part
241       Float_t rad2=x[0]*x[0]+x[1]*x[1];
242       if(rad2<D2RA2) {
243         if(x[2]>D2BEG) {
244           
245 //    Separator Dipole D2
246           if(x[2]<D2END) b[1]=FDIP;
247         } else if(x[2]>D1BEG) {
248
249 //    Separator Dipole D1
250           if(x[2]<D1END) b[1]=-FDIP;
251         }
252         if(rad2<CORRA2) {
253
254 //    First quadrupole of inner triplet de-focussing in x-direction
255 //    Inner triplet
256           if(x[2]>Z4BEG) {
257             if(x[2]<Z4END) {
258               
259 //    2430 <-> 3060
260               b[0]=-G1*x[1];
261               b[1]=-G1*x[0];
262             }
263           } else if(x[2]>Z3BEG) {
264             if(x[2]<Z3END) {
265
266 //    1530 <-> 2080
267               b[0]=G1*x[1];
268               b[1]=G1*x[0];
269             }
270           } else if(x[2]>Z2BEG) {
271             if(x[2]<Z2END) {
272
273 //    890 <-> 1430
274               b[0]=G1*x[1];
275               b[1]=G1*x[0];
276             }
277           } else if(x[2]>Z1BEG) {
278             if(x[2]<Z1END) {
279
280 //    0 <->  630
281               b[0]=-G1*x[1];
282               b[1]=-G1*x[0];
283             }
284           } else if(x[2]>CORBEG) {
285             if(x[2]<COREND) {
286 //    Corrector dipole (because of dimuon arm)
287               b[0]=FCORN;
288             }
289           }
290         }
291       }
292     }
293   }
294 }
295
296 //________________________________________
297 void AliMagFCM::ReadField()
298 {
299   FILE *magfile;
300   Int_t ix, iy, iz, ipx, ipy, ipz;
301   Float_t bx, by, bz;
302   char *fname;
303   printf("Reading Magnetic Field %s from file %s\n",fName.Data(),fTitle.Data());
304   fname = gSystem->ExpandPathName(fTitle.Data());
305   magfile=fopen(fname,"r");
306   delete [] fname;
307   if (magfile) {
308     fscanf(magfile,"%d %d %d %f %f %f %f %f %f",
309            &fXn, &fYn, &fZn, &fXdel, &fYdel, &fZdel, &fXbeg, &fYbeg, &fZbeg);
310     printf("fXn %d, fYn %d, fZn %d, fXdel %f, fYdel %f, fZdel %f, fXbeg %f, fYbeg %f, fZbeg %f\n",
311            fXn, fYn, fZn, fXdel, fYdel, fZdel, fXbeg, fYbeg, fZbeg);
312     fXdeli=1./fXdel;
313     fYdeli=1./fYdel;
314     fZdeli=1./fZdel;
315     fB = new TVector(3*fXn*fYn*fZn);
316     for (iz=0; iz<fZn; iz++) {
317       ipz=iz*3*(fXn*fYn);
318       for (iy=0; iy<fYn; iy++) {
319         ipy=ipz+iy*3*fXn;
320         for (ix=0; ix<fXn; ix++) {
321           ipx=ipy+ix*3;
322           fscanf(magfile,"%f %f %f",&bz,&by,&bx);
323           (*fB)(ipx+2)=bz;
324           (*fB)(ipx+1)=by;
325           (*fB)(ipx  )=bx;
326         }
327       }
328     }
329   } else { 
330     printf("File %s not found !\n",fTitle.Data());
331     exit(1);
332   }
333 }
334
335   
336