From e90cad99b9c7fad0643122ed302f20d608bab6e7 Mon Sep 17 00:00:00 2001 From: Oz Amram Date: Wed, 17 Jul 2024 17:09:58 -0500 Subject: [PATCH 1/3] Add options for log spaced energy and specifying R and eta --- .../interface/CloseByParticleGunProducer.h | 6 +- .../src/CloseByParticleGunProducer.cc | 55 +++++++++++++++---- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h index 8f0ef06e9698f..02b4266b09681 100644 --- a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h +++ b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h @@ -25,10 +25,12 @@ namespace edm { protected: // data members - bool fControlledByEta; - double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax, + bool fControlledByEta, fControlledByREta; + double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax, fOffsetFirst; + double log_fVarMin = 0., log_fVarMax = 0.; int fNParticles; + bool fLogSpacedVar = false; bool fMaxVarSpread = false; bool fFlatPtGeneration = false; bool fPointing = false; diff --git a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc index 1eb3b03c7d595..2131763064e3c 100644 --- a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc +++ b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc @@ -26,14 +26,26 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) : BaseFlatGunProducer(pset), m_fieldToken(esConsumes()) { ParameterSet pgun_params = pset.getParameter("PGunParameters"); fControlledByEta = pgun_params.getParameter("ControlledByEta"); + fControlledByREta = pgun_params.getParameter("ControlledByREta"); + if(fControlledByEta and fControlledByREta) + LogError("CloseByParticleGunProducer") << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta "; + fVarMax = pgun_params.getParameter("VarMax"); fVarMin = pgun_params.getParameter("VarMin"); fMaxVarSpread = pgun_params.getParameter("MaxVarSpread"); + fLogSpacedVar = pgun_params.getParameter("LogSpacedVar"); fFlatPtGeneration = pgun_params.getParameter("FlatPtGeneration"); if (fVarMin < 1 && !fFlatPtGeneration) LogError("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time " "information may be invalid or not reliable"; - if (fControlledByEta) { + if (fVarMin < 0 && fLogSpacedVar) + LogError("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing"; + else{ + log_fVarMin = std::log(fVarMin); + log_fVarMax = std::log(fVarMax); + } + + if (fControlledByEta || fControlledByREta) { fEtaMax = pgun_params.getParameter("MaxEta"); fEtaMin = pgun_params.getParameter("MinEta"); if (fEtaMax <= fEtaMin) @@ -44,8 +56,13 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) if (fRMax <= fRMin) LogError("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration"; } - fZMax = pgun_params.getParameter("ZMax"); - fZMin = pgun_params.getParameter("ZMin"); + if(!fControlledByREta){ + fZMax = pgun_params.getParameter("ZMax"); + fZMin = pgun_params.getParameter("ZMin"); + + if (fZMax <= fZMin) + LogError("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; + } fDelta = pgun_params.getParameter("Delta"); fPhiMin = pgun_params.getParameter("MinPhi"); fPhiMax = pgun_params.getParameter("MaxPhi"); @@ -81,10 +98,12 @@ void CloseByParticleGunProducer::fillDescriptions(ConfigurationDescriptions& des { edm::ParameterSetDescription psd0; psd0.add("ControlledByEta", false); + psd0.add("ControlledByREta", false); psd0.add("Delta", 10); psd0.add("VarMax", 200.0); psd0.add("VarMin", 25.0); psd0.add("MaxVarSpread", false); + psd0.add("LogSpacedVar", false); psd0.add("FlatPtGeneration", false); psd0.add("MaxEta", 2.7); psd0.add("MaxPhi", 3.14159265359); @@ -129,17 +148,27 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { unsigned int numParticles = fRandomShoot ? CLHEP::RandFlat::shoot(engine, 1, fNParticles) : fNParticles; double phi = CLHEP::RandFlat::shoot(engine, fPhiMin, fPhiMax); - double fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax); + double fZ; double fR, fEta; double fT; - if (!fControlledByEta) { - fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); - fEta = asinh(fZ / fR); - } else { - fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); - fR = (fZ / sinh(fEta)); + if(!fControlledByREta){ + fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax); + + if (!fControlledByEta) { + fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); + fEta = asinh(fZ / fR); + } else { + fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); + fR = (fZ / sinh(fEta)); + } } + else{ + fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); + fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); + fZ = sinh(fEta)/fR; + } + if (fUseDeltaT) { fT = CLHEP::RandFlat::shoot(engine, fTMin, fTMax); @@ -161,6 +190,12 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { double fVar; if (numParticles > 1 && fMaxVarSpread) fVar = fVarMin + ip * (fVarMax - fVarMin) / (numParticles - 1); + else if(fLogSpacedVar){ + + double fVar_log = CLHEP::RandFlat::shoot(engine, log_fVarMin, log_fVarMax); + fVar = std::exp(fVar_log); + } + else fVar = CLHEP::RandFlat::shoot(engine, fVarMin, fVarMax); From f1c2e4919d8010558ba1602b920b1a599522bf50 Mon Sep 17 00:00:00 2001 From: Oz Amram Date: Thu, 18 Jul 2024 14:46:34 -0500 Subject: [PATCH 2/3] Promote configuration issues to exceptions --- .../src/CloseByParticleGunProducer.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc index 2131763064e3c..ce679cdcdfa6a 100644 --- a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc +++ b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc @@ -28,7 +28,7 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fControlledByEta = pgun_params.getParameter("ControlledByEta"); fControlledByREta = pgun_params.getParameter("ControlledByREta"); if(fControlledByEta and fControlledByREta) - LogError("CloseByParticleGunProducer") << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta "; + throw cms::Exception("CloseByParticleGunProducer") << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta "; fVarMax = pgun_params.getParameter("VarMax"); fVarMin = pgun_params.getParameter("VarMin"); @@ -36,10 +36,10 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fLogSpacedVar = pgun_params.getParameter("LogSpacedVar"); fFlatPtGeneration = pgun_params.getParameter("FlatPtGeneration"); if (fVarMin < 1 && !fFlatPtGeneration) - LogError("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time " + throw cms::Exception("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time " "information may be invalid or not reliable"; if (fVarMin < 0 && fLogSpacedVar) - LogError("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing"; + throw cms::Exception("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing"; else{ log_fVarMin = std::log(fVarMin); log_fVarMax = std::log(fVarMax); @@ -49,19 +49,19 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fEtaMax = pgun_params.getParameter("MaxEta"); fEtaMin = pgun_params.getParameter("MinEta"); if (fEtaMax <= fEtaMin) - LogError("CloseByParticleGunProducer") << " Please fix MinEta and MaxEta values in the configuration"; + throw cms::Exception("CloseByParticleGunProducer") << " Please fix MinEta and MaxEta values in the configuration"; } else { fRMax = pgun_params.getParameter("RMax"); fRMin = pgun_params.getParameter("RMin"); if (fRMax <= fRMin) - LogError("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration"; + throw cms::Exception("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration"; } if(!fControlledByREta){ fZMax = pgun_params.getParameter("ZMax"); fZMin = pgun_params.getParameter("ZMin"); if (fZMax <= fZMin) - LogError("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; + throw cms::Exception("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; } fDelta = pgun_params.getParameter("Delta"); fPhiMin = pgun_params.getParameter("MinPhi"); @@ -69,7 +69,7 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fPointing = pgun_params.getParameter("Pointing"); fOverlapping = pgun_params.getParameter("Overlapping"); if (fFlatPtGeneration && !fPointing) - LogError("CloseByParticleGunProducer") + throw cms::Exception("CloseByParticleGunProducer") << " Can't generate non pointing FlatPt samples; please disable FlatPt generation or generate pointing sample"; fRandomShoot = pgun_params.getParameter("RandomShoot"); fNParticles = pgun_params.getParameter("NParticles"); @@ -80,7 +80,7 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fTMax = pgun_params.getParameter("TMax"); fTMin = pgun_params.getParameter("TMin"); if (fTMax <= fTMin) - LogError("CloseByParticleGunProducer") << " Please fix TMin and TMax values in the configuration"; + throw cms::Exception("CloseByParticleGunProducer") << " Please fix TMin and TMax values in the configuration"; // set a fixed time offset for the particles fOffsetFirst = pgun_params.getParameter("OffsetFirst"); From 7eae51de3dd37900827b312203fd0ac7d7e05c96 Mon Sep 17 00:00:00 2001 From: Oz Amram Date: Fri, 19 Jul 2024 17:15:34 -0500 Subject: [PATCH 3/3] Code style checks --- .../interface/CloseByParticleGunProducer.h | 2 +- .../src/CloseByParticleGunProducer.cc | 41 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h index 02b4266b09681..ffd6b9e06c110 100644 --- a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h +++ b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h @@ -26,7 +26,7 @@ namespace edm { protected: // data members bool fControlledByEta, fControlledByREta; - double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax, + double fVarMin, fVarMax, fEtaMin, fEtaMax, fRMin, fRMax, fZMin, fZMax, fDelta, fPhiMin, fPhiMax, fTMin, fTMax, fOffsetFirst; double log_fVarMin = 0., log_fVarMax = 0.; int fNParticles; diff --git a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc index ce679cdcdfa6a..6c04c94c88a47 100644 --- a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc +++ b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc @@ -27,8 +27,9 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) ParameterSet pgun_params = pset.getParameter("PGunParameters"); fControlledByEta = pgun_params.getParameter("ControlledByEta"); fControlledByREta = pgun_params.getParameter("ControlledByREta"); - if(fControlledByEta and fControlledByREta) - throw cms::Exception("CloseByParticleGunProducer") << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta "; + if (fControlledByEta and fControlledByREta) + throw cms::Exception("CloseByParticleGunProducer") + << " Conflicting configuration, cannot have both ControlledByEta and ControlledByREta "; fVarMax = pgun_params.getParameter("VarMax"); fVarMin = pgun_params.getParameter("VarMin"); @@ -36,13 +37,14 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) fLogSpacedVar = pgun_params.getParameter("LogSpacedVar"); fFlatPtGeneration = pgun_params.getParameter("FlatPtGeneration"); if (fVarMin < 1 && !fFlatPtGeneration) - throw cms::Exception("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time " - "information may be invalid or not reliable"; + throw cms::Exception("CloseByParticleGunProducer") + << " Please choose a minimum energy greater than 1 GeV, otherwise time " + "information may be invalid or not reliable"; if (fVarMin < 0 && fLogSpacedVar) throw cms::Exception("CloseByParticleGunProducer") << " Minimum energy must be greater than zero for log spacing"; - else{ - log_fVarMin = std::log(fVarMin); - log_fVarMax = std::log(fVarMax); + else { + log_fVarMin = std::log(fVarMin); + log_fVarMax = std::log(fVarMax); } if (fControlledByEta || fControlledByREta) { @@ -56,12 +58,12 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) if (fRMax <= fRMin) throw cms::Exception("CloseByParticleGunProducer") << " Please fix RMin and RMax values in the configuration"; } - if(!fControlledByREta){ - fZMax = pgun_params.getParameter("ZMax"); - fZMin = pgun_params.getParameter("ZMin"); + if (!fControlledByREta) { + fZMax = pgun_params.getParameter("ZMax"); + fZMin = pgun_params.getParameter("ZMin"); - if (fZMax <= fZMin) - throw cms::Exception("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; + if (fZMax <= fZMin) + throw cms::Exception("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; } fDelta = pgun_params.getParameter("Delta"); fPhiMin = pgun_params.getParameter("MinPhi"); @@ -152,7 +154,7 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { double fR, fEta; double fT; - if(!fControlledByREta){ + if (!fControlledByREta) { fZ = CLHEP::RandFlat::shoot(engine, fZMin, fZMax); if (!fControlledByEta) { @@ -162,14 +164,12 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); fR = (fZ / sinh(fEta)); } - } - else{ - fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); - fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); - fZ = sinh(fEta)/fR; + } else { + fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); + fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); + fZ = sinh(fEta) / fR; } - if (fUseDeltaT) { fT = CLHEP::RandFlat::shoot(engine, fTMin, fTMax); } else { @@ -190,8 +190,7 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { double fVar; if (numParticles > 1 && fMaxVarSpread) fVar = fVarMin + ip * (fVarMax - fVarMin) / (numParticles - 1); - else if(fLogSpacedVar){ - + else if (fLogSpacedVar) { double fVar_log = CLHEP::RandFlat::shoot(engine, log_fVarMin, log_fVarMax); fVar = std::exp(fVar_log); }