/
PndMultiField.cxx
218 lines (161 loc) · 5.84 KB
/
PndMultiField.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// -------------------------------------------------------------------------
// ----- PndMultiField source file -----
// ----- Created 29/01/07 by M. Al/Turany -----
// -------------------------------------------------------------------------
#include "PndMultiField.h"
#include "PndRegion.h"
#include "PndConstField.h"
#include "PndFieldMap.h"
#include "PndMapPar.h"
#include "PndMultiFieldPar.h"
#include "PndSolenoidMap.h"
#include "PndTransMap.h"
#include "PndDipoleMap.h"
#include "FairRun.h"
#include "FairRuntimeDb.h"
#include "TObjArray.h"
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
// ------------- Default constructor ----------------------------------
PndMultiField::PndMultiField()
: fMaps(new TObjArray(10)), fNoOfMaps(0), fFieldMaps(), fMapIter(), fBeamMom(0.)
{
fType = 5;
}
// ------------- Default constructor ----------------------------------
PndMultiField::PndMultiField(TString Map, Double_t BeamMom)
: fMaps(new TObjArray(10)), fNoOfMaps(0), fFieldMaps(), fMapIter(), fBeamMom(BeamMom)
{
fType = 5;
Map.ToUpper();
if (Map=="FULL") {
PndTransMap *map_t= new PndTransMap("TransMap", "R", fBeamMom);
PndDipoleMap *map_d1= new PndDipoleMap("DipoleMap1", "R", fBeamMom);
PndDipoleMap *map_d2= new PndDipoleMap("DipoleMap2", "R", fBeamMom);
PndSolenoidMap *map_s1= new PndSolenoidMap("SolenoidMap1", "R");
PndSolenoidMap *map_s2= new PndSolenoidMap("SolenoidMap2", "R");
PndSolenoidMap *map_s3= new PndSolenoidMap("SolenoidMap3", "R");
PndSolenoidMap *map_s4= new PndSolenoidMap("SolenoidMap4", "R");
AddField(map_t);
AddField(map_d1);
AddField(map_d2);
AddField(map_s1);
AddField(map_s2);
AddField(map_s3);
AddField(map_s4);
}else if (Map=="DIPOLE") {
PndDipoleMap *map_d1= new PndDipoleMap("DipoleMap1", "R", fBeamMom);
PndDipoleMap *map_d2= new PndDipoleMap("DipoleMap2", "R", fBeamMom);
AddField(map_d1);
AddField(map_d2);
}else if (Map=="SOLENOID") {
PndSolenoidMap *map_s1= new PndSolenoidMap("SolenoidMap1", "R");
PndSolenoidMap *map_s2= new PndSolenoidMap("SolenoidMap2", "R");
PndSolenoidMap *map_s3= new PndSolenoidMap("SolenoidMap3", "R");
PndSolenoidMap *map_s4= new PndSolenoidMap("SolenoidMap4", "R");
AddField(map_s1);
AddField(map_s2);
AddField(map_s3);
AddField(map_s4);
}
}
// ------------------------------------------------------------------------
// ------------ Constructor from PndFieldPar --------------------------
PndMultiField::PndMultiField(PndMultiFieldPar* fieldPar)
: fMaps( new TObjArray(10)), fNoOfMaps(0), fFieldMaps(), fMapIter(), fBeamMom(0.)
{
fType = 5;
TObjArray *fArray= fieldPar->GetParArray();
if(fArray->IsEmpty()) fType=-1;
}
// ------------ Destructor --------------------------------------------
PndMultiField::~PndMultiField() {
//printf("PndMultiField::~PndMultiField() \n");
fMaps->Delete();
delete fMaps;
}
// ----------- Adding fields ------------------------------------------
void PndMultiField::AddField(FairField *field){
if(field){
fMaps->AddLast(field);
fNoOfMaps++;
}
}
// ----------- Intialisation ------------------------------------------
void PndMultiField::Init() {
PndConstField *field=0;
PndFieldMap *fieldMap=0;
for (Int_t n=0; n<=fNoOfMaps; n++){
fieldMap = dynamic_cast<PndFieldMap *>(fMaps->At(n));
field = dynamic_cast<PndConstField *>(fMaps->At(n));
if(fieldMap){
fieldMap->Init();
fFieldMaps.insert( pair<PndRegion*, FairField*>(new PndRegion(fieldMap->GetZmin(),fieldMap->GetZmax()) , fieldMap ));
}else if(field){
field->Init();
fFieldMaps.insert( pair<PndRegion*, FairField*>(new PndRegion(field->GetZmin(),field->GetZmax() ), field ));
}
}
}
// --------- Screen output --------------------------------------------
void PndMultiField::Print() {
for (Int_t n=0; n<=fNoOfMaps; n++){
FairField *fieldMap = dynamic_cast<FairField *>(fMaps->At(n));
if(fieldMap) fieldMap->Print();
}
}
// --------- Fill the parameters --------------------------------------------
void PndMultiField::FillParContainer() {
// for (Int_t n=0; n<=fNoOfMaps; n++){
// FairField *fieldMap = dynamic_cast<FairField *>(fMaps->At(n));
// if(fieldMap) fieldMap->FillParContainer();
// }
FairRun *fRun=FairRun::Instance();
FairRuntimeDb *rtdb=fRun->GetRuntimeDb();
Bool_t kParameterMerged=kTRUE;
PndMultiFieldPar* Par = (PndMultiFieldPar*) rtdb->getContainer("PndMultiFieldPar");
Par->SetParameters(this);
Par->setInputVersion(fRun->GetRunId(),1);
Par->setChanged();
}
// -------------------------------------------------------------------------
void PndMultiField::GetFieldValue(const Double_t point[3], Double_t* bField)
{
PndRegion *fReg=0;
FairField *fField=0;
for (fMapIter=fFieldMaps.begin(); fMapIter!= fFieldMaps.end();fMapIter++ ){
fReg=fMapIter->first;
if(fReg->IsInside(point[2])){
fField=fMapIter->second;
break;
}
}
if(fField){
//printf("%s\n", fField->GetName());
fField->GetBxyz(point, bField);
}else{
bField[0] = 0;
bField[1] = 0;
bField[2] = 0;
}
// 2015/08/28 -> NB: EicMagneticField does this job; this code has never been used;
#if 0
// Well, I rather want a superposition of all fields contributiong to
// this Z-range; in fact this crap is needed for DID test studies only;
for(unsigned iq=0; iq<3; iq++)
bField[iq] = 0.0;
for (fMapIter=fFieldMaps.begin(); fMapIter!= fFieldMaps.end();fMapIter++ ){
PndRegion *fReg = fMapIter->first;
if(fReg->IsInside(point[2])){
FairField *fField = fMapIter->second;
double buffer[3];
fField->GetBxyz(point, buffer);
for(unsigned iq=0; iq<3; iq++)
bField[iq] += buffer[iq];
} //if
} //for
#endif
}
ClassImp(PndMultiField)