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 std::unique_ptr<IDataCollector>& dc,
38 const EventContext& ctx) const {
39 ATH_MSG_DEBUG("run()");
40 if (dc){dc->collect(*this, "start");}
41
42
43 // read in LArStrip neighborhood TOBs from the event store
44 auto in =
46 ctx);
47 CHECK(in.isValid());
48
49 ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
50
52 CHECK(h_BDTScore.record(std::make_unique<std::vector<float> >()));
53
54 //Setup a container of TOBs with associated GlobalLArCell windows
55 auto eEmEg1BDTTOBs = std::make_unique<IOBitwise::eEmEg1BDTTOBContainer>();
56
57 for (const auto nbhdTOB : *in) {
58 auto c_phi = combine_phi(nbhdTOB);
59 if (c_phi.empty()) {continue;} // corner case: not all phi have len 17
60 auto input = digitizer::digitize10(c_phi);
61
62 assert(input.size() == n_features);
63 ap_int<BDT_ouput_width>* c_input = &input[0]; // vector->array
64
66
67 // the bdt variable is already set up
68 bdt.decision_function(c_input, scores);
69 if (msgLevel() <= MSG::DEBUG) {
70 std::stringstream ss;
71 ss << "BDT input: ";
72 for (const auto& i : input) {ss << i << ' ';}
73 ATH_MSG_DEBUG(ss.str());
74 }
75
76 if (msgLevel() <= MSG::DEBUG) {
77 std::stringstream ss;
78 ss << "C BDT output: ";
79 for (const auto& i : scores) {ss << i << ' ';}
80 ATH_MSG_DEBUG(ss.str());
81 }
82
83 //Extract the bits from the ap_fixed<10,5> object.
84 std::bitset<BDT_ouput_width> BDT_bits;
85 for (int i=0;i<scores[0].length();i++){
86 BDT_bits[i] = scores[0][i];
87 }
88 ATH_MSG_DEBUG("BDT bits " << BDT_bits);
89
90 //Shift to an unsigned range, stored in a Bitset<8> as the hardware will.
91 std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width> result;
92 //First, interpret the ap_fixed<10,5> as an integer.
93 int BDT_int = bitSetToInt(BDT_bits);
94 ATH_MSG_DEBUG("BDT int " << BDT_int);
95 //We are going to restrict the range, but keep the resolution.
96 if(BDT_int >= 128) {
97 //So, cut off at 2^8/2-1 as the maximum possible value.
98 result = std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width>{0xFF};
99 } else if (BDT_int < -128) {
100 //So, cut off at and -2^8/2 as the minimum possible value.
101 result = std::bitset<eEmEg1BDTTOB::s_eGamma1BDT_width>{0x00};
102 } else {
103 //Then we take the remaining bits, flipping the maximum remaining bit.
104 //Due to the above logic, this is only 1 if -ive.
106 for(uint i = 0; i <= eEmEg1BDTTOB::s_eGamma1BDT_width-2;i++){
107 result[i] = BDT_bits[i];
108 }
109 }
110
111 ATH_MSG_DEBUG("Result bits " << result);
112 ATH_MSG_DEBUG("Result int " << result.to_ulong());
113
114 //Outpout the ulong for debug, and store the result in the output TOB
115 h_BDTScore->push_back(result.to_ulong());
116 eEmEg1BDTTOBs->push_back(std::make_unique<IOBitwise::eEmEg1BDTTOB>(*nbhdTOB, result));
117 }
118
119 //Setup the write out of the resultant TOBs
121 CHECK(h_eEmEg1BDTTOBs.record(std::move(eEmEg1BDTTOBs)));
122
123 if (dc){dc->collect(*this, "end");}
124
125 return StatusCode::SUCCESS;
126 }
127
128 int Egamma1BDTAlgTool::bitSetToInt(std::bitset<BDT_ouput_width> bitSet) const {
129 if (!bitSet[BDT_ouput_width - 1]) return bitSet.to_ulong();
130 bitSet.flip();
131 return -(bitSet.to_ulong() + 1);
132 }
133
134 std::vector<double>
136 auto result = std::vector<double>();
137
138 const auto& phi_low = nbhdTOB->Neighbourhood().phi_low();
139 if (phi_low.size() != s_required_phi_len) {return result;}
140
141 const auto& phi_center = nbhdTOB->Neighbourhood().phi_center();
142 if (phi_center.size() != s_required_phi_len) {return result;}
143
144
145 const auto& phi_high = nbhdTOB->Neighbourhood().phi_high();
146 if (phi_high.size() != s_required_phi_len) {return result;}
147
148 result.resize(s_combination_len);
149
150 constexpr int c{8};
151
152 result.at(0) = phi_center.at(c).m_e;
153
154 result.at(1) = std::max(phi_low.at(c).m_e, phi_high.at(c).m_e);
155
156 int ri{2};
157 for (int diff = 1; diff != 9; ++diff) {
158 result.at(ri) =
159 std::max({phi_center.at(c-diff).m_e,
160 phi_center.at(c+diff).m_e});
161
162 result.at(ri+1) =
163 std::max({phi_low.at(c-diff).m_e,
164 phi_low.at(c+diff).m_e,
165 phi_high.at(c-diff).m_e,
166 phi_high.at(c+diff).m_e});
167
168 ri += 2;
169 }
170
171 return result;
172 }
173
174 std::string Egamma1BDTAlgTool::toString() const {
175
176 std::stringstream ss;
177 ss << "Egamma1BDTAlgTool. name: " << name() << '\n'
179 << '\n';
180 return ss.str();
181 }
182
183}
184
#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
virtual StatusCode run(const std::unique_ptr< IDataCollector > &, const EventContext &ctx) const override
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
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 BDT 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