4 #include <G4UnitsTable.hh> 5 #include <G4TransportationManager.hh> 6 #include <G4Navigator.hh> 7 #include <G4ThreeVector.hh> 8 #include <G4RotationMatrix.hh> 9 #include <G4VPhysicalVolume.hh> 10 #include <G4LogicalVolume.hh> 11 #include <G4Material.hh> 12 #include <G4VisExtent.hh> 13 #include <Randomize.hh> 14 #include <G4SystemOfUnits.hh> 33 const G4LorentzVector& vtx) {
37 if (!(*test)->Apply(vtx))
return false;
44 class InternalVolumeName
47 InternalVolumeName(
const G4String&
name):
fName(name) {};
48 virtual ~InternalVolumeName() {};
49 virtual bool Apply(
const G4LorentzVector& vtx) {
51 G4Navigator* navigator
52 = G4TransportationManager::GetTransportationManager()
53 ->GetNavigatorForTracking();
57 = navigator->LocateGlobalPointAndSetup(vtx);
59 if (!volume)
return false;
62 if (!volume->GetName().contains(
fName)) {
72 class InternalNotVolumeName
73 :
public InternalVolumeName {
75 InternalNotVolumeName(
const G4String&
name)
76 : InternalVolumeName(name) {};
77 virtual ~InternalNotVolumeName() {};
78 virtual bool Apply(
const G4LorentzVector& vtx) {
79 return !InternalVolumeName::Apply(vtx);
84 class InternalVolumeMaterial
87 InternalVolumeMaterial(
const G4String&
name): fMater(name) {};
88 virtual ~InternalVolumeMaterial() {};
89 virtual bool Apply(
const G4LorentzVector& vtx) {
91 G4Navigator* navigator
92 = G4TransportationManager::GetTransportationManager()
93 ->GetNavigatorForTracking();
97 = navigator->LocateGlobalPointAndSetup(vtx);
99 if (!volume)
return false;
101 G4String matter = volume->GetLogicalVolume()
102 ->GetMaterial()->GetName();
105 if (!matter.contains(fMater))
return false;
113 class InternalNotVolumeMaterial
114 :
public InternalVolumeMaterial {
116 InternalNotVolumeMaterial(
const G4String&
name)
117 : InternalVolumeMaterial(name) {};
118 virtual ~InternalNotVolumeMaterial() {};
119 virtual bool Apply(
const G4LorentzVector& vtx) {
120 return !InternalVolumeMaterial::Apply(vtx);
125 class InternalMinimumCoordinate
129 fCoordinate(coord), fValue(minimum) {};
130 virtual ~InternalMinimumCoordinate() {};
131 virtual bool Apply(
const G4LorentzVector& vtx) {
132 if (vtx[fCoordinate] < fValue)
return false;
141 class InternalMaximumCoordinate
145 fCoordinate(coord), fValue(maximum) {};
146 virtual ~InternalMaximumCoordinate() {};
147 virtual bool Apply(
const G4LorentzVector& vtx) {
148 if (fValue < vtx[fCoordinate])
return false;
159 const G4String&
name) {
164 const G4String&
name) {
169 const G4String&
name) {
174 const G4String&
name) {
211 QueueElement(G4VPhysicalVolume* v,
212 const G4ThreeVector&
t,
213 const G4RotationMatrix&
r)
214 :
volume(v), translation(t), rotation(r) {}
215 G4VPhysicalVolume*
volume;
216 G4ThreeVector translation;
217 G4RotationMatrix rotation;
226 EDepSimError(
"EDepSim::VConstrainedPositionGenerator:: " 227 "The sample volume must be set");
232 G4Navigator* navigator
233 = G4TransportationManager::GetTransportationManager()
234 ->GetNavigatorForTracking();
236 std::queue<QueueElement> volumes;
237 volumes.push(QueueElement(navigator->GetWorldVolume(),
238 G4ThreeVector(0,0,0),
239 G4RotationMatrix()));
240 while (!volumes.empty()) {
241 G4VPhysicalVolume* phyVolume = volumes.front().volume;
242 G4ThreeVector translation
243 = volumes.front().translation + phyVolume->GetObjectTranslation();
244 G4RotationMatrix rotation = volumes.front().rotation;
245 rotation.transform(phyVolume->GetObjectRotationValue());
248 if (phyVolume->GetName().find(
fSampleVolume) != std::string::npos) {
249 G4VisExtent volExtent
250 = phyVolume->GetLogicalVolume()->GetSolid()->GetExtent();
251 G4ThreeVector volMin;
252 G4ThreeVector volMax;
253 volMin.set(volExtent.GetXmin(),
255 volExtent.GetZmin());
256 volMax.set(volExtent.GetXmax(),
258 volExtent.GetZmax());
259 volMin = rotation*volMin + translation;
260 volMax = rotation*volMax + translation;
270 G4LogicalVolume* logVolume = phyVolume->GetLogicalVolume();
271 for (std::size_t i=0; i< logVolume->GetNoDaughters(); ++i) {
272 volumes.push(QueueElement(logVolume->GetDaughter(i),
290 for (
int i=0; i<3; ++i) {
#define EDepSimLog(outStream)
G4ThreeVector fMinimumCorner
The lower boundary of the volume to be sampled for the vertex.
virtual bool ValidPosition(const G4LorentzVector &vtx)
Return true if the vertex is valid. This is used in the derived class.
void CheckMaxZ(double z)
Check that the vertex Z position is less than some value.
G4String fSampleVolume
The name of the volume to be sampled.
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
static const std::string volume[nvol]
void FindLimits()
Find the limits of the volume to be sampled for a good vertex.
G4String fName
The name of the generator.
bool fLimitsFound
True if the limits have been initialized.
G4LorentzVector TrialPosition()
Generate a trial position uniformly in the sample box.
void CheckVolumeName(const G4String &name)
Construct a module from components.
void CheckMaxX(double x)
Check that the vertex X position is less than some value.
void CheckMinY(double y)
Check that the vertex Y position is greater than some value.
void CheckVolumeMaterial(const G4String &name)
Check that the vertex is inside of a material specified by name.
virtual bool ForcePosition()
yes & test(std::ostream &)
meter_as<> meter
Type of space stored in meters, in double precision.
G4ThreeVector fMaximumCorner
The upper boundary of the volume to be sampled for the vertex.
void CheckMaxY(double y)
Check that the vertex Y position is less than some value.
void CheckNotVolumeName(const G4String &name)
#define EDepSimError(outStream)
void CheckMinX(double x)
Check that the vertex X position is greater than some value.
VConstrainedPositionGenerator(const G4String &name)
PositionTests fPositionTests
The vertex tests to apply.
virtual ~VConstrainedPositionGenerator()
void CheckMinZ(double z)
Check that the vertex Z position is greater than some value.
void CheckNotVolumeMaterial(const G4String &name)
Check that the vertex is not inside of a material specified by name.