ATLAS Offline Software
Loading...
Searching...
No Matches
HLT::MET::PufitGrid Class Reference

Bins energy deposits into a grid. More...

#include <PufitGrid.h>

Inheritance diagram for HLT::MET::PufitGrid:
Collaboration diagram for HLT::MET::PufitGrid:

Classes

class  Tower
 Describes a single element of the grid. More...

Public Types

enum class  SumStrategy { All , Masked , Unmasked }
 Helper enum to describe how to sum over towers. More...

Public Member Functions

 PufitGrid (double maxEta, std::size_t nEtaTowers, std::size_t nPhiTowers, bool displaceEta=false, bool displacePhi=false)
 Create a new tower grid.
 PufitGrid (const GridParameters &parameters)
 Construct a grid from the provided parameters.
 PufitGrid (const PufitGrid &other)
 Copy constructor.
PufitGridoperator= (const PufitGrid &other)
 Assignment operator.
void reset ()
 Reset the internal storage.
PufitGridoperator+= (const SignedKinematics &kin)
 Add a signed object to this grid.
PufitGridoperator-= (const SignedKinematics &kin)
 Remove the energy of a signed object from this grid.
Toweroperator[] (const std::pair< std::size_t, std::size_t > &indices)
 Access stored value by eta/phi index (access is bounds-checked)
const Toweroperator[] (const std::pair< std::size_t, std::size_t > &indices) const
 Access stored value by eta/phi index (access is bounds checked)
Toweroperator[] (std::size_t index)
 Access stored value by global index number (access is bounds checked)
const Toweroperator[] (std::size_t index) const
 Access stored value by global index number (access is bounds checked)
std::vector< Tower >::iterator begin ()
 Access by iterator.
std::vector< Tower >::const_iterator begin () const
 Access by iterator.
std::vector< Tower >::iterator end ()
 Iterator end point.
std::vector< Tower >::const_iterator end () const
 Iterator end point.
METComponent sum (SumStrategy strategy=SumStrategy::All) const
PufitGridoperator+= (const PufitGrid &other)
 Add a whole grid into this.
PufitGridoperator-= (const PufitGrid &other)
 Subtract a whole grid from this.
std::size_t getIndex (double eta, double phi, bool &outOfRange) const
 Get the index for the given eta, phi values.
std::size_t getEtaIndex (double eta, bool &outOfRange) const
 Get the eta index for the given value.
std::size_t getPhiIndex (double phi) const
 Get the phi index for the given value.
std::size_t globalIndex (std::size_t iEta, std::size_t iPhi) const
 Convert eta and phi to a global index.
std::pair< std::size_t, std::size_t > etaPhiIndex (std::size_t index) const
 Convert a global index to an eta/phi index pair.
double centralEta (std::size_t iEta) const
 Central eta coordinate of the given eta index.
double centralPhi (std::size_t iPhi) const
 Central phi coordinate of the given phi.
const GridParametersparameters () const
 The grid parameters.
double maxEta () const
 The maximum eta range for the grid.
std::size_t nEtaTowers () const
 The number of eta bins.
std::size_t nPhiTowers () const
 The number of phi bins.
std::size_t nTowers () const
 The number of bins.
bool displaceEta () const
 Whether or not this is displaced in eta.
bool displacePhi () const
 Whether or not this is displaced in phi.
GridDisplacement displacement () const
 The grid displacement.
double etaWidth () const
 The bin width in eta.
double phiWidth () const
 The bin width in phi.

Private Attributes

std::vector< Towerm_towers
const GridParameters m_params
 The grid's parameters.

Detailed Description

Bins energy deposits into a grid.

The grid can be displaced in eta and/or phi. In this case the grid will be moved by half a bin in the relevant directions. For these purposes the grid will be treated as periodic in eta, even though the calorimeter isn't really.

Definition at line 37 of file PufitGrid.h.

Member Enumeration Documentation

◆ SumStrategy

Helper enum to describe how to sum over towers.

Enumerator
All 
Masked 
Unmasked 

Definition at line 220 of file PufitGrid.h.

