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