ATLAS Offline Software
Loading...
Searching...
No Matches
eEmEg1BDTMultAlgTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "./CommonSelector.h"
7#include "./eEmSelector.h"
9
10#include <fstream>
11
12namespace GlobalSim {
13
15 const std::string& name,
16 const IInterface* parent) :
17 base_class(type, name, parent) {
18 }
19
20
21 // Initialize function running before first event
23
25
26 if (m_n_multbits < 0) {
27 ATH_MSG_ERROR("number of bits to write to TIP is negative");
28 return StatusCode::FAILURE;
29 }
30
31 int max_tip_pos = s_nbits_TIP - m_n_multbits;
32
34 ATH_MSG_ERROR("TIP word out of bounds " << m_TIP_position);
35 return StatusCode::FAILURE;
36 }
37
38 // create the necessary selector objects
39 m_c_selector = std::make_unique<CommonSelector>(m_et_low_str,
45 );
46
47 try {
48 m_bdt_selector = std::make_unique<eEmEg1BDTSelector>(std::stoul(m_Eg1BDT_str),
50 );
51 } catch (const std::exception& e) {
52
53 ATH_MSG_ERROR("Error initialising eEmEg1BDTSelector " << e.what());
54 return StatusCode::FAILURE;
55 }
56
57
58
59 if (m_n_multbits == 0){
60 m_maxtob = 0;
61 } else {
62 ulong maxtob = 1;
63 for (ulong i = m_n_multbits; i != 0; --i) { maxtob *= 2;}
64 m_maxtob = maxtob - 1;
65 }
66
67 return StatusCode::SUCCESS;
68 }
69
70
71 StatusCode eEmEg1BDTMultAlgTool::updateTIP(std::bitset<s_nbits_TIP>& word,
72 const EventContext& ctx) const {
73 auto tobs =
75 ctx);
76
77 CHECK(tobs.isValid());
78
79 // check if any of the incoming tobs is selected.
80
81 ulong tob_count{0};
82 std::vector<bool> tob_pass(tobs->size(), false);
83 for (int tob_it = 0; const GlobalSim::IOBitwise::eEmEg1BDTTOB* t : *tobs){
84 if (m_c_selector->select(*t) and m_bdt_selector->select(*t)) {
85 tob_pass[tob_it] = true;
86 if (++tob_count == m_maxtob){
87 break;
88 }
89 }
90 tob_it++;
91 }
92
93 ATH_MSG_DEBUG("no of passing TOBS" << tob_count);
94
95 auto count_bits = std::bitset<s_nbits_TIP>(tob_count);
96
97 int p0{0};
98 int p1{m_TIP_position};
99
100 const int& mxb = m_n_multbits;
101
102 for (; p0 != mxb; ++p0, ++p1) {
103 if (count_bits.test(p0)) {word.set(p1);}
104 }
105
106 ATH_MSG_DEBUG("TIP word " << word);
107
108
109 if (m_enableDump) {
110 std::stringstream ss;
111 ss << "\nRun " << ctx <<' ' << "TIP:\n" << word << '\n';
112 std::size_t ind{0};
113 for (const GlobalSim::IOBitwise::eEmEg1BDTTOB* tob : *tobs) {
114 ss << tob->to_string() << ' ' << std::boolalpha << " pass " << tob_pass[ind++] << '\n';
115 }
116 ss << "tob count " << tob_count << '\n';
117
118 std::ofstream out(name() + ".log", std::ios_base::app);
119 out << ss.str();
120 out.close();
121 }
122
123
124 return StatusCode::SUCCESS;
125 }
126
127 std::string eEmEg1BDTMultAlgTool::toString() const {
128 std::stringstream ss;
129 ss <<name () << ": " <<m_menu_name << ' '
130 << "eEmEg1BDTMultAlgTool read, select, count and report number of related eEmEg1BDTTOBS\n"
131 << m_c_selector->to_string() << '\n'
132 << m_bdt_selector->to_string() << '\n'
133 << m_TIP_position << ' ' << m_n_multbits;
134
135 return ss.str();
136 }
137
138}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t ss
Gaudi::Property< std::string > m_phi_low_str
Gaudi::Property< std::string > m_eta_high_str
Gaudi::Property< std::string > m_et_low_str
std::unique_ptr< ICommonSelector > m_c_selector
Gaudi::Property< std::string > m_Eg1BDT_str
Gaudi::Property< std::string > m_Eg1BDT_op
Gaudi::Property< std::string > m_phi_high_str
Gaudi::Property< std::string > m_menu_name
virtual std::string toString() const override
virtual StatusCode updateTIP(std::bitset< s_nbits_TIP > &, const EventContext &) const override
Gaudi::Property< std::string > m_eta_low_str
SG::ReadHandleKey< IOBitwise::eEmEg1BDTTOBContainer > m_eEmEg1BDTTOBContainerKey
Gaudi::Property< std::string > m_et_high_str
eEmEg1BDTMultAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
std::unique_ptr< IeEmEg1BDTSelector > m_bdt_selector
virtual StatusCode initialize() override
Initialize function running before first event.
AlgTool that to test whether expected the TIP values generated by data supplied by eEmMultTestBench c...