2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/SystemOfUnits.h"
15#include "CaloGeoHelpers/CaloSampling.h"
21#include "CaloDetDescr/CaloDetDescrElement.h"
51 const std::string& name,
52 const IInterface* pParent)
63 declareInterface<CaloTowerCollectionProcessor>(
this);
96 ATH_MSG_INFO(
"Configure for building topo-towers (filtered mode):");
99 ATH_MSG_WARNING(
"[ignore] cannot apply energy thresholds to topo-towers!");
114 ATH_MSG_INFO(
"[accept] configure exclusive towers: use cell energy threshold");
117 <<
" GeV is smaller than default (no-op) " <<
m_energyThresholdDef/Athena::Units::GeV <<
" GeV - fatal");
118 return StatusCode::FAILURE;
148 ATH_MSG_INFO(
"Cells from all samplings used for topo-cluster included");
157 for (
size_t i(0); i<nex; ++i ) {
166 std::map<bool,std::string> blu { {
true,
"true" }, {
false,
"false" } };
177 return StatusCode::SUCCESS;
181{
return StatusCode::SUCCESS; }
195 return StatusCode::FAILURE;
217 size_t numberOfTowers=towerGeo->
towerBins();
218 protocont_t pProtoCont; pProtoCont.reserve(numberOfTowers);
240 if ( !pTopoClusCont.
isValid() ) {
242 return StatusCode::FAILURE;
259 for (
uint_t ipc(0); ipc<pProtoCont.size(); ++ipc ) {
289 volatile double pt1(pc1->pt());
290 volatile double pt2(pc2->pt());
291 return ( pt1 > pt2 );
296 return StatusCode::SUCCESS;
313 for (
const auto *pClus : pClusCont ) {
314 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
315 uint_t cidx(
static_cast<uint_t>((*fCell)->caloDDE()->calo_hash()));
316 if ( cidx < cellTags.size() ) {
317 if ( !cellTags.at(cidx) ) { cellTags[cidx] = this->
addCellToProtoCluster(towerGeo,*fCell,pProtoCont); }
327 std::vector<std::tuple<const CaloCell*,double> > cellList(towerGeo->
totalNumberCells(),std::tuple<const CaloCell*,double>(
nullptr,0.));
328 for (
const auto *pClus : pClusCont ) {
330 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
331 uint_t cidx(
static_cast<uint_t>((*fCell)->caloDDE()->calo_hash()));
332 if ( cellTags.at(cidx) ) {
333 std::get<1>(cellList[cidx]) += fCell.weight();
335 cellList[cidx] = std::tuple<const CaloCell*,double>(*fCell,fCell.weight());
336 cellTags[cidx] =
true;
344 for (
auto tpl : cellList ) { this->
addCellToProtoCluster(towerGeo,std::get<0>(tpl),pProtoCont,std::get<1>(tpl)); }
348 return cCtr+pProtoCont.size();
365 for (
const auto *pClus : pClusCont ) {
367 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
371 cellWeights->
set(*fCell,fCell.weight());
376 for (
const auto *pClus : pClusCont ) {
380 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
384 cellWeights->
set(*fCell,fCell.weight());
393 return cCtr+pProtoCont.size();
405 for (
const auto *cptr : pCellCont ) {
406 if ( cptr ==
nullptr ) {
415 return pProtoCont.size();
423 for (
const auto *cptr : pCellCont ) {
424 if ( cptr ==
nullptr ) {
434 return pProtoCont.size();
442 if ( cptr ==
nullptr ) {
return false; }
450 uint_t cellIdx(pProtoCont.at(towerIdx).getCellLinks()->getCellContainer()->findIndex(cptr->
caloDDE()->
calo_hash()));
451 pProtoCont[towerIdx].addCell(cellIdx,towerGeo->
cellWeight(elm)*weight); ++nctr;
468 return nTowers == 6400
481 int nrc(0);
int hid(0);
482 auto fcell(clk->
begin());
483 while ( fcell != clk->
end() ) {
487 if ( pCell ==
nullptr ) {
489 fcell.index(),nc-1,nclus,towerGeo->
towerEta(nclus),towerGeo->
towerPhi(nclus),
490 (
void*)pCell,(
void*)aCell,++nrc,clk->
size()) );
505 }
else if ( fcell.weight() <= 0.0000001 ) {
519{
return clnk.
size() > 0; }
529 if ( pCellCont ==
nullptr ) {
531 }
else if ( pCellCont->
empty() ) {
540 std::string algname(this->name());
541 if ( algname.find_last_of(
'.') != std::string::npos ) { algname = algname.substr(algname.find_last_of(
'.')+1); }
543 std::ofstream logstream; logstream.open(logname);
544 if ( !logstream.is_open() ) {
548 logstream <<
"##########################################################################" << std::endl;
549 logstream <<
"### This file contains a list of CaloCell indices in CaloCellContainer ###" << std::endl;
550 logstream <<
"### for which this index is not the same as the calorimeter cell hash ###" << std::endl;
551 logstream <<
"### identifier. An empty list indicates full consistency between this ###" << std::endl;
552 logstream <<
"### index and the hash identifier for all cells. ###" << std::endl;
553 logstream <<
"##########################################################################" << std::endl;
554 logstream <<
"<begin list>--------------------------------------------------------------" << std::endl;
562 auto chkflg = std::make_unique<std::bitset<200000> >();
564 for (
size_t i(0); i<pCellCont->
size(); ++i ) {
565 if ( pCellCont->
at(i) !=
nullptr ) {
568 std::string cni(
"UKNOWN");
569 double etai(0.);
double phii(0.);
571 if ( iel !=
nullptr ) {
576 std::string cnc(
"UNKNOWN");
577 double etac(0.);
double phic(0.);
579 if ( cel !=
nullptr ) {
584 size_t cidx(pCellCont->
findIndex(chash));
585 logstream <<
CaloRec::Helpers::fmtMsg(
"[%06zu] Cell %6zu [%12.12s %5.3f %5.3f] non-matching id %6zu [%12.12s %5.3f %5.3f] findCell() index %6zu",
586 ++ifc,i,cni.c_str(),etai,phii,chash,cnc.c_str(),etac,phic,cidx) << std::endl;
591 logstream <<
"<end list>----------------------------------------------------------------" << std::endl;
604 for (
size_t i(0); i<chl.size(); ++i ) {
if ( !chkflg->test(i) ) { chl.push_back(i); } }
605 if ( !chl.empty() ) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
Definition of CaloDetDescrManager.
CaloPhiRange class declaration.
std::atomic< bool > CaloTopoTowerFromClusterMaker_checkCellIndices(false)
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Wrapper to avoid constant divisions when using units.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool msgLvl(const MSG::Level lvl) const
Header file for AthHistogramAlgorithm.
Hash lookup of calibration weights for calorimeter cells.
bool check(size_t hash) const
Safe checking if cell is used by any cluster.
void set(size_t hash, double value)
Container class for CaloCell.
int findIndex(const IdentifierHash theHash) const
Return index of the cell with a given hash.
Data object for each calorimeter readout cell.
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Bookkeeping of cells that make up a cluster Simplified replacement for CaloCellLink,...
const CaloCellContainer * getCellContainer() const
Method to access underlying cell container.
const_iterator end() const
const end method
size_t size() const
size method
CaloClusterCellLink::iterator removeCell(iterator cellItr)
Method to remove a cell.
const_iterator begin() const
const begin method
This class groups all DetDescr information related to a CaloCell.
IdentifierHash calo_hash() const
cell calo hash
float eta_raw() const
cell eta_raw
CaloCell_ID::CaloSample getSampling() const
cell sampling
float phi_raw() const
cell phi_raw
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
calo_element_vec_size element_size() const
total number of elements
This class provides the client interface for accessing the detector description information common to...
CaloClusterCellLink * releaseCellLinks()
Hand over ownership of CaloClusterCellLink to client.
provides Calorimeter Sampling enum
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
static const double m_energyThresholdDef
Default energy threshold.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
double m_clusterRange
Range where topo-clusters are used when m_buildCombinedSignal = true
static const double m_clusterRangeDef
Default cluster range.
virtual StatusCode execute(const EventContext &ctx, xAOD::CaloClusterContainer *pClusCont, CaloCellClusterWeights *cellWeights) const override
Execute the tool and fill the xAOD::CaloClusterContainer pointed to by pClusCont.
uint_t m_numberOfSamplings
Number of samplings.
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Calorimeter cell container.
bool checkCellIndices(const CaloTowerGeometry *towerGeo, const CaloDetDescrManager *caloDDM, const CaloCellContainer *pCellCont) const
Checks consistency between cell indices and hash identifiers.
bool m_buildCombinedSignal
Build topo-clusters within given range, else topo-towers.
static const uint_t m_errorValueUINT
Error value for uint_t type values.
double m_energyThreshold
Cell energy threshold, default is set in m_energyThresholdDef.
std::bitset< _CALOTOPOTOWERFROMCLUSTERMAKER_BITSET_SIZE > m_excludedSamplingsPattern
Bit pattern indicates if sampling is excluded.
std::vector< std::string > m_excludedSamplingsName
List of excluded samplings (human-readable names)
bool addCellToProtoCluster(const CaloTowerGeometry *towerGeo, const CaloCell *cptr, protocont_t &pProtoCont, double weight=1.) const
Adding cells to proto-clusters.
bool m_useCellsFromClusters
Use cells from topo-clusters if true, else use all cells, default is true.
std::vector< CaloProtoCluster > protocont_t
Container for CaloProtoCluster objects.
static xAOD::CaloCluster::ClusterSize getClusterSize(uint_t etaBins, uint_t phiBins)
Returns a cluster size tag from number of eta and phi bins in tower grid.
bool m_prepareLCW
Prepare LCW calibration, default is false.
bool m_doCellIndexCheck
Check cell hash index consistency if true (default false)
uint_t buildInclTowers(const CaloTowerGeometry *towerGeo, const CaloCellContainer &pCellCont, protocont_t &pProtoCont) const
Inclusive towers.
std::vector< CaloSampling::CaloSample > m_excludedSamplings
List of excluded samplings (CaloSampling::CaloSample enumerators)
bool isValidIndex(uint_t idx) const
Checks if argument is a valid index value.
bool m_removeSamplingData
Remove sampling data for towers.
CaloTopoTowerFromClusterMaker(const std::string &type, const std::string &name, const IInterface *pParent)
Tool constructor.
uint_t buildExclTowers(const CaloTowerGeometry *towerGeo, const CaloCellContainer &pCellCont, protocont_t &pProtoCont) const
Exclusive towers.
uint_t buildLCWTopoTowers(const CaloTowerGeometry *towerGeo, const xAOD::CaloClusterContainer &clusCont, protocont_t &protoCont, CaloCellClusterWeights *cellWeights) const
LCW topo-towers.
std::size_t uint_t
Unsigned integral type.
bool m_applyCellEnergyThreshold
Apply cell energy threshold, default is false.
SG::ReadCondHandleKey< CaloTowerGeometry > m_towerGeoKey
the name of the key of the CaloTowerGeometry object in the ConditonsStore
virtual StatusCode initialize() override
Setting up the operational mode and corresponding parameters.
virtual StatusCode finalize() override
Finalize the tool (no action)
static bool filterProtoCluster(const CaloClusterCellLink &clnk)
Checks for and removes invalid cell links.
uint_t buildEMTopoTowers(const CaloTowerGeometry *towerGeo, const xAOD::CaloClusterContainer &clusCont, protocont_t &protoCont) const
EM topo-towers.
bool m_orderByPt
Orders cluster container by , default true.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Topo-cluster container key.
int cleanupCells(const CaloTowerGeometry *towerGeo, CaloClusterCellLink *clk, uint_t nclus) const
Checks CaloClusterCellLink for consistency.
Retrieve the list of towers associated with a calorimeter cell referenced by its hash identifier.
index_t towerIndex(IdentifierHash cellHash) const
Get global tower index for a calorimeter cell referenced by its hash identifier.
uint_t totalNumberCells() const
Total number of cells.
double towerEta(index_t towerIndex) const
Return pseudorapidity from global tower index (bin center)
uint_t towerBins() const
Total number of towers.
double cellWeight(const element_t &elm) const
Retrieve cell signal weight from lookup table entry.
double towerPhi(index_t towerIndex) const
Return azimuth from global tower index (bin center)
bool isInvalidIndex(index_t idx) const
Returns true if argument is equal to the value provided by invalidIndex()
elementvector_t getTowers(IdentifierHash cellHash) const
Retrieve the list of towers associated with a calorimeter cell referenced its hash identifier.
uint_t maxCellHash() const
Maximum cell hash value.
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
void addCellLink(CaloClusterCellLink *CCCL)
void setClusterSize(const ClusterSize)
Get cluster size.
ClusterSize
Enumeration to identify different cluster sizes.
void setPhi0(flt_t)
Set raw of cluster seed.
void clearSamplingData()
Clear the sampling data.
bool calculateKine(xAOD::CaloCluster *pClus, bool onlyKine=false)
Kinematic updates.
std::string fmtMsg(const char *fmt,...)
static const std::string & getSamplingName(CaloSampling::CaloSample sid)
Lookup sampling name by identifier (function)
static CaloSampling::CaloSample getSamplingId(const std::string &sname)
Lookup sampling identifier by name (function)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.