EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndSolenoidMap.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndSolenoidMap.cxx
1 #include <iostream>
2 #include "TArrayF.h"
3 #include "stdlib.h"
4 #include "PndSolenoidMap.h"
5 #include "PndMapPar.h"
6 
8 
9 using namespace std;
10 // ------------- Default constructor ----------------------------------
12  :PndFieldMap(),
13  fRegionNo(0),
14  fHemiX(0),
15  fHemiY(0)
16 {
17  fType = 2;
18 }
19 // ------------------------------------------------------------------------
20 
21 
22 
23 // ------------- Standard constructor ---------------------------------
24 PndSolenoidMap::PndSolenoidMap(const char* mapName,
25  const char* fileType)
26  : PndFieldMap(mapName, fileType),
27  fRegionNo(0),
28  fHemiX(0),
29  fHemiY(0)
30 {
31  fType = 2;
34 }
35 // ------------------------------------------------------------------------
36 
37 // ------------ Constructor from PndFieldPar --------------------------
39  : PndFieldMap(),
40  fRegionNo(fNumberOfRegions++),
41  fHemiX(0),
42  fHemiY(0)
43 {
44  fType = 2;
45  if ( ! fieldPar ) {
46  cerr << "-W- PndSolenoidMap::PndSolenoidMap: empty parameter container!"
47  << endl;
48  fName = "";
49  fFileName = "";
50  fType = -1;
51  }
52  else {
53  fieldPar->MapName(fName);
54  fPosX = fieldPar->GetPositionX();
55  fPosY = fieldPar->GetPositionY();
56  fPosZ = fieldPar->GetPositionZ();
57  fScale = fieldPar->GetScale();
58  TString dir = getenv("VMCWORKDIR");
59  fFileName = dir + "/input/" + fName + ".root";
60  fType = fieldPar->GetType();
61  }
62 }
63 // ------------------------------------------------------------------------
64 
65 
66 
67 // ------------ Destructor --------------------------------------------
69 {
70 }
71 // ------------------------------------------------------------------------
72 void PndSolenoidMap::GetBxyz(const Double_t point[3], Double_t* bField)
73 {
74  Double_t x =point[0];
75  Double_t y =point[1];
76  Double_t z =point[2];
77  Int_t ix = 0;
78  Int_t iy = 0;
79  Int_t iz = 0;
80  Double_t dx = 0.;
81  Double_t dy = 0.;
82  Double_t dz = 0.;
83 
84  if ( IsInside(x, y, z, ix, iy, iz, dx, dy, dz) ){
85 
86  // Get Bx field values at grid cell corners
87  fHa[0][0][0] = fBx->At(ix *fNy*fNz + iy *fNz + iz);
88  fHa[1][0][0] = fBx->At((ix+1)*fNy*fNz + iy *fNz + iz);
89  fHa[0][1][0] = fBx->At(ix *fNy*fNz + (iy+1)*fNz + iz);
90  fHa[1][1][0] = fBx->At((ix+1)*fNy*fNz + (iy+1)*fNz + iz);
91  fHa[0][0][1] = fBx->At(ix *fNy*fNz + iy *fNz + (iz+1));
92  fHa[1][0][1] = fBx->At((ix+1)*fNy*fNz + iy *fNz + (iz+1));
93  fHa[0][1][1] = fBx->At(ix *fNy*fNz + (iy+1)*fNz + (iz+1));
94  fHa[1][1][1] = fBx->At((ix+1)*fNy*fNz + (iy+1)*fNz + (iz+1));
95 
96  //Bx is antisymtric in X and symetric in Y
97  bField[0] =Interpolate(dx, dy, dz) * fHemiX;
98  // Get By field values at grid cell corners
99  fHa[0][0][0] = fBy->At(ix *fNy*fNz + iy *fNz + iz);
100  fHa[1][0][0] = fBy->At((ix+1)*fNy*fNz + iy *fNz + iz);
101  fHa[0][1][0] = fBy->At(ix *fNy*fNz + (iy+1)*fNz + iz);
102  fHa[1][1][0] = fBy->At((ix+1)*fNy*fNz + (iy+1)*fNz + iz);
103  fHa[0][0][1] = fBy->At(ix *fNy*fNz + iy *fNz + (iz+1));
104  fHa[1][0][1] = fBy->At((ix+1)*fNy*fNz + iy *fNz + (iz+1));
105  fHa[0][1][1] = fBy->At(ix *fNy*fNz + (iy+1)*fNz + (iz+1));
106  fHa[1][1][1] = fBy->At((ix+1)*fNy*fNz + (iy+1)*fNz + (iz+1));
107 
108  //By is symtric in X and antisymetric in Y
109  bField[1] = Interpolate(dx, dy, dz) * fHemiY;
110 
111 
112  // Get Bz field values at grid cell corners
113  fHa[0][0][0] = fBz->At(ix *fNy*fNz + iy *fNz + iz);
114  fHa[1][0][0] = fBz->At((ix+1)*fNy*fNz + iy *fNz + iz);
115  fHa[0][1][0] = fBz->At(ix *fNy*fNz + (iy+1)*fNz + iz);
116  fHa[1][1][0] = fBz->At((ix+1)*fNy*fNz + (iy+1)*fNz + iz);
117  fHa[0][0][1] = fBz->At(ix *fNy*fNz + iy *fNz + (iz+1));
118  fHa[1][0][1] = fBz->At((ix+1)*fNy*fNz + iy *fNz + (iz+1));
119  fHa[0][1][1] = fBz->At(ix *fNy*fNz + (iy+1)*fNz + (iz+1));
120  fHa[1][1][1] = fBz->At((ix+1)*fNy*fNz + (iy+1)*fNz + (iz+1));
121 
122 
123  //Bz is symtric in X and Y
124  bField[2] =Interpolate(dx, dy, dz) ;
125 
126  }else{
127  bField[0]=0;
128  bField[1]=0;
129  bField[2]=0;
130  }
131 
132 }
133 
134 // ----------- Check whether a point is inside the map ----------------
135 Bool_t PndSolenoidMap::IsInside(Double_t x, Double_t y, Double_t z,
136  Int_t& ix, Int_t& iy, Int_t& iz,
137  Double_t& dx, Double_t& dy,
138  Double_t& dz) {
139 
140  // --- Transform into local coordinate system
141  Double_t xl = x - fPosX;
142  Double_t yl = y - fPosY;
143  Double_t zl = z - fPosZ;
144 
145  // --- Reflect w.r.t. symmetry axes
146  fHemiX = fHemiY = 1.;
147  if ( xl < 0. ) {
148  fHemiX = -1.;
149  xl = -1. * xl;
150  }
151  if ( yl < 0. ) {
152  fHemiY = -1.;
153  yl = -1. * yl;
154  }
155 
156  // --- Check for being outside the map range
157  if ( ! ( xl >= 0 && xl <= fXmax && yl >= 0 && yl <= fYmax &&
158  zl >= fZmin && zl <= fZmax ) ) {
159  ix = iy = iz = 0;
160  dx = dy = dz = 0.;
161  return kFALSE;
162  }
163 
164  // --- Determine grid cell
165  ix = Int_t( (xl-fXmin) / fXstep );
166  iy = Int_t( (yl-fYmin) / fYstep );
167  iz = Int_t( (zl-fZmin) / fZstep );
168 
169 
170  // Relative distance from grid point (in units of cell size)
171  dx = (xl-fXmin) / fXstep - Double_t(ix);
172  dy = (yl-fYmin) / fYstep - Double_t(iy);
173  dz = (zl-fZmin) / fZstep - Double_t(iz);
174 
175  return kTRUE;
176 
177 }
178 // ------------------------------------------------------------------------
180 {
181  TString MapName=GetName();
182  cout << "PndSolenoidMap::FillParContainer() " << endl;
183 
184 }