CMS 3D CMS Logo

HLTTauDQMPath.cc
Go to the documentation of this file.
3 
5 
10 
14 
15 #include <cstdio>
16 #include <sstream>
17 #include <algorithm>
18 #include <utility>
19 
20 namespace {
21  // Used as a helper only in this file
22  class HLTPath {
23  public:
24  HLTPath(std::string name) : name_(std::move(name)) {}
25 
26  using FilterIndex = HLTTauDQMPath::FilterIndex;
30  bool>
31  FilterIndexSave;
32 
33  constexpr static size_t kName = HLTTauDQMPath::kName;
34  constexpr static size_t kType = HLTTauDQMPath::kType;
35  constexpr static size_t kModuleIndex = HLTTauDQMPath::kModuleIndex;
36  constexpr static size_t kSaveTags = 3;
37 
38  std::vector<FilterIndex> interestingFilters(const HLTConfigProvider& HLTCP, bool doRefAnalysis) {
39  const std::vector<std::string>& moduleLabels = HLTCP.moduleLabels(name_);
40  std::vector<std::string> leptonTauFilters;
41  allInterestingFilters_.clear();
42 
43  // Ignore all "Selector"s, for ref-analysis keep only those with saveTags=True
44  // Also record HLT2(Electron|Muon)(PF)?Tau module names
45  LogTrace("HLTTauDQMOffline") << "Path " << name_
46  << ", list of all filters (preceded by the module index in the path)";
47  for (auto iLabel = moduleLabels.begin(); iLabel != moduleLabels.end(); ++iLabel) {
48  if (HLTCP.moduleEDMType(*iLabel) != "EDFilter")
49  continue;
50  const std::string type = HLTCP.moduleType(*iLabel);
51  LogTrace("HLTTauDQMOffline") << " " << std::distance(moduleLabels.begin(), iLabel) << " " << *iLabel << " "
52  << type << " saveTags " << HLTCP.saveTags(*iLabel);
53  if (type.find("Selector") != std::string::npos)
54  continue;
55  if (type == "HLTTriggerTypeFilter" || type == "HLTBool")
56  continue;
57  if (type == "HLT2PhotonPFTau" || type == "HLT2ElectronPFTau" || type == "HLT2MuonPFTau" ||
58  type == "HLT2PhotonTau" || type == "HLT2ElectronTau" || type == "HLT2MuonTau")
59  leptonTauFilters.emplace_back(*iLabel);
60  // else if(type.find("Electron") != std::string::npos || type.find("Egamma") != std::string::npos || type.find("Muon") != std::string::npos)
61  // continue;
62  allInterestingFilters_.emplace_back(*iLabel, type, iLabel - moduleLabels.begin(), HLTCP.saveTags(*iLabel));
63  }
64 
65  // Insert the last filters of lepton legs
66  for (const std::string& leptonTauLabel : leptonTauFilters) {
67  const edm::ParameterSet& pset = HLTCP.modulePSet(leptonTauLabel);
68  std::string input1 = pset.getParameter<edm::InputTag>("inputTag1").label();
69  std::string input2 = pset.getParameter<edm::InputTag>("inputTag2").label();
70  unsigned idx1 = HLTCP.moduleIndex(name_, input1);
71  unsigned idx2 = HLTCP.moduleIndex(name_, input2);
72  std::string type = "dummy"; //HLTCP.moduleType(name_);
73 
74  auto func = [&](const FilterIndexSave& a, unsigned idxb) { return std::get<kModuleIndex>(a) < idxb; };
75 
76  auto found = std::lower_bound(allInterestingFilters_.begin(), allInterestingFilters_.end(), idx1, func);
77  if (found == allInterestingFilters_.end() || std::get<kModuleIndex>(*found) != idx1)
78  allInterestingFilters_.emplace(found, input1, type, idx1, HLTCP.saveTags(input1));
79  found = std::lower_bound(allInterestingFilters_.begin(), allInterestingFilters_.end(), idx2, func);
80  if (found == allInterestingFilters_.end() || std::get<kModuleIndex>(*found) != idx2)
81  allInterestingFilters_.emplace(found, input2, type, idx2, HLTCP.saveTags(input1));
82  }
83 
84  std::vector<FilterIndex> selectedFilters;
85  // For reference-matched case exclude filters with saveTags=False.
86  // However, they are needed a bit later to find the position of the
87  // first L3 tau filter.
88  for (const auto& item : allInterestingFilters_) {
89  if (!doRefAnalysis || (doRefAnalysis && std::get<kSaveTags>(item))) {
90  selectedFilters.emplace_back(std::get<kName>(item), std::get<kType>(item), std::get<kModuleIndex>(item));
91  }
92  }
93 
94  return selectedFilters;
95  }
96 
97  bool isL3TauProducer(const HLTConfigProvider& HLTCP, const std::string& producerLabel) const {
98  const std::string type = HLTCP.moduleType(producerLabel);
99  if (type == "PFRecoTauProducer" || type == "RecoTauPiZeroUnembedder") {
100  LogDebug("HLTTauDQMOffline") << "Found tau producer " << type << " with label " << producerLabel
101  << " from path " << name_;
102  return true;
103  }
104  return false;
105  }
106 
107  bool isL3ElectronProducer(const HLTConfigProvider& HLTCP, const std::string& producerLabel) const {
108  const std::string type = HLTCP.moduleType(producerLabel);
109  if (type == "EgammaHLTPixelMatchElectronProducers") {
110  LogDebug("HLTTauDQMOffline") << "Found electron producer " << type << " with label " << producerLabel
111  << " from path " << name_;
112  return true;
113  }
114  return false;
115  }
116 
117  bool isL3MuonProducer(const HLTConfigProvider& HLTCP, const std::string& producerLabel) const {
118  const std::string type = HLTCP.moduleType(producerLabel);
119  if (type == "L3MuonCandidateProducer" || type == "L3MuonCombinedRelativeIsolationProducer") {
120  LogDebug("HLTTauDQMOffline") << "Found muon producer " << type << " with label " << producerLabel
121  << " from path " << name_;
122  return true;
123  }
124  return false;
125  }
126 
127  bool isL3TauFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
129  if (pset.exists("inputTag"))
130  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
131  if (pset.exists("inputTag1"))
132  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
133  if (pset.exists("inputTag2"))
134  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
135  return false;
136  }
137 
138  bool isL3ElectronFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
140  if (pset.exists("inputTag"))
141  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
142  if (pset.exists("inputTag1"))
143  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
144  if (pset.exists("inputTag2"))
145  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
146  return false;
147  }
148 
149  bool isL3MuonFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
151  if (pset.exists("inputTag"))
152  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
153  if (pset.exists("inputTag1"))
154  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
155  if (pset.exists("inputTag2"))
156  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
157  return false;
158  }
159 
160  size_t firstL3TauFilterIndex(const HLTConfigProvider& HLTCP) const {
161  // Loop over filters and check if a filter uses L3 tau producer
162  // output.
163  for (const auto& filter : allInterestingFilters_) {
164  if (isL3TauFilter(HLTCP, std::get<kName>(filter)))
165  return std::get<kModuleIndex>(filter);
166  }
168  }
169 
170  size_t firstL3ElectronFilterIndex(const HLTConfigProvider& HLTCP) const {
171  // Loop over filters and check if a filter uses L3 tau producer
172  // output.
173  for (const auto& filter : allInterestingFilters_) {
174  if (isL3ElectronFilter(HLTCP, std::get<kName>(filter)))
175  return std::get<kModuleIndex>(filter);
176  }
178  }
179 
180  size_t firstL3MuonFilterIndex(const HLTConfigProvider& HLTCP) const {
181  // Loop over filters and check if a filter uses L3 tau producer
182  // output.
183  for (const auto& filter : allInterestingFilters_) {
184  if (isL3MuonFilter(HLTCP, std::get<kName>(filter)))
185  return std::get<kModuleIndex>(filter);
186  }
188  }
189 
190  const std::string& name() const { return name_; }
191 
192  private:
193  std::string name_;
194 
195  std::vector<FilterIndexSave> allInterestingFilters_;
196  };
197 
198  int getParameterSafe(const HLTConfigProvider& HLTCP,
199  const std::string& filterName,
200  const std::string& parameterName) {
202  if (pset.existsAs<int>(parameterName))
203  return pset.getParameter<int>(parameterName);
204  else {
205  edm::LogWarning("HLTTauDQMOfflineSource") << "No parameter '" << parameterName << "' in configuration of filter "
206  << filterName << " pset " << pset.dump() << std::endl;
207  return 0;
208  }
209  }
210 
211  struct TauLeptonMultiplicity {
212  TauLeptonMultiplicity() : tau(0), electron(0), muon(0), met(0), level(0) {}
213  int tau;
214  int electron;
215  int muon;
216  int met;
217  int level;
218  };
219  TauLeptonMultiplicity inferTauLeptonMultiplicity(const HLTConfigProvider& HLTCP,
220  const std::string& filterName,
221  const std::string& moduleType,
222  const std::string& pathName) {
223  TauLeptonMultiplicity n;
224  //std::cout << "check menu " << HLTCP.tableName() << std::endl;
225  if (moduleType == "HLTL1TSeed") {
226  n.level = 1;
227  if (filterName.find("Single") != std::string::npos) {
228  if (filterName.find("Mu") != std::string::npos) {
229  n.muon = 1;
230  } else if (filterName.find("EG") != std::string::npos) {
231  n.electron = 1;
232  }
233  } else if (filterName.find("Double") != std::string::npos && filterName.find("Tau") != std::string::npos) {
234  n.tau = 2;
235  }
236  // else if(filterName.find("Mu") != std::string::npos && filterName.find("Tau") != std::string::npos) {
237  if (filterName.find("Mu") != std::string::npos) {
238  n.muon = 1;
239  //n.tau = 1;
240  }
241  if (filterName.find("EG") != std::string::npos && filterName.find("Tau") != std::string::npos) {
242  n.electron = 1;
243  //n.tau = 1;
244  }
245  if (filterName.find("ETM") != std::string::npos) {
246  n.met = 1;
247  }
248  } else if (moduleType == "HLT1CaloMET") {
249  n.level = 2;
250  if (getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerMET) {
251  n.met = 1;
252  }
253  } else if (moduleType == "HLT1CaloJet") {
254  n.level = 2;
255  if (getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerTau) {
256  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
257  }
258  } else if (moduleType == "HLT1PFJet") {
259  n.level = 3;
260  //const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
261  //pset.getParameter<int>("triggerType") == trigger::TriggerTau) {
262  if (getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerTau) {
263  //n.tau = pset.getParameter<int>("MinN");
264  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
265  }
266  } else if (moduleType == "HLTCaloJetTag") {
267  n.level = 2;
268  //const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
269  //if(pset.getParameter<int>("triggerType") == trigger::TriggerTau) {
270  if (getParameterSafe(HLTCP, filterName, "TriggerType") == trigger::TriggerTau) {
271  //n.tau = pset.getParameter<int>("MinJets");
272  n.tau = getParameterSafe(HLTCP, filterName, "MinJets");
273  }
274  } else if (moduleType == "HLT1Tau" || moduleType == "HLT1PFTau") {
275  n.level = 3;
276  //n.tau = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
277  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
278  } else if (moduleType == "HLTPFTauPairDzMatchFilter") {
279  n.level = 3;
280  n.tau = 2;
281  } else if (moduleType == "HLTEgammaGenericFilter") {
282  n.level = 3;
283  n.electron = getParameterSafe(HLTCP, filterName, "ncandcut");
284  } else if (moduleType == "HLTElectronGenericFilter") {
285  n.level = 3;
286  //n.electron = HLTCP.modulePSet(filterName).getParameter<int>("ncandcut");
287  n.electron = getParameterSafe(HLTCP, filterName, "ncandcut");
288  } else if (moduleType == "HLTMuonL2PreFilter") {
289  n.level = 2;
290  //n.muon = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
291  n.muon = getParameterSafe(HLTCP, filterName, "MinN");
292  } else if (moduleType == "HLTMuonIsoFilter" || moduleType == "HLTMuonL3PreFilter") {
293  n.level = 3;
294  n.muon = getParameterSafe(HLTCP, filterName, "MinN");
295  } else if (moduleType == "HLTMuonGenericFilter") {
296  n.level = 3;
297  n.muon = 1;
298  } else if (moduleType == "HLT2ElectronTau" || moduleType == "HLT2ElectronPFTau" || moduleType == "HLT2PhotonTau" ||
299  moduleType == "HLT2PhotonPFTau") {
300  n.level = 3;
301  //int num = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
302  int num = getParameterSafe(HLTCP, filterName, "MinN");
303  n.tau = num;
304  n.electron = num;
305  } else if (moduleType == "HLT2MuonTau" || moduleType == "HLT2MuonPFTau") {
306  n.level = 3;
307  //int num = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
308  int num = getParameterSafe(HLTCP, filterName, "MinN");
309  n.tau = num;
310  n.muon = num;
311  } else if (moduleType == "HLTPrescaler") { // || moduleType == "HLT1CaloMET") {
312  // ignore
313  } else {
314  edm::LogInfo("HLTTauDQMOfflineSource")
315  << "HLTTauDQMPath.cc, inferTauLeptonMultiplicity(): module type '" << moduleType
316  << "' not recognized, filter '" << filterName << "' in path '" << pathName
317  << "' will be ignored for offline matching." << std::endl;
318  }
319  return n;
320  }
321 
322  template <typename T1, typename T2>
323  bool deltaRmatch(const T1& obj,
324  const std::vector<T2>& refColl,
325  double dR,
326  std::vector<bool>& refMask,
327  std::vector<T2>& matchedRefs) {
328  double minDr = 2 * dR;
329  size_t found = refColl.size();
330  //std::cout << "Matching with DR " << dR << ", obj eta " << obj.eta() << " phi " << obj.phi() << std::endl;
331  for (size_t i = 0; i < refColl.size(); ++i) {
332  if (!refMask[i])
333  continue;
334 
335  double dr = reco::deltaR(obj, refColl[i]);
336  //std::cout << " " << i << " ref eta " << refColl[i].eta() << " phi " << refColl[i].phi() << " dr " << dr << std::endl;
337  if (dr < minDr) {
338  minDr = dr;
339  found = i;
340  }
341  }
342  if (found < refColl.size()) {
343  matchedRefs.emplace_back(refColl[found]);
344  refMask[found] = false;
345  return true;
346  }
347  return false;
348  }
349 } // namespace
350 
353  bool doRefAnalysis,
354  const HLTConfigProvider& HLTCP)
355  : hltProcess_(std::move(hltProcess)),
356  doRefAnalysis_(doRefAnalysis),
357  pathName_(std::move(pathName)),
358  pathIndex_(HLTCP.triggerIndex(pathName_)),
359  lastFilterBeforeL2TauIndex_(0),
360  lastL2TauFilterIndex_(0),
361  lastFilterBeforeL3TauIndex_(0),
362  lastL3TauFilterIndex_(0),
363  lastFilterBeforeL2ElectronIndex_(0),
364  lastL2ElectronFilterIndex_(0),
365  lastFilterBeforeL2MuonIndex_(0),
366  lastL2MuonFilterIndex_(0),
367  lastFilterBeforeL2METIndex_(0),
368  lastL2METFilterIndex_(0),
369  firstFilterBeforeL2METIndex_(0),
370  firstL2METFilterIndex_(0),
371 
372  isFirstL1Seed_(false),
373  isValid_(false) {
374 #ifdef EDM_ML_DEBUG
375  std::stringstream ss;
376  ss << "HLTTauDQMPath: " << pathName_ << "\n";
377 #endif
378  // Get the filters
379  HLTPath thePath(pathName_);
380  filterIndices_ = thePath.interestingFilters(HLTCP, doRefAnalysis_);
381  if (filterIndices_.empty()) {
382  edm::LogInfo("HLTTauDQMOffline") << "HLTTauDQMPath: " << pathName_ << " no interesting filters found";
383  return;
384  }
385  isFirstL1Seed_ = HLTCP.moduleType(std::get<kName>(filterIndices_[0])) == "HLTL1TSeed";
386 #ifdef EDM_ML_DEBUG
387  ss << " Interesting filters (preceded by the module index in the path)";
388 #endif
389  // Set the filter multiplicity counts
390  filterTauN_.clear();
391  filterElectronN_.clear();
392  filterMuonN_.clear();
393  filterMET_.clear();
394  filterTauN_.reserve(filterIndices_.size());
395  filterElectronN_.reserve(filterIndices_.size());
396  filterMuonN_.reserve(filterIndices_.size());
397  filterMET_.reserve(filterIndices_.size());
398  filterLevel_.reserve(filterIndices_.size());
399 #ifdef EDM_ML_DEBUG
400  size_t i(0);
401 #endif
402  for (auto& filterIndice : filterIndices_) {
403  const std::string& filterName = std::get<kName>(filterIndice);
404  const std::string& moduleType = HLTCP.moduleType(filterName);
405 
406  TauLeptonMultiplicity n = inferTauLeptonMultiplicity(HLTCP, filterName, moduleType, pathName_);
407  filterTauN_.push_back(n.tau);
408  filterElectronN_.push_back(n.electron);
409  filterMuonN_.push_back(n.muon);
410  filterMET_.push_back(n.met);
411  filterLevel_.push_back(n.level);
412 
413 #ifdef EDM_ML_DEBUG
414  ss << "\n " << i << " " << std::get<kModuleIndex>(filterIndice) << " " << filterName << " " << moduleType
415  << " ntau " << n.tau << " nele " << n.electron << " nmu " << n.muon;
416  i++;
417 #endif
418  }
419 #ifdef EDM_ML_DEBUG
420  LogDebug("HLTTauDQMOffline") << ss.str();
421 #endif
422 
423  // Find the position of tau producer, use filters with taus before
424  // it for L2 tau efficiency, and filters with taus after it for L3
425  // tau efficiency. Here we have to take into account that for
426  // reference-matched case filterIndices_ contains only those filters
427  // that have saveTags=True, while for searching the first L3 tau
428  // filter we have to consider all filters
429  const size_t firstL3TauFilterIndex = thePath.firstL3TauFilterIndex(HLTCP);
430  if (firstL3TauFilterIndex == kInvalidIndex) {
431  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 tau producer as input in path " << pathName_;
432  }
433  const size_t firstL3ElectronFilterIndex = thePath.firstL3ElectronFilterIndex(HLTCP);
434  if (firstL3ElectronFilterIndex == kInvalidIndex) {
435  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 electron producer as input in path "
436  << pathName_;
437  }
438  const size_t firstL3MuonFilterIndex = thePath.firstL3MuonFilterIndex(HLTCP);
439  if (firstL3MuonFilterIndex == kInvalidIndex) {
440  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 muon producer as input in path " << pathName_;
441  }
442 
459  /*
460  size_t i = 0;
461  for(; i<filtersSize() && getFilterIndex(i) < firstL3TauFilterIndex; ++i) {
462  if(lastL2TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
463  lastFilterBeforeL2TauIndex_ = i;
464  if(getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
465  lastL2TauFilterIndex_ = i;
466  }
467  lastFilterBeforeL3TauIndex_ = i-1;
468  for(; i<filtersSize(); ++i) {
469  if(lastL3TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
470  lastFilterBeforeL3TauIndex_ = i;
471  if(getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
472  lastL3TauFilterIndex_ = i;
473  }
474 */
475  for (size_t i = 0; i < filtersSize(); ++i) {
476  // Tau
477  if (getFilterLevel(i) == 2 && getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
481 
482  // if(lastFilterBeforeL3TauIndex_ < 2 && lastL3TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
483  // lastFilterBeforeL3TauIndex_ = i;
484  if (getFilterLevel(i) == 3 && getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
488 
489  // Electron
492  if (getFilterLevel(i) == 2 && getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
494 
495  if (getFilterLevel(i) == 3 && getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
499  /*
500  if(lastL2ElectronFilterIndex_ == kInvalidIndex && getFilterNElectrons(i) == 0)
501  lastFilterBeforeL2ElectronIndex_ = i;
502  if(getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
503  lastL2ElectronFilterIndex_ = i;
504 
505  if(lastFilterBeforeL3ElectronIndex_ == 0 && lastL3ElectronFilterIndex_ == kInvalidIndex && getFilterNElectrons(i) == 0)
506  lastFilterBeforeL3ElectronIndex_ = i;
507  if(getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
508  lastL3ElectronFilterIndex_ = i;
509 */
510  // Muon
513  if (getFilterLevel(i) == 2 && getFilterNMuons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNElectrons(i) == 0)
515 
516  if (getFilterLevel(i) == 3 && getFilterNMuons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNElectrons(i) == 0)
520 
521  // MET
524  if (getFilterMET(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
526 
530  getFilterNMuons(i) == 0)
532  }
533  // lastFilterBeforeL3TauIndex_ = firstL3TauFilterIndex - 1;
534  // lastFilterBeforeL3ElectronIndex_ = firstL3ElectronFilterIndex - 1;
535  // lastFilterBeforeL3MuonIndex_ = firstL3MuonFilterIndex - 1;
536  LogDebug("HLTTauDQMOffline") << "lastFilterBeforeL2 " << lastFilterBeforeL2TauIndex_ << " lastL2TauFilter "
537  << lastL2TauFilterIndex_ << " lastFilterBeforeL3 " << lastFilterBeforeL3TauIndex_
538  << " lastL3TauFilter " << lastL3TauFilterIndex_;
539  isValid_ = true;
540 }
541 
543 
545 
547  if (fired(triggerResults)) {
548  //std::cout << "Event passed" << std::endl;
549  return filterIndices_.size() - 1;
550  }
551 
552  unsigned int firstFailedFilter = triggerResults.index(pathIndex_);
553  int lastPassedFilter = -1;
554  for (size_t i = 0; i < filterIndices_.size(); ++i) {
555  if (std::get<kModuleIndex>(filterIndices_[i]) < firstFailedFilter) {
557  } else {
558  //std::cout << "Decision-making filter " << firstFailedFilter << " this " << std::get<kModuleIndex>(filterIndices_[i]) << std::endl;
559  break;
560  }
561  }
562  return lastPassedFilter;
563 }
564 
566  size_t i,
567  std::vector<Object>& retval) const {
568  trigger::size_type filterIndex = triggerEvent.filterIndex(edm::InputTag(getFilterName(i), "", hltProcess_));
569  if (filterIndex != triggerEvent.sizeFilters()) {
570  const trigger::Keys& keys = triggerEvent.filterKeys(filterIndex);
571  const trigger::Vids& ids = triggerEvent.filterIds(filterIndex);
573  for (size_t i = 0; i < keys.size(); ++i) {
574  const trigger::TriggerObject& object = triggerObjects[keys[i]];
575  retval.emplace_back(Object{object, ids[i]});
576  }
577  }
578 }
579 
581  const std::vector<Object>& triggerObjects,
582  const HLTTauDQMOfflineObjects& offlineObjects,
583  double dR,
584  std::vector<Object>& matchedTriggerObjects,
585  HLTTauDQMOfflineObjects& matchedOfflineObjects) const {
586  bool isL1 = (i == 0 && isFirstL1Seed_);
587  std::vector<bool> offlineMask;
588  if (filterTauN_[i] > 0) {
589  int matchedObjects = 0;
590  offlineMask.resize(offlineObjects.taus.size());
591  std::fill(offlineMask.begin(), offlineMask.end(), true);
592  for (const Object& trgObj : triggerObjects) {
593  //std::cout << "trigger object id " << isL1 << " " << trgObj.id << " " << trigger::TriggerL1Tau << " "<< trigger::TriggerTau << std::endl;
594  if (!((isL1 && trgObj.id == trigger::TriggerL1Tau) || trgObj.id == trigger::TriggerTau))
595  continue;
596  if (deltaRmatch(trgObj.object, offlineObjects.taus, dR, offlineMask, matchedOfflineObjects.taus)) {
597  ++matchedObjects;
598  matchedTriggerObjects.emplace_back(trgObj);
599  //std::cout << "trigger object DR match" << std::endl;
600  }
601  }
602  if (matchedObjects < filterTauN_[i])
603  return false;
604  }
605  if (filterElectronN_[i] > 0) {
606  int matchedObjects = 0;
607  offlineMask.resize(offlineObjects.electrons.size());
608  std::fill(offlineMask.begin(), offlineMask.end(), true);
609  for (const Object& trgObj : triggerObjects) {
610  //std::cout << "trigger object id " << trgObj.id << std::endl;
611  if (!((isL1 && (trgObj.id == trigger::TriggerL1EG)) || trgObj.id == trigger::TriggerElectron ||
612  trgObj.id == trigger::TriggerPhoton))
613  continue;
614  if (deltaRmatch(trgObj.object, offlineObjects.electrons, dR, offlineMask, matchedOfflineObjects.electrons)) {
615  ++matchedObjects;
616  matchedTriggerObjects.emplace_back(trgObj);
617  }
618  }
619  if (matchedObjects < filterElectronN_[i])
620  return false;
621  }
622  if (filterMuonN_[i] > 0) {
623  int matchedObjects = 0;
624  offlineMask.resize(offlineObjects.muons.size());
625  std::fill(offlineMask.begin(), offlineMask.end(), true);
626  for (const Object& trgObj : triggerObjects) {
627  //std::cout << "trigger object id " << trgObj.id << std::endl;
628  if (!((isL1 && trgObj.id == trigger::TriggerL1Mu) || trgObj.id == trigger::TriggerMuon))
629  continue;
630  if (deltaRmatch(trgObj.object, offlineObjects.muons, dR, offlineMask, matchedOfflineObjects.muons)) {
631  ++matchedObjects;
632  matchedTriggerObjects.emplace_back(trgObj);
633  }
634  }
635  if (matchedObjects < filterMuonN_[i])
636  return false;
637  }
638  if (filterMET_[i] > 0) {
639  int matchedObjects = 0;
640  offlineMask.resize(offlineObjects.met.size());
641  std::fill(offlineMask.begin(), offlineMask.end(), true);
642  for (const Object& trgObj : triggerObjects) {
643  if (!((isL1 && (trgObj.id == trigger::TriggerL1ETM || trgObj.id == trigger::TriggerL1ETMHF)) ||
644  trgObj.id == trigger::TriggerMET))
645  continue;
646  ++matchedObjects;
647  matchedTriggerObjects.emplace_back(trgObj);
648  }
649  if (matchedObjects < filterMET_[i]) {
650  return false;
651  }
652  }
653 
654  // Sort offline objects by pt
655  std::sort(matchedOfflineObjects.taus.begin(), matchedOfflineObjects.taus.end(), [](const LV& a, const LV& b) {
656  return a.pt() > b.pt();
657  });
658  std::sort(matchedOfflineObjects.electrons.begin(),
659  matchedOfflineObjects.electrons.end(),
660  [](const LV& a, const LV& b) { return a.pt() > b.pt(); });
661  std::sort(matchedOfflineObjects.muons.begin(), matchedOfflineObjects.muons.end(), [](const LV& a, const LV& b) {
662  return a.pt() > b.pt();
663  });
664  matchedOfflineObjects.met = offlineObjects.met;
665  return true;
666 }
667 
668 bool HLTTauDQMPath::goodOfflineEvent(size_t i, const HLTTauDQMOfflineObjects& offlineObjects) const {
669  return (static_cast<size_t>(getFilterNTaus(i)) <= offlineObjects.taus.size() &&
670  static_cast<size_t>(getFilterNElectrons(i)) <= offlineObjects.electrons.size() &&
671  static_cast<size_t>(getFilterNMuons(i)) <= offlineObjects.muons.size());
672 }
HLTConfigProvider::moduleIndex
unsigned int moduleIndex(unsigned int trigger, const std::string &module) const
slot position of module on trigger path (0 to size-1)
Definition: HLTConfigProvider.h:96
personalPlayback.level
level
Definition: personalPlayback.py:22
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
mps_fire.i
i
Definition: mps_fire.py:428
kType
static const std::string kType("type")
trigger::TriggerElectron
Definition: TriggerTypeDefs.h:78
HLTTauDQMPath::fired
bool fired(const edm::TriggerResults &triggerResults) const
Definition: HLTTauDQMPath.cc:544
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HLTConfigProvider::moduleType
const std::string moduleType(const std::string &module) const
C++ class name of module.
Definition: HLTConfigProvider.h:104
HLTTauDQMPath::lastFilterBeforeL3MuonIndex_
size_t lastFilterBeforeL3MuonIndex_
Definition: HLTTauDQMPath.h:154
HLTTauDQMPath::lastL2TauFilterIndex_
size_t lastL2TauFilterIndex_
Definition: HLTTauDQMPath.h:145
triggerMatchMonitor_cfi.triggerObjects
triggerObjects
Definition: triggerMatchMonitor_cfi.py:15
HLTTauDQMPath::doRefAnalysis_
const bool doRefAnalysis_
Definition: HLTTauDQMPath.h:134
trigger::Vids
std::vector< int > Vids
Definition: TriggerTypeDefs.h:21
TriggerResults.h
HLTTauDQMPath::isValid_
bool isValid_
Definition: HLTTauDQMPath.h:161
metsig::tau
Definition: SignAlgoResolutions.h:49
muon
Definition: MuonCocktails.h:17
HLTTauDQMPath::lastFilterBeforeL3ElectronIndex_
size_t lastFilterBeforeL3ElectronIndex_
Definition: HLTTauDQMPath.h:150
TriggerNamesService.h
HLTTauDQMPath::filterElectronN_
std::vector< int > filterElectronN_
Definition: HLTTauDQMPath.h:138
TriggerEvent.h
HLTTauDQMPath::filterMuonN_
std::vector< int > filterMuonN_
Definition: HLTTauDQMPath.h:139
HLTTauDQMPath::getFilterNTaus
int getFilterNTaus(size_t i) const
Definition: HLTTauDQMPath.h:55
HLTTauDQMPath::lastFilterBeforeL3TauIndex_
size_t lastFilterBeforeL3TauIndex_
Definition: HLTTauDQMPath.h:146
trigger::TriggerTau
Definition: TriggerTypeDefs.h:80
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
HLTTauDQMPath::lastL2MuonFilterIndex_
size_t lastL2MuonFilterIndex_
Definition: HLTTauDQMPath.h:153
edm::hash_detail::isValid_
bool isValid_(value_type const &hash)
Definition: Hash.cc:63
HLTTauDQMPath::lastPassedFilter
int lastPassedFilter(const edm::TriggerResults &triggerResults) const
Definition: HLTTauDQMPath.cc:546
HLTTauDQMPath::hltProcess_
const std::string hltProcess_
Definition: HLTTauDQMPath.h:133
HLTTauDQMPath::kInvalidIndex
constexpr static size_t kInvalidIndex
Definition: HLTTauDQMPath.h:31
SUSYBSM_Ele_HT_BTag_SingleLepton_cff.hltProcess
hltProcess
Definition: SUSYBSM_Ele_HT_BTag_SingleLepton_cff.py:26
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
HLTTauDQMPath::lastL2ElectronFilterIndex_
size_t lastL2ElectronFilterIndex_
Definition: HLTTauDQMPath.h:149
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HLTTauDQMPath::lastFilterBeforeL2METIndex_
size_t lastFilterBeforeL2METIndex_
Definition: HLTTauDQMPath.h:156
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
HLTTauDQMPath::lastL3TauFilterIndex_
size_t lastL3TauFilterIndex_
Definition: HLTTauDQMPath.h:147
HLTTauDQMPath::lastFilterBeforeL2MuonIndex_
size_t lastFilterBeforeL2MuonIndex_
Definition: HLTTauDQMPath.h:152
HLTTauDQMPath::FilterIndex
std::tuple< std::string, std::string, size_t > FilterIndex
Definition: HLTTauDQMPath.h:26
HLTTauDQMPath::getFilterNMuons
int getFilterNMuons(size_t i) const
Definition: HLTTauDQMPath.h:67
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
HLTConfigProvider::moduleLabels
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
Definition: HLTConfigProvider.h:76
trigger::TriggerMET
Definition: TriggerTypeDefs.h:83
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
HLTTauDQMPath::filterTauN_
std::vector< int > filterTauN_
Definition: HLTTauDQMPath.h:137
HLTTauDQMPlotter.h
hltMonBTagIPClient_cfi.pathName
pathName
Definition: hltMonBTagIPClient_cfi.py:5
HLTTauDQMPath::LV
math::XYZTLorentzVectorD LV
Definition: HLTTauDQMPath.h:24
HLTConfigProvider::saveTags
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
Definition: HLTConfigProvider.h:116
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11710
HLTTauDQMPath::HLTTauDQMPath
HLTTauDQMPath(std::string pathName, std::string hltProcess, bool doRefAnalysis, const HLTConfigProvider &HLTCP)
Definition: HLTTauDQMPath.cc:351
Service.h
HLTTauDQMPath::lastL2METFilterIndex_
size_t lastL2METFilterIndex_
Definition: HLTTauDQMPath.h:157
HLTTauDQMOfflineObjects::electrons
std::vector< LV > electrons
Definition: HLTTauDQMPlotter.h:24
trigger::TriggerL1ETMHF
Definition: TriggerTypeDefs.h:50
HLTTauDQMOfflineObjects
Definition: HLTTauDQMPlotter.h:18
trigger::TriggerMuon
Definition: TriggerTypeDefs.h:79
metsig::electron
Definition: SignAlgoResolutions.h:48
HLTTauDQMPath::getFilterNElectrons
int getFilterNElectrons(size_t i) const
Definition: HLTTauDQMPath.h:61
HLTTauDQMPath::~HLTTauDQMPath
~HLTTauDQMPath()
HLTConfigProvider::moduleEDMType
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
Definition: HLTConfigProvider.h:107
b
double b
Definition: hdecay.h:118
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
trigger::TriggerObject
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
HLTTauDQMPath::Object
Definition: HLTTauDQMPath.h:33
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.filterLabel
filterLabel
Definition: HLT_FULL_cff.py:89702
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
HLTConfigProvider::modulePSet
const edm::ParameterSet & modulePSet(const std::string &module) const
ParameterSet of module.
Definition: HLTConfigProvider.h:113
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
HLTTauDQMPath::kModuleIndex
constexpr static size_t kModuleIndex
Definition: HLTTauDQMPath.h:30
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
HLTTauDQMPath::goodOfflineEvent
bool goodOfflineEvent(size_t i, const HLTTauDQMOfflineObjects &offlineObjects) const
Definition: HLTTauDQMPath.cc:668
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
trigger::TriggerL1Tau
Definition: TriggerTypeDefs.h:49
deltaR.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
trigger::TriggerL1Mu
enum start value shifted to 81 so as to avoid clashes with PDG codes
Definition: TriggerTypeDefs.h:30
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
HLTTauDQMPath::lastFilterBeforeL2TauIndex_
size_t lastFilterBeforeL2TauIndex_
Definition: HLTTauDQMPath.h:144
HLTTauDQMPath::isFirstL1Seed_
bool isFirstL1Seed_
Definition: HLTTauDQMPath.h:160
trigger::TriggerObjectCollection
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
HLTTauDQMOfflineObjects::met
std::vector< LV > met
Definition: HLTTauDQMPlotter.h:28
HLTTauDQMPath::filtersSize
size_t filtersSize() const
Definition: HLTTauDQMPath.h:52
TriggerNames.h
HLTTauDQMOfflineObjects::muons
std::vector< LV > muons
Definition: HLTTauDQMPlotter.h:26
trigger::Keys
std::vector< size_type > Keys
Definition: TriggerTypeDefs.h:19
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
HLTTauDQMPath::getFilterName
const std::string & getFilterName(size_t i) const
Definition: HLTTauDQMPath.h:53
trigger::TriggerEvent
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
HLTConfigProvider.h
HLTTauDQMPath.h
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
trigger::TriggerL1EG
Definition: TriggerTypeDefs.h:47
PDWG_DiPhoton_SD_cff.triggerEvent
triggerEvent
Definition: PDWG_DiPhoton_SD_cff.py:39
input2
#define input2
Definition: AMPTWrapper.h:159
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
HLTTauDQMPath::pathName_
const std::string pathName_
Definition: HLTTauDQMPath.h:142
pdwgDoubleElectron_cfi.filterName
filterName
Definition: pdwgDoubleElectron_cfi.py:7
HLTTauDQMPath::filterLevel_
std::vector< int > filterLevel_
Definition: HLTTauDQMPath.h:141
HLTTauDQMPath::lastFilterBeforeL2ElectronIndex_
size_t lastFilterBeforeL2ElectronIndex_
Definition: HLTTauDQMPath.h:148
HLTConfigProvider
Definition: HLTConfigProvider.h:29
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HLTTauDQMPath::offlineMatching
bool offlineMatching(size_t i, const std::vector< Object > &triggerObjects, const HLTTauDQMOfflineObjects &offlineObjects, double dR, std::vector< Object > &matchedTriggerObjects, HLTTauDQMOfflineObjects &matchedOfflineObjects) const
Definition: HLTTauDQMPath.cc:580
HLTTauDQMPath::getFilterMET
int getFilterMET(size_t i) const
Definition: HLTTauDQMPath.h:73
HLTTauDQMPath::kName
constexpr static size_t kName
Definition: HLTTauDQMPath.h:28
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
HLTTauDQMOfflineObjects::taus
std::vector< LV > taus
Definition: HLTTauDQMPlotter.h:27
HLTTauDQMPath::getFilterLevel
int getFilterLevel(size_t i) const
Definition: HLTTauDQMPath.h:79
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trigger::TriggerL1ETM
Definition: TriggerTypeDefs.h:36
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
HLTTauDQMPath::lastL3ElectronFilterIndex_
size_t lastL3ElectronFilterIndex_
Definition: HLTTauDQMPath.h:151
HLTTauDQMPath::pathIndex_
const unsigned int pathIndex_
Definition: HLTTauDQMPath.h:143
HLTTauDQMPath::filterIndices_
std::vector< FilterIndex > filterIndices_
Definition: HLTTauDQMPath.h:136
HLTTauDQMPath::firstL2METFilterIndex_
size_t firstL2METFilterIndex_
Definition: HLTTauDQMPath.h:159
pwdgSkimBPark_cfi.HLTPath
HLTPath
Definition: pwdgSkimBPark_cfi.py:19
HLTTauDQMPath::filterMET_
std::vector< int > filterMET_
Definition: HLTTauDQMPath.h:140
trigger::TriggerPhoton
HLT.
Definition: TriggerTypeDefs.h:77
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
input1
#define input1
Definition: AMPTWrapper.h:139
HLTTauDQMPath::kType
constexpr static size_t kType
Definition: HLTTauDQMPath.h:29
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
HLTTauDQMPath::lastL3MuonFilterIndex_
size_t lastL3MuonFilterIndex_
Definition: HLTTauDQMPath.h:155
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::TriggerResults
Definition: TriggerResults.h:35
HLTTauDQMPath::getFilterObjects
void getFilterObjects(const trigger::TriggerEvent &triggerEvent, size_t i, std::vector< Object > &retval) const
Definition: HLTTauDQMPath.cc:565
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
HLTTauDQMPath::firstFilterBeforeL2METIndex_
size_t firstFilterBeforeL2METIndex_
Definition: HLTTauDQMPath.h:158