1#include "SimCore/DetectorConstruction.h"
3#include "Framework/Exception/Exception.h"
4#include "SimCore/SensitiveDetector.h"
5#include "SimCore/XsecBiasingOperator.h"
9namespace logical_volume_tests {
23static bool isInEcal(G4LogicalVolume* vol,
const std::string& vol_to_bias) {
24 const G4String& volumeName = vol->GetName();
25 return ((volumeName.contains(
"Si") || volumeName.contains(
"W") ||
26 volumeName.contains(
"PCB") || volumeName.contains(
"strongback") ||
27 volumeName.contains(
"Glue") || volumeName.contains(
"CFMix") ||
28 volumeName.contains(
"Al") || volumeName.contains(
"C")) &&
29 volumeName.contains(
"volume")) ||
30 (volumeName.contains(
"nohole_motherboard"));
41static bool isInHcal(G4LogicalVolume* vol,
const std::string& vol_to_bias) {
42 const G4String& volumeName = vol->GetName();
43 return ((volumeName.contains(
"abso") || volumeName.contains(
"ScintBox") ||
44 volumeName.contains(
"scint")) &&
45 volumeName.contains(
"hcal") && volumeName.contains(
"olume"));
59static bool isInEcalOld(G4LogicalVolume* vol,
const std::string& vol_to_bias) {
60 const G4String& volumeName = vol->GetName();
61 return ((volumeName.contains(
"Si") || volumeName.contains(
"W")) &&
62 volumeName.contains(
"volume"));
73static bool isInTargetRegion(G4LogicalVolume* vol,
74 const std::string& vol_to_bias) {
75 auto region = vol->GetRegion();
76 return (region and region->GetName().contains(
"target"));
89static bool isInTargetOnly(G4LogicalVolume* vol,
90 const std::string& vol_to_bias) {
91 return vol->GetName().contains(
"target");
106static bool nameContains(G4LogicalVolume* vol,
const std::string& vol_to_bias) {
107 return vol->GetName().contains(vol_to_bias);
115using Test = bool (*)(G4LogicalVolume*,
const std::string&);
122 : parser_(parser), parameters_{parameters}, conditions_interface_{ci} {}
128void DetectorConstruction::ConstructSDandField() {
131 "sensitive_detectors", {})};
132 for (
auto& det : sens_dets) {
135 det.getParameter<std::string>(
"class_name"),
139 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
140 if (sd->isSensDet(volume)) {
141 ldmx_log(debug) <<
"Attaching " << sd->GetName() <<
" to "
142 << volume->GetName();
143 volume->SetSensitiveDetector(sd);
152 logical_volume_tests::Test includeVolumeTest{
nullptr};
153 if (bop->getVolumeToBias().compare(
"ecal") == 0) {
154 includeVolumeTest = &logical_volume_tests::isInEcal;
155 }
else if (bop->getVolumeToBias().compare(
"old_ecal") == 0) {
156 includeVolumeTest = &logical_volume_tests::isInEcalOld;
157 }
else if (bop->getVolumeToBias().compare(
"target") == 0) {
158 includeVolumeTest = &logical_volume_tests::isInTargetOnly;
159 }
else if (bop->getVolumeToBias().compare(
"target_region") == 0) {
160 includeVolumeTest = &logical_volume_tests::isInTargetRegion;
161 }
else if (bop->getVolumeToBias().compare(
"hcal") == 0) {
162 includeVolumeTest = &logical_volume_tests::isInHcal;
164 std::cerr <<
"[ DetectorConstruction ] : "
165 <<
"WARN - Requested volume to bias '" << bop->getVolumeToBias()
166 <<
"' is not recognized. Will attach volumes based on if their"
167 <<
" name contains the volume to bias." << std::endl;
168 includeVolumeTest = &logical_volume_tests::nameContains;
171 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
172 auto volume_name = volume->GetName();
173 if (includeVolumeTest(volume, bop->getVolumeToBias())) {
174 bop->AttachTo(volume);
175 ldmx_log(debug) <<
"Attaching biasing operator " << bop->GetName()
176 <<
" to volume " << volume->GetName();
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Handle to the conditions system, provided at construction to classes which require it.
framework::config::Parameters parameters_
The set of parameters used to configure this class.
G4VPhysicalVolume * Construct()
Construct the detector.
DetectorConstruction(simcore::geo::Parser *parser, framework::config::Parameters ¶meters, ConditionsInterface &ci)
Constructor.
simcore::geo::Parser * parser_
The parser used to load the detector into memory.
simcore::ConditionsInterface & conditions_interface_
interface to conditions to be passed to SDs
void apply(UnaryFunction f) const
Apply the input UnaryFunction to each entry in the inventory.
static Factory & get()
get the factory instance
PrototypePtr make(const std::string &full_name, PrototypeConstructorArgs... maker_args)
make a new object by name
Interface for a parser used to load a geometry into Geant4.
virtual G4VPhysicalVolume * GetWorldVolume()=0
Pure virtual method used to retrieve the G4VPhysicalVolume associated with the most top-level (world)...