Skip to content

Commit 980d337

Browse files
authored
Merge pull request #45515 from OzAmram/update_CloseByParticleGun
Add new configuration options to CloseByParticleGun
2 parents 62cadd8 + 7eae51d commit 980d337

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ namespace edm {
2525

2626
protected:
2727
// data members
28-
bool fControlledByEta;
28+
bool fControlledByEta, fControlledByREta;
2929
double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax,
3030
fOffsetFirst;
31+
double log_fVarMin = 0., log_fVarMax = 0.;
3132
int fNParticles;
33+
bool fLogSpacedVar = false;
3234
bool fMaxVarSpread = false;
3335
bool fFlatPtGeneration = false;
3436
bool fPointing = false;

IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,52 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset)
2626
: BaseFlatGunProducer(pset), m_fieldToken(esConsumes()) {
2727
ParameterSet pgun_params = pset.getParameter<ParameterSet>("PGunParameters");
2828
fControlledByEta = pgun_params.getParameter<bool>("ControlledByEta");
29+
fControlledByREta = pgun_params.getParameter<bool>("ControlledByREta");
30+
if (fControlledByEta and fControlledByREta)
31+
throw cms::Exception("CloseByParticleGunProducer")
32+
<< " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta ";
33+
2934
fVarMax = pgun_params.getParameter<double>("VarMax");
3035
fVarMin = pgun_params.getParameter<double>("VarMin");
3136
fMaxVarSpread = pgun_params.getParameter<bool>("MaxVarSpread");
37+
fLogSpacedVar = pgun_params.getParameter<bool>("LogSpacedVar");
3238
fFlatPtGeneration = pgun_params.getParameter<bool>("FlatPtGeneration");
3339
if (fVarMin < 1 && !fFlatPtGeneration)
34-
LogError("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time "
35-
"information may be invalid or not reliable";
36-
if (fControlledByEta) {
40+
throw cms::Exception("CloseByParticleGunProducer")
41+
<< " Please choose a minimum energy greater than 1 GeV, otherwise time "
42+
"information may be invalid or not reliable";
43+
if (fVarMin < 0 && fLogSpacedVar)
44+
throw cms::Exception("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing";
45+
else {
46+
log_fVarMin = std::log(fVarMin);
47+
log_fVarMax = std::log(fVarMax);
48+
}
49+
50+
if (fControlledByEta || fControlledByREta) {
3751
fEtaMax = pgun_params.getParameter<double>("MaxEta");
3852
fEtaMin = pgun_params.getParameter<double>("MinEta");
3953
if (fEtaMax <= fEtaMin)
40-
LogError("CloseByParticleGunProducer") << " Please fix MinEta and MaxEta values in the configuration";
54+
throw cms::Exception("CloseByParticleGunProducer") << " Please fix MinEta and MaxEta values in the configuration";
4155
} else {
4256
fRMax = pgun_params.getParameter<double>("RMax");
4357
fRMin = pgun_params.getParameter<double>("RMin");
4458
if (fRMax <= fRMin)
45-
LogError("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration";
59+
throw cms::Exception("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration";
60+
}
61+
if (!fControlledByREta) {
62+
fZMax = pgun_params.getParameter<double>("ZMax");
63+
fZMin = pgun_params.getParameter<double>("ZMin");
64+
65+
if (fZMax <= fZMin)
66+
throw cms::Exception("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration";
4667
}
47-
fZMax = pgun_params.getParameter<double>("ZMax");
48-
fZMin = pgun_params.getParameter<double>("ZMin");
4968
fDelta = pgun_params.getParameter<double>("Delta");
5069
fPhiMin = pgun_params.getParameter<double>("MinPhi");
5170
fPhiMax = pgun_params.getParameter<double>("MaxPhi");
5271
fPointing = pgun_params.getParameter<bool>("Pointing");
5372
fOverlapping = pgun_params.getParameter<bool>("Overlapping");
5473
if (fFlatPtGeneration && !fPointing)
55-
LogError("CloseByParticleGunProducer")
74+
throw cms::Exception("CloseByParticleGunProducer")
5675
<< " Can't generate non pointing FlatPt samples; please disable FlatPt generation or generate pointing sample";
5776
fRandomShoot = pgun_params.getParameter<bool>("RandomShoot");
5877
fNParticles = pgun_params.getParameter<int>("NParticles");
@@ -63,7 +82,7 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset)
6382
fTMax = pgun_params.getParameter<double>("TMax");
6483
fTMin = pgun_params.getParameter<double>("TMin");
6584
if (fTMax <= fTMin)
66-
LogError("CloseByParticleGunProducer") << " Please fix TMin and TMax values in the configuration";
85+
throw cms::Exception("CloseByParticleGunProducer") << " Please fix TMin and TMax values in the configuration";
6786
// set a fixed time offset for the particles
6887
fOffsetFirst = pgun_params.getParameter<double>("OffsetFirst");
6988

@@ -81,10 +100,12 @@ void CloseByParticleGunProducer::fillDescriptions(ConfigurationDescriptions& des
81100
{
82101
edm::ParameterSetDescription psd0;
83102
psd0.add<bool>("ControlledByEta", false);
103+
psd0.add<bool>("ControlledByREta", false);
84104
psd0.add<double>("Delta", 10);
85105
psd0.add<double>("VarMax", 200.0);
86106
psd0.add<double>("VarMin", 25.0);
87107
psd0.add<bool>("MaxVarSpread", false);
108+
psd0.add<bool>("LogSpacedVar", false);
88109
psd0.add<bool>("FlatPtGeneration", false);
89110
psd0.add<double>("MaxEta", 2.7);
90111
psd0.add<double>("MaxPhi", 3.14159265359);
@@ -129,16 +150,24 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) {
129150
unsigned int numParticles = fRandomShoot ? CLHEP::RandFlat::shoot(engine, 1, fNParticles) : fNParticles;
130151

131152
double phi = CLHEP::RandFlat::shoot(engine, fPhiMin, fPhiMax);
132-
double fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax);
153+
double fZ;
133154
double fR, fEta;
134155
double fT;
135156

136-
if (!fControlledByEta) {
137-
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
138-
fEta = asinh(fZ / fR);
157+
if (!fControlledByREta) {
158+
fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax);
159+
160+
if (!fControlledByEta) {
161+
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
162+
fEta = asinh(fZ / fR);
163+
} else {
164+
fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax);
165+
fR = (fZ / sinh(fEta));
166+
}
139167
} else {
168+
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
140169
fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax);
141-
fR = (fZ / sinh(fEta));
170+
fZ = sinh(fEta) / fR;
142171
}
143172

144173
if (fUseDeltaT) {
@@ -161,6 +190,11 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) {
161190
double fVar;
162191
if (numParticles > 1 && fMaxVarSpread)
163192
fVar = fVarMin + ip * (fVarMax - fVarMin) / (numParticles - 1);
193+
else if (fLogSpacedVar) {
194+
double fVar_log = CLHEP::RandFlat::shoot(engine, log_fVarMin, log_fVarMax);
195+
fVar = std::exp(fVar_log);
196+
}
197+
164198
else
165199
fVar = CLHEP::RandFlat::shoot(engine, fVarMin, fVarMax);
166200

0 commit comments

Comments
 (0)