File indexing completed on 2025-08-05 08:17:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include "EvtGenExtDecayerPhysics.hh"
0034
0035 #include <Geant4/G4Decay.hh>
0036 #include <Geant4/G4ParticleDefinition.hh>
0037 #include <Geant4/G4ParticleTable.hh> // for G4ParticleTable::G4PTblDi...
0038 #include <Geant4/G4ProcessManager.hh>
0039 #include <Geant4/G4ProcessVector.hh> // for G4ProcessVector
0040 #include <Geant4/G4String.hh> // for G4String
0041 #include <Geant4/G4VPhysicsConstructor.hh>
0042 #include <Geant4/G4VProcess.hh> // for G4VProcess
0043 #include <Geant4/G4Version.hh>
0044
0045 #include <boost/io/ios_state.hpp>
0046
0047 #include <cstddef> // for size_t
0048 #include <fstream>
0049 #include <iostream> // for operator<<, endl, basic_o...
0050 #include <string> // for operator<<
0051
0052
0053
0054
0055 #ifndef aParticleIterator
0056 #define aParticleIterator ((subInstanceManager.offset[g4vpcInstanceID])._aParticleIterator)
0057 #endif
0058
0059 EvtGenExtDecayerPhysics::EvtGenExtDecayerPhysics(const G4String& name)
0060 : G4VPhysicsConstructor(name)
0061 {
0062
0063 }
0064
0065
0066
0067
0068
0069
0070
0071 void EvtGenExtDecayerPhysics::ConstructProcess()
0072 {
0073
0074 boost::io::ios_all_saver ias_cout(std::cout);
0075 boost::io::ios_all_saver ias_cerr(std::cerr);
0076
0077
0078
0079
0080
0081 extDecayer = new G4EvtGenDecayer();
0082 extDecayer->SetVerboseLevel(0);
0083
0084 if (!DecayFile.empty())
0085 {
0086 std::ifstream f_local(DecayFile);
0087
0088 if (f_local.good())
0089 {
0090 extDecayer->SetDecayTable(DecayFile, false);
0091 }
0092 else
0093 {
0094 const char* CALIBRATIONROOT = getenv("CALIBRATIONROOT");
0095 if (!CALIBRATIONROOT)
0096 {
0097 exit(1);
0098 }
0099 std::string DecayFileCalibrationRepo = std::string(CALIBRATIONROOT) + "/EvtGen/" + DecayFile;
0100
0101 std::ifstream f_calib(DecayFileCalibrationRepo);
0102
0103 if (f_calib.good())
0104 {
0105 extDecayer->SetDecayTable(DecayFileCalibrationRepo, false);
0106 }
0107 else
0108 {
0109 std::cout << __PRETTY_FUNCTION__ << " : Fatal error. Decay file can not be found at "
0110 << DecayFile << " nor at " << DecayFileCalibrationRepo << std::endl;
0111
0112 exit(1);
0113 }
0114 }
0115 }
0116
0117 aParticleIterator->reset();
0118 int decayer_used = 0;
0119 while ((*aParticleIterator)())
0120 {
0121 G4ParticleDefinition* particle = aParticleIterator->value();
0122 G4ProcessManager* pmanager = particle->GetProcessManager();
0123
0124 if (verboseLevel > 1)
0125 {
0126 std::cout << "Setting ext decayer for: "
0127 << aParticleIterator->value()->GetParticleName()
0128 << std::endl;
0129 }
0130
0131 G4ProcessVector* processVector = pmanager->GetProcessList();
0132 #if G4VERSION_NUMBER >= 1060
0133 for (size_t i = 0; i < processVector->length(); i++)
0134 #else
0135 for (G4int i = 0; i < processVector->length(); i++)
0136 #endif
0137 {
0138 G4Decay* decay = dynamic_cast<G4Decay*>((*processVector)[i]);
0139 if (decay)
0140 {
0141
0142
0143
0144
0145
0146 decay->SetExtDecayer(extDecayer);
0147 decayer_used++;
0148 }
0149 }
0150 }
0151
0152
0153
0154 if (!decayer_used)
0155 {
0156 delete extDecayer;
0157 }
0158
0159 if (verboseLevel > 0)
0160 {
0161 std::cout << "External decayer physics constructed." << std::endl;
0162 }
0163 }
0164
0165