gparticle
Loading...
Searching...
No Matches
gparticle.h
Go to the documentation of this file.
1#pragma once
2
9
14
20
26
27// gemc
28#include <gemc/glogging/glogger.h>
29#include <gemc/guts/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
63
89{
90public:
125 Gparticle(const std::string& name,
126 int multiplicity,
127 double p,
128 double delta_p,
129 const std::string& randomMomentumModel,
130 double theta,
131 double delta_theta,
132 const std::string& thetaModel,
133 double phi,
134 double delta_phi,
135 double avx,
136 double avy,
137 double avz,
138 double adelta_vx,
139 double adelta_vy,
140 double adelta_vz,
141 const std::string& randomVertexModel,
142 const std::shared_ptr<GLogger>& logger,
143 int generator_type = 1);
144
150 Gparticle(const Gparticle&) = delete;
151
155 Gparticle& operator=(const Gparticle&) = delete;
156
160 ~Gparticle() { log->debug(DESTRUCTOR, "Gparticle"); }
161
181 [[nodiscard]] std::vector<GparticleRuntimeRecord> shootParticle(G4ParticleGun* particleGun,
182 G4Event* anEvent) const;
183
196 static std::shared_ptr<Gparticle> create_default_gparticle(const std::shared_ptr<GLogger>& log) {
197 return std::make_shared<Gparticle>(
198 "e-",
199 1,
201 0,
202 "uniform",
203 0,
204 0,
205 "uniform",
206 0,
207 0,
208 0,
209 0,
210 0,
211 0,
212 0,
213 0,
214 "uniform",
215 log
216 );
217 }
218
224 [[nodiscard]] const std::string& getName() const { return name; }
225
231 [[nodiscard]] int getPid() const { return pid; }
232
238 [[nodiscard]] int getMultiplicity() const { return multiplicity; }
239
245 [[nodiscard]] double getMomentum() const { return p; }
246
252 [[nodiscard]] double getTheta() const { return theta; }
253
259 [[nodiscard]] double getPhi() const { return phi; }
260
266 [[nodiscard]] const G4ThreeVector& getVertex() const { return v; }
267
269 [[nodiscard]] double getDeltaMomentum() const { return delta_p; }
270
272 [[nodiscard]] std::string getMomentumModel() const {
273 return gutilities::to_string(randomMomentumModel);
274 }
275
277 [[nodiscard]] double getDeltaTheta() const { return delta_theta; }
278
280 [[nodiscard]] std::string getThetaModel() const {
281 return gutilities::to_string(randomThetaModel);
282 }
283
285 [[nodiscard]] double getDeltaPhi() const { return delta_phi; }
286
288 [[nodiscard]] const G4ThreeVector& getDeltaVertex() const { return delta_v; }
289
291 [[nodiscard]] std::string getVertexModel() const {
292 return gutilities::to_string(randomVertexModel);
293 }
294
305 [[nodiscard]] int getGeneratorType() const { return generator_type; }
306
307 // ---- Setters (used by the GUI to reflect user edits in real time) ----
308 void setName(const std::string& n) { name = n; pid = get_pdg_id(); }
309 void setMultiplicity(int m) { multiplicity = m; }
310 void setMomentum(double p_mev) { p = p_mev; }
311 void setDeltaMomentum(double dp) { delta_p = dp; }
312 void setMomentumModel(const std::string& s) { randomMomentumModel = gutilities::stringToRandomModel(s); }
313 void setTheta(double t_rad) { theta = t_rad; }
314 void setDeltaTheta(double dt) { delta_theta = dt; }
315 void setThetaModel(const std::string& s) { randomThetaModel = gutilities::stringToRandomModel(s); }
316 void setPhi(double ph_rad) { phi = ph_rad; }
317 void setDeltaPhi(double dp) { delta_phi = dp; }
318 void setVertexX(double x) { v.setX(x); }
319 void setVertexY(double y) { v.setY(y); }
320 void setVertexZ(double z) { v.setZ(z); }
321 void setDeltaVertexX(double x) { delta_v.setX(x); }
322 void setDeltaVertexY(double y) { delta_v.setY(y); }
323 void setDeltaVertexZ(double z) { delta_v.setZ(z); }
324 void setVertexModel(const std::string& s) { randomVertexModel = gutilities::stringToRandomModel(s); }
325
326private:
328 std::string name;
329
331 int generator_type;
332
334 int pid;
335
337 int multiplicity;
338
340 double p;
341
343 double delta_p;
344
346 gutilities::randomModel randomMomentumModel;
347
349 double theta;
350
352 double delta_theta;
353
355 gutilities::randomModel randomThetaModel;
356
358 double phi;
359
361 double delta_phi;
362
364 G4ThreeVector v;
365
367 G4ThreeVector delta_v;
368
370 gutilities::randomModel randomVertexModel;
371
373 std::shared_ptr<GLogger> log;
374
376 [[nodiscard]] double get_mass() const;
377
379 friend std::ostream& operator<<(std::ostream& os, const Gparticle& gp);
380
388 friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<Gparticle>& ptr) {
389 if (ptr) return os << *ptr;
390 else return os << "<null Gparticle>";
391 }
392
401 [[nodiscard]] double randomizeNumberFromSigmaWithModel(double center,
402 double delta,
403 gutilities::randomModel model) const;
404
406 [[nodiscard]] double calculateMomentum() const;
407
413 [[nodiscard]] double calculateKinEnergy(double mass) const;
414
416 [[nodiscard]] G4ThreeVector calculateBeamDirection(double thetaRad, double phiRad) const;
417
419 [[nodiscard]] G4ThreeVector calculateVertex() const;
420
422 int get_pdg_id();
423
424};
425
431using GparticlePtr = std::shared_ptr<Gparticle>;
Lightweight particle specification and primary vertex shooter.
Definition gparticle.h:89
double getDeltaPhi() const
Returns the azimuthal-angle spread parameter (GEMC internal units, radians).
Definition gparticle.h:285
const G4ThreeVector & getDeltaVertex() const
Returns the vertex spread vector (GEMC internal units, mm).
Definition gparticle.h:288
void setDeltaMomentum(double dp)
Definition gparticle.h:311
void setVertexX(double x)
Definition gparticle.h:318
const std::string & getName() const
Returns the particle name stored in this generator definition.
Definition gparticle.h:224
std::string getMomentumModel() const
Returns the momentum randomization model as a string token.
Definition gparticle.h:272
int getPid() const
Returns the resolved PDG particle id.
Definition gparticle.h:231
int getMultiplicity() const
Returns how many copies are generated per event.
Definition gparticle.h:238
friend std::ostream & operator<<(std::ostream &os, const Gparticle &gp)
Stream insertion operator used for pretty-printing configuration summaries.
Definition gparticle.cc:237
void setVertexY(double y)
Definition gparticle.h:319
double getPhi() const
Returns the nominal azimuthal angle.
Definition gparticle.h:259
Gparticle(const Gparticle &)=delete
Copying is disabled.
std::vector< GparticleRuntimeRecord > shootParticle(G4ParticleGun *particleGun, G4Event *anEvent) const
Shoots this particle configuration into a Geant4 event.
Definition gparticle.cc:60
void setName(const std::string &n)
Definition gparticle.h:308
double getMomentum() const
Returns the nominal momentum magnitude.
Definition gparticle.h:245
Gparticle(const std::string &name, int multiplicity, double p, double delta_p, const std::string &randomMomentumModel, double theta, double delta_theta, const std::string &thetaModel, double phi, double delta_phi, double avx, double avy, double avz, double adelta_vx, double adelta_vy, double adelta_vz, const std::string &randomVertexModel, const std::shared_ptr< GLogger > &logger, int generator_type=1)
Constructs a particle configuration from pre-converted G4-unit values.
Definition gparticle.cc:17
void setDeltaTheta(double dt)
Definition gparticle.h:314
int getGeneratorType() const
Returns the generator source type.
Definition gparticle.h:305
void setPhi(double ph_rad)
Definition gparticle.h:316
void setMomentum(double p_mev)
Definition gparticle.h:310
double getDeltaTheta() const
Returns the polar-angle spread parameter (GEMC internal units, radians).
Definition gparticle.h:277
void setDeltaVertexX(double x)
Definition gparticle.h:321
void setTheta(double t_rad)
Definition gparticle.h:313
void setVertexZ(double z)
Definition gparticle.h:320
void setDeltaVertexY(double y)
Definition gparticle.h:322
double getTheta() const
Returns the nominal polar angle.
Definition gparticle.h:252
void setThetaModel(const std::string &s)
Definition gparticle.h:315
friend std::ostream & operator<<(std::ostream &os, const std::shared_ptr< Gparticle > &ptr)
Stream insertion operator overload for shared pointers.
Definition gparticle.h:388
static std::shared_ptr< Gparticle > create_default_gparticle(const std::shared_ptr< GLogger > &log)
Creates a minimal default particle configuration.
Definition gparticle.h:196
~Gparticle()
Destructor emits a debug-level lifecycle message.
Definition gparticle.h:160
void setMomentumModel(const std::string &s)
Definition gparticle.h:312
const G4ThreeVector & getVertex() const
Returns the nominal vertex position.
Definition gparticle.h:266
double getDeltaMomentum() const
Returns the momentum spread parameter (GEMC internal units, MeV).
Definition gparticle.h:269
void setVertexModel(const std::string &s)
Definition gparticle.h:324
Gparticle & operator=(const Gparticle &)=delete
Copy assignment is disabled.
void setMultiplicity(int m)
Definition gparticle.h:309
std::string getVertexModel() const
Returns the vertex randomization model as a string token.
Definition gparticle.h:291
void setDeltaPhi(double dp)
Definition gparticle.h:317
void setDeltaVertexZ(double z)
Definition gparticle.h:323
std::string getThetaModel() const
Returns the theta randomization model as a string token.
Definition gparticle.h:280
DESTRUCTOR
std::shared_ptr< Gparticle > GparticlePtr
Shared pointer type used for Gparticle instances.
Definition gparticle.h:431
double getG4Number(const string &v, bool warnIfNotUnit=false)
randomModel stringToRandomModel(const std::string &str)
constexpr const char * to_string(randomModel m) noexcept
Runtime values for one generated primary particle.
Definition gparticle.h:46
G4ThreeVector vertex
Definition gparticle.h:53