ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GlobalSim::Egamma1eRatioAlgTool Class Reference

#include <Egamma1eRatioAlgTool.h>

Inheritance diagram for GlobalSim::Egamma1eRatioAlgTool:
Collaboration diagram for GlobalSim::Egamma1eRatioAlgTool:

Public Member Functions

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

Private Member Functions

std::vector< double > combine_phi (const IOBitwise::IeEmNbhoodTOB *) const
 
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
 

Private Attributes

Gaudi::Property< bool > m_enableDump
 
SG::ReadHandleKey< IOBitwise::IeEmNbhoodTOBContainerm_nbhdTOBContainerReadKey
 
SG::WriteHandleKey< IOBitwise::IeEmEg1eRatioTOBContainerm_eRatioResultKey
 
SG::WriteHandleKey< std::vector< int > > m_eRatioKey
 
SG::WriteHandleKey< std::vector< float > > m_eRatioSimpleKey
 

Static Private Attributes

static constexpr int s_required_phi_len = 17
 
static constexpr int s_combination_len = 51
 

Detailed Description

Definition at line 29 of file Egamma1eRatioAlgTool.h.

Constructor & Destructor Documentation

◆ Egamma1eRatioAlgTool()

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

Definition at line 15 of file Egamma1eRatioAlgTool.cxx.

17  :
18  base_class(type, name, parent){
19  }

◆ ~Egamma1eRatioAlgTool()

virtual GlobalSim::Egamma1eRatioAlgTool::~Egamma1eRatioAlgTool ( )
virtualdefault

Member Function Documentation

◆ combine_phi()

std::vector< double > GlobalSim::Egamma1eRatioAlgTool::combine_phi ( const IOBitwise::IeEmNbhoodTOB nbhdTOB) const
private

Definition at line 178 of file Egamma1eRatioAlgTool.cxx.

178  {
179  auto result = std::vector<double>();
180 
181  const auto& phi_low = nbhdTOB->Neighbourhood().phi_low();
182  //if (phi_low.size() != s_required_phi_len) {return result;}
183 
184  const auto& phi_center = nbhdTOB->Neighbourhood().phi_center();
185  //if (phi_center.size() != s_required_phi_len) {return result;}
186 
187  const auto& phi_high = nbhdTOB->Neighbourhood().phi_high();
188  //if (phi_high.size() != s_required_phi_len) {return result;}
189 
190  result.reserve(s_combination_len);
191 
192  //Make a big vector as the VHDL does. Not strictly necessary, could just use the nbhd.
193  std::transform(std::begin(phi_high), std::end(phi_high), std::back_inserter(result), [](const auto& high) {
194  return high.m_e;
195  });
196  std::transform(std::begin(phi_center), std::end(phi_center), std::back_inserter(result), [](const auto& center) {
197  return center.m_e;
198  });
199  std::transform(std::begin(phi_low), std::end(phi_low), std::back_inserter(result), [](const auto& low) {
200  return low.m_e;
201  });
202 
203  return result;
204  }

◆ initialize()

StatusCode GlobalSim::Egamma1eRatioAlgTool::initialize ( )
override

Definition at line 21 of file Egamma1eRatioAlgTool.cxx.

21  {
22 
23  CHECK(m_nbhdTOBContainerReadKey.initialize());
24  CHECK(m_eRatioResultKey.initialize());
27 
28  return StatusCode::SUCCESS;
29  }

◆ run()

StatusCode GlobalSim::Egamma1eRatioAlgTool::run ( const EventContext &  ctx) const
overridevirtual

Definition at line 32 of file Egamma1eRatioAlgTool.cxx.

32  {
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_eRatioResult.record(std::make_unique<IOBitwise::IeEmEg1eRatioTOBContainer>()));
50  CHECK(h_eRatio.record(std::make_unique<std::vector<int> >()));
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  //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 " << eRatio);
115 
116  //Make a bitset to hold the result
117  std::bitset<IOBitwise::IeEmEg1eRatioTOB::s_eGamma1eRatio_width> result = 0;
118  //Sanity check to make sure we are in range 0-1
119  if(eRatio >= 0. && eRatio <= 1.0){
120  //Convert to 0-2047. If s_eGamma1eRatio_width changes this will change.
121  int eRatioPower = (1 << IOBitwise::IeEmEg1eRatioTOB::s_eGamma1eRatio_width) -1;
122  h_eRatio->push_back((int)(eRatio*eRatioPower));
123  result = (int)(eRatio*eRatioPower);
124  } else {
125  ATH_MSG_DEBUG("eRatio is not in the range 0-1");
126  }
127  h_eRatioResult->push_back(std::make_unique<IOBitwise::eEmEg1eRatioTOB>(*nbhdTOB, result));
128  }
129  }
130 
131  return StatusCode::SUCCESS;
132  }

◆ secondPeakSearch()

ap_int< 16 > GlobalSim::Egamma1eRatioAlgTool::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
private

Definition at line 134 of file Egamma1eRatioAlgTool.cxx.

