ATLAS Offline Software
Loading...
Searching...
No Matches
Egamma1BDTAlgTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "Egamma1BDTAlgTool.h"
6#include "../Utilities/dump.h"
11
12#include "../IO/eEmEg1BDTTOB.h"
13
14
15namespace GlobalSim {
16
18
20 const std::string& name,
21 const IInterface* parent) :
22 base_class(type, name, parent){
23 }
24
26
27 //Input keys
28 CHECK(m_nbhdTOBContainerReadKey.initialize());
29 CHECK(m_BDTScoreKey.initialize());
30 //Output keys
32
33 return StatusCode::SUCCESS;
34 }
35
36 StatusCode
37 Egamma1BDTAlgTool::run(const EventContext& ctx) const {
38 ATH_MSG_DEBUG("run()");
39
40
41 // read in LArStrip neighborhood TOBs from the event store
42 auto in =
44 ctx);
45 CHECK(in.isValid());
46
47 ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
48
50 CHECK(h_BDTScore.record(std::make_unique<std::vector<float> >()));
51
52 //Setup a container of TOBs with associated GlobalLArCell windows
53 auto eEmEg1BDTTOBs = std::make_unique<IOBitwise::eEmEg1BDTTOBContainer>();
54
55 for (const auto nbhdTOB : *in) {
56 auto c_phi = combine_phi(nbhdTOB);
57 if (c_phi.empty()) {continue;} // corner case: not all phi have len 17
58 auto input = digitizer::digitize10(c_phi);
59
60 assert(input.size() == n_features);
61 ap_int<BDT_ouput_width>* c_input = &input[0]; // vector->array
62
64
65 // the bdt variable is already set up
66 bdt.decision_function(c_input, scores);
67 if (msgLevel() <= MSG::DEBUG) {
68 std::stringstream ss;
69 ss << "BDT input: ";
70 for (const auto& i : input) {ss << i << ' ';}
71 ATH_MSG_DEBUG(ss.str());
72 }
73
74 if (msgLevel() <= MSG::DEBUG) {
75 std::stringstream ss;
76 ss << "C BDT output: ";
77 for (const auto& i : scores) {ss << i << ' ';}
78 ATH_MSG_DEBUG(ss.str());
79 }
80
81 //Extract the bits from the ap_fixed<10,5> object.
82 std::bitset<BDT_ouput_width> BDT_bits;
83 for (int i=0;i<scores[0].length();i++){
84 BDT_bits[i] = scores[0][i];
85 }
86 ATH_MSG_DEBUG("BDT bits " << BDT_bits);
87
88 //Shift to an unsigned range, stored in a Bitset<8> as the hardware will.
89 std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width> result;
90 //First, interpret the ap_fixed<10,5> as an integer.
91 int BDT_int = bitSetToInt(BDT_bits);
92 ATH_MSG_DEBUG("BDT int " << BDT_int);
93 //We are going to restrict the range, but keep the resolution.
94 if(BDT_int >= 128) {
95 //So, cut off at 2^8/2-1 as the maximum possible value.
96 result = std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width>{0xFF};
97 } else if (BDT_int < -128) {
98 //So, cut off at and -2^8/2 as the minimum possible value.
99 result = std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width>{0x00};
100 } else {
101 //Then we take the remaining bits, flipping the maximum remaining bit.
102 //Due to the above logic, this is only 1 if -ive.
104 for(uint i = 0; i <= eEmEg1BDTTOB::s_eGamma1BDT_width-2;i++){
105 result[i] = BDT_bits[i];
106 }
107 }
108
109 ATH_MSG_DEBUG("Result bits " << result);
110 ATH_MSG_DEBUG("Result int " << result.to_ulong());
111
112 //Outpout the ulong for debug, and store the result in the output TOB
113 h_BDTScore->push_back(result.to_ulong());
114 eEmEg1BDTTOBs->push_back(std::make_unique<IOBitwise::eEmEg1BDTTOB>(*nbhdTOB, result));
115 }
116
117 //Setup the write out of the resultant TOBs
119 CHECK(h_eEmEg1BDTTOBs.record(std::move(eEmEg1BDTTOBs)));
120
121 return StatusCode::SUCCESS;
122 }
123
124 int Egamma1BDTAlgTool::bitSetToInt(std::bitset<BDT_ouput_width> bitSet) const {
125 if (!bitSet[BDT_ouput_width - 1]) return bitSet.to_ulong();
126 bitSet.flip();
127 return -(bitSet.to_ulong() + 1);
128 }
129
130 std::vector<double>
132 auto result = std::vector<double>();
133
134 const auto& phi_low = nbhdTOB->Neighbourhood().phi_low();
135 if (phi_low.size() != s_required_phi_len) {return result;}
136
137 const auto& phi_center = nbhdTOB->Neighbourhood().phi_center();
138 if (phi_center.size() != s_required_phi_len) {return result;}
139
140
141 const auto& phi_high = nbhdTOB->Neighbourhood().phi_high();
142 if (phi_high.size() != s_required_phi_len) {return result;}
143
144 result.resize(s_combination_len);
145
146 constexpr int c{8};
147
148 result.at(0) = phi_center.at(c).m_e;
149
150 result.at(1) = std::max(phi_low.at(c).m_e, phi_high.at(c).m_e);
151
152 int ri{2};
153 for (int diff = 1; diff != 9; ++diff) {
154 result.at(ri) =
155 std::max({phi_center.at(c-diff).m_e,
156 phi_center.at(c+diff).m_e});
157
158 result.at(ri+1) =
159 std::max({phi_low.at(c-diff).m_e,
160 phi_low.at(c+diff).m_e,
161 phi_high.at(c-diff).m_e,
162 phi_high.at(c+diff).m_e});
163
164 ri += 2;
165 }
166
167 return result;
168 }
169
170 std::string Egamma1BDTAlgTool::toString() const {
171
172 std::stringstream ss;
173 ss << "Egamma1BDTAlgTool. name: " << name() << '\n'
175 << '\n';
176 return ss.str();
177 }
178
179}
180
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
unsigned int uint
static Double_t ss
Header file to be included by clients of the Monitored infrastructure.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
static constexpr int s_combination_len
Egamma1BDTAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
std::vector< double > combine_phi(const IOBitwise::eEmNbhoodTOB *) const
SG::WriteHandleKey< std::vector< float > > m_BDTScoreKey
StatusCode initialize() override
static constexpr std::size_t BDT_ouput_width
int bitSetToInt(std::bitset< BDT_ouput_width > bitSet) const
virtual StatusCode run(const EventContext &ctx) const override
SG::ReadHandleKey< eEmNbhoodTOBContainer > m_nbhdTOBContainerReadKey
static constexpr int s_required_phi_len
virtual std::string toString() const override
SG::WriteHandleKey< eEmEg1BDTTOBContainer > m_eEmEg1BDTTOBContainerKey
static const std::size_t s_eGamma1BDT_width
virtual const LArStripNeighborhood & Neighbourhood() const
const StripDataVector & phi_low() const
Returns a vector of strip cell e/eta/phi data for the low phi row of the neighborhood.
const StripDataVector & phi_center() const
Returns a vector of strip cell e/eta/phi data for the central phi row of the neighborhood.
const StripDataVector & phi_high() const
Returns a vector of strip cell e/eta/phi data for the central high row of the neighborhood.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AlgTool to read in LArStripNeighborhoods, and run the eRatio Algorithm.
static const BDT::BDT< n_trees, n_classes, input_arr_t, score_t, threshold_t > bdt
Definition parameters.h:25
static const int n_features
Definition parameters.h:15
ap_fixed< 10, 5 > score_t
Definition parameters.h:21
static const int n_classes
Definition parameters.h:16
static std::vector< ap_int< 10 > > digitize10(const std::vector< double > &v)
Definition Digitizer.h:28