221 {
222 All, //> Sum all towers, regardless of masks
223 Masked, //> Only sum masked towers
224 Unmasked //> Only sum unmasked towers
225 };

Constructor & Destructor Documentation

◆ PufitGrid() [1/3]

HLT::MET::PufitGrid::PufitGrid ( double maxEta,
std::size_t nEtaTowers,
std::size_t nPhiTowers,
bool displaceEta = false,
bool displacePhi = false )

Create a new tower grid.

Parameters
maxEtaThe maximum eta range for the grid
nEtaTowersThe number of eta towers
nPhiTowersThe number of phi towers
displaceEtaWhether to displace eta
displacePhiWhether to displace phi

Definition at line 76 of file PufitGrid.cxx.

83 {
84 }
std::size_t nPhiTowers() const
The number of phi bins.
double maxEta() const
The maximum eta range for the grid.
std::size_t nEtaTowers() const
The number of eta bins.
bool displacePhi() const
Whether or not this is displaced in phi.
bool displaceEta() const
Whether or not this is displaced in eta.
PufitGrid(double maxEta, std::size_t nEtaTowers, std::size_t nPhiTowers, bool displaceEta=false, bool displacePhi=false)
Create a new tower grid.
Definition PufitGrid.cxx:76

◆ PufitGrid() [2/3]

HLT::MET::PufitGrid::PufitGrid ( const GridParameters & parameters)

Construct a grid from the provided parameters.

Definition at line 86 of file PufitGrid.cxx.

88 {
89 m_towers.reserve(nTowers());
90 for (std::size_t index = 0; index < nTowers(); ++index)
91 m_towers.emplace_back(this, index);
92 }
std::size_t nTowers() const
The number of bins.
PeriodicGridBase(const GridParameters &parameters)
Construct the grid from its parameters.
const GridParameters & parameters() const
The grid parameters.
std::vector< Tower > m_towers
Definition PufitGrid.h:235
str index
Definition DeMoScan.py:362

◆ PufitGrid() [3/3]

HLT::MET::PufitGrid::PufitGrid ( const PufitGrid & other)

Copy constructor.

Definition at line 94 of file PufitGrid.cxx.

94 : PufitGrid(other.parameters())
95 {
96 *this = other;
97 }

Member Function Documentation

◆ begin() [1/2]

std::vector< PufitGrid::Tower >::iterator HLT::MET::PufitGrid::begin ( )

Access by iterator.

Definition at line 154 of file PufitGrid.cxx.

155 {
156 return m_towers.begin();
157 }

◆ begin() [2/2]

std::vector< PufitGrid::Tower >::const_iterator HLT::MET::PufitGrid::begin ( ) const

Access by iterator.

Definition at line 158 of file PufitGrid.cxx.

159 {
160 return m_towers.begin();
161 }

◆ centralEta()

double HLT::MET::PeriodicGridBase::centralEta ( std::size_t iEta) const
inherited

Central eta coordinate of the given eta index.

Definition at line 129 of file PeriodicGridBase.cxx.

130 {
131 return -maxEta() + etaWidth() * (iEta + 0.5) + (displaceEta() ? etaWidth() / 2 : 0);
132 }
double etaWidth() const
The bin width in eta.
setScale setgFexType iEta

◆ centralPhi()

double HLT::MET::PeriodicGridBase::centralPhi ( std::size_t iPhi) const
inherited

Central phi coordinate of the given phi.

Definition at line 133 of file PeriodicGridBase.cxx.

134 {
135 return phiWidth() * (iPhi + 0.5) + (displacePhi() ? phiWidth() / 2 : 0);
136 }
double phiWidth() const
The bin width in phi.
@ iPhi
Definition ParamDefs.h:47

◆ displaceEta()

bool HLT::MET::PeriodicGridBase::displaceEta ( ) const
inherited

Whether or not this is displaced in eta.

Definition at line 143 of file PeriodicGridBase.cxx.

143{ return parameters().displaceEta; }
bool displaceEta
Whether the grid is displaced in eta.

◆ displacement()

GridDisplacement HLT::MET::PeriodicGridBase::displacement ( ) const
inherited

The grid displacement.

