Skip to content

Commit

Permalink
storing LHCInfo in nanoAOD per luminosity block instead of per event
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Williams committed Oct 5, 2020
1 parent 1f7f1db commit b0c0009
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
41 changes: 13 additions & 28 deletions PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,41 @@

#include "DataFormats/NanoAOD/interface/FlatTable.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h"

#include "FWCore/Utilities/interface/transform.h"

// LHC Info
#include "CondFormats/RunInfo/interface/LHCInfo.h"
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"
#include "CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h"

class LHCInfoProducer : public edm::global::EDProducer<> {
class LHCInfoProducer : public edm::global::EDProducer<edm::BeginLuminosityBlockProducer> {
public:
LHCInfoProducer(edm::ParameterSet const& ps) : precision_(ps.getParameter<int>("precision")) {
produces<nanoaod::FlatTable>("lhcInfoTab");
LHCInfoProducer(edm::ParameterSet const&) {
produces<nanoaod::MergeableCounterTable, edm::Transition::BeginLuminosityBlock>();
}
~LHCInfoProducer() override {}

// ------------ method called to produce the data ------------
void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {
// Get LHCInfo handle
void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {}

void globalBeginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) const override {
edm::ESHandle<LHCInfo> lhcInfo;
iSetup.get<LHCInfoRcd>().get(lhcInfo);

std::unique_ptr<nanoaod::FlatTable> out = fillTable(iEvent, lhcInfo);
out->setDoc("LHC Info");

iEvent.put(std::move(out), "lhcInfoTab");
}

std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event& iEvent, const edm::ESHandle<LHCInfo>& prod) const {
const LHCInfo* info = prod.product();
float crossingAngle = info->crossingAngle();
float betaStar = info->betaStar();
float energy = info->energy();

auto out = std::make_unique<nanoaod::FlatTable>(1, "LHCInfo", true);
out->addColumnValue<float>("crossingAngle", crossingAngle, "LHC crossing angle", precision_);
out->addColumnValue<float>("betaStar", betaStar, "LHC beta star", precision_);
out->addColumnValue<float>("energy", energy, "LHC beam energy", precision_);
return out;
const LHCInfo* info = lhcInfo.product();
auto out = std::make_unique<nanoaod::MergeableCounterTable>();
out->addFloat("crossingAngle", "LHC crossing angle", info->crossingAngle());
out->addFloat("betaStar", "LHC beta star", info->betaStar());
out->addFloat("energy", "LHC beam energy", info->energy());
iLumi.put(std::move(out));
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
}

protected:
const unsigned int precision_;
};

DEFINE_FWK_MODULE(LHCInfoProducer);
16 changes: 16 additions & 0 deletions PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class NanoAODOutputModule : public edm::one::OutputModule<> {
std::vector<EventStringOutputBranches> m_evstrings;

std::vector<SummaryTableOutputBranches> m_runTables;
std::vector<SummaryTableOutputBranches> m_lumiTables;

std::vector<std::pair<std::string, edm::EDGetToken>> m_nanoMetadata;
};
Expand Down Expand Up @@ -224,6 +225,10 @@ void NanoAODOutputModule::writeLuminosityBlock(edm::LuminosityBlockForOutput con
jr->reportLumiSection(m_jrToken, iLumi.id().run(), iLumi.id().value());

m_commonLumiBranches.fill(iLumi.id());

for (auto& t : m_lumiTables)
t.fill(iLumi, *m_lumiTree);

m_lumiTree->Fill();

m_processHistoryRegistry.registerProcessHistory(iLumi.processHistory());
Expand Down Expand Up @@ -287,6 +292,7 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) {
m_triggers_areSorted = false;
m_evstrings.clear();
m_runTables.clear();
m_lumiTables.clear();
const auto& keeps = keptProducts();
for (const auto& keep : keeps[edm::InEvent]) {
if (keep.first->className() == "nanoaod::FlatTable")
Expand All @@ -300,6 +306,16 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) {
throw cms::Exception("Configuration", "NanoAODOutputModule cannot handle class " + keep.first->className());
}

for (const auto& keep : keeps[edm::InLumi]) {
if (keep.first->className() == "nanoaod::MergeableCounterTable")
m_lumiTables.push_back(SummaryTableOutputBranches(keep.first, keep.second));
else if (keep.first->className() == "nanoaod::UniqueString" && keep.first->moduleLabel() == "nanoMetadata")
m_nanoMetadata.emplace_back(keep.first->productInstanceName(), keep.second);
else
throw cms::Exception("Configuration",
"NanoAODOutputModule cannot handle class " + keep.first->className() + " in LuminosityBlock branch");
}

for (const auto& keep : keeps[edm::InRun]) {
if (keep.first->className() == "nanoaod::MergeableCounterTable")
m_runTables.push_back(SummaryTableOutputBranches(keep.first, keep.second));
Expand Down

0 comments on commit b0c0009

Please sign in to comment.