138  {
139  //First set a series of counters to "descending" = 0
140  int ascending = 0;
141 
142  //Setup holder of the last energy we checked... which starts at the peak...
143  ap_int<16> lastEnergy = peak;
144  ap_int<16> secondPeak = 0;
145 
146  //There must be a better way to do this?
147  int direction = 0;
148  if(startCell > endCell) {
149  direction =-1;
150  } else {
151  direction =1;
152  }
153 
154  //Route 1: go down in the middlle row
155  for (auto itr = input.begin() + startCell; itr != input.begin() + endCell + direction; itr+=direction){
156  //Going down hill... until we are not...
157  ATH_MSG_DEBUG("Input is " << *itr << " last energy is " << lastEnergy);
158  if(ascending==0 && *itr>lastEnergy && *itr-lastEnergy > noiseMargin){
159  ATH_MSG_DEBUG("We are going up now " << *itr << " is more then " << lastEnergy);
160  ascending=1;
161  lastEnergy=*itr;
162  //Now check if we are at the peak as we are going uphill
163  } else if(ascending==1 && lastEnergy>*itr && lastEnergy-*itr > noiseMargin){
164  ATH_MSG_DEBUG("We are past the top " << *itr << " is less than " << lastEnergy);
165  if(secondPeak<*itr) secondPeak = lastEnergy;
166  ATH_MSG_DEBUG("The peak was " << secondPeak);
167  //I think we can break here... don't need to find a third peak
168  break;
169  } else {
170  lastEnergy=*itr;
171  }
172  }
173 
174  return secondPeak;
175  }

◆ toString()

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

Definition at line 206 of file Egamma1eRatioAlgTool.cxx.

206  {
207 
208  std::stringstream ss;
209  ss << "Egamma1eRatioAlgTool. name: " << name() << '\n'
210  << m_nbhdTOBContainerReadKey << '\n'
211  << '\n';
212  return ss.str();
213  }

Member Data Documentation

◆ m_enableDump

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

Definition at line 47 of file Egamma1eRatioAlgTool.h.

◆ m_eRatioKey

SG::WriteHandleKey<std::vector<int> > GlobalSim::Egamma1eRatioAlgTool::m_eRatioKey
private
Initial value:
{
this,
"eRatioKey",
"eRatio"}

Definition at line 67 of file Egamma1eRatioAlgTool.h.

◆ m_eRatioResultKey

SG::WriteHandleKey<IOBitwise::IeEmEg1eRatioTOBContainer> GlobalSim::Egamma1eRatioAlgTool::m_eRatioResultKey
private
Initial value:
{
this,
"eRatioResultKey",
"eRatioResult"}

Definition at line 61 of file Egamma1eRatioAlgTool.h.

◆ m_eRatioSimpleKey

SG::WriteHandleKey<std::vector<float> > GlobalSim::Egamma1eRatioAlgTool::m_eRatioSimpleKey
private
Initial value:
{
this,
"eRatioSimpleKey",
"eRatioSimple"}

Definition at line 73 of file Egamma1eRatioAlgTool.h.

◆ m_nbhdTOBContainerReadKey

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

Definition at line 54 of file Egamma1eRatioAlgTool.h.

◆ s_combination_len

constexpr int GlobalSim::Egamma1eRatioAlgTool::s_combination_len = 51
inlinestaticconstexprprivate

Definition at line 90 of file Egamma1eRatioAlgTool.h.

◆ s_required_phi_len

constexpr int GlobalSim::Egamma1eRatioAlgTool::s_required_phi_len = 17
inlinestaticconstexprprivate

Definition at line 86 of file Egamma1eRatioAlgTool.h.


The documentation for this class was generated from the following files:
GlobalSim::Egamma1eRatioAlgTool::secondPeakSearch
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
Definition: Egamma1eRatioAlgTool.cxx:134
GlobalSim::Egamma1eRatioAlgTool::m_eRatioSimpleKey
SG::WriteHandleKey< std::vector< float > > m_eRatioSimpleKey
Definition: Egamma1eRatioAlgTool.h:73
get_generator_info.result
result
Definition: get_generator_info.py:21
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
GlobalSim::digitizer::digitize16
static std::vector< ap_int< 16 > > digitize16(const std::vector< double > &v)
Definition: Digitizer.h:42
GlobalSim::Egamma1eRatioAlgTool::combine_phi
std::vector< double > combine_phi(const IOBitwise::IeEmNbhoodTOB *) const
Definition: Egamma1eRatioAlgTool.cxx:178
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GlobalSim::Egamma1eRatioAlgTool::m_eRatioKey
SG::WriteHandleKey< std::vector< int > > m_eRatioKey
Definition: Egamma1eRatioAlgTool.h:67
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
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
python.TriggerAPI.TriggerAPISession.ascending
ascending
Definition: TriggerAPISession.py:435
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
GlobalSim::Egamma1eRatioAlgTool::m_nbhdTOBContainerReadKey
SG::ReadHandleKey< IOBitwise::IeEmNbhoodTOBContainer > m_nbhdTOBContainerReadKey
Definition: Egamma1eRatioAlgTool.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
GlobalSim::Egamma1eRatioAlgTool::s_combination_len
static constexpr int s_combination_len
Definition: Egamma1eRatioAlgTool.h:90
DEBUG
#define DEBUG
Definition: page_access.h:11
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
GlobalSim::IOBitwise::IeEmEg1eRatioTOB::s_eGamma1eRatio_width
static const std::size_t s_eGamma1eRatio_width
Count: Size of output bits of the eGamma1 eRatio algorithm.
Definition: IeEmEg1eRatioTOB.h:33
GlobalSim::Egamma1eRatioAlgTool::m_eRatioResultKey
SG::WriteHandleKey< IOBitwise::IeEmEg1eRatioTOBContainer > m_eRatioResultKey
Definition: Egamma1eRatioAlgTool.h:61