LDMX Software
XsecBiasingOperator.cxx
1#include "SimCore/BiasOperators/XsecBiasingOperator.h"
2
3#include "Framework/Exception/Exception.h"
4
5namespace simcore {
6
8 std::string name, const framework::config::Parameters& parameters)
9 : G4VBiasingOperator(name),
10 the_log_{framework::logging::makeLogger(name)} {}
11
13 if (this->getParticleToBias().compare("gamma") == 0) {
14 process_manager_ = G4Gamma::GammaDefinition()->GetProcessManager();
15 } else if (this->getParticleToBias().compare("e-") == 0) {
16 process_manager_ = G4Electron::ElectronDefinition()->GetProcessManager();
17 } else if (this->getParticleToBias().compare("neutron") == 0) {
18 process_manager_ = G4Neutron::NeutronDefinition()->GetProcessManager();
19 } else if (this->getParticleToBias().compare("kaon0L") == 0) {
21 G4KaonZeroLong::KaonZeroLongDefinition()->GetProcessManager();
22 } else {
23 EXCEPTION_RAISE("BiasSetup", "Invalid particle type '" +
24 this->getParticleToBias() + "'.");
25 }
26
27 ldmx_log(info) << "Biasing particles of type " << this->getParticleToBias();
28
29 if (processIsBiased(this->getProcessToBias())) {
31 new G4BOptnChangeCrossSection("changeXsec-" + this->getProcessToBias());
32 } else {
33 EXCEPTION_RAISE("BiasSetup",
34 this->getProcessToBias() +
35 " is not found in list of biased processes!");
36 }
37}
38
39bool XsecBiasingOperator::processIsBiased(std::string process) {
40 // Loop over all processes and check if the given process is being
41 // biased.
42 const G4BiasingProcessSharedData* shared_data =
43 G4BiasingProcessInterface::GetSharedData(process_manager_);
44 if (shared_data) {
45 for (size_t iprocess = 0;
46 iprocess < (shared_data->GetPhysicsBiasingProcessInterfaces()).size();
47 ++iprocess) {
48 const G4BiasingProcessInterface* wrapper_process =
49 (shared_data->GetPhysicsBiasingProcessInterfaces())[iprocess];
50
51 if (wrapper_process->GetWrappedProcess()->GetProcessName().compareTo(
52 process) == 0) {
53 return true;
54 }
55 }
56 }
57 return false;
58}
59
61
62} // namespace simcore
#define DEFINE_FACTORY(classtype)
This should go into an implementation file for your prototype class.
Definition Factory.h:411
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Our specialization of the biasing operator used with Geant4.
virtual std::string getProcessToBias() const =0
Return the process whose cross-section will be biased.
void StartRun()
Method called at the beginning of a run.
XsecBiasingOperator(std::string name, const framework::config::Parameters &parameters)
Constructor.
bool processIsBiased(std::string process)
Check if the given processed is being biased.
G4ProcessManager * process_manager_
Process manager associated with the particle of interest.
virtual std::string getParticleToBias() const =0
Return the particle which should be biased.
G4BOptnChangeCrossSection * xsec_operation_
Cross-section biasing operation.
All classes in the ldmx-sw project use this namespace.
Dynamically loadable photonuclear models either from SimCore or external libraries implementing this ...