4#include "Framework/Exception/Exception.h"
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"
17namespace logical_volume_tests {
24using Test = bool (*)(G4LogicalVolume*,
const std::string&);
29 std::shared_ptr<simcore::geo::Parser> parser,
31 : parser_(parser), parameters_{parameters}, conditions_interface_{ci} {}
34 return parser_->getWorldVolume();
37void DetectorConstruction::ConstructSDandField() {
38 auto sens_dets{
parameters_.
get<std::vector<framework::config::Parameters>>(
39 "sensitive_detectors", {})};
40 for (
auto& det : sens_dets) {
42 auto sd = SensitiveDetector::Factory::get().make(
43 det.get<std::string>(
"class_name"),
46 EXCEPTION_RAISE(
"UnableToCreate",
47 "Unable to create a SensitiveDetector of type " +
48 det.get<std::string>(
"class_name"));
51 for (G4LogicalVolume* volume : *G4LogicalVolumeStore::GetInstance()) {
52 if (sd.value()->isSensDet(volume)) {
53 ldmx_log(debug) <<
"Attaching " << sd.value()->GetName() <<
" to "
55 volume->SetSensitiveDetector(sd.value());
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;
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;
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();
Class encapsulating parameters for configuring a processor.
const T & get(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.
DetectorConstruction(std::shared_ptr< simcore::geo::Parser > parser, framework::config::Parameters ¶meters, 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 ...