CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Fireworks/Core/src/FWHLTTriggerTableView.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWHLTTriggerTableView
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  
00010 //         Created:  Tue Jan 25 16:02:03 CET 2011
00011 // $Id: FWHLTTriggerTableView.cc,v 1.3 2011/02/16 18:38:36 amraktad Exp $
00012 //
00013 #include <boost/regex.hpp>
00014 
00015 #include "Fireworks/Core/interface/FWHLTTriggerTableView.h"
00016 #include "Fireworks/Core/interface/fwLog.h"
00017 
00018 #include "DataFormats/FWLite/interface/Handle.h"
00019 #include "DataFormats/FWLite/interface/Event.h"
00020 #include "FWCore/Common/interface/TriggerNames.h"
00021 #include "DataFormats/Common/interface/TriggerResults.h"
00022 #include "FWCore/Utilities/interface/Exception.h"
00023 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
00024 #include "Fireworks/Core/interface/CmsShowViewPopup.h"
00025 
00026 
00027 FWHLTTriggerTableView::FWHLTTriggerTableView(TEveWindowSlot* iParent)
00028    : FWTriggerTableView(iParent, FWViewType::kTableHLT),
00029      m_event(0)
00030 {  
00031 
00032    m_columns[0].title = "Filter Name";
00033    m_columns.push_back(Column("Accept"));
00034    m_columns.push_back(Column("Average Accept"));
00035    dataChanged();
00036 }
00037 
00038 
00039 void FWHLTTriggerTableView::fillTable(fwlite::Event* event)
00040 {
00041    if ( event != m_event ) {
00042       m_event = event;
00043       fillAverageAcceptFractions();
00044    }
00045    fwlite::Handle<edm::TriggerResults> hTriggerResults;
00046    edm::TriggerNames const* triggerNames(0);
00047    try{
00048       hTriggerResults.getByLabel(*event,"TriggerResults","",m_process.value().c_str());
00049       triggerNames = &event->triggerNames(*hTriggerResults);
00050    } catch (cms::Exception&) {
00051       fwLog(fwlog::kWarning) << " no trigger results with process name HLT is available" << std::endl;
00052       m_tableManager->dataChanged();
00053       return;
00054    }
00055    boost::regex filter(m_regex.value());
00056    for(unsigned int i=0; i<triggerNames->size(); ++i) {
00057       if ( !boost::regex_search(triggerNames->triggerName(i),filter) ) continue;
00058       m_columns.at(0).values.push_back(triggerNames->triggerName(i));
00059       m_columns.at(1).values.push_back(Form("%d",hTriggerResults->accept(i)));
00060       m_columns.at(2).values.push_back(Form("%6.1f%%",m_averageAccept[triggerNames->triggerName(i)]*100));
00061    }
00062 }
00063 
00064 void
00065 FWHLTTriggerTableView::fillAverageAcceptFractions()
00066 {
00067    edm::EventID currentEvent = m_event->id();
00068    // better to keep the keys and just set to zero the values
00069    for (acceptmap_t::iterator it = m_averageAccept.begin(), ed = m_averageAccept.end(); it != ed; ++it) {
00070       it->second = 0;
00071    }
00072 
00073    // loop over events
00074    fwlite::Handle<edm::TriggerResults> hTriggerResults;
00075    for (m_event->toBegin(); !m_event->atEnd(); ++(*m_event)) {
00076       hTriggerResults.getByLabel(*m_event,"TriggerResults","","HLT");
00077       edm::TriggerNames const* triggerNames(0);
00078       try{
00079          triggerNames = &m_event->triggerNames(*hTriggerResults);
00080       } catch (cms::Exception&) {
00081          fwLog(fwlog::kError) <<" exception caught while trying to get trigger info"<<std::endl;
00082          break;
00083       }
00084 
00085       for(unsigned int i=0; i<triggerNames->size(); ++i) {
00086          if ( hTriggerResults->accept(i) ) { 
00087             m_averageAccept[triggerNames->triggerName(i)]++;
00088          }
00089       }
00090    }
00091    m_event->to(currentEvent);
00092 
00093    double denominator = 1.0/m_event->size();
00094    for (acceptmap_t::iterator it = m_averageAccept.begin(), ed = m_averageAccept.end(); it != ed; ++it) {
00095       it->second *= denominator;
00096    }
00097 }