EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndFieldPar.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndFieldPar.cxx
1 #include <iostream>
2 #include "PndConstField.h"
3 #include "PndFieldMap.h"
4 #include "PndFieldPar.h"
5 #include "FairParamList.h"
6 #include "PndMultiField.h"
7 #include "TObjArray.h"
8 
9 using namespace std;
10 
11 // ------ Constructor --------------------------------------------------
12 PndFieldPar::PndFieldPar(const char* name, const char* title,
13  const char* context)
14  : FairParGenericSet(name, title, context),
15  fType(-1),
16  fXmin(0),
17  fXmax(0),
18  fYmin(0),
19  fYmax(0),
20  fZmin(0),
21  fZmax(0),
22  fBx(0),
23  fBy(0),
24  fBz(0),
25  fMapName(TString("")),
26  fPosX(0),
27  fPosY(0),
28  fPosZ(0),
29  fScale(0)
30 
31 {
32 }
33 // -------------------------------------------------------------------------
34 
36  :fType(-1),
37  fXmin(0),
38  fXmax(0),
39  fYmin(0),
40  fYmax(0),
41  fZmin(0),
42  fZmax(0),
43  fBx(0),
44  fBy(0),
45  fBz(0),
46  fMapName(TString("")),
47  fPosX(0),
48  fPosY(0),
49  fPosZ(0),
50  fScale(0)
51 {
52 }
53 // -------------------------------------------------------------------------
54 
55 // ------ Destructor ---------------------------------------------------
57 // -------------------------------------------------------------------------
58 
59 
60 
61 // ------ Put parameters -----------------------------------------------
63 
64  if ( ! list ) return;
65 
66  list->add("Field Type", fType);
67 
68  if ( fType == 0 ) { // constant field
69  list->add("Field min x", fXmin);
70  list->add("Field max x", fXmax);
71  list->add("Field min y", fYmin);
72  list->add("Field max y", fYmax);
73  list->add("Field min z", fZmin);
74  list->add("Field max z", fZmax);
75  list->add("Field Bx", fBx);
76  list->add("Field By", fBy);
77  list->add("Field Bz", fBz);
78  }
79 
80  else if (fType >=1 && fType <= 4) { // 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 
87  }
88 
89 }
90 // -------------------------------------------------------------------------
91 
92 
93 
94 // -------- Get parameters ---------------------------------------------
96 
97  if ( ! list ) return kFALSE;
98 
99  if ( ! list->fill("Field Type", &fType) ) return kFALSE;
100 
101  if ( fType == 0 ) { // constant field
102  if ( ! list->fill("Field min x", &fXmin) ) return kFALSE;
103  if ( ! list->fill("Field max x", &fXmax) ) return kFALSE;
104  if ( ! list->fill("Field min y", &fYmin) ) return kFALSE;
105  if ( ! list->fill("Field max y", &fYmax) ) return kFALSE;
106  if ( ! list->fill("Field min z", &fZmin) ) return kFALSE;
107  if ( ! list->fill("Field max z", &fZmax) ) return kFALSE;
108  if ( ! list->fill("Field Bx", &fBx) ) return kFALSE;
109  if ( ! list->fill("Field By", &fBy) ) return kFALSE;
110  if ( ! list->fill("Field Bz", &fBz) ) return kFALSE;
111  }
112 
113  else if (fType >=1 && fType <= 4) { // field map
114  Text_t mapName[80];
115  if ( ! list->fill("Field map name", mapName, 80) ) return kFALSE;
116  fMapName = mapName;
117  if ( ! list->fill("Field x position", &fPosX) ) return kFALSE;
118  if ( ! list->fill("Field y position", &fPosY) ) return kFALSE;
119  if ( ! list->fill("Field z position", &fPosZ) ) return kFALSE;
120  if ( ! list->fill("Field scaling factor", &fScale) ) return kFALSE;
121  }
122  return kTRUE;
123 
124 }
125 // -------------------------------------------------------------------------
126 
127 
128 
129 // --------- Set parameters from FairField ------------------------------
130 void PndFieldPar::SetParameters(FairField* field) {
131 
132  if ( ! field ) {
133  cerr << "-W- PndFieldPar::SetParameters: Empty field pointer!" << endl;
134  return;
135  }
136 
137  fType = field->GetType();
138 
139  if ( fType == 0 ) { // constant field
140  PndConstField* fieldConst = (PndConstField*) 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 <= 4 ) { // field map
155  PndFieldMap* fieldMap = (PndFieldMap*) 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  } else if (fType ==5) {
165 
166  PndMultiField *fMulti=(PndMultiField *)field;
167  TObjArray *fieldlist = fMulti->GetFieldList();
168  TIterator* FieldIter = fieldlist->MakeIterator();
169  FieldIter->Reset();
170  FairField *fi=0;
171  while( (fi = (FairField*)FieldIter->Next() ) ) {
172  SetParameters(fi);
173  }
174 
175  delete FieldIter;
176  }else {
177  cerr << "-W- PndFieldPar::SetParameters: Unknown field type "
178  << fType << "!" << endl;
179  fBx = fBy = fBz = 0.;
180  fXmin = fXmax = fYmin = fYmax = fZmin = fZmax = 0.;
181  fMapName = "";
182  fPosX = fPosY = fPosZ = fScale = 0.;
183  }
184 
185  return;
186 
187 }
188 // -------------------------------------------------------------------------
189 
190 
191 
192 
193 
194 
196