26 return StatusCode::SUCCESS;
39 if (chain.name() ==
"HLT_noalg_eb_L1All")
continue;
40 std::vector<std::string> streams = chain.streams();
41 if (std::find(streams.begin(), streams.end(),
"EnhancedBias") != streams.end()){
48 return StatusCode::SUCCESS;
54 if (!m_outputFilename.empty()){
55 std::ofstream outputStream;
56 outputStream.open(m_outputFilename);
57 outputStream <<
"<?xml version=\"1.0\" encoding=\"us-ascii\"?>" << std::endl;
58 outputStream <<
"<run>" << std::endl;
59 outputStream <<
"<weights>" << std::endl;
61 for (
size_t i = 0; i < m_ebWeights.size(); ++i){
62 outputStream <<
"<weight id=\"" << i <<
"\" value=\"" << m_ebWeights[i].first <<
"\" unbiased=\"" << m_ebWeights[i].second <<
"\"/>" << std::endl;
65 outputStream <<
"</weights>" << std::endl;
66 outputStream <<
"<events>" << std::endl;
68 for (
const auto& event : m_eventToWeight){
69 outputStream <<
"<e n=\"" <<
event.first <<
"\" w=\"" <<
event.second <<
"\"/>" << std::endl;
72 outputStream <<
"</events>" << std::endl;
73 outputStream <<
"</run>" << std::endl;
77 return StatusCode::SUCCESS;
85 ATH_MSG_DEBUG(
"Number of eb chains that passed int this event: " << EBChains.size());
88 if (EBChains.empty()) {
90 return StatusCode::SUCCESS;
101 if ( context.evt() == 0 ){
102 std::stringstream filename;
103 filename <<
"EnhancedBiasWeights_" << context.eventID().run_number() <<
".xml";
104 m_outputFilename = filename.str();
105 ATH_MSG_INFO(
"The output file name is " << m_outputFilename);
109 auto resultPair = std::pair<double, bool>(
result.weight,
result.isUnbiased);
110 auto newPair = std::find(m_ebWeights.begin(), m_ebWeights.end(), resultPair);
111 if (newPair == m_ebWeights.end()){
112 newPair = m_ebWeights.push_back(resultPair);
113 ATH_MSG_DEBUG(
"New weight value: " <<
result.weight <<
" with id " << (m_ebWeights.size()-1));
115 m_eventToWeight[context.eventID().event_number()] = std::distance(m_ebWeights.begin(), newPair);
119 return StatusCode::SUCCESS;
132 if ( not HLTPrescalesSet->prescale(chain.getId()).enabled ){
133 chain.setTotalPrescale(-1);
137 double HLTPrescale = HLTPrescalesSet->prescale(chain.getId()).prescale;
138 double L1Prescale = 1.0;
139 if (!chain.getIsNoPS()) {
141 L1Prescale *= L1PrescalesSet->prescale(item).prescale;
145 chain.setTotalPrescale(HLTPrescale * L1Prescale);
148 return StatusCode::SUCCESS;
157 if (chain.getIsDisabled()){
161 ATH_MSG_DEBUG(
"Chain " << chain.getName() <<
" total prescale " << chain.getTotalPrescale());
162 weight *= 1. - ( 1. / chain.getTotalPrescale() );
165 weight = (std::fabs(1.0 - weight) < 1e-10) ? 0. : (1. / (1. - weight));
170 return {double(weight), isUnbiased};
176 std::vector<EBChainInfo> passedEBChains;
181 bool ebChainIsSeeded =
false;
183 if ((chainName.find(
"_eb_") != std::string::npos) && (!
m_chainToHLTSeed.empty())){
186 ebChainIsSeeded =
true;
190 }
else if (chainName.find(
"L1RD3") != std::string::npos){
192 ebChainIsSeeded =
m_tdt->isPassed(chainName);
196 ebChainIsSeeded =
true;
201 if (ebChainIsSeeded) {
206 return passedEBChains;
212 return std::find_if (EBChains.begin(), EBChains.end(),
213 [](
const EBChainInfo& chain) ->
bool { return chain.getIsRandom(); }) != EBChains.end();
218 std::vector<std::string> items;
220 std::stringstream itemStream (itemStr);
223 while (std::getline(itemStream, item,
',')) {
224 items.push_back(item);
#define ATH_CHECK
Evaluate an expression and check for errors.
An algorithm that can be simultaneously executed in multiple threads.
Store necessary information for weight computing for Enhanced Bias chain.
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_finalDecisionKey
virtual StatusCode start() override
std::vector< HLT::Identifier > m_EBChainIds
Available EB chains' IDs from HLT Menu.
std::map< HLT::Identifier, std::vector< std::string > > m_EBChainIdToItem
L1 items for EB chains from HLT Menu.
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_chainToHLTSeed
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &context) const override
StatusCode fillTotalPrescaleForChains(const EventContext &context, std::vector< EBChainInfo > &EBChains) const
Retrieve total prescales (L1 * HLT) for chains into map.
EBResult calculateEBWeight(const std::vector< EBChainInfo > &EBChains) const
Calculate EB result based on total prescales of chains.
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
SG::ReadCondHandleKey< TrigConf::L1PrescalesSet > m_L1PrescaleSetInputKey
PublicToolHandle< Trig::TrigDecisionTool > m_tdt
std::vector< std::string > parseItems(const std::string &itemStr)
Parse list of l1 items.
virtual StatusCode stop() override
EnhancedBiasWeightCompAlg(const std::string &name, ISvcLocator *svcLoc)
std::vector< EBChainInfo > getPassedEBChains() const
Get list of Enhanced Bias chains that cound have passed.
bool checkIfTriggeredByRandomChain(const std::vector< EBChainInfo > &EBChain) const
Check if any of random chains passed.
SG::ReadCondHandleKey< TrigConf::HLTPrescalesSet > m_HLTPrescaleSetInputKey
std::string name() const
reports human redable name
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
static const unsigned int L1_isPassedBeforePrescale
Store result of EB weight calculation.