EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndConstField.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndConstField.cxx
1 // -------------------------------------------------------------------------
2 // ----- PndConstField source file -----
3 // ----- Created 30/01/07 by M. Al/Turany -----
4 // -------------------------------------------------------------------------
5 
6 #include "PndConstField.h"
7 #include "PndConstPar.h"
8 
9 
10 #include "FairRun.h"
11 #include "FairRuntimeDb.h"
12 
13 
14 
15 #include <iomanip>
16 #include <iostream>
17 
18 
19 using namespace std;
20 
21 // ----- Default constructor -------------------------------------------
23 : fXmin(0),
24  fXmax(0),
25  fYmin(0),
26  fYmax(0),
27  fZmin(0),
28  fZmax(0),
29  fBx(0),
30  fBy(0),
31  fBz(0)
32 {
33  fType = 0;
34 }
35 // -------------------------------------------------------------------------
36 
37 
38 
39 // ----- Standard constructor ------------------------------------------
40 PndConstField::PndConstField(const char* name, Double_t xMin,
41  Double_t xMax, Double_t yMin,
42  Double_t yMax, Double_t zMin,
43  Double_t zMax, Double_t bX,
44  Double_t bY, Double_t bZ)
45  : FairField(name),
46  fXmin(xMin),
47  fXmax(xMax),
48  fYmin(yMin),
49  fYmax(yMax),
50  fZmin(zMin),
51  fZmax(zMax),
52  fBx(bX),
53  fBy(bY),
54  fBz(bZ)
55 
56 {
57  fType = 0;
58 }
59 // -------------------------------------------------------------------------
60 
61 
62 
63 // -------- Constructor from PndFieldPar -------------------------------
65  : FairField(),
66  fXmin(0),
67  fXmax(0),
68  fYmin(0),
69  fYmax(0),
70  fZmin(0),
71  fZmax(0),
72  fBx(0),
73  fBy(0),
74  fBz(0)
75  {
76  if ( ! fieldPar ) {
77  cerr << "-W- PndConstField::PndConstField: empty parameter container!"<< endl;
78  fType= -1;
79  }
80  else {
81  fXmin = fieldPar->GetXmin();
82  fXmax = fieldPar->GetXmax();
83  fYmin = fieldPar->GetYmin();
84  fYmax = fieldPar->GetYmax();
85  fZmin = fieldPar->GetZmin();
86  fZmax = fieldPar->GetZmax();
87  fBx = fieldPar->GetBx();
88  fBy = fieldPar->GetBy();
89  fBz = fieldPar->GetBz();
90  fType = fieldPar->GetType();
91  }
92 }
93 // -------------------------------------------------------------------------
94 
95 
96 
97 // ----- Destructor ----------------------------------------------------
99 // -------------------------------------------------------------------------
100 
101 
102 
103 // ----- Set field region ----------------------------------------------
104 void PndConstField::SetFieldRegion(Double_t xMin, Double_t xMax,
105  Double_t yMin, Double_t yMax,
106  Double_t zMin, Double_t zMax) {
107  fXmin = xMin;
108  fXmax = xMax;
109  fYmin = yMin;
110  fYmax = yMax;
111  fZmin = zMin;
112  fZmax = zMax;
113 }
114 // -------------------------------------------------------------------------
115 
116 
117 
118 // ----- Set field values ----------------------------------------------
119 void PndConstField::SetField(Double_t bX, Double_t bY, Double_t bZ) {
120  fBx = bX;
121  fBy = bY;
122  fBz = bZ;
123 }
124 // -------------------------------------------------------------------------
125 
126 
127 
128 // ----- Get x component of field --------------------------------------
129 Double_t PndConstField::GetBx(Double_t x, Double_t y, Double_t z) {
130  if ( x < fXmin || x > fXmax ||
131  y < fYmin || y > fYmax ||
132  z < fZmin || z > fZmax ) return 0.;
133  return fBx;
134 }
135 // -------------------------------------------------------------------------
136 
137 
138 
139 // ----- Get y component of field --------------------------------------
140 Double_t PndConstField::GetBy(Double_t x, Double_t y, Double_t z) {
141  if ( x < fXmin || x > fXmax ||
142  y < fYmin || y > fYmax ||
143  z < fZmin || z > fZmax ) return 0.;
144  return fBy;
145 }
146 // -------------------------------------------------------------------------
147 
148 
149 
150 // ----- Get z component of field --------------------------------------
151 Double_t PndConstField::GetBz(Double_t x, Double_t y, Double_t z) {
152  if ( x < fXmin || x > fXmax ||
153  y < fYmin || y > fYmax ||
154  z < fZmin || z > fZmax ) return 0.;
155  return fBz;
156 }
157 // -------------------------------------------------------------------------
158 
159 // ----- GetBxyz components of field ------------------------------------
160 void PndConstField::GetBxyz(const Double_t point[3], Double_t* bField){
161  //This method is added for comatibility with the field maps and to be able to use a mixture of
162  // of maps and constant fields
163 
164 
165  if ( point [0] < fXmin || point [0] > fXmax ||
166  point [1] < fYmin || point [1] > fYmax ||
167  point [2] < fZmin || point [2] > fZmax ) {
168  bField[0]=0; bField[1]=0; bField[2]=0;
169  }
170  else{
171  bField[0]=fBx; bField[1]=fBy; bField[2]=fBz;
172  }
173 }
174 
175 // ----- Screen output -------------------------------------------------
177  cout << "======================================================" << endl;
178  cout << "---- " << fTitle << " : " << fName << endl;
179  cout << "----" << endl;
180  cout << "---- Field type : constant" << endl;
181  cout << "----" << endl;
182  cout << "---- Field regions : " << endl;
183  cout << "---- x = " << setw(4) << fXmin << " to " << setw(4)
184  << fXmax << " cm" << endl;
185  cout << "---- y = " << setw(4) << fYmin << " to " << setw(4)
186  << fYmax << " cm" << endl;
187  cout << "---- z = " << setw(4) << fZmin << " to " << setw(4)
188  << fZmax << " cm" << endl;
189  cout.precision(4);
190  cout << "---- B = ( " << fBx << ", " << fBy << ", " << fBz << " ) kG"
191  << endl;
192  cout << "======================================================" << endl;
193 }
194 // -------------------------------------------------------------------------
195 // --------- Fill the parameters --------------------------------------------
197 {
198  TString MapName=GetName();
199 // cout << "PndConstField::FillParContainer() " << endl;
200  FairRun *fRun=FairRun::Instance();
201  FairRuntimeDb *rtdb=fRun->GetRuntimeDb();
202  Bool_t kParameterMerged=kTRUE;
203  PndConstPar* Par = (PndConstPar*) rtdb->getContainer("PndConstPar");
204  Par->SetParameters(this);
205  Par->setInputVersion(fRun->GetRunId(),1);
206  Par->setChanged();
207 
208 }
209 
210