LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
myParticleGunAction.cc
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. // [GeV]]
25 // Position: [ 0, 0, -130. ] // [cm]
26 // }
27 // . ..
28 // }
29 // }
30 // Author: Hans Wenzel (Fermilab)
31 //=============================================================================
32 
33 // art includes
34 #include "fhiclcpp/ParameterSet.h"
36 
37 // artg4tk includes
39 
40 // Geant4 includes
41 #include "Geant4/G4ParticleTable.hh"
42 
44  : PrimaryGeneratorActionBase(p.get<std::string>("name", "myParticleGunAction"))
45  , nparticle_(p.get<G4int>("NParticle"))
46  , particleName_(p.get<std::string>("Name"))
47  , momentumDirection_(p.get<std::vector<double>>("Direction"))
48  , energy_(p.get<double>("Energy"))
49  , position_(p.get<std::vector<double>>("Position"))
50 {}
51 
52 void
54 {
55  mf::LogInfo("myParticleGunAction") << "Initializing particle gun.";
56  auto particleGun = std::make_unique<G4ParticleGun>(nparticle_);
57  particleGun->SetParticleDefinition(
58  G4ParticleTable::GetParticleTable()->FindParticle(particleName_));
59  particleGun->SetParticleMomentumDirection(
60  G4ThreeVector(momentumDirection_[0], momentumDirection_[1], momentumDirection_[2]));
61  particleGun->SetParticleEnergy(energy_ * CLHEP::GeV);
62  particleGun->SetParticlePosition(
63  G4ThreeVector(position_[0] * CLHEP::cm, position_[1] * CLHEP::cm, position_[2] * CLHEP::cm));
64  particleGun_ = move(particleGun);
65 }
66 
67 // Create a primary particle for an event!
68 // (Standard Art G4 simulation)
69 
70 void
72 {
73  particleGun_->GeneratePrimaryVertex(anEvent);
74 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
STL namespace.
std::unique_ptr< G4ParticleGun > particleGun_
void generatePrimaries(G4Event *anEvent) override
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
myParticleGunActionService(fhicl::ParameterSet const &)