Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
atlas
athena
Commits
6d3ecfcd
Commit
6d3ecfcd
authored
Sep 03, 2014
by
Scott Snyder
Committed by
Graeme Stewart
Sep 19, 2014
Browse files
Coverity warning fixes. (CaloEvent-01-08-49)
parent
ae7807ac
Changes
90
Expand all
Hide whitespace changes
Inline
Side-by-side
Calorimeter/CaloEvent/CaloEvent/CaloBinDescriptor.h
0 → 100644
View file @
6d3ecfcd
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef CALOEVENT_CALOBINDESCRIPTOR_H
#define CALOEVENT_CALOBINDESCRIPTOR_H
#include
<vector>
template
<
typename
T
>
class
CaloBinDescriptor
{
public:
/*! \brief Default constructor generates empty bin descriptor */
CaloBinDescriptor
()
{
m_bins
.
clear
();
};
/*! \brief Explicit copy constructor */
explicit
CaloBinDescriptor
(
const
CaloBinDescriptor
&
theBins
);
/// Assignment.
CaloBinDescriptor
&
operator
=
(
const
CaloBinDescriptor
&
theBins
);
/*! \brief Construct with variable sized bins
*
* \param theBins reference to vector of bin boundaries with n+1
* entries for n bins;
*
* \note There is no consistency check performed on the bin delimiters.
* Any invalid sequence of delimiters, i.e. not ordered increasing
* in value, will lead to unexpected index mapping.
*/
CaloBinDescriptor
(
const
std
::
vector
<
T
>&
theBins
);
/*! \brief Construct with regular bins
*
* \param nBins number of bins
* \param lowerLimit lower limit of value range
* \param upperLimit upper limit of value range
*
* \note Invalid input (\a nbins = 0, \a lowerLimit >= \a upperLimit) will
* lead to empty (unusable) bin descriptor.
*
* The input parameters are internally converted into a vector of lower
* bin boundaries (first n entries) and the upper limit of the value
* range (n+1 entry).
*/
CaloBinDescriptor
(
size_t
nBins
,
const
T
&
lowerLimit
,
const
T
&
upperLimit
);
/*! \brief Default constructor */
~
CaloBinDescriptor
()
{
};
/*! \brief Retrieve the number of bins
*
* Returns 0 for empty bin descriptor.
*/
size_t
getNumberOfBins
()
const
;
/*! \brief Retrieve the lower value range boundary */
T
lowerBound
()
const
;
/*! \brief Retrieve the upper value range boundary */
T
upperBound
()
const
;
/*! \brief Retrieve the lower bin edge of a given bin
*
* \param theIndex bin index \f$ i \in [1,n] \f$ for \f$ n \f$ bins.
*
* Returns 0 if \a theIndex out of range.
*
* \warning 0 is a valid return as well.
*/
T
lowerBinEdge
(
size_t
theIndex
)
const
;
/*! \brief Retrieve the upper bin edge of a given bin
*
* \param theIndex bin index \f$ i \in [1,n] \f$ for \f$ n \f$ bins.
*
* Returns 0 if \a theIndex out of range.
*
* \warning 0 is a valid return as well.
*/
T
upperBinEdge
(
size_t
theIndex
)
const
;
/*! \brief Retrieve the bin width of a given bin
*
* \param theIndex bin index \f$ i \in [1,n] \f$ for \f$ n \f$ bins.
*
* Returns 0 if \a theIndex out of range. A valid return is positive
* definit.
*
*/
T
binWidth
(
size_t
theIndex
)
const
;
/*! \brief Direct Access to the vector describing the binning */
const
std
::
vector
<
T
>&
getBinning
()
const
;
/*! \brief Get the index for a iven value
*
* \param theData input value to be tested
*
* Returns 0 if \a theData is smaller than the lower value range boundary,
* and \a outOfRangeMarker if \a theData is bigger than the upper
* value range boundary.
*/
size_t
getIndex
(
const
T
&
theData
)
const
;
/*! \brief Tests if given index is out of valid range
*
* \param theIndex input index to be tested
*
* Returns <tt>true</tt> if \a theIndex within range.
*/
bool
outOfRange
(
size_t
theIndex
)
const
;
/*! \brief Returns the value of the out-of-range marker */
size_t
outOfRangeMarker
()
const
;
private:
/*! \brief Bin store
*
* n+1 entries for n bins.
*/
std
::
vector
<
T
>
m_bins
;
/*! \brief Out-of-range marker (convention) */
static
size_t
m_outOfRange
;
};
template
<
typename
T
>
CaloBinDescriptor
<
T
>::
CaloBinDescriptor
(
const
CaloBinDescriptor
&
theBins
)
:
m_bins
(
theBins
.
m_bins
)
{
}
template
<
typename
T
>
CaloBinDescriptor
<
T
>&
CaloBinDescriptor
<
T
>::
operator
=
(
const
CaloBinDescriptor
&
theBins
)
{
if
(
this
!=
&
theBins
)
m_bins
=
theBins
.
m_bins
;
return
*
this
;
}
template
<
typename
T
>
size_t
CaloBinDescriptor
<
T
>::
m_outOfRange
=
size_t
(
-
1
);
template
<
typename
T
>
CaloBinDescriptor
<
T
>::
CaloBinDescriptor
(
const
std
::
vector
<
T
>&
theBins
)
:
m_bins
(
theBins
)
{
}
template
<
typename
T
>
CaloBinDescriptor
<
T
>::
CaloBinDescriptor
(
size_t
nBins
,
const
T
&
lowerEdge
,
const
T
&
upperEdge
)
{
if
(
lowerEdge
<
upperEdge
&&
nBins
>
0
)
{
double
fBin
=
lowerEdge
;
double
dBin
=
(
upperEdge
-
lowerEdge
)
/
(
double
)
nBins
;
while
(
fBin
<=
(
upperEdge
+
dBin
/
2.
)
)
{
m_bins
.
push_back
(
fBin
);
fBin
+=
dBin
;
}
}
else
{
m_bins
.
clear
();
}
}
template
<
typename
T
>
inline
size_t
CaloBinDescriptor
<
T
>::
getNumberOfBins
()
const
{
return
m_bins
.
size
()
-
1
;
}
template
<
typename
T
>
inline
T
CaloBinDescriptor
<
T
>::
lowerBound
()
const
{
return
m_bins
.
size
()
>
0
?
*
(
m_bins
.
begin
())
:
0.
;
}
template
<
typename
T
>
inline
T
CaloBinDescriptor
<
T
>::
upperBound
()
const
{
return
m_bins
.
size
()
>
0
?
*
(
--
(
m_bins
.
end
()))
:
0.
;
}
template
<
typename
T
>
inline
T
CaloBinDescriptor
<
T
>::
lowerBinEdge
(
size_t
theIndex
)
const
{
return
theIndex
<
m_bins
.
size
()
-
2
?
m_bins
[
theIndex
]
:
0.
;
}
template
<
typename
T
>
inline
T
CaloBinDescriptor
<
T
>::
upperBinEdge
(
size_t
theIndex
)
const
{
return
theIndex
<
m_bins
.
size
()
-
1
?
m_bins
[
theIndex
+
1
]
:
0
;
}
template
<
typename
T
>
inline
T
CaloBinDescriptor
<
T
>::
binWidth
(
size_t
theIndex
)
const
{
return
theIndex
<
m_bins
.
size
()
-
2
?
m_bins
[
theIndex
+
1
]
-
m_bins
[
theIndex
]
:
0.
;
}
template
<
typename
T
>
inline
const
std
::
vector
<
T
>&
CaloBinDescriptor
<
T
>::
getBinning
()
const
{
return
m_bins
;
}
template
<
typename
T
>
size_t
CaloBinDescriptor
<
T
>::
getIndex
(
const
T
&
theData
)
const
{
size_t
theIndex
=
0
;
while
(
theData
>
m_bins
[
theIndex
]
&&
theIndex
<
this
->
getNumberOfBins
()
)
{
theIndex
++
;
}
return
theIndex
<
this
->
getNumberOfBins
()
?
theIndex
:
m_outOfRange
;
}
template
<
typename
T
>
inline
bool
CaloBinDescriptor
<
T
>::
outOfRange
(
size_t
theIndex
)
const
{
return
theIndex
!=
m_outOfRange
?
theIndex
<
this
->
getNumberOfBins
()
:
true
;
}
template
<
typename
T
>
inline
size_t
CaloBinDescriptor
<
T
>::
outOfRangeMarker
()
const
{
return
m_outOfRange
;
}
/*! \class CaloBinDescriptor
*
* \brief Data object containing bin descriptions
*
* \author Peter Loch <loch@physics.arizona.edu>
* \date April 1, 2005
* \version 0
*
* This data object stores the description of bins for any data type
* \a T with support for simple arithmatic
* (operators <tt>+</tt>,<tt>-</tt>,<tt>*</tt>,<tt>/</tt>)
* and valid comparators
* (operators <tt>></tt>,<tt>=></tt>,<tt><</tt>,<tt><=</tt>). The bins
* can be equidistant or variable.
*/
#endif
Calorimeter/CaloEvent/CaloEvent/CaloCell.h
0 → 100644
View file @
6d3ecfcd
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef CALOEVENT_CALOCELL_H
#define CALOEVENT_CALOCELL_H
/**
@class CaloCell
@brief Data object for each calorimeter readout cell.
CaloCell is a class with nearly all information on a calorimeter cell
in a given event. It has 4-momentum behavior through P4EEtaPhiMBase
inheritance, and Navigable behavior through INavigable4Momentum,
and NavigableTerminalNode inheritance.
Further static information can be obtained through the CaloDetDescrElement
obtained with caloDDE() method.
CaloCell is a base class to LArCell (which is identical) and TileCell.
@author Hong Ma
@author David Rousseau
@author Peter Loch
*/
// Update:
// Jan 10 2001 HMA
// ordor of static/virtual/const
// Nov 12 2001 EDF
// Inherit from Navigible. Now CaloCell has a pure virtual method
// and can not be instantiated directly.
// June 13 2003 DR delegate to CaloDetDescrElement
// Feb 25 2004 DR CaloGain data member
// Apr 01 2004 PL new navigation and clean-up
//
#include
"EventKernel/INavigable4Momentum.h"
#include
"Navigation/NavigableTerminalNode.h"
#include
"Identifier/Identifier.h"
#include
"CaloIdentifier/CaloGain.h"
#include
"FourMom/P4EEtaPhiMBase.h"
#include
"CxxUtils/final.h"
#include
<math.h>
#include
<iostream>
#include
<functional>
//class CaloDetDescrElement;
#include
"CaloDetDescr/CaloDetDescrElement.h"
#include
"GeoPrimitives/GeoPrimitives.h"
class
CaloCell
:
virtual
public
P4EEtaPhiMBase
,
virtual
public
INavigable4Momentum
,
public
NavigableTerminalNode
{
public:
/** @brief default constructor (should not be used, only there for persistency reason) */
CaloCell
();
/** @brief Legacy constructor */
CaloCell
(
const
CaloDetDescrElement
*
caloDDE
,
float
energy
,
float
time
,
double
quality
,
CaloGain
::
CaloGain
gain
);
/** @brief Main constructor */
CaloCell
(
const
CaloDetDescrElement
*
caloDDE
,
float
energy
,
float
time
,
uint16_t
quality
,
uint16_t
provenance
,
CaloGain
::
CaloGain
gain
);
/** @brief Legacy constructor for MBTS cells which doesn't use caloDDE to get ID */
CaloCell
(
const
CaloDetDescrElement
*
caloDDE
,
const
Identifier
&
ID
,
float
energy
,
float
time
,
double
quality
,
CaloGain
::
CaloGain
gain
);
/** @brief Main constructor for MBTS cells which doesn't use caloDDE to get ID */
CaloCell
(
const
CaloDetDescrElement
*
caloDDE
,
const
Identifier
&
ID
,
float
energy
,
float
time
,
uint16_t
quality
,
uint16_t
provenance
,
CaloGain
::
CaloGain
gain
);
/** @brief default destructor */
virtual
~
CaloCell
();
/** @brief get energy (data member) */
virtual
double
energy
()
const
ATH_FINAL
;
/** @brief get phi (through CaloDetDescrElement) */
virtual
double
phi
()
const
ATH_FINAL
;
/** @brief get eta (through CaloDetDescrElement) */
virtual
double
eta
()
const
ATH_FINAL
;
/** @brief get sin(theta) (through CaloDetDescrElement) */
virtual
double
sinTh
()
const
ATH_FINAL
;
/** @brief get cos(theta) (derived from sinTh) */
virtual
double
cosTh
()
const
ATH_FINAL
;
/** @brief get sin(phi) */
virtual
double
sinPhi
()
const
ATH_FINAL
;
/** @brief get cos(phi) */
virtual
double
cosPhi
()
const
ATH_FINAL
;
/** @brief get cottan(theta) */
virtual
double
cotTh
()
const
ATH_FINAL
;
/** @brief get mass (hardcoded to be null) */
virtual
double
m
()
const
ATH_FINAL
;
/** @brief get energy (data member) (synonym to method e() */
virtual
double
e
()
const
ATH_FINAL
;
/** @brief get x (through CaloDetDescrElement) */
virtual
float
x
()
const
ATH_FINAL
;
/** @brief get y (through CaloDetDescrElement) */
virtual
float
y
()
const
ATH_FINAL
;
/** @brief get z (through CaloDetDescrElement) */
virtual
float
z
()
const
ATH_FINAL
;
/** @brief get ID (from cached data member)
* non-virtual and inline for fast access */
Identifier
ID
()
const
;
// TODO: These can probably be made non-virtual.
/** @brief get time (data member) */
virtual
float
time
()
const
ATH_FINAL
;
/** @brief get quality (data member) */
virtual
uint16_t
quality
()
const
ATH_FINAL
;
/** @brief get provenance (data member) */
virtual
uint16_t
provenance
()
const
ATH_FINAL
;
/** @brief get gain (data member ) */
virtual
CaloGain
::
CaloGain
gain
()
const
ATH_FINAL
;
/** @brief check is cell is dead */
virtual
bool
badcell
()
const
;
/** @brief get pointer to CaloDetDescrElement (data member) */
const
CaloDetDescrElement
*
caloDDE
()
const
;
/** @brief set pointer to CaloDetDescrElement */
virtual
void
setCaloDDE
(
const
CaloDetDescrElement
*
caloDDE
);
/** @brief set energy */
virtual
void
setEnergy
(
float
energy
);
/** @brief add energy */
virtual
void
addEnergy
(
float
energy
);
/** @brief scale energy */
virtual
void
scaleEnergy
(
float
scale
);
/** @brief set time */
virtual
void
setTime
(
float
time
);
/** @brief set quality */
virtual
void
setQuality
(
uint16_t
quality
);
/** @brief set Quality (obsolete) */
virtual
void
setQuality
(
double
quality
);
/** @brief set Provenance */
virtual
void
setProvenance
(
uint16_t
prov
);
/** @brief set gain */
virtual
void
setGain
(
CaloGain
::
CaloGain
gain
=
CaloGain
::
INVALIDGAIN
);
/** set 4Momentum (will throw exception since cannot be implemented) */
virtual
void
set4Mom
(
const
I4Momentum
*
const
theI4Mom
)
;
/** set 4Momentum (will throw exception since cannot be implemented) */
virtual
void
set4Mom
(
const
I4Momentum
&
theI4Mom
);
/** set 4Momentum (will throw exception since cannot be implemented) */
virtual
void
set4Mom
(
const
CLHEP
::
HepLorentzVector
&
theHlv
)
;
/** @brief clone a CaloCell */
virtual
CaloCell
*
clone
()
const
;
/** @brief Fast method to change the identity of a cell. */
void
set
(
const
CaloDetDescrElement
*
caloDDE
,
const
Identifier
&
ID
);
/** @brief Fast method to change the data of a cell. */
void
set
(
float
energy
,
float
time
,
uint16_t
quality
,
uint16_t
provenance
,
CaloGain
::
CaloGain
gain
);
/** @brief Fast method to change the data of a cell. OBSOLETE*/
void
set
(
float
energy
,
float
time
,
double
quality
,
CaloGain
::
CaloGain
gain
);
protected:
/** @brief energy (in MeV) */
float
m_energy
;
/** @brief time */
float
m_time
;
// Reflex doesn't handle unions completely correctly.
// If you have a union as a data member, it will print a warning
// at runtime. So, hide the union from reflex. (Only m_quality is used
// in inlined code.)
/** @brief quality */
#ifdef __REFLEX__
int
m_quality
;
# define m_qualProv ((uint16_t*)&m_quality)
# define m_tileQual ((uint8_t*)&m_quality)
#else
union
{
int
m_quality
;
uint16_t
m_qualProv
[
2
];
uint8_t
m_tileQual
[
4
];
};
#endif
/** @brief offline identifier */
Identifier
m_ID
;
/** @brief gain */
CaloGain
::
CaloGain
m_gain
;
/** @brief pointer to static CaloDetDescrElement to access information that does
* not change from event to event */
const
CaloDetDescrElement
*
m_caloDDE
;
};
// inlines
inline
CaloCell
::
CaloCell
()
:
m_energy
(
0
),
m_time
(
0
),
m_quality
(
0
),
m_gain
(
CaloGain
::
UNKNOWNGAIN
),
m_caloDDE
(
0
)
{}
inline
Identifier
CaloCell
::
ID
()
const
{
return
m_ID
;
}
/**
* @brief A functional to get the ID from a CaloCell pointer.
*
* This can be used as the hash function to @c unordered_map and friends.
*/
struct
CaloCellIDFcn
:
public
std
::
unary_function
<
const
CaloCell
*
,
std
::
size_t
>
{
std
::
size_t
operator
()
(
const
CaloCell
*
p
)
const
{
return
p
->
ID
().
get_identifier32
().
get_compact
();
}
};
// Make this the default hash function for NavigationToken.
inline
std
::
size_t
navigationHash
(
const
CaloCell
*
p
)
{
return
p
->
ID
().
get_identifier32
().
get_compact
();
}
inline
const
CaloDetDescrElement
*
CaloCell
::
caloDDE
()
const
{
return
m_caloDDE
;
}
inline
double
CaloCell
::
energy
()
const
{
return
m_energy
;
}
inline
double
CaloCell
::
e
()
const
{
return
m_energy
;
}
inline
double
CaloCell
::
m
()
const
{
// zero mass by convention
return
0.
;
}
inline
uint16_t
CaloCell
::
quality
()
const
{
return
m_qualProv
[
0
];
}
inline
uint16_t
CaloCell
::
provenance
()
const
{
return
m_qualProv
[
1
];
}
inline
CaloGain
::
CaloGain
CaloCell
::
gain
()
const
{
return
m_gain
;
}
inline
float
CaloCell
::
time
()
const
{
return
m_time
;
}
inline
double
CaloCell
::
phi
()
const
{
return
m_caloDDE
->
phi
();
}
inline
double
CaloCell
::
eta
()
const
{
return
m_caloDDE
->
eta
();
}
inline
double
CaloCell
::
sinTh
()
const
{
return
m_caloDDE
->
sinTh
();
}
inline
double
CaloCell
::
cosTh
()
const
{
return
m_caloDDE
->
cosTh
();
}
inline
double
CaloCell
::
cotTh
()
const
{
return
m_caloDDE
->
cotTh
();
}