This class takes a vector of HLT paths and returns a weight based on their HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale of the selected paths. More...
#include <CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h>
Public Member Functions | |
void | initRun (const edm::Run &run, const edm::EventSetup &setup) |
int | prescaleWeight (const edm::Event &event, const edm::EventSetup &setup) |
PrescaleWeightProvider (const edm::ParameterSet &config) | |
~PrescaleWeightProvider () | |
Private Member Functions | |
void | parseL1Seeds (const std::string &l1Seeds) |
Private Attributes | |
bool | configured_ |
HLTConfigProvider | hltConfig_ |
std::vector< std::string > | hltPaths_ |
bool | init_ |
edm::InputTag | l1GtTriggerMenuLite_ |
std::vector< std::string > | l1SeedPaths_ |
edm::Handle< L1GtTriggerMenuLite > | triggerMenuLite_ |
edm::InputTag | triggerResults_ |
unsigned | verbosity_ |
This class takes a vector of HLT paths and returns a weight based on their HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale of the selected paths.
Definition at line 37 of file PrescaleWeightProvider.h.
PrescaleWeightProvider::PrescaleWeightProvider | ( | const edm::ParameterSet & | config | ) |
Definition at line 17 of file PrescaleWeightProvider.cc.
References configured_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), hltPaths_, l1GtTriggerMenuLite_, edm::InputTag::label(), edm::InputTag::process(), triggerResults_, and verbosity_.
: verbosity_( 0 ) , triggerResults_( "TriggerResults::HLT" ) , l1GtTriggerMenuLite_( "l1GtTriggerMenuLite" ) { hltPaths_.clear(); if ( config.exists( "prescaleWeightVerbosityLevel" ) ) verbosity_ = config.getParameter< unsigned >( "prescaleWeightVerbosityLevel" ); if ( config.exists( "prescaleWeightTriggerResults" ) ) triggerResults_ = config.getParameter< edm::InputTag >( "prescaleWeightTriggerResults" ); if ( config.exists( "prescaleWeightL1GtTriggerMenuLite" ) ) l1GtTriggerMenuLite_ = config.getParameter< edm::InputTag >( "prescaleWeightL1GtTriggerMenuLite" ); if ( config.exists( "prescaleWeightHltPaths" ) ) hltPaths_ = config.getParameter< std::vector< std::string > >( "prescaleWeightHltPaths" ); configured_ = true; if ( triggerResults_.process().empty() ) { configured_ = false; if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Process name not configured via TriggerResults InputTag"; } else if ( triggerResults_.label().empty() ) { configured_ = false; if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "TriggerResults label not configured"; } else if ( l1GtTriggerMenuLite_.label().empty() ) { configured_ = false; if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite label not configured"; } else if ( hltPaths_.empty() ) { configured_ = false; if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT paths of interest not configured"; } }
PrescaleWeightProvider::~PrescaleWeightProvider | ( | ) | [inline] |
Definition at line 55 of file PrescaleWeightProvider.h.
{}
void PrescaleWeightProvider::initRun | ( | const edm::Run & | run, |
const edm::EventSetup & | setup | ||
) |
Definition at line 47 of file PrescaleWeightProvider.cc.
References configured_, edm::Run::getByLabel(), hltConfig_, HLTConfigProvider::init(), init_, edm::HandleBase::isValid(), l1GtTriggerMenuLite_, edm::InputTag::label(), edm::InputTag::process(), HLTConfigProvider::size(), triggerMenuLite_, triggerResults_, and verbosity_.
{ init_ = true; if ( ! configured_ ) { init_ = false; if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider" ) << "Run initialisation failed due to failing configuration"; return; } bool hltChanged( false ); if ( ! hltConfig_.init( run, setup, triggerResults_.process(), hltChanged ) ) { if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config initialization error with process name \"" << triggerResults_.process() << "\""; init_ = false; } else if ( hltConfig_.size() <= 0 ) { if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "HLT config size error"; init_ = false; } else if ( hltChanged ) { if ( verbosity_ > 0 ) edm::LogInfo( "PrescaleWeightProvider" ) << "HLT configuration changed"; } if ( ! init_ ) return; run.getByLabel( l1GtTriggerMenuLite_.label(), triggerMenuLite_ ); if ( ! triggerMenuLite_.isValid() ) { if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider" ) << "L1GtTriggerMenuLite with label \"" << l1GtTriggerMenuLite_.label() << "\" not found"; init_ = false; } }
void PrescaleWeightProvider::parseL1Seeds | ( | const std::string & | l1Seeds | ) | [private] |
Definition at line 164 of file PrescaleWeightProvider.cc.
References l1SeedPaths_, and verbosity_.
Referenced by prescaleWeight().
{ l1SeedPaths_.clear(); std::stringstream ss( l1Seeds ); std::string buf; while ( ss.good() && ! ss.eof() ){ ss >> buf; if ( buf[0] == '(' || buf[ buf.size() - 1 ] == ')' || buf == "AND" || buf == "NOT" ){ l1SeedPaths_.clear(); if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::parseL1Seeds" ) << "Only supported logical expression is OR"; return; } else if (buf == "OR") continue; else l1SeedPaths_.push_back( buf ); } }
int PrescaleWeightProvider::prescaleWeight | ( | const edm::Event & | event, |
const edm::EventSetup & | setup | ||
) |
Definition at line 79 of file PrescaleWeightProvider.cc.
References L1GtUtils::decision(), edm::InputTag::encode(), hltConfig_, HLTConfigProvider::hltL1GTSeeds(), hltPaths_, init_, edm::HandleBase::isValid(), l1SeedPaths_, parseL1Seeds(), L1GtUtils::prescaleFactor(), HLTConfigProvider::prescaleValue(), L1GtUtils::retrieveL1EventSetup(), HLTConfigProvider::size(), HLTConfigProvider::triggerIndex(), triggerMenuLite_, patRefSel_triggerSelection_cff::triggerResults, triggerResults_, interactiveExample::ui, verbosity_, and CommonMethods::weight().
{ if ( ! init_ ) return 1; // L1 L1GtUtils l1GtUtils; l1GtUtils.retrieveL1EventSetup( setup ); // HLT edm::Handle< edm::TriggerResults > triggerResults; event.getByLabel( triggerResults_, triggerResults); if( ! triggerResults.isValid() ) { if ( verbosity_ > 0 ) edm::LogError("PrescaleWeightProvider::prescaleWeight") << "TriggerResults product not found for InputTag \"" << triggerResults_.encode() << "\""; return 1; } const int SENTINEL( -1 ); int weight( SENTINEL ); for ( unsigned ui = 0; ui < hltPaths_.size(); ui++ ) { const std::string hltPath( hltPaths_.at( ui ) ); unsigned hltIndex( hltConfig_.triggerIndex( hltPath ) ); if ( hltIndex == hltConfig_.size() ) { if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" does not exist"; continue; } if ( ! triggerResults->accept( hltIndex ) ) continue; const std::vector< std::pair < bool, std::string > > level1Seeds = hltConfig_.hltL1GTSeeds( hltPath ); if ( level1Seeds.size() != 1 ) { if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "HLT path \"" << hltPath << "\" provides too many L1 seeds"; return 1; } parseL1Seeds( level1Seeds.at( 0 ).second ); if ( l1SeedPaths_.empty() ){ if ( verbosity_ > 0 ) edm::LogWarning("PrescaleWeightProvider::prescaleWeight") << "Failed to parse L1 seeds for HLT path \"" << hltPath << "\""; continue; } int l1Prescale( SENTINEL ); for ( unsigned uj = 0; uj < l1SeedPaths_.size(); uj++ ) { int l1TempPrescale( SENTINEL ); int errorCode( 0 ); if ( level1Seeds.at( 0 ).first ) { // technical triggers unsigned techBit( atoi( l1SeedPaths_.at( uj ).c_str() ) ); const std::string techName( *( triggerMenuLite_->gtTechTrigName( techBit, errorCode ) ) ); if ( errorCode != 0 ) continue; if ( ! l1GtUtils.decision( event, techName, errorCode ) ) continue; if ( errorCode != 0 ) continue; l1TempPrescale = l1GtUtils.prescaleFactor( event, techName, errorCode ); if ( errorCode != 0 ) continue; } else { // algorithmic triggers if ( ! l1GtUtils.decision( event, l1SeedPaths_.at( uj ), errorCode ) ) continue; if ( errorCode != 0 ) continue; l1TempPrescale = l1GtUtils.prescaleFactor( event, l1SeedPaths_.at( uj ), errorCode ); if ( errorCode != 0 ) continue; } if ( l1TempPrescale > 0 ){ if ( l1Prescale == SENTINEL || l1Prescale > l1TempPrescale ) l1Prescale = l1TempPrescale; } } if ( l1Prescale == SENTINEL ){ if ( verbosity_ > 0 ) edm::LogError( "PrescaleWeightProvider::prescaleWeight" ) << "Unable to find the L1 prescale for HLT path \"" << hltPath << "\""; continue; } int hltPrescale( hltConfig_.prescaleValue( event, setup, hltPath ) ); if ( hltPrescale * l1Prescale > 0 ) { if ( weight == SENTINEL || weight > hltPrescale * l1Prescale ) { weight = hltPrescale * l1Prescale; } } } if ( weight == SENTINEL ){ if ( verbosity_ > 0 ) edm::LogWarning( "PrescaleWeightProvider::prescaleWeight" ) << "No valid weight for any requested HLT path, returning default weight of 1"; return 1; } return weight; }
bool PrescaleWeightProvider::configured_ [private] |
Definition at line 39 of file PrescaleWeightProvider.h.
Referenced by initRun(), and PrescaleWeightProvider().
Definition at line 41 of file PrescaleWeightProvider.h.
Referenced by initRun(), and prescaleWeight().
std::vector< std::string > PrescaleWeightProvider::hltPaths_ [private] |
Definition at line 50 of file PrescaleWeightProvider.h.
Referenced by prescaleWeight(), and PrescaleWeightProvider().
bool PrescaleWeightProvider::init_ [private] |
Definition at line 40 of file PrescaleWeightProvider.h.
Referenced by initRun(), and prescaleWeight().
Definition at line 49 of file PrescaleWeightProvider.h.
Referenced by initRun(), and PrescaleWeightProvider().
std::vector< std::string > PrescaleWeightProvider::l1SeedPaths_ [private] |
Definition at line 44 of file PrescaleWeightProvider.h.
Referenced by parseL1Seeds(), and prescaleWeight().
Definition at line 42 of file PrescaleWeightProvider.h.
Referenced by initRun(), and prescaleWeight().
Definition at line 48 of file PrescaleWeightProvider.h.
Referenced by initRun(), prescaleWeight(), and PrescaleWeightProvider().
unsigned PrescaleWeightProvider::verbosity_ [private] |
Definition at line 47 of file PrescaleWeightProvider.h.
Referenced by initRun(), parseL1Seeds(), prescaleWeight(), and PrescaleWeightProvider().