ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::Egamma1BDTAlgTool Class Reference

#include <Egamma1BDTAlgTool.h>

Inheritance diagram for GlobalSim::Egamma1BDTAlgTool:
Collaboration diagram for GlobalSim::Egamma1BDTAlgTool:

Public Member Functions

 Egamma1BDTAlgTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~Egamma1BDTAlgTool ()=default
StatusCode initialize () override
virtual StatusCode run (const std::unique_ptr< IDataCollector > &, const EventContext &ctx) const override
virtual std::string toString () const override

Static Public Attributes

static constexpr std::size_t BDT_ouput_width = 10

Private Types

using eEmEg1BDTTOBContainer = GlobalSim::IOBitwise::eEmEg1BDTTOBContainer
using eEmNbhoodTOBContainer = GlobalSim::IOBitwise::eEmNbhoodTOBContainer

Private Member Functions

int bitSetToInt (std::bitset< BDT_ouput_width > bitSet) const
std::vector< double > combine_phi (const IOBitwise::eEmNbhoodTOB *) const

Private Attributes

Gaudi::Property< bool > m_enableDump
SG::WriteHandleKey< std::vector< float > > m_BDTScoreKey
SG::ReadHandleKey< eEmNbhoodTOBContainerm_nbhdTOBContainerReadKey
SG::WriteHandleKey< eEmEg1BDTTOBContainerm_eEmEg1BDTTOBContainerKey

Static Private Attributes

static constexpr int s_required_phi_len = 17
static constexpr int s_combination_len = 18

Detailed Description

Definition at line 32 of file Egamma1BDTAlgTool.h.

Member Typedef Documentation

◆ eEmEg1BDTTOBContainer

◆ eEmNbhoodTOBContainer

Constructor & Destructor Documentation

◆ Egamma1BDTAlgTool()

GlobalSim::Egamma1BDTAlgTool::Egamma1BDTAlgTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Definition at line 19 of file Egamma1BDTAlgTool.cxx.

21 :
22 base_class(type, name, parent){
23 }

◆ ~Egamma1BDTAlgTool()

virtual GlobalSim::Egamma1BDTAlgTool::~Egamma1BDTAlgTool ( )
virtualdefault

Member Function Documentation

◆ bitSetToInt()

int GlobalSim::Egamma1BDTAlgTool::bitSetToInt ( std::bitset< BDT_ouput_width > bitSet) const
private

Definition at line 128 of file Egamma1BDTAlgTool.cxx.

128 {
129 if (!bitSet[BDT_ouput_width - 1]) return bitSet.to_ulong();
130 bitSet.flip();
131 return -(bitSet.to_ulong() + 1);
132 }
static constexpr std::size_t BDT_ouput_width

◆ combine_phi()

std::vector< double > GlobalSim::Egamma1BDTAlgTool::combine_phi ( const IOBitwise::eEmNbhoodTOB * nbhdTOB) const
private

Definition at line 135 of file Egamma1BDTAlgTool.cxx.

135 {
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
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 }
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
static constexpr int s_required_phi_len

◆ initialize()

StatusCode GlobalSim::Egamma1BDTAlgTool::initialize ( )
override

Definition at line 25 of file Egamma1BDTAlgTool.cxx.

25 {
26
27 //Input keys
28 CHECK(m_nbhdTOBContainerReadKey.initialize());
29 CHECK(m_BDTScoreKey.initialize());
30 //Output keys
32
33 return StatusCode::SUCCESS;
34 }
#define CHECK(...)
Evaluate an expression and check for errors.
SG::WriteHandleKey< std::vector< float > > m_BDTScoreKey
SG::ReadHandleKey< eEmNbhoodTOBContainer > m_nbhdTOBContainerReadKey
SG::WriteHandleKey< eEmEg1BDTTOBContainer > m_eEmEg1BDTTOBContainerKey

◆ run()

StatusCode GlobalSim::Egamma1BDTAlgTool::run ( const std::unique_ptr< IDataCollector > & dc,
const EventContext & ctx ) const
overridevirtual

Definition at line 37 of file Egamma1BDTAlgTool.cxx.

38 {
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 =
45 SG::ReadHandle<IOBitwise::eEmNbhoodTOBContainer>(m_nbhdTOBContainerReadKey,
46 ctx);
47 CHECK(in.isValid());
48
49 ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
50
51 SG::WriteHandle<std::vector<float> > h_BDTScore(m_BDTScoreKey, ctx);
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
120 SG::WriteHandle<GlobalSim::IOBitwise::eEmEg1BDTTOBContainer> h_eEmEg1BDTTOBs(m_eEmEg1BDTTOBContainerKey, ctx);
121 CHECK(h_eEmEg1BDTTOBs.record(std::move(eEmEg1BDTTOBs)));
122
123 if (dc){dc->collect(*this, "end");}
124
125 return StatusCode::SUCCESS;
126 }
#define ATH_MSG_DEBUG(x)
unsigned int uint
static Double_t ss
std::vector< double > combine_phi(const IOBitwise::eEmNbhoodTOB *) const
int bitSetToInt(std::bitset< BDT_ouput_width > bitSet) const
static const std::size_t s_eGamma1BDT_width
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

◆ toString()

std::string GlobalSim::Egamma1BDTAlgTool::toString ( ) const
overridevirtual

Definition at line 174 of file Egamma1BDTAlgTool.cxx.

174 {
175
176 std::stringstream ss;
177 ss << "Egamma1BDTAlgTool. name: " << name() << '\n'
179 << '\n';
180 return ss.str();
181 }

Member Data Documentation

◆ BDT_ouput_width

std::size_t GlobalSim::Egamma1BDTAlgTool::BDT_ouput_width = 10
staticconstexpr

Definition at line 51 of file Egamma1BDTAlgTool.h.

◆ m_BDTScoreKey

SG::WriteHandleKey<std::vector<float> > GlobalSim::Egamma1BDTAlgTool::m_BDTScoreKey
private
Initial value:
{
this,
"BDTScoreKey",
"eGamma1BDT"}

Definition at line 63 of file Egamma1BDTAlgTool.h.

63 {
64 this,
65 "BDTScoreKey",
66 "eGamma1BDT"};

◆ m_eEmEg1BDTTOBContainerKey

SG::WriteHandleKey<eEmEg1BDTTOBContainer> GlobalSim::Egamma1BDTAlgTool::m_eEmEg1BDTTOBContainerKey
private
Initial value:
{
this,
"eEmEg1BDTTOBContainerKey",
"eEmEg1BDTTOBContainer"}

Definition at line 77 of file Egamma1BDTAlgTool.h.

77 {
78 this,
79 "eEmEg1BDTTOBContainerKey",
80 "eEmEg1BDTTOBContainer"};

◆ m_enableDump

Gaudi::Property<bool> GlobalSim::Egamma1BDTAlgTool::m_enableDump
private
Initial value:
{this,
"enableDump",
{false},
"flag to enable dumps"}

Definition at line 57 of file Egamma1BDTAlgTool.h.

57 {this,
58 "enableDump",
59 {false},
60 "flag to enable dumps"};

◆ m_nbhdTOBContainerReadKey

SG::ReadHandleKey<eEmNbhoodTOBContainer> GlobalSim::Egamma1BDTAlgTool::m_nbhdTOBContainerReadKey
private
Initial value:
{
this,
"LArNeighborhoodTOBContainerReadKey",
"stripNeighborhoodTOBContainer",
"key to read inLArNeighborhoodTOBsReadKeys"}

Definition at line 70 of file Egamma1BDTAlgTool.h.

70 {
71 this,
72 "LArNeighborhoodTOBContainerReadKey",
73 "stripNeighborhoodTOBContainer",
74 "key to read inLArNeighborhoodTOBsReadKeys"};

◆ s_combination_len

int GlobalSim::Egamma1BDTAlgTool::s_combination_len = 18
inlinestaticconstexprprivate

Definition at line 92 of file Egamma1BDTAlgTool.h.

◆ s_required_phi_len

int GlobalSim::Egamma1BDTAlgTool::s_required_phi_len = 17
inlinestaticconstexprprivate

Definition at line 88 of file Egamma1BDTAlgTool.h.


The documentation for this class was generated from the following files: