File indexing completed on 2024-04-06 12:09:38
0001 #include "DQMOffline/Lumi/interface/TriggerTools.h"
0002
0003 #include "FWCore/Utilities/interface/RegexMatch.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "DataFormats/Math/interface/deltaR.h"
0006
0007 #include <algorithm>
0008
0009
0010 void TriggerTools::initPathNames(const std::vector<std::string>& triggerNames) {
0011
0012
0013
0014 edm::LogVerbatim("TriggerTools") << "TriggerTools::initPathNames initHLT";
0015 for (auto& iRec : records) {
0016 iRec.hltPathName = "";
0017 iRec.hltPathIndex = (unsigned int)-1;
0018 const std::string pattern = iRec.hltPattern;
0019 if (edm::is_glob(pattern)) {
0020 std::vector<std::vector<std::string>::const_iterator> matches = edm::regexMatch(triggerNames, pattern);
0021 if (matches.empty()) {
0022 edm::LogWarning("ZCounting") << "requested pattern [" << pattern << "] does not match any HLT paths";
0023 } else {
0024 for (auto const& match : matches) {
0025 iRec.hltPathName = *match;
0026 }
0027 }
0028 } else {
0029 iRec.hltPathName = pattern;
0030 }
0031 }
0032 }
0033
0034
0035 void TriggerTools::initHLTObjects(const HLTConfigProvider& hltConfigProvider_) {
0036
0037
0038
0039 edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects initHLTObjects";
0040 const std::vector<std::string>& triggerNames(hltConfigProvider_.triggerNames());
0041
0042 initPathNames(triggerNames);
0043
0044 for (auto& iRec : records) {
0045 std::vector<std::string> hltFiltersWithTags_;
0046
0047 for (auto const& iPathName : triggerNames) {
0048 if (iPathName != iRec.hltPathName) {
0049 continue;
0050 }
0051 edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects trigger name: " << iPathName;
0052
0053 iRec.hltPathIndex = hltConfigProvider_.triggerIndex(iPathName);
0054
0055 auto const& moduleLabels(hltConfigProvider_.moduleLabels(iRec.hltPathIndex));
0056
0057 for (int idx = moduleLabels.size() - 1; idx >= 0; --idx) {
0058 auto const& moduleLabel(moduleLabels.at(idx));
0059
0060 auto const& moduleEDMType(hltConfigProvider_.moduleEDMType(moduleLabel));
0061 if (moduleEDMType != "EDFilter") {
0062 continue;
0063 }
0064
0065 auto const& moduleType(hltConfigProvider_.moduleType(moduleLabel));
0066 if ((moduleType == "HLTTriggerTypeFilter") or (moduleType == "HLTBool") or (moduleType == "HLTPrescaler")) {
0067 continue;
0068 }
0069
0070 if (!hltConfigProvider_.saveTags(moduleLabel)) {
0071 continue;
0072 }
0073 edm::LogVerbatim("TriggerTools") << "TriggerTools::initHLTObjects new hlt object name: " << moduleLabel;
0074
0075 iRec.hltObjName = moduleLabel;
0076 break;
0077 }
0078 break;
0079 }
0080
0081 if (iRec.hltPathIndex == (unsigned int)-1) {
0082 edm::LogWarning("TriggerTools") << "TriggerTools::initHLTObjects hltPathIndex has not been found for: "
0083 << iRec.hltPattern << std::endl;
0084 continue;
0085 }
0086 }
0087 }
0088
0089
0090 void TriggerTools::readEvent(const edm::Event& iEvent) {
0091
0092
0093
0094
0095 LogDebug("TriggerTools") << "TriggerTools::readEvent";
0096
0097 iEvent.getByToken(fHLTTag_token, hTrgRes);
0098 if (!hTrgRes.isValid()) {
0099 edm::LogWarning("TriggerTools") << "TriggerTools::readEvent No valid trigger result product found";
0100 }
0101
0102 iEvent.getByToken(fHLTObjTag_token, hTrgEvt);
0103 if (!hTrgEvt.isValid()) {
0104 edm::LogWarning("TriggerTools") << "TriggerTools::readEvent No valid trigger event product found";
0105 }
0106
0107 triggerBits.reset();
0108 for (unsigned int i = 0; i < records.size(); i++) {
0109 if (records.at(i).hltPathIndex == (unsigned int)-1) {
0110 LogDebug("TriggerTools") << "TriggerTools::readEvent hltPathIndex has not been set" << std::endl;
0111 continue;
0112 }
0113 if (hTrgRes->accept(records.at(i).hltPathIndex)) {
0114 triggerBits[i] = true;
0115 }
0116 }
0117 LogDebug("TriggerTools") << "TriggerTools::readEvent bitset = " << triggerBits[1] << triggerBits[0];
0118 }
0119
0120
0121 bool TriggerTools::pass() const {
0122
0123
0124
0125
0126 return triggerBits != 0;
0127 }
0128
0129
0130 bool TriggerTools::passObj(const double eta, const double phi) const {
0131
0132
0133
0134
0135 for (unsigned int i = 0; i < records.size(); i++) {
0136 const std::string& filterName = records.at(i).hltObjName;
0137
0138 edm::InputTag filterTag(filterName, "", "HLT");
0139
0140 if (hTrgEvt->filterIndex(filterTag) < hTrgEvt->sizeFilters()) {
0141 const trigger::TriggerObjectCollection& toc(hTrgEvt->getObjects());
0142 const trigger::Keys& keys(hTrgEvt->filterKeys(hTrgEvt->filterIndex(filterTag)));
0143
0144 for (unsigned int hlto = 0; hlto < keys.size(); hlto++) {
0145 trigger::size_type hltf = keys[hlto];
0146 const trigger::TriggerObject& tobj(toc[hltf]);
0147 if (reco::deltaR2(eta, phi, tobj.eta(), tobj.phi()) < DRMAX) {
0148 return true;
0149 }
0150 }
0151 }
0152 }
0153 return false;
0154 }