diff --git a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h index 8f0ef06e9698f..ffd6b9e06c110 100644 --- a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h +++ b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h @@ -25,10 +25,12 @@ namespace edm { protected: // data members - bool fControlledByEta; + 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..6c04c94c88a47 100644 --- a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc +++ b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc @@ -26,33 +26,52 @@ 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) + throw cms::Exception("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) { + 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); + } + + if (fControlledByEta || fControlledByREta) { 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) + throw cms::Exception("CloseByParticleGunProducer") << " Please fix ZMin and ZMax values in the configuration"; } - fZMax = pgun_params.getParameter("ZMax"); - fZMin = pgun_params.getParameter("ZMin"); fDelta = pgun_params.getParameter("Delta"); fPhiMin = pgun_params.getParameter("MinPhi"); fPhiMax = pgun_params.getParameter("MaxPhi"); 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"); @@ -63,7 +82,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"); @@ -81,10 +100,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,16 +150,24 @@ 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); + 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); - fR = (fZ / sinh(fEta)); + fZ = sinh(fEta) / fR; } if (fUseDeltaT) { @@ -161,6 +190,11 @@ 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);