Definition at line 145 of file PeriodicGridBase.cxx.

146 {
147 return parameters().displacement();
148 }
GridDisplacement displacement() const
The.

◆ displacePhi()

bool HLT::MET::PeriodicGridBase::displacePhi ( ) const
inherited

Whether or not this is displaced in phi.

Definition at line 144 of file PeriodicGridBase.cxx.

144{ return parameters().displacePhi; }
bool displacePhi
Whether the grid is displaced in phi.

◆ end() [1/2]

std::vector< PufitGrid::Tower >::iterator HLT::MET::PufitGrid::end ( )

Iterator end point.

Definition at line 162 of file PufitGrid.cxx.

163 {
164 return m_towers.end();
165 }

◆ end() [2/2]

std::vector< PufitGrid::Tower >::const_iterator HLT::MET::PufitGrid::end ( ) const

Iterator end point.

Definition at line 166 of file PufitGrid.cxx.

167 {
168 return m_towers.end();
169 }

◆ etaPhiIndex()

std::pair< std::size_t, std::size_t > HLT::MET::PeriodicGridBase::etaPhiIndex ( std::size_t index) const
inherited

Convert a global index to an eta/phi index pair.

Definition at line 124 of file PeriodicGridBase.cxx.

125 {
126 return std::make_pair(index / nPhiTowers(), index % nPhiTowers());
127 }

◆ etaWidth()

double HLT::MET::PeriodicGridBase::etaWidth ( ) const
inherited

The bin width in eta.

Definition at line 149 of file PeriodicGridBase.cxx.

149{ return 2 * maxEta() / nEtaTowers(); }

◆ getEtaIndex()

std::size_t HLT::MET::PeriodicGridBase::getEtaIndex ( double eta,
bool & outOfRange ) const
inherited

Get the eta index for the given value.

Parameters
etaThe eta value
[out]outOfRangeSet to true if outside of the eta range

If it's out of range the returned index will be nEta

Definition at line 87 of file PeriodicGridBase.cxx.

88 {
89 if (std::abs(eta) >= maxEta())
90 {
91 outOfRange = true;
92 return nEtaTowers();
93 }
94 outOfRange = false;
95 if (displaceEta())
96 {
97 // Apply the displacement by adding the displacement to the input
98 // coordinate. This shifts the grid in the negative direction
99 eta += etaWidth() / 2;
100 // If necessary apply eta periodicity here
101 if (eta >= maxEta())
102 eta -= 2 * maxEta();
103 }
104 return (eta + maxEta()) / etaWidth();
105 }
Scalar eta() const
pseudorapidity method

◆ getIndex()

std::size_t HLT::MET::PeriodicGridBase::getIndex ( double eta,
double phi,
bool & outOfRange ) const
inherited

Get the index for the given eta, phi values.

Parameters
etaThe eta value
phiThe phi value
[out]outOfRangeSet to true if outside of the eta range

If it's out of range the returned index will be nTowers

Definition at line 79 of file PeriodicGridBase.cxx.

80 {
81 std::size_t etaIndex = getEtaIndex(eta, outOfRange);
82 if (outOfRange)
83 return nTowers();
84 return globalIndex(etaIndex, getPhiIndex(phi));
85 }
Scalar phi() const
phi method
std::size_t getPhiIndex(double phi) const
Get the phi index for the given value.
std::size_t globalIndex(std::size_t iEta, std::size_t iPhi) const
Convert eta and phi to a global index.
std::size_t getEtaIndex(double eta, bool &outOfRange) const
Get the eta index for the given value.

◆ getPhiIndex()

std::size_t HLT::MET::PeriodicGridBase::getPhiIndex ( double phi) const
inherited

Get the phi index for the given value.

Definition at line 107 of file PeriodicGridBase.cxx.

108 {
109 if (displacePhi())
110 // Apply the displacement by adding the displacement to the input
111 // coordinate. This shifts the grid in the negative direction
112 phi += phiWidth() / 2;
113 // Apply periodicity
114 phi = std::fmod(phi, 2 * M_PI);
115 if (phi < 0)
116 phi += 2 * M_PI;
117 return phi / phiWidth();
118 }
#define M_PI

