LDMX Software
DetectorConstruction.cxx
1/*~~~~~~~~~~~~~~~*/
2/* Framework */
3/*~~~~~~~~~~~~~~~*/
4#include "Framework/Exception/Exception.h"
5
6/*~~~~~~~~~~~~~*/
7/* SimCore */
8/*~~~~~~~~~~~~~*/
9#include "SimCore/DetectorConstruction.h"
10#include "SimCore/G4User/VolumeChecks.h"
11#include "SimCore/SensitiveDetector.h"
12#include "SimCore/XsecBiasingOperator.h"
13
14namespace simcore {
15namespace logical_volume_tests {
16
22using Test = bool (*)(G4LogicalVolume*, const std::string&);
23
24} // namespace logical_volume_tests
25
29 : parser_(parser), parameters_{parameters}, conditions_interface_{ci} {}
30
31G4VPhysicalVolume* DetectorConstruction::Construct() {
32 return parser_->GetWorldVolume();
33}
34
35void DetectorConstruction::ConstructSDandField() {
36 auto sens_dets{
37 parameters_.getParameter<std::vector<framework::config::Parameters>>(
38 "sensitive_detectors", {})};
39 for (auto& det : sens_dets) {
40 // create
42 det.getParameter<std::string>("class_name"),
43 det.getParameter<std::string>("instance_name"), conditions_interface_,
44 det);
45 // attach to volumes
46 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
47 if (sd->isSensDet(volume)) {
48 ldmx_log(debug) << "Attaching " << sd->GetName() << " to "
49 << volume->GetName();
50 volume->SetSensitiveDetector(sd);
51 }
52 }
53 }
54
55 // Biasing operators were created in RunManager::setupPhysics
56 // which is called before G4RunManager::Initialize
57 // which is where this method ends up being called.
59 logical_volume_tests::Test includeVolumeTest{nullptr};
60 if (bop->getVolumeToBias().compare("ecal") == 0) {
61 includeVolumeTest = &simcore::g4user::volumechecks::isInEcal;
62 } else if (bop->getVolumeToBias().compare("old_ecal") == 0) {
63 includeVolumeTest = &simcore::g4user::volumechecks::isInEcalOld;
64 } else if (bop->getVolumeToBias().compare("target") == 0) {
65 includeVolumeTest = &simcore::g4user::volumechecks::isInTargetOnly;
66 } else if (bop->getVolumeToBias().compare("target_region") == 0) {
67 includeVolumeTest = &simcore::g4user::volumechecks::isInTargetRegion;
68 } else if (bop->getVolumeToBias().compare("hcal") == 0) {
69 includeVolumeTest = &simcore::g4user::volumechecks::isInHcal;
70 } else {
71 std::cerr << "[ DetectorConstruction ] : "
72 << "WARN - Requested volume to bias '" << bop->getVolumeToBias()
73 << "' is not recognized. Will attach volumes based on if their"
74 << " name contains the volume to bias." << std::endl;
75 includeVolumeTest = &simcore::g4user::volumechecks::nameContains;
76 }
77
78 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
79 auto volume_name = volume->GetName();
80 if (includeVolumeTest(volume, bop->getVolumeToBias())) {
81 bop->AttachTo(volume);
82 ldmx_log(debug) << "Attaching biasing operator " << bop->GetName()
83 << " to volume " << volume->GetName();
84 } // BOP attached to target or ecal
85 } // loop over volumes
86 }); // loop over biasing operators
87}
88} // namespace simcore
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
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)...