G4Helper.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file G4Helper.h
3 /// \brief Use Geant4 to run the detector simulation
4 ///
5 /// \version $Id: G4Helper.h,v 1.15 2012-12-03 23:29:50 rhatcher Exp $
6 /// \author seligman@nevis.columbia.edu, brebel@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 
9 /// This object has the following functions:
10 ///
11 /// - Initialize Geant4 physics, detector geometry, and other
12 /// processing.
13 ///
14 /// - Pass the primary particles to the Geant4 simulation to calculate
15 /// "truth" information for the detector response.
16 ///
17 
18 #ifndef G4BASE_G4HELPER_H
19 #define G4BASE_G4HELPER_H
20 
21 // nutools includes
22 #include "nutools/G4Base/ConvertMCTruthToG4.h"
23 
24 #include <cstring>
25 
26 // ART Includes
29 
30 #include "Geant4/G4RunManager.hh"
31 #include "Geant4/G4VUserParallelWorld.hh"
32 
33 // Forward declarations
34 class G4UImanager;
35 
36 namespace simb{ class MCTruth; }
37 namespace rndm { class ParticleList; }
38 
39 ///basic interface to Geant4 for ART-based software
40 namespace g4b {
41 
42  // Forward declarations within namespace.
43  class ParticleListAction;
44  class ConvertPrimaryToGeant4;
45  class DetectorConstruction;
46 
47  class G4Helper {
48 
49  public:
50 
51  /// Standard constructor and destructor for an FMWK module.
52  G4Helper();
53  G4Helper(std::string const& g4macropath,
54  std::string const& g4physicslist = "QGSP_BERT",
55  std::string const& gdmlFile = "");
56  virtual ~G4Helper();
57 
58  // have to call this before InitPhysics if you want to load in
59  // parallel worlds. G4Helper takes over ownership
60  void SetParallelWorlds(std::vector<G4VUserParallelWorld*> pworlds);
61 
62  // Call this method to set a step size limit in the chosen volume
63  // It must be called before InitPhysics (which calls SetPhysicsList)
64  // so that the physics list will know to register a step limiter
65  void SetVolumeStepLimit(std::string const& volumeName,
66  double maxStepSize);
67 
68  // extra control over how GDML is parsed
69  inline void SetOverlapCheck(bool check);
70  inline void SetValidateGDMLSchema(bool validate);
71 
72  // have to call this before InitPhysics if you want to control
73  // when the detector is constructed, useful if you need to
74  // muck with G4LogicalVolumes
75  // if the fDetector pointer is null when InitMC is called
76  // it will just construct the fDetector
77  void ConstructDetector(std::string const& gdmlFile);
78 
79  // Initialization for the Geant4 Monte Carlo, called before the
80  // first event is simulated. InitPhysics gets the G4 physics
81  // initialized, and the UserPrimaryGeneratorAction (ConvertMCTruthToG4).
82  // SetUserAction hands the UserActionManager over (so call it
83  // after it is fully configured) to the RunManager; it also
84  // runs the initial command macro and completes the initialization.
85  // These two should be called in this order with any UserActionManager
86  // configuration in between.
87  void InitPhysics();
88  void SetUserAction();
89 
90  // This is the method that actually passes a list of MCTruth objects to G4
91  // so it can create a list of particles
92  bool G4Run(std::vector<const simb::MCTruth*> &primaries);
93 
94  // Pass a single MCTruth object to G4
95  bool G4Run(art::Ptr<simb::MCTruth>& primary);
96 
97  // Pass a single MCTruth object to G4
98  bool G4Run(const simb::MCTruth* primary);
99 
100  G4RunManager* GetRunManager() { return fRunManager; }
101 
102  protected:
103 
104  void SetPhysicsList(std::string physicsList);
105 
106  // These variables are "protected" rather than private, because I
107  // can forsee that it may be desirable to derive other simulation
108  // routines from this one.
109  std::string fG4MacroPath; ///< Full directory path for Geant4 macro file
110  ///< to be executed before main MC processing.
111  std::string fG4PhysListName; ///< Name of physics list to use
112  std::string fGDMLFile; ///< Name of the gdml file containing the detector Geometry
113  bool fCheckOverlaps; ///< Have G4GDML check for overlaps?
114  bool fValidateGDMLSchema; ///< Have G4GDML validate geometry schema?
115  bool fUseStepLimits; ///< Set in SetVolumeStepLimit
116 
117  G4RunManager* fRunManager; ///< Geant4's run manager.
118  G4UImanager* fUIManager; ///< Geant4's user-interface manager.
119  ConvertMCTruthToG4* fConvertMCTruth; ///< Converts MCTruth objects;
120  ///< Geant4 event generator.
121  DetectorConstruction* fDetector; ///< DetectorConstruction object
122  std::vector<G4VUserParallelWorld*> fParallelWorlds; ///< list of parallel worlds
123  };
124 
125 } // namespace g4b
126 
127 #ifndef __GCCXML__
128 inline void g4b::G4Helper::SetOverlapCheck(bool check) { fCheckOverlaps = check; }
129 inline void g4b::G4Helper::SetValidateGDMLSchema(bool validate) { fValidateGDMLSchema = validate; }
130 #endif
131 
132 
133 #endif // G4BASE_G4HELPER_H
bool fValidateGDMLSchema
Have G4GDML validate geometry schema?
Definition: G4Helper.h:114
std::string string
Definition: nybbler.cc:12
std::vector< G4VUserParallelWorld * > fParallelWorlds
list of parallel worlds
Definition: G4Helper.h:122
void SetValidateGDMLSchema(bool validate)
Definition: G4Helper.h:129
G4RunManager * GetRunManager()
Definition: G4Helper.h:100
bool check(const std::vector< std::vector< float > > &outputs)
void SetOverlapCheck(bool check)
Definition: G4Helper.h:128
std::string fGDMLFile
Name of the gdml file containing the detector Geometry.
Definition: G4Helper.h:112
bool fCheckOverlaps
Have G4GDML check for overlaps?
Definition: G4Helper.h:113
basic interface to Geant4 for ART-based software
std::string fG4MacroPath
to be executed before main MC processing.
Definition: G4Helper.h:109
Base utilities and modules for event generation and detector simulation.
def validate(nxgraph, desc)
Definition: graph.py:45
DetectorConstruction * fDetector
DetectorConstruction object.
Definition: G4Helper.h:121
G4RunManager * fRunManager
Geant4&#39;s run manager.
Definition: G4Helper.h:117
std::string fG4PhysListName
Name of physics list to use.
Definition: G4Helper.h:111
Event generator information.
Definition: MCTruth.h:32
bool fUseStepLimits
Set in SetVolumeStepLimit.
Definition: G4Helper.h:115
ConvertMCTruthToG4 * fConvertMCTruth
Geant4 event generator.
Definition: G4Helper.h:119
G4UImanager * fUIManager
Geant4&#39;s user-interface manager.
Definition: G4Helper.h:118