Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous improvements to SimBeamSpotObjects handling utilities #41967

Merged
merged 5 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions CondCore/BeamSpotPlugins/interface/BeamSpotPayloadInspectorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <fmt/printf.h>
#include <memory>
#include <sstream>
#include <regex>

// ROOT includes
#include "TCanvas.h"
Expand Down Expand Up @@ -91,19 +92,22 @@ namespace beamSpotPI {
*/
template <class PayloadType>
class BSParamsHelper {
typedef std::array<double, 8> bshelpdata;
typedef std::array<double, parameters::lastLumi> bshelpdata;

public:
BSParamsHelper(const std::shared_ptr<PayloadType>& bs) {
// fill in the central values
m_values[0] = bs->x(), m_values[1] = bs->y(), m_values[2] = bs->z();
m_values[3] = bs->beamWidthX(), m_values[4] = bs->beamWidthY(), m_values[5] = bs->sigmaZ();
m_values[6] = bs->dxdz(), m_values[7] = bs->dydz();
m_values[parameters::X] = bs->x(), m_values[parameters::Y] = bs->y(), m_values[parameters::Z] = bs->z();
m_values[parameters::sigmaX] = bs->beamWidthX(), m_values[parameters::sigmaY] = bs->beamWidthY(),
m_values[parameters::sigmaZ] = bs->sigmaZ();
m_values[parameters::dxdz] = bs->dxdz(), m_values[parameters::dydz] = bs->dydz();

// fill in the errors
m_errors[0] = bs->xError(), m_errors[1] = bs->yError(), m_errors[2] = bs->zError();
m_errors[3] = bs->beamWidthXError(), m_errors[4] = bs->beamWidthYError(), m_errors[5] = bs->sigmaZError();
m_errors[6] = bs->dxdzError(), m_errors[7] = bs->dydzError();
m_errors[parameters::X] = bs->xError(), m_errors[parameters::Y] = bs->yError(),
m_errors[parameters::Z] = bs->zError();
m_errors[parameters::sigmaX] = bs->beamWidthXError(), m_errors[parameters::sigmaY] = bs->beamWidthYError(),
m_errors[parameters::sigmaZ] = bs->sigmaZError();
m_errors[parameters::dxdz] = bs->dxdzError(), m_errors[parameters::dydz] = bs->dydzError();
}

void printDebug(std::stringstream& ss) {
Expand Down Expand Up @@ -636,16 +640,17 @@ namespace beamSpotPI {
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,
X = 0, // 0 - Positions
Y = 1, // 1
Z = 2, // 2
sigmaZ = 3, // 3 - Widths
betaStar = 4, // 4
emittance = 5, // 5
expTransWidth = 6, // 6 - from LPC-like calculation
phi = 7, // 7 - Additional parameters
alpha = 8, // 8
timeOffset = 9, // 9
END_OF_TYPES = 10,
};

/************************************************/
Expand All @@ -663,6 +668,8 @@ namespace simBeamSpotPI {
return (addUnits ? "#beta* [cm]" : "BetaStar");
case emittance:
return (addUnits ? "Emittance [cm]" : "Emittance");
case expTransWidth:
return (addUnits ? "#sigma^{trans}_{xy} [#mum]" : "Exp. trans width");
case phi:
return (addUnits ? "Phi [rad]" : "Phi");
case alpha:
Expand All @@ -681,14 +688,17 @@ namespace simBeamSpotPI {
*/
template <class PayloadType>
class SimBSParamsHelper {
typedef std::array<double, 9> bshelpdata;
typedef std::array<double, parameters::END_OF_TYPES> bshelpdata;

public:
SimBSParamsHelper(const std::shared_ptr<PayloadType>& 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();
m_values[parameters::X] = bs->x(), m_values[parameters::Y] = bs->y(), m_values[parameters::Z] = bs->z();
m_values[parameters::sigmaZ] = bs->sigmaZ(), m_values[parameters::betaStar] = bs->betaStar(),
m_values[parameters::emittance] = bs->emittance();
m_values[parameters::expTransWidth] = (1 / std::sqrt(2)) * std::sqrt(bs->emittance() * bs->betaStar()) * 10000.f;
m_values[parameters::phi] = bs->phi(), m_values[parameters::alpha] = bs->alpha(),
m_values[parameters::timeOffset] = bs->timeOffset();
}

void printDebug(std::stringstream& ss) {
Expand Down Expand Up @@ -745,7 +755,7 @@ namespace simBeamSpotPI {
canvas.cd(1)->Modified();
canvas.cd(1)->SetGrid();

auto h2_SimBSParameters = std::make_unique<TH2F>("Parameters", "", 1, 0.0, 1.0, 9, 0, 9.);
auto h2_SimBSParameters = std::make_unique<TH2F>("Parameters", "", 1, 0.0, 1.0, END_OF_TYPES, 0, END_OF_TYPES);
h2_SimBSParameters->SetStats(false);

std::function<double(parameters)> cutFunctor = [this](parameters my_param) {
Expand All @@ -769,6 +779,8 @@ namespace simBeamSpotPI {
return m_payload->alpha();
case timeOffset:
return m_payload->timeOffset();
case expTransWidth:
return (1 / std::sqrt(2)) * std::sqrt(m_payload->emittance() * m_payload->betaStar()) * cmToUm;
case END_OF_TYPES:
return ret;
default:
Expand All @@ -778,7 +790,7 @@ namespace simBeamSpotPI {

h2_SimBSParameters->GetXaxis()->SetBinLabel(1, "Value");

unsigned int yBin = 9;
unsigned int yBin = END_OF_TYPES;
for (int foo = parameters::X; foo <= parameters::timeOffset; foo++) {
parameters param = static_cast<parameters>(foo);
std::string theLabel = getStringFromParamEnum(param, true);
Expand All @@ -796,15 +808,16 @@ namespace simBeamSpotPI {
auto ltx = TLatex();
ltx.SetTextFont(62);
ltx.SetTextSize(0.025);
ltx.SetTextAlign(11);
//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());
ltx.SetTextAlign(32); // Set text alignment to left (left-aligned)
ltx.DrawLatexNDC(1 - gPad->GetRightMargin(),
1 - gPad->GetTopMargin() + 0.01,
("#color[2]{" + 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());
Expand All @@ -814,6 +827,9 @@ namespace simBeamSpotPI {

protected:
std::shared_ptr<PayloadType> m_payload;

private:
static constexpr double cmToUm = 10000.f;
};

/************************************************
Expand Down Expand Up @@ -862,7 +878,7 @@ namespace simBeamSpotPI {
canvas.cd(1)->SetGrid();

// for the "text"-filled histogram
auto h2_SimBSParameters = std::make_unique<TH2F>("Parameters", "", 1, 0.0, 1.0, 9, 0, 9.);
auto h2_SimBSParameters = std::make_unique<TH2F>("Parameters", "", 1, 0.0, 1.0, END_OF_TYPES, 0, END_OF_TYPES);
h2_SimBSParameters->SetStats(false);
h2_SimBSParameters->GetXaxis()->SetBinLabel(1, "Value");
h2_SimBSParameters->GetXaxis()->LabelsOption("h");
Expand All @@ -887,7 +903,7 @@ namespace simBeamSpotPI {
const auto diffPars = fBS.diffCentralValues(lBS);
//const auto pullPars = fBS.diffCentralValues(lBS,true /*normalize*/);

unsigned int yBin = 9;
unsigned int yBin = END_OF_TYPES;
for (int foo = parameters::X; foo <= parameters::timeOffset; foo++) {
parameters param = static_cast<parameters>(foo);
std::string theLabel = simBeamSpotPI::getStringFromParamEnum(param, true /*use units*/);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@

namespace {

using namespace simBeamSpotPI;

/************************************************
Display of Sim Beam Spot parameters
*************************************************/

typedef DisplayParameters<SimBeamSpotObjects> SimBeamSpotParameters;
typedef simBeamSpotPI::DisplayParameters<SimBeamSpotObjects> SimBeamSpotParameters;

/************************************************
Display of Sim Beam Spot parameters Differences
*************************************************/

typedef DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::MULTI_IOV, 1>
typedef simBeamSpotPI::DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::MULTI_IOV, 1>
SimBeamSpotParametersDiffSingleTag;
typedef DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::SINGLE_IOV, 2>
typedef simBeamSpotPI::DisplayParametersDiff<SimBeamSpotObjects, cond::payloadInspector::SINGLE_IOV, 2>
SimBeamSpotParametersDiffTwoTags;

} // namespace
Expand Down
27 changes: 27 additions & 0 deletions CondCore/BeamSpotPlugins/test/testBeamSpotPayloadInspector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <sstream>
#include "CondCore/Utilities/interface/PayloadInspector.h"
#include "CondCore/BeamSpotPlugins/plugins/SimBeamSpot_PayloadInspector.cc"
#include "CondCore/BeamSpotPlugins/plugins/BeamSpot_PayloadInspector.cc"
#include "CondCore/BeamSpotPlugins/plugins/BeamSpotOnline_PayloadInspector.cc"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
Expand Down Expand Up @@ -49,6 +50,7 @@ int main(int argc, char** argv) {

edm::LogPrint("testBeamSpotPayloadInspector") << "## Exercising BeamSpotOnline plots " << std::endl;

// BeamSpotOnline
tag = "BeamSpotOnlineTestLegacy";
start = static_cast<unsigned long long>(1443392479297557);
end = static_cast<unsigned long long>(1470910334763033);
Expand Down Expand Up @@ -79,5 +81,30 @@ int main(int argc, char** argv) {
histoOnlineParametersDiffTwoTags.process(connectionString, PI::mk_input(tag1, start, start, tag2, start, start));
edm::LogPrint("testBeamSpotPayloadInspector") << histoOnlineParametersDiffTwoTags.data() << std::endl;

// SimBeamSpot
std::string prepConnectionString("frontier://FrontierPrep/CMS_CONDITIONS");

tag = "SimBeamSpotObjects_Realistic25ns13p6TeVEOY2022Collision_v0_mc";
start = static_cast<unsigned long long>(1);
end = static_cast<unsigned long long>(1);

edm::LogPrint("testBeamSpotPayloadInspector") << "## Exercising SimBeamSpot plots " << std::endl;

SimBeamSpotParameters histoSimParameters;
histoSimParameters.process(prepConnectionString, PI::mk_input(tag, start, start));
edm::LogPrint("testBeamSpotPayloadInspector") << histoSimParameters.data() << std::endl;

SimBeamSpotParametersDiffSingleTag histoSimParametersDiff;
histoSimParametersDiff.process(prepConnectionString, PI::mk_input(tag, start, end));
edm::LogPrint("testBeamSpotPayloadInspector") << histoSimParametersDiff.data() << std::endl;

tag1 = "SimBeamSpotObjects_Realistic25ns13p6TeVEOY2022Collision_v0_mc";
tag2 = "SimBeamSpotObjects_Realistic25ns13p6TeVEarly2023Collision_v0_mc";
start = static_cast<unsigned long long>(1);

SimBeamSpotParametersDiffTwoTags histoSimParametersDiffTwoTags;
histoSimParametersDiffTwoTags.process(prepConnectionString, PI::mk_input(tag1, start, start, tag2, start, start));
edm::LogPrint("testBeamSpotPayloadInspector") << histoSimParametersDiffTwoTags.data() << std::endl;

Py_Finalize();
}
12 changes: 4 additions & 8 deletions CondTools/BeamSpot/plugins/BeamProfile2DBReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class BeamProfile2DBReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit BeamProfile2DBReader(const edm::ParameterSet&);
~BeamProfile2DBReader() override;
~BeamProfile2DBReader() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand Down Expand Up @@ -89,8 +89,6 @@ BeamProfile2DBReader::BeamProfile2DBReader(const edm::ParameterSet& iConfig)
}
}

BeamProfile2DBReader::~BeamProfile2DBReader() = default;

//
// member functions
//
Expand Down Expand Up @@ -146,7 +144,7 @@ void BeamProfile2DBReader::analyze(const edm::Event& iEvent, const edm::EventSet
if (output_.get())
*output_ << output.str();
else
edm::LogInfo("") << output.str();
edm::LogInfo("BeamProfile2DBReader") << output.str();
}

// ------------ method called once each job just before starting event loop ------------
Expand All @@ -169,11 +167,9 @@ void BeamProfile2DBReader::beginJob() {

// ------------ 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);
desc.addUntracked<std::string>("rawFileName", {});
descriptions.addWithDefaultLabel(desc);
}

//define this as a plug-in
Expand Down
12 changes: 7 additions & 5 deletions CondTools/BeamSpot/plugins/BeamProfile2DBWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
class BeamProfile2DBWriter : public edm::global::EDAnalyzer<> {
public:
explicit BeamProfile2DBWriter(const edm::ParameterSet&);
~BeamProfile2DBWriter() override;
~BeamProfile2DBWriter() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand All @@ -48,13 +48,15 @@ class BeamProfile2DBWriter : public edm::global::EDAnalyzer<> {
void endJob() override;

// ----------member data ---------------------------
const std::string recordName_;
SimBeamSpotObjects beamSpot_;
};

//
// constructors and destructor
//
BeamProfile2DBWriter::BeamProfile2DBWriter(const edm::ParameterSet& iConfig) {
BeamProfile2DBWriter::BeamProfile2DBWriter(const edm::ParameterSet& iConfig)
: recordName_(iConfig.getParameter<std::string>("recordName")) {
beamSpot_.setX(iConfig.getParameter<double>("X0"));
beamSpot_.setY(iConfig.getParameter<double>("Y0"));
beamSpot_.setZ(iConfig.getParameter<double>("Z0"));
Expand All @@ -66,8 +68,6 @@ BeamProfile2DBWriter::BeamProfile2DBWriter(const edm::ParameterSet& iConfig) {
beamSpot_.setTimeOffset(iConfig.getParameter<double>("TimeOffset"));
}

BeamProfile2DBWriter::~BeamProfile2DBWriter() = default;

//
// member functions
//
Expand All @@ -78,14 +78,16 @@ void BeamProfile2DBWriter::analyze(edm::StreamID, const edm::Event& iEvent, cons
// ------------ method called once each job just after ending the event loop ------------
void BeamProfile2DBWriter::endJob() {
edm::Service<cond::service::PoolDBOutputService> poolDbService;
poolDbService->createOneIOV<SimBeamSpotObjects>(beamSpot_, poolDbService->beginOfTime(), "SimBeamSpotObjectsRcd");
poolDbService->createOneIOV<SimBeamSpotObjects>(beamSpot_, poolDbService->beginOfTime(), recordName_);
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
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;
desc.add<std::string>("recordName", "SimBeamSpotObjectsRcd")
->setComment("name of the record to use for the PoolDBOutputService");
desc.add<double>("X0")->setComment("in cm");
desc.add<double>("Y0")->setComment("in cm");
desc.add<double>("Z0")->setComment("in cm");
Expand Down
12 changes: 4 additions & 8 deletions CondTools/BeamSpot/plugins/BeamSpotRcdReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
class BeamSpotRcdReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit BeamSpotRcdReader(const edm::ParameterSet&);
~BeamSpotRcdReader() override;
~BeamSpotRcdReader() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand Down Expand Up @@ -95,8 +95,6 @@ BeamSpotRcdReader::BeamSpotRcdReader(const edm::ParameterSet& iConfig)
}
}

BeamSpotRcdReader::~BeamSpotRcdReader() = default;

//
// member functions
//
Expand Down Expand Up @@ -150,7 +148,7 @@ void BeamSpotRcdReader::analyze(const edm::Event& iEvent, const edm::EventSetup&
if (output_.get())
*output_ << output.str();
else
edm::LogInfo("") << output.str();
edm::LogInfo("BeamSpotRcdReader") << output.str();
}

// ------------ method called once each job just before starting event loop ------------
Expand All @@ -171,11 +169,9 @@ void BeamSpotRcdReader::beginJob() {

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void BeamSpotRcdReader::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);
desc.addUntracked<std::string>("rawFileName", {});
descriptions.addWithDefaultLabel(desc);
}

//define this as a plug-in
Expand Down
5 changes: 0 additions & 5 deletions CondTools/BeamSpot/python/BeamProfile2DBRead_cfi.py

This file was deleted.

5 changes: 0 additions & 5 deletions CondTools/BeamSpot/python/BeamSpotRcdRead_cfi.py

This file was deleted.

Loading