Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 0 additions & 4 deletions CalibTracker/SiStripCommon/plugins/SealModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ DEFINE_FWK_MODULE(ShallowSimhitClustersProducer);
DEFINE_FWK_MODULE(ShallowTracksProducer);
DEFINE_FWK_MODULE(ShallowSimTracksProducer);
DEFINE_FWK_MODULE(ShallowGainCalibration);

#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"
typedef SimpleFlatTableProducer<reco::Track> SimpleTrackFlatTableProducer;
DEFINE_FWK_MODULE(SimpleTrackFlatTableProducer);
1 change: 1 addition & 0 deletions DPGAnalysis/MuonTools/interface/MuDigiBaseProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MuDigiBaseProducer : public SimpleFlatTableProducerBase<DIGI_T, MuonDigiCo

variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.addUntracked<bool>("lazyEval")->setComment("set to True if the type read from the Event is unknown");

variable.ifValue(edm::ParameterDescription<std::string>("type", "int", true, comType),
edm::allowedValues<std::string>("int", "uint", "int16", "uint8"));
Expand Down
1 change: 1 addition & 0 deletions DPGAnalysis/MuonTools/interface/MuLocalRecoBaseProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class MuRecObjBaseProducer

varBase.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
varBase.add<std::string>("doc")->setComment("few words description of the branch content");
varBase.addUntracked<bool>("lazyEval")->setComment("if True, check object type during Event processing.");

return varBase;
};
Expand Down
10 changes: 6 additions & 4 deletions DPGAnalysis/MuonTools/python/common_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DEFAULT_VAL(NamedTuple):

defaults = DEFAULT_VAL()

def DetIdVar(expr, type, doc=None):
def DetIdVar(expr, type, doc=None, lazyEval=False):
""" Create a PSet for a DetId variable in the tree:
- expr is the expression to evaluate to compute the variable,
- type of the value (int, bool, or a string that the table producer understands),
Expand All @@ -22,10 +22,11 @@ def DetIdVar(expr, type, doc=None):
return cms.PSet(
type = cms.string(type),
expr = cms.string(expr),
doc = cms.string(doc if doc else expr)
doc = cms.string(doc if doc else expr),
lazyEval = cms.untracked.bool(lazyEval)
)

def GlobGeomVar(expr, doc=None, precision=-1):
def GlobGeomVar(expr, doc=None, precision=-1, lazyEval=False):
""" Create a PSet for a Global position/direction variable in the tree ,
- expr is the expression to evaluate to compute the variable,
- doc is a docstring, that will be passed to the table producer,
Expand All @@ -34,7 +35,8 @@ def GlobGeomVar(expr, doc=None, precision=-1):
return cms.PSet(
expr = cms.string(expr),
doc = cms.string(doc if doc else expr),
precision=cms.string(precision) if type(precision)==str else cms.int32(precision)
precision = cms.string(precision) if type(precision)==str else cms.int32(precision),
lazyEval = cms.untracked.bool(lazyEval)
)


Expand Down
4 changes: 2 additions & 2 deletions DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from PhysicsTools.NanoAOD.common_cff import *
from DPGAnalysis.MuonTools.common_cff import *

from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
from PhysicsTools.NanoAOD.simplePATMuonFlatTableProducer_cfi import simplePATMuonFlatTableProducer

from PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import *

