CMS 3D CMS Logo

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