Skip to content

Commit cd59f17

Browse files
authored
BoxGenerator: enable sampling of pT and rapidity instead of p and eta
1 parent a63596e commit cd59f17

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎Generators/include/Generators/BoxGenerator.h‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,47 @@ class BoxGenerator : public Generator
3535
BoxGenerator() = default;
3636
BoxGenerator(int pdgid, int mult = 1);
3737

38+
/// With sampleYAndPt, eta bounds specify rapidity and p bounds specify pT.
3839
BoxGenerator(int pdgid,
3940
int mult,
4041
double etamin,
4142
double etamax,
4243
double pmin,
4344
double pmax,
4445
double phimin,
45-
double phimax) : mPDG{pdgid}, mMult{mult}
46+
double phimax,
47+
bool sampleYAndPt = false) : mPDG{pdgid}, mMult{mult}
4648
{
47-
SetEtaRange(etamin, etamax);
48-
SetPRange(pmin, pmax);
49+
if (sampleYAndPt) {
50+
SetYRange(etamin, etamax);
51+
SetPtRange(pmin, pmax);
52+
} else {
53+
SetEtaRange(etamin, etamax);
54+
SetPRange(pmin, pmax);
55+
}
4956
SetPhiRange(phimin, phimax);
5057
}
5158

52-
BoxGenerator(BoxGenConfig const& config) : mPDG{config.pdg}, mMult{config.number}
59+
BoxGenerator(BoxGenConfig const& config)
60+
: BoxGenerator(config.pdg, config.number, config.eta[0], config.eta[1],
61+
config.prange[0], config.prange[1], config.phirange[0], config.phirange[1], config.sampleYAndPt)
5362
{
54-
SetEtaRange(config.eta[0], config.eta[1]);
55-
SetPRange(config.prange[0], config.prange[1]);
56-
SetPhiRange(config.phirange[0], config.phirange[1]);
5763
}
5864

5965
void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10)
6066
{
6167
mPMin = pmin;
6268
mPMax = pmax;
6369
mPRangeIsSet = true;
70+
mPtRangeIsSet = false;
71+
}
72+
73+
void SetPtRange(Double32_t ptmin = 0, Double32_t ptmax = 10)
74+
{
75+
mPtMin = ptmin;
76+
mPtMax = ptmax;
77+
mPtRangeIsSet = true;
78+
mPRangeIsSet = false;
6479
}
6580

6681
void SetPhiRange(double phimin = 0, double phimax = 360)
@@ -74,6 +89,16 @@ class BoxGenerator : public Generator
7489
mEtaMin = etamin;
7590
mEtaMax = etamax;
7691
mEtaRangeIsSet = true;
92+
mYRangeIsSet = false;
93+
}
94+
95+
/// Sample rapidity uniformly; requires a transverse momentum range.
96+
void SetYRange(double ymin = -5, double ymax = 5)
97+
{
98+
mYMin = ymin;
99+
mYMax = ymax;
100+
mYRangeIsSet = true;
101+
mEtaRangeIsSet = false;
77102
}
78103

79104
/// generates a single particle conforming to particle gun parameters

‎Generators/include/Generators/BoxGunParam.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ struct BoxGunParam : public o2::conf::ConfigurableParamHelper<BoxGunParam> {
4040
struct BoxGenConfig {
4141
int pdg = 211; // which particle (default pion); could make this an enum
4242
int number = 10; // how many particles
43-
double eta[2] = {-1, 1}; // eta range
44-
double prange[2] = {0.1, 5}; // energy range min, max in GeV
43+
double eta[2] = {-1, 1}; // eta range, or rapidity range when sampleYAndPt is true
44+
double prange[2] = {0.1, 5}; // p range [GeV], or pT range when sampleYAndPt is true
4545
double phirange[2] = {0., 360.}; // phi range
46+
bool sampleYAndPt = false; // sample uniformly in rapidity and pT instead of eta and p
4647
};
4748

4849
} // end namespace eventgen

‎Generators/src/BoxGenerator.cxx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Generators/BoxGenerator.h"
1515
#include "TRandom.h"
1616
#include "TDatabasePDG.h"
17+
#include <stdexcept>
1718

1819
using namespace o2::eventgen;
1920

@@ -36,6 +37,10 @@ TParticle o2::eventgen::BoxGenerator::sampleParticle() const
3637
// if SetCosTheta() function is used, the distribution will be uniform in
3738
// cos(theta)
3839

40+
if (mYRangeIsSet && !mPtRangeIsSet) {
41+
throw std::invalid_argument("BoxGenerator: rapidity sampling requires SetPtRange() or sampleYAndPt=true in the configuration");
42+
}
43+
3944
// per instance, since several box generators with different PDG codes can coexist
4045
const double mass = GetPDGMass(mPDG);
4146

0 commit comments

Comments
 (0)