CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HltComparator.cc
Go to the documentation of this file.
1 // Originally written by James Jackson
2 // modified by Peter Wittich
3 
4 // user include files
7 //#include "FWCore/Utilities/interface/Exception.h"
8 
9 //#include "FWCore/MessageLogger/interface/MessageLogger.h"
12 
13 #include <TH1.h>
14 #include <iostream>
15 #include <string>
16 #include <vector>
17 
18 typedef std::vector<std::string> StringCollection;
19 
20 // types of outcomes possible.
21 // only some are errors
22 enum {
33 };
34 
35 // Analyser constructor
37  : hltOnlineResults_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("OnlineResults"))),
38  hltOfflineResults_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("OfflineResults"))),
39  init_(false),
40  verbose_(iConfig.getUntrackedParameter<bool>("verbose")),
41  skipPathList_(iConfig.getUntrackedParameter<std::vector<std::string>>("skipPaths")),
42  usePathList_(iConfig.getUntrackedParameter<std::vector<std::string>>("usePaths")) {
43  // std::cout << " HERE I AM " << std::endl;
44  produces<StringCollection>("failedTriggerDescription");
45  // std::cout << " HERE I GO " << std::endl;
46 }
47 
49 
50 // Initialises online --> offline trigger bit mappings and histograms
52  const edm::TriggerResults &offlineResults,
53  edm::Event &e) {
54  init_ = true;
55 
56  // Get trigger names
57  const edm::TriggerNames &onlineTriggerNames = e.triggerNames(onlineResults);
58  const edm::TriggerNames &offlineTriggerNames = e.triggerNames(offlineResults);
59  onlineActualNames_ = onlineTriggerNames.triggerNames();
60  offlineActualNames_ = offlineTriggerNames.triggerNames();
62 
63  // do we need to throw? I guess the whole job is crap if this happens.
64  // sort of assumes we're the only game in town.
65  if (numTriggers_ != offlineActualNames_.size()) {
66  throw cms::Exception("IncorrectTriggers") << "Online had " << numTriggers_ << "triggers, "
67  << "Offline had " << offlineActualNames_.size() << "triggers";
68  }
69 
70  // Create bit mappings
71  std::map<std::string, unsigned int> offlineNameBitMap;
72  for (unsigned int i = 0; i < numTriggers_; ++i) {
73  offlineNameBitMap[offlineActualNames_[i]] = i;
74  }
75  for (unsigned int i = 0; i < numTriggers_; ++i) {
76  // Find offline position for fixed online bit
77  std::map<std::string, unsigned int>::iterator it = offlineNameBitMap.find(onlineActualNames_[i]);
78  if (it != offlineNameBitMap.end()) {
79  onlineToOfflineBitMappings_.push_back(it->second);
80  } else {
81  throw cms::Exception("IncorrectTriggers") << "Online trigger path " << onlineActualNames_[i]
82  << " not found in Offline "
83  "processing";
84  }
85  }
86 
87  // Create histograms
89  for (std::vector<std::string>::iterator it = onlineActualNames_.begin(); it != onlineActualNames_.end(); ++it) {
90  // Bin descriptions: OnOfPass, OnOffFail, OnPassOffFail, OnFailOffPass,
91  // OnOffError, OnRunOffError, OnErrorOffRun, OnRunOffNot OnNotOffRun
92  // OnNotOffNot
93  TH1F *h = fs->make<TH1F>(it->c_str(), it->c_str(), 10, 0, 10);
94  TAxis *a = h->GetXaxis();
95  a->SetBinLabel(1, "OnPass_OffPass");
96  a->SetBinLabel(2, "OnFail_OffFail");
97  a->SetBinLabel(3, "OnPass_OffFail");
98  a->SetBinLabel(4, "OnFail_OffPass");
99  a->SetBinLabel(5, "OnError_OffError");
100  a->SetBinLabel(6, "OnRun_OffError");
101  a->SetBinLabel(7, "OnError_OffRun");
102  a->SetBinLabel(8, "OnRun_OffNotRun");
103  a->SetBinLabel(9, "OnNotRun_OffRun");
104  a->SetBinLabel(10, "OnNotRun_OffNotRun");
105  comparisonHists_.push_back(h);
106  }
107 }
108 
109 // Format a comparison result
111  switch (i) {
112  case 0:
113  return std::string("OnPass_OffPass");
114  break;
115  case 1:
116  return std::string("OnFail_OffFail");
117  break;
118  case 2:
119  return std::string("OnPass_OffFail");
120  break;
121  case 3:
122  return std::string("OnFail_OffPass");
123  break;
124  case 4:
125  return std::string("OnError_OffError");
126  break;
127  case 5:
128  return std::string("OnRun_OffError");
129  break;
130  case 6:
131  return std::string("OnError_OffRun");
132  break;
133  case 7:
134  return std::string("OnRun_OffNotRun");
135  break;
136  case 8:
137  return std::string("OnNotRun_OffRun");
138  break;
139  case 9:
140  return std::string("OnNotRun_OffNotRun");
141  break;
142  }
143  return std::string("CODE NOT KNOWN");
144 }
145 
147  // std::cout << "top of the filter " << std::endl;
148  // Get trigger results
149  edm::Handle<edm::TriggerResults> onlineResults;
150  edm::Handle<edm::TriggerResults> offlineResults;
151  event.getByToken(hltOnlineResults_, onlineResults);
152  event.getByToken(hltOfflineResults_, offlineResults);
153 
154  std::unique_ptr<StringCollection> resultDescription(new StringCollection);
155 
156  // Initialise comparator if required
157  if (!init_) {
158  initialise(*onlineResults, *offlineResults, event);
159  }
160 
161  // Perform trigger checks
162  bool hasDisagreement = false;
163  for (unsigned int i = 0; i < numTriggers_; ++i) {
164  unsigned int offlineTriggerBit = onlineToOfflineBitMappings_[i];
165 
166  bool onRun = onlineResults->wasrun(i);
167  bool offRun = offlineResults->wasrun(offlineTriggerBit);
168  bool onAccept = onlineResults->accept(i);
169  bool offAccept = offlineResults->accept(offlineTriggerBit);
170  bool onError = onlineResults->error(i);
171  bool offError = offlineResults->error(offlineTriggerBit);
172 
173  int result = -1;
174  if (onError || offError) {
175  if (onError && offError) {
176  result = 4;
177  } else if (onError) {
178  result = 6;
179  } else {
180  result = 5;
181  }
182  } else if ((!onRun) || (!offRun)) {
183  if ((!onRun) && (!offRun)) {
184  result = 9;
185  } else if (!onRun) {
186  result = 8;
187  } else {
188  result = 7;
189  }
190  } else {
191  if (onAccept && offAccept) {
192  result = 0;
193  } else if ((!onAccept) && (!offAccept)) {
194  result = 1;
195  } else if (onAccept) {
196  result = 2;
197  } else {
198  result = 3;
199  }
200  }
201 
202  // Fill the results histogram
203  comparisonHists_[i]->Fill(result);
204 
205  // if the online-offline comparison results in a failure, we
206  // want to send the result to a special stream. Hence we _pass_ the filter.
207  // If it all worked as expected the filter fails and the event doesn't go
208  // to the output stream.
209  if ((result == kOnPassOffFail) || (result == kOnFailOffPass) || (result == kOnRunOffError) ||
210  (result == kOnErrorOffRun) || (result == kOnRunOffNot) || (result == kOnNotOffRun)) {
211  // is this one we should ignore? check the skip list
212  if (verbose()) {
213  std::cout << "Found disagreemenet " << result << ", name is " << onlineActualNames_[i] << std::endl;
214  }
215  std::ostringstream desc;
216  desc << onlineActualNames_[i] << ":" << formatResult(result);
217  resultDescription->push_back(desc.str());
218  if (std::find(skipPathList_.begin(), skipPathList_.end(), onlineActualNames_[i]) == skipPathList_.end()) {
219  if (!usePathList_.empty()) {
220  // only use specified paths to debug
221  if (std::find(usePathList_.begin(), usePathList_.end(), onlineActualNames_[i]) != usePathList_.end())
222  hasDisagreement = true;
223  } else
224  hasDisagreement = true;
225  }
226  }
227 
228  // Record the trigger error code
229  // I think this should be result > 2? (pw)
230  if (verbose() && (result > 1)) {
231  std::cout << "HLT-Compare: Event " << event.id().event() << " Path " << onlineActualNames_[i] << " "
232  << formatResult(result) << std::endl;
233 #ifdef NOTDEF
234  triggerComparisonErrors_[event.id().event()][onlineActualNames_[i]] = result;
235 #endif // NOTDEF
236  }
237  }
238 
239  // std::cout << " HERE I STAY " << std::endl;
240  event.put(std::move(resultDescription), "failedTriggerDescription");
241  // std::cout << " HERE I WENT " << std::endl;
242 
243  if (hasDisagreement)
244  return true;
245  else
246  return false;
247 }
248 
250 
251 // Print the trigger results
253 #ifdef NOTDEF
254  std::cout << "HLT-Compare ---------- Trigger Comparison Summary ----------" << std::endl;
255  std::cout << "HLT-Compare The following events had trigger mismatches:" << std::endl;
256  std::map<unsigned int, std::map<std::string, unsigned int>>::iterator it;
257  for (it = triggerComparisonErrors_.begin(); it != triggerComparisonErrors_.end(); ++it) {
258  std::cout << "HLT-Compare Event: " << it->first << std::endl;
259  std::map<std::string, unsigned int>::iterator jt;
260  for (jt = it->second.begin(); jt != it->second.end(); ++jt) {
261  std::cout << "HLT-Compare Path: " << jt->first << " : " << formatResult(jt->second) << std::endl;
262  }
263  }
264  std::cout << "HLT-Compare ------------ End Trigger Comparison ------------" << std::endl;
265 #endif // NOTDEF
266 }
unsigned int numTriggers_
Definition: HltComparator.h:38
std::vector< unsigned int > onlineToOfflineBitMappings_
Definition: HltComparator.h:26
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< edm::TriggerResults > hltOnlineResults_
Definition: HltComparator.h:21
bool filter(edm::Event &, const edm::EventSetup &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Strings const & triggerNames() const
Definition: TriggerNames.cc:48
HltComparator(const edm::ParameterSet &)
tuple result
Definition: mps_fire.py:311
bool verbose() const
Definition: HltComparator.h:33
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
std::vector< TH1F * > comparisonHists_
Definition: HltComparator.h:28
edm::EDGetTokenT< edm::TriggerResults > hltOfflineResults_
Definition: HltComparator.h:22
std::vector< std::string > onlineActualNames_
Definition: HltComparator.h:24
std::vector< std::string > usePathList_
Definition: HltComparator.h:36
void endJob() override
def move
Definition: eostools.py:511
std::vector< std::string > offlineActualNames_
Definition: HltComparator.h:25
void initialise(const edm::TriggerResults &, const edm::TriggerResults &, edm::Event &e)
void beginJob() override
~HltComparator() override
std::string formatResult(const unsigned int)
std::vector< std::string > skipPathList_
Definition: HltComparator.h:35
double a
Definition: hdecay.h:119
std::vector< std::string > StringCollection
tuple cout
Definition: gather_cfg.py:144
std::map< unsigned int, std::map< std::string, unsigned int > > triggerComparisonErrors_
Definition: HltComparator.h:29
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4