23 for(
int i=0;
i<10; ++
i) {
24 snprintf(buffer, 10,
"tr%d",
i);
25 boost::ssub_match sm = what[buffer];
30 thresholds_.push_back(std::stoi(sm.str()));
31 }
catch(std::invalid_argument&
e) {
32 throw cms::Exception(
"Configuration") <<
"Interpreting regex of path " << name <<
", threshold " << buffer <<
": unable to convert '" << sm.str() <<
"' to integer";
33 }
catch(std::out_of_range& e) {
34 throw cms::Exception(
"Configuration") <<
"Interpreting regex of path " << name <<
", threshold " << buffer <<
": '" << sm.str() <<
"' is out of int range";
46 for(
unsigned int iSet = 0; iSet < HLTCP.
prescaleSize(); ++iSet) {
48 unsigned int prescaleOther = HLTCP.
prescaleValue(iSet, other.name_);
49 if(prescale == 0 && prescaleOther == 0)
53 if(prescaleOther == 0)
56 if(prescale != prescaleOther)
57 return prescale < prescaleOther;
62 if(thresholds_.size() != other.thresholds_.size())
63 throw cms::Exception(
"Configuration") <<
"Comparing path " << name_ <<
" and " << other.name_ <<
", they have different numbers of thresholds (" << thresholds_.size() <<
" != " << other.thresholds_.size() <<
")";
64 for(
size_t i=0;
i<thresholds_.size(); ++
i) {
65 if(thresholds_[
i] != other.thresholds_[
i])
66 return thresholds_[
i] < other.thresholds_[
i];
70 throw cms::Exception(
"Configuration") <<
"Comparing path " << name_ <<
" and " << other.name_ <<
", unable to tell which to choose. Improve your input regex!";
76 std::vector<FilterIndex> interestingFilters(
const HLTConfigProvider& HLTCP,
bool doRefAnalysis,
const std::vector<boost::regex>& ignoreFilterTypes,
const std::vector<boost::regex>& ignoreFilterNames)
const {
77 const std::vector<std::string>& moduleLabels = HLTCP.
moduleLabels(name_);
78 std::vector<FilterIndex> selectedFilters;
79 std::vector<std::string> leptonTauFilters;
83 for(std::vector<std::string>::const_iterator iLabel = moduleLabels.begin(); iLabel != moduleLabels.end(); ++iLabel) {
87 if(type.find(
"Selector") != std::string::npos)
89 if(type ==
"HLTTriggerTypeFilter" || type ==
"HLTBool")
91 if(doRefAnalysis && !HLTCP.
saveTags(*iLabel))
93 if(type ==
"HLT2ElectronPFTau" || type ==
"HLT2MuonPFTau" || type ==
"HLT2ElectronTau" || type ==
"HLT2MuonTau")
94 leptonTauFilters.emplace_back(*iLabel);
95 else if(type.find(
"Electron") != std::string::npos || type.find(
"Egamma") != std::string::npos || type.find(
"Muon") != std::string::npos)
97 selectedFilters.emplace_back(*iLabel, iLabel-moduleLabels.begin());
101 for(
const std::string& leptonTauLabel: leptonTauFilters) {
108 auto func = [&](
const FilterIndex&
a,
unsigned idxb) {
109 return std::get<1>(
a) < idxb;
111 std::vector<FilterIndex>::iterator
found = std::lower_bound(selectedFilters.begin(), selectedFilters.end(), idx1,
func);
112 if(found == selectedFilters.end() || std::get<1>(*found) != idx1)
113 selectedFilters.emplace(found, input1, idx1);
114 found = std::lower_bound(selectedFilters.begin(), selectedFilters.end(), idx2,
func);
115 if(found == selectedFilters.end() || std::get<1>(*found) != idx2)
116 selectedFilters.emplace(found, input2, idx2);
120 std::vector<FilterIndex>::iterator selectedFiltersEnd = std::remove_if(selectedFilters.begin(), selectedFilters.end(), [&](
const FilterIndex& labelIndex) {
121 for(
const boost::regex& re: ignoreFilterTypes) {
122 if(boost::regex_search(HLTCP.
moduleType(std::get<0>(labelIndex)), re))
128 selectedFiltersEnd = std::remove_if(selectedFilters.begin(), selectedFiltersEnd, [&](
const FilterIndex& labelIndex) {
129 for(
const boost::regex& re: ignoreFilterNames) {
130 if(boost::regex_search(std::get<0>(labelIndex), re))
137 std::vector<FilterIndex>
ret;
138 ret.reserve(selectedFiltersEnd-selectedFilters.begin());
139 std::move(selectedFilters.begin(), selectedFiltersEnd, std::back_inserter(ret));
144 const std::vector<std::string>& moduleLabels = HLTCP.
moduleLabels(name_);
145 for(std::vector<std::string>::const_iterator iLabel = moduleLabels.begin(); iLabel != moduleLabels.end(); ++iLabel) {
150 if(type ==
"PFRecoTauProducer") {
152 return iLabel-moduleLabels.begin();
163 std::vector<int> thresholds_;
168 if(pset.
existsAs<
int>(parameterName))
171 edm::LogWarning(
"HLTTauDQMOfflineSource") <<
"No parameter '" << parameterName <<
"' in configuration of filter " << filterName <<
" pset " << pset.
dump() << std::endl;
176 struct TauLeptonMultiplicity {
183 TauLeptonMultiplicity
n;
185 if(moduleType ==
"HLTLevel1GTSeed") {
186 if(filterName.find(
"SingleMu") != std::string::npos) {
189 else if(filterName.find(
"SingleEG") != std::string::npos) {
192 else if(filterName.find(
"DoubleTau") != std::string::npos) {
196 else if(moduleType ==
"HLT1CaloJet") {
201 n.tau = getParameterSafe(HLTCP, filterName,
"MinN");
204 else if(moduleType ==
"HLTCaloJetTag") {
209 n.tau = getParameterSafe(HLTCP, filterName,
"MinJets");
212 else if(moduleType ==
"HLT1PFTau") {
214 n.tau = getParameterSafe(HLTCP, filterName,
"MinN");
216 else if(moduleType ==
"HLTPFTauPairDzMatchFilter") {
219 else if(moduleType ==
"HLTElectronGenericFilter") {
221 n.electron = getParameterSafe(HLTCP, filterName,
"ncandcut");
223 else if(moduleType ==
"HLTMuonIsoFilter") {
226 else if(moduleType ==
"HLT2ElectronTau" || moduleType ==
"HLT2ElectronPFTau") {
228 int num = getParameterSafe(HLTCP, filterName,
"MinN");
232 else if(moduleType ==
"HLT2MuonPFTau") {
234 int num = getParameterSafe(HLTCP, filterName,
"MinN");
238 else if(moduleType ==
"HLTPrescaler" || moduleType ==
"HLT1CaloMET") {
242 edm::LogWarning(
"HLTTauDQMOfflineSource") <<
"HLTTauDQMPath.cc, inferTauLeptonMultiplicity(): module type '" << moduleType <<
"' not recognized, filter '" << filterName <<
"' will be ignored for offline matching." << std::endl;
248 template <
typename T1,
typename T2>
249 bool deltaRmatch(
const T1&
obj,
const std::vector<T2>& refColl,
double dR, std::vector<bool>& refMask, std::vector<T2>& matchedRefs) {
251 size_t found = refColl.size();
253 for(
size_t i=0;
i<refColl.size(); ++
i) {
264 if(found < refColl.size()) {
265 matchedRefs.emplace_back(refColl[found]);
266 refMask[
found] =
false;
275 hltProcess_(hltProcess),
276 dqmFolder_(dqmFolder),
277 doRefAnalysis_(doRefAnalysis),
279 lastFilterBeforeL2TauIndex_(0), lastL2TauFilterIndex_(0),
280 lastFilterBeforeL3TauIndex_(0), lastL3TauFilterIndex_(0),
281 isFirstL1Seed_(
false)
286 std::vector<std::string> regexs;
287 std::vector<boost::regex> ignoreFilterTypes;
288 std::vector<boost::regex> ignoreFilterNames;
294 std::vector<std::string> ignoreFilterTypesTmp;
295 std::vector<std::string> ignoreFilterNamesTmp;
298 ignoreFilterTypes.reserve(ignoreFilterTypesTmp.size());
299 ignoreFilterNames.reserve(ignoreFilterNamesTmp.size());
301 ignoreFilterTypes.emplace_back(str);
303 ignoreFilterNames.emplace_back(str);
309 std::vector<HLTPath> foundPaths;
310 const std::vector<std::string>& triggerNames = HLTCP.
triggerNames();
316 if(boost::regex_match(
path, what, re)) {
317 foundPaths.emplace_back(
path, what);
320 if(!foundPaths.empty())
323 if(foundPaths.empty()) {
324 std::stringstream ss;
325 for(std::vector<boost::regex>::const_iterator iRegex = pathRegexs_.begin(); iRegex != pathRegexs_.end(); ++iRegex) {
326 if(iRegex != pathRegexs_.begin())
330 edm::LogWarning(
"HLTTauDQMOffline") <<
"HLTTauDQMPath::beginRun(): did not find any paths matching to regexes " << ss.str();
335 std::vector<HLTPath>::const_iterator thePath = foundPaths.begin();
337 std::vector<HLTPath>::const_iterator iPath = thePath;
339 for(; iPath != foundPaths.end(); ++iPath) {
340 if(!thePath->isBetterThan(*iPath, HLTCP))
347 std::stringstream ss;
348 ss <<
"HLTTauDQMPath::beginRun(): " <<
dqmFolder_ <<
": chose path " << thePath->name() <<
"\n";
365 TauLeptonMultiplicity n = inferTauLeptonMultiplicity(HLTCP, filterName, moduleType);
374 <<
" nele " << n.electron
375 <<
" nmu " << n.muon;
384 const size_t tauProducerIndex = thePath->tauProducerIndex(HLTCP);
386 edm::LogWarning(
"HLTTauDQMOffline") <<
"HLTTauDQMPath::beginRun(): Did not find PFRecoTauProducer from HLT path " << thePath->name();
426 if(
fired(triggerResults)) {
435 lastPassedFilter =
i;
452 for(
size_t i=0; i<keys.size(); ++
i) {
462 std::vector<bool> offlineMask;
464 int matchedObjects = 0;
465 offlineMask.resize(offlineObjects.
taus.size());
466 std::fill(offlineMask.begin(), offlineMask.end(),
true);
467 for(
const Object& trgObj: triggerObjects) {
472 if(deltaRmatch(trgObj.object, offlineObjects.
taus, dR, offlineMask, matchedOfflineObjects.
taus)) {
474 matchedTriggerObjects.emplace_back(trgObj);
481 int matchedObjects = 0;
482 offlineMask.resize(offlineObjects.
electrons.size());
483 std::fill(offlineMask.begin(), offlineMask.end(),
true);
484 for(
const Object& trgObj: triggerObjects) {
489 if(deltaRmatch(trgObj.object, offlineObjects.
electrons, dR, offlineMask, matchedOfflineObjects.
electrons)) {
491 matchedTriggerObjects.emplace_back(trgObj);
498 int matchedObjects = 0;
499 offlineMask.resize(offlineObjects.
muons.size());
500 std::fill(offlineMask.begin(), offlineMask.end(),
true);
501 for(
const Object& trgObj: triggerObjects) {
506 if(deltaRmatch(trgObj.object, offlineObjects.
muons, dR, offlineMask, matchedOfflineObjects.
muons)) {
508 matchedTriggerObjects.emplace_back(trgObj);
515 std::sort(matchedOfflineObjects.
taus.begin(), matchedOfflineObjects.
taus.end(), [](
const LV&
a,
const LV&
b) {
return a.pt() >
b.pt();});
517 std::sort(matchedOfflineObjects.
muons.begin(), matchedOfflineObjects.
muons.end(), [](
const LV&
a,
const LV&
b) {
return a.pt() >
b.pt();});
std::vector< boost::regex > pathRegexs_
virtual char const * what() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::tuple< std::string, size_t > FilterIndex
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
bool goodOfflineEvent(size_t i, const HLTTauDQMOfflineObjects &offlineObjects) const
const std::string moduleType(const std::string &module) const
C++ class name of module.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
std::vector< LV > electrons
The single EDProduct to be saved for each event (AOD case)
trigger::size_type sizeFilters() const
std::vector< boost::regex > ignoreFilterTypes_
std::string dump(unsigned int indent=0) const
enum start value shifted to 81 so as to avoid clashes with PDG codes
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
const Keys & filterKeys(trigger::size_type index) const
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
int lastPassedFilter(const edm::TriggerResults &triggerResults) const
const edm::ParameterSet & modulePSet(const std::string &module) const
ParameterSet of module.
int getFilterNElectrons(size_t i) const
int getFilterNTaus(size_t i) const
const std::string hltProcess_
void initialize(const edm::ParameterSet &pset)
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
Single trigger physics object (e.g., an isolated muon)
const Vids & filterIds(trigger::size_type index) const
void getFilterObjects(const trigger::TriggerEvent &triggerEvent, size_t i, std::vector< Object > &retval) const
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
unsigned int moduleIndex(unsigned int trigger, const std::string &module) const
slot position of module on trigger path (0 to size-1)
int getFilterNMuons(size_t i) const
HLTTauDQMPath(const std::string &hltProcess, const std::string &dqmFolder, bool doRefAnalysis)
const T & max(const T &a, const T &b)
size_t lastFilterBeforeL2TauIndex_
const TriggerObjectCollection & getObjects() const
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
size_t filtersSize() const
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
size_t lastFilterBeforeL3TauIndex_
static std::string const triggerResults
bool beginRun(const HLTConfigProvider &HLTCP)
bool offlineMatching(size_t i, const std::vector< Object > &triggerObjects, const HLTTauDQMOfflineObjects &offlineObjects, double dR, std::vector< Object > &matchedTriggerObjects, HLTTauDQMOfflineObjects &matchedOfflineObjects) const
std::vector< int > filterTauN_
const std::string dqmFolder_
math::XYZTLorentzVectorD LV
std::vector< FilterIndex > filterIndices_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
size_t getFilterIndex(size_t i) const
const bool doRefAnalysis_
std::vector< boost::regex > ignoreFilterNames_
std::vector< size_type > Keys
const std::string & getFilterName(size_t i) const
size_t lastL3TauFilterIndex_
bool fired(const edm::TriggerResults &triggerResults) const
size_t lastL2TauFilterIndex_
std::vector< int > filterElectronN_
unsigned int prescaleSize() const
volatile std::atomic< bool > shutdown_flag false
std::vector< int > filterMuonN_