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 // Fallback: look up arbitrary particles via G4ParticleTable
24 // This supports custom particles like A' ("A^1") and any future additions
25 auto* particle = G4ParticleTable::GetParticleTable()->FindParticle(
26 this->getParticleToBias());
27 if (particle) {
28 process_manager_ = particle->GetProcessManager();
29 } else {
30 EXCEPTION_RAISE("BiasSetup", "Invalid particle type '" +
31 this->getParticleToBias() + "'.");
32 }
33 }
34
35 ldmx_log(info) << "Biasing particles of type " << this->getParticleToBias();
36
37 if (processIsBiased(this->getProcessToBias())) {
39 new G4BOptnChangeCrossSection("changeXsec-" + this->getProcessToBias());
40 } else {
41 EXCEPTION_RAISE("BiasSetup",
42 this->getProcessToBias() +
43 " is not found in list of biased processes!");
44 }
45}
46
47bool XsecBiasingOperator::processIsBiased(std::string process) {
48 // Loop over all processes and check if the given process is being
49 // biased.
50 const G4BiasingProcessSharedData* shared_data =
51 G4BiasingProcessInterface::GetSharedData(process_manager_);
52 if (shared_data) {
53 for (size_t iprocess = 0;
54 iprocess < (shared_data->GetPhysicsBiasingProcessInterfaces()).size();
55 ++iprocess) {
56 const G4BiasingProcessInterface* wrapper_process =
57 (shared_data->GetPhysicsBiasingProcessInterfaces())[iprocess];
58
59 if (wrapper_process->GetWrappedProcess()->GetProcessName().compareTo(
60 process) == 0) {
61 return true;
62 }
63 }
64 }
65 return false;
66}
67
69
70} // 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 ...