Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMagneticFieldMapConst.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DMagneticFieldMapConst.cc
4 // Created: Fri Nov 7 04:01:28 EST 2008
5 // Creator: davidl (on Darwin Amelia.local 8.11.1 i386)
6 //
7 
8 #include <cmath>
9 using namespace std;
10 
11 #include "DMagneticFieldMapConst.h"
12 
13 
14 
15 //---------------------------------
16 // DMagneticFieldMapConst (Constructor)
17 //---------------------------------
19 {
20  int32_t runnumber = 1;
21  jcalib = japp->GetJCalibration(runnumber);
22  if(GetValues(namepath, runnumber)==0){
23  _DBG_<<"Error getting JCalibration object for magnetic field!"<<endl;
24  japp->Quit();
25  }
26 }
27 
28 //---------------------------------
29 // DMagneticFieldMapConst (Constructor)
30 //---------------------------------
31 DMagneticFieldMapConst::DMagneticFieldMapConst(JCalibration *jcalib, string namepath)
32 {
33  this->jcalib = jcalib;
34  if(GetValues(namepath)==0){
35  _DBG_<<"Error getting JCalibration object for magnetic field!"<<endl;
36  exit(-1);
37  }
38 }
39 
40 //---------------------------------
41 // DMagneticFieldMapConst (Constructor)
42 //---------------------------------
43 DMagneticFieldMapConst::DMagneticFieldMapConst(double Br, double Bphi, double Bz)
44 {
45  this->jcalib = NULL;
46 
47  this->Br = Br;
48  this->Bphi = Bphi;
49  this->Bz = Bz;
50 }
51 
52 //---------------------------------
53 // ~DMagneticFieldMapConst (Destructor)
54 //---------------------------------
56 {
57 
58 }
59 
60 //---------------------------------
61 // GetValues
62 //---------------------------------
63 int DMagneticFieldMapConst::GetValues(string namepath, int32_t runnumber, string context)
64 {
65  /// Read the parameters for the constant magnetic field map from the calibration database.
66 
67  if(!jcalib)return 0;
68 
69  cout<<"Reading Constant Magnetic field values from "<<namepath<<" ..."<<endl;
70  map<string,double> vals;
71  jcalib->Get(namepath, vals);
72  if(vals.size()==0)return 0;
73 
74  Br = vals["Br"];
75  Bphi = vals["Bphi"];
76  Bz = vals["Bz"];
77  cout<<" Br="<<Br<<" Bphi="<<Bphi<<" Bz="<<Bz<<endl;
78 
79  return vals.size();
80 }
81 
82 
83 //-------------
84 // GetFieldGradient
85 //-------------
86 void DMagneticFieldMapConst::GetFieldGradient(double x, double y, double z,
87  double &dBxdx, double &dBxdy,
88  double &dBxdz,
89  double &dBydx, double &dBydy,
90  double &dBydz,
91  double &dBzdx, double &dBzdy,
92  double &dBzdz) const{
93 
94 
95  // Constant field has zero gradient
96  dBxdx = 0.0;
97  dBxdy = 0.0;
98  dBxdz = 0.0;
99  dBydx = 0.0;
100  dBydy = 0.0;
101  dBydz = 0.0;
102  dBzdx = 0.0;
103  dBzdy = 0.0;
104  dBzdz = 0.0;
105 }
106 
107 
108 
109 //---------------------------------
110 // GetField
111 //---------------------------------
112 void DMagneticFieldMapConst::GetField(double x, double y, double z, double &Bx, double &By, double &Bz, int method) const
113 {
114  /// This calculates the magnetic field at an arbitrary point
115  /// in space using the constat field map parameters read from the calibaration
116  /// database.
117 
118  if(Br!=0.0){
119  double r = sqrt(x*x + y*y);
120  double cos_phi = x/r;
121  double sin_phi = y/r;
122  if(r==0.0){
123  cos_phi=1.0;
124  sin_phi=0.0;
125  }
126  Bx = Br*cos_phi;
127  By = Br*sin_phi;
128  }else{
129  Bx=By=0.0;
130  }
131  Bz = this->Bz;
132 }
133 
134 //---------------------------------
135 // GetField
136 //---------------------------------
138  DVector3 &Bout) const
139 {
140  /// This calculates the magnetic field at an arbitrary point
141  /// in space using the constat field map parameters read from the calibaration
142  /// database.
143 
144  if(Br!=0.0){
145  double r = pos.Perp();
146  double x= pos.x();
147  double y= pos.y();
148  double cos_phi = x/r;
149  double sin_phi = y/r;
150  if(r==0.0){
151  cos_phi=1.0;
152  sin_phi=0.0;
153  }
154  Bout.SetXYZ(Br*cos_phi,Br*sin_phi,this->Bz);
155  }else{
156  Bout.SetXYZ(0.0,0.0,this->Bz);
157  }
158 }
159 
160 
161 void DMagneticFieldMapConst::GetFieldBicubic(double x,double y,double z,
162  double &Bx,double &By,double &Bz)
163  const{
164  GetField(x,y,z,Bx,By,Bz);
165 }
166 
167 
168 void DMagneticFieldMapConst::GetFieldAndGradient(double x,double y,double z,
169  double &Bx,double &By,
170  double &Bz,
171  double &dBxdx, double &dBxdy,
172  double &dBxdz,
173  double &dBydx, double &dBydy,
174  double &dBydz,
175  double &dBzdx, double &dBzdy,
176  double &dBzdz) const{
177  GetField(x,y,z,Bx,By,Bz);
178  // Constant field has zero gradient
179  dBxdx = 0.0;
180  dBxdy = 0.0;
181  dBxdz = 0.0;
182  dBydx = 0.0;
183  dBydy = 0.0;
184  dBydz = 0.0;
185  dBzdx = 0.0;
186  dBzdy = 0.0;
187  dBzdz = 0.0;
188 }
int GetValues(string namepath, int32_t runnumber=1, string context="")
TVector3 DVector3
Definition: DVector3.h:14
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define y
JApplication * japp
void GetFieldBicubic(double x, double y, double z, double &Bx, double &By, double &Bz) const
void GetFieldGradient(double x, double y, double z, double &dBxdx, double &dBxdy, double &dBxdz, double &dBydx, double &dBydy, double &dBydz, double &dBzdx, double &dBzdy, double &dBzdz) const
#define _DBG_
Definition: HDEVIO.h:12
double sqrt(double)
void GetFieldAndGradient(double x, double y, double z, double &Bx, double &By, double &Bz, double &dBxdx, double &dBxdy, double &dBxdz, double &dBydx, double &dBydy, double &dBydz, double &dBzdx, double &dBzdy, double &dBzdz) const
DMagneticFieldMapConst(JApplication *japp, string namepath="Magnets/Solenoid/solenoid_const")
void GetField(const DVector3 &pos, DVector3 &Bout) const