diff --git a/IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h b/IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h index 83ecf8f607366..e6723da7f765f 100644 --- a/IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h +++ b/IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h @@ -13,6 +13,7 @@ * */ +#include #include "IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" @@ -27,7 +28,7 @@ class FlatEvtVtxGenerator : public BaseEvtVtxGenerator { FlatEvtVtxGenerator(const FlatEvtVtxGenerator& p) = delete; /** Copy assignment operator */ FlatEvtVtxGenerator& operator=(const FlatEvtVtxGenerator& rhs) = delete; - ~FlatEvtVtxGenerator() override; + ~FlatEvtVtxGenerator() override = default; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); @@ -42,6 +43,10 @@ class FlatEvtVtxGenerator : public BaseEvtVtxGenerator { inline void minY(double m = 0.0) { fMinY = m; } /// set min in Z in cm inline void minZ(double m = 0.0) { fMinZ = m; } + /// set min in R in cm + inline void minR(double m = 0.0) { fMinR = m; } + /// set min in phi in rad + inline void minPhi(double m = 0.0) { fMinPhi = m; } /// set max in X in cm inline void maxX(double m = 0) { fMaxX = m; } @@ -49,11 +54,22 @@ class FlatEvtVtxGenerator : public BaseEvtVtxGenerator { inline void maxY(double m = 0) { fMaxY = m; } /// set max in Z in cm inline void maxZ(double m = 0) { fMaxZ = m; } + /// set max in R in cm + inline void maxR(double m = 0.0) { fMaxR = m; } + /// set max in phi in rad + inline void maxPhi(double m = 0.0) { fMaxPhi = m; } private: - double fMinX, fMinY, fMinZ, fMinT, fMinR, fMinPhi; - double fMaxX, fMaxY, fMaxZ, fMaxT, fMaxR, fMaxPhi; - bool fFixedR; + // parameters always configured + const bool fUseCylindricalCoords; + double fMinZ, fMaxZ; + double fMinT, fMaxT; + + // parameters conditionally configured + std::optional fMaxX, fMaxY; + std::optional fMinX, fMinY; + std::optional fMinR, fMaxR; + std::optional fMinPhi, fMaxPhi; }; #endif diff --git a/IOMC/EventVertexGenerators/python/VtxDisplacedFlat_cfi.py b/IOMC/EventVertexGenerators/python/VtxDisplacedFlat_cfi.py index 40f1e5c1bdaa3..13844c947e78b 100644 --- a/IOMC/EventVertexGenerators/python/VtxDisplacedFlat_cfi.py +++ b/IOMC/EventVertexGenerators/python/VtxDisplacedFlat_cfi.py @@ -5,6 +5,3 @@ FlatVtxDisplacedParameters, src = cms.InputTag("generator", "unsmeared"), ) - - - diff --git a/IOMC/EventVertexGenerators/python/VtxSmearedParameters_cfi.py b/IOMC/EventVertexGenerators/python/VtxSmearedParameters_cfi.py index 1f3daa8782a82..d2dd8b5fba802 100644 --- a/IOMC/EventVertexGenerators/python/VtxSmearedParameters_cfi.py +++ b/IOMC/EventVertexGenerators/python/VtxSmearedParameters_cfi.py @@ -85,7 +85,7 @@ # Can restore correlation via MinT += (MinZ - MaxZ)/2 and MaxT += (MaxZ - MinZ)/2 # in [ns] units (recall c_light = 29.98cm/ns) FlatVtxSmearingParameters = cms.PSet( - FixedR = cms.bool(False), + UseCylindricalCoords = cms.bool(False), MaxZ = cms.double(5.3), MaxX = cms.double(0.0015), MaxY = cms.double(0.0015), @@ -97,7 +97,7 @@ ) FlatVtxDisplacedParameters = cms.PSet( - FixedR = cms.bool(True), + UseCylindricalCoords = cms.bool(True), MaxR = cms.double(10.1), MinR = cms.double(10.0), MaxZ = cms.double(0.001), diff --git a/IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc b/IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc index 1cb39e485d7b8..efc05fca9153d 100644 --- a/IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc +++ b/IOMC/EventVertexGenerators/src/FlatEvtVtxGenerator.cc @@ -1,43 +1,46 @@ -#include "IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h" -#include "FWCore/Utilities/interface/Exception.h" +// system includes +#include +#include +#include +#include +// user includes #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include -#include -#include +#include "FWCore/Utilities/interface/Exception.h" +#include "IOMC/EventVertexGenerators/interface/FlatEvtVtxGenerator.h" using CLHEP::cm; using CLHEP::ns; using CLHEP::radian; -FlatEvtVtxGenerator::FlatEvtVtxGenerator(const edm::ParameterSet& p) : BaseEvtVtxGenerator(p) { - fFixedR = p.getParameter("FixedR"); - if (fFixedR) { +FlatEvtVtxGenerator::FlatEvtVtxGenerator(const edm::ParameterSet& p) + : BaseEvtVtxGenerator(p), + fUseCylindricalCoords(p.getParameter("UseCylindricalCoords")), + fMinZ(p.getParameter("MinZ") * cm), + fMaxZ(p.getParameter("MaxZ") * cm), + fMinT(p.getParameter("MinT") * ns * c_light), + fMaxT(p.getParameter("MaxT") * ns * c_light) { + if (fUseCylindricalCoords) { fMaxR = p.getParameter("MaxR") * cm; fMinR = p.getParameter("MinR") * cm; fMaxPhi = p.getParameter("MaxPhi") * radian; fMinPhi = p.getParameter("MinPhi") * radian; + fMinX = std::nullopt; + fMaxX = std::nullopt; + fMinY = std::nullopt; + fMaxY = std::nullopt; } else { fMinX = p.getParameter("MinX") * cm; fMaxX = p.getParameter("MaxX") * cm; fMinY = p.getParameter("MinY") * cm; fMaxY = p.getParameter("MaxY") * cm; + fMaxR = std::nullopt; + fMinR = std::nullopt; + fMaxPhi = std::nullopt; + fMinPhi = std::nullopt; } - fMaxZ = p.getParameter("MaxZ") * cm; - fMinZ = p.getParameter("MinZ") * cm; - fMinT = p.getParameter("MinT") * ns * c_light; - fMaxT = p.getParameter("MaxT") * ns * c_light; - if (fMinX > fMaxX) { - throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " - << "MinX is greater than MaxX"; - } - if (fMinY > fMaxY) { - throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " - << "MinY is greater than MaxY"; - } if (fMinZ > fMaxZ) { throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " << "MinZ is greater than MaxZ"; @@ -46,31 +49,47 @@ FlatEvtVtxGenerator::FlatEvtVtxGenerator(const edm::ParameterSet& p) : BaseEvtVt throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " << "MinT is greater than MaxT"; } - if (fMinR > fMaxR) { - throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " - << "MinR is greater than MaxR"; - } - if (fMinPhi > fMaxPhi) { - throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " - << "MinPhi is greater than MaxPhi"; + + // configuration dependent checks + if (fUseCylindricalCoords) { + if (fMinR.value() > fMaxR.value()) { + throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " + << "MinR is greater than MaxR"; + } + if (fMinPhi.value() > fMaxPhi.value()) { + throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " + << "MinPhi is greater than MaxPhi"; + } + + edm::LogVerbatim("FlatEvtVtx") << "FlatEvtVtxGenerator Initialized with r[" << *fMinR << ":" << *fMaxR + << "] cm; phi[" << *fMinPhi << ":" << *fMaxPhi << "] rad; z[" << fMinZ << ":" + << fMaxZ << "] cm; t[" << fMinT << ":" << fMaxT << "] mm"; + } else { + if (fMinX.value() > fMaxX.value()) { + throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " + << "MinX is greater than MaxX"; + } + if (fMinY.value() > fMaxY.value()) { + throw cms::Exception("Configuration") << "Error in FlatEvtVtxGenerator: " + << "MinY is greater than MaxY"; + } + + edm::LogVerbatim("FlatEvtVtx") << "FlatEvtVtxGenerator Initialized with x[" << *fMinX << ":" << *fMaxX << "] cm; y[" + << *fMinY << ":" << *fMaxY << "] cm; z[" << fMinZ << ":" << fMaxZ << "] cm; t[" + << fMinT << ":" << fMaxT << "] mm" << std::endl; } - edm::LogVerbatim("FlatEvtVtx") << "FlatEvtVtxGenerator Initialized with x[" << fMinX << ":" << fMaxX << "] cm; y[" - << fMinY << ":" << fMaxY << "] cm; z[" << fMinZ << ":" << fMaxZ << "] cm; t[" << fMinT - << ":" << fMaxT << "]"; } -FlatEvtVtxGenerator::~FlatEvtVtxGenerator() {} - ROOT::Math::XYZTVector FlatEvtVtxGenerator::vertexShift(CLHEP::HepRandomEngine* engine) const { double aX, aY, aZ, aT; - if (fFixedR) { - double aR = CLHEP::RandFlat::shoot(engine, fMinR, fMaxR); - double aPhi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi); + if (fUseCylindricalCoords) { + double aR = CLHEP::RandFlat::shoot(engine, *fMinR, *fMaxR); + double aPhi = CLHEP::RandFlat::shoot(engine, *fMinPhi, *fMaxPhi); aX = aR * std::cos(aPhi); aY = aR * std::sin(aPhi); } else { - aX = CLHEP::RandFlat::shoot(engine, fMinX, fMaxX); - aY = CLHEP::RandFlat::shoot(engine, fMinY, fMaxY); + aX = CLHEP::RandFlat::shoot(engine, *fMinX, *fMaxX); + aY = CLHEP::RandFlat::shoot(engine, *fMinY, *fMaxY); } aZ = CLHEP::RandFlat::shoot(engine, fMinZ, fMaxZ); aT = CLHEP::RandFlat::shoot(engine, fMinT, fMaxT); @@ -83,19 +102,23 @@ ROOT::Math::XYZTVector FlatEvtVtxGenerator::vertexShift(CLHEP::HepRandomEngine* void FlatEvtVtxGenerator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("MinX", 0.0)->setComment("in cm"); - desc.add("MaxX", 0.001)->setComment("in cm"); - desc.add("MinY", 0.0)->setComment("in cm"); - desc.add("MaxY", 0.001)->setComment("in cm"); desc.add("MinZ", 0.0)->setComment("in cm"); desc.add("MaxZ", 0.001)->setComment("in cm"); desc.add("MinT", 0.0)->setComment("in ns"); desc.add("MaxT", 0.001)->setComment("in ns"); - desc.add("FixedR", false); - desc.add("MinR", 0.0)->setComment("in cm"); - desc.add("MaxR", 0.001)->setComment("in cm"); - desc.add("MinPhi", -3.14159265359)->setComment("in radians"); - desc.add("MaxPhi", 3.14159265359)->setComment("in radians"); desc.add("src"); - descriptions.add("FlatEvtVtxGenerator", desc); + + desc.ifValue(edm::ParameterDescription("UseCylindricalCoords", false, true), + // Cartesian (UseCylindricalCoords = false) branch + (false >> (edm::ParameterDescription("MinX", 0.0, true) and + edm::ParameterDescription("MaxX", 0.001, true) and + edm::ParameterDescription("MinY", 0.0, true) and + edm::ParameterDescription("MaxY", 0.001, true))) or + // Cylindrical (UseCylindricalCoords = true) branch + (true >> (edm::ParameterDescription("MinR", 0.0, true) and + edm::ParameterDescription("MaxR", 0.001, true) and + edm::ParameterDescription("MinPhi", -std::numbers::pi, true) and + edm::ParameterDescription("MaxPhi", std::numbers::pi, true)))); + + descriptions.addWithDefaultLabel(desc); }