actions
Loading...
Searching...
No Matches
generator_file_events_example.cc
Go to the documentation of this file.
1// actions
3
4// gparticle
5#include "gparticle_reader.h"
6
7// geant4
8#include "G4Event.hh"
9#include "G4RunManagerFactory.hh"
10#include "QBBC.hh"
11
12// c++
13#include <cstdlib>
14#include <iostream>
15#include <memory>
16
17int main(int argc, char* argv[]) {
18 auto option_definitions = gparticle::defineOptions();
19 option_definitions += gprimaryaction::defineOptions();
20
21 auto gopts = std::make_shared<GOptions>(argc, argv, option_definitions);
22 auto log = std::make_shared<GLogger>(gopts, FUNCTION_NAME, GPRIMARYGENERATORACTION_LOGGER);
23
24 auto runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
25 runManager->SetUserInitialization(new QBBC);
26
27 auto source_events = gparticle::getGParticleEventsFromSources(gopts, log);
28 if (source_events.size() != 11) {
29 std::cerr << "Expected 11 gparticlefile events, got " << source_events.size() << '\n';
30 delete runManager;
31 return EXIT_FAILURE;
32 }
33
34 GPrimaryGeneratorAction generator(gopts);
35 auto inline_particles = gparticle::getGParticlesFromOption(gopts, log);
36 for (size_t event_index = 0; event_index < source_events.size(); event_index++) {
37 G4Event event(static_cast<G4int>(event_index));
38 generator.GeneratePrimaries(&event);
39
40 const auto expected_vertices = static_cast<G4int>(inline_particles.size() + source_events[event_index].size());
41 if (event.GetNumberOfPrimaryVertex() != expected_vertices) {
42 std::cerr << "Event " << event_index << " expected " << expected_vertices
43 << " primary vertices, got " << event.GetNumberOfPrimaryVertex() << '\n';
44 delete runManager;
45 return EXIT_FAILURE;
46 }
47 }
48
49 delete runManager;
50 return EXIT_SUCCESS;
51}
Generates the primary vertices for each Geant4 event.
void GeneratePrimaries(G4Event *event) override
Generates the primary content for one event.
Declares GPrimaryGeneratorAction, the primary-particle generation action for the GEMC actions module.
constexpr const char * GPRIMARYGENERATORACTION_LOGGER
event
#define FUNCTION_NAME
vector< GparticlePtr > getGParticlesFromOption(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger)
GOptions defineOptions()
GParticleEvents getGParticleEventsFromSources(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger, bool propagated_only=true)
GOptions defineOptions()
Returns the options associated with the primary-generator action scope.
int main(int argc, char *argv[])