3 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
4 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
5 from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer
import NTupleVariable
7 import PhysicsTools.HeppyCore.framework.config
as cfg
10 def __init__(self, cfg_ana, cfg_comp, looperName ):
11 super(TriggerMatchAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
16 self.trgObjSelectors.extend(getattr(self.cfg_ana,
"trgObjSelectors",[]))
17 self.
collToMatch = getattr(self.cfg_ana,
"collToMatch",
None)
19 self.collMatchSelectors.extend(getattr(self.cfg_ana,
"collMatchSelectors",[]))
21 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")
22 self.
match1To1 = getattr(self.cfg_ana,
"univoqueMatching",
True)
26 self.handles[
'TriggerBits'] = AutoHandle( (
'TriggerResults',
'',
'HLT'),
'edm::TriggerResults' )
27 self.handles[
'TriggerObjects'] = AutoHandle( (
'selectedPatTrigger',
'',self.
processName),
'std::vector<pat::TriggerObjectStandAlone>' )
30 super(TriggerMatchAnalyzer,self).
beginLoop(setup)
33 self.readCollections( event.input )
34 triggerBits = self.handles[
'TriggerBits'].product()
35 allTriggerObjects = self.handles[
'TriggerObjects'].product()
36 names = event.input.object().triggerNames(triggerBits)
37 for ob
in allTriggerObjects: ob.unpackPathNames(names)
38 triggerObjects = [ob
for ob
in allTriggerObjects
if False not in [
sel(ob)
for sel
in self.
trgObjSelectors]]
40 setattr(event,
'trgObjects_'+self.
label,triggerObjects)
44 doubleandselector =
lambda lep,ob:
False if False in [
sel(lep,ob)
for sel
in self.
collMatchSelectors]
else True
46 for lep
in tcoll: setattr(lep,
'matchedTrgObj'+self.
label,pairs[lep])
49 print 'Verbose debug for triggerMatchAnalyzer %s'%self.
label
50 for ob
in getattr(event,
'trgObjects_'+self.
label):
51 types =
", ".
join([str(f)
for f
in ob.filterIds()])
52 filters =
", ".
join([str(f)
for f
in ob.filterLabels()])
53 paths =
", ".
join([(
"%s***" if f
in set(ob.pathNames(
True))
else "%s")%f
for f
in ob.pathNames()])
54 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)
58 if getattr(lep,
'matchedTrgObj'+self.
label):
59 mstring =
'trigger obj with pt=%.2f, eta=%.2f, phi=%.2f, collection=%s'%(ob.pt(),ob.eta(),ob.phi(),ob.collection())
60 print 'Lepton pt=%.2f, eta=%.2f, phi=%.2f matched to %s'%(lep.pt(),lep.eta(),lep.phi(),mstring)
65 setattr(TriggerMatchAnalyzer,
"defaultConfig",cfg.Analyzer(
66 TriggerMatchAnalyzer, name=
"TriggerMatchAnalyzerDefault",
67 label=
'DefaultTrigObjSelection',
69 unpackPathNames =
True,
72 collMatchSelectors = [],
74 univoqueMatching =
True,
def matchObjectCollection
static std::string join(char **cmd)
def matchObjectCollection3