CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
128  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
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 {
139  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
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 {
150  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
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) {
201  const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
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 
352  std::string hltProcess,
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 
544 bool HLTTauDQMPath::fired(const edm::TriggerResults& triggerResults) const { return triggerResults.accept(pathIndex_); }
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) {
556  lastPassedFilter = i;
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);
572  const trigger::TriggerObjectCollection& triggerObjects = triggerEvent.getObjects();
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 }
const std::string pathName_
int getFilterLevel(size_t i) const
Definition: HLTTauDQMPath.h:79
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
bool isValid_(value_type const &hash)
Definition: Hash.cc:63
bool goodOfflineEvent(size_t i, const HLTTauDQMOfflineObjects &offlineObjects) const
const std::string moduleType(const std::string &module) const
C++ class name of module.
size_t lastL3ElectronFilterIndex_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
std::vector< LV > electrons
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
std::vector< int > filterMET_
std::vector< LV > taus
std::string dump(unsigned int indent=0) const
enum start value shifted to 81 so as to avoid clashes with PDG codes
size_t lastFilterBeforeL2METIndex_
bool accept() const
Has at least one path accepted the event?
std::tuple< std::string, std::string, size_t > FilterIndex
Definition: HLTTauDQMPath.h:26
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:132
bool exists(std::string const &parameterName) const
checks if a parameter exists
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
int lastPassedFilter(const edm::TriggerResults &triggerResults) const
size_t lastFilterBeforeL3ElectronIndex_
math::XYZTLorentzVectorD LV
Definition: HLTTauDQMPath.h:24
static const std::string kType("type")
const edm::ParameterSet & modulePSet(const std::string &module) const
ParameterSet of module.
int getFilterNElectrons(size_t i) const
Definition: HLTTauDQMPath.h:61
int getFilterNTaus(size_t i) const
Definition: HLTTauDQMPath.h:55
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 Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:117
void getFilterObjects(const trigger::TriggerEvent &triggerEvent, size_t i, std::vector< Object > &retval) const
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
Definition: HLTTauDQMPath.h:67
const unsigned int pathIndex_
size_t lastFilterBeforeL2TauIndex_
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
static constexpr size_t kName
Definition: HLTTauDQMPath.h:28
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
def move
Definition: eostools.py:511
size_t filtersSize() const
Definition: HLTTauDQMPath.h:52
#define input1
Definition: AMPTWrapper.h:139
size_t lastFilterBeforeL3TauIndex_
static std::string const triggerResults
Definition: EdmProvDump.cc:44
std::vector< LV > met
size_t lastFilterBeforeL2ElectronIndex_
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_
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::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
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_
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
std::vector< size_type > Keys
const std::string & getFilterName(size_t i) const
Definition: HLTTauDQMPath.h:53
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
size_t lastL3TauFilterIndex_
double b
Definition: hdecay.h:118
bool fired(const edm::TriggerResults &triggerResults) const
std::string const & label() const
Definition: InputTag.h:36
static constexpr size_t kType
Definition: HLTTauDQMPath.h:29
size_t lastL2TauFilterIndex_
int getFilterMET(size_t i) const
Definition: HLTTauDQMPath.h:73
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
double a
Definition: hdecay.h:119
std::vector< int > filterElectronN_
size_t lastL3MuonFilterIndex_
size_t lastL2ElectronFilterIndex_
size_t firstFilterBeforeL2METIndex_
tuple level
Definition: testEve_cfg.py:47
Log< level::Warning, false > LogWarning
std::vector< int > filterMuonN_
static constexpr size_t kModuleIndex
Definition: HLTTauDQMPath.h:30
std::vector< int > Vids
std::vector< LV > muons
static constexpr size_t kInvalidIndex
Definition: HLTTauDQMPath.h:31
size_t lastL2METFilterIndex_
#define LogDebug(id)
size_t lastFilterBeforeL2MuonIndex_
size_t firstL2METFilterIndex_