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