Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:15

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWHLTTriggerTableView
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:
0010 //         Created:  Tue Jan 25 16:02:03 CET 2011
0011 //
0012 #include <boost/regex.hpp>
0013 
0014 #include "Fireworks/Core/interface/FWHLTTriggerTableView.h"
0015 #include "Fireworks/Core/interface/fwLog.h"
0016 
0017 #include "DataFormats/FWLite/interface/Handle.h"
0018 #include "DataFormats/FWLite/interface/Event.h"
0019 #include "FWCore/Common/interface/TriggerNames.h"
0020 #include "DataFormats/Common/interface/TriggerResults.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
0023 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
0024 
0025 FWHLTTriggerTableView::FWHLTTriggerTableView(TEveWindowSlot* iParent)
0026     : FWTriggerTableView(iParent, FWViewType::kTableHLT), m_event(nullptr) {
0027   m_columns[0].title = "Filter Name";
0028   m_columns.push_back(Column("Accept"));
0029   m_columns.push_back(Column("Average Accept"));
0030   dataChanged();
0031 }
0032 
0033 void FWHLTTriggerTableView::fillTable(fwlite::Event* event) {
0034   if (event != m_event) {
0035     m_event = event;
0036     fillAverageAcceptFractions();
0037   }
0038   fwlite::Handle<edm::TriggerResults> hTriggerResults;
0039   edm::TriggerNames const* triggerNames(nullptr);
0040   try {
0041     hTriggerResults.getByLabel(*event, "TriggerResults", "", m_process.value().c_str());
0042     triggerNames = &event->triggerNames(*hTriggerResults);
0043   } catch (cms::Exception&) {
0044     fwLog(fwlog::kWarning) << " no trigger results with process name HLT is available" << std::endl;
0045     m_tableManager->dataChanged();
0046     return;
0047   }
0048   boost::regex filter(m_regex.value());
0049   for (unsigned int i = 0; i < triggerNames->size(); ++i) {
0050     if (!boost::regex_search(triggerNames->triggerName(i), filter))
0051       continue;
0052     m_columns.at(0).values.push_back(triggerNames->triggerName(i));
0053     m_columns.at(1).values.push_back(Form("%d", hTriggerResults->accept(i)));
0054     m_columns.at(2).values.push_back(Form("%6.1f%%", m_averageAccept[triggerNames->triggerName(i)] * 100));
0055   }
0056 }
0057 
0058 void FWHLTTriggerTableView::fillAverageAcceptFractions() {
0059   edm::EventID currentEvent = m_event->id();
0060   // better to keep the keys and just set to zero the values
0061   for (acceptmap_t::iterator it = m_averageAccept.begin(), ed = m_averageAccept.end(); it != ed; ++it) {
0062     it->second = 0;
0063   }
0064 
0065   // loop over events
0066   fwlite::Handle<edm::TriggerResults> hTriggerResults;
0067   for (m_event->toBegin(); !m_event->atEnd(); ++(*m_event)) {
0068     hTriggerResults.getByLabel(*m_event, "TriggerResults", "", "HLT");
0069     edm::TriggerNames const* triggerNames(nullptr);
0070     try {
0071       triggerNames = &m_event->triggerNames(*hTriggerResults);
0072     } catch (cms::Exception&) {
0073       fwLog(fwlog::kError) << " exception caught while trying to get trigger info" << std::endl;
0074       break;
0075     }
0076 
0077     for (unsigned int i = 0; i < triggerNames->size(); ++i) {
0078       if (hTriggerResults->accept(i)) {
0079         m_averageAccept[triggerNames->triggerName(i)]++;
0080       }
0081     }
0082   }
0083   m_event->to(currentEvent);
0084 
0085   double denominator = 1.0 / m_event->size();
0086   for (acceptmap_t::iterator it = m_averageAccept.begin(), ed = m_averageAccept.end(); it != ed; ++it) {
0087     it->second *= denominator;
0088   }
0089 }