From bec539c7cfa71b9d64a30aa0fe610a1d10565699 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sat, 10 Jun 2023 20:47:21 +0200 Subject: [PATCH 1/9] add SimBeamSpotObjects to standard payload utilities --- CondCore/Utilities/plugins/Module_2XML.cc | 1 + CondCore/Utilities/src/CondDBFetch.cc | 1 + CondCore/Utilities/src/CondDBImport.cc | 1 + CondCore/Utilities/src/CondFormats.h | 1 + 4 files changed, 4 insertions(+) diff --git a/CondCore/Utilities/plugins/Module_2XML.cc b/CondCore/Utilities/plugins/Module_2XML.cc index 09e00aebbc052..f998451c222e0 100644 --- a/CondCore/Utilities/plugins/Module_2XML.cc +++ b/CondCore/Utilities/plugins/Module_2XML.cc @@ -255,6 +255,7 @@ PAYLOAD_2XML_MODULE(pluginUtilities_payload2xml) { PAYLOAD_2XML_CLASS(RPFlatParams); PAYLOAD_2XML_CLASS(RecoIdealGeometry); PAYLOAD_2XML_CLASS(RunInfo); + PAYLOAD_2XML_CLASS(SimBeamSpotObjects); PAYLOAD_2XML_CLASS(SiPhase2OuterTrackerLorentzAngle); PAYLOAD_2XML_CLASS(SiPixel2DTemplateDBObject); PAYLOAD_2XML_CLASS(SiPixelCPEGenericErrorParm); diff --git a/CondCore/Utilities/src/CondDBFetch.cc b/CondCore/Utilities/src/CondDBFetch.cc index f82f1fae959b0..b57943e136c5d 100644 --- a/CondCore/Utilities/src/CondDBFetch.cc +++ b/CondCore/Utilities/src/CondDBFetch.cc @@ -276,6 +276,7 @@ namespace cond { FETCH_PAYLOAD_CASE(RPFlatParams) FETCH_PAYLOAD_CASE(RecoIdealGeometry) FETCH_PAYLOAD_CASE(RunInfo) + FETCH_PAYLOAD_CASE(SimBeamSpotObjects) FETCH_PAYLOAD_CASE(SiPhase2OuterTrackerLorentzAngle) FETCH_PAYLOAD_CASE(SiPixelCalibConfiguration) FETCH_PAYLOAD_CASE(SiPixelCPEGenericErrorParm) diff --git a/CondCore/Utilities/src/CondDBImport.cc b/CondCore/Utilities/src/CondDBImport.cc index a35f61600a67c..85298689b50d7 100644 --- a/CondCore/Utilities/src/CondDBImport.cc +++ b/CondCore/Utilities/src/CondDBImport.cc @@ -302,6 +302,7 @@ namespace cond { IMPORT_PAYLOAD_CASE(RPFlatParams) IMPORT_PAYLOAD_CASE(RecoIdealGeometry) IMPORT_PAYLOAD_CASE(RunInfo) + IMPORT_PAYLOAD_CASE(SimBeamSpotObjects) IMPORT_PAYLOAD_CASE(SiPhase2OuterTrackerLorentzAngle) IMPORT_PAYLOAD_CASE(SiPixelCalibConfiguration) IMPORT_PAYLOAD_CASE(SiPixelCPEGenericErrorParm) diff --git a/CondCore/Utilities/src/CondFormats.h b/CondCore/Utilities/src/CondFormats.h index c35957099e6d4..9ff3f71bba310 100644 --- a/CondCore/Utilities/src/CondFormats.h +++ b/CondCore/Utilities/src/CondFormats.h @@ -8,6 +8,7 @@ #include "CondFormats/Alignment/interface/Alignments.h" #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" #include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" +#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h" #include "CondFormats/CastorObjects/interface/CastorSaturationCorrs.h" #include "CondFormats/HIObjects/interface/CentralityTable.h" From daf6dd0bed928046ee1fbf7309408eaeb839f085 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sat, 10 Jun 2023 20:49:31 +0200 Subject: [PATCH 2/9] add cfg writer for SimBeamSpotObjects payloads --- .../src/BeamProfile2DB.cc | 22 ++------ .../test/BeamProfile2DBWriter_cfg.py | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py diff --git a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc b/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc index 6a922283d057a..78d59250fef9c 100644 --- a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc +++ b/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc @@ -48,7 +48,6 @@ class BeamProfile2DB : public edm::global::EDAnalyzer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - void beginJob() override; void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override; void endJob() override; @@ -72,23 +71,13 @@ namespace { } } // namespace -// -// constants, enums and typedefs -// - -// -// static data member definitions -// // // constructors and destructor // BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) : beamSpot_(read(iConfig)) {} -BeamProfile2DB::~BeamProfile2DB() { - // do anything here that needs to be done at desctruction time - // (e.g. close files, deallocate resources etc.) -} +BeamProfile2DB::~BeamProfile2DB() = default; // // member functions @@ -97,9 +86,6 @@ BeamProfile2DB::~BeamProfile2DB() { // ------------ method called for each event ------------ void BeamProfile2DB::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {} -// ------------ method called once each job just before starting event loop ------------ -void BeamProfile2DB::beginJob() {} - // ------------ method called once each job just after ending the event loop ------------ void BeamProfile2DB::endJob() { edm::Service poolDbService; @@ -117,9 +103,9 @@ void BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("SigmaZ")->setComment("in cm"); desc.add("BetaStar")->setComment("in cm"); desc.add("Emittance")->setComment("in cm"); - desc.add("Alpha")->setComment("in radians"); - desc.add("Phi")->setComment("in radians"); - desc.add("TimeOffset")->setComment("in ns"); + desc.add("Alpha", 0.0)->setComment("in radians"); + desc.add("Phi", 0.0)->setComment("in radians"); + desc.add("TimeOffset", 0.0)->setComment("in ns"); descriptions.addDefault(desc); } diff --git a/IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py b/IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py new file mode 100644 index 0000000000000..4077b19e9fa27 --- /dev/null +++ b/IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py @@ -0,0 +1,53 @@ +import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing + +process = cms.Process("writeBeamProfile2DB") + +options = VarParsing.VarParsing() +options.register('unitTest', + False, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.bool, # string, int, or float + "are we running the unit test?") +options.register('inputTag', + "myTagName", # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.string, # string, int, or float + "output tag name") +options.parseArguments() + + +process.load("FWCore.MessageLogger.MessageLogger_cfi") +from CondCore.CondDB.CondDB_cfi import * + +if options.unitTest : + tag_name = 'simBS_tag' +else: + tag_name = options.inputTag + +################################# +# Produce a SQLITE FILE +################################# +CondDBSimBeamSpotObjects = CondDB.clone(connect = cms.string('sqlite_file:test_%s.db' % tag_name)) # choose an output name +process.PoolDBOutputService = cms.Service("PoolDBOutputService", + CondDBSimBeamSpotObjects, + timetype = cms.untracked.string('runnumber'), + toPut = cms.VPSet(cms.PSet(record = cms.string("SimBeamSpotObjectsRcd"), # SimBeamSpot record + tag = cms.string(tag_name))), # choose your favourite tag + loadBlobStreamer = cms.untracked.bool(False) + ) + +process.source = cms.Source("EmptySource") + +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) + +process.simbeamspotwriter = cms.EDAnalyzer("BeamProfile2DB", + X0 = cms.double(0.0458532), # in cm + Y0 = cms.double(-0.016966), # in cm + Z0 = cms.double(-0.074992), # in cm + SigmaZ = cms.double(3.6), # in cm + BetaStar = cms.double(30.0), # in cm + Emittance = cms.double(3.931e-8) # in cm + ) + +process.p = cms.Path(process.simbeamspotwriter) From 4a4f8bd44642e4ff42df54e8de8ddea7a46d05ae Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sun, 11 Jun 2023 10:56:17 +0200 Subject: [PATCH 3/9] add setters and getters in CondFormats SimBeamSpotObjects --- .../interface/SimBeamSpotObjects.h | 53 +++++++++++++++++-- .../BeamSpotObjects/src/SimBeamSpotObjects.cc | 13 ++++- .../src/BeamProfile2DB.cc | 18 +++---- .../src/BetafuncEvtVtxGenerator.cc | 18 +++---- 4 files changed, 80 insertions(+), 22 deletions(-) diff --git a/CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h b/CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h index 2e968a2e8602b..b4b1ce5c2f34a 100644 --- a/CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h +++ b/CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h @@ -13,17 +13,64 @@ class SimBeamSpotObjects { public: - SimBeamSpotObjects(){}; + /// default constructor + SimBeamSpotObjects() { + fX0 = 0.0; + fY0 = 0.0; + fZ0 = 0.0; + fSigmaZ = 0.0; + fbetastar = 0.0; + femittance = 0.0; + fPhi = 0.0; + fAlpha = 0.0; + fTimeOffset = 0.0; + }; + virtual ~SimBeamSpotObjects(){}; + /// set X, Y, Z positions + void setX(double val) { fX0 = val; } + void setY(double val) { fY0 = val; } + void setZ(double val) { fZ0 = val; } + /// set sigmaZ + void setSigmaZ(double val) { fSigmaZ = val; } + /// set BetaStar and Emittance + void setBetaStar(double val) { fbetastar = val; } + void setEmittance(double val) { femittance = val; } + /// set Phi, Alpha and TimeOffset + void setPhi(double val) { fPhi = val; } + void setAlpha(double val) { fAlpha = val; } + void setTimeOffset(double val) { fTimeOffset = val; } + + /// get X position + double x() const { return fX0; } + /// get Y position + double y() const { return fY0; } + /// get Z position + double z() const { return fZ0; } + /// get sigmaZ + double sigmaZ() const { return fSigmaZ; } + /// get BetaStar + double betaStar() const { return fbetastar; } + /// get Emittance + double emittance() const { return femittance; } + /// get Phi + double phi() const { return fPhi; } + /// get Alpha + double alpha() const { return fAlpha; } + /// get TimeOffset + double timeOffset() const { return fTimeOffset; } + + /// print sim beam spot parameters + void print(std::stringstream& ss) const; + +private: double fX0, fY0, fZ0; double fSigmaZ; double fbetastar, femittance; double fPhi, fAlpha; double fTimeOffset; - void print(std::stringstream& ss) const; - COND_SERIALIZABLE; }; diff --git a/CondFormats/BeamSpotObjects/src/SimBeamSpotObjects.cc b/CondFormats/BeamSpotObjects/src/SimBeamSpotObjects.cc index 3ed60eadb6e8c..2d1973fbcb03b 100644 --- a/CondFormats/BeamSpotObjects/src/SimBeamSpotObjects.cc +++ b/CondFormats/BeamSpotObjects/src/SimBeamSpotObjects.cc @@ -3,7 +3,18 @@ #include void SimBeamSpotObjects::print(std::stringstream& ss) const { - ss << "-----------------------------------------------------\n" << fX0 << std::endl; + ss << "-----------------------------------------------------\n" + << " Sim Beam Spot Data\n\n" + << " X0 = " << x() << " [cm]\n" + << " Y0 = " << y() << " [cm]\n" + << " Z0 = " << z() << " [cm]\n" + << " Sigma Z0 = " << sigmaZ() << " [cm]\n" + << " Beta star = " << betaStar() << " [cm]\n" + << " Emittance X = " << emittance() << " [cm]\n" + << " Phi = " << phi() << " [radians]\n" + << " Alpha = " << alpha() << " [radians]\n" + << " TimeOffset = " << timeOffset() << " [ns]\n" + << "-----------------------------------------------------\n\n"; } std::ostream& operator<<(std::ostream& os, SimBeamSpotObjects beam) { diff --git a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc b/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc index 78d59250fef9c..215031f767aa2 100644 --- a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc +++ b/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc @@ -58,15 +58,15 @@ class BeamProfile2DB : public edm::global::EDAnalyzer<> { namespace { SimBeamSpotObjects read(const edm::ParameterSet& p) { SimBeamSpotObjects ret; - ret.fX0 = p.getParameter("X0") * cm; - ret.fY0 = p.getParameter("Y0") * cm; - ret.fZ0 = p.getParameter("Z0") * cm; - ret.fSigmaZ = p.getParameter("SigmaZ") * cm; - ret.fAlpha = p.getParameter("Alpha") * radian; - ret.fPhi = p.getParameter("Phi") * radian; - ret.fbetastar = p.getParameter("BetaStar") * cm; - ret.femittance = p.getParameter("Emittance") * cm; // this is not the normalized emittance - ret.fTimeOffset = p.getParameter("TimeOffset") * ns * c_light; // HepMC time units are mm + ret.setX(p.getParameter("X0") * cm); + ret.setY(p.getParameter("Y0") * cm); + ret.setZ(p.getParameter("Z0") * cm); + ret.setSigmaZ(p.getParameter("SigmaZ") * cm); + ret.setAlpha(p.getParameter("Alpha") * radian); + ret.setPhi(p.getParameter("Phi") * radian); + ret.setBetaStar(p.getParameter("BetaStar") * cm); + ret.setEmittance(p.getParameter("Emittance") * cm); // this is not the normalized emittance + ret.setTimeOffset(p.getParameter("TimeOffset") * ns * c_light); // HepMC time units are mm return ret; } diff --git a/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc b/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc index 1710c03cf1874..4e9485ee5371d 100644 --- a/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc +++ b/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc @@ -62,15 +62,15 @@ void BetafuncEvtVtxGenerator::update(const edm::EventSetup& iEventSetup) { if (readDB_ && parameterWatcher_.check(iEventSetup)) { edm::ESHandle beamhandle = iEventSetup.getHandle(beamToken_); - fX0 = beamhandle->fX0; - fY0 = beamhandle->fY0; - fZ0 = beamhandle->fZ0; - // falpha=beamhandle->fAlpha; - fSigmaZ = beamhandle->fSigmaZ; - fTimeOffset = beamhandle->fTimeOffset; - fbetastar = beamhandle->fbetastar; - femittance = beamhandle->femittance; - setBoost(beamhandle->fAlpha, beamhandle->fPhi); + fX0 = beamhandle->x(); + fY0 = beamhandle->y(); + fZ0 = beamhandle->z(); + // falpha=beamhandle->alpha(); + fSigmaZ = beamhandle->sigmaZ(); + fTimeOffset = beamhandle->timeOffset(); + fbetastar = beamhandle->betaStar(); + femittance = beamhandle->emittance(); + setBoost(beamhandle->alpha(), beamhandle->phi()); } } From 7ddd3f805be36e1aeabad1af0b99266029498911 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sun, 11 Jun 2023 10:57:13 +0200 Subject: [PATCH 4/9] add Payload Inspector for SimBeamSpotObjects --- .../BeamSpotPayloadInspectorHelper.h | 326 ++++++++++++++++++ .../BeamSpotPlugins/plugins/BuildFile.xml | 6 + .../plugins/SimBeamSpot_PayloadInspector.cc | 33 ++ 3 files changed, 365 insertions(+) create mode 100644 CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc diff --git a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h index 3fa2a88687ada..f785112162aa8 100644 --- a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h +++ b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h @@ -632,4 +632,330 @@ namespace BeamSpotPI { }; } // namespace BeamSpotPI +// Similar namespace for SimBeamSpotObject +namespace SimBeamSpotPI { + + enum parameters { + X = 0, // 0 - Positions + Y = 1, // 1 + Z = 2, // 2 + sigmaZ = 3, // 3 - Widths + betaStar = 4, // 4 + emittance = 5, // 5 + phi = 6, // 6 - Additional parameters + alpha = 7, // 7 + timeOffset = 8, // 8 + END_OF_TYPES = 9, + }; + + /************************************************/ + inline std::string getStringFromParamEnum(const parameters& parameter, const bool addUnits = false) { + switch (parameter) { + case X: + return (addUnits ? "X [cm]" : "X"); + case Y: + return (addUnits ? "Y [cm]" : "Y"); + case Z: + return (addUnits ? "Z [cm]" : "Z"); + case sigmaZ: + return (addUnits ? "#sigma_{Z} [cm]" : "sigmaZ"); + case betaStar: + return (addUnits ? "#beta* [cm]" : "BetaStar"); + case emittance: + return (addUnits ? "Emittance [cm]" : "Emittance"); + case phi: + return (addUnits ? "Phi [rad]" : "Phi"); + case alpha: + return (addUnits ? "Alpha [rad]" : "Alpha"); + case timeOffset: + return (addUnits ? "TimeOffset [ns]" : "TimeOffset"); + default: + return "should never be here"; + } + } + + /** + * Helper class for operations on the Sim Beam Spot Parameters + * It's a simplified representation of the beamspot + * data used as the underlying type for data transfers and comparisons + */ + template + class SimBSParamsHelper { + typedef std::array bshelpdata; + + public: + SimBSParamsHelper(const std::shared_ptr& bs) { + // fill in the values + m_values[0] = bs->x(), m_values[1] = bs->y(), m_values[2] = bs->z(); + m_values[3] = bs->sigmaZ(), m_values[4] = bs->betaStar(), m_values[5] = bs->emittance(); + m_values[6] = bs->phi(), m_values[7] = bs->alpha(), m_values[8] = bs->timeOffset(); + } + + void printDebug(std::stringstream& ss) { + ss << "Dumping SimBeamSpot parameters Data:" << std::endl; + for (uint i = parameters::X; i <= parameters::timeOffset; i++) { + parameters par = static_cast(i); + ss << getStringFromParamEnum(par) << " : " << m_values[i] << std::endl; + ss << std::endl; + } + } + + inline const bshelpdata centralValues() const { return m_values; } + + // get the difference in values + const bshelpdata diffCentralValues(const SimBSParamsHelper& bs2, const bool isPull = false) const { + bshelpdata ret; + for (uint i = parameters::X; i <= parameters::timeOffset; i++) { + ret[i] = this->centralValues()[i] - bs2.centralValues()[i]; + if (isPull) + (this->centralValues()[i] != 0.) ? ret[i] /= this->centralValues()[i] : 0.; + } + return ret; + } + + private: + bshelpdata m_values; + }; + + /************************************************ + Display of Sim Beam Spot parameters + *************************************************/ + template + class DisplayParameters : public cond::payloadInspector::PlotImage { + public: + DisplayParameters() + : cond::payloadInspector::PlotImage( + "Display of SimBeamSpot parameters") {} + + bool fill() override { + auto tag = cond::payloadInspector::PlotBase::getTag<0>(); + auto tagname = tag.name; + auto iov = tag.iovs.front(); + + gStyle->SetHistMinimumZero(kTRUE); + + m_payload = this->fetchPayload(std::get<1>(iov)); + + TCanvas canvas("Sim Beam Spot Parameters Summary", "Sim BeamSpot Parameters summary", 1000, 1000); + canvas.cd(1); + canvas.cd(1)->SetTopMargin(0.05); + canvas.cd(1)->SetBottomMargin(0.06); + canvas.cd(1)->SetLeftMargin(0.25); + canvas.cd(1)->SetRightMargin(0.01); + canvas.cd(1)->Modified(); + canvas.cd(1)->SetGrid(); + + auto h2_SimBSParameters = std::make_unique("Parameters", "", 1, 0.0, 1.0, 9, 0, 9.); + h2_SimBSParameters->SetStats(false); + + std::function cutFunctor = [this](parameters my_param) { + double ret(-999.); + switch (my_param) { + case X: + return m_payload->x(); + case Y: + return m_payload->y(); + case Z: + return m_payload->z(); + case sigmaZ: + return m_payload->sigmaZ(); + case betaStar: + return m_payload->betaStar(); + case emittance: + return m_payload->emittance(); + case phi: + return m_payload->phi(); + case alpha: + return m_payload->alpha(); + case timeOffset: + return m_payload->timeOffset(); + case END_OF_TYPES: + return ret; + default: + return ret; + } + }; + + h2_SimBSParameters->GetXaxis()->SetBinLabel(1, "Value"); + + unsigned int yBin = 9; + for (int foo = parameters::X; foo <= parameters::timeOffset; foo++) { + parameters param = static_cast(foo); + std::string theLabel = getStringFromParamEnum(param, true); + h2_SimBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str()); + h2_SimBSParameters->SetBinContent(1, yBin, cutFunctor(param)); + yBin--; + } + + h2_SimBSParameters->GetXaxis()->LabelsOption("h"); + h2_SimBSParameters->GetYaxis()->SetLabelSize(0.05); + h2_SimBSParameters->GetXaxis()->SetLabelSize(0.05); + h2_SimBSParameters->SetMarkerSize(1.5); + h2_SimBSParameters->Draw("TEXT"); + + auto ltx = TLatex(); + ltx.SetTextFont(62); + ltx.SetTextSize(0.025); + ltx.SetTextAlign(11); + + auto runLS = BeamSpotPI::unpack(std::get<0>(iov)); + + ltx.DrawLatexNDC( + gPad->GetLeftMargin(), + 1 - gPad->GetTopMargin() + 0.01, + (tagname + " IOV: #color[4]{" + std::to_string(runLS.first) + "," + std::to_string(runLS.second) + "}") + .c_str()); + + std::string fileName(this->m_imageFileName); + canvas.SaveAs(fileName.c_str()); + + return true; + } + + protected: + std::shared_ptr m_payload; + }; + + /************************************************ + Display of Sim Beam Spot parameters difference + *************************************************/ + template + class DisplayParametersDiff : public cond::payloadInspector::PlotImage { + public: + DisplayParametersDiff() + : cond::payloadInspector::PlotImage( + "Display of Sim BeamSpot parameters differences") {} + + bool fill() override { + // trick to deal with the multi-ioved tag and two tag case at the same time + auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs; + auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name; + std::string l_tagname = ""; + auto firstiov = theIOVs.front(); + std::tuple lastiov; + + // we don't support (yet) comparison with more than 2 tags + assert(this->m_plotAnnotations.ntags < 3); + + if (this->m_plotAnnotations.ntags == 2) { + auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs; + l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name; + lastiov = tag2iovs.front(); + } else { + lastiov = theIOVs.back(); + } + + l_payload = this->fetchPayload(std::get<1>(lastiov)); + f_payload = this->fetchPayload(std::get<1>(firstiov)); + + std::string lastIOVsince = std::to_string(std::get<0>(lastiov)); + std::string firstIOVsince = std::to_string(std::get<0>(firstiov)); + + TCanvas canvas( + "Sim Beam Spot Parameters Difference Summary", "Sim Beam Spot Parameters Difference summary", 1000, 1000); + canvas.cd(1); + canvas.cd(1)->SetTopMargin(0.10); + canvas.cd(1)->SetBottomMargin(0.06); + canvas.cd(1)->SetLeftMargin(0.23); + canvas.cd(1)->SetRightMargin(0.16); + canvas.cd(1)->Modified(); + canvas.cd(1)->SetGrid(); + + // for the "text"-filled histogram + auto h2_SimBSParameters = std::make_unique("Parameters", "", 1, 0.0, 1.0, 9, 0, 9.); + h2_SimBSParameters->SetStats(false); + h2_SimBSParameters->GetXaxis()->SetBinLabel(1, "Value"); + h2_SimBSParameters->GetXaxis()->LabelsOption("h"); + h2_SimBSParameters->GetYaxis()->SetLabelSize(0.05); + h2_SimBSParameters->GetXaxis()->SetLabelSize(0.05); + h2_SimBSParameters->SetMarkerSize(1.5); + + // prepare the arrays to fill the histogram + SimBeamSpotPI::SimBSParamsHelper fBS(f_payload); + SimBeamSpotPI::SimBSParamsHelper lBS(l_payload); + +#ifdef MM_DEBUG + std::stringstream ss1, ss2; + edm::LogPrint("") << "**** first payload"; + fBS.printDebug(ss1); + edm::LogPrint("") << ss1.str(); + edm::LogPrint("") << "**** last payload"; + lBS.printDebug(ss2); + edm::LogPrint("") << ss2.str(); +#endif + + const auto diffPars = fBS.diffCentralValues(lBS); + //const auto pullPars = fBS.diffCentralValues(lBS,true /*normalize*/); + + unsigned int yBin = 9; + for (int foo = parameters::X; foo <= parameters::timeOffset; foo++) { + parameters param = static_cast(foo); + std::string theLabel = SimBeamSpotPI::getStringFromParamEnum(param, true /*use units*/); + h2_SimBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str()); + h2_SimBSParameters->SetBinContent(1, yBin, diffPars[foo]); /* profiting of the parameters enum indexing */ + yBin--; + } + + // for the "colz"-filled histogram (clonde from the text-based one) + auto h2_SimBSShadow = (TH2F*)(h2_SimBSParameters->Clone("shadow")); + h2_SimBSShadow->GetZaxis()->SetTitle("#Delta Parameter(payload A - payload B)"); + h2_SimBSShadow->GetZaxis()->CenterTitle(); + h2_SimBSShadow->GetZaxis()->SetTitleOffset(1.5); + + // this is the fine gradient palette (blue to red) + double max = h2_SimBSShadow->GetMaximum(); + double min = h2_SimBSShadow->GetMinimum(); + double val_white = 0.; + double per_white = (max != min) ? ((val_white - min) / (max - min)) : 0.5; + + const int Number = 3; + double Red[Number] = {0., 1., 1.}; + double Green[Number] = {0., 1., 0.}; + double Blue[Number] = {1., 1., 0.}; + double Stops[Number] = {0., per_white, 1.}; + int nb = 256; + h2_SimBSShadow->SetContour(nb); + TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb); + + h2_SimBSShadow->Draw("colz"); + h2_SimBSParameters->Draw("TEXTsame"); + + auto ltx = TLatex(); + ltx.SetTextFont(62); + ltx.SetTextSize(0.025); + ltx.SetTextAlign(11); + + // compute the (run,LS) pairs + auto l_runLS = BeamSpotPI::unpack(std::get<0>(lastiov)); + std::string l_runLSs = "(" + std::to_string(l_runLS.first) + "," + std::to_string(l_runLS.second) + ")"; + auto f_runLS = BeamSpotPI::unpack(std::get<0>(firstiov)); + std::string f_runLSs = "(" + std::to_string(f_runLS.first) + "," + std::to_string(f_runLS.second) + ")"; + + if (this->m_plotAnnotations.ntags == 2) { + ltx.DrawLatexNDC( + gPad->GetLeftMargin(), + 1 - gPad->GetTopMargin() + 0.025, + (fmt::sprintf( + "#splitline{A = #color[4]{%s}: %s}{B = #color[4]{%s}: %s}", f_tagname, f_runLSs, l_tagname, l_runLSs)) + .c_str()); + } else { + ltx.DrawLatexNDC( + gPad->GetLeftMargin(), + 1 - gPad->GetTopMargin() + 0.025, + (fmt::sprintf("#splitline{#color[4]{%s}}{A = %s | B = %s}", f_tagname, l_runLSs, f_runLSs)).c_str()); + } + + std::string fileName(this->m_imageFileName); + canvas.SaveAs(fileName.c_str()); + + return true; + } + + protected: + std::shared_ptr f_payload; + std::shared_ptr l_payload; + }; + +} // namespace SimBeamSpotPI + #endif diff --git a/CondCore/BeamSpotPlugins/plugins/BuildFile.xml b/CondCore/BeamSpotPlugins/plugins/BuildFile.xml index dce62f068af36..4ed737eff59eb 100644 --- a/CondCore/BeamSpotPlugins/plugins/BuildFile.xml +++ b/CondCore/BeamSpotPlugins/plugins/BuildFile.xml @@ -9,3 +9,9 @@ + + + + + + diff --git a/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc b/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc new file mode 100644 index 0000000000000..d56af467a52f5 --- /dev/null +++ b/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc @@ -0,0 +1,33 @@ +#include "CondCore/Utilities/interface/PayloadInspectorModule.h" +#include "CondCore/Utilities/interface/PayloadInspector.h" +#include "CondCore/CondDB/interface/Time.h" + +#include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h" +#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" + +namespace { + + using namespace SimBeamSpotPI; + + /************************************************ + Display of Sim Beam Spot parameters + *************************************************/ + + typedef DisplayParameters SimBeamSpotParameters; + + /************************************************ + Display of Sim Beam Spot parameters Differences + *************************************************/ + + typedef DisplayParametersDiff + SimBeamSpotParametersDiffSingleTag; + typedef DisplayParametersDiff + SimBeamSpotParametersDiffTwoTags; + +} // namespace + +PAYLOAD_INSPECTOR_MODULE(SimBeamSpot) { + PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParameters); + PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParametersDiffSingleTag); + PAYLOAD_INSPECTOR_CLASS(SimBeamSpotParametersDiffTwoTags); +} From 68fbaac1ecd3b774eb46f6cdfb99358e89e2e33a Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sun, 11 Jun 2023 11:21:38 +0200 Subject: [PATCH 5/9] Move SimBeamSpotObject producers to CondTools/BeamSpot --- CondTools/BeamSpot/BuildFile.xml | 1 + .../src => CondTools/BeamSpot/plugins}/BeamProfile2DB.cc | 2 +- .../BeamSpot}/test/BeamProfile2DBWriter_cfg.py | 8 +++++++- IOMC/EventVertexGenerators/BuildFile.xml | 1 - 4 files changed, 9 insertions(+), 3 deletions(-) rename {IOMC/EventVertexGenerators/src => CondTools/BeamSpot/plugins}/BeamProfile2DB.cc (98%) rename {IOMC/EventVertexGenerators => CondTools/BeamSpot}/test/BeamProfile2DBWriter_cfg.py (81%) diff --git a/CondTools/BeamSpot/BuildFile.xml b/CondTools/BeamSpot/BuildFile.xml index c29c5e0b51236..7ea3d0c066574 100644 --- a/CondTools/BeamSpot/BuildFile.xml +++ b/CondTools/BeamSpot/BuildFile.xml @@ -1,6 +1,7 @@ + diff --git a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc b/CondTools/BeamSpot/plugins/BeamProfile2DB.cc similarity index 98% rename from IOMC/EventVertexGenerators/src/BeamProfile2DB.cc rename to CondTools/BeamSpot/plugins/BeamProfile2DB.cc index 215031f767aa2..ad945628b3ea3 100644 --- a/IOMC/EventVertexGenerators/src/BeamProfile2DB.cc +++ b/CondTools/BeamSpot/plugins/BeamProfile2DB.cc @@ -106,7 +106,7 @@ void BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add("Alpha", 0.0)->setComment("in radians"); desc.add("Phi", 0.0)->setComment("in radians"); desc.add("TimeOffset", 0.0)->setComment("in ns"); - descriptions.addDefault(desc); + descriptions.addWithDefaultLabel(desc); } //define this as a plug-in diff --git a/IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py b/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py similarity index 81% rename from IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py rename to CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py index 4077b19e9fa27..b8238cb675b59 100644 --- a/IOMC/EventVertexGenerators/test/BeamProfile2DBWriter_cfg.py +++ b/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py @@ -42,12 +42,18 @@ process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) process.simbeamspotwriter = cms.EDAnalyzer("BeamProfile2DB", - X0 = cms.double(0.0458532), # in cm + X0 = cms.double(0.0458532), # in cm # Early 2023 Y0 = cms.double(-0.016966), # in cm Z0 = cms.double(-0.074992), # in cm SigmaZ = cms.double(3.6), # in cm BetaStar = cms.double(30.0), # in cm Emittance = cms.double(3.931e-8) # in cm + #X0 = cms.double(0.1027975), # in cm # EOY 2022 + #Y0 = cms.double(-0.016762), # in cm + #Z0 = cms.double(0.101756), # in cm + #SigmaZ = cms.double(3.4), # in cm + #BetaStar = cms.double(30.0), # in cm + #Emittance = cms.double(4.276e-8) # in cm ) process.p = cms.Path(process.simbeamspotwriter) diff --git a/IOMC/EventVertexGenerators/BuildFile.xml b/IOMC/EventVertexGenerators/BuildFile.xml index f499f663df824..ed8376e250ee2 100644 --- a/IOMC/EventVertexGenerators/BuildFile.xml +++ b/IOMC/EventVertexGenerators/BuildFile.xml @@ -11,4 +11,3 @@ - From ad63263ea65605a2c5857161fa0a90930cf7d6f9 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sun, 11 Jun 2023 12:55:11 +0200 Subject: [PATCH 6/9] armonize SimBeamSpotObjects units --- CondTools/BeamSpot/plugins/BeamProfile2DB.cc | 29 +++++++------------ .../src/BetafuncEvtVtxGenerator.cc | 19 ++++++------ 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/CondTools/BeamSpot/plugins/BeamProfile2DB.cc b/CondTools/BeamSpot/plugins/BeamProfile2DB.cc index ad945628b3ea3..cced0908f064f 100644 --- a/CondTools/BeamSpot/plugins/BeamProfile2DB.cc +++ b/CondTools/BeamSpot/plugins/BeamProfile2DB.cc @@ -55,27 +55,20 @@ class BeamProfile2DB : public edm::global::EDAnalyzer<> { SimBeamSpotObjects beamSpot_; }; -namespace { - SimBeamSpotObjects read(const edm::ParameterSet& p) { - SimBeamSpotObjects ret; - ret.setX(p.getParameter("X0") * cm); - ret.setY(p.getParameter("Y0") * cm); - ret.setZ(p.getParameter("Z0") * cm); - ret.setSigmaZ(p.getParameter("SigmaZ") * cm); - ret.setAlpha(p.getParameter("Alpha") * radian); - ret.setPhi(p.getParameter("Phi") * radian); - ret.setBetaStar(p.getParameter("BetaStar") * cm); - ret.setEmittance(p.getParameter("Emittance") * cm); // this is not the normalized emittance - ret.setTimeOffset(p.getParameter("TimeOffset") * ns * c_light); // HepMC time units are mm - return ret; - } - -} // namespace - // // constructors and destructor // -BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) : beamSpot_(read(iConfig)) {} +BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) { + beamSpot_.setX(iConfig.getParameter("X0")); + beamSpot_.setY(iConfig.getParameter("Y0")); + beamSpot_.setZ(iConfig.getParameter("Z0")); + beamSpot_.setSigmaZ(iConfig.getParameter("SigmaZ")); + beamSpot_.setAlpha(iConfig.getParameter("Alpha")); + beamSpot_.setPhi(iConfig.getParameter("Phi")); + beamSpot_.setBetaStar(iConfig.getParameter("BetaStar")); + beamSpot_.setEmittance(iConfig.getParameter("Emittance")); + beamSpot_.setTimeOffset(iConfig.getParameter("TimeOffset")); +} BeamProfile2DB::~BeamProfile2DB() = default; diff --git a/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc b/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc index 4e9485ee5371d..b09af7a6337ed 100644 --- a/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc +++ b/IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc @@ -48,6 +48,8 @@ BetafuncEvtVtxGenerator::BetafuncEvtVtxGenerator(const edm::ParameterSet& p) : B } } if (readDB_) { + // NOTE: this is currently watching LS transitions, while it should watch Run transitions, + // even though in reality there is no Run Dependent MC (yet) in CMS beamToken_ = esConsumes(); } } @@ -62,15 +64,14 @@ void BetafuncEvtVtxGenerator::update(const edm::EventSetup& iEventSetup) { if (readDB_ && parameterWatcher_.check(iEventSetup)) { edm::ESHandle beamhandle = iEventSetup.getHandle(beamToken_); - fX0 = beamhandle->x(); - fY0 = beamhandle->y(); - fZ0 = beamhandle->z(); - // falpha=beamhandle->alpha(); - fSigmaZ = beamhandle->sigmaZ(); - fTimeOffset = beamhandle->timeOffset(); - fbetastar = beamhandle->betaStar(); - femittance = beamhandle->emittance(); - setBoost(beamhandle->alpha(), beamhandle->phi()); + fX0 = beamhandle->x() * cm; + fY0 = beamhandle->y() * cm; + fZ0 = beamhandle->z() * cm; + fSigmaZ = beamhandle->sigmaZ() * cm; + fTimeOffset = beamhandle->timeOffset() * ns * c_light; // HepMC time units are mm + fbetastar = beamhandle->betaStar() * cm; + femittance = beamhandle->emittance() * cm; + setBoost(beamhandle->alpha() * radian, beamhandle->phi() * radian); } } From 03af6ab3e159c2651cd10291e0dd6eabc07e2215 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Sun, 11 Jun 2023 22:09:42 +0200 Subject: [PATCH 7/9] add SimBeamSpotObjects reader and use cfi files --- .../BeamSpot/plugins/BeamProfile2DBReader.cc | 183 ++++++++++++++++++ ...mProfile2DB.cc => BeamProfile2DBWriter.cc} | 26 +-- .../BeamSpot/python/BeamProfile2DBRead_cfi.py | 5 + .../BeamSpot/test/BeamProfile2DBReader_cfg.py | 68 +++++++ .../BeamSpot/test/BeamProfile2DBWriter_cfg.py | 25 +-- 5 files changed, 278 insertions(+), 29 deletions(-) create mode 100644 CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc rename CondTools/BeamSpot/plugins/{BeamProfile2DB.cc => BeamProfile2DBWriter.cc} (79%) create mode 100644 CondTools/BeamSpot/python/BeamProfile2DBRead_cfi.py create mode 100644 CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py diff --git a/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc b/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc new file mode 100644 index 0000000000000..2e678fb9018d1 --- /dev/null +++ b/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc @@ -0,0 +1,183 @@ +// -*- C++ -*- +// +// Package: CondTools/BeamProfile2DBReader +// Class: BeamProfile2DBReader +// +/**\class BeamProfile2DBReader BeamProfile2DBReader.cc CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc + + Description: simple emd::one::EDAnalyzer to retrieve and ntuplize SimBeamSpot data from the conditions database + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Francesco Brivio +// Created: 11 June 2023 +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/ESWatcher.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h" +#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" + +// For ROOT +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include + +#include +#include + +// +// class declaration +// + +class BeamProfile2DBReader : public edm::one::EDAnalyzer { +public: + explicit BeamProfile2DBReader(const edm::ParameterSet&); + ~BeamProfile2DBReader() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void beginJob() override; + void analyze(const edm::Event&, const edm::EventSetup&) override; + + struct theBSfromDB { + int run; + int ls; + double fX0, fY0, fZ0; + double fSigmaZ; + double fbetastar, femittance; + double fPhi, fAlpha; + double fTimeOffset; + void init(); + } theBSfromDB_; + + const edm::ESGetToken beamSpotToken_; + edm::Service tFileService; + TTree* bstree_; + + // ----------member data --------------------------- + edm::ESWatcher watcher_; + std::unique_ptr output_; +}; + +// +// constructors and destructor +// +BeamProfile2DBReader::BeamProfile2DBReader(const edm::ParameterSet& iConfig) + : beamSpotToken_(esConsumes()), bstree_(nullptr) { + //now do what ever initialization is needed + usesResource("TFileService"); + std::string fileName(iConfig.getUntrackedParameter("rawFileName")); + if (!fileName.empty()) { + output_ = std::make_unique(fileName.c_str()); + if (!output_->good()) { + edm::LogError("IOproblem") << "Could not open output file " << fileName << "."; + output_.reset(); + } + } +} + +BeamProfile2DBReader::~BeamProfile2DBReader() = default; + +// +// member functions +// + +void BeamProfile2DBReader::theBSfromDB::init() { + float dummy_double = 0.0; + int dummy_int = 0; + + run = dummy_int; + ls = dummy_int; + fX0 = dummy_double; + fY0 = dummy_double; + fZ0 = dummy_double; + fSigmaZ = dummy_double; + fbetastar = dummy_double; + femittance = dummy_double; + fPhi = dummy_double; + fAlpha = dummy_double; + fTimeOffset = dummy_double; +} + +// ------------ method called for each event ------------ +void BeamProfile2DBReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + using namespace edm; + std::ostringstream output; + + // initialize the ntuple + theBSfromDB_.init(); + + if (watcher_.check(iSetup)) { // check for new IOV for this run / LS + + output << " for runs: " << iEvent.id().run() << " - " << iEvent.id().luminosityBlock() << std::endl; + + // Get SimBeamSpot from EventSetup: + const SimBeamSpotObjects* mybeamspot = &iSetup.getData(beamSpotToken_); + + theBSfromDB_.run = iEvent.id().run(); + theBSfromDB_.ls = iEvent.id().luminosityBlock(); + theBSfromDB_.fX0 = mybeamspot->x(); + theBSfromDB_.fY0 = mybeamspot->y(); + theBSfromDB_.fZ0 = mybeamspot->z(); + theBSfromDB_.fSigmaZ = mybeamspot->sigmaZ(); + theBSfromDB_.fbetastar = mybeamspot->betaStar(); + theBSfromDB_.femittance = mybeamspot->emittance(); + theBSfromDB_.fPhi = mybeamspot->phi(); + theBSfromDB_.fAlpha = mybeamspot->alpha(); + theBSfromDB_.fTimeOffset = mybeamspot->timeOffset(); + bstree_->Fill(); + output << *mybeamspot << std::endl; + } + + // Final output - either message logger or output file: + if (output_.get()) + *output_ << output.str(); + else + edm::LogInfo("") << output.str(); +} + +// ------------ method called once each job just before starting event loop ------------ +void BeamProfile2DBReader::beginJob() { + bstree_ = tFileService->make("BSNtuple", "SimBeamSpot analyzer ntuple"); + + //Tree Branches + bstree_->Branch("run", &theBSfromDB_.run, "run/I"); + bstree_->Branch("ls", &theBSfromDB_.ls, "ls/I"); + bstree_->Branch("BSx0", &theBSfromDB_.fX0, "BSx0/F"); + bstree_->Branch("BSy0", &theBSfromDB_.fY0, "BSy0/F"); + bstree_->Branch("BSz0", &theBSfromDB_.fZ0, "BSz0/F"); + bstree_->Branch("Beamsigmaz", &theBSfromDB_.fSigmaZ, "Beamsigmaz/F"); + bstree_->Branch("BetaStar", &theBSfromDB_.fbetastar, "BetaStar/F"); + bstree_->Branch("Emittance", &theBSfromDB_.femittance, "Emittance/F"); + bstree_->Branch("Phi", &theBSfromDB_.fPhi, "Phi/F"); + bstree_->Branch("Alpha", &theBSfromDB_.fAlpha, "Alpha/F"); + bstree_->Branch("TimeOffset", &theBSfromDB_.fTimeOffset, "TimeOffset/F"); +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void BeamProfile2DBReader::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(BeamProfile2DBReader); diff --git a/CondTools/BeamSpot/plugins/BeamProfile2DB.cc b/CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc similarity index 79% rename from CondTools/BeamSpot/plugins/BeamProfile2DB.cc rename to CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc index cced0908f064f..cbfe48e075ff3 100644 --- a/CondTools/BeamSpot/plugins/BeamProfile2DB.cc +++ b/CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc @@ -1,9 +1,9 @@ // -*- C++ -*- // -// Package: BeamProfile2DB -// Class: BeamProfile2DB +// Package: BeamProfile2DBWriter +// Class: BeamProfile2DBWriter // -/**\class BeamProfile2DB BeamProfile2DB.cc IOMC/BeamProfile2DB/src/BeamProfile2DB.cc +/**\class BeamProfile2DBWriter BeamProfile2DBWriter.cc CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc Description: [one line class summary] @@ -14,6 +14,7 @@ // Original Author: Jean-Roch Vlimant,40 3-A28,+41227671209, // Created: Fri Jan 6 14:49:42 CET 2012 // +// Updated; Francesco Brivio, June 11, 2023 // // system include files @@ -39,11 +40,10 @@ // // class declaration // - -class BeamProfile2DB : public edm::global::EDAnalyzer<> { +class BeamProfile2DBWriter : public edm::global::EDAnalyzer<> { public: - explicit BeamProfile2DB(const edm::ParameterSet&); - ~BeamProfile2DB() override; + explicit BeamProfile2DBWriter(const edm::ParameterSet&); + ~BeamProfile2DBWriter() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); @@ -58,7 +58,7 @@ class BeamProfile2DB : public edm::global::EDAnalyzer<> { // // constructors and destructor // -BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) { +BeamProfile2DBWriter::BeamProfile2DBWriter(const edm::ParameterSet& iConfig) { beamSpot_.setX(iConfig.getParameter("X0")); beamSpot_.setY(iConfig.getParameter("Y0")); beamSpot_.setZ(iConfig.getParameter("Z0")); @@ -70,23 +70,23 @@ BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig) { beamSpot_.setTimeOffset(iConfig.getParameter("TimeOffset")); } -BeamProfile2DB::~BeamProfile2DB() = default; +BeamProfile2DBWriter::~BeamProfile2DBWriter() = default; // // member functions // // ------------ method called for each event ------------ -void BeamProfile2DB::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {} +void BeamProfile2DBWriter::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {} // ------------ method called once each job just after ending the event loop ------------ -void BeamProfile2DB::endJob() { +void BeamProfile2DBWriter::endJob() { edm::Service poolDbService; poolDbService->createOneIOV(beamSpot_, poolDbService->beginOfTime(), "SimBeamSpotObjectsRcd"); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void BeamProfile2DBWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { //The following says we do not know what parameters are allowed so do no validation // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; @@ -103,4 +103,4 @@ void BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptio } //define this as a plug-in -DEFINE_FWK_MODULE(BeamProfile2DB); +DEFINE_FWK_MODULE(BeamProfile2DBWriter); diff --git a/CondTools/BeamSpot/python/BeamProfile2DBRead_cfi.py b/CondTools/BeamSpot/python/BeamProfile2DBRead_cfi.py new file mode 100644 index 0000000000000..1a3c33bb84de7 --- /dev/null +++ b/CondTools/BeamSpot/python/BeamProfile2DBRead_cfi.py @@ -0,0 +1,5 @@ +import FWCore.ParameterSet.Config as cms + +BeamProfile2DBRead = cms.EDAnalyzer("BeamProfile2DBReader", + rawFileName = cms.untracked.string("") + ) diff --git a/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py b/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py new file mode 100644 index 0000000000000..c2e6594bb6098 --- /dev/null +++ b/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py @@ -0,0 +1,68 @@ +import FWCore.ParameterSet.Config as cms + +process = cms.Process("READ") + +process.load("FWCore.MessageService.MessageLogger_cfi") +#process.MessageLogger.cerr.FwkReport.reportEvery = 1000000 # do not clog output with IO + +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) # large number of events is needed since we probe 5000LS for run (see below) + +#################################################################### +# Empty source +#################################################################### + +process.source = cms.Source("EmptySource", + firstRun = cms.untracked.uint32(1), + firstLuminosityBlock = cms.untracked.uint32(1), # probe one LS after the other + numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS + numberEventsInRun = cms.untracked.uint32(1), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h) + ) + +#################################################################### +# Connect to conditions DB +#################################################################### + +# either from Global Tag +# process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cfi") +# from Configuration.AlCa.GlobalTag import GlobalTag +# process.GlobalTag = GlobalTag(process.GlobalTag,"auto:phase1_2023_realistic") + +# ...or specify database connection and tag... +# from CondCore.CondDB.CondDB_cfi import * +# CondDBSimBeamSpot = CondDB.clone(connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS')) +# process.dbInput = cms.ESSource("PoolDBESSource", +# CondDBSimBeamSpot, +# toGet = cms.VPSet(cms.PSet(record = cms.string('SimBeamSpotObjectsRcd'), +# tag = cms.string('your_tag_name') # customize with input tag name +# ) +# ) +# ) + +# ...or specify local db file: +from CondCore.CondDB.CondDB_cfi import * +CondDBSimBeamSpot = CondDB.clone(connect = cms.string("sqlite_file:your_db_file.db")) # customize with input db file +process.PoolDBESSource = cms.ESSource("PoolDBESSource", + CondDBSimBeamSpot, + DumpStat=cms.untracked.bool(True), + toGet = cms.VPSet(cms.PSet( + record = cms.string('SimBeamSpotObjectsRcd'), + tag = cms.string('your_tag_name') # customize with input tag name + )) +) + + +#################################################################### +# Load and configure analyzer +#################################################################### +process.load("CondTools.BeamSpot.BeamProfile2DBRead_cfi") +process.BeamProfile2DBRead.rawFileName = 'reference_SimBeamSpotObjects.txt' + +#################################################################### +# Output file +#################################################################### +process.TFileService = cms.Service("TFileService", + fileName=cms.string("reference_SimBeamSpotObjects.root") + ) + +# Put module in path: +process.p = cms.Path(process.BeamProfile2DBRead) diff --git a/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py b/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py index b8238cb675b59..ba907148ba074 100644 --- a/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py +++ b/CondTools/BeamSpot/test/BeamProfile2DBWriter_cfg.py @@ -41,19 +41,12 @@ process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) -process.simbeamspotwriter = cms.EDAnalyzer("BeamProfile2DB", - X0 = cms.double(0.0458532), # in cm # Early 2023 - Y0 = cms.double(-0.016966), # in cm - Z0 = cms.double(-0.074992), # in cm - SigmaZ = cms.double(3.6), # in cm - BetaStar = cms.double(30.0), # in cm - Emittance = cms.double(3.931e-8) # in cm - #X0 = cms.double(0.1027975), # in cm # EOY 2022 - #Y0 = cms.double(-0.016762), # in cm - #Z0 = cms.double(0.101756), # in cm - #SigmaZ = cms.double(3.4), # in cm - #BetaStar = cms.double(30.0), # in cm - #Emittance = cms.double(4.276e-8) # in cm - ) - -process.p = cms.Path(process.simbeamspotwriter) +process.load("CondTools.BeamSpot.beamProfile2DBWriter_cfi") +process.beamProfile2DBWriter.X0 = 0.0458532 +process.beamProfile2DBWriter.Y0 = -0.016966 +process.beamProfile2DBWriter.Z0 = -0.074992 +process.beamProfile2DBWriter.SigmaZ = 3.6 +process.beamProfile2DBWriter.BetaStar = 30.0 +process.beamProfile2DBWriter.Emittance = 3.931e-8 + +process.p = cms.Path(process.beamProfile2DBWriter) From 78ee4e1ebe5e720ae1423630f2580d8465042336 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Mon, 12 Jun 2023 18:43:22 +0200 Subject: [PATCH 8/9] apply cms naming rules and alpha-order imports --- .../BeamSpotPayloadInspectorHelper.h | 66 +++++++++---------- .../BeamSpotOnline_PayloadInspector.cc | 8 +-- .../plugins/BeamSpot_PayloadInspector.cc | 9 ++- .../plugins/SimBeamSpot_PayloadInspector.cc | 9 ++- .../BeamSpot/plugins/BeamProfile2DBReader.cc | 27 ++++---- .../BeamSpot/plugins/BeamProfile2DBWriter.cc | 10 +-- 6 files changed, 60 insertions(+), 69 deletions(-) diff --git a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h index f785112162aa8..7479260083e65 100644 --- a/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h +++ b/CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h @@ -2,11 +2,11 @@ #define CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H // User includes -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "CondCore/Utilities/interface/PayloadInspectorModule.h" -#include "CondCore/Utilities/interface/PayloadInspector.h" #include "CondCore/CondDB/interface/Time.h" +#include "CondCore/Utilities/interface/PayloadInspector.h" +#include "CondCore/Utilities/interface/PayloadInspectorModule.h" #include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" // system includes #include @@ -15,13 +15,13 @@ // ROOT includes #include "TCanvas.h" -#include "TStyle.h" #include "TH2F.h" #include "TLatex.h" +#include "TStyle.h" //#define MMDEBUG /* to make it verbose */ -namespace BeamSpotPI { +namespace beamSpotPI { inline std::pair unpack(cond::Time_t since) { auto kLowMask = 0XFFFFFFFF; @@ -396,7 +396,7 @@ namespace BeamSpotPI { } ltx.SetTextAlign(11); - auto runLS = BeamSpotPI::unpack(std::get<0>(iov)); + auto runLS = beamSpotPI::unpack(std::get<0>(iov)); ltx.DrawLatexNDC( gPad->GetLeftMargin(), @@ -448,7 +448,7 @@ namespace BeamSpotPI { std::shared_ptr m_payload; /** - * Can't use BeamSpotPI::getStringFromParamEnum becasue it needs to be overridden + * Can't use beamSpotPI::getStringFromParamEnum becasue it needs to be overridden * for the BeamSpotOnlineObjects case. */ virtual std::string getStringFromTypeEnum(const parameters& parameter) const { @@ -536,8 +536,8 @@ namespace BeamSpotPI { h2_BSParameters->SetMarkerSize(1.5); // prepare the arrays to fill the histogram - BeamSpotPI::BSParamsHelper fBS(f_payload); - BeamSpotPI::BSParamsHelper lBS(l_payload); + beamSpotPI::BSParamsHelper fBS(f_payload); + beamSpotPI::BSParamsHelper lBS(l_payload); #ifdef MM_DEBUG std::stringstream ss1, ss2; @@ -557,7 +557,7 @@ namespace BeamSpotPI { unsigned int yBin = 8; for (int foo = parameters::X; foo <= parameters::dydz; foo++) { parameters param = static_cast(foo); - std::string theLabel = BeamSpotPI::getStringFromParamEnum(param, true /*use units*/); + std::string theLabel = beamSpotPI::getStringFromParamEnum(param, true /*use units*/); h2_BSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str()); h2_BSParameters->SetBinContent(1, yBin, diffPars[foo]); /* profiting of the parameters enum indexing */ h2_BSParameters->SetBinContent(2, yBin, diffErrors[foo]); @@ -576,14 +576,14 @@ namespace BeamSpotPI { double val_white = 0.; double per_white = (max != min) ? ((val_white - min) / (max - min)) : 0.5; - const int Number = 3; - double Red[Number] = {0., 1., 1.}; - double Green[Number] = {0., 1., 0.}; - double Blue[Number] = {1., 1., 0.}; - double Stops[Number] = {0., per_white, 1.}; + const int number = 3; + double Red[number] = {0., 1., 1.}; + double Green[number] = {0., 1., 0.}; + double Blue[number] = {1., 1., 0.}; + double Stops[number] = {0., per_white, 1.}; int nb = 256; h2_BSShadow->SetContour(nb); - TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb); + TColor::CreateGradientColorTable(number, Stops, Red, Green, Blue, nb); h2_BSShadow->Draw("colz"); h2_BSParameters->Draw("TEXTsame"); @@ -594,9 +594,9 @@ namespace BeamSpotPI { ltx.SetTextAlign(11); // compute the (run,LS) pairs - auto l_runLS = BeamSpotPI::unpack(std::get<0>(lastiov)); + auto l_runLS = beamSpotPI::unpack(std::get<0>(lastiov)); std::string l_runLSs = "(" + std::to_string(l_runLS.first) + "," + std::to_string(l_runLS.second) + ")"; - auto f_runLS = BeamSpotPI::unpack(std::get<0>(firstiov)); + auto f_runLS = beamSpotPI::unpack(std::get<0>(firstiov)); std::string f_runLSs = "(" + std::to_string(f_runLS.first) + "," + std::to_string(f_runLS.second) + ")"; if (this->m_plotAnnotations.ntags == 2) { @@ -630,10 +630,10 @@ namespace BeamSpotPI { std::shared_ptr f_payload; std::shared_ptr l_payload; }; -} // namespace BeamSpotPI +} // namespace beamSpotPI // Similar namespace for SimBeamSpotObject -namespace SimBeamSpotPI { +namespace simBeamSpotPI { enum parameters { X = 0, // 0 - Positions @@ -798,7 +798,7 @@ namespace SimBeamSpotPI { ltx.SetTextSize(0.025); ltx.SetTextAlign(11); - auto runLS = BeamSpotPI::unpack(std::get<0>(iov)); + auto runLS = beamSpotPI::unpack(std::get<0>(iov)); ltx.DrawLatexNDC( gPad->GetLeftMargin(), @@ -871,8 +871,8 @@ namespace SimBeamSpotPI { h2_SimBSParameters->SetMarkerSize(1.5); // prepare the arrays to fill the histogram - SimBeamSpotPI::SimBSParamsHelper fBS(f_payload); - SimBeamSpotPI::SimBSParamsHelper lBS(l_payload); + simBeamSpotPI::SimBSParamsHelper fBS(f_payload); + simBeamSpotPI::SimBSParamsHelper lBS(l_payload); #ifdef MM_DEBUG std::stringstream ss1, ss2; @@ -890,7 +890,7 @@ namespace SimBeamSpotPI { unsigned int yBin = 9; for (int foo = parameters::X; foo <= parameters::timeOffset; foo++) { parameters param = static_cast(foo); - std::string theLabel = SimBeamSpotPI::getStringFromParamEnum(param, true /*use units*/); + std::string theLabel = simBeamSpotPI::getStringFromParamEnum(param, true /*use units*/); h2_SimBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str()); h2_SimBSParameters->SetBinContent(1, yBin, diffPars[foo]); /* profiting of the parameters enum indexing */ yBin--; @@ -908,14 +908,14 @@ namespace SimBeamSpotPI { double val_white = 0.; double per_white = (max != min) ? ((val_white - min) / (max - min)) : 0.5; - const int Number = 3; - double Red[Number] = {0., 1., 1.}; - double Green[Number] = {0., 1., 0.}; - double Blue[Number] = {1., 1., 0.}; - double Stops[Number] = {0., per_white, 1.}; + const int number = 3; + double Red[number] = {0., 1., 1.}; + double Green[number] = {0., 1., 0.}; + double Blue[number] = {1., 1., 0.}; + double Stops[number] = {0., per_white, 1.}; int nb = 256; h2_SimBSShadow->SetContour(nb); - TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, nb); + TColor::CreateGradientColorTable(number, Stops, Red, Green, Blue, nb); h2_SimBSShadow->Draw("colz"); h2_SimBSParameters->Draw("TEXTsame"); @@ -926,9 +926,9 @@ namespace SimBeamSpotPI { ltx.SetTextAlign(11); // compute the (run,LS) pairs - auto l_runLS = BeamSpotPI::unpack(std::get<0>(lastiov)); + auto l_runLS = beamSpotPI::unpack(std::get<0>(lastiov)); std::string l_runLSs = "(" + std::to_string(l_runLS.first) + "," + std::to_string(l_runLS.second) + ")"; - auto f_runLS = BeamSpotPI::unpack(std::get<0>(firstiov)); + auto f_runLS = beamSpotPI::unpack(std::get<0>(firstiov)); std::string f_runLSs = "(" + std::to_string(f_runLS.first) + "," + std::to_string(f_runLS.second) + ")"; if (this->m_plotAnnotations.ntags == 2) { @@ -956,6 +956,6 @@ namespace SimBeamSpotPI { std::shared_ptr l_payload; }; -} // namespace SimBeamSpotPI +} // namespace simBeamSpotPI #endif diff --git a/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc b/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc index c72f2395bd95f..3782998c44197 100644 --- a/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc +++ b/CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc @@ -1,14 +1,14 @@ -#include "CondCore/Utilities/interface/PayloadInspectorModule.h" -#include "CondCore/Utilities/interface/PayloadInspector.h" -#include "CondCore/CondDB/interface/Time.h" #include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h" +#include "CondCore/CondDB/interface/Time.h" +#include "CondCore/Utilities/interface/PayloadInspector.h" +#include "CondCore/Utilities/interface/PayloadInspectorModule.h" #include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" #include namespace { - using namespace BeamSpotPI; + using namespace beamSpotPI; /************************************************ history plots diff --git a/CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc b/CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc index 1f65c538ea782..e53df5be2e0bc 100644 --- a/CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc +++ b/CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc @@ -1,13 +1,12 @@ -#include "CondCore/Utilities/interface/PayloadInspectorModule.h" -#include "CondCore/Utilities/interface/PayloadInspector.h" -#include "CondCore/CondDB/interface/Time.h" - #include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h" +#include "CondCore/CondDB/interface/Time.h" +#include "CondCore/Utilities/interface/PayloadInspector.h" +#include "CondCore/Utilities/interface/PayloadInspectorModule.h" #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" namespace { - using namespace BeamSpotPI; + using namespace beamSpotPI; class BeamSpot_hx : public cond::payloadInspector::HistoryPlot > { public: diff --git a/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc b/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc index d56af467a52f5..1532e61b86425 100644 --- a/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc +++ b/CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc @@ -1,13 +1,12 @@ -#include "CondCore/Utilities/interface/PayloadInspectorModule.h" -#include "CondCore/Utilities/interface/PayloadInspector.h" -#include "CondCore/CondDB/interface/Time.h" - #include "CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h" +#include "CondCore/CondDB/interface/Time.h" +#include "CondCore/Utilities/interface/PayloadInspector.h" +#include "CondCore/Utilities/interface/PayloadInspectorModule.h" #include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" namespace { - using namespace SimBeamSpotPI; + using namespace simBeamSpotPI; /************************************************ Display of Sim Beam Spot parameters diff --git a/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc b/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc index 2e678fb9018d1..3e84c66806489 100644 --- a/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc +++ b/CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc @@ -16,30 +16,27 @@ // // system include files +#include #include +#include // user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/EventSetup.h" +#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" +#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/ESWatcher.h" - +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h" -#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" // For ROOT -#include "FWCore/ServiceRegistry/interface/Service.h" #include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "FWCore/ServiceRegistry/interface/Service.h" #include -#include -#include - // // class declaration // @@ -55,7 +52,7 @@ class BeamProfile2DBReader : public edm::one::EDAnalyzer // user include files +#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" +#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/global/EDAnalyzer.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" - #include "FWCore/ServiceRegistry/interface/Service.h" -#include "CondCore/DBOutputService/interface/PoolDBOutputService.h" -#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" #include "CLHEP/Units/GlobalSystemOfUnits.h" #include "CLHEP/Units/GlobalPhysicalConstants.h" From efca3b965cd433d3c11f23a092bdddab3a173f07 Mon Sep 17 00:00:00 2001 From: francescobrivio Date: Mon, 12 Jun 2023 19:19:12 +0200 Subject: [PATCH 9/9] add unittest for simBeamSpot writer and reader --- .../BeamSpot/test/BeamProfile2DBReader_cfg.py | 47 +++++++++++++++---- CondTools/BeamSpot/test/BuildFile.xml | 2 +- ...mDB.sh => testReadWriteBeamSpotsFromDB.sh} | 14 +++++- 3 files changed, 51 insertions(+), 12 deletions(-) rename CondTools/BeamSpot/test/{testReadWriteOnlineBSFromDB.sh => testReadWriteBeamSpotsFromDB.sh} (76%) diff --git a/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py b/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py index c2e6594bb6098..251dbbef08286 100644 --- a/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py +++ b/CondTools/BeamSpot/test/BeamProfile2DBReader_cfg.py @@ -1,27 +1,56 @@ import FWCore.ParameterSet.Config as cms +import FWCore.ParameterSet.VarParsing as VarParsing process = cms.Process("READ") +options = VarParsing.VarParsing() +options.register('unitTest', + False, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.bool, # string, int, or float + "are we running the unit test?") +options.register('inputTag', + "myTagName", # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.string, # string, int, or float + "output tag name") +options.register('startRun', + 1, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.int, # string, int, or float + "location of the input data") +options.register('startLumi', + 1, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.int, # string, int, or float + "IOV Start Lumi") +options.parseArguments() + process.load("FWCore.MessageService.MessageLogger_cfi") -#process.MessageLogger.cerr.FwkReport.reportEvery = 1000000 # do not clog output with IO +process.MessageLogger.cerr.FwkReport.reportEvery = 1000000 # do not clog output with IO -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) # large number of events is needed since we probe 5000LS for run (see below) +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1) ) # large number of events is needed since we probe 5000LS for run (see below) #################################################################### # Empty source #################################################################### process.source = cms.Source("EmptySource", - firstRun = cms.untracked.uint32(1), - firstLuminosityBlock = cms.untracked.uint32(1), # probe one LS after the other - numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS - numberEventsInRun = cms.untracked.uint32(1), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h) + firstRun = cms.untracked.uint32(options.startRun), + firstLuminosityBlock = cms.untracked.uint32(options.startRun), # probe one LS after the other + numberEventsInLuminosityBlock = cms.untracked.uint32(1), # probe one event per LS + numberEventsInRun = cms.untracked.uint32(1), # a number of events > the number of LS possible in a real run (5000 s ~ 32 h) ) #################################################################### # Connect to conditions DB #################################################################### +if options.unitTest: + tag_name = 'simBS_tag' +else: + tag_name = options.inputTag + # either from Global Tag # process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cfi") # from Configuration.AlCa.GlobalTag import GlobalTag @@ -33,20 +62,20 @@ # process.dbInput = cms.ESSource("PoolDBESSource", # CondDBSimBeamSpot, # toGet = cms.VPSet(cms.PSet(record = cms.string('SimBeamSpotObjectsRcd'), -# tag = cms.string('your_tag_name') # customize with input tag name +# tag = cms.string(tag_name) # customize with input tag name # ) # ) # ) # ...or specify local db file: from CondCore.CondDB.CondDB_cfi import * -CondDBSimBeamSpot = CondDB.clone(connect = cms.string("sqlite_file:your_db_file.db")) # customize with input db file +CondDBSimBeamSpot = CondDB.clone(connect = cms.string("sqlite_file:test_%s.db" % tag_name)) # customize with input db file process.PoolDBESSource = cms.ESSource("PoolDBESSource", CondDBSimBeamSpot, DumpStat=cms.untracked.bool(True), toGet = cms.VPSet(cms.PSet( record = cms.string('SimBeamSpotObjectsRcd'), - tag = cms.string('your_tag_name') # customize with input tag name + tag = cms.string(tag_name) # customize with input tag name )) ) diff --git a/CondTools/BeamSpot/test/BuildFile.xml b/CondTools/BeamSpot/test/BuildFile.xml index 8538937c0b59d..539c958bd1c70 100644 --- a/CondTools/BeamSpot/test/BuildFile.xml +++ b/CondTools/BeamSpot/test/BuildFile.xml @@ -1 +1 @@ - + diff --git a/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh b/CondTools/BeamSpot/test/testReadWriteBeamSpotsFromDB.sh similarity index 76% rename from CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh rename to CondTools/BeamSpot/test/testReadWriteBeamSpotsFromDB.sh index c093957eac86d..619bb71bbf4ea 100755 --- a/CondTools/BeamSpot/test/testReadWriteOnlineBSFromDB.sh +++ b/CondTools/BeamSpot/test/testReadWriteBeamSpotsFromDB.sh @@ -2,7 +2,7 @@ function die { echo $1: status $2 ; exit $2; } -echo "TESTING BeamSpotOnline From DB Read / Write codes ..." +echo "TESTING BeamSpot + BeamSpotOnline + SimBeamSpot From DB Read / Write codes ..." ## clean the input db files if test -f "test_BSHLT_tag.db"; then @@ -13,6 +13,10 @@ if test -f "test_BSLegacy_tag.db"; then rm -fr test_BSLegacy_tag.db fi +if test -f "test_simBS_tag.db"; then + rm -fr test_simBS_tag.db +fi + ## copy the input file cp -pr $CMSSW_BASE/src/CondTools/BeamSpot/data/BeamFitResults_Run306171.txt . @@ -22,8 +26,11 @@ cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsWriter_cfg.py unitTest=True input printf "TESTING Writing BeamSpotOnlineHLTObjectsRcd DB object ...\n\n" cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsWriter_cfg.py unitTest=True inputRecord=BeamSpotOnlineHLTObjectsRcd || die "Failure writing payload for BeamSpotOnlineHLTObjectsRcd" $? -# test read +printf "TESTING Writing SimBeamSpotObjectsRcd DB object ...\n\n" +cmsRun ${SCRAM_TEST_PATH}/BeamProfile2DBWriter_cfg.py unitTest=True || die "Failure writing payload for SimBeamSpotObjectsRcd" $? + +# test read printf "TESTING Reading BeamSpotOnlineLegacyObjectsRcd DB object ...\n\n" cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineRecordsReader_cfg.py unitTest=True inputRecord=BeamSpotOnlineLegacyObjectsRcd || die "Failure reading payload for BeamSpotOnlineLegacyObjectsRcd" $? @@ -35,3 +42,6 @@ cmsRun ${SCRAM_TEST_PATH}/BeamSpotRcdPrinter_cfg.py || die "Failure running Beam printf "TESTING converting BeamSpotOnlineObjects from BeamSpotObjects ...\n\n" cmsRun ${SCRAM_TEST_PATH}/BeamSpotOnlineFromOfflineConverter_cfg.py unitTest=True || die "Failure running BeamSpotRcdPrinter" $? + +printf "TESTING Reading SimBeamSpotObjectsRcd DB object ...\n\n" +cmsRun ${SCRAM_TEST_PATH}/BeamProfile2DBReader_cfg.py unitTest=True || die "Failure reading payload for SimBeamSpotObjectsRcd" $?