9 #include "nutools/G4Base/G4Helper.h" 10 #include "nutools/G4Base/DetectorConstruction.h" 11 #include "nutools/G4Base/UserActionManager.h" 15 #include "Geant4/G4UImanager.hh" 16 #include "Geant4/G4VUserDetectorConstruction.hh" 17 #include "Geant4/G4VUserPrimaryGeneratorAction.hh" 18 #include "Geant4/G4VUserPhysicsList.hh" 19 #include "Geant4/G4UserLimits.hh" 20 #include "Geant4/G4UserRunAction.hh" 21 #include "Geant4/G4UserEventAction.hh" 22 #include "Geant4/G4UserTrackingAction.hh" 23 #include "Geant4/G4UserSteppingAction.hh" 24 #include "Geant4/G4VisExecutive.hh" 25 #include "Geant4/G4StepLimiterPhysics.hh" 26 #include "Geant4/G4LogicalVolumeStore.hh" 28 #include <boost/algorithm/string.hpp> 30 #include "Geant4/QGSP_BERT.hh" 31 #define TRY_NEW_PL_FACTORY 32 #ifdef TRY_NEW_PL_FACTORY 33 #include "nutools/G4Base/G4PhysListFactory.hh" 35 #include "Geant4/G4PhysListFactory.hh" 38 #include "nutools/G4Base/G4PhysicsProcessFactorySingleton.hh" 39 #include "Geant4/G4VModularPhysicsList.hh" 51 static G4VisExecutive*
vm_ = 0;
56 : fCheckOverlaps (false )
57 , fValidateGDMLSchema(false )
58 , fUseStepLimits (false )
59 , fUIManager (nullptr)
60 , fConvertMCTruth (nullptr)
119 fRunManager->SetUserAction( static_cast<G4UserRunAction*>(0) );
120 fRunManager->SetUserAction( static_cast<G4UserEventAction*>(0) );
121 fRunManager->SetUserAction( static_cast<G4UserTrackingAction*>(0) );
122 fRunManager->SetUserAction( static_cast<G4UserSteppingAction*>(0) );
124 fRunManager->SetUserAction( static_cast<G4UserStackingAction*>(0) );
131 <<
"G4Helper never initialized; probably because there were no input primary events";
163 G4VUserPhysicsList* physics = 0;
166 bool list_known_procs =
true;
171 std::vector< std::string > pstrings;
174 boost::token_compress_on );
176 for (
unsigned int j=0; j < pstrings.size(); ++j )
179 if ( pstrings.size() < 1 ) pstrings.push_back(
"");
187 #ifdef TRY_NEW_PL_FACTORY 190 factoryname =
"alt::G4PhysListFactory";
209 G4PhysListFactory factory;
213 if ( factory.IsReferencePhysList(phListName) ) {
214 bywhom = factoryname;
219 if ( phListName !=
"" ) {
221 <<
" failed to find ReferencePhysList \"" 223 #ifdef TRY_NEW_PL_FACTORY 224 factory.PrintAvailablePhysLists();
226 std::vector<G4String> list = factory.AvailablePhysLists();
228 <<
"For reference: PhysicsLists in G4PhysListFactory are: ";
229 for (
size_t indx=0; indx < list.size(); ++indx ) {
232 <<
"\"" << list[indx] <<
"\"";
241 <<
"G4PhysListFactory could not construct \"" 245 <<
"fall back to using QGSP_BERT";
247 physics =
new QGSP_BERT;
248 phListName =
"QGSP_BERT";
253 <<
" constructed G4VUserPhysicsList \"" 264 for (
unsigned int k=1;
k < pstrings.size(); ++
k ) {
268 std::vector< std::string > physProcParts;
270 boost::is_any_of(
"(,)"),
271 boost::token_compress_on );
273 for (
unsigned int j=0; j < physProcParts.size(); ++j )
278 if ( physProcName ==
"" )
continue;
284 <<
"G4PhysicsProcessFactorySingleton could not " 289 if ( ! list_known_procs )
continue;
290 list_known_procs =
false;
293 <<
"For reference: PhysicsProcesses in " 294 <<
"G4PhysicsProcessFactorySingleton are: ";
298 <<
" ... no registered processes";
300 for (
size_t indx=0; indx < list.size(); ++indx ) {
303 <<
"\"" << list[indx] <<
"\"";
312 <<
"\" physics process to \"" 320 G4VModularPhysicsList* mpl =
dynamic_cast<G4VModularPhysicsList*
>(physics);
321 if ( ! pctor )
MF_LOG_VERBATIM(
"G4Helper") <<
" ... failed with null pointer";
322 else if ( ! mpl )
MF_LOG_VERBATIM(
"G4Helper") <<
" ... failed, physics list wasn't a G4VModularPhysicsList";
323 else mpl->RegisterPhysics(pctor);
329 for (
unsigned int i=1; i < physProcParts.size(); ++i ) {
330 if ( physProcParts[i] ==
"" )
continue;
342 auto mpl =
dynamic_cast<G4VModularPhysicsList*
>(physics);
343 if(mpl) mpl->RegisterPhysics(
new G4StepLimiterPhysics());
346 <<
"Step limits requested, but unable to register G4StepLimiterPhysics" 347 <<
"\n NO STEP LIMITS WILL BE APPLIED";
359 for(
auto const& pw : pworlds){
385 G4LogicalVolume* logVol = G4LogicalVolumeStore::GetInstance()->GetVolume(volumeName);
389 G4UserLimits *stepLimit =
new G4UserLimits(maxStepSize);
390 logVol->SetUserLimits(stepLimit);
396 <<
"Unable to find volume " 398 <<
" and set step size limit";
412 fDetector->RegisterParallelWorld(pWorld);
446 G4UserRunAction* runAction = (G4UserRunAction* ) uaManager;
447 G4UserEventAction* eventAction = (G4UserEventAction* ) uaManager;
448 G4UserTrackingAction* trackingAction = (G4UserTrackingAction*) uaManager;
449 G4UserSteppingAction* steppingAction = (G4UserSteppingAction*) uaManager;
456 G4UserStackingAction* stackingAction = (G4UserStackingAction*) uaManager;
464 if(!vm_) vm_ =
new G4VisExecutive();
481 return this->
G4Run( primary.
get() );
509 for(
auto primary : primaries)
static std::string trim(const std::string &str, const std::string &whitespace=" \t")
virtual bool DoesAnyActionProvideStacking()
void Reset()
Get ready to convert a new set of MCTruth objects.
bool fValidateGDMLSchema
Have G4GDML validate geometry schema?
bool G4Run(std::vector< const simb::MCTruth * > &primaries)
void SetUserAction()
Initialization for the Geant4 Monte Carlo.
void ConstructDetector(std::string const &gdmlFile)
#define MF_LOG_ERROR(category)
void SetParallelWorlds(std::vector< G4VUserParallelWorld * > pworlds)
std::vector< G4VUserParallelWorld * > fParallelWorlds
list of parallel worlds
const std::vector< G4String > & AvailablePhysicsProcesses() const
void InitPhysics()
Initialization for the Geant4 Monte Carlo.
void SetPhysicsList(std::string physicsList)
static G4VisExecutive * vm_
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
std::string fGDMLFile
Name of the gdml file containing the detector Geometry.
static G4PhysicsProcessFactorySingleton & Instance()
bool fCheckOverlaps
Have G4GDML check for overlaps?
basic interface to Geant4 for ART-based software
void SetVolumeStepLimit(std::string const &volumeName, double maxStepSize)
std::string fG4MacroPath
to be executed before main MC processing.
Q_EXPORT QTSManip setw(int w)
DetectorConstruction * fDetector
DetectorConstruction object.
G4Helper()
Standard constructor and destructor for an FMWK module.
G4bool IsKnownPhysicsProcess(const G4String &)
static UserActionManager * Instance()
#define MF_LOG_VERBATIM(category)
G4RunManager * fRunManager
Geant4's run manager.
std::string fG4PhysListName
Name of physics list to use.
void split(std::string const &s, char c, OutIter dest)
void Append(art::Ptr< simb::MCTruth > &mct)
Event generator information.
bool fUseStepLimits
Set in SetVolumeStepLimit.
#define MF_LOG_WARNING(category)
G4VPhysicsConstructor * GetPhysicsProcess(const G4String &)
ConvertMCTruthToG4 * fConvertMCTruth
Geant4 event generator.
QTextStream & endl(QTextStream &s)
G4UImanager * fUIManager
Geant4's user-interface manager.