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:
25  name_(std::move(name))
26  {}
27 
28  using FilterIndex = HLTTauDQMPath::FilterIndex;
32  bool> FilterIndexSave;
33 
34  constexpr static size_t kName = HLTTauDQMPath::kName;
35  constexpr static size_t kType = HLTTauDQMPath::kType;
36  constexpr static size_t kModuleIndex = HLTTauDQMPath::kModuleIndex;
37  constexpr static size_t kSaveTags = 3;
38 
39  std::vector<FilterIndex> interestingFilters(const HLTConfigProvider& HLTCP, bool doRefAnalysis) {
40  const std::vector<std::string>& moduleLabels = HLTCP.moduleLabels(name_);
41  std::vector<std::string> leptonTauFilters;
42  allInterestingFilters_.clear();
43 
44  // Ignore all "Selector"s, for ref-analysis keep only those with saveTags=True
45  // Also record HLT2(Electron|Muon)(PF)?Tau module names
46  LogTrace("HLTTauDQMOffline") << "Path " << name_ << ", 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 << " " << type << " saveTags " << HLTCP.saveTags(*iLabel);
52  if(type.find("Selector") != std::string::npos)
53  continue;
54  if(type == "HLTTriggerTypeFilter" || type == "HLTBool")
55  continue;
56  if(type == "HLT2PhotonPFTau" || type == "HLT2ElectronPFTau" || type == "HLT2MuonPFTau" || type == "HLT2PhotonTau" || type == "HLT2ElectronTau" || type == "HLT2MuonTau")
57  leptonTauFilters.emplace_back(*iLabel);
58 // else if(type.find("Electron") != std::string::npos || type.find("Egamma") != std::string::npos || type.find("Muon") != std::string::npos)
59 // continue;
60  allInterestingFilters_.emplace_back(*iLabel, type, iLabel-moduleLabels.begin(), HLTCP.saveTags(*iLabel));
61  }
62 
63  // Insert the last filters of lepton legs
64  for(const std::string& leptonTauLabel: leptonTauFilters) {
65  const edm::ParameterSet& pset = HLTCP.modulePSet(leptonTauLabel);
66  std::string input1 = pset.getParameter<edm::InputTag>("inputTag1").label();
67  std::string input2 = pset.getParameter<edm::InputTag>("inputTag2").label();
68  unsigned idx1 = HLTCP.moduleIndex(name_, input1);
69  unsigned idx2 = HLTCP.moduleIndex(name_, input2);
70  std::string type = "dummy";//HLTCP.moduleType(name_);
71 
72  auto func = [&](const FilterIndexSave& a, unsigned idxb) {
73  return std::get<kModuleIndex>(a) < idxb;
74  };
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 << " from path " << name_;
101  return true;
102  }
103  return false;
104  }
105 
106  bool isL3ElectronProducer(const HLTConfigProvider& HLTCP, const std::string& producerLabel) const {
107  const std::string type = HLTCP.moduleType(producerLabel);
108  if(type == "EgammaHLTPixelMatchElectronProducers") {
109  LogDebug("HLTTauDQMOffline") << "Found electron producer " << type << " with label " << producerLabel << " from path " << name_;
110  return true;
111  }
112  return false;
113  }
114 
115  bool isL3MuonProducer(const HLTConfigProvider& HLTCP, const std::string& producerLabel) const {
116  const std::string type = HLTCP.moduleType(producerLabel);
117  if(type == "L3MuonCandidateProducer" || type == "L3MuonCombinedRelativeIsolationProducer") {
118  LogDebug("HLTTauDQMOffline") << "Found muon producer " << type << " with label " << producerLabel << " from path " << name_;
119  return true;
120  }
121  return false;
122  }
123 
124  bool isL3TauFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
125  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
126  if(pset.exists("inputTag"))
127  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
128  if(pset.exists("inputTag1"))
129  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
130  if(pset.exists("inputTag2"))
131  return isL3TauProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
132  return false;
133  }
134 
135  bool isL3ElectronFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
136  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
137  if(pset.exists("inputTag"))
138  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
139  if(pset.exists("inputTag1"))
140  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
141  if(pset.exists("inputTag2"))
142  return isL3ElectronProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
143  return false;
144  }
145 
146  bool isL3MuonFilter(const HLTConfigProvider& HLTCP, const std::string& filterLabel) const {
147  const edm::ParameterSet& pset = HLTCP.modulePSet(filterLabel);
148  if(pset.exists("inputTag"))
149  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag").label());
150  if(pset.exists("inputTag1"))
151  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag1").label());
152  if(pset.exists("inputTag2"))
153  return isL3MuonProducer(HLTCP, pset.getParameter<edm::InputTag>("inputTag2").label());
154  return false;
155  }
156 
157  size_t firstL3TauFilterIndex(const HLTConfigProvider& HLTCP) const {
158  // Loop over filters and check if a filter uses L3 tau producer
159  // output.
160  for(const auto& filter: allInterestingFilters_) {
161  if(isL3TauFilter(HLTCP, std::get<kName>(filter)))
162  return std::get<kModuleIndex>(filter);
163  }
165  }
166 
167  size_t firstL3ElectronFilterIndex(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(isL3ElectronFilter(HLTCP, std::get<kName>(filter)))
172  return std::get<kModuleIndex>(filter);
173  }
175  }
176 
177  size_t firstL3MuonFilterIndex(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(isL3MuonFilter(HLTCP, std::get<kName>(filter)))
182  return std::get<kModuleIndex>(filter);
183  }
185  }
186 
187  const std::string& name() const { return name_; }
188 
189  private:
190  std::string name_;
191 
192  std::vector<FilterIndexSave> allInterestingFilters_;
193  };
194 
195  int getParameterSafe(const HLTConfigProvider& HLTCP, const std::string& filterName, const std::string& parameterName) {
196  const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
197  if(pset.existsAs<int>(parameterName))
198  return pset.getParameter<int>(parameterName);
199  else {
200  edm::LogWarning("HLTTauDQMOfflineSource") << "No parameter '" << parameterName << "' in configuration of filter " << filterName << " pset " << pset.dump() << std::endl;
201  return 0;
202  }
203  }
204 
205  struct TauLeptonMultiplicity {
206  TauLeptonMultiplicity(): tau(0), electron(0), muon(0), met(0), level(0) {}
207  int tau;
208  int electron;
209  int muon;
210  int met;
211  int level;
212  };
213  TauLeptonMultiplicity inferTauLeptonMultiplicity(const HLTConfigProvider& HLTCP, const std::string& filterName, const std::string& moduleType, const std::string& pathName) {
214  TauLeptonMultiplicity n;
215  //std::cout << "check menu " << HLTCP.tableName() << std::endl;
216  if(moduleType == "HLTL1TSeed") {
217  n.level = 1;
218  if(filterName.find("Single") != std::string::npos) {
219  if(filterName.find("Mu") != std::string::npos) {
220  n.muon = 1;
221  }
222  else if(filterName.find("EG") != std::string::npos) {
223  n.electron = 1;
224  }
225  }
226  else if(filterName.find("Double") != std::string::npos && filterName.find("Tau") != std::string::npos) {
227  n.tau = 2;
228  }
229 // else if(filterName.find("Mu") != std::string::npos && filterName.find("Tau") != std::string::npos) {
230  if(filterName.find("Mu") != std::string::npos) {
231  n.muon = 1;
232  //n.tau = 1;
233  }
234  if(filterName.find("EG") != std::string::npos && filterName.find("Tau") != std::string::npos) {
235  n.electron = 1;
236  //n.tau = 1;
237  }
238  if(filterName.find("ETM") != std::string::npos) {
239  n.met = 1;
240  }
241  }
242  else if(moduleType == "HLT1CaloMET") {
243  n.level = 2;
244  if(getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerMET) {
245  n.met = 1;
246  }
247  }
248  else if(moduleType == "HLT1CaloJet") {
249  n.level = 2;
250  if(getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerTau) {
251  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
252  }
253  }
254  else if(moduleType == "HLT1PFJet") {
255  n.level = 3;
256  //const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
257  //pset.getParameter<int>("triggerType") == trigger::TriggerTau) {
258  if(getParameterSafe(HLTCP, filterName, "triggerType") == trigger::TriggerTau) {
259  //n.tau = pset.getParameter<int>("MinN");
260  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
261  }
262  }
263  else if(moduleType == "HLTCaloJetTag") {
264  n.level = 2;
265  //const edm::ParameterSet& pset = HLTCP.modulePSet(filterName);
266  //if(pset.getParameter<int>("triggerType") == trigger::TriggerTau) {
267  if(getParameterSafe(HLTCP, filterName, "TriggerType") == trigger::TriggerTau) {
268  //n.tau = pset.getParameter<int>("MinJets");
269  n.tau = getParameterSafe(HLTCP, filterName, "MinJets");
270  }
271  }
272  else if(moduleType == "HLT1Tau" || moduleType == "HLT1PFTau") {
273  n.level = 3;
274  //n.tau = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
275  n.tau = getParameterSafe(HLTCP, filterName, "MinN");
276  }
277  else if(moduleType == "HLTPFTauPairDzMatchFilter") {
278  n.level = 3;
279  n.tau = 2;
280  }
281  else if(moduleType == "HLTEgammaGenericFilter") {
282  n.level = 3;
283  n.electron = getParameterSafe(HLTCP, filterName, "ncandcut");
284  }
285  else if(moduleType == "HLTElectronGenericFilter") {
286  n.level = 3;
287  //n.electron = HLTCP.modulePSet(filterName).getParameter<int>("ncandcut");
288  n.electron = getParameterSafe(HLTCP, filterName, "ncandcut");
289  }
290  else if(moduleType == "HLTMuonL2PreFilter") {
291  n.level = 2;
292  //n.muon = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
293  n.muon = getParameterSafe(HLTCP, filterName, "MinN");
294  }
295  else if(moduleType == "HLTMuonIsoFilter" || moduleType == "HLTMuonL3PreFilter") {
296  n.level = 3;
297  n.muon = getParameterSafe(HLTCP, filterName, "MinN");
298  }
299  else if(moduleType == "HLTMuonGenericFilter") {
300  n.level = 3;
301  n.muon = 1;
302  }
303  else if(moduleType == "HLT2ElectronTau" || moduleType == "HLT2ElectronPFTau" || moduleType == "HLT2PhotonTau" || moduleType == "HLT2PhotonPFTau") {
304  n.level = 3;
305  //int num = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
306  int num = getParameterSafe(HLTCP, filterName, "MinN");
307  n.tau = num;
308  n.electron = num;
309  }
310  else if(moduleType == "HLT2MuonTau" || moduleType == "HLT2MuonPFTau") {
311  n.level = 3;
312  //int num = HLTCP.modulePSet(filterName).getParameter<int>("MinN");
313  int num = getParameterSafe(HLTCP, filterName, "MinN");
314  n.tau = num;
315  n.muon = num;
316  }
317  else if(moduleType == "HLTPrescaler"){// || moduleType == "HLT1CaloMET") {
318  // ignore
319  }
320  else {
321  edm::LogInfo("HLTTauDQMOfflineSource") << "HLTTauDQMPath.cc, inferTauLeptonMultiplicity(): module type '" << moduleType << "' not recognized, filter '" << filterName << "' in path '" << pathName << "' will be ignored for offline matching." << std::endl;
322  }
323  return n;
324  }
325 
326  template <typename T1, typename T2>
327  bool deltaRmatch(const T1& obj, const std::vector<T2>& refColl, double dR, std::vector<bool>& refMask, 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 }
350 
351 
352 HLTTauDQMPath::HLTTauDQMPath(std::string pathName, std::string hltProcess, bool doRefAnalysis, const HLTConfigProvider& HLTCP):
353  hltProcess_(std::move(hltProcess)),
354  doRefAnalysis_(doRefAnalysis),
355  pathName_(std::move(pathName)),
356  pathIndex_(HLTCP.triggerIndex(pathName_)),
357  lastFilterBeforeL2TauIndex_(0), lastL2TauFilterIndex_(0),
358  lastFilterBeforeL3TauIndex_(0), lastL3TauFilterIndex_(0),
359  lastFilterBeforeL2ElectronIndex_(0), lastL2ElectronFilterIndex_(0),
360  lastFilterBeforeL2MuonIndex_(0), lastL2MuonFilterIndex_(0),
361  lastFilterBeforeL2METIndex_(0), lastL2METFilterIndex_(0),
362  firstFilterBeforeL2METIndex_(0), firstL2METFilterIndex_(0),
363 
364  isFirstL1Seed_(false),
365  isValid_(false)
366 {
367 #ifdef EDM_ML_DEBUG
368  std::stringstream ss;
369  ss << "HLTTauDQMPath: " << pathName_ << "\n";
370 #endif
371  // Get the filters
372  HLTPath thePath(pathName_);
373  filterIndices_ = thePath.interestingFilters(HLTCP, doRefAnalysis_);
374  if(filterIndices_.empty()) {
375  edm::LogInfo("HLTTauDQMOffline") << "HLTTauDQMPath: " << pathName_ << " no interesting filters found";
376  return;
377  }
378  isFirstL1Seed_ = HLTCP.moduleType(std::get<kName>(filterIndices_[0])) == "HLTL1TSeed";
379 #ifdef EDM_ML_DEBUG
380  ss << " Interesting filters (preceded by the module index in the path)";
381 #endif
382  // Set the filter multiplicity counts
383  filterTauN_.clear();
384  filterElectronN_.clear();
385  filterMuonN_.clear();
386  filterMET_.clear();
387  filterTauN_.reserve(filterIndices_.size());
388  filterElectronN_.reserve(filterIndices_.size());
389  filterMuonN_.reserve(filterIndices_.size());
390  filterMET_.reserve(filterIndices_.size());
391  filterLevel_.reserve(filterIndices_.size());
392  for(auto & filterIndice : filterIndices_) {
393  const std::string& filterName = std::get<kName>(filterIndice);
394  const std::string& moduleType = HLTCP.moduleType(filterName);
395 
396  TauLeptonMultiplicity n = inferTauLeptonMultiplicity(HLTCP, filterName, moduleType, pathName_);
397  filterTauN_.push_back(n.tau);
398  filterElectronN_.push_back(n.electron);
399  filterMuonN_.push_back(n.muon);
400  filterMET_.push_back(n.met);
401  filterLevel_.push_back(n.level);
402 
403 #ifdef EDM_ML_DEBUG
404  ss << "\n " << i << " " << std::get<kModuleIndex>(filterIndices_[i])
405  << " " << filterName
406  << " " << moduleType
407  << " ntau " << n.tau
408  << " nele " << n.electron
409  << " nmu " << n.muon;
410 #endif
411  }
412 #ifdef EDM_ML_DEBUG
413  LogDebug("HLTTauDQMOffline") << ss.str();
414 #endif
415 
416  // Find the position of tau producer, use filters with taus before
417  // it for L2 tau efficiency, and filters with taus after it for L3
418  // tau efficiency. Here we have to take into account that for
419  // reference-matched case filterIndices_ contains only those filters
420  // that have saveTags=True, while for searching the first L3 tau
421  // filter we have to consider all filters
422  const size_t firstL3TauFilterIndex = thePath.firstL3TauFilterIndex(HLTCP);
423  if(firstL3TauFilterIndex == kInvalidIndex) {
424  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 tau producer as input in path " << pathName_;
425  }
426  const size_t firstL3ElectronFilterIndex = thePath.firstL3ElectronFilterIndex(HLTCP);
427  if(firstL3ElectronFilterIndex == kInvalidIndex) {
428  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 electron producer as input in path " << pathName_;
429  }
430  const size_t firstL3MuonFilterIndex = thePath.firstL3MuonFilterIndex(HLTCP);
431  if(firstL3MuonFilterIndex == kInvalidIndex) {
432  edm::LogInfo("HLTTauDQMOffline") << "Did not find a filter with L3 muon producer as input in path " << pathName_;
433  }
434 
451 /*
452  size_t i = 0;
453  for(; i<filtersSize() && getFilterIndex(i) < firstL3TauFilterIndex; ++i) {
454  if(lastL2TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
455  lastFilterBeforeL2TauIndex_ = i;
456  if(getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
457  lastL2TauFilterIndex_ = i;
458  }
459  lastFilterBeforeL3TauIndex_ = i-1;
460  for(; i<filtersSize(); ++i) {
461  if(lastL3TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
462  lastFilterBeforeL3TauIndex_ = i;
463  if(getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
464  lastL3TauFilterIndex_ = i;
465  }
466 */
467  for(size_t i = 0; i<filtersSize(); ++i) {
468  // Tau
469  if(getFilterLevel(i) == 2 && getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
473 
474 // if(lastFilterBeforeL3TauIndex_ < 2 && lastL3TauFilterIndex_ == kInvalidIndex && getFilterNTaus(i) == 0)
475 // lastFilterBeforeL3TauIndex_ = i;
476  if(getFilterLevel(i) == 3 && getFilterNTaus(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
480 
481  // Electron
484  if(getFilterLevel(i) == 2 && getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
486 
487  if(getFilterLevel(i) == 3 && getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
491 /*
492  if(lastL2ElectronFilterIndex_ == kInvalidIndex && getFilterNElectrons(i) == 0)
493  lastFilterBeforeL2ElectronIndex_ = i;
494  if(getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
495  lastL2ElectronFilterIndex_ = i;
496 
497  if(lastFilterBeforeL3ElectronIndex_ == 0 && lastL3ElectronFilterIndex_ == kInvalidIndex && getFilterNElectrons(i) == 0)
498  lastFilterBeforeL3ElectronIndex_ = i;
499  if(getFilterNElectrons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNMuons(i) == 0)
500  lastL3ElectronFilterIndex_ = i;
501 */
502  // Muon
505  if(getFilterLevel(i) == 2 && getFilterNMuons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNElectrons(i) == 0)
507 
508  if(getFilterLevel(i) == 3 && getFilterNMuons(i) > 0 && getFilterNTaus(i) == 0 && getFilterNElectrons(i) == 0)
512 
513 
514  // MET
517  if(getFilterMET(i) > 0 && getFilterNElectrons(i) == 0 && getFilterNMuons(i) == 0)
519 
524  }
525 // lastFilterBeforeL3TauIndex_ = firstL3TauFilterIndex - 1;
526 // lastFilterBeforeL3ElectronIndex_ = firstL3ElectronFilterIndex - 1;
527 // lastFilterBeforeL3MuonIndex_ = firstL3MuonFilterIndex - 1;
528  LogDebug("HLTTauDQMOffline") << "lastFilterBeforeL2 " << lastFilterBeforeL2TauIndex_
529  << " lastL2TauFilter " << lastL2TauFilterIndex_
530  << " lastFilterBeforeL3 " << lastFilterBeforeL3TauIndex_
531  << " lastL3TauFilter " << lastL3TauFilterIndex_;
532  isValid_ = true;
533 }
534 
536 
537 
539  return triggerResults.accept(pathIndex_);
540 }
541 
543 
544  if(fired(triggerResults)) {
545  //std::cout << "Event passed" << std::endl;
546  return filterIndices_.size()-1;
547  }
548 
549  unsigned int firstFailedFilter = triggerResults.index(pathIndex_);
550  int lastPassedFilter = -1;
551  for(size_t i=0; i<filterIndices_.size(); ++i) {
552  if(std::get<kModuleIndex>(filterIndices_[i]) < firstFailedFilter) {
553  lastPassedFilter = i;
554  }
555  else {
556  //std::cout << "Decision-making filter " << firstFailedFilter << " this " << std::get<kModuleIndex>(filterIndices_[i]) << std::endl;
557  break;
558  }
559  }
560  return lastPassedFilter;
561 }
562 
563 void HLTTauDQMPath::getFilterObjects(const trigger::TriggerEvent& triggerEvent, size_t i, std::vector<Object>& retval) const {
564  trigger::size_type filterIndex = triggerEvent.filterIndex(edm::InputTag(getFilterName(i), "", hltProcess_));
565  if(filterIndex != triggerEvent.sizeFilters()) {
566  const trigger::Keys& keys = triggerEvent.filterKeys(filterIndex);
567  const trigger::Vids& ids = triggerEvent.filterIds(filterIndex);
569  for(size_t i=0; i<keys.size(); ++i) {
570  const trigger::TriggerObject& object = triggerObjects[keys[i]];
571  retval.emplace_back(Object{object, ids[i]});
572  }
573  }
574 }
575 
576 bool HLTTauDQMPath::offlineMatching(size_t i, const std::vector<Object>& triggerObjects, const HLTTauDQMOfflineObjects& offlineObjects, double dR, std::vector<Object>& matchedTriggerObjects, HLTTauDQMOfflineObjects& matchedOfflineObjects) const {
577  bool isL1 = (i==0 && isFirstL1Seed_);
578  std::vector<bool> offlineMask;
579  if(filterTauN_[i] > 0) {
580  int matchedObjects = 0;
581  offlineMask.resize(offlineObjects.taus.size());
582  std::fill(offlineMask.begin(), offlineMask.end(), true);
583  for(const Object& trgObj: triggerObjects) {
584  //std::cout << "trigger object id " << isL1 << " " << trgObj.id << " " << trigger::TriggerL1Tau << " "<< trigger::TriggerTau << std::endl;
585  if(! ((isL1 && trgObj.id == trigger::TriggerL1Tau) || 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  }
593  if(matchedObjects < filterTauN_[i])
594  return false;
595  }
596  if(filterElectronN_[i] > 0) {
597  int matchedObjects = 0;
598  offlineMask.resize(offlineObjects.electrons.size());
599  std::fill(offlineMask.begin(), offlineMask.end(), true);
600  for(const Object& trgObj: triggerObjects) {
601  //std::cout << "trigger object id " << trgObj.id << std::endl;
602  if(! ((isL1 && (trgObj.id == trigger::TriggerL1EG))
603  || trgObj.id == trigger::TriggerElectron || trgObj.id == trigger::TriggerPhoton) )
604  continue;
605  if(deltaRmatch(trgObj.object, offlineObjects.electrons, dR, offlineMask, matchedOfflineObjects.electrons)) {
606  ++matchedObjects;
607  matchedTriggerObjects.emplace_back(trgObj);
608  }
609  }
610  if(matchedObjects < filterElectronN_[i])
611  return false;
612  }
613  if(filterMuonN_[i] > 0) {
614  int matchedObjects = 0;
615  offlineMask.resize(offlineObjects.muons.size());
616  std::fill(offlineMask.begin(), offlineMask.end(), true);
617  for(const Object& trgObj: triggerObjects) {
618  //std::cout << "trigger object id " << trgObj.id << std::endl;
619  if(! ((isL1 && trgObj.id == trigger::TriggerL1Mu)
620  || trgObj.id == trigger::TriggerMuon) )
621  continue;
622  if(deltaRmatch(trgObj.object, offlineObjects.muons, dR, offlineMask, matchedOfflineObjects.muons)) {
623  ++matchedObjects;
624  matchedTriggerObjects.emplace_back(trgObj);
625  }
626  }
627  if(matchedObjects < filterMuonN_[i])
628  return false;
629  }
630  if(filterMET_[i] > 0) {
631  int matchedObjects = 0;
632  offlineMask.resize(offlineObjects.met.size());
633  std::fill(offlineMask.begin(), offlineMask.end(), true);
634  for(const Object& trgObj: triggerObjects) {
635  if(! ((isL1 && trgObj.id == trigger::TriggerL1ETM)
636  || trgObj.id == trigger::TriggerMET) )
637  continue;
638  ++matchedObjects;
639  matchedTriggerObjects.emplace_back(trgObj);
640  }
641  if(matchedObjects < filterMET_[i]){
642  return false;
643  }
644  }
645 
646  // Sort offline objects by pt
647  std::sort(matchedOfflineObjects.taus.begin(), matchedOfflineObjects.taus.end(), [](const LV& a, const LV&b) { return a.pt() > b.pt();});
648  std::sort(matchedOfflineObjects.electrons.begin(), matchedOfflineObjects.electrons.end(), [](const LV& a, const LV&b) { return a.pt() > b.pt();});
649  std::sort(matchedOfflineObjects.muons.begin(), matchedOfflineObjects.muons.end(), [](const LV& a, const LV&b) { return a.pt() > b.pt();});
650  matchedOfflineObjects.met = offlineObjects.met;
651  return true;
652 }
653 
654 bool HLTTauDQMPath::goodOfflineEvent(size_t i, const HLTTauDQMOfflineObjects& offlineObjects) const {
655  return (static_cast<size_t>(getFilterNTaus(i)) <= offlineObjects.taus.size() &&
656  static_cast<size_t>(getFilterNElectrons(i)) <= offlineObjects.electrons.size() &&
657  static_cast<size_t>(getFilterNMuons(i)) <= offlineObjects.muons.size());
658 }
#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
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
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_
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: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
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
#define input1
Definition: AMPTWrapper.h:129
size_t lastFilterBeforeL3TauIndex_
static std::string const triggerResults
Definition: EdmProvDump.cc:41
#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_
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
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:81
const bool doRefAnalysis_
met
===> hadronic RAZOR
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
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:58
double a
Definition: hdecay.h:121
std::vector< int > filterElectronN_
size_t lastL3MuonFilterIndex_
size_t lastL2ElectronFilterIndex_
size_t firstFilterBeforeL2METIndex_
std::vector< int > filterMuonN_
static constexpr size_t kModuleIndex
Definition: HLTTauDQMPath.h:30
std::vector< int > Vids
def move(src, dest)
Definition: eostools.py:510
std::vector< LV > muons
static constexpr size_t kInvalidIndex
Definition: HLTTauDQMPath.h:31
size_t lastL2METFilterIndex_
size_t lastFilterBeforeL2MuonIndex_
size_t firstL2METFilterIndex_