CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
TriggerTools Class Reference

#include <TriggerTools.h>

Classes

struct  Record
 

Public Member Functions

void addTriggerRecord (const std::string &name)
 
void addTriggerRecord (const std::string &name, const std::string &objName)
 
void initHLTObjects (const HLTConfigProvider &hltConfigProvider_)
 
bool pass () const
 
bool passObj (const double eta, const double phi) const
 
void readEvent (const edm::Event &iEvent)
 
void setDRMAX (const double _drMax)
 
void setTriggerEventToken (edm::EDGetTokenT< trigger::TriggerEvent > token)
 
void setTriggerResultsToken (edm::EDGetTokenT< edm::TriggerResults > token)
 
 TriggerTools ()
 
 ~TriggerTools ()
 

Private Member Functions

void initPathNames (const std::vector< std::string > &triggerNames)
 

Private Attributes

double DRMAX = 0.1
 
edm::EDGetTokenT< trigger::TriggerEventfHLTObjTag_token
 
edm::EDGetTokenT< edm::TriggerResultsfHLTTag_token
 
edm::ParameterSetID fTriggerNamesID
 
edm::Handle< trigger::TriggerEventhTrgEvt
 
edm::Handle< edm::TriggerResultshTrgRes
 
std::vector< Recordrecords
 
TriggerBits triggerBits
 

Detailed Description

Definition at line 19 of file TriggerTools.h.

Constructor & Destructor Documentation

◆ TriggerTools()

TriggerTools::TriggerTools ( )
inline

Definition at line 21 of file TriggerTools.h.

21 {};

◆ ~TriggerTools()

TriggerTools::~TriggerTools ( )
inline

Definition at line 22 of file TriggerTools.h.

22 {};

Member Function Documentation

◆ addTriggerRecord() [1/2]

void TriggerTools::addTriggerRecord ( const std::string &  name)
inline

Definition at line 30 of file TriggerTools.h.

References TriggerTools::Record::hltPattern, Skims_PA_cff::name, and records.

Referenced by ZCounting::ZCounting(), and ZCountingElectrons::ZCountingElectrons().

30  {
31  Record rec;
32  rec.hltPattern = name;
33  records.push_back(rec);
34  }
std::vector< Record > records
Definition: TriggerTools.h:54

◆ addTriggerRecord() [2/2]

void TriggerTools::addTriggerRecord ( const std::string &  name,
const std::string &  objName 
)
inline

Definition at line 35 of file TriggerTools.h.

References TriggerTools::Record::hltObjName, TriggerTools::Record::hltPattern, Skims_PA_cff::name, mkLumiAveragedPlots::objName, and records.

35  {
36  Record rec;
37  rec.hltPattern = name;
38  rec.hltObjName = objName;
39  records.push_back(rec);
40  }
std::vector< Record > records
Definition: TriggerTools.h:54

◆ initHLTObjects()

void TriggerTools::initHLTObjects ( const HLTConfigProvider hltConfigProvider_)

Definition at line 35 of file TriggerTools.cc.

References heavyIonCSV_trainingSettings::idx, initPathNames(), HLTConfigProvider::moduleEDMType(), HerwigMaxPtPartonFilter_cfi::moduleLabel, HLTConfigProvider::moduleLabels(), HLTConfigProvider::moduleType(), or, records, HLTConfigProvider::saveTags(), HLTConfigProvider::triggerIndex(), L1TEGammaOffline_cfi::triggerNames, and HLTConfigProvider::triggerNames().

Referenced by ZCountingElectrons::dqmBeginRun(), and ZCounting::dqmBeginRun().

35  {
36  /*
37  execture each run to initialize the last filter of each trigger corresponding to the corresponding object that has fired the trigger
38  */
39  edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects initHLTObjects";
40  const std::vector<std::string>& triggerNames(hltConfigProvider_.triggerNames());
41 
43 
44  for (auto& iRec : records) {
45  std::vector<std::string> hltFiltersWithTags_;
46 
47  for (auto const& iPathName : triggerNames) {
48  if (iPathName != iRec.hltPathName) {
49  continue;
50  }
51  edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects trigger name: " << iPathName;
52 
53  iRec.hltPathIndex = hltConfigProvider_.triggerIndex(iPathName);
54 
55  auto const& moduleLabels(hltConfigProvider_.moduleLabels(iRec.hltPathIndex));
56 
57  for (int idx = moduleLabels.size() - 1; idx >= 0; --idx) {
58  auto const& moduleLabel(moduleLabels.at(idx));
59 
60  auto const& moduleEDMType(hltConfigProvider_.moduleEDMType(moduleLabel));
61  if (moduleEDMType != "EDFilter") {
62  continue;
63  }
64 
65  auto const& moduleType(hltConfigProvider_.moduleType(moduleLabel));
66  if ((moduleType == "HLTTriggerTypeFilter") or (moduleType == "HLTBool") or (moduleType == "HLTPrescaler")) {
67  continue;
68  }
69 
70  if (!hltConfigProvider_.saveTags(moduleLabel)) {
71  continue;
72  }
73  edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects new hlt object name: " << moduleLabel;
74 
75  iRec.hltObjName = moduleLabel;
76  break;
77  }
78  break;
79  }
80 
81  if (iRec.hltPathIndex == (unsigned int)-1) {
82  edm::LogWarning("TriggerTools") << "TriggerTools::initHLTObjects hltPathIndex has not been found for: "
83  << iRec.hltPattern << std::endl;
84  continue;
85  }
86  }
87 }
Log< level::Info, true > LogVerbatim
const std::string moduleType(const std::string &module) const
C++ class name of module.
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< Record > records
Definition: TriggerTools.h:54
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
const std::vector< std::string > & triggerNames() const
names of trigger paths
void initPathNames(const std::vector< std::string > &triggerNames)
Definition: TriggerTools.cc:10
Log< level::Warning, false > LogWarning

◆ initPathNames()

void TriggerTools::initPathNames ( const std::vector< std::string > &  triggerNames)
private

Definition at line 10 of file TriggerTools.cc.

References createfilelist::int, edm::is_glob(), match(), oniaPATMuonsWithTrigger_cff::matches, topSingleLeptonDQM_PU_cfi::pattern, records, edm::regexMatch(), AlCaHLTBitMon_QueryRunRegistry::string, and L1TEGammaOffline_cfi::triggerNames.

Referenced by initHLTObjects().

10  {
11  /*
12  init HLT path every run (e.g. versions can change)
13  */
14  edm::LogVerbatim("TriggerTools") << "TriggerTools::initPathNames initHLT";
15  for (auto& iRec : records) {
16  iRec.hltPathName = "";
17  iRec.hltPathIndex = (unsigned int)-1;
18  const std::string pattern = iRec.hltPattern;
19  if (edm::is_glob(pattern)) { // handle pattern with wildcards (*,?)
20  std::vector<std::vector<std::string>::const_iterator> matches = edm::regexMatch(triggerNames, pattern);
21  if (matches.empty()) {
22  edm::LogWarning("ZCounting") << "requested pattern [" << pattern << "] does not match any HLT paths";
23  } else {
24  for (auto const& match : matches) {
25  iRec.hltPathName = *match;
26  }
27  }
28  } else { // take full HLT path name given
29  iRec.hltPathName = pattern;
30  }
31  }
32 }
Log< level::Info, true > LogVerbatim
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
std::vector< Record > records
Definition: TriggerTools.h:54
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
Log< level::Warning, false > LogWarning

◆ pass()

bool TriggerTools::pass ( ) const

Definition at line 121 of file TriggerTools.cc.

References triggerBits.

Referenced by ZCountingElectrons::analyze(), and ZCounting::analyze().

121  {
122  /*
123  check if the event passed any of the initialized triggers
124  */
125 
126  return triggerBits != 0;
127 }
TriggerBits triggerBits
Definition: TriggerTools.h:67

◆ passObj()

bool TriggerTools::passObj ( const double  eta,
const double  phi 
) const

Definition at line 130 of file TriggerTools.cc.

References reco::deltaR2(), DRMAX, trigger::TriggerObject::eta(), PVValHelper::eta, trigger::TriggerEvent::filterIndex(), trigger::TriggerEvent::filterKeys(), pdwgDoubleElectron_cfi::filterName, trigger::TriggerEvent::getObjects(), hTrgEvt, mps_fire::i, relativeConstraints::keys, phi, trigger::TriggerObject::phi(), records, trigger::TriggerEvent::sizeFilters(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ZCountingElectrons::analyze(), and ZCounting::analyze().

130  {
131  /*
132  check if the object is matched to any trigger of the initialized triggers, and that this trigger is passed
133  */
134 
135  for (unsigned int i = 0; i < records.size(); i++) {
136  const std::string& filterName = records.at(i).hltObjName;
137 
138  edm::InputTag filterTag(filterName, "", "HLT");
139  // filterIndex must be less than the size of trgEvent or you get a CMSException: _M_range_check
140  if (hTrgEvt->filterIndex(filterTag) < hTrgEvt->sizeFilters()) {
142  const trigger::Keys& keys(hTrgEvt->filterKeys(hTrgEvt->filterIndex(filterTag)));
143 
144  for (unsigned int hlto = 0; hlto < keys.size(); hlto++) {
145  trigger::size_type hltf = keys[hlto];
146  const trigger::TriggerObject& tobj(toc[hltf]);
147  if (reco::deltaR2(eta, phi, tobj.eta(), tobj.phi()) < DRMAX) {
148  return true;
149  }
150  }
151  }
152  }
153  return false;
154 }
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:119
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:147
double DRMAX
Definition: TriggerTools.h:70
uint16_t size_type
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
std::vector< Record > records
Definition: TriggerTools.h:54
edm::Handle< trigger::TriggerEvent > hTrgEvt
Definition: TriggerTools.h:60
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:102
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:133
std::vector< size_type > Keys

◆ readEvent()

void TriggerTools::readEvent ( const edm::Event iEvent)

Definition at line 90 of file TriggerTools.cc.

References edm::HLTGlobalStatus::accept(), fHLTObjTag_token, fHLTTag_token, hTrgEvt, hTrgRes, mps_fire::i, iEvent, createfilelist::int, edm::HandleBase::isValid(), LogDebug, records, and triggerBits.

Referenced by ZCountingElectrons::analyze(), and ZCounting::analyze().

90  {
91  /*
92  execture each event to load trigger objects
93  */
94 
95  LogDebug("TriggerTools") << "TriggerTools::readEvent";
96 
97  iEvent.getByToken(fHLTTag_token, hTrgRes);
98  if (!hTrgRes.isValid()) {
99  edm::LogWarning("TriggerTools") << "TriggerTools::readEvent No valid trigger result product found";
100  }
101 
102  iEvent.getByToken(fHLTObjTag_token, hTrgEvt);
103  if (!hTrgEvt.isValid()) {
104  edm::LogWarning("TriggerTools") << "TriggerTools::readEvent No valid trigger event product found";
105  }
106 
107  triggerBits.reset();
108  for (unsigned int i = 0; i < records.size(); i++) {
109  if (records.at(i).hltPathIndex == (unsigned int)-1) {
110  LogDebug("TriggerTools") << "TriggerTools::readEvent hltPathIndex has not been set" << std::endl;
111  continue;
112  }
113  if (hTrgRes->accept(records.at(i).hltPathIndex)) {
114  triggerBits[i] = true;
115  }
116  }
117  LogDebug("TriggerTools") << "TriggerTools::readEvent bitset = " << triggerBits[1] << triggerBits[0];
118 }
bool accept() const
Has at least one path accepted the event?
edm::Handle< edm::TriggerResults > hTrgRes
Definition: TriggerTools.h:59
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::TriggerResults > fHLTTag_token
Definition: TriggerTools.h:56
edm::EDGetTokenT< trigger::TriggerEvent > fHLTObjTag_token
Definition: TriggerTools.h:57
std::vector< Record > records
Definition: TriggerTools.h:54
edm::Handle< trigger::TriggerEvent > hTrgEvt
Definition: TriggerTools.h:60
bool isValid() const
Definition: HandleBase.h:70
TriggerBits triggerBits
Definition: TriggerTools.h:67
Log< level::Warning, false > LogWarning
#define LogDebug(id)

◆ setDRMAX()

void TriggerTools::setDRMAX ( const double  _drMax)
inline

Definition at line 28 of file TriggerTools.h.

References DRMAX.

Referenced by ZCounting::ZCounting(), and ZCountingElectrons::ZCountingElectrons().

28 { DRMAX = _drMax; }
double DRMAX
Definition: TriggerTools.h:70

◆ setTriggerEventToken()

void TriggerTools::setTriggerEventToken ( edm::EDGetTokenT< trigger::TriggerEvent token)
inline

Definition at line 27 of file TriggerTools.h.

References fHLTObjTag_token, and unpackBuffers-CaloStage2::token.

Referenced by ZCounting::ZCounting(), and ZCountingElectrons::ZCountingElectrons().

edm::EDGetTokenT< trigger::TriggerEvent > fHLTObjTag_token
Definition: TriggerTools.h:57

◆ setTriggerResultsToken()

void TriggerTools::setTriggerResultsToken ( edm::EDGetTokenT< edm::TriggerResults token)
inline

Definition at line 26 of file TriggerTools.h.

References fHLTTag_token, and unpackBuffers-CaloStage2::token.

Referenced by ZCounting::ZCounting(), and ZCountingElectrons::ZCountingElectrons().

26 { fHLTTag_token = token; }
edm::EDGetTokenT< edm::TriggerResults > fHLTTag_token
Definition: TriggerTools.h:56

Member Data Documentation

◆ DRMAX

double TriggerTools::DRMAX = 0.1
private

Definition at line 70 of file TriggerTools.h.

Referenced by passObj(), and setDRMAX().

◆ fHLTObjTag_token

edm::EDGetTokenT<trigger::TriggerEvent> TriggerTools::fHLTObjTag_token
private

Definition at line 57 of file TriggerTools.h.

Referenced by readEvent(), and setTriggerEventToken().

◆ fHLTTag_token

edm::EDGetTokenT<edm::TriggerResults> TriggerTools::fHLTTag_token
private

Definition at line 56 of file TriggerTools.h.

Referenced by readEvent(), and setTriggerResultsToken().

◆ fTriggerNamesID

edm::ParameterSetID TriggerTools::fTriggerNamesID
private

Definition at line 62 of file TriggerTools.h.

◆ hTrgEvt

edm::Handle<trigger::TriggerEvent> TriggerTools::hTrgEvt
private

Definition at line 60 of file TriggerTools.h.

Referenced by passObj(), and readEvent().

◆ hTrgRes

edm::Handle<edm::TriggerResults> TriggerTools::hTrgRes
private

Definition at line 59 of file TriggerTools.h.

Referenced by readEvent().

◆ records

std::vector<Record> TriggerTools::records
private

Definition at line 54 of file TriggerTools.h.

Referenced by addTriggerRecord(), initHLTObjects(), initPathNames(), passObj(), and readEvent().

◆ triggerBits

TriggerBits TriggerTools::triggerBits
private

Definition at line 67 of file TriggerTools.h.

Referenced by pass(), and readEvent().