LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
myParticleGunAction_service.hh
Go to the documentation of this file.
1 //
2 // __ __ __ __ __
3 // ____ ______/ /_____ _/ // / / /_/ /__
4 // / __ `/ ___/ __/ __ `/ // /_/ __/ //_/
5 // / /_/ / / / /_/ /_/ /__ __/ /_/ ,<
6 // \__,_/_/ \__/\__, / /_/ \__/_/|_|
7 // /____/
8 //
9 // artg4tk: art based Geant 4 Toolkit
10 //
11 //=============================================================================
12 // ParticleGunActionService.hh: art wrapper for G4ParticleGun
13 // To use this, all you need to do is put it in the services section
14 // of the configuration file, like this:
15 //
16 // services: {
17 // ...
18 // user: {
19 // myParticleGunAction: {
20 // name: "myParticleGun"
21 // NParticle: 1
22 // Name: "proton"
23 // Direction: [ 0, 0, 1 ]
24 // Energy: 10.
25 // Position: [ 0, 0, -130. ]
26 // }
27 // . ..
28 // }
29 // }
30 // Author: Hans Wenzel (Fermilab)
31 //=============================================================================
32 
33 #ifndef artg4tk_pluginActions_myparticleGun_myParticleGunAction_service_hh
34 #define artg4tk_pluginActions_myparticleGun_myParticleGunAction_service_hh
35 
36 // art Includes:
38 #include "fhiclcpp/fwd.h"
39 
40 // artg4tk includes
42 
43 // Geant 4 includes
44 #include "Geant4/G4ParticleGun.hh"
45 class G4Event;
46 
47 #include <string>
48 
49 namespace artg4tk {
50 
52  public:
54 
55  void initialize() override;
56 
57  // To generate primaries, we need to overload the GeneratePrimaries
58  // method.
59  void generatePrimaries(G4Event* anEvent) override;
60 
61  G4ParticleGun const*
62  GetGun() const
63  {
64  return particleGun_.get();
65  };
66 
67  private:
68  std::unique_ptr<G4ParticleGun> particleGun_{nullptr};
69  G4int nparticle_;
70  std::string particleName_;
71  std::vector<double> momentumDirection_;
72  double energy_;
73  std::vector<double> position_;
74  };
75 } // namespace artg4tk
76 
78 
79 #endif /* artg4tk_pluginActions_myparticleGun_myParticleGunAction_service_hh */
std::unique_ptr< G4ParticleGun > particleGun_
void generatePrimaries(G4Event *anEvent) override
#define DECLARE_ART_SERVICE(svc, scope)
myParticleGunActionService(fhicl::ParameterSet const &)