muonFlatTableProducer = simpleCandidateFlatTableProducer.clone(
muonFlatTableProducer = simplePATMuonFlatTableProducer.clone(
src = cms.InputTag("patMuons"),
name = cms.string("muon"),
doc = cms.string("RECO muon information"),
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Candidate/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@
<class name="edm::reftobase::RefHolder<reco::VertexCompositePtrCandidateRef>" />
<class name="edm::reftobase::VectorHolder<reco::Candidate, reco::VertexCompositePtrCandidateRefVector>" />
<class name="edm::reftobase::RefVectorHolder<reco::VertexCompositePtrCandidateRefVector>" />
<class name="edm::PtrVector<reco::VertexCompositePtrCandidate>" />
<class name="edm::Wrapper<edm::PtrVector<reco::VertexCompositePtrCandidate> >" />


<class name="reco::NamedCompositeCandidateCollection" />
Expand Down
29 changes: 20 additions & 9 deletions PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class FuncVariable : public Variable<ObjType> {
public:
FuncVariable(const std::string &aname, const edm::ParameterSet &cfg)
: Variable<ObjType>(aname, cfg),
func_(cfg.getParameter<std::string>("expr"), true),
func_(cfg.getParameter<std::string>("expr"), cfg.getUntrackedParameter<bool>("lazyEval")),
precisionFunc_(cfg.existsAs<std::string>("precision") ? cfg.getParameter<std::string>("precision") : "23",
true) {}
cfg.getUntrackedParameter<bool>("lazyEval")) {}
~FuncVariable() override {}

void fill(std::vector<const ObjType *> &selobjs, nanoaod::FlatTable &out) const override {
Expand Down Expand Up @@ -212,6 +212,8 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
edm::ParameterSetDescription variable;
variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.addUntracked<bool>("lazyEval", false)
->setComment("if true, can use methods of inheriting classes in `expr`. Can cause problems with threading.");
variable.ifValue(
edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
Expand Down Expand Up @@ -271,7 +273,8 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
singleton_(params.getParameter<bool>("singleton")),
maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
: std::numeric_limits<unsigned int>::max()),
cut_(!singleton_ ? params.getParameter<std::string>("cut") : "", true) {
cut_(!singleton_ ? params.getParameter<std::string>("cut") : "",
!singleton_ ? params.getUntrackedParameter<bool>("lazyEval") : false) {
if (params.existsAs<edm::ParameterSet>("externalVariables")) {
edm::ParameterSet const &extvarsPSet = params.getParameter<edm::ParameterSet>("externalVariables");
for (const std::string &vname : extvarsPSet.getParameterNamesForType<edm::ParameterSet>()) {
Expand Down Expand Up @@ -312,11 +315,17 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
static edm::ParameterSetDescription baseDescriptions() {
edm::ParameterSetDescription desc = SimpleFlatTableProducerBase<T, edm::View<T>>::baseDescriptions();

desc.ifValue(edm::ParameterDescription<bool>(
"singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
false >> edm::ParameterDescription<std::string>(
"cut", "", true, edm::Comment("selection on the main input collection")) or
true >> edm::EmptyGroupDescription());
desc.ifValue(
edm::ParameterDescription<bool>(
"singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
false >> (edm::ParameterDescription<std::string>(
"cut", "", true, edm::Comment("selection on the main input collection")) and
edm::ParameterDescription<bool>("lazyEval",
false,
false,
edm::Comment("if true, can use methods of inheriting classes. Can "
"cause problems when multi-threading."))) or
true >> edm::EmptyGroupDescription());
desc.addOptional<unsigned int>("maxLen")->setComment(
"define the maximum length of the input collection to put in the branch");

Expand Down Expand Up @@ -442,6 +451,8 @@ class SimpleTypedExternalFlatTableProducer : public SimpleFlatTableProducer<T> {
extvariable.add<std::string>("expr")->setComment(
"a function to define the content of the branch in the flat table");
extvariable.add<std::string>("doc")->setComment("few words description of the branch content");
extvariable.addUntracked<bool>("lazyEval", false)
->setComment("if true, can use methods of inheriting classes in `expr`. Can cause problems with threading.");
extvariable.ifValue(
edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
Expand Down Expand Up @@ -482,7 +493,7 @@ class BXVectorSimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, BX
: SimpleFlatTableProducerBase<T, BXVector<T>>(params),
maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
: std::numeric_limits<unsigned int>::max()),
cut_(params.getParameter<std::string>("cut"), true),
cut_(params.getParameter<std::string>("cut"), false),
minBX_(params.getParameter<int>("minBX")),
maxBX_(params.getParameter<int>("maxBX")),
alwaysWriteBXValue_(params.getParameter<bool>("alwaysWriteBXValue")),
Expand Down
61 changes: 61 additions & 0 deletions PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@
#include "DataFormats/Candidate/interface/Candidate.h"
typedef SimpleFlatTableProducer<reco::Candidate> SimpleCandidateFlatTableProducer;

#include "DataFormats/TrackReco/interface/Track.h"
typedef SimpleFlatTableProducer<reco::Track> SimpleTrackFlatTableProducer;

#include "DataFormats/JetReco/interface/PFJet.h"
typedef SimpleFlatTableProducer<reco::PFJet> SimplePFJetFlatTableProducer;

#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
typedef SimpleFlatTableProducer<reco::VertexCompositePtrCandidate> SimpleSecondaryVertexFlatTableProducer;

#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
typedef SimpleFlatTableProducer<reco::GenParticle> SimpleGenParticleFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Electron.h"
typedef SimpleFlatTableProducer<pat::Electron> SimplePATElectronFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Muon.h"
typedef SimpleFlatTableProducer<pat::Muon> SimplePATMuonFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Tau.h"
typedef SimpleFlatTableProducer<pat::Tau> SimplePATTauFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Photon.h"
typedef SimpleFlatTableProducer<pat::Photon> SimplePATPhotonFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Jet.h"
typedef SimpleFlatTableProducer<pat::Jet> SimplePATJetFlatTableProducer;

#include "DataFormats/PatCandidates/interface/IsolatedTrack.h"
typedef SimpleFlatTableProducer<pat::IsolatedTrack> SimplePATIsolatedTrackFlatTableProducer;

#include "DataFormats/PatCandidates/interface/GenericParticle.h"
typedef SimpleFlatTableProducer<pat::GenericParticle> SimplePATGenericParticleFlatTableProducer;

#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
typedef SimpleFlatTableProducer<pat::PackedCandidate> SimplePATCandidateFlatTableProducer;

#include "DataFormats/PatCandidates/interface/MET.h"
typedef SimpleFlatTableProducer<pat::MET> SimplePATMETFlatTableProducer;

typedef SimpleTypedExternalFlatTableProducer<reco::Candidate, reco::Candidate>
SimpleCandidate2CandidateFlatTableProducer;

Expand Down Expand Up @@ -66,9 +105,28 @@ typedef SimpleFlatTableProducer<reco::Vertex> SimpleVertexFlatTableProducer;
#include "DataFormats/VertexReco/interface/TrackTimeLifeInfo.h"
typedef SimpleTypedExternalFlatTableProducer<reco::Candidate, TrackTimeLifeInfo>
SimpleCandidate2TrackTimeLifeInfoFlatTableProducer;
typedef SimpleTypedExternalFlatTableProducer<pat::Electron, TrackTimeLifeInfo>
SimplePATElectron2TrackTimeLifeInfoFlatTableProducer;
typedef SimpleTypedExternalFlatTableProducer<pat::Muon, TrackTimeLifeInfo>
SimplePATMuon2TrackTimeLifeInfoFlatTableProducer;
typedef SimpleTypedExternalFlatTableProducer<pat::Tau, TrackTimeLifeInfo>
SimplePATTau2TrackTimeLifeInfoFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimplePFJetFlatTableProducer);
DEFINE_FWK_MODULE(SimpleSecondaryVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenParticleFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATTauFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATJetFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATIsolatedTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATGenericParticleFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMETFlatTableProducer);
DEFINE_FWK_MODULE(SimpleCandidate2CandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenFilterFlatTableProducerLumi);
Expand All @@ -90,3 +148,6 @@ DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimpleVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleCandidate2TrackTimeLifeInfoFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATElectron2TrackTimeLifeInfoFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMuon2TrackTimeLifeInfoFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATTau2TrackTimeLifeInfoFlatTableProducer);
7 changes: 3 additions & 4 deletions PhysicsTools/NanoAOD/plugins/VertexTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ VertexTableProducer::VertexTableProducer(const edm::ParameterSet& params)
produces<nanoaod::FlatTable>("pv");
produces<nanoaod::FlatTable>("otherPVs");
produces<nanoaod::FlatTable>("svs");
produces<edm::PtrVector<reco::Candidate>>();
produces<edm::PtrVector<reco::VertexCompositePtrCandidate>>();
}

//
Expand Down Expand Up @@ -167,7 +167,7 @@ void VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
otherPVsTable->addColumn<float>("score", pvscores, "scores of other primary vertices, excluding the main PV", 8);

const auto& svsProd = iEvent.get(svs_);
auto selCandSv = std::make_unique<PtrVector<reco::Candidate>>();
auto selCandSv = std::make_unique<PtrVector<reco::VertexCompositePtrCandidate>>();
std::vector<float> dlen, dlenSig, pAngle, dxy, dxySig;
std::vector<int16_t> charge;
VertexDistance3D vdist;
Expand All @@ -182,8 +182,7 @@ void VertexTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
if (dl.value() > dlenMin_ and dl.significance() > dlenSigMin_) {
dlen.push_back(dl.value());
dlenSig.push_back(dl.significance());
edm::Ptr<reco::Candidate> c = svsProd.ptrAt(i);
selCandSv->push_back(c);
selCandSv->push_back(svsProd.ptrAt(i));
double dx = (PV0.x() - sv.vx()), dy = (PV0.y() - sv.vy()), dz = (PV0.z() - sv.vz());
double pdotv = (dx * sv.px() + dy * sv.py() + dz * sv.pz()) / sv.p() / sqrt(dx * dx + dy * dy + dz * dz);
pAngle.push_back(std::acos(pdotv));
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/NanoAOD/python/boostedTaus_cff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import FWCore.ParameterSet.Config as cms
from PhysicsTools.NanoAOD.common_cff import *
from PhysicsTools.NanoAOD.nano_eras_cff import *
from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
from PhysicsTools.NanoAOD.simplePATTauFlatTableProducer_cfi import simplePATTauFlatTableProducer

##################### Import reusable funtions and objects from std taus ########
from PhysicsTools.NanoAOD.taus_cff import _tauIdWPMask, tausMCMatchLepTauForTable, tausMCMatchHadTauForTable,tauMCTable
Expand All @@ -18,7 +18,7 @@
cut = "pt > 40 && tauID('decayModeFindingNewDMs') && (tauID('byVVLooseIsolationMVArun2DBoldDMwLT') || tauID('byVVLooseIsolationMVArun2DBoldDMdR0p3wLT') || tauID('byVVLooseIsolationMVArun2DBnewDMwLT'))"
)

boostedTauTable = simpleCandidateFlatTableProducer.clone(
boostedTauTable = simplePATTauFlatTableProducer.clone(
src = cms.InputTag("linkedObjects", "boostedTaus"),
name= cms.string("boostedTau"),
doc = cms.string("slimmedBoostedTaus after basic selection (" + finalBoostedTaus.cut.value()+")"),
Expand Down
6 changes: 3 additions & 3 deletions PhysicsTools/NanoAOD/python/btvMC_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
]

btvGenTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
"SimpleGenParticleFlatTableProducer",
src=finalGenParticles.src,
name= cms.string("GenPart"),
doc = cms.string("interesting gen particles "),
Expand All @@ -31,7 +31,7 @@
btvMCTable = cms.EDProducer("BTVMCFlavourTableProducer",name=jetPuppiTable.name,src=cms.InputTag("linkedObjects","jets"),genparticles=cms.InputTag("prunedGenParticles"))

btvAK4JetExtTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
"SimplePATJetFlatTableProducer",
src=jetPuppiTable.src,
cut=jetPuppiTable.cut,
name=jetPuppiTable.name,
Expand All @@ -48,7 +48,7 @@
))

btvSubJetMCExtTable = cms.EDProducer(
"SimpleCandidateFlatTableProducer",
"SimplePATJetFlatTableProducer",
src = subJetTable.src,
cut = subJetTable.cut,
name = subJetTable.name,
Expand Down
9 changes: 5 additions & 4 deletions PhysicsTools/NanoAOD/python/common_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ def OVar(valtype, doc=None, precision=-1):
return cms.PSet(
type = cms.string(valtype),
doc = cms.string(doc if doc else expr),
precision=cms.optional.allowed(cms.string, cms.int32, default = (cms.string(precision) if type(precision)==str else cms.int32(precision)
)))
def Var(expr, valtype, doc=None, precision=-1):
precision=cms.optional.allowed(cms.string, cms.int32, default = (cms.string(precision) if type(precision)==str else cms.int32(precision)))
)

def Var(expr, valtype, doc=None, precision=-1, lazyEval=False):
"""Create a PSet for a variable computed with the string parser

expr is the expression to evaluate to compute the variable
Expand All @@ -22,7 +23,7 @@ def Var(expr, valtype, doc=None, precision=-1):
see OVar above for all the other arguments
"""
return OVar(valtype, doc=(doc if doc else expr), precision=precision).clone(
expr = cms.string(expr))
expr = cms.string(expr), lazyEval=cms.untracked.bool(lazyEval))

def ExtVar(tag, valtype, doc=None, precision=-1):
"""Create a PSet for a variable read from the event
Expand Down
Loading