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