er  dev
ERFieldConst.cxx
1 // -------------------------------------------------------------------------
2 // ----- ERFieldConst source file -----
3 // ----- Created 05/17 V.Schetinin -----
4 // -------------------------------------------------------------------------
5 
6 #include "ERFieldConst.h"
7 
8 #include "ERFieldPar.h"
9 #include <iomanip>
10 #include <iostream>
11 
12 using std::cout;
13 using std::cerr;
14 using std::endl;
15 using std::setw;
16 
17 // ----- Default constructor -------------------------------------------
18 
20 : FairField(),
21  fXmin(0.),
22  fXmax(0.),
23  fYmin(0.),
24  fYmax(0.),
25  fZmin(0.),
26  fZmax(0.),
27  fBx(0.),
28  fBy(0.),
29  fBz(0.)
30 {
31  fType = 0;
32 }
33 // -------------------------------------------------------------------------
34 
35 // ----- Standard constructor ------------------------------------------
36 ERFieldConst::ERFieldConst(const char* name, Double_t xMin,
37  Double_t xMax, Double_t yMin,
38  Double_t yMax, Double_t zMin,
39  Double_t zMax, Double_t bX,
40  Double_t bY, Double_t bZ)
41  : FairField(name),
42  fXmin(xMin),
43  fXmax(xMax),
44  fYmin(yMin),
45  fYmax(yMax),
46  fZmin(zMin),
47  fZmax(zMax),
48  fBx(bX),
49  fBy(bY),
50  fBz(bZ)
51 {
52  fType=0;
53 }
54 // -------------------------------------------------------------------------
55 
56 // -------- Constructor from ERFieldPar -------------------------------
58  : FairField(),
59  fXmin(0.),
60  fXmax(0.),
61  fYmin(0.),
62  fYmax(0.),
63  fZmin(0.),
64  fZmax(0.),
65  fBx(0.),
66  fBy(0.),
67  fBz(0.)
68 {
69  if ( ! fieldPar ) {
70  cerr << "-W- ERFieldConst::ERFieldConst: empty parameter container!"
71  << endl;
72  fType=0;
73  }
74  else {
75  fXmin = fieldPar->GetXmin();
76  fXmax = fieldPar->GetXmax();
77  fYmin = fieldPar->GetYmin();
78  fYmax = fieldPar->GetYmax();
79  fZmin = fieldPar->GetZmin();
80  fZmax = fieldPar->GetZmax();
81  fBx = fieldPar->GetBx();
82  fBy = fieldPar->GetBy();
83  fBz = fieldPar->GetBz();
84  fType = fieldPar->GetType();
85  }
86 }
87 // -------------------------------------------------------------------------
88 
89 // ----- Destructor ----------------------------------------------------
91 // -------------------------------------------------------------------------
92 
93 // ----- Set field region ----------------------------------------------
94 void ERFieldConst::SetFieldRegion(Double_t xMin, Double_t xMax,
95  Double_t yMin, Double_t yMax,
96  Double_t zMin, Double_t zMax) {
97  fXmin = xMin;
98  fXmax = xMax;
99  fYmin = yMin;
100  fYmax = yMax;
101  fZmin = zMin;
102  fZmax = zMax;
103 }
104 // -------------------------------------------------------------------------
105 
106 // ----- Set field values ----------------------------------------------
107 void ERFieldConst::SetField(Double_t bX, Double_t bY, Double_t bZ) {
108  fBx = bX;
109  fBy = bY;
110  fBz = bZ;
111 }
112 // -------------------------------------------------------------------------
113 
114 // ----- Get x component of field --------------------------------------
115 Double_t ERFieldConst::GetBx(Double_t x, Double_t y, Double_t z) {
116  if ( x < fXmin || x > fXmax ||
117  y < fYmin || y > fYmax ||
118  z < fZmin || z > fZmax ) return 0.;
119  return fBx;
120 }
121 // -------------------------------------------------------------------------
122 
123 // ----- Get y component of field --------------------------------------
124 Double_t ERFieldConst::GetBy(Double_t x, Double_t y, Double_t z) {
125  if ( x < fXmin || x > fXmax ||
126  y < fYmin || y > fYmax ||
127  z < fZmin || z > fZmax ) return 0.;
128  return fBy;
129 }
130 // -------------------------------------------------------------------------
131 
132 // ----- Get z component of field --------------------------------------
133 Double_t ERFieldConst::GetBz(Double_t x, Double_t y, Double_t z) {
134  if ( x < fXmin || x > fXmax ||
135  y < fYmin || y > fYmax ||
136  z < fZmin || z > fZmax ) return 0.;
137  return fBz;
138 }
139 // -------------------------------------------------------------------------
140 
141 // ----- Screen output -------------------------------------------------
142 void ERFieldConst::Print(Option_t*) const {
143  cout << "======================================================" << endl;
144  cout << "---- " << fTitle << " : " << fName << endl;
145  cout << "----" << endl;
146  cout << "---- Field type : constant" << endl;
147  cout << "----" << endl;
148  cout << "---- Field regions : " << endl;
149  cout << "---- x = " << setw(4) << fXmin << " to " << setw(4)
150  << fXmax << " cm" << endl;
151  cout << "---- y = " << setw(4) << fYmin << " to " << setw(4)
152  << fYmax << " cm" << endl;
153  cout << "---- z = " << setw(4) << fZmin << " to " << setw(4)
154  << fZmax << " cm" << endl;
155  cout.precision(4);
156  cout << "---- B = ( " << fBx << ", " << fBy << ", " << fBz << " ) kG"
157  << endl;
158  cout << "======================================================" << endl;
159 }
160 
161 // -------------------------------------------------------------------------
162 
163 ClassImp(ERFieldConst)
virtual ~ERFieldConst()
Int_t GetType() const
Definition: ERFieldPar.h:36
Double_t fXmin
Definition: ERFieldConst.h:78
virtual void Print(Option_t *="") const
void SetField(Double_t bX, Double_t bY, Double_t bZ)
void SetFieldRegion(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax)
Double_t GetBx() const
Definition: ERFieldConst.h:69
Double_t fBx
Definition: ERFieldConst.h:86