ATLAS Offline Software
Loading...
Searching...
No Matches
eRatioAlgTool_UCL.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 "eRatioAlgTool_UCL.h"
6#include "../Utilities/dump.h"
10
12#include <sstream>
13
14namespace GlobalSim {
15
17 const std::string& name,
18 const IInterface* parent) :
19 base_class(type, name, parent){
20 }
21
23
24 CHECK(m_nbhdTOBContainerReadKey.initialize());
25 CHECK(m_eRatioKey.initialize());
26 CHECK(m_eRatioSimpleKey.initialize());
27
28 return StatusCode::SUCCESS;
29 }
30
31 StatusCode
32 eRatioAlgTool_UCL::run(const std::unique_ptr<IDataCollector>& dc,
33 const EventContext& ctx) const {
34 ATH_MSG_DEBUG("run()");
35
36 if (dc){dc->collect(*this, "start");}
37
38 // read in LArStrip neighborhoods from the event store
39 auto in =
41 ctx);
42 CHECK(in.isValid());
43
44 ATH_MSG_DEBUG("read in " << (*in).size() << " neighborhoods");
45
46 ap_int<16> peak = 0;
47 ap_int<16> secondMax = 0;
48
50 CHECK(h_eRatio.record(std::make_unique<std::vector<float> >()));
52 CHECK(h_eRatioSimple.record(std::make_unique<std::vector<float> >()));
53
54 for (const auto nbhdTOB : *in) {
55 auto c_phi = combine_phi(nbhdTOB);
56 if (msgLevel() <= MSG::DEBUG) {
57 std::stringstream ss;
58 ss << "eRatio input: ";
59 for (const auto& i : c_phi) {ss << i << ' ';}
60 ATH_MSG_DEBUG(ss.str());
61 }
62 //if (c_phi.empty()) {continue;} // corner case: not all phi have len 17
63 auto input = digitizer::digitize16(c_phi);
64 //Do want to ap_int them?
65 //ap_int<10>* c_input = &input[0]; // vector->array
66
67 if (msgLevel() <= MSG::DEBUG) {
68 std::stringstream ss;
69 ss << "eRatio input: ";
70 for (const auto& i : input) {ss << i << ' ';}
71 ATH_MSG_DEBUG(ss.str());
72 }
73
74 //Neighbourhood size sanity check
75 if(input.size() == 51){
76 //Central peak is easy, it's column 9 in the middle row, i.e. entry 25.
77 peak = input.at(25);
78 ATH_MSG_DEBUG("Peak " << peak);
79
80 //Find the 6 secondary peaks, lets do it like the VHDL
81 //holder of the current second peak (we will have 6)
82 std::vector<ap_int<16>> secondPeak;
83 secondPeak.resize(6);
84
85 //Noise Margin: This should be 2sigma... set to 1 for now...
86 int noiseMargin = 1;
87 //Route one: <<< middle row, 24 down to 17
88 secondPeak[0] = secondPeakSearch(input, peak, 24, 17, noiseMargin);
89 //Route two: middle row >>>, 26 up to 33
90 secondPeak[1] = secondPeakSearch(input, peak, 26, 33, noiseMargin);
91 //Route three: <<< top row, 8 down to 0
92 secondPeak[2] = secondPeakSearch(input, peak, 8, 0, noiseMargin);
93 //Route four: top row >>>, 8 up to 16
94 secondPeak[3] = secondPeakSearch(input, peak, 8, 16, noiseMargin);
95 //Route five: <<< bottom row, 42 down to 34
96 secondPeak[4] = secondPeakSearch(input, peak, 42, 34, noiseMargin);
97 //Route five: bottom row >>>, 42 up to 50
98 secondPeak[5] = secondPeakSearch(input, peak, 42, 50, noiseMargin);
99
100 auto result = std::max_element(secondPeak.begin(), secondPeak.end());
101 ATH_MSG_DEBUG("Max element found at index "
102 << std::distance(secondPeak.begin(), result)
103 << " has value " << *result);
104
105 secondMax = *result;
106 ATH_MSG_DEBUG("Peak " << peak << " second " << secondMax);
107
108 //I am not confident on waht div_gen_0 does. So I am casting to floats for now.
109 if(peak > 0 || secondMax > 0){
110 auto eRatio = static_cast< float >(peak - secondMax)/static_cast< float >(peak + secondMax);
111 h_eRatio->push_back(eRatio);
112 ATH_MSG_DEBUG("eRatio (p-sp/p+sp) is " << eRatio);
113
114 auto eRatioSimple = static_cast< float >(secondMax)/static_cast< float >(peak);
115 h_eRatioSimple->push_back(eRatioSimple);
116 ATH_MSG_DEBUG("eRatio (sp/p) is " << eRatioSimple);
117 }
118 }
119 }
120
121 if (dc){dc->collect(*this, "end");}
122
123 return StatusCode::SUCCESS;
124 }
125
126 ap_int<16> eRatioAlgTool_UCL::secondPeakSearch(const std::vector<ap_int<16>>& input,
127 const ap_int<16> peak,
128 const int startCell,
129 const int endCell,
130 const ap_int<16> noiseMargin) const {
131 //First set a series of counters to "descending" = 0
132 int ascending = 0;
133
134 //Setup holder of the last energy we checked... which starts at the peak...
135 ap_int<16> lastEnergy = peak;
136 ap_int<16> secondPeak = 0;
137
138 //There must be a better way to do this?
139 int direction = 0;
140 if(startCell > endCell) {
141 direction =-1;
142 } else {
143 direction =1;
144 }
145
146 //Route 1: go down in the middlle row
147 for (auto itr = input.begin() + startCell; itr != input.begin() + endCell + direction; itr+=direction){
148 //Going down hill... until we are not...
149 ATH_MSG_DEBUG("Input is " << *itr << " last energy is " << lastEnergy);
150 if(ascending==0 && *itr>lastEnergy && *itr-lastEnergy > noiseMargin){
151 ATH_MSG_DEBUG("We are going up now " << *itr << " is more then " << lastEnergy);
152 ascending=1;
153 lastEnergy=*itr;
154 //Now check if we are at the peak as we are going uphill
155 } else if(ascending==1 && lastEnergy>*itr && lastEnergy-*itr > noiseMargin){
156 ATH_MSG_DEBUG("We are past the top " << *itr << " is less than " << lastEnergy);
157 secondPeak = lastEnergy;
158 ATH_MSG_DEBUG("The peak was " << secondPeak);
159 //I think we can break here... don't need to find a third peak
160 break;
161 } else {
162 lastEnergy=*itr;
163 }
164 }
165
166 return secondPeak;
167 }
168
169 std::vector<double>
171 auto result = std::vector<double>();
172
173 const auto& phi_low = nbhdTOB->Neighbourhood().phi_low();
174 //if (phi_low.size() != s_required_phi_len) {return result;}
175
176 const auto& phi_center = nbhdTOB->Neighbourhood().phi_center();
177 //if (phi_center.size() != s_required_phi_len) {return result;}
178
179 const auto& phi_high = nbhdTOB->Neighbourhood().phi_high();
180 //if (phi_high.size() != s_required_phi_len) {return result;}
181
182 result.reserve(s_combination_len);
183
184 //Make a big vector as the VHDL does. Not strictly necessary, could just use the nbhd.
185 std::transform(std::begin(phi_high), std::end(phi_high), std::back_inserter(result), [](const auto& high) {
186 return high.m_e;
187 });
188 std::transform(std::begin(phi_center), std::end(phi_center), std::back_inserter(result), [](const auto& center) {
189 return center.m_e;
190 });
191 std::transform(std::begin(phi_low), std::end(phi_low), std::back_inserter(result), [](const auto& low) {
192 return low.m_e;
193 });
194
195 return result;
196 }
197
198 std::string eRatioAlgTool_UCL::toString() const {
199
200 std::stringstream ss;
201 ss << "eRatioAlgTool_UCL. name: " << name() << '\n'
203 << '\n';
204 return ss.str();
205 }
206}
207
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t ss
Header file to be included by clients of the Monitored infrastructure.
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.
ap_int< 16 > secondPeakSearch(const std::vector< ap_int< 16 > > &input, const ap_int< 16 > peak, const int startCell, const int endCell, const ap_int< 16 > noiseMargin) const
std::vector< double > combine_phi(const IOBitwise::eEmNbhoodTOB *) const
eRatioAlgTool_UCL(const std::string &type, const std::string &name, const IInterface *parent)
virtual std::string toString() const override
virtual StatusCode run(const std::unique_ptr< IDataCollector > &, const EventContext &ctx) const override
SG::ReadHandleKey< IOBitwise::eEmNbhoodTOBContainer > m_nbhdTOBContainerReadKey
static constexpr int s_combination_len
StatusCode initialize() override
SG::WriteHandleKey< std::vector< float > > m_eRatioKey
SG::WriteHandleKey< std::vector< float > > m_eRatioSimpleKey
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 std::vector< ap_int< 16 > > digitize16(const std::vector< double > &v)
Definition Digitizer.h:42