20#include "BDSException.hh"
21#include "BDSFieldEM.hh"
22#include "BDSFieldEMVectorSum.hh"
24#include "G4ThreeVector.hh"
30BDSFieldEMVectorSum::BDSFieldEMVectorSum()
33BDSFieldEMVectorSum::BDSFieldEMVectorSum(
const std::vector<BDSFieldEM*>& fieldsIn,
34 const std::vector<G4ThreeVector>& fieldOffsetsIn,
35 const std::vector<G4double>& timeOffsetsIn,
36 const std::vector<double>& zLengthsIn):
38 fieldOffsets(fieldOffsetsIn),
39 timeOffsets(timeOffsetsIn),
40 zLengthsOver2(zLengthsIn)
42 if (fields.size() != fieldOffsets.size())
43 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of position offsets do not match");}
44 if (fields.size() != timeOffsets.size())
45 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of time offsets do not match");}
46 if (fields.size() != zLengthsOver2.size())
47 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of z lengths do not match");}
49 for (
auto it = zLengthsOver2.begin(); it < zLengthsOver2.end(); ++it)
55BDSFieldEMVectorSum::~BDSFieldEMVectorSum()
61void BDSFieldEMVectorSum::PushBackField(
const G4ThreeVector& positionOffset,
65 fields.push_back(emfield);
66 fieldOffsets.push_back(positionOffset);
67 timeOffsets.push_back(timeOffset);
68 zLengthsOver2.push_back(zLength/2);
72 const G4double t)
const
74 std::pair<G4ThreeVector, G4ThreeVector> result;
75 for (G4int i = 0; i < (G4int)fields.size(); i++)
77 G4ThreeVector dr = position - fieldOffsets[i];
78 if (fabs(dr.z()) > zLengthsOver2[i])
82 G4double dt = t - timeOffsets[i];
83 auto deltaField = fields[i]->GetField(dr,dt);
84 result.first += deltaField.first;
85 result.second += deltaField.second;
General exception with possible name of object and message.
virtual std::pair< G4ThreeVector, G4ThreeVector > GetField(const G4ThreeVector &position, const G4double t=0) const
Calculate the field value.
Interface for BDSIM electro-magnetic fields that may or may not be local.