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)
55 declareInterface<CaloTowerCollectionProcessor>(
this);
76 ATH_MSG_INFO(
"Configure for building topo-towers (filtered mode):");
79 ATH_MSG_WARNING(
"[ignore] cannot apply energy thresholds to topo-towers!");
94 ATH_MSG_INFO(
"[accept] configure exclusive towers: use cell energy threshold");
97 <<
" GeV is smaller than default (no-op) " <<
m_energyThresholdDef/Athena::Units::GeV <<
" GeV - fatal");
98 return StatusCode::FAILURE;
128 ATH_MSG_INFO(
"Cells from all samplings used for topo-cluster included");
137 for (
size_t i(0); i<nex; ++i ) {
146 std::map<bool,std::string> blu { {
true,
"true" }, {
false,
"false" } };
157 return StatusCode::SUCCESS;
161{
return StatusCode::SUCCESS; }
175 return StatusCode::FAILURE;
197 size_t numberOfTowers=towerGeo->
towerBins();
198 protocont_t pProtoCont; pProtoCont.reserve(numberOfTowers);
220 if ( !pTopoClusCont.
isValid() ) {
222 return StatusCode::FAILURE;
239 for (
uint_t ipc(0); ipc<pProtoCont.size(); ++ipc ) {
269 volatile double pt1(pc1->pt());
270 volatile double pt2(pc2->pt());
271 return ( pt1 > pt2 );
276 return StatusCode::SUCCESS;
293 for (
const auto *pClus : pClusCont ) {
294 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
295 uint_t cidx(
static_cast<uint_t>((*fCell)->caloDDE()->calo_hash()));
296 if ( cidx < cellTags.size() ) {
297 if ( !cellTags.at(cidx) ) { cellTags[cidx] = this->
addCellToProtoCluster(towerGeo,*fCell,pProtoCont); }
307 std::vector<std::tuple<const CaloCell*,double> > cellList(towerGeo->
totalNumberCells(),std::tuple<const CaloCell*,double>(
nullptr,0.));
308 for (
const auto *pClus : pClusCont ) {
310 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
311 uint_t cidx(
static_cast<uint_t>((*fCell)->caloDDE()->calo_hash()));
312 if ( cellTags.at(cidx) ) {
313 std::get<1>(cellList[cidx]) += fCell.weight();
315 cellList[cidx] = std::tuple<const CaloCell*,double>(*fCell,fCell.weight());
316 cellTags[cidx] =
true;
324 for (
auto tpl : cellList ) { this->
addCellToProtoCluster(towerGeo,std::get<0>(tpl),pProtoCont,std::get<1>(tpl)); }
328 return cCtr+pProtoCont.size();
345 for (
const auto *pClus : pClusCont ) {
347 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
351 cellWeights->
set(*fCell,fCell.weight());
356 for (
const auto *pClus : pClusCont ) {
360 for (
auto fCell(pClus->cell_begin()); fCell != pClus->cell_end(); ++fCell ) {
364 cellWeights->
set(*fCell,fCell.weight());
373 return cCtr+pProtoCont.size();
385 for (
const auto *
cptr : pCellCont ) {
386 if (
cptr ==
nullptr ) {
395 return pProtoCont.size();
403 for (
const auto *
cptr : pCellCont ) {
404 if (
cptr ==
nullptr ) {
414 return pProtoCont.size();
422 if (
cptr ==
nullptr ) {
return false; }
426 for (
auto elm : towerGeo->
getTowers(
cptr->caloDDE()->calo_hash()) ) {
430 uint_t cellIdx(pProtoCont.at(towerIdx).getCellLinks()->getCellContainer()->findIndex(
cptr->caloDDE()->calo_hash()));
431 pProtoCont[towerIdx].addCell(cellIdx,towerGeo->
cellWeight(elm)*weight); ++nctr;
448 return nTowers == 6400
461 int nrc(0);
int hid(0);
462 auto fcell(clk->
begin());
463 while ( fcell != clk->
end() ) {
467 if ( pCell ==
nullptr ) {
469 fcell.index(),nc-1,nclus,towerGeo->
towerEta(nclus),towerGeo->
towerPhi(nclus),
470 (
void*)pCell,(
void*)aCell,++nrc,clk->
size()) );
485 }
else if ( fcell.weight() <= 0.0000001 ) {
499{
return clnk.
size() > 0; }
509 if ( pCellCont ==
nullptr ) {
511 }
else if ( pCellCont->
empty() ) {
520 std::string algname(this->name());
521 if ( algname.find_last_of(
'.') != std::string::npos ) { algname = algname.substr(algname.find_last_of(
'.')+1); }
523 std::ofstream logstream; logstream.open(logname);
524 if ( !logstream.is_open() ) {
528 logstream <<
"##########################################################################\n";
529 logstream <<
"### This file contains a list of CaloCell indices in CaloCellContainer ###\n";
530 logstream <<
"### for which this index is not the same as the calorimeter cell hash ###\n";
531 logstream <<
"### identifier. An empty list indicates full consistency between this ###\n";
532 logstream <<
"### index and the hash identifier for all cells. ###\n";
533 logstream <<
"##########################################################################\n";
534 logstream <<
"<begin list>--------------------------------------------------------------\n";
542 auto chkflg = std::make_unique<std::bitset<200000> >();
544 for (
size_t i(0); i<pCellCont->
size(); ++i ) {
545 if ( pCellCont->
at(i) !=
nullptr ) {
548 std::string cni(
"UKNOWN");
549 double etai(0.);
double phii(0.);
551 if ( iel !=
nullptr ) {
556 std::string cnc(
"UNKNOWN");
557 double etac(0.);
double phic(0.);
559 if ( cel !=
nullptr ) {
564 size_t cidx(pCellCont->
findIndex(chash));
565 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",
566 ++ifc,i,cni.c_str(),etai,phii,chash,cnc.c_str(),etac,phic,cidx) <<
'\n';
571 logstream <<
"<end list>----------------------------------------------------------------\n";
584 for (
size_t i(0); i<chl.size(); ++i ) {
if ( !chkflg->test(i) ) { chl.push_back(i); } }
585 if ( !chl.empty() ) {
#define ATH_CHECK
Evaluate an expression and check for errors.
ElementConstPointer cptr() const
Return a pointer to the referenced element.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Definition of CaloDetDescrManager.
std::ostream & operator<<(std::ostream &s, const std::tuple< Tup... > &tup)
CaloPhiRange class declaration.
std::atomic< bool > CaloTopoTowerFromClusterMaker_checkCellIndices(false)
Wrapper to avoid constant divisions when using units.
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.
static std::string getSamplingName(CaloSample theSample)
Returns a string (name) for each CaloSampling.
static const double m_energyThresholdDef
Default energy threshold.
Gaudi::Property< double > m_energyThreshold
Cell energy threshold, default is set in m_energyThresholdDef.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
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.
Gaudi::Property< double > m_clusterRange
Range where topo-clusters are used when m_buildCombinedSignal = true.
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.
static const uint_t m_errorValueUINT
Error value for uint_t type values.
std::bitset< _CALOTOPOTOWERFROMCLUSTERMAKER_BITSET_SIZE > m_excludedSamplingsPattern
Bit pattern indicates if sampling is excluded.
Gaudi::Property< bool > m_useCellsFromClusters
Use cells from topo-clusters if true, else use all cells, default is true.
bool addCellToProtoCluster(const CaloTowerGeometry *towerGeo, const CaloCell *cptr, protocont_t &pProtoCont, double weight=1.) const
Adding cells to proto-clusters.
Gaudi::Property< bool > m_buildCombinedSignal
Build topo-clusters within given range, else topo-towers.
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.
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.
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.
Gaudi::Property< bool > m_applyCellEnergyThreshold
Apply cell energy threshold, default is false.
std::size_t uint_t
Unsigned integral type.
Gaudi::Property< bool > m_removeSamplingData
Remove sampling data for towers.
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.
Gaudi::Property< bool > m_doCellIndexCheck
Check cell hash index consistency if true (default false).
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.
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Topo-cluster container key.
Gaudi::Property< bool > m_orderByPt
Orders cluster container by , default true.
Gaudi::Property< bool > m_prepareLCW
Prepare LCW calibration, default is false.
Gaudi::Property< std::vector< std::string > > m_excludedSamplingsName
List of excluded samplings (human-readable names).
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.