LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PrimaryEventAction.cc
Go to the documentation of this file.
2 
7 
11 
12 // Geant4 includes
13 #include "Geant4/G4Event.hh"
14 
15 #include <iostream>
16 
18  : PrimaryGeneratorActionBase(p.get<std::string>("name", "PrimaryEventActionService"))
19 {}
20 
21 // Create a primary particle for an event!
22 // (Standard Art G4 simulation)
23 void
25 {
27  auto const allGens = e.getMany<GenParticleCollection>();
28  std::cout << "Primary:: GenParticles*******************Size: " << allGens.size() << '\n';
29  for (auto const& h : allGens) {
30  GenParticleCollection const& gens = *h;
31  std::cout << "Primary:: GenParticlesCollection*******************Size: " << gens.size() << '\n';
32  for (GenParticle const& genpart : gens) {
33  std::cout << " genpart.pdgId(): " << genpart.pdgId()
34  << "\n position: " << genpart.position() << "\nmomentum: " << genpart.momentum()
35  << "\nenergy: " << genpart.momentum().e() << '\n';
36  addG4Particle(anEvent,
37  genpart.pdgId(),
38  genpart.position(),
39  0.0,
40  genpart.momentum().e(),
41  genpart.momentum());
42  }
43  }
44 }
45 
46 void
48  int const pdgId,
49  G4ThreeVector const& pos,
50  double const time,
51  double const energy,
52  G4ThreeVector const& mom)
53 {
54  auto vertex = new G4PrimaryVertex{pos, time};
55  vertex->SetPrimary(new G4PrimaryParticle{pdgId, mom.x(), mom.y(), mom.z(), energy});
56  event->AddPrimaryVertex(vertex);
57 }
PrimaryEventActionService(fhicl::ParameterSet const &)
void generatePrimaries(G4Event *anEvent) override
STL namespace.
std::vector< GenParticle > GenParticleCollection
double energy
Definition: plottest35.C:25
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Float_t e
Definition: plot.C:35
void addG4Particle(G4Event *event, int pdgId, const G4ThreeVector &pos, double time, double energy, const G4ThreeVector &mom)
Event finding and building.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
vertex reconstruction