Skip to content

Commit e90cad9

Browse files
author
Oz Amram
committed
Add options for log spaced energy and specifying R and eta
1 parent b20c7aa commit e90cad9

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ namespace edm {
2525

2626
protected:
2727
// data members
28-
bool fControlledByEta;
29-
double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax,
28+
bool fControlledByEta, fControlledByREta;
29+
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: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,26 @@ 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+
LogError("CloseByParticleGunProducer") << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta ";
32+
2933
fVarMax = pgun_params.getParameter<double>("VarMax");
3034
fVarMin = pgun_params.getParameter<double>("VarMin");
3135
fMaxVarSpread = pgun_params.getParameter<bool>("MaxVarSpread");
36+
fLogSpacedVar = pgun_params.getParameter<bool>("LogSpacedVar");
3237
fFlatPtGeneration = pgun_params.getParameter<bool>("FlatPtGeneration");
3338
if (fVarMin < 1 && !fFlatPtGeneration)
3439
LogError("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time "
3540
"information may be invalid or not reliable";
36-
if (fControlledByEta) {
41+
if (fVarMin < 0 && fLogSpacedVar)
42+
LogError("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing";
43+
else{
44+
log_fVarMin = std::log(fVarMin);
45+
log_fVarMax = std::log(fVarMax);
46+
}
47+
48+
if (fControlledByEta || fControlledByREta) {
3749
fEtaMax = pgun_params.getParameter<double>("MaxEta");
3850
fEtaMin = pgun_params.getParameter<double>("MinEta");
3951
if (fEtaMax <= fEtaMin)
@@ -44,8 +56,13 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset)
4456
if (fRMax <= fRMin)
4557
LogError("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration";
4658
}
47-
fZMax = pgun_params.getParameter<double>("ZMax");
48-
fZMin = pgun_params.getParameter<double>("ZMin");
59+
if(!fControlledByREta){
60+
fZMax = pgun_params.getParameter<double>("ZMax");
61+
fZMin = pgun_params.getParameter<double>("ZMin");
62+
63+
if (fZMax <= fZMin)
64+
LogError("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration";
65+
}
4966
fDelta = pgun_params.getParameter<double>("Delta");
5067
fPhiMin = pgun_params.getParameter<double>("MinPhi");
5168
fPhiMax = pgun_params.getParameter<double>("MaxPhi");
@@ -81,10 +98,12 @@ void CloseByParticleGunProducer::fillDescriptions(ConfigurationDescriptions& des
8198
{
8299
edm::ParameterSetDescription psd0;
83100
psd0.add<bool>("ControlledByEta", false);
101+
psd0.add<bool>("ControlledByREta", false);
84102
psd0.add<double>("Delta", 10);
85103
psd0.add<double>("VarMax", 200.0);
86104
psd0.add<double>("VarMin", 25.0);
87105
psd0.add<bool>("MaxVarSpread", false);
106+
psd0.add<bool>("LogSpacedVar", false);
88107
psd0.add<bool>("FlatPtGeneration", false);
89108
psd0.add<double>("MaxEta", 2.7);
90109
psd0.add<double>("MaxPhi", 3.14159265359);
@@ -129,17 +148,27 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) {
129148
unsigned int numParticles = fRandomShoot ? CLHEP::RandFlat::shoot(engine, 1, fNParticles) : fNParticles;
130149

131150
double phi = CLHEP::RandFlat::shoot(engine, fPhiMin, fPhiMax);
132-
double fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax);
151+
double fZ;
133152
double fR, fEta;
134153
double fT;
135154

136-
if (!fControlledByEta) {
137-
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
138-
fEta = asinh(fZ / fR);
139-
} else {
140-
fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax);
141-
fR = (fZ / sinh(fEta));
155+
if(!fControlledByREta){
156+
fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax);
157+
158+
if (!fControlledByEta) {
159+
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
160+
fEta = asinh(fZ / fR);
161+
} else {
162+
fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax);
163+
fR = (fZ / sinh(fEta));
164+
}
142165
}
166+
else{
167+
fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax);
168+
fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax);
169+
fZ = sinh(fEta)/fR;
170+
}
171+
143172

144173
if (fUseDeltaT) {
145174
fT = CLHEP::RandFlat::shoot(engine, fTMin, fTMax);
@@ -161,6 +190,12 @@ 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+
195+
double fVar_log = CLHEP::RandFlat::shoot(engine, log_fVarMin, log_fVarMax);
196+
fVar = std::exp(fVar_log);
197+
}
198+
164199
else
165200
fVar = CLHEP::RandFlat::shoot(engine, fVarMin, fVarMax);
166201

0 commit comments

Comments
 (0)