Skip to content
Snippets Groups Projects

Make CaloClusterizationTool const

Merged Carla Marin Benito requested to merge caloreco_caloclusterizationtool into master
Files
6
@@ -12,7 +12,6 @@
@@ -12,7 +12,6 @@
// ============================================================================
// ============================================================================
#include "CaloUtils/ClusterFunctors.h"
#include "CaloUtils/ClusterFunctors.h"
#include "CaloUtils/CaloNeighbours.h"
#include "CaloUtils/CaloNeighbours.h"
#include "CaloInterfaces/ICounterLevel.h"
// local
// local
#include "CaloClusterizationTool.h"
#include "CaloClusterizationTool.h"
#include "TaggedCellFunctor.h"
#include "TaggedCellFunctor.h"
@@ -34,7 +33,7 @@ DECLARE_COMPONENT( CaloClusterizationTool )
@@ -34,7 +33,7 @@ DECLARE_COMPONENT( CaloClusterizationTool )
inline bool CaloClusterizationTool::isLocMax
inline bool CaloClusterizationTool::isLocMax
( const LHCb::CaloDigit* digit ,
( const LHCb::CaloDigit* digit ,
const CaloClusterizationTool::DirVector& hits ,
const CaloClusterizationTool::DirVector& hits ,
const DeCalorimeter* det )
const DeCalorimeter* det ) const
{
{
const CaloNeighbors& ns = det->neighborCells( digit -> cellID() ) ;
const CaloNeighbors& ns = det->neighborCells( digit -> cellID() ) ;
@@ -72,7 +71,8 @@ inline void
@@ -72,7 +71,8 @@ inline void
CaloClusterizationTool::appliRulesTagger
CaloClusterizationTool::appliRulesTagger
( CelAutoTaggedCell* cell ,
( CelAutoTaggedCell* cell ,
CaloClusterizationTool::DirVector& hits ,
CaloClusterizationTool::DirVector& hits ,
const DeCalorimeter* det )
const DeCalorimeter* det ,
 
const bool releaseBool) const
{
{
// Find in the neighbors cells tagged before, the clustered neighbors cells
// Find in the neighbors cells tagged before, the clustered neighbors cells
@@ -84,7 +84,7 @@ CaloClusterizationTool::appliRulesTagger
@@ -84,7 +84,7 @@ CaloClusterizationTool::appliRulesTagger
const CelAutoTaggedCell* nei = hits[ *iN ] ;
const CelAutoTaggedCell* nei = hits[ *iN ] ;
if ( 0 == nei ) { continue ; }
if ( 0 == nei ) { continue ; }
//
//
if( nei->isEdge() && m_release ){
if( nei->isEdge() && releaseBool ){
hasEdgeNeighbor = true;
hasEdgeNeighbor = true;
for( std::vector<LHCb::CaloCellID>::const_iterator id = nei->seeds().begin();id != nei->seeds().end();id++){
for( std::vector<LHCb::CaloCellID>::const_iterator id = nei->seeds().begin();id != nei->seeds().end();id++){
if( !cell->isWithSeed( *id ) )cell->addSeed( *id );
if( !cell->isWithSeed( *id ) )cell->addSeed( *id );
@@ -97,14 +97,14 @@ CaloClusterizationTool::appliRulesTagger
@@ -97,14 +97,14 @@ CaloClusterizationTool::appliRulesTagger
if ( cell->isWithSeed( seed ) ) { continue ; }
if ( cell->isWithSeed( seed ) ) { continue ; }
cell->addSeed ( seed ) ;
cell->addSeed ( seed ) ;
}
}
// Tag or or not the cell
// Tag or or not the cell
switch ( cell -> numberSeeds() ) {
switch ( cell -> numberSeeds() ) {
case 0:
case 0:
if( !m_release)break;
if( !releaseBool)break;
if( hasEdgeNeighbor && !hasClusteredNeighbor)cell->setEdge(); //
if( hasEdgeNeighbor && !hasClusteredNeighbor)cell->setEdge(); //
break;
break;
case 1:
case 1:
cell->setClustered();
cell->setClustered();
@@ -116,7 +116,8 @@ CaloClusterizationTool::appliRulesTagger
@@ -116,7 +116,8 @@ CaloClusterizationTool::appliRulesTagger
}
}
// ============================================================================
// ============================================================================
inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* cluster, const DeCalorimeter* detector ){
inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* cluster, const DeCalorimeter* detector ) const
 
{
///
///
double E, X, Y;
double E, X, Y;
///
///
@@ -125,7 +126,7 @@ inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* clus
@@ -125,7 +126,7 @@ inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* clus
cluster->entries().end () ,
cluster->entries().end () ,
detector , E , X , Y );
detector , E , X , Y );
///
///
if(counterStat->isVerbose())counter("Cluster energy") += E;
m_clusterEnergy += E;
if( sc.isSuccess() ){
if( sc.isSuccess() ){
cluster->position().parameters()( LHCb::CaloPosition::E ) = E ;
cluster->position().parameters()( LHCb::CaloPosition::E ) = E ;
cluster->position().parameters()( LHCb::CaloPosition::X ) = X ;
cluster->position().parameters()( LHCb::CaloPosition::X ) = X ;
@@ -137,22 +138,6 @@ inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* clus
@@ -137,22 +138,6 @@ inline StatusCode CaloClusterizationTool::setEXYCluster( LHCb::CaloCluster* clus
return sc;
return sc;
}
}
// ============================================================================
// ============================================================================
// Standard constructor, initializes variables
// ============================================================================
CaloClusterizationTool::CaloClusterizationTool( const std::string& type,
const std::string& name,
const IInterface* parent )
: base_class ( type, name , parent )
{
declareInterface<ICaloClusterization>(this);
// eTcut
declareProperty ( "withET" , m_withET ) ;
declareProperty ( "ETcut" , m_ETcut ) ;
declareProperty ( "CellSelectorForEnergy" , m_usedE = "3x3");
declareProperty ( "CellSelectorForPosition" , m_usedP = "3x3");
declareProperty ( "MaxIteration" , m_passMax = 10);
}
// ============================================================================
// initialization
// initialization
// ============================================================================
// ============================================================================
StatusCode CaloClusterizationTool::initialize()
StatusCode CaloClusterizationTool::initialize()
@@ -161,23 +146,29 @@ StatusCode CaloClusterizationTool::initialize()
@@ -161,23 +146,29 @@ StatusCode CaloClusterizationTool::initialize()
if( sc.isFailure() )
if( sc.isFailure() )
{ return Error("Could not initialize base class CaloAlgorithm",sc);}
{ return Error("Could not initialize base class CaloAlgorithm",sc);}
counterStat = tool<ICounterLevel>("CounterLevel");
return StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
}
template <class TYPE>
template <class TYPE>
StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>& clusters ,
unsigned int CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>& clusters ,
const TYPE& hits,
const TYPE& hits,
const DeCalorimeter* m_detector ,
const DeCalorimeter* m_detector ,
const std::vector<LHCb::CaloCellID>& _cell_list ,
const std::vector<LHCb::CaloCellID>& _cell_list ,
const unsigned int m_neig_level ){
const unsigned int m_neig_level ) const
 
{
//
//
m_cellSelectorE.setSelector(m_usedE);
m_cellSelectorP.setSelector(m_usedP);
// cmb: this needs to be done every time in order
m_cellSelectorE.setDet(m_detector);
// to allow different detectors in the same algorithm
m_cellSelectorP.setDet(m_detector);
// --> to be revisited in a future round
m_release = false;
CellSelector cellSelectorE;
 
CellSelector cellSelectorP;
 
cellSelectorE.setSelector(m_usedE);
 
cellSelectorP.setSelector(m_usedP);
 
cellSelectorE.setDet(m_detector);
 
cellSelectorP.setDet(m_detector);
 
bool releaseBool = false;
bool useData = false;
bool useData = false;
//
//
LHCb::CaloCellID::Set out_cells;
LHCb::CaloCellID::Set out_cells;
@@ -189,7 +180,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -189,7 +180,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
_cell_list.empty() && level > 0 -> All local maxima + neighborhood(level)
_cell_list.empty() && level > 0 -> All local maxima + neighborhood(level)
_cell_list.empty() && level = 0 -> All data (default)
_cell_list.empty() && level = 0 -> All data (default)
!_cell_list.empty() && level > 0 -> seed lis + neighborhood(level)
!_cell_list.empty() && level > 0 -> seed lis + neighborhood(level)
!_cell_list.empty() && level = 0 -> seed list
!_cell_list.empty() && level = 0 -> seed list
*/
*/
@@ -310,12 +301,12 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -310,12 +301,12 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
SeqVector::iterator itTagLastClustered = itTagLastSeed ;
SeqVector::iterator itTagLastClustered = itTagLastSeed ;
SeqVector::iterator itTagFirst = itTagLastClustered ;
SeqVector::iterator itTagFirst = itTagLastClustered ;
m_pass = 0;
unsigned int nPass = 0;
while ( itTagLastClustered != taggedCellsSeq.end() ) {
while ( itTagLastClustered != taggedCellsSeq.end() ) {
// Apply rules tagger for all not tagged cells
// Apply rules tagger for all not tagged cells
for ( SeqVector::iterator itTag = itTagLastClustered ; taggedCellsSeq.end() != itTag ; ++itTag ){
for ( SeqVector::iterator itTag = itTagLastClustered ; taggedCellsSeq.end() != itTag ; ++itTag ){
appliRulesTagger( (*itTag), taggedCellsDirect , m_detector );
appliRulesTagger( (*itTag), taggedCellsDirect , m_detector, releaseBool );
}
}
// Valid result
// Valid result
@@ -326,7 +317,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -326,7 +317,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
TaggedCellFunctor::isClusteredOrEdge() );
TaggedCellFunctor::isClusteredOrEdge() );
// Test if cells are tagged in this pass
// Test if cells are tagged in this pass
if ( itTagLastClustered == itTagFirst && m_release ){
if ( itTagLastClustered == itTagFirst && releaseBool ){
const long number = taggedCellsSeq.end() - itTagLastClustered ;
const long number = taggedCellsSeq.end() - itTagLastClustered ;
if( UNLIKELY( msgLevel(MSG::DEBUG) ) )
if( UNLIKELY( msgLevel(MSG::DEBUG) ) )
debug() << " TAGGING NOT FULL - Remain "
debug() << " TAGGING NOT FULL - Remain "
@@ -334,16 +325,16 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -334,16 +325,16 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
<< " not clustered cells" << endmsg ;
<< " not clustered cells" << endmsg ;
itTagLastClustered = taggedCellsSeq.end();
itTagLastClustered = taggedCellsSeq.end();
}
}
if( itTagLastClustered == itTagFirst )m_release = true; // try additional passes releasing appliRulesTagger criteria
if( itTagLastClustered == itTagFirst )releaseBool = true; // try additional passes releasing appliRulesTagger criteria
m_pass++;
nPass++;
itTagFirst = itTagLastClustered;
itTagFirst = itTagLastClustered;
if( m_passMax > 0 && m_pass >= m_passMax)break;
if( m_passMax > 0 && nPass >= m_passMax)break;
}
}
LHCb::CaloDigitStatus::Status usedForE = LHCb::CaloDigitStatus::UseForEnergy | LHCb::CaloDigitStatus::UseForCovariance ;
LHCb::CaloDigitStatus::Status usedForE = LHCb::CaloDigitStatus::UseForEnergy | LHCb::CaloDigitStatus::UseForCovariance ;
LHCb::CaloDigitStatus::Status usedForP = LHCb::CaloDigitStatus::UseForPosition | LHCb::CaloDigitStatus::UseForCovariance ;
LHCb::CaloDigitStatus::Status usedForP = LHCb::CaloDigitStatus::UseForPosition | LHCb::CaloDigitStatus::UseForCovariance ;
LHCb::CaloDigitStatus::Status seed = LHCb::CaloDigitStatus::SeedCell |LHCb::CaloDigitStatus::LocalMaximum | usedForP | usedForE;
LHCb::CaloDigitStatus::Status seed = LHCb::CaloDigitStatus::SeedCell |LHCb::CaloDigitStatus::LocalMaximum | usedForP | usedForE;
@@ -359,42 +350,45 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -359,42 +350,45 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
if( digit->e() <= 0 ) {
if( digit->e() <= 0 ) {
itTagSeed++;
itTagSeed++;
if(counterStat->isQuiet())counter("Negative seed energy") += digit->e();
m_negativeSeed += digit->e();
continue; // does not keep cluster with seed.energy <= 0
continue; // does not keep cluster with seed.energy <= 0
}
}
LHCb::CaloCellID seedID = (*itTagSeed)->cellID();
LHCb::CaloCellID seedID = (*itTagSeed)->cellID();
 
// Do partitions first
 
itTagClustered2 = std::stable_partition( itTagClustered1 ,
 
itTagLastClustered ,
 
TaggedCellFunctor::isWithSeed(seedID) ) ;
 
auto itTagFirstEdge = itTagLastClustered ;
 
auto itTagLastEdge = std::stable_partition( itTagLastClustered ,
 
taggedCellsSeq.end() ,
 
TaggedCellFunctor::isWithSeed (seedID) ) ;
 
 
// Create cluster, reserve, fill
auto cluster = std::make_unique<LHCb::CaloCluster>();
auto cluster = std::make_unique<LHCb::CaloCluster>();
 
cluster->entries().reserve(1 + (itTagClustered2 - itTagClustered1) + (itTagLastEdge - itTagFirstEdge) );
// set seed
// set seed
cluster->entries().push_back( LHCb::CaloClusterEntry( digit , seed ) );
cluster->entries().emplace_back( digit , seed );
cluster->setSeed( digit->cellID() );
cluster->setSeed( digit->cellID() );
itTagClustered2 = std::stable_partition( itTagClustered1 ,
itTagLastClustered ,
TaggedCellFunctor::isWithSeed(seedID) ) ;
// Owned cells
// Owned cells
for ( ; itTagClustered1 != itTagClustered2 ; ++itTagClustered1 ){
for ( ; itTagClustered1 != itTagClustered2 ; ++itTagClustered1 ){
LHCb::CaloCellID cellID = (*itTagClustered1)->cellID();
LHCb::CaloCellID cellID = (*itTagClustered1)->cellID();
const LHCb::CaloDigit* digit = (*itTagClustered1)->digit() ;
const LHCb::CaloDigit* digit = (*itTagClustered1)->digit() ;
LHCb::CaloDigitStatus::Status owned = LHCb::CaloDigitStatus::OwnedCell ;
LHCb::CaloDigitStatus::Status owned = LHCb::CaloDigitStatus::OwnedCell ;
if( m_cellSelectorE( seedID, cellID) > 0.)owned |= usedForE;
if( cellSelectorE( seedID, cellID) > 0.)owned |= usedForE;
if( m_cellSelectorP( seedID, cellID) > 0.)owned |= usedForP;
if( cellSelectorP( seedID, cellID) > 0.)owned |= usedForP;
cluster->entries().push_back( LHCb::CaloClusterEntry( digit , owned ) );
cluster->entries().emplace_back( digit , owned );
}
}
// Shared cells
// Shared cells
auto itTagFirstEdge = itTagLastClustered ;
auto itTagLastEdge = std::stable_partition( itTagLastClustered ,
taggedCellsSeq.end() ,
TaggedCellFunctor::isWithSeed (seedID) ) ;
for( ; itTagFirstEdge != itTagLastEdge ; ++itTagFirstEdge ){
for( ; itTagFirstEdge != itTagLastEdge ; ++itTagFirstEdge ){
const LHCb::CaloDigit* digit = (*itTagFirstEdge)->digit() ;
const LHCb::CaloDigit* digit = (*itTagFirstEdge)->digit() ;
LHCb::CaloCellID cellID = (*itTagFirstEdge)->cellID();
LHCb::CaloCellID cellID = (*itTagFirstEdge)->cellID();
LHCb::CaloDigitStatus::Status shared = LHCb::CaloDigitStatus::SharedCell;
LHCb::CaloDigitStatus::Status shared = LHCb::CaloDigitStatus::SharedCell;
if( m_cellSelectorE( seedID, cellID) > 0.)shared |= usedForE;
if( cellSelectorE( seedID, cellID) > 0.)shared |= usedForE;
if( m_cellSelectorP( seedID, cellID) > 0.)shared |= usedForP;
if( cellSelectorP( seedID, cellID) > 0.)shared |= usedForP;
cluster->entries().push_back( LHCb::CaloClusterEntry( digit , shared ) );
cluster->entries().emplace_back( digit , shared );
};
};
if( setEXYCluster ( cluster.get(), m_detector ).isSuccess() ){
if( setEXYCluster ( cluster.get(), m_detector ).isSuccess() ){
@@ -402,7 +396,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -402,7 +396,7 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
cluster->position().setZ( zPosition( cluster.get() ) );
cluster->position().setZ( zPosition( cluster.get() ) );
// put cluster to the output
// put cluster to the output
clusters.push_back( cluster.release() );
clusters.push_back( cluster.release() );
if(counterStat->isVerbose())counter("Cluster size")+= clusters.back()->entries().size();
m_clusterEnergy += clusters.back()->entries().size();
}
}
itTagClustered1 = itTagClustered2;
itTagClustered1 = itTagClustered2;
itTagSeed++;
itTagSeed++;
@@ -418,5 +412,5 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
@@ -418,5 +412,5 @@ StatusCode CaloClusterizationTool::_clusterize( std::vector<LHCb::CaloCluster*>&
return StatusCode::SUCCESS;
return nPass;
}
}
Loading