er  dev
ERFieldPar.cxx
1 // -------------------------------------------------------------------------
2 // ----- ERFieldPar source file -----
3 // ----- Created 05/17 by V. Schetinin -----
4 // -------------------------------------------------------------------------
5 #include "ERFieldPar.h"
6 #include "ERFieldConst.h"
7 
8 #include "FairParamList.h"
9 #include <iostream>
10 using std::cout;
11 using std::cerr;
12 using std::endl;
13 const int kMaxLen = 2048;
14 // ------ Constructor --------------------------------------------------
15 ERFieldPar::ERFieldPar(const char* name, const char* title,
16  const char* context)
17  : FairParGenericSet(name, title, context),
18  fType(-1),
19  fXmin(0.),
20  fXmax(0.),
21  fYmin(0.),
22  fYmax(0.),
23  fZmin(0.),
24  fZmax(0.),
25  fBx(0.),
26  fBy(0.),
27  fBz(0.),
28  fMapName(""),
29  fPosX(0.),
30  fPosY(0.),
31  fPosZ(0.),
32  fScale(0.),
33  fDistortionFilename(""),
34  fParentName(""),
35  fTypeOfParent(0)
36 {
37 }
38 // -------------------------------------------------------------------------
40  : FairParGenericSet(),
41  fType(-1),
42  fXmin(0.),
43  fXmax(0.),
44  fYmin(0.),
45  fYmax(0.),
46  fZmin(0.),
47  fZmax(0.),
48  fBx(0.),
49  fBy(0.),
50  fBz(0.),
51  fMapName(""),
52  fPosX(0.),
53  fPosY(0.),
54  fPosZ(0.),
55  fScale(0.),
57  fParentName(""),
58  fTypeOfParent(0)
59 {
60 }
61 // -------------------------------------------------------------------------
62 // ------ Destructor ---------------------------------------------------
64 // -------------------------------------------------------------------------
65 // ------ Put parameters -----------------------------------------------
66 void ERFieldPar::putParams(FairParamList* list) {
67  if ( ! list ) return;
68  list->add("Field Type", fType);
69  if ( fType == 0 ) { // constant field
70  list->add("Field min x", fXmin);
71  list->add("Field max x", fXmax);
72  list->add("Field min y", fYmin);
73  list->add("Field max y", fYmax);
74  list->add("Field min z", fZmin);
75  list->add("Field max z", fZmax);
76  list->add("Field Bx", fBx);
77  list->add("Field By", fBy);
78  list->add("Field Bz", fBz);
79  }
80  else if (fType >=1 && fType <= kMaxFieldMapType) { // field map
81  list->add("Field map name", fMapName);
82  list->add("Field x position", fPosX);
83  list->add("Field y position", fPosY);
84  list->add("Field z position", fPosZ);
85  list->add("Field scaling factor", fScale);
86  if (fType==kTypeDistorted) {
87  list->add("Field map distortion filename", fDistortionFilename.Data());
88  list->add("Field name of parent field", fParentName.Data());
89  list->add("Field type of parent field", fTypeOfParent);
90  }
91  }
92 }
93 // -------------------------------------------------------------------------
94 // -------- Get parameters ---------------------------------------------
95 Bool_t ERFieldPar::getParams(FairParamList* list) {
96  if ( ! list ) return kFALSE;
97  if ( ! list->fill("Field Type", &fType) ) return kFALSE;
98  if ( fType == 0 ) { // constant field
99  if ( ! list->fill("Field min x", &fXmin) ) return kFALSE;
100  if ( ! list->fill("Field max x", &fXmax) ) return kFALSE;
101  if ( ! list->fill("Field min y", &fYmin) ) return kFALSE;
102  if ( ! list->fill("Field max y", &fYmax) ) return kFALSE;
103  if ( ! list->fill("Field min z", &fZmin) ) return kFALSE;
104  if ( ! list->fill("Field max z", &fZmax) ) return kFALSE;
105  if ( ! list->fill("Field Bx", &fBx) ) return kFALSE;
106  if ( ! list->fill("Field By", &fBy) ) return kFALSE;
107  if ( ! list->fill("Field Bz", &fBz) ) return kFALSE;
108  }
109  else if (fType >=1 && fType <= kMaxFieldMapType) { // field map
110  Text_t mapName[80];
111  if ( ! list->fill("Field map name", mapName, 80) ) return kFALSE;
112  fMapName = mapName;
113  if ( ! list->fill("Field x position", &fPosX) ) return kFALSE;
114  if ( ! list->fill("Field y position", &fPosY) ) return kFALSE;
115  if ( ! list->fill("Field z position", &fPosZ) ) return kFALSE;
116  if ( ! list->fill("Field scaling factor", &fScale) ) return kFALSE;
117  if (fType==kTypeDistorted) { // CbmFieldMapDistorted case
118  Text_t tmp[kMaxLen];
119  fDistortionFilename = "";
120  if ( ! list->fill("Field map distortion filename", tmp,kMaxLen) ) return kFALSE;
121  fDistortionFilename = tmp;
122  fParentName = "";
123  if ( ! list->fill("Field name of parent field", tmp,kMaxLen) ) return kFALSE;
124  fParentName = tmp;
125  if ( ! list->fill("Field type of parent field", &fTypeOfParent) ) return kFALSE;
126  }
127  }
128  return kTRUE;
129 }
130 // -------------------------------------------------------------------------
131 // --------- Set parameters from CbmField ------------------------------
132 void ERFieldPar::SetParameters(FairField* field) {
133  if ( ! field ) {
134  cerr << "-W- ERFieldPar::SetParameters: Empty field pointer!" << endl;
135  return;
136  }
137  fType = field->GetType();
138 
139  if ( fType == 0 ) { // constant field
140  ERFieldConst* fieldConst = (ERFieldConst*) field;
141  fBx = fieldConst->GetBx();
142  fBy = fieldConst->GetBy();
143  fBz = fieldConst->GetBz();
144  fXmin = fieldConst->GetXmin();
145  fXmax = fieldConst->GetXmax();
146  fYmin = fieldConst->GetYmin();
147  fYmax = fieldConst->GetYmax();
148  fZmin = fieldConst->GetZmin();
149  fZmax = fieldConst->GetZmax();
150  fMapName = "";
151  fPosX = fPosY = fPosZ = fScale = 0.;
152  }
153  /*
154  else if ( fType >=1 && fType <= kMaxFieldMapType ) { // field map
155  CbmFieldMap* fieldMap = (CbmFieldMap*) field;
156  fBx = fBy = fBz = 0.;
157  fXmin = fXmax = fYmin = fYmax = fZmin = fZmax = 0.;
158 
159  fMapName = field->GetName();
160  fPosX = fieldMap->GetPositionX();
161  fPosY = fieldMap->GetPositionY();
162  fPosZ = fieldMap->GetPositionZ();
163  fScale = fieldMap->GetScale();
164  /*
165  if (fieldMap->GetType()==kTypeDistorted) { // CbmFieldMapDistorted case
166  fDistortionFilename = ((CbmFieldMapDistorted*)fieldMap)->GetDistortionFilename();
167  fParentName = ((CbmFieldMapDistorted*)fieldMap)->GetParent()->GetName();
168  fTypeOfParent = ((CbmFieldMapDistorted*)fieldMap)->GetParent()->GetType();
169  }
170  */
171  //}
172  else {
173  cerr << "-W- ERFieldPar::SetParameters: Unknown field type "
174  << fType << "!" << endl;
175  fBx = fBy = fBz = 0.;
176  fXmin = fXmax = fYmin = fYmax = fZmin = fZmax = 0.;
177  fMapName = "";
178  fPosX = fPosY = fPosZ = fScale = 0.;
179  }
180 
181  return;
182 }
183 // -------------------------------------------------------------------------
184 
185 ClassImp(ERFieldPar)
Double_t fPosX
Definition: ERFieldPar.h:82
TString fMapName
Definition: ERFieldPar.h:79
virtual void putParams(FairParamList *list)
Definition: ERFieldPar.cxx:66
Double_t fBx
Definition: ERFieldPar.h:76
Int_t fTypeOfParent
Definition: ERFieldPar.h:94
Double_t GetXmin() const
Definition: ERFieldConst.h:60
Int_t fType
Definition: ERFieldPar.h:68
virtual Double_t GetBx(Double_t x, Double_t y, Double_t z)
void SetParameters(FairField *field)
Definition: ERFieldPar.cxx:132
Double_t fXmin
Definition: ERFieldPar.h:71
TString fDistortionFilename
Definition: ERFieldPar.h:88
TString fParentName
Definition: ERFieldPar.h:91
virtual Bool_t getParams(FairParamList *list)
Definition: ERFieldPar.cxx:95
Double_t fScale
Definition: ERFieldPar.h:85