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