19#include "BDSException.hh"
20#include "BDSFieldEM.hh"
21#include "BDSFieldEMVectorSum.hh"
23#include "G4ThreeVector.hh"
29BDSFieldEMVectorSum::BDSFieldEMVectorSum()
32BDSFieldEMVectorSum::BDSFieldEMVectorSum(
const std::vector<BDSFieldEM*>& fieldsIn,
33 const std::vector<G4ThreeVector>& fieldOffsetsIn,
34 const std::vector<G4double>& timeOffsetsIn,
35 const std::vector<double>& zLengthsIn):
37 fieldOffsets(fieldOffsetsIn),
38 timeOffsets(timeOffsetsIn),
39 zLengthsOver2(zLengthsIn)
41 if (fields.size() != fieldOffsets.size())
42 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of position offsets do not match");}
43 if (fields.size() != timeOffsets.size())
44 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of time offsets do not match");}
45 if (fields.size() != zLengthsOver2.size())
46 {
throw BDSException(__METHOD_NAME__,
"number of fields and number of z lengths do not match");}
48 for (
auto it = zLengthsOver2.begin(); it < zLengthsOver2.end(); ++it)
54BDSFieldEMVectorSum::~BDSFieldEMVectorSum()
60void BDSFieldEMVectorSum::PushBackField(
const G4ThreeVector& positionOffset,
64 fields.push_back(emfield);
65 fieldOffsets.push_back(positionOffset);
66 timeOffsets.push_back(timeOffset);
67 zLengthsOver2.push_back(zLength/2);
71 const G4double t)
const
73 std::pair<G4ThreeVector, G4ThreeVector> result;
74 for (G4int i = 0; i < (G4int)fields.size(); i++)
76 G4ThreeVector dr = position - fieldOffsets[i];
77 if (fabs(dr.z()) > zLengthsOver2[i])
81 G4double dt = t - timeOffsets[i];
82 auto deltaField = fields[i]->GetField(dr,dt);
83 result.first += deltaField.first;
84 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.