LDMX Software
DetectorConstruction.cxx
1#include "SimCore/DetectorConstruction.h"
2
3#include "Framework/Exception/Exception.h"
4#include "SimCore/SensitiveDetector.h"
5#include "SimCore/XsecBiasingOperator.h"
6
7namespace simcore {
8
9namespace logical_volume_tests {
10
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"));
31}
32
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"));
46}
47
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"));
63}
64
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"));
77}
78
89static bool isInTargetOnly(G4LogicalVolume* vol,
90 const std::string& vol_to_bias) {
91 return vol->GetName().contains("target");
92}
93
106static bool nameContains(G4LogicalVolume* vol, const std::string& vol_to_bias) {
107 return vol->GetName().contains(vol_to_bias);
108}
109
115using Test = bool (*)(G4LogicalVolume*, const std::string&);
116
117} // namespace logical_volume_tests
118
122 : parser_(parser), parameters_{parameters}, conditions_interface_{ci} {}
123
125 return parser_->GetWorldVolume();
126}
127
128void DetectorConstruction::ConstructSDandField() {
129 auto sens_dets{
130 parameters_.getParameter<std::vector<framework::config::Parameters>>(
131 "sensitive_detectors", {})};
132 for (auto& det : sens_dets) {
133 // create
135 det.getParameter<std::string>("class_name"),
136 det.getParameter<std::string>("instance_name"), conditions_interface_,
137 det);
138 // attach to volumes
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);
144 }
145 }
146 }
147
148 // Biasing operators were created in RunManager::setupPhysics
149 // which is called before G4RunManager::Initialize
150 // which is where this method ends up being called.
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;
163 } else {
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;
169 }
170
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();
177 } // BOP attached to target or ecal
178 } // loop over volumes
179 }); // loop over biasing operators
180}
181} // namespace simcore
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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 &parameters, 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.
Definition Factory.h:283
static Factory & get()
get the factory instance
Definition Factory.h:217
PrototypePtr make(const std::string &full_name, PrototypeConstructorArgs... maker_args)
make a new object by name
Definition Factory.h:265
Interface for a parser used to load a geometry into Geant4.
Definition Parser.h:25
virtual G4VPhysicalVolume * GetWorldVolume()=0
Pure virtual method used to retrieve the G4VPhysicalVolume associated with the most top-level (world)...