◆ globalIndex()

std::size_t HLT::MET::PeriodicGridBase::globalIndex ( std::size_t iEta,
std::size_t iPhi ) const
inherited

Convert eta and phi to a global index.

Definition at line 120 of file PeriodicGridBase.cxx.

121 {
122 return iEta * nPhiTowers() + iPhi;
123 }

◆ maxEta()

double HLT::MET::PeriodicGridBase::maxEta ( ) const
inherited

The maximum eta range for the grid.

Definition at line 139 of file PeriodicGridBase.cxx.

139{ return parameters().maxEta; }
double maxEta
The maximum |eta| value.

◆ nEtaTowers()

std::size_t HLT::MET::PeriodicGridBase::nEtaTowers ( ) const
inherited

The number of eta bins.

Definition at line 140 of file PeriodicGridBase.cxx.

140{ return parameters().nEtaTowers; }
std::size_t nEtaTowers
The number of divisions along the eta axis.

◆ nPhiTowers()

std::size_t HLT::MET::PeriodicGridBase::nPhiTowers ( ) const
inherited

The number of phi bins.

Definition at line 141 of file PeriodicGridBase.cxx.

141{ return parameters().nPhiTowers; }
std::size_t nPhiTowers
The number of divisions along the phi axis.

◆ nTowers()

std::size_t HLT::MET::PeriodicGridBase::nTowers ( ) const
inherited

The number of bins.

Definition at line 142 of file PeriodicGridBase.cxx.

142{ return nEtaTowers() * nPhiTowers(); }

◆ operator+=() [1/2]

PufitGrid & HLT::MET::PufitGrid::operator+= ( const PufitGrid & other)

Add a whole grid into this.

Definition at line 194 of file PufitGrid.cxx.

195 {
196 if (parameters() != other.parameters())
197 throw std::invalid_argument("Grid parameters do not match");
198 auto itr = begin();
199 auto otherItr = other.begin();
200 for (; itr != end(); ++itr, ++otherItr)
201 *itr += *otherItr;
202 return *this;
203 }
std::vector< Tower >::iterator begin()
Access by iterator.
std::vector< Tower >::iterator end()
Iterator end point.

◆ operator+=() [2/2]

PufitGrid & HLT::MET::PufitGrid::operator+= ( const SignedKinematics & kin)

Add a signed object to this grid.

The object will be assigned to the relevant bin. It will not be added if it falls outside of the eta range. The momentum of the kinematics will be used. If you do not want this (i.e. you want mass to be ignored) you should construct the kinematics without mass.

Definition at line 115 of file PufitGrid.cxx.

116 {
117 // Find the right tower to add to
118 bool outOfRange = false;
119 std::size_t index = getIndex(kin.eta(), kin.phi(), outOfRange);
120 if (!outOfRange)
121 operator[](index) += kin;
122 return *this;
123 }
std::size_t getIndex(double eta, double phi, bool &outOfRange) const
Get the index for the given eta, phi values.
Tower & operator[](const std::pair< std::size_t, std::size_t > &indices)
Access stored value by eta/phi index (access is bounds-checked)

◆ operator-=() [1/2]

PufitGrid & HLT::MET::PufitGrid::operator-= ( const PufitGrid & other)

Subtract a whole grid from this.

Definition at line 204 of file PufitGrid.cxx.

205 {
206 if (parameters() != other.parameters())
207 throw std::invalid_argument("Grid parameters do not match");
208 auto itr = begin();
209 auto otherItr = other.begin();
210 for (; itr != end(); ++itr, ++otherItr)
211 *itr -= *otherItr;
212 return *this;
213 }

◆ operator-=() [2/2]

PufitGrid & HLT::MET::PufitGrid::operator-= ( const SignedKinematics & kin)

Remove the energy of a signed object from this grid.

The object will be assigned to the relevant bin. It will not be added if it falls outside of the eta range. The momentum of the kinematics will be used. If you do not want this (i.e. you want mass to be ignored) you should construct the kinematics without mass.

Definition at line 124 of file PufitGrid.cxx.

125 {
126 // Find the right tower to subtract from
127 bool outOfRange = false;
128 std::size_t index = getIndex(kin.eta(), kin.phi(), outOfRange);
129 if (!outOfRange)
130 operator[](index) -= kin;
131 return *this;
132 }

◆ operator=()

PufitGrid & HLT::MET::PufitGrid::operator= ( const PufitGrid & other)

Assignment operator.

Parameters
otherThe grid whose towers to take @except std::invalid_argument If other's parameters don't match ours.

Take the tower energies/masking from the other grid. This is only allowed between two grids with matching parameters.

Definition at line 99 of file PufitGrid.cxx.

100 {
101 if (parameters() != other.parameters())
102 throw std::invalid_argument("Grid parameters do not match!");
103 std::copy(other.begin(), other.end(), m_towers.begin());
104 return *this;
105 }

◆ operator[]() [1/4]

PufitGrid::Tower & HLT::MET::PufitGrid::operator[] ( const std::pair< std::size_t, std::size_t > & indices)

Access stored value by eta/phi index (access is bounds-checked)

Definition at line 134 of file PufitGrid.cxx.

136 {
137 return operator[](globalIndex(indices.first, indices.second));
138 }
std::pair< long int, long int > indices

◆ operator[]() [2/4]

const PufitGrid::Tower & HLT::MET::PufitGrid::operator[] ( const std::pair< std::size_t, std::size_t > & indices) const

Access stored value by eta/phi index (access is bounds checked)

Definition at line 139 of file PufitGrid.cxx.

141 {
142 return operator[](globalIndex(indices.first, indices.second));
143 }

◆ operator[]() [3/4]

PufitGrid::Tower & HLT::MET::PufitGrid::operator[] ( std::size_t index)

Access stored value by global index number (access is bounds checked)

Definition at line 145 of file PufitGrid.cxx.

146 {
147 return m_towers.at(index);
148 }

◆ operator[]() [4/4]

const PufitGrid::Tower & HLT::MET::PufitGrid::operator[] ( std::size_t index) const

Access stored value by global index number (access is bounds checked)

Definition at line 149 of file PufitGrid.cxx.

150 {
151 return m_towers.at(index);
152 }

◆ parameters()

const GridParameters & HLT::MET::PeriodicGridBase::parameters ( ) const
inherited

The grid parameters.

Definition at line 138 of file PeriodicGridBase.cxx.

138{ return m_params; }
const GridParameters m_params
The grid's parameters.

◆ phiWidth()

double HLT::MET::PeriodicGridBase::phiWidth ( ) const
inherited

The bin width in phi.

Definition at line 150 of file PeriodicGridBase.cxx.

150{ return 2 * M_PI / nPhiTowers(); }

◆ reset()

void HLT::MET::PufitGrid::reset ( )

Reset the internal storage.

Definition at line 107 of file PufitGrid.cxx.

108 {
109 // Here we construct a standalone tower to copy in 0 values to the tower
110 // kinematics. This kind of object is safe here but in general it's not a
111 // good idea to have one.
112 std::fill(begin(), end(), Tower(nullptr, -1));
113 }
Describes a single element of the grid.
Definition PufitGrid.h:48

◆ sum()

METComponent HLT::MET::PufitGrid::sum ( SumStrategy strategy = SumStrategy::All) const

Definition at line 171 of file PufitGrid.cxx.

172 {
173 METComponent total;
174 switch (strategy)
175 {
176 case SumStrategy::All:
177 for (const Tower &tower : *this)
178 total += tower;
179 break;
181 for (const Tower &tower : *this)
182 if (tower.masked())
183 total += tower;
184 break;
186 for (const Tower &tower : *this)
187 if (!tower.masked())
188 total += tower;
189 break;
190 }
191 return total;
192 }

Member Data Documentation

◆ m_params

const GridParameters HLT::MET::PeriodicGridBase::m_params
privateinherited

The grid's parameters.

Definition at line 191 of file PeriodicGridBase.h.

◆ m_towers

std::vector<Tower> HLT::MET::PufitGrid::m_towers
private

Definition at line 235 of file PufitGrid.h.


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