22 const double meter(1000.0);
23 const double gauss(1.0e-7);
24 const string myname(
"BFieldSolenoid::readMap()");
32 cerr << myname <<
": version number is " << version <<
" instead of 4" << endl;
43 m_orig->reserve( nz, nr, nphi+1 );
46 for (
int i = 0; i < nr; i++ ) { input >>
x;
m_orig->appendMesh(1,
x*meter); }
47 for (
int i = 0; i < nz; i++ ) { input >>
x;
m_orig->appendMesh(0,
x*meter); }
48 for (
int i = 0; i < nphi; i++ ) { input >>
x;
m_orig->appendMesh(2,
x); }
50 double zmin =
m_orig->mesh(0,0);
51 double zmax =
m_orig->mesh(0,nz-1);
52 double rmin =
m_orig->mesh(1,0);
53 double rmax =
m_orig->mesh(1,nr-1);
54 double phimin =
m_orig->mesh(2,0);
55 double phimax =
m_orig->mesh(2,nphi);
56 m_orig->setRange( zmin, zmax, rmin, rmax, phimin, phimax );
68 for (
int k = 0; k < nphi; k++ ) {
69 for (
int j = 0; j < nr; j++ ) {
70 for (
int i = 0; i < nz; i++ ) { input >> b; Bz.push_back(b*gauss); }
72 for (
int j = 0; j < nr; j++ ) {
73 for (
int i = 0; i < nz; i++ ) { input >> b;
Br.push_back(b*gauss); }
75 for (
int j = 0; j < nr; j++ ) {
76 for (
int i = 0; i < nz; i++ ) { input >> b; Bphi.push_back(b*gauss); }
79 for (
int i = 0; i < nz; i++ ) {
80 for (
int j = 0; j < nr; j++ ) {
81 for (
int k = 0; k < nphi; k++ ) {
82 int index = i + nz*(j + nr*k);
84 m_orig->appendField( field );
89 m_orig->appendField( field );
107 if ( map ==
nullptr )
return;
111 TTree*
tree =
new TTree(
"BFieldSolenoid",
"BFieldSolenoid version 4" );
112 double zmin = map->zmin();
113 double zmax = map->zmax();
114 double rmin = map->rmin();
115 double rmax = map->rmax();
116 double phimin = map->phimin();
117 double phimax = map->phimax();
118 int nmeshz = map->nmesh(0);
119 int nmeshr = map->nmesh(1);
120 int nmeshphi = map->nmesh(2);
126 int nfield = nmeshz*nmeshr*nmeshphi;
132 meshz =
new double[nmeshz];
133 meshr =
new double[nmeshr];
134 meshphi =
new double[nmeshphi];
135 fieldz =
new double[nfield];
136 fieldr =
new double[nfield];
137 fieldphi =
new double[nfield];
139 tree->Branch(
"zmin", &zmin,
"zmin/D" );
140 tree->Branch(
"zmax", &zmax,
"zmax/D" );
141 tree->Branch(
"rmin", &rmin,
"rmin/D" );
142 tree->Branch(
"rmax", &rmax,
"rmax/D" );
143 tree->Branch(
"phimin", &phimin,
"phimin/D" );
144 tree->Branch(
"phimax", &phimax,
"phimax/D" );
145 tree->Branch(
"nmeshz", &nmeshz,
"nmeshz/I" );
146 tree->Branch(
"meshz", meshz,
"meshz[nmeshz]/D" );
147 tree->Branch(
"nmeshr", &nmeshr,
"nmeshr/I" );
148 tree->Branch(
"meshr", meshr,
"meshr[nmeshr]/D" );
149 tree->Branch(
"nmeshphi", &nmeshphi,
"nmeshphi/I" );
150 tree->Branch(
"meshphi", meshphi,
"meshphi[nmeshphi]/D" );
151 tree->Branch(
"nfield", &nfield,
"nfield/I" );
152 tree->Branch(
"fieldz", fieldz,
"fieldz[nfield]/D" );
153 tree->Branch(
"fieldr", fieldr,
"fieldr[nfield]/D" );
154 tree->Branch(
"fieldphi", fieldphi,
"fieldphi[nfield]/D" );
156 for (
int j = 0; j < nmeshz; j++ ) {
157 meshz[j] = map->mesh(0,j);
159 for (
int j = 0; j < nmeshr; j++ ) {
160 meshr[j] = map->mesh(1,j);
162 for (
int j = 0; j < nmeshphi; j++ ) {
163 meshphi[j] = map->mesh(2,j);
165 for (
int j = 0; j < nfield; j++ ) {
169 fieldphi[j] = f.phi();
190 if (
rootfile ==
nullptr )
return 1;
197 if (
tree ==
nullptr )
return 3;
227 tree->SetBranchAddress(
"zmin", &zmin );
228 tree->SetBranchAddress(
"zmax", &zmax );
229 tree->SetBranchAddress(
"rmin", &rmin );
230 tree->SetBranchAddress(
"rmax", &rmax );
231 tree->SetBranchAddress(
"phimin", &phimin );
232 tree->SetBranchAddress(
"phimax", &phimax );
233 tree->SetBranchAddress(
"nmeshz", &nmeshz );
234 tree->SetBranchAddress(
"nmeshr", &nmeshr );
235 tree->SetBranchAddress(
"nmeshphi", &nmeshphi );
236 tree->SetBranchAddress(
"nfield", &nfield );
239 meshz =
new double[nmeshz];
240 meshr =
new double[nmeshr];
241 meshphi =
new double[nmeshphi];
242 fieldz =
new double[nfield];
243 fieldr =
new double[nfield];
244 fieldphi =
new double[nfield];
246 tree->SetBranchAddress(
"meshz", meshz );
247 tree->SetBranchAddress(
"meshr", meshr );
248 tree->SetBranchAddress(
"meshphi", meshphi );
249 tree->SetBranchAddress(
"fieldz", fieldz );
250 tree->SetBranchAddress(
"fieldr", fieldr );
251 tree->SetBranchAddress(
"fieldphi", fieldphi );
254 m_orig->setRange( zmin, zmax, rmin, rmax, phimin, phimax );
255 m_orig->reserve( nmeshz, nmeshr, nmeshphi );
256 for (
int j = 0; j < nmeshz; j++ ) {
257 m_orig->appendMesh( 0, meshz[j] );
259 for (
int j = 0; j < nmeshr; j++ ) {
260 m_orig->appendMesh( 1, meshr[j] );
262 for (
int j = 0; j < nmeshphi; j++ ) {
263 m_orig->appendMesh( 2, meshphi[j] );
265 for (
int j = 0; j < nfield; j++ ) {
267 m_orig->appendField( field );
308 cerr <<
"BFieldSolenoid::moveMap() : original map has not been read" << endl;
315 const double zlim = 2820.;
316 const double rlim = 1075.;
319 m_tilt->appendMesh( 0, -zlim );
320 for (
unsigned i = 0; i <
m_orig->nmesh(0); i++ ) {
323 m_tilt->appendMesh( 0, zlim );
325 for (
unsigned i = 0; i <
m_orig->nmesh(1); i++ ) {
328 m_tilt->appendMesh( 1, rlim );
330 for (
unsigned i = 0; i <
m_orig->nmesh(2); i++ ) {
337 double sinax( sin(ax) );
338 double cosax( cos(ax) );
339 double sinay( sin(ay) );
340 double cosay( cos(ay) );
341 for (
unsigned i = 0; i <
m_tilt->nmesh(0); i++ ) {
342 double z0(
m_tilt->mesh(0,i) );
343 for (
unsigned j = 0; j <
m_tilt->nmesh(1); j++ ) {
344 double r0(
m_tilt->mesh(1,j) );
345 for (
unsigned k = 0; k <
m_tilt->nmesh(2); k++ ) {
346 double phi0(
m_tilt->mesh(2,k) );
347 double x0( r0*cos(phi0) );
348 double y0( r0*sin(phi0) );
350 double x1( x0 - dx );
351 double y1( y0 - dy );
352 double z1( z0 - dz );
355 double y2( y1*cosax + z1*sinax );
356 double z2( z1*cosax - y1*sinax );
358 double xyz3[3] = { x2*cosay-z2*sinay, y2, z2*cosay + x2*sinay };
363 double Bx1( B[0]*cosay + B[2]*sinay );
365 double Bz1( B[2]*cosay - B[0]*sinay );
368 double By2( By1*cosax - Bz1*sinax );
369 double Bz2( Bz1*cosax + By1*sinax );
371 double cosphi0( cos(phi0) );
372 double sinphi0( sin(phi0) );
373 double Br( Bx2*cosphi0 + By2*sinphi0 );
374 double Bphi( -Bx2*sinphi0 + By2*cosphi0 );
376 m_tilt->appendField( field );