Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0b87cd0
necessary additions to BuildFile for pps info
Sep 21, 2020
49d6733
added ProtonProducer version compatible with CMSSW_11_2_X
Sep 21, 2020
47f2a92
added LHCInfoProducer to get conditions from LHC db
Sep 21, 2020
bc14a01
updates SimpleFlatTableProducerPlugins to work with newly added proto…
Sep 21, 2020
6ac43cd
Added nanoSequenceOnlyData to introduce proton and lhcInfo variables.…
Sep 21, 2020
6d2d78b
added proton table for singleRP and multiRP instances
Sep 21, 2020
08af7a7
removed FloatColumn, IntColumn, etc. to be compatible with 11_2_X
Sep 21, 2020
458d1a5
patched code recommended by code-checks
Sep 22, 2020
872f58b
added Marco Peruzzi's suggested edits for compatibility with datasets…
Sep 22, 2020
262c975
code-format updates
Sep 23, 2020
1f7f1db
Added proton plots
Sep 29, 2020
b0c0009
storing LHCInfo in nanoAOD per luminosity block instead of per event
Oct 5, 2020
64a5934
fixed code checks
Oct 5, 2020
4376344
excluding EOY datasets for PPS tables
Oct 6, 2020
f5822f9
imported run2_nanoAOD_102Xv1
Oct 6, 2020
93b952e
revisions to stored variables decided by proton POG
Oct 15, 2020
7f92de5
code checks fix
Oct 15, 2020
76151d0
updated nanoDQM with POG recommended variables
Oct 15, 2020
833a81f
Added proton filter and removed excess proton variables
Oct 28, 2020
25243c2
Updated with code checks
Oct 28, 2020
5b7877d
Another attempt at code checks
Oct 28, 2020
c8df93a
Removed unnecessary variables
Oct 28, 2020
9e322a0
implemented suggestions from perrotta
Oct 30, 2020
e25b018
removed duplicate config file
Oct 31, 2020
f558b4e
removed singleRP protons and only storing contributing tracks for mul…
Nov 16, 2020
10264f0
code check fixes
Nov 16, 2020
960358d
update to master
Nov 16, 2020
31df4eb
Merge branch 'master' into pps_nanoAOD
Nov 16, 2020
4425dc4
configurable option to store singleRP protons
Nov 20, 2020
9be3994
Updated name of tables in dqm
Nov 24, 2020
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
71 changes: 46 additions & 25 deletions PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
: name_(params.getParameter<std::string>("name")),
doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
src_(consumes<TProd>(params.getParameter<edm::InputTag>("src"))) {
skipNonExistingSrc_(
params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
src_(skipNonExistingSrc_ ? mayConsume<TProd>(params.getParameter<edm::InputTag>("src"))
: consumes<TProd>(params.getParameter<edm::InputTag>("src"))) {
edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
Expand Down Expand Up @@ -58,6 +61,7 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
const std::string name_;
const std::string doc_;
const bool extension_;
const bool skipNonExistingSrc_;
const edm::EDGetTokenT<TProd> src_;

class VariableBase {
Expand Down Expand Up @@ -135,15 +139,20 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
const auto &varPSet = extvarsPSet.getParameter<edm::ParameterSet>(vname);
const std::string &type = varPSet.getParameter<std::string>("type");
if (type == "int")
extvars_.push_back(std::make_unique<IntExtVar>(vname, varPSet, this->consumesCollector()));
extvars_.push_back(
std::make_unique<IntExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
else if (type == "float")
extvars_.push_back(std::make_unique<FloatExtVar>(vname, varPSet, this->consumesCollector()));
extvars_.push_back(
std::make_unique<FloatExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
else if (type == "double")
extvars_.push_back(std::make_unique<DoubleExtVar>(vname, varPSet, this->consumesCollector()));
extvars_.push_back(
std::make_unique<DoubleExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
else if (type == "uint8")
extvars_.push_back(std::make_unique<UInt8ExtVar>(vname, varPSet, this->consumesCollector()));
extvars_.push_back(
std::make_unique<UInt8ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
else if (type == "bool")
extvars_.push_back(std::make_unique<BoolExtVar>(vname, varPSet, this->consumesCollector()));
extvars_.push_back(
std::make_unique<BoolExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
else
throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
}
Expand All @@ -156,21 +165,23 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
const edm::Handle<edm::View<T>> &prod) const override {
std::vector<const T *> selobjs;
std::vector<edm::Ptr<T>> selptrs; // for external variables
if (singleton_) {
assert(prod->size() == 1);
selobjs.push_back(&(*prod)[0]);
if (!extvars_.empty())
selptrs.emplace_back(prod->ptrAt(0));
} else {
for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
const auto &obj = (*prod)[i];
if (cut_(obj)) {
selobjs.push_back(&obj);
if (!extvars_.empty())
selptrs.emplace_back(prod->ptrAt(i));
if (prod.isValid() || !(this->skipNonExistingSrc_)) {
if (singleton_) {
assert(prod->size() == 1);
selobjs.push_back(&(*prod)[0]);
if (!extvars_.empty())
selptrs.emplace_back(prod->ptrAt(0));
} else {
for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
const auto &obj = (*prod)[i];
if (cut_(obj)) {
selobjs.push_back(&obj);
if (!extvars_.empty())
selptrs.emplace_back(prod->ptrAt(i));
}
if (selobjs.size() >= maxLen_)
break;
}
if (selobjs.size() >= maxLen_)
break;
}
}
auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, singleton_, this->extension_);
Expand All @@ -194,19 +205,29 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
template <typename TIn, typename ValType = TIn>
class ValueMapVariable : public ExtVariable {
public:
ValueMapVariable(const std::string &aname, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
: ExtVariable(aname, cfg), token_(cc.consumes<edm::ValueMap<TIn>>(cfg.getParameter<edm::InputTag>("src"))) {}
ValueMapVariable(const std::string &aname,
const edm::ParameterSet &cfg,
edm::ConsumesCollector &&cc,
bool skipNonExistingSrc = false)
: ExtVariable(aname, cfg),
skipNonExistingSrc_(skipNonExistingSrc),
token_(skipNonExistingSrc_ ? cc.mayConsume<edm::ValueMap<TIn>>(cfg.getParameter<edm::InputTag>("src"))
: cc.consumes<edm::ValueMap<TIn>>(cfg.getParameter<edm::InputTag>("src"))) {}
void fill(const edm::Event &iEvent, std::vector<edm::Ptr<T>> selptrs, nanoaod::FlatTable &out) const override {
edm::Handle<edm::ValueMap<TIn>> vmap;
iEvent.getByToken(token_, vmap);
std::vector<ValType> vals(selptrs.size());
for (unsigned int i = 0, n = vals.size(); i < n; ++i) {
vals[i] = (*vmap)[selptrs[i]];
std::vector<ValType> vals;
if (vmap.isValid() || !skipNonExistingSrc_) {
vals.resize(selptrs.size());
for (unsigned int i = 0, n = vals.size(); i < n; ++i) {
vals[i] = (*vmap)[selptrs[i]];
}
}
out.template addColumn<ValType>(this->name_, vals, this->doc_, this->precision_);
}

protected:
const bool skipNonExistingSrc_;
edm::EDGetTokenT<edm::ValueMap<TIn>> token_;
};
typedef ValueMapVariable<int> IntExtVar;
Expand Down
6 changes: 6 additions & 0 deletions PhysicsTools/NanoAOD/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<use name="CondFormats/BTauObjects"/>
<use name="CondFormats/L1TObjects"/>
<use name="CondTools/BTau"/>
<use name="DataFormats/CTPPSDetId"/>
<use name="DataFormats/CTPPSReco"/>
<use name="DataFormats/ProtonReco"/>
<use name="CondFormats/RunInfo"/>
<use name="CondFormats/DataRecord"/>
<use name="RecoPPS/ProtonReconstruction"/>
<use name="fastjet"/>
<use name="fastjet-contrib"/>
<library file="*.cc" name="PhysicsToolsNanoAODPlugins">
Expand Down
80 changes: 80 additions & 0 deletions PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// -*- C++ -*-
//
// Package: PhysicsTools/NanoAOD
// Class: LHCInfoProducer
//
/**\class LHCInfoProducer LHCInfoProducer.cc PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Justin Williams
// Created: 05 Jul 2019 14:06:12 GMT
//
//

// System include files
#include <memory>
#include <map>
#include <string>
#include <vector>
#include <iostream>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
#include "FWCore/Framework/interface/SourceFactory.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/StreamID.h"

#include "CommonTools/Egamma/interface/EffectiveAreas.h"

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

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

#include "CondFormats/RunInfo/interface/LHCInfo.h"
#include "CondFormats/DataRecord/interface/LHCInfoRcd.h"

class LHCInfoProducer : public edm::global::EDProducer<edm::BeginLuminosityBlockProducer> {
public:
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 {}

void globalBeginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) const override {
edm::ESHandle<LHCInfo> lhcInfo;
iSetup.get<LHCInfoRcd>().get(lhcInfo);
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);
}
};

DEFINE_FWK_MODULE(LHCInfoProducer);
17 changes: 17 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,17 @@ 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
Loading