1 from __future__
import print_function
4 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
5 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
6 from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer
import NTupleVariable
8 import PhysicsTools.HeppyCore.framework.config
as cfg
11 def __init__(self, cfg_ana, cfg_comp, looperName ):
12 super(TriggerMatchAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
13 self.
processName = getattr(self.cfg_ana,
"processName",
"PAT")
14 self.
fallbackName = getattr(self.cfg_ana,
"fallbackProcessName",
"RECO")
16 self.
label = self.cfg_ana.label
18 self.trgObjSelectors.extend(getattr(self.cfg_ana,
"trgObjSelectors",[]))
19 self.
collToMatch = getattr(self.cfg_ana,
"collToMatch",
None)
21 self.collMatchSelectors.extend(getattr(self.cfg_ana,
"collMatchSelectors",[]))
23 if self.
collToMatch and not hasattr(self.cfg_ana,
"univoqueMatching"):
raise RuntimeError(
"Please specify if the matching to trigger objects should be 1-to-1 or 1-to-many")
24 self.
match1To1 = getattr(self.cfg_ana,
"univoqueMatching",
True)
28 self.handles[
'TriggerBits'] = AutoHandle( (
'TriggerResults',
'',
'HLT'),
'edm::TriggerResults' )
30 self.handles[
'TriggerObjects'] = AutoHandle( (
'selectedPatTrigger',
'',self.
processName),
'std::vector<pat::TriggerObjectStandAlone>', fallbackLabel=fallback )
33 super(TriggerMatchAnalyzer,self).
beginLoop(setup)
36 self.readCollections( event.input )
37 triggerBits = self.handles[
'TriggerBits'].product()
38 allTriggerObjects = self.handles[
'TriggerObjects'].product()
40 for ob
in allTriggerObjects: ob.unpackPathNames(names)
41 triggerObjects = [ob
for ob
in allTriggerObjects
if False not in [
sel(ob)
for sel
in self.
trgObjSelectors]]
43 setattr(event,
'trgObjects_'+self.
label,triggerObjects)
47 doubleandselector =
lambda lep,ob:
False if False in [
sel(lep,ob)
for sel
in self.
collMatchSelectors]
else True 49 for lep
in tcoll: setattr(lep,
'matchedTrgObj'+self.
label,pairs[lep])
52 print(
'Verbose debug for triggerMatchAnalyzer %s'%self.
label)
53 for ob
in getattr(event,
'trgObjects_'+self.
label):
54 types =
", ".
join([
str(f)
for f
in ob.filterIds()])
55 filters =
", ".
join([
str(f)
for f
in ob.filterLabels()])
56 paths =
", ".
join([(
"%s***" if f
in set(ob.pathNames(
True))
else "%s")%f
for f
in ob.pathNames()])
57 print(
'Trigger object: pt=%.2f, eta=%.2f, phi=%.2f, collection=%s, type_ids=%s, filters=%s, paths=%s'%(ob.pt(),ob.eta(),ob.phi(),ob.collection(),types,filters,paths))
61 ob = getattr(lep,
'matchedTrgObj'+self.
label)
62 if ob: mstring =
'trigger obj with pt=%.2f, eta=%.2f, phi=%.2f, collection=%s'%(ob.pt(),ob.eta(),ob.phi(),ob.collection())
63 print(
'Lepton pt=%.2f, eta=%.2f, phi=%.2f matched to %s'%(lep.pt(),lep.eta(),lep.phi(),mstring))
68 setattr(TriggerMatchAnalyzer,
"defaultConfig",cfg.Analyzer(
69 TriggerMatchAnalyzer, name=
"TriggerMatchAnalyzerDefault",
70 label=
'DefaultTrigObjSelection',
72 fallbackProcessName =
'RECO',
73 unpackPathNames =
True,
76 collMatchSelectors = [],
78 univoqueMatching =
True,
S & print(S &os, JobReport::InputFile const &f)
def matchObjectCollection
def beginLoop(self, setup)
static std::string join(char **cmd)
def __init__(self, cfg_ana, cfg_comp, looperName)
def matchObjectCollection3