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