Skip to content

Commit

Permalink
Add custom Run 3 scouting NanoAOD
Browse files Browse the repository at this point in the history
  • Loading branch information
alintulu committed Dec 19, 2022
1 parent 52c0dac commit 016218c
Show file tree
Hide file tree
Showing 9 changed files with 1,632 additions and 334 deletions.
37 changes: 25 additions & 12 deletions CommonTools/RecoAlgos/plugins/JetDeltaRValueMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Math/interface/deltaR.h"

template <class T, class C = T>
template <class T, class C = T, typename TN = float>
class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
public:
typedef edm::ValueMap<float> JetValueMap;
typedef TN value_type;
typedef edm::ValueMap<value_type> JetValueMap;
typedef std::vector<value_type> ValueVector;

JetDeltaRValueMapProducer(edm::ParameterSet const& params)
: srcToken_(consumes<typename edm::View<T> >(params.getParameter<edm::InputTag>("src"))),
Expand All @@ -46,8 +48,10 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
lazyParser_(params.existsAs<bool>("lazyParser") ? params.getParameter<bool>("lazyParser") : false),
multiValue_(false) {
if (!value_.empty()) {
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
if (value_ != "index") {
evaluationMap_.insert(std::make_pair(
value_, std::unique_ptr<StringObjectFunction<C> >(new StringObjectFunction<C>(value_, lazyParser_))));
}
produces<JetValueMap>();
}

Expand Down Expand Up @@ -75,7 +79,8 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
edm::Handle<typename edm::View<C> > h_jets2;
iEvent.getByToken(matchedToken_, h_jets2);

std::vector<float> values(h_jets1->size(), -99999);
ValueVector values(h_jets1->size(), -99999);

std::map<std::string, std::vector<float> > valuesMap;
if (multiValue_) {
for (size_t i = 0; i < valueLabels_.size(); ++i)
Expand All @@ -88,19 +93,20 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
++ijet) {
float matched_dR2 = 1e9;
int matched_index = -1;
int iindex = ijet - ibegin;

for (typename edm::View<T>::const_iterator jbegin = h_jets1->begin(), jend = h_jets1->end(), jjet = jbegin;
jjet != jend;
++jjet) {
int index = jjet - jbegin;
int jindex = jjet - jbegin;

if (jets1_locks.at(index))
if (jets1_locks.at(jindex))
continue; // skip jets that have already been matched

float temp_dR2 = reco::deltaR2(ijet->eta(), ijet->phi(), jjet->eta(), jjet->phi());
if (temp_dR2 < matched_dR2) {
matched_dR2 = temp_dR2;
matched_index = index;
matched_index = jindex;
}
} // end loop over src jets

Expand All @@ -109,8 +115,13 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
edm::LogInfo("MatchedJetsFarApart") << "Matched jets separated by dR greater than distMax=" << distMax_;
else {
jets1_locks.at(matched_index) = true;
if (!value_.empty())
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
if (!value_.empty()) {
if (value_ == "index") {
values.at(matched_index) = iindex;
} else {
values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
}
}
if (multiValue_) {
for (size_t i = 0; i < valueLabels_.size(); ++i)
valuesMap.at(valueLabels_[i]).at(matched_index) = (*(evaluationMap_.at(valueLabels_[i])))(*ijet);
Expand All @@ -122,7 +133,7 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
if (!value_.empty()) {
std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());

JetValueMap::Filler filler(*jetValueMap);
typename JetValueMap::Filler filler(*jetValueMap);
filler.insert(h_jets1, values.begin(), values.end());
filler.fill();

Expand All @@ -133,7 +144,7 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
for (size_t i = 0; i < valueLabels_.size(); ++i) {
std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());

JetValueMap::Filler filler(*jetValueMap);
typename JetValueMap::Filler filler(*jetValueMap);
filler.insert(h_jets1, valuesMap.at(valueLabels_[i]).begin(), valuesMap.at(valueLabels_[i]).end());
filler.fill();

Expand All @@ -157,7 +168,9 @@ class JetDeltaRValueMapProducer : public edm::stream::EDProducer<> {
typedef JetDeltaRValueMapProducer<reco::Jet> RecoJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<reco::Jet, pat::Jet> RecoJetToPatJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<pat::Jet> PatJetDeltaRValueMapProducer;
typedef JetDeltaRValueMapProducer<reco::Jet, reco::GenJet, int> RecoJetToGenJetDeltaRValueMapProducer;

DEFINE_FWK_MODULE(RecoJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(RecoJetToPatJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(PatJetDeltaRValueMapProducer);
DEFINE_FWK_MODULE(RecoJetToGenJetDeltaRValueMapProducer);
7 changes: 5 additions & 2 deletions PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class NanoAODOutputModule : public edm::one::OutputModule<> {
std::unique_ptr<TTree> m_tree, m_lumiTree, m_runTree, m_metaDataTree, m_parameterSetsTree;

static constexpr int m_firstFlush{1000};
bool m_isPFScouting;

class CommonEventBranches {
public:
Expand Down Expand Up @@ -159,7 +160,8 @@ NanoAODOutputModule::NanoAODOutputModule(edm::ParameterSet const& pset)
m_writeProvenance(pset.getUntrackedParameter<bool>("saveProvenance", true)),
m_fakeName(pset.getUntrackedParameter<bool>("fakeNameForCrab", false)),
m_autoFlush(pset.getUntrackedParameter<int>("autoFlush", -10000000)),
m_processHistoryRegistry() {}
m_processHistoryRegistry(),
m_isPFScouting(pset.getUntrackedParameter<bool>("isPFScouting", false)) {}

NanoAODOutputModule::~NanoAODOutputModule() {}

Expand Down Expand Up @@ -322,7 +324,7 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) {
if (keep.first->className() == "nanoaod::FlatTable")
m_tables.emplace_back(keep.first, keep.second);
else if (keep.first->className() == "edm::TriggerResults") {
m_triggers.emplace_back(keep.first, keep.second);
m_triggers.emplace_back(keep.first, keep.second, m_isPFScouting);
} else if (keep.first->className() == "std::basic_string<char,std::char_traits<char> >" &&
keep.first->productInstanceName() == "genModel") { // friendlyClassName == "String"
m_evstrings.emplace_back(keep.first, keep.second, true); // update only at lumiBlock transitions
Expand Down Expand Up @@ -416,6 +418,7 @@ void NanoAODOutputModule::fillDescriptions(edm::ConfigurationDescriptions& descr
"Change the OutputModule name in the fwk job report to fake PoolOutputModule. This is needed to run on cran "
"(and publish) till crab is fixed");
desc.addUntracked<int>("autoFlush", -10000000)->setComment("Autoflush parameter for ROOT file");
desc.addUntracked<bool>("isPFScouting", false);

//replace with whatever you want to get from the EDM by default
const std::vector<std::string> keep = {"drop *",
Expand Down
Loading

0 comments on commit 016218c

Please sign in to comment.