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 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 31 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 124 of file Egamma1BDTAlgTool.cxx.

124 {
125 if (!bitSet[BDT_ouput_width - 1]) return bitSet.to_ulong();
126 bitSet.flip();
127 return -(bitSet.to_ulong() + 1);
128 }
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 131 of file Egamma1BDTAlgTool.cxx.

131 {
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
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 }
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 EventContext & ctx) const
overridevirtual

Definition at line 37 of file Egamma1BDTAlgTool.cxx.

37 {
38 ATH_MSG_DEBUG("run()");
39
40
41 // read in LArStrip neighborhood TOBs from the event store
42 auto in =
43 SG::ReadHandle<IOBitwise::eEmNbhoodTOBContainer>(m_nbhdTOBContainerReadKey,
44 ctx);
45 CHECK(in.isValid());
46
47 ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
48
49 SG::WriteHandle<std::vector<float> > h_BDTScore(m_BDTScoreKey, ctx);
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
118 SG::WriteHandle<GlobalSim::IOBitwise::eEmEg1BDTTOBContainer> h_eEmEg1BDTTOBs(m_eEmEg1BDTTOBContainerKey, ctx);
119 CHECK(h_eEmEg1BDTTOBs.record(std::move(eEmEg1BDTTOBs)));
120
121 return StatusCode::SUCCESS;
122 }
#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 170 of file Egamma1BDTAlgTool.cxx.

170 {
171
172 std::stringstream ss;
173 ss << "Egamma1BDTAlgTool. name: " << name() << '\n'
175 << '\n';
176 return ss.str();
177 }

Member Data Documentation

◆ BDT_ouput_width

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

Definition at line 49 of file Egamma1BDTAlgTool.h.

◆ m_BDTScoreKey

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

Definition at line 61 of file Egamma1BDTAlgTool.h.

61 {
62 this,
63 "BDTScoreKey",
64 "eGamma1BDT"};

◆ m_eEmEg1BDTTOBContainerKey

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

Definition at line 75 of file Egamma1BDTAlgTool.h.

75 {
76 this,
77 "eEmEg1BDTTOBContainerKey",
78 "eEmEg1BDTTOBContainer"};

◆ m_enableDump

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

Definition at line 55 of file Egamma1BDTAlgTool.h.

55 {this,
56 "enableDump",
57 {false},
58 "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 68 of file Egamma1BDTAlgTool.h.

68 {
69 this,
70 "LArNeighborhoodTOBContainerReadKey",
71 "stripNeighborhoodTOBContainer",
72 "key to read inLArNeighborhoodTOBsReadKeys"};

◆ s_combination_len

int GlobalSim::Egamma1BDTAlgTool::s_combination_len = 18
inlinestaticconstexprprivate

Definition at line 90 of file Egamma1BDTAlgTool.h.

◆ s_required_phi_len

int GlobalSim::Egamma1BDTAlgTool::s_required_phi_len = 17
inlinestaticconstexprprivate

Definition at line 86 of file Egamma1BDTAlgTool.h.


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