ATLAS Offline Software
Egamma1BDTAlgTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "Egamma1BDTAlgTool.h"
6 #include "../dump.h"
7 #include "../dump.icc"
11 
12 namespace GlobalSim {
13 
15  const std::string& name,
16  const IInterface* parent) :
17  base_class(type, name, parent){
18  }
19 
21 
22  CHECK(m_nbhdContainerReadKey.initialize());
23 
24  return StatusCode::SUCCESS;
25  }
26 
28  Egamma1BDTAlgTool::run(const EventContext& ctx) const {
29  ATH_MSG_DEBUG("run()");
30 
31 
32  // read in LArStrip neighborhoods from the event store
33  // there is one neighborhood per EFex RoI
34  auto in =
36  ctx);
37  CHECK(in.isValid());
38 
39  ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
40 
41 
42  for (const auto& nbhd : *in) {
43  auto c_phi = combine_phi(nbhd);
44  if (c_phi.empty()) {continue;} // corner case: not all phi have len 17
45  auto input = digitize(c_phi);
46 
47  assert(input.size() == n_features);
48  ap_int<10>* c_input = &input[0]; // vector->array
49 
50  score_t scores[GlobalSim::BDT::fn_classes(n_classes)];
51 
52  // the bdt variable is already set up
53  bdt.decision_function(c_input, scores);
54  {
55  std::stringstream ss;
56  ss << "BDT input: ";
57  for (const auto& i : input) {ss << i << ' ';}
58  ATH_MSG_DEBUG(ss.str());
59  }
60 
61  {
62  std::stringstream ss;
63  ss << "C BDT output: ";
64  for (const auto& i : scores) {ss << i << ' ';}
65  ATH_MSG_DEBUG(ss.str());
66  }
67 
68  }
69 
70 
71  return StatusCode::SUCCESS;
72  }
73 
74 
75  std::vector<double>
77  auto result = std::vector<double>();
78 
79  const auto& phi_low = nbhd->phi_low();
80  if (phi_low.size() != s_required_phi_len) {return result;}
81 
82  const auto& phi_center = nbhd->phi_center();
83  if (phi_center.size() != s_required_phi_len) {return result;}
84 
85 
86  const auto& phi_high = nbhd->phi_high();
87  if (phi_high.size() != s_required_phi_len) {return result;}
88 
89  result.resize(s_combination_len);
90 
91  constexpr int c{8};
92 
93  result.at(0) = phi_center.at(c).m_e;
94 
95  result.at(1) = std::max(phi_low.at(c).m_e, phi_high.at(c).m_e);
96 
97  int ri{2};
98  for (int diff = 1; diff != 9; ++diff) {
99  result.at(ri) =
100  std::max({phi_center.at(c-diff).m_e,
101  phi_center.at(c+diff).m_e});
102 
103  result.at(ri+1) =
104  std::max({phi_low.at(c-diff).m_e,
105  phi_low.at(c+diff).m_e,
106  phi_high.at(c-diff).m_e,
107  phi_high.at(c+diff).m_e});
108 
109  ri += 2;
110  }
111 
112  return result;
113  }
114 
115 
116  std::vector<ap_int<10>>
117  Egamma1BDTAlgTool::digitize(const std::vector<double>& v) const {
118  auto sf = [](double v) {
119  if (v < 0) {return 0.;}
120  if (v < 8000) {return v / 31.25;}
121  if (v < 40000) {return 192. + v / 125;}
122  if (v < 168000) {return 432. + v / 500;}
123  if (v < 678000) {return 686. + v / 2000;}
124  return 1023.;
125  };
126 
127  auto result = std::vector<ap_int<10>>();
128  result.reserve(s_combination_len);
129 
130  std::transform(std::cbegin(v),
131  std::cend(v),
132  std::back_inserter(result),
133  sf);
134 
135  return result;
136  }
137 
138 
139  std::string Egamma1BDTAlgTool::toString() const {
140 
141  std::stringstream ss;
142  ss << "Egamma1BDTAlgTool. name: " << name() << '\n'
143  << m_nbhdContainerReadKey << '\n'
144  << '\n';
145  return ss.str();
146  }
147 }
148 
get_generator_info.result
result
Definition: get_generator_info.py:21
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
GlobalSim::Egamma1BDTAlgTool::run
virtual StatusCode run(const EventContext &ctx) const override
Definition: Egamma1BDTAlgTool.cxx:28
GlobalSim::LArStripNeighborhood::phi_center
const StripDataVector & phi_center() const
Definition: LArStripNeighborhood.h:40
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
GlobalSim::Egamma1BDTAlgTool::digitize
std::vector< ap_int< 10 > > digitize(const std::vector< double > &) const
Definition: Egamma1BDTAlgTool.cxx:117
GlobalSim::Egamma1BDTAlgTool::s_combination_len
static constexpr int s_combination_len
Definition: Egamma1BDTAlgTool.h:68
GlobalSim::Egamma1BDTAlgTool::combine_phi
std::vector< double > combine_phi(const LArStripNeighborhood *) const
Definition: Egamma1BDTAlgTool.cxx:76
GlobalSim
AlgTool to obtain a selection of eFex RoIs read in from the event store.
Definition: dump.h:8
GlobalSim::Egamma1BDTAlgTool::s_required_phi_len
static constexpr int s_required_phi_len
Definition: Egamma1BDTAlgTool.h:64
MonitoredCollection.h
Egamma1BDTAlgTool.h
GlobalSim::ap_int< 10 >
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GlobalSim::BDT::fn_classes
constexpr int fn_classes(int n_classes)
Definition: Trigger/TrigT1/Global/GlobalSimulation/src/GlobalAlgs/Egamma1BDT/BDT.h:44
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
GlobalSim::ap_fixed< 10, 5 >
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
GlobalSim::Egamma1BDTAlgTool::initialize
StatusCode initialize() override
Definition: Egamma1BDTAlgTool.cxx:20
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
GlobalSim::LArStripNeighborhood::phi_low
const StripDataVector & phi_low() const
Definition: LArStripNeighborhood.h:39
GlobalSim::Egamma1BDTAlgTool::toString
virtual std::string toString() const override
Definition: Egamma1BDTAlgTool.cxx:139
GlobalSim::Egamma1BDTAlgTool::Egamma1BDTAlgTool
Egamma1BDTAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: Egamma1BDTAlgTool.cxx:14
parameters.h
GlobalSim::LArStripNeighborhood::phi_high
const StripDataVector & phi_high() const
Definition: LArStripNeighborhood.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
GlobalSim::Egamma1BDTAlgTool::m_nbhdContainerReadKey
SG::ReadHandleKey< LArStripNeighborhoodContainer > m_nbhdContainerReadKey
Definition: Egamma1BDTAlgTool.h:52
python.PyAthena.v
v
Definition: PyAthena.py:154
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GlobalSim::LArStripNeighborhood
Definition: LArStripNeighborhood.h:28
python.compressB64.c
def c
Definition: compressB64.py:93