EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PndFieldCreator.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PndFieldCreator.cxx
1 
2 #include "PndFieldCreator.h"
3 
4 #include "PndFieldMap.h"
5 #include "PndConstField.h"
6 #include "PndSolenoidMap.h"
7 #include "PndDipoleMap.h"
8 #include "PndTransMap.h"
9 #include "PndMultiField.h"
10 #include "PndMultiFieldPar.h"
11 #include "PndConstPar.h"
12 #include "PndDipoleMap.h"
13 #include "PndSolenoidMap.h"
14 #include "PndDipolePar.h"
15 #include "PndSolenoidPar.h"
16 #include "PndTransPar.h"
17 #include "PndTransMap.h"
18 #include "PndMapPar.h"
19 #include "FairBaseParSet.h"
20 #include "FairRunAna.h"
21 #include "FairRuntimeDb.h"
22 
23 #include "TObjArray.h"
24 
25 using std::cout;
26 using std::endl;
27 
29 
30 #include <EicMagneticField.h>
31 
34  fFieldPar(0),
35  fSPar(0),
36  fDPar(0),
37  fTPar(0),
38  fCPar(0),
39  fMPar(0)
40 
41 {
42  fCreator=this;
43 
44 }
46 {
47 }
49 {
50 
51 // cout << "PndFieldCreator::SetParm()" <<endl;
52  FairRun *Run = FairRun::Instance();
53  FairRuntimeDb *RunDB = Run->GetRuntimeDb();
54 
55  FairBaseParSet* par=(FairBaseParSet*)(RunDB->getContainer("FairBaseParSet"));
56 
57 #if 1
58  TObjArray *contList= par->GetContList();
59  TObject *obj=0;
60  if (contList) {
61  obj=contList->FindObject("PndMultiFieldPar");
62  }
63 
64  cout << "PndFieldCreator::SetParm() " << obj <<endl;
65 
66 
67  if (obj) {
68  fMPar = (PndMultiFieldPar*)RunDB->getContainer("PndMultiFieldPar");
69  }else if (contList->FindObject("PndFieldPar")) {
70  fFieldPar = (PndFieldPar*) RunDB->getContainer("PndFieldPar");
71  }else if (contList->FindObject("PndSolenoidPar")) {
72  fSPar = (PndSolenoidPar*) RunDB->getContainer("PndSolenoidPar");
73  }else if (contList->FindObject("PndDipolePar")) {
74  fDPar = (PndDipolePar*) RunDB->getContainer("PndDipolePar");
75  }else if (contList->FindObject("PndTransPar")) {
76  fTPar = (PndTransPar*) RunDB->getContainer("PndTransPar");
77  }else if (contList->FindObject("PndConstPar")) {
78  fCPar = (PndConstPar*) RunDB->getContainer("PndConstPar");
79  }
80 #endif
81 }
82 
84 {
85  //cout << "PndFieldCreator::createFairField()" <<endl;
86  FairField *fMagneticField=0;
87 
88  // Try to read in the EicMagneticField data; if fail, proceed in a usual fashion;
89  {
91  ioman->GetInFile()->GetObject(_EIC_MAGNETIC_FIELD_, fMagneticField);
92 
93  if (fMagneticField) return fMagneticField;
94  }
95 
96  PndMultiField *MField=0;
97  Int_t Type=-1;
98  Bool_t multi=kFALSE;
99  if (fMPar) {
100  MField = new PndMultiField(fMPar);
101  Type= fMPar->GetType();
102  }
103  if (Type==-1) {delete MField; MField=0;}
104 
105  if(MField) {
106  multi=kTRUE;
107  TObjArray *fParArray=fMPar->GetParArray();
108  TIterator *Iter=fParArray->MakeIterator();
109  Iter->Reset();
110  PndMapPar* fPar = NULL;
111  while( (fPar = (PndMapPar*)Iter->Next() ) ) {
112  fPar->Print();
113  if (fPar->GetType()==0){
114  FairField *fField1 = new PndConstField((PndConstPar*)fPar);
115  MField->AddField(fField1);
116  }
117  if (fPar->GetType()==1){
118  FairField *fField2 = new PndFieldMap((PndFieldPar*)fPar);
119  MField->AddField(fField2);
120  }
121  if (fPar->GetType()==2){
122  FairField *fField3 = new PndSolenoidMap((PndSolenoidPar*)fPar);
123  MField->AddField(fField3);
124  }
125  if (fPar->GetType()==3){
126  FairField *fField4 = new PndDipoleMap((PndDipolePar*)fPar);
127  MField->AddField(fField4);
128  }
129  if (fPar->GetType()==4){
130  FairField *fField5 = new PndTransMap((PndTransPar*)fPar);
131  MField->AddField(fField5);
132  }
133  }
134  }
135 
136  if (fCPar) {
137  FairField *fField1 = new PndConstField(fCPar);
138  Type= fCPar->GetType();
139  if (Type==-1) {delete fField1; fField1=0;}
140  if(fField1)fMagneticField=fField1;
141  }
142  if(fFieldPar){
143  FairField *fField2 = new PndFieldMap(fFieldPar);
144  Type= fFieldPar->GetType();
145  if (Type==-1){delete fField2; fField2=0;}
146  if(fField2)fMagneticField=fField2;
147  }
148  if(fSPar){
149  FairField *fField3 = new PndSolenoidMap(fSPar);
150  Type= fSPar->GetType();
151  if (Type==-1) {delete fField3; fField3=0;}
152  if(fField3)fMagneticField=fField3;
153  }
154  if(fDPar){
155  FairField *fField4 = new PndDipoleMap(fDPar);
156  Type= fDPar->GetType();
157  if (Type==-1) {delete fField4; fField4=0;}
158  if(fField4)fMagneticField=fField4;
159  }
160  if(fTPar){
161  FairField *fField5 = new PndTransMap(fTPar);
162  Type= fTPar->GetType();
163  if (Type==-1){delete fField5; fField5=0;}
164  if(fField5)fMagneticField=fField5;
165  }
166 
167  if (multi) {
168  MField->Init();
169  return MField;
170  }else{
171  if(fMagneticField){
172  fMagneticField->Init();
173  }
174  return fMagneticField;
175  }
176 }
177 
178 
180 
181 
182