gparticle
Loading...
Searching...
No Matches
gparticle.h
Go to the documentation of this file.
1#pragma once
2
27// gemc
28#include "glogger.h"
29#include "gutilities.h"
30
31// geant4
32#include "G4ThreeVector.hh"
33#include "G4ParticleGun.hh"
34
35// c++
36#include <string>
37#include <vector>
38
46{
47 std::string name;
48 int pid = 0;
49 int type = 1;
50 double p = 0;
51 double theta = 0;
52 double phi = 0;
53 G4ThreeVector vertex;
54};
55
56
89{
90public:
127 Gparticle(const std::string& name,
128 int multiplicity,
129 double p,
130 double delta_p,
131 const std::string& punit,
132 const std::string& randomMomentumModel,
133 double theta,
134 double delta_theta,
135 const std::string& thetaModel,
136 double phi,
137 double delta_phi,
138 const std::string& aunit,
139 double avx,
140 double avy,
141 double avz,
142 double adelta_vx,
143 double adelta_vy,
144 double adelta_vz,
145 const std::string& vunit,
146 const std::string& randomVertexModel,
147 const std::shared_ptr<GLogger>& logger,
148 int generator_type = 1);
149
155 Gparticle(const Gparticle&) = delete;
156
160 Gparticle& operator=(const Gparticle&) = delete;
161
165 ~Gparticle() { log->debug(DESTRUCTOR, "Gparticle"); }
166
185 void shootParticle(G4ParticleGun* particleGun, G4Event* anEvent);
186
199 static std::shared_ptr<Gparticle> create_default_gparticle(const std::shared_ptr<GLogger>& log) {
200 return std::make_shared<Gparticle>(
201 "e-",
202 1,
203 1,
204 0,
205 "GeV",
206 "uniform",
207 0,
208 0,
209 "uniform",
210 0,
211 0,
212 "deg",
213 0,
214 0,
215 0,
216 0,
217 0,
218 0,
219 "cm",
220 "uniform",
221 log
222 );
223 }
224
230 [[nodiscard]] const std::string& getName() const { return name; }
231
237 [[nodiscard]] int getPid() const { return pid; }
238
244 [[nodiscard]] int getMultiplicity() const { return multiplicity; }
245
251 [[nodiscard]] double getMomentum() const { return p; }
252
258 [[nodiscard]] double getTheta() const { return theta; }
259
265 [[nodiscard]] double getPhi() const { return phi; }
266
272 [[nodiscard]] const G4ThreeVector& getVertex() const { return v; }
273
284 [[nodiscard]] int getGeneratorType() const { return generator_type; }
285
292 [[nodiscard]] const std::vector<GparticleRuntimeRecord>& getRuntimeRecords() const {
293 return runtimeRecords;
294 }
295
296private:
298 std::string name;
299
301 int generator_type;
302
304 int pid;
305
307 int multiplicity;
308
310 double p;
311
313 double delta_p;
314
316 gutilities::randomModel randomMomentumModel;
317
319 double theta;
320
322 double delta_theta;
323
325 gutilities::randomModel randomThetaModel;
326
328 double phi;
329
331 double delta_phi;
332
334 G4ThreeVector v;
335
337 G4ThreeVector delta_v;
338
340 gutilities::randomModel randomVertexModel;
341
343 std::shared_ptr<GLogger> log;
344
346 std::vector<GparticleRuntimeRecord> runtimeRecords;
347
349 [[nodiscard]] double get_mass() const;
350
352 friend std::ostream& operator<<(std::ostream& os, const Gparticle& gp);
353
361 friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<Gparticle>& ptr) {
362 if (ptr) return os << *ptr;
363 else return os << "<null Gparticle>";
364 }
365
374 [[nodiscard]] double randomizeNumberFromSigmaWithModel(double center,
375 double delta,
376 gutilities::randomModel model) const;
377
379 double calculateMomentum();
380
386 double calculateKinEnergy(double mass);
387
389 G4ThreeVector calculateBeamDirection(double thetaRad, double phiRad);
390
392 G4ThreeVector calculateVertex();
393
395 int get_pdg_id();
396
397
398 // assigned at shootParticle for each multiplicity
399 double kinenergy;
400 G4ThreeVector beamDirection;
401 G4ThreeVector vertex;
402
403 void setRunTimeQuantities(double ke, G4ThreeVector bd, G4ThreeVector v) {
404 kinenergy = ke;
405 beamDirection = bd;
406 vertex = v;
407 }
408};
409
415using GparticlePtr = std::shared_ptr<Gparticle>;
void debug(debug_type type, Args &&... args) const
Lightweight particle specification and primary vertex shooter.
Definition gparticle.h:89
void shootParticle(G4ParticleGun *particleGun, G4Event *anEvent)
Shoots this particle configuration into a Geant4 event.
Definition gparticle.cc:77
const std::string & getName() const
Returns the particle name stored in this generator definition.
Definition gparticle.h:230
int getPid() const
Returns the resolved PDG particle id.
Definition gparticle.h:237
int getMultiplicity() const
Returns how many copies are generated per event.
Definition gparticle.h:244
friend std::ostream & operator<<(std::ostream &os, const Gparticle &gp)
Stream insertion operator used for pretty-printing configuration summaries.
Definition gparticle.cc:247
double getPhi() const
Returns the nominal azimuthal angle.
Definition gparticle.h:265
Gparticle(const Gparticle &)=delete
Copying is disabled.
double getMomentum() const
Returns the nominal momentum magnitude.
Definition gparticle.h:251
int getGeneratorType() const
Returns the generator source type.
Definition gparticle.h:284
double getTheta() const
Returns the nominal polar angle.
Definition gparticle.h:258
const std::vector< GparticleRuntimeRecord > & getRuntimeRecords() const
Returns the runtime records from the most recent shoot.
Definition gparticle.h:292
friend std::ostream & operator<<(std::ostream &os, const std::shared_ptr< Gparticle > &ptr)
Stream insertion operator overload for shared pointers.
Definition gparticle.h:361
static std::shared_ptr< Gparticle > create_default_gparticle(const std::shared_ptr< GLogger > &log)
Creates a minimal default particle configuration.
Definition gparticle.h:199
~Gparticle()
Destructor emits a debug-level lifecycle message.
Definition gparticle.h:165
const G4ThreeVector & getVertex() const
Returns the nominal vertex position.
Definition gparticle.h:272
Gparticle(const std::string &name, int multiplicity, double p, double delta_p, const std::string &punit, const std::string &randomMomentumModel, double theta, double delta_theta, const std::string &thetaModel, double phi, double delta_phi, const std::string &aunit, double avx, double avy, double avz, double adelta_vx, double adelta_vy, double adelta_vz, const std::string &vunit, const std::string &randomVertexModel, const std::shared_ptr< GLogger > &logger, int generator_type=1)
Constructs a particle configuration from user-facing parameters.
Definition gparticle.cc:22
Gparticle & operator=(const Gparticle &)=delete
Copy assignment is disabled.
DESTRUCTOR
std::shared_ptr< Gparticle > GparticlePtr
Shared pointer type used for Gparticle instances.
Definition gparticle.h:415
Runtime values for one generated primary particle.
Definition gparticle.h:46
G4ThreeVector vertex
Definition gparticle.h:53