CMS 3D CMS Logo

TriggerTools.cc
Go to the documentation of this file.
2 
6 
7 #include <algorithm>
8 
9 //--------------------------------------------------------------------------------------------------
10 void TriggerTools::initPathNames(const std::vector<std::string>& triggerNames) {
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 }
33 
34 //--------------------------------------------------------------------------------------------------
35 void TriggerTools::initHLTObjects(const HLTConfigProvider& hltConfigProvider_) {
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 }
88 
89 //--------------------------------------------------------------------------------------------------
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 }
119 
120 //--------------------------------------------------------------------------------------------------
121 bool TriggerTools::pass() const {
122  /*
123  check if the event passed any of the initialized triggers
124  */
125 
126  return triggerBits != 0;
127 }
128 
129 //--------------------------------------------------------------------------------------------------
130 bool TriggerTools::passObj(const double eta, const double phi) const {
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 }
bool accept() const
Has at least one path accepted the event?
Log< level::Info, true > LogVerbatim
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
void initHLTObjects(const HLTConfigProvider &hltConfigProvider_)
Definition: TriggerTools.cc:35
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
bool is_glob(std::string const &pattern)
Definition: RegexMatch.cc:17
double DRMAX
Definition: TriggerTools.h:70
const std::string moduleType(const std::string &module) const
C++ class name of module.
uint16_t size_type
edm::Handle< edm::TriggerResults > hTrgRes
Definition: TriggerTools.h:59
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
int iEvent
Definition: GenABIO.cc:224
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
edm::EDGetTokenT< edm::TriggerResults > fHLTTag_token
Definition: TriggerTools.h:56
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
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
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
bool pass() const
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
bool passObj(const double eta, const double phi) const
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
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:132
std::vector< size_type > Keys
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool isValid() const
Definition: HandleBase.h:70
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::regex const &regexp)
Definition: RegexMatch.cc:26
TriggerBits triggerBits
Definition: TriggerTools.h:67
void initPathNames(const std::vector< std::string > &triggerNames)
Definition: TriggerTools.cc:10
void readEvent(const edm::Event &iEvent)
Definition: TriggerTools.cc:90
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
#define LogDebug(id)