diff --git a/Configuration/Generator/python/CE_E_Front_120um_cfi.py b/Configuration/Generator/python/CE_E_Front_120um_cfi.py index 48957836b7ac3..57887a3de467f 100644 --- a/Configuration/Generator/python/CE_E_Front_120um_cfi.py +++ b/Configuration/Generator/python/CE_E_Front_120um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(54.99), RMax = cms.double(55.01), ZMin = cms.double(320.99), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_E_Front_200um_cfi.py b/Configuration/Generator/python/CE_E_Front_200um_cfi.py index 9390e996f0102..1d2f2a4168c9b 100644 --- a/Configuration/Generator/python/CE_E_Front_200um_cfi.py +++ b/Configuration/Generator/python/CE_E_Front_200um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(89.99), RMax = cms.double(90.01), ZMin = cms.double(320.99), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_E_Front_300um_cfi.py b/Configuration/Generator/python/CE_E_Front_300um_cfi.py index 3c53fb5a57349..7bc6c732d407b 100644 --- a/Configuration/Generator/python/CE_E_Front_300um_cfi.py +++ b/Configuration/Generator/python/CE_E_Front_300um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(134.99), RMax = cms.double(135.01), ZMin = cms.double(320.99), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_H_Coarse_300um_cfi.py b/Configuration/Generator/python/CE_H_Coarse_300um_cfi.py index 175c2513cd32e..8ae9767959af5 100644 --- a/Configuration/Generator/python/CE_H_Coarse_300um_cfi.py +++ b/Configuration/Generator/python/CE_H_Coarse_300um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(79.99), RMax = cms.double(80.01), ZMin = cms.double(429.99), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_H_Coarse_Scint_cfi.py b/Configuration/Generator/python/CE_H_Coarse_Scint_cfi.py index 593be715f7d1e..5cdaf1659ea03 100644 --- a/Configuration/Generator/python/CE_H_Coarse_Scint_cfi.py +++ b/Configuration/Generator/python/CE_H_Coarse_Scint_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(179.99), RMax = cms.double(180.01), ZMin = cms.double(429.99), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_H_Fine_120um_cfi.py b/Configuration/Generator/python/CE_H_Fine_120um_cfi.py index 007fca742ed00..59bc183c193fa 100644 --- a/Configuration/Generator/python/CE_H_Fine_120um_cfi.py +++ b/Configuration/Generator/python/CE_H_Fine_120um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(49.99), RMax = cms.double(50.01), ZMin = cms.double(362.519), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_H_Fine_200um_cfi.py b/Configuration/Generator/python/CE_H_Fine_200um_cfi.py index d86e8b04e5269..2fb37c5ebfa3a 100644 --- a/Configuration/Generator/python/CE_H_Fine_200um_cfi.py +++ b/Configuration/Generator/python/CE_H_Fine_200um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(89.99), RMax = cms.double(90.01), ZMin = cms.double(362.519), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/Configuration/Generator/python/CE_H_Fine_300um_cfi.py b/Configuration/Generator/python/CE_H_Fine_300um_cfi.py index 07e61eb07245e..1833072494c74 100644 --- a/Configuration/Generator/python/CE_H_Fine_300um_cfi.py +++ b/Configuration/Generator/python/CE_H_Fine_300um_cfi.py @@ -3,9 +3,10 @@ generator = cms.EDProducer("CloseByParticleGunProducer", PGunParameters = cms.PSet(PartID = cms.vint32(22), ControlledByEta = cms.bool(False), - EnMin = cms.double(25.), - EnMax = cms.double(200.), - MaxEnSpread = cms.bool(False), + VarMin = cms.double(25.), + VarMax = cms.double(200.), + MaxVarSpread = cms.bool(False), + FlatPtGeneration = cms.bool(False), RMin = cms.double(134.99), RMax = cms.double(135.01), ZMin = cms.double(362.519), @@ -19,7 +20,10 @@ MinEta = cms.double(1.7), MaxPhi = cms.double(3.14159265359), MinPhi = cms.double(-3.14159265359), - + UseDeltaT = cms.bool(False), + TMin = cms.double(0.), + TMax = cms.double(0.05), + OffsetFirst = cms.double(0.) ), Verbosity = cms.untracked.int32(0), diff --git a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h index 50a7fb4f25c70..ffd6b9e06c110 100644 --- a/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h +++ b/IOMC/ParticleGuns/interface/CloseByParticleGunProducer.h @@ -25,11 +25,14 @@ namespace edm { protected: // data members - bool fControlledByEta; - double fEnMin, fEnMax, 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 fMaxEnSpread = false; + bool fLogSpacedVar = false; + bool fMaxVarSpread = false; + bool fFlatPtGeneration = false; bool fPointing = false; bool fOverlapping = false; bool fRandomShoot = false; diff --git a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc index 7ae8bd9d93de1..6c04c94c88a47 100644 --- a/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc +++ b/IOMC/ParticleGuns/src/CloseByParticleGunProducer.cc @@ -14,10 +14,10 @@ #include "FWCore/Utilities/interface/RandomNumberGenerator.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "CLHEP/Random/RandFlat.h" -#include "CLHEP/Units/GlobalSystemOfUnits.h" -#include "CLHEP/Units/GlobalPhysicalConstants.h" -#include "CLHEP/Random/RandFlat.h" +#include +#include +#include +#include using namespace edm; using namespace std; @@ -26,31 +26,53 @@ CloseByParticleGunProducer::CloseByParticleGunProducer(const ParameterSet& pset) : BaseFlatGunProducer(pset), m_fieldToken(esConsumes()) { ParameterSet pgun_params = pset.getParameter("PGunParameters"); fControlledByEta = pgun_params.getParameter("ControlledByEta"); - fEnMax = pgun_params.getParameter("EnMax"); - fEnMin = pgun_params.getParameter("EnMin"); - if (fEnMin < 1) - LogError("CloseByParticleGunProducer") << " Please choose a minimum energy greater than 1 GeV, otherwise time " - "information may be invalid or not reliable"; - - fMaxEnSpread = pgun_params.getParameter("MaxEnSpread"); - if (fControlledByEta) { + 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) + 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) + 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"); fPartIDs = pgun_params.getParameter>("PartID"); @@ -60,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"); @@ -78,10 +100,13 @@ void CloseByParticleGunProducer::fillDescriptions(ConfigurationDescriptions& des { edm::ParameterSetDescription psd0; psd0.add("ControlledByEta", false); + psd0.add("ControlledByREta", false); psd0.add("Delta", 10); - psd0.add("EnMax", 200.0); - psd0.add("EnMin", 25.0); - psd0.add("MaxEnSpread", false); + 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); psd0.add("MinEta", 1.7); @@ -125,15 +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 fR; + double fZ; + double fR, fEta; double fT; - if (!fControlledByEta) { - fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); + 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 { - double fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); - fR = (fZ / sinh(fEta)); + fR = CLHEP::RandFlat::shoot(engine, fRMin, fRMax); + fEta = CLHEP::RandFlat::shoot(engine, fEtaMin, fEtaMax); + fZ = sinh(fEta) / fR; } if (fUseDeltaT) { @@ -153,26 +187,44 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { } else phi += fDelta / fR; - double fEn; - if (numParticles > 1 && fMaxEnSpread) - fEn = fEnMin + ip * (fEnMax - fEnMin) / (numParticles - 1); + 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 - fEn = CLHEP::RandFlat::shoot(engine, fEnMin, fEnMax); + fVar = CLHEP::RandFlat::shoot(engine, fVarMin, fVarMax); int partIdx = CLHEP::RandFlat::shoot(engine, 0, fPartIDs.size()); int PartID = fPartIDs[partIdx]; const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))); double mass = PData->mass().value(); - double mom2 = fEn * fEn - mass * mass; - double mom = 0.; - if (mom2 > 0.) { - mom = sqrt(mom2); - } - double px = 0.; - double py = 0.; - double pz = mom; - double energy = fEn; + double mom, px, py, pz; + double energy; + + if (!fFlatPtGeneration) { + double mom2 = fVar * fVar - mass * mass; + mom = 0.; + if (mom2 > 0.) { + mom = sqrt(mom2); + } + px = 0.; + py = 0.; + pz = mom; + energy = fVar; + } else { + double theta = 2. * atan(exp(-fEta)); + mom = fVar / sin(theta); + px = fVar * cos(phi); + py = fVar * sin(phi); + pz = mom * cos(theta); + double energy2 = mom * mom + mass * mass; + energy = sqrt(energy2); + } // Compute Vertex Position double x = fR * cos(phi); double y = fR * sin(phi); @@ -189,7 +241,7 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { // compute correct path assuming uniform magnetic field in CMS double pathLength = 0.; - const double speed = p.pz() / p.e() * c_light / cm; + const double speed = p.pz() / p.e() * c_light / CLHEP::cm; if (PData->charge()) { // Radius [cm] = P[GeV/c] * 10^9 / (c[mm/ns] * 10^6 * q[C] * B[T]) * 100[cm/m] const double radius = std::sqrt(p.px() * p.px() + p.py() * p.py()) * std::pow(10, 5) / @@ -202,9 +254,10 @@ void CloseByParticleGunProducer::produce(Event& e, const EventSetup& es) { // if not pointing time doesn't mean a lot, keep the old way const double pathTime = fPointing ? (pathLength / speed) : (std::sqrt(x * x + y * y + fZ * fZ) / speed); - double timeOffset = fOffsetFirst + (pathTime + ip * fT) * ns * c_light; + double timeOffset = fOffsetFirst + (pathTime + ip * fT) * CLHEP::ns * c_light; - HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(x * cm, y * cm, fZ * cm, timeOffset)); + HepMC::GenVertex* Vtx = + new HepMC::GenVertex(HepMC::FourVector(x * CLHEP::cm, y * CLHEP::cm, fZ * CLHEP::cm, timeOffset)); HepMC::GenParticle* Part = new HepMC::GenParticle(p, PartID, 1); Part->suggest_barcode(barcode);