All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCTruthEventAction_service.h
Go to the documentation of this file.
1 // MCTruthEventAction is the service that injects particles into
2 // the simulation.
3 // To use this action, all you need to do is put it in the services section
4 // of the configuration file, like this:
5 //
6 // services: {
7 // ...
8 // MCTruthEventAction: {}
9 // ...
10 // }
11 // Expected parameters:
12 // - name (string): A name describing the action service.
13 // Default is 'exampleParticleGun'
14 
15 // Include guard
16 #ifndef MCTRUTHEVENTACTION_SERVICE_HH
17 #define MCTRUTHEVENTACTION_SERVICE_HH
18 
19 #include "artg4tk/actionBase/PrimaryGeneratorActionBase.hh"
20 
21 #include "nusimdata/SimulationBase/MCTruth.h"
22 
23 #include "art/Framework/Principal/Handle.h"
24 #include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"
25 
26 namespace fhicl {
27  class ParameterSet;
28 }
29 
30 #include "Geant4/G4Types.hh"
31 
32 class G4Event;
33 class G4ParticleTable;
34 
35 #include <map>
36 #include <vector>
37 
38 namespace larg4 {
39 
40  class MCTruthEventActionService : public artg4tk::PrimaryGeneratorActionBase {
41  public:
42  MCTruthEventActionService(fhicl::ParameterSet const&);
44 
45  void
46  setInputCollections(std::vector<art::Handle<std::vector<simb::MCTruth>>> const& mclists)
47  {
48  fMCLists = &mclists;
49  }
50 
51  private:
52  // To generate primaries, we need to overload the GeneratePrimaries
53  // method.
54 
55  void generatePrimaries(G4Event* anEvent) override;
56 
57  static G4ParticleTable* fParticleTable; ///< Geant4's table of particle definitions.
58  std::vector<art::Handle<std::vector<simb::MCTruth>>> const*
59  fMCLists; ///< MCTruthCollection input lists
60  std::map<G4int, G4int> fUnknownPDG; ///< map of unknown PDG codes to instances
61  std::map<G4int, G4int> fNon1StatusPDG; ///< PDG codes skipped because not status 1
62  std::map<G4int, G4int> fProcessedPDG; ///< PDG codes processed
63  };
64 } //namespace larg4
65 
66 DECLARE_ART_SERVICE(larg4::MCTruthEventActionService, LEGACY)
67 
68 #endif // MCTRUTHEVENTACTION_SERVICE_HH
static G4ParticleTable * fParticleTable
Geant4&#39;s table of particle definitions.
std::vector< art::Handle< std::vector< simb::MCTruth > > > const * fMCLists
MCTruthCollection input lists.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void setInputCollections(std::vector< art::Handle< std::vector< simb::MCTruth >>> const &mclists)
void generatePrimaries(G4Event *anEvent) override
std::map< G4int, G4int > fProcessedPDG
PDG codes processed.
std::map< G4int, G4int > fNon1StatusPDG
PDG codes skipped because not status 1.
std::map< G4int, G4int > fUnknownPDG
map of unknown PDG codes to instances
MCTruthEventActionService(fhicl::ParameterSet const &)