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