LDMX Software
simcore::DetectorConstruction Class Reference

Implements the Geant4 detector construction. More...

#include <DetectorConstruction.h>

Public Member Functions

 DetectorConstruction (std::shared_ptr< simcore::geo::Parser > parser, framework::config::Parameters &parameters, ConditionsInterface &ci)
 Constructor.
 
virtual ~DetectorConstruction ()=default
 Class destructor.
 
G4VPhysicalVolume * Construct ()
 Construct the detector.
 
void ConstructSDandField ()
 
std::string getDetectorName ()
 

Private Attributes

std::shared_ptr< simcore::geo::Parserparser_
 The parser used to load the detector into memory.
 
framework::config::Parameters parameters_
 The set of parameters used to configure this class.
 
simcore::ConditionsInterfaceconditions_interface_
 interface to conditions to be passed to SDs
 

Detailed Description

Implements the Geant4 detector construction.

Note
This class reads in a detector description from a GDML file using the basic G4GDMLParser and instantiates supplemental information using the AuxInfoReader.
See also
AuxInfoReader

Definition at line 33 of file DetectorConstruction.h.

Constructor & Destructor Documentation

◆ DetectorConstruction()

simcore::DetectorConstruction::DetectorConstruction ( std::shared_ptr< simcore::geo::Parser > parser,
framework::config::Parameters & parameters,
ConditionsInterface & ci )

Constructor.

Parameters
parserParser used to parse the geometry into memory.
parametersThe parameters used to configure this class.
ciThe conditions needed to build the detector.

Definition at line 26 of file DetectorConstruction.cxx.

29 : parser_(parser), parameters_{parameters}, conditions_interface_{ci} {}
framework::config::Parameters parameters_
The set of parameters used to configure this class.
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

Member Function Documentation

◆ Construct()

G4VPhysicalVolume * simcore::DetectorConstruction::Construct ( )

Construct the detector.

Returns
The top volume of the detector.

Definition at line 31 of file DetectorConstruction.cxx.

31 {
32 return parser_->getWorldVolume();
33}

References parser_.

◆ ConstructSDandField()

void simcore::DetectorConstruction::ConstructSDandField ( )

Definition at line 35 of file DetectorConstruction.cxx.

35 {
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}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78

◆ getDetectorName()

std::string simcore::DetectorConstruction::getDetectorName ( )
inline
Returns
The name of this detector. This is extracted from the description file used to build this detector.

Definition at line 65 of file DetectorConstruction.h.

65{ return parser_->getDetectorName(); }

References parser_.

Referenced by simcore::Simulator::beforeNewRun().

Member Data Documentation

◆ conditions_interface_

simcore::ConditionsInterface& simcore::DetectorConstruction::conditions_interface_
private

interface to conditions to be passed to SDs

Definition at line 75 of file DetectorConstruction.h.

◆ parameters_

framework::config::Parameters simcore::DetectorConstruction::parameters_
private

The set of parameters used to configure this class.

Definition at line 72 of file DetectorConstruction.h.

◆ parser_

std::shared_ptr<simcore::geo::Parser> simcore::DetectorConstruction::parser_
private

The parser used to load the detector into memory.

Definition at line 69 of file DetectorConstruction.h.

Referenced by Construct(), and getDetectorName().


The documentation for this class was generated from the following files: