gparticle
Loading...
Searching...
No Matches
gparticle_reader.h
Go to the documentation of this file.
1#pragma once
2
3// gparticle
4#include "gparticle.h"
5
6// gemc
7#include "gbase.h"
8#include "gdl.h"
9#include "goptions.h"
10
11// c++
12#include <memory>
13#include <string>
14#include <utility>
15#include <vector>
16
24using GParticleEvent = std::vector<GparticlePtr>;
25
33using GParticleEvents = std::vector<GParticleEvent>;
34
49{
51 std::string name;
52
54 int pid = 0;
55
57 int type = 1;
58
60 int multiplicity = 1;
61
63 double p = 0;
64
66 double theta = 0;
67
69 double phi = 0;
70
72 double vx = 0;
73
75 double vy = 0;
76
78 double vz = 0;
79};
80
84using GParticleRecordEvent = std::vector<GParticleRecord>;
85
89using GParticleRecordEvents = std::vector<GParticleRecordEvent>;
90
99{
102
109 GParticleSourceDefinition(std::string f, std::string n)
110 : format(std::move(f)), filename(std::move(n)) {
111 }
112
114 std::string format;
115
117 std::string filename;
118
124 [[nodiscard]] std::string gparticlePluginName() const { return "gparticle_" + format + "_plugin"; }
125};
126
138class GParticleReader : public GBase<GParticleReader>
139{
140public:
146 explicit GParticleReader(const std::shared_ptr<GOptions>& gopts);
147
149 ~GParticleReader() override = default;
150
161 virtual std::vector<GparticlePtr> loadParticles(const GParticleSourceDefinition& source,
162 const std::shared_ptr<GLogger>& logger) = 0;
163
179 const std::shared_ptr<GLogger>& logger,
180 bool propagated_only = true);
181
194 const std::shared_ptr<GLogger>& logger);
195
197 void set_loggers([[maybe_unused]] const std::shared_ptr<GOptions>& gopts) {
198 }
199
209 static GParticleReader* instantiate(dlhandle h, std::shared_ptr<GOptions> gopts);
210};
211
212namespace gparticle {
219std::vector<GParticleSourceDefinition> getGParticleSourceDefinitions(const std::shared_ptr<GOptions>& gopts);
220
228std::vector<GparticlePtr> getGParticlesFromSources(const std::shared_ptr<GOptions>& gopts,
229 std::shared_ptr<GLogger>& logger);
230
239GParticleEvents getGParticleEventsFromSources(const std::shared_ptr<GOptions>& gopts,
240 std::shared_ptr<GLogger>& logger,
241 bool propagated_only = true);
242
253GParticleRecordEvents getGParticleRecordEventsFromSources(const std::shared_ptr<GOptions>& gopts,
254 std::shared_ptr<GLogger>& logger);
255
261const std::vector<std::string>& supported_static_reader_formats();
262}
Abstract base class for gparticle file readers.
~GParticleReader() override=default
Virtual destructor for plugin use through base pointers.
virtual GParticleRecordEvents loadParticleRecordEvents(const GParticleSourceDefinition &source, const std::shared_ptr< GLogger > &logger)
Loads file-backed events as output-bank records.
virtual GParticleEvents loadParticleEvents(const GParticleSourceDefinition &source, const std::shared_ptr< GLogger > &logger, bool propagated_only=true)
Loads file-backed events as Gparticle objects.
virtual std::vector< GparticlePtr > loadParticles(const GParticleSourceDefinition &source, const std::shared_ptr< GLogger > &logger)=0
Loads all propagated particles as one flattened list.
GParticleReader(const std::shared_ptr< GOptions > &gopts)
Constructs a reader with the shared options container.
void set_loggers(const std::shared_ptr< GOptions > &gopts)
Reader plugins currently share the base logger setup.
static GParticleReader * instantiate(dlhandle h, std::shared_ptr< GOptions > gopts)
Instantiates a dynamic reader plugin from a library handle.
void * dlhandle
Definition of the Gparticle class used by the gparticle module.
std::vector< GParticleEvent > GParticleEvents
Sequence of file-backed generated-particle events.
std::vector< GparticlePtr > GParticleEvent
Event-local list of Geant4-propagated generator particles.
std::vector< GParticleRecordEvent > GParticleRecordEvents
Sequence of generated-particle record events indexed by event number.
std::vector< GParticleRecord > GParticleRecordEvent
Event-local list of generated-particle records for output.
const std::vector< std::string > & supported_static_reader_formats()
Returns built-in file-reader format tokens.
std::vector< GparticlePtr > getGParticlesFromSources(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger)
Loads propagated particles from all configured file sources.
GParticleRecordEvents getGParticleRecordEventsFromSources(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger)
Loads event-indexed generated-particle records from all configured file sources.
GParticleEvents getGParticleEventsFromSources(const std::shared_ptr< GOptions > &gopts, std::shared_ptr< GLogger > &logger, bool propagated_only)
Loads event-indexed propagated particles from all configured file sources.
std::vector< GParticleSourceDefinition > getGParticleSourceDefinitions(const std::shared_ptr< GOptions > &gopts)
Parses all configured -gparticlefile entries.
Immutable generated-particle metadata used for output banks.
double phi
Azimuthal angle in GEMC internal angular units.
int type
Source generator type. Lund type == 1 means propagated in Geant4.
double p
Momentum magnitude in GEMC internal units.
double vy
Vertex y coordinate in GEMC internal length units.
int pid
PDG id or source particle id.
double vx
Vertex x coordinate in GEMC internal length units.
std::string name
Particle name when known, otherwise a source-format identifier such as the numeric pid.
double theta
Polar angle in GEMC internal angular units.
int multiplicity
Number of copies represented by this record.
double vz
Vertex z coordinate in GEMC internal length units.
One configured -gparticlefile source.
GParticleSourceDefinition()=default
Creates an empty source definition.
std::string gparticlePluginName() const
Returns the dynamic plugin name associated with this format.
std::string filename
Source filename.
GParticleSourceDefinition(std::string f, std::string n)
Creates a source definition from a format token and filename.
std::string format
Source format token, for example lund.