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