Skip to content

Commit

Permalink
use pset instead of vpset for trigger objects
Browse files Browse the repository at this point in the history
  • Loading branch information
swertz committed Dec 9, 2022
1 parent aec4cfd commit e2d1af1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 66 deletions.
43 changes: 21 additions & 22 deletions PhysicsTools/NanoAOD/plugins/TriggerObjectTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ class TriggerObjectTableProducer : public edm::stream::EDProducer<> {
l1Jet_(consumes<l1t::JetBxCollection>(iConfig.getParameter<edm::InputTag>("l1Jet"))),
l1Muon_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("l1Muon"))),
l1Tau_(consumes<l1t::TauBxCollection>(iConfig.getParameter<edm::InputTag>("l1Tau"))) {
std::vector<edm::ParameterSet> selPSets = iConfig.getParameter<std::vector<edm::ParameterSet>>("selections");
sels_.reserve(selPSets.size());
edm::ParameterSet selPSet = iConfig.getParameter<edm::ParameterSet>("selections");
const auto selNames = selPSet.getParameterNames();
std::stringstream idstr, qualitystr;
idstr << "ID of the object: ";
for (auto &pset : selPSets) {
sels_.emplace_back(pset);
idstr << sels_.back().id << " = " << sels_.back().name;
if (sels_.size() < selPSets.size())
for (const auto &name: selNames) {
sels_.emplace_back(selPSet.getParameter<edm::ParameterSet>(name));
const auto& sel = sels_.back();
idstr << sel.id << " = " << name + sel.doc;
if (sels_.size() < selNames.size())
idstr << ", ";
if (!sels_.back().qualityBitsDoc.empty()) {
qualitystr << sels_.back().qualityBitsDoc << " for " << sels_.back().name << "; ";
if (!sel.qualityBitsDoc.empty()) {
qualitystr << sel.qualityBitsDoc << " for " << name << "; ";
}
}
idDoc_ = idstr.str();
Expand All @@ -71,7 +72,7 @@ class TriggerObjectTableProducer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<l1t::TauBxCollection> l1Tau_;

struct SelectedObject {
std::string name;
std::string doc;
int id;
StringCutObjectSelector<pat::TriggerObjectStandAlone> cut;
StringCutObjectSelector<pat::TriggerObjectStandAlone> l1cut, l1cut_2, l2cut;
Expand All @@ -81,7 +82,7 @@ class TriggerObjectTableProducer : public edm::stream::EDProducer<> {
std::string qualityBitsDoc;

SelectedObject(const edm::ParameterSet &pset)
: name(pset.getParameter<std::string>("name")),
: doc(pset.getParameter<std::string>("doc")),
id(pset.getParameter<int>("id")),
cut(pset.getParameter<std::string>("sel")),
l1cut(""),
Expand All @@ -94,6 +95,9 @@ class TriggerObjectTableProducer : public edm::stream::EDProducer<> {
qualityBits("0"), //will be overwritten from configuration
qualityBitsDoc("") //will be created from configuration
{
if (doc.size() > 0) {
doc = "(" + doc + ")";
}
std::vector<edm::ParameterSet> qualityBitsConfig =
pset.getParameter<std::vector<edm::ParameterSet>>("qualityBits");
std::stringstream qualityBitsFunc;
Expand Down Expand Up @@ -334,26 +338,17 @@ void TriggerObjectTableProducer::fillDescriptions(edm::ConfigurationDescriptions

edm::ParameterSetDescription selection;
selection.setComment("a parameterset to define a trigger collection in flat table");
selection.add<std::string>("name")->setComment("name of the leaf in the flat table");
selection.add<std::string>("doc", "")->setComment("optional additional info to be added to the table doc for that object");
selection.add<int>("id")->setComment("identifier of the trigger collection in the flat table");
selection.add<std::string>("sel")->setComment("function to selection on pat::TriggerObjectStandAlone");
selection.add<bool>("skipObjectsNotPassingQualityBits")->setComment("flag to skip object on quality bit");

edm::ParameterDescription<std::string> oldSelection(
"qualityBits", "0", true, edm::Comment("function on pat::TriggerObjectStandAlone to define quality bits"));
edm::ParameterDescription<std::string> oldDoc(
"qualityBitsDoc", "", true, edm::Comment("documentation of the quality bits"));
edm::ParameterSetDescription bit;
bit.add<std::string>("selection")->setComment("function on pat::TriggerObjectStandAlone to define quality bit");
bit.add<std::string>("doc")->setComment("definition of the quality bit");
bit.addOptional<uint>("bit")->setComment("value of the bit, if not the order in the VPset");
bit.setComment("parameter set to define quality bit of matching object");

//selection.addVPSet("qualityBits", bit); // non-backqard compatible
edm::ParameterDescription<std::vector<edm::ParameterSet>> bits(
"qualityBits", bit, true, std::vector<edm::ParameterSet>());
//allow for backward compatible configuration with qualityBits and qualityBitsDoc as strings
selection.addNode(bits xor (oldSelection and oldDoc));
selection.addVPSet("qualityBits", bit);

selection.ifExists(edm::ParameterDescription<std::string>("l1seed", "selection on pat::TriggerObjectStandAlone"),
edm::ParameterDescription<double>(
Expand All @@ -364,7 +359,11 @@ void TriggerObjectTableProducer::fillDescriptions(edm::ConfigurationDescriptions
selection.ifExists(edm::ParameterDescription<std::string>("l2seed", "selection on pat::TriggerObjectStandAlone"),
edm::ParameterDescription<double>(
"l2deltaR", "deltaR criteria to match pat::TriggerObjectStandAlone to 'L2' primitive"));
desc.addVPSet("selections", selection);

edm::ParameterWildcard<edm::ParameterSetDescription> selectionsNode("*", edm::RequireOneOrMore, true, selection);
edm::ParameterSetDescription selections;
selections.addNode(selectionsNode);
desc.add<edm::ParameterSetDescription>("selections", selections);

descriptions.addWithDefaultLabel(desc);
}
Expand Down
75 changes: 31 additions & 44 deletions PhysicsTools/NanoAOD/python/triggerObjects_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def AND(tokens):
l1Jet = cms.InputTag("caloStage2Digis","Jet"),
l1Muon = cms.InputTag("gmtStage2Digis","Muon"),
l1Tau = cms.InputTag("caloStage2Digis","Tau"),
selections = cms.VPSet(
cms.PSet(
name = cms.string("Electron (PixelMatched e/gamma)"), # this selects also photons for the moment!
selections = cms.PSet(
Electron = cms.PSet(
doc = cms.string("PixelMatched e/gamma"), # this may also select photons!
id = cms.int32(11),
sel = cms.string("type(92) && pt > 7 && coll('hltEgammaCandidates') && filter('*PixelMatchFilter')"),
l1seed = cms.string("type(-98)"), l1deltaR = cms.double(0.3),
Expand All @@ -75,8 +75,7 @@ def AND(tokens):
mksel(["hltEG175HEFilter","hltEG200HEFilter"],"1e (Photon175_OR_Photon200)"),
)
),
cms.PSet(
name = cms.string("Photon"),
Photon = cms.PSet(
id = cms.int32(22),
sel = cms.string("type(92) && pt > 20 && coll('hltEgammaCandidates')"),
l1seed = cms.string("type(-98)"), l1deltaR = cms.double(0.3),
Expand All @@ -97,8 +96,7 @@ def AND(tokens):
mksel("filter('hltMu17Photon30IsoCaloIdPhotonlegTrackIsoFilter')","1mu-1photon")
)
),
cms.PSet(
name = cms.string("Muon"),
Muon = cms.PSet(
id = cms.int32(13),
sel = cms.string("type(83) && pt > 5 && (coll('hltIterL3MuonCandidates') || (pt > 45 && coll('hltHighPtTkMuonCands')) || (pt > 95 && coll('hltOldL3MuonCandidates')))"),
l1seed = cms.string("type(-81)"), l1deltaR = cms.double(0.5),
Expand All @@ -120,8 +118,7 @@ def AND(tokens):
mksel("filter('hltMu17Photon30IsoCaloIdMuonlegL3Filtered17Q')","1mu-1photon")
)
),
cms.PSet(
name = cms.string("Tau"),
Tau = cms.PSet(
id = cms.int32(15),
sel = cms.string("type(84) && pt > 5 && coll('*Tau*') && ( filter('*LooseChargedIso*') || filter('*MediumChargedIso*') || filter('*DeepTau*') || filter('*TightChargedIso*') || filter('*TightOOSCPhotons*') || filter('hltL2TauIsoFilter') || filter('*OverlapFilterIsoMu*') || filter('*OverlapFilterIsoEle*') || filter('*L1HLTMatched*') || filter('*Dz02*') || filter('*DoublePFTau*') || filter('*SinglePFTau*') || filter('hlt*SelectedPFTau') || filter('*DisplPFTau*') )"), #All trigger objects from a Tau collection + passing at least one filter
l1seed = cms.string("type(-100)"), l1deltaR = cms.double(0.3),
Expand Down Expand Up @@ -150,8 +147,7 @@ def AND(tokens):
mksel("filter('*1Prong')","1 prong tau paths")
)
),
cms.PSet(
name = cms.string("BoostedTau"),
BoostedTau = cms.PSet(
id = cms.int32(1515),
sel = cms.string("type(85) && pt > 120 && coll('hltAK8PFJetsCorrected') && filter('hltAK8SinglePFJets*SoftDropMass40*ParticleNetTauTau')"),
l1seed = cms.string("type(-99)"), l1deltaR = cms.double(0.3),
Expand All @@ -161,8 +157,7 @@ def AND(tokens):
mksel("filter('hltAK8SinglePFJets*SoftDropMass40*ParticleNetTauTau')","HLT_AK8PFJetX_SoftDropMass40_PFAK8ParticleNetTauTau0p30")
)
),
cms.PSet(
name = cms.string("Jet"),
Jet = cms.PSet(
id = cms.int32(1),
sel = cms.string("( type(0) || type(85) || type(86) || type(-99) )"),
l1seed = cms.string("type(-99)"), l1deltaR = cms.double(0.3),
Expand Down Expand Up @@ -200,17 +195,15 @@ def AND(tokens):
mksel(["hltBTagPFDeepCSV1p5Single"])
),
),
cms.PSet(
name = cms.string("FatJet"),
FatJet = cms.PSet(
id = cms.int32(6),
sel = cms.string("type(85) && pt > 120 && coll('hltAK8PFJetsCorrected')"),
l1seed = cms.string("type(-99)"), l1deltaR = cms.double(0.3),
l2seed = cms.string("type(85) && coll('hltAK8CaloJetsCorrectedIDPassed')"), l2deltaR = cms.double(0.3),
skipObjectsNotPassingQualityBits = cms.bool(True),
qualityBits = cms.VPSet()
),
cms.PSet(
name = cms.string("MET"),
MET = cms.PSet(
id = cms.int32(2),
sel = cms.string("type(87) && pt > 30 && coll('hltPFMETProducer')"),
l1seed = cms.string("type(-87) && coll('L1ETM')"), l1deltaR = cms.double(9999),
Expand All @@ -219,8 +212,7 @@ def AND(tokens):
skipObjectsNotPassingQualityBits = cms.bool(True),
qualityBits = cms.VPSet()
),
cms.PSet(
name = cms.string("HT"),
HT = cms.PSet(
id = cms.int32(3),
sel = cms.string("type(89) || type(-89)"),
l1seed = cms.string("type(-89) && coll('L1HTT')"), l1deltaR = cms.double(9999),
Expand All @@ -235,8 +227,7 @@ def AND(tokens):
mksel(["hltPFCentralJetsLooseIDQuad30HT300","hltPFCentralJetsLooseIDQuad30HT330"])
),
),
cms.PSet(
name = cms.string("MHT"),
MHT = cms.PSet(
id = cms.int32(4),
sel = cms.string("type(90)"),
l1seed = cms.string("type(-90) && coll('L1HTM')"), l1deltaR = cms.double(9999),
Expand All @@ -254,34 +245,30 @@ def AND(tokens):
# ERA-dependent configuration
# Tune filter and collection names to 2016 HLT menus
# FIXME: check non-lepton objects and cross check leptons
selections2016 = copy.deepcopy(triggerObjectTable.selections)
for sel in selections2016:
if sel.name=='Muon':
sel.sel = cms.string("type(83) && pt > 5 && (coll('hlt*L3MuonCandidates') || coll('hlt*TkMuonCands') || coll('hlt*TrkMuonCands'))")
sel.qualityBits = cms.VPSet(
run2_HLTconditions_2016.toModify(
triggerObjectTable.selections.Muon,
sel = "type(83) && pt > 5 && (coll('hlt*L3MuonCandidates') || coll('hlt*TkMuonCands') || coll('hlt*TrkMuonCands'))",
qualityBits = cms.VPSet(
mksel("filter('*RelTrkIso*Filtered0p4')","TrkIsoVVL"),
mksel("filter('hltL3cr*IsoFiltered0p09')","Iso"),
mksel("filter('*OverlapFilter*IsoMu*PFTau*')","OverlapFilter PFTau"),
mksel("filter('hltL3f*IsoFiltered0p09')","IsoTkMu"),
mksel(["hltL3fL1sMu*L3Filtered50*","hltL3fL1sMu*TkFiltered50*"],"1mu (Mu50)", bit=10)
)
elif sel.name=='Tau':
sel.sel = cms.string("type(84) && pt > 5 && coll('*Tau*') && ( filter('*LooseIso*') || filter('*MediumIso*') || filter('*MediumComb*Iso*') || filter('hltL2TauIsoFilter') || filter('*OverlapFilter*IsoMu*') || filter('*OverlapFilter*IsoEle*') || filter('*L1HLTMatched*') || filter('*Dz02*') )")
sel.qualityBits = cms.VPSet(
mksel("(filter('*LooseIso*')-filter('*VLooseIso*'))","LooseIso"),
mksel("filter('*Medium*Iso*')","Medium(Comb)Iso"),
mksel("filter('*VLooseIso*')","VLooseIso"),
mksel("0","None"),
mksel("filter('hltL2TauIsoFilter')","L2p5 pixel iso"),
mksel("filter('*OverlapFilter*IsoMu*')","OverlapFilter IsoMu"),
mksel("filter('*OverlapFilter*IsoEle*')","OverlapFilter IsoEle"),
mksel("filter('*L1HLTMatched*')","L1-HLT matched"),
mksel("filter('*Dz02*')","Dz")
)

run2_HLTconditions_2016.toModify(
triggerObjectTable,
selections = selections2016
)
).toModify(
triggerObjectTable.selections.Tau,
sel = "type(84) && pt > 5 && coll('*Tau*') && ( filter('*LooseIso*') || filter('*MediumIso*') || filter('*MediumComb*Iso*') || filter('hltL2TauIsoFilter') || filter('*OverlapFilter*IsoMu*') || filter('*OverlapFilter*IsoEle*') || filter('*L1HLTMatched*') || filter('*Dz02*') )",
qualityBits = cms.VPSet(
mksel("(filter('*LooseIso*')-filter('*VLooseIso*'))","LooseIso"),
mksel("filter('*Medium*Iso*')","Medium(Comb)Iso"),
mksel("filter('*VLooseIso*')","VLooseIso"),
mksel("0","None"),
mksel("filter('hltL2TauIsoFilter')","L2p5 pixel iso"),
mksel("filter('*OverlapFilter*IsoMu*')","OverlapFilter IsoMu"),
mksel("filter('*OverlapFilter*IsoEle*')","OverlapFilter IsoEle"),
mksel("filter('*L1HLTMatched*')","L1-HLT matched"),
mksel("filter('*Dz02*')","Dz")
)
)

from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight
Expand Down

0 comments on commit e2d1af1

Please sign in to comment.