CMS 3D CMS Logo

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