FairShip
Loading...
Searching...
No Matches
ParticleGunGenerator.h
Go to the documentation of this file.
1#ifndef SHIPGEN_PARTICLEGUNGENERATOR_H_
2#define SHIPGEN_PARTICLEGUNGENERATOR_H_
3
4#include <Rtypes.h> // for Double32_t, Bool_t, kTRUE, etc
5
6#include "Generator.h"
7#include "TH1.h"
8#include "TRandom.h"
9
10class FairPrimaryGenerator;
12 Double32_t X{0}, Y{0}, Z{0};
13 Double32_t Px{0}, Py{0}, Pz{0};
14};
15
16struct ModelSpec {
18 const char* description;
19 std::function<void(ParticleGunParticle&, const std::vector<Double32_t>&)>
21};
22
24 public:
27
32 explicit ParticleGunGenerator(Int_t pdgid, Int_t mult = 1);
33
36
38
39 void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10) {
40 fPMin = pmin;
41 fPMax = pmax;
42 fPRangeIsSet = kTRUE;
43 }
44
45 void SetPtRange(Double32_t ptmin = 0, Double32_t ptmax = 10) {
46 fPtMin = ptmin;
47 fPtMax = ptmax;
48 fPtRangeIsSet = kTRUE;
49 }
50
51 void SetEkinRange(Double32_t kmin = 0, Double32_t kmax = 10) {
52 fEkinMin = kmin;
53 fEkinMax = kmax;
54 fEkinRangeIsSet = kTRUE;
55 }
56
57 void SetPhiRange(Double32_t phimin = 0, Double32_t phimax = 360) {
58 fPhiMin = phimin;
59 fPhiMax = phimax;
60 }
61
62 void SetEtaRange(Double32_t etamin = -5, Double32_t etamax = 7) {
63 fEtaMin = etamin;
64 fEtaMax = etamax;
65 fEtaRangeIsSet = kTRUE;
66 }
67
68 void SetYRange(Double32_t ymin = -5, Double32_t ymax = 7) {
69 fYMin = ymin;
70 fYMax = ymax;
71 fYRangeIsSet = kTRUE;
72 }
73
74 void SetThetaRange(Double32_t thetamin = 0, Double32_t thetamax = 90) {
75 fThetaMin = thetamin;
76 fThetaMax = thetamax;
77 fThetaRangeIsSet = kTRUE;
78 }
79
80 void SetCosTheta() { fCosThetaIsSet = kTRUE; }
81
82 void SetBothCharges(bool flag, Double32_t fraction = 0.5);
83
84 void SetPDGType(int pdgid) { m_pdgid = pdgid; };
85 void SetMultiplicity(int mult) { m_mult = mult; };
87 void SetCommonVertex(bool flag) { m_commonVertex = flag; };
88 int GenPDGType() const;
89 int GetMultiplicity() { return m_mult; };
90
91 void LoadHistoFromFile(const std::string& inFile, const std::string& inHisto,
92 std::vector<std::string> varNames);
93
94 Double32_t GetPDGMass() { return fPDGMass; };
95
101 void SetDebug(Bool_t /*debug*/) {}
103
105 Bool_t Init() override;
106 Bool_t Init(const char* inFile) override { return Init(inFile, 0); };
107
108 Bool_t Init(const char* inFile, int startEvent) override {
109 LOG(warning) << "Init with files not implemented for ParticleGunGenerator. "
110 "Using default Init() instead";
111 return Init();
112 };
113
116 Bool_t ReadEvent(FairPrimaryGenerator* primGen) override;
117
119 FairGenerator* CloneGenerator() const override;
120
121 void SetVertexModel(const std::string& model, std::vector<Double32_t> pars);
122 void SetMomentumModel(const int modelNo, std::vector<Double32_t> pars);
123
124 void PrintMomentumModels();
125 void PrintVertexModels();
126
127 protected:
131
132 private:
135
138 Double32_t& GetVar(ParticleGunParticle& p, const std::string& name);
139 void SetVar(ParticleGunParticle& p, const std::string& name,
140 Double32_t value);
141
142 Double32_t fPtMin{0}, fPtMax{0}; // Transverse momentum range [GeV]
143 Double32_t fPhiMin{0}, fPhiMax{0}; // Azimuth angle range [degree]
144 Double32_t fEtaMin{0}, fEtaMax{0}; // Pseudorapidity range in lab system
145 Double32_t fYMin{0}, fYMax{0}; // Rapidity range in lab system
146 Double32_t fPMin{0}, fPMax{0}; // Momentum range in lab system
147 Double32_t fThetaMin{0},
148 fThetaMax{0}; // Polar angle range in lab system [degree]
149 Double32_t fEkinMin{0},
150 fEkinMax{0}; // Kinetic Energy range in lab system [GeV]
151 Double32_t fVx{0}, fVy{0}, fVz{0};
152 Double32_t fVex{0}, fVey{0}, fVez{0};
153 Double32_t fPDGMass{0};
154
155 bool m_bothCharges{false};
156 Double32_t m_chargeFraction{1.};
157
158 struct HistoEntry {
159 std::shared_ptr<TH1> hist;
160 int dims{0};
161 std::vector<std::string> varNames;
162 };
163 std::vector<HistoEntry> fHistoEntries;
164
165 Bool_t fEtaRangeIsSet{false}; // True if eta range is set
166 Bool_t fYRangeIsSet{false}; // True if rapidity range is set
167 Bool_t fThetaRangeIsSet{false}; // True if theta range is set
168 Bool_t fCosThetaIsSet{false}; // True if uniform distribution in
169 // cos(theta) is set (default -> not set)
170 Bool_t fPtRangeIsSet{false}; // True if transverse momentum range is set
171 Bool_t fPRangeIsSet{false}; // True if abs.momentum range is set
172 Bool_t fEkinRangeIsSet{false}; // True if kinetic energy range is set
173
175 std::string fVertexModel = "gaussian";
176 std::vector<Double32_t> fMomentumPars;
177 std::vector<Double32_t> fVertexPars;
178 int m_mult{1};
179 bool m_commonVertex{false};
180 int m_pdgid{0};
181};
182
183#endif // SHIPGEN_PARTICLEGUNGENERATOR_H_
void SetPtRange(Double32_t ptmin=0, Double32_t ptmax=10)
void OverrideFromHistogram(ParticleGunParticle &p)
~ParticleGunGenerator() override
Bool_t Init(const char *inFile, int startEvent) override
void SetVertexModel(const std::string &model, std::vector< Double32_t > pars)
std::vector< HistoEntry > fHistoEntries
Bool_t ReadEvent(FairPrimaryGenerator *primGen) override
ParticleGunGenerator(const ParticleGunGenerator &)=default
void GenVertexModel(ParticleGunParticle &p)
void GenMomentumModel(ParticleGunParticle &p)
void SetCommonVertex(bool flag)
Give all particles of an event the same vertex, drawn once per event.
Bool_t Init(const char *inFile) override
void SetBothCharges(bool flag, Double32_t fraction=0.5)
Double32_t & GetVar(ParticleGunParticle &p, const std::string &name)
void SetVar(ParticleGunParticle &p, const std::string &name, Double32_t value)
ParticleGunParticle GenerateKinematics()
std::vector< Double32_t > fMomentumPars
FairGenerator * CloneGenerator() const override
void SetEkinRange(Double32_t kmin=0, Double32_t kmax=10)
void SetYRange(Double32_t ymin=-5, Double32_t ymax=7)
void SetMomentumModel(const int modelNo, std::vector< Double32_t > pars)
void SetEtaRange(Double32_t etamin=-5, Double32_t etamax=7)
void LoadHistoFromFile(const std::string &inFile, const std::string &inHisto, std::vector< std::string > varNames)
std::vector< Double32_t > fVertexPars
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
void SetThetaRange(Double32_t thetamin=0, Double32_t thetamax=90)
ParticleGunGenerator & operator=(const ParticleGunGenerator &)=default
virtual Bool_t Init(const char *, int)=0
std::function< void(ParticleGunParticle &, const std::vector< Double32_t > &)> generate
const char * description
std::vector< std::string > varNames