ATLAS Offline Software
CaloTopoClusterTowerMerger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "StoreGate/ReadHandle.h"
7 
9 
12 
14 
15 #define CL_RHMSG( NAME ) MsgStream& operator<<(MsgStream& mstr,const SG::ReadHandleKey< NAME >& ckey ) { mstr << ckey.key(); return mstr; }
16 #define CL_WHMSG( NAME ) MsgStream& operator<<(MsgStream& mstr,const SG::WriteHandleKey< NAME >& ckey ) { mstr << ckey.key(); return mstr; }
17 
18 namespace {
20 }
21 
22 // std::vector<xAOD::CaloCluster::MomentType> CaloTopoClusterTowerMerger::m_momentList = std::vector< CL_MNAME( MomentType ) >();
23 // std::vector<std::tuple<xAOD::CaloCluster::MomentType,std::string> > CaloTopoClusterTowerMerger::m_momentMap {
24 // CL_ENTRY( FIRST_PHI ),
25 // CL_ENTRY( FIRST_ETA ),
26 // CL_ENTRY( SECOND_R ),
27 // CL_ENTRY( SECOND_LAMBDA ),
28 // CL_ENTRY( DELTA_PHI ),
29 // CL_ENTRY( DELTA_THETA ),
30 // CL_ENTRY( DELTA_ALPHA ),
31 // CL_ENTRY( CENTER_X ),
32 // CL_ENTRY( CENTER_Y ),
33 // CL_ENTRY( CENTER_Z ),
34 // CL_ENTRY( CENTER_MAG ),
35 // CL_ENTRY( CENTER_LAMBDA ),
36 // CL_ENTRY( LATERAL ),
37 // CL_ENTRY( LONGITUDINAL ),
38 // CL_ENTRY( ENG_FRAC_EM ),
39 // CL_ENTRY( ENG_FRAC_MAX ),
40 // CL_ENTRY( ENG_FRAC_CORE ),
41 // CL_ENTRY( FIRST_ENG_DENS ),
42 // CL_ENTRY( SECOND_ENG_DENS ),
43 // CL_ENTRY( ISOLATION ),
44 // CL_ENTRY( ENG_BAD_CELLS ),
45 // CL_ENTRY( N_BAD_CELLS ),
46 // CL_ENTRY( N_BAD_CELLS_CORR ),
47 // CL_ENTRY( BAD_CELLS_CORR_E ),
48 // CL_ENTRY( BADLARQ_FRAC ),
49 // CL_ENTRY( ENG_POS ),
50 // CL_ENTRY( SIGNIFICANCE ),
51 // CL_ENTRY( CELL_SIGNIFICANCE ),
52 // CL_ENTRY( CELL_SIG_SAMPLING ),
53 // CL_ENTRY( AVG_LAR_Q ),
54 // CL_ENTRY( AVG_TILE_Q ),
55 // CL_ENTRY( ENG_BAD_HV_CELLS ),
56 // CL_ENTRY( N_BAD_HV_CELLS ),
57 // CL_ENTRY( PTD ),
58 // CL_ENTRY( EM_PROBABILITY ),
59 // CL_ENTRY( HAD_WEIGHT ),
60 // CL_ENTRY( OOC_WEIGHT ),
61 // CL_ENTRY( DM_WEIGHT ),
62 // CL_ENTRY( TILE_CONFIDENCE_LEVEL ),
63 // CL_ENTRY( VERTEX_FRACTION ),
64 // CL_ENTRY( NVERTEX_FRACTION ),
65 // CL_ENTRY( ETACALOFRAME ),
66 // CL_ENTRY( PHICALOFRAME ),
67 // CL_ENTRY( ETA1CALOFRAME ),
68 // CL_ENTRY( PHI1CALOFRAME ),
69 // CL_ENTRY( ETA2CALOFRAME ),
70 // CL_ENTRY( PHI2CALOFRAME ),
71 // CL_ENTRY( ENG_CALIB_TOT ),
72 // CL_ENTRY( ENG_CALIB_OUT_L ),
73 // CL_ENTRY( ENG_CALIB_OUT_M ),
74 // CL_ENTRY( ENG_CALIB_OUT_T ),
75 // CL_ENTRY( ENG_CALIB_DEAD_L ),
76 // CL_ENTRY( ENG_CALIB_DEAD_M ),
77 // CL_ENTRY( ENG_CALIB_DEAD_T ),
78 // CL_ENTRY( ENG_CALIB_EMB0 ),
79 // CL_ENTRY( ENG_CALIB_EME0 ),
80 // CL_ENTRY( ENG_CALIB_TILEG3 ),
81 // CL_ENTRY( ENG_CALIB_DEAD_TOT ),
82 // CL_ENTRY( ENG_CALIB_DEAD_EMB0 ),
83 // CL_ENTRY( ENG_CALIB_DEAD_TILE0 ),
84 // CL_ENTRY( ENG_CALIB_DEAD_TILEG3 ),
85 // CL_ENTRY( ENG_CALIB_DEAD_EME0 ),
86 // CL_ENTRY( ENG_CALIB_DEAD_HEC0 ),
87 // CL_ENTRY( ENG_CALIB_DEAD_FCAL ),
88 // // CL_ENTRY( ENG_CALIB_DEAD_LEAKAG ), // not in r21
89 // // CL_ENTRY( ENG_CALIB_DEAD_UNCLAS ), // not in r21
90 // CL_ENTRY( ENG_CALIB_FRAC_EM ),
91 // CL_ENTRY( ENG_CALIB_FRAC_HAD ),
92 // CL_ENTRY( ENG_CALIB_FRAC_REST )
93 // };
94 
95 CaloTopoClusterTowerMerger::CaloTopoClusterTowerMerger(const std::string& name,ISvcLocator* pSvcLocator)
96  : AthReentrantAlgorithm(name,pSvcLocator)
97  , m_clusterContainerKey("CaloCalTopoCluster")
98  , m_towerContainerKey("CaloCalFwdTopoTower")
99  , m_topoSignalContainerKey("CaloCalTopoSignal")
100  , m_cellLinkContainerKey("")
101  , m_clusterRange(3.2)
102 {
103  declareProperty("TopoClusterContainerKey",m_clusterContainerKey, "Topo-cluster container key" );
104  declareProperty("TopoTowerContainerKey", m_towerContainerKey, "Topo-tower container key" );
105  declareProperty("TopoSignalContainerKey", m_topoSignalContainerKey,"Topo-signal container key" );
106  declareProperty("TopoSignalCellLinksKey", m_cellLinkContainerKey, "Topo-signal cell links key" );
107  declareProperty("TopoClusterRange", m_clusterRange, "Rapidity range for using topo-clusters in combined signal mode");
108 }
109 
111 = default;
112 
114 {
115  if ( m_clusterRange <= 0. ) {
116  ATH_MSG_ERROR( CaloRec::Helpers::fmtMsg("Invalid topo-cluster range |y| < %6.3f - algorithm non-functional",m_clusterRange) );
117  return StatusCode::FAILURE;
118  }
119 
120  if ( m_cellLinkContainerKey.key().empty() ) { m_cellLinkContainerKey = m_topoSignalContainerKey.key() + std::string("_links"); }
121  ATH_CHECK( m_clusterContainerKey.initialize() ); // topo-cluster input key
122  ATH_CHECK( m_towerContainerKey.initialize() ); // topo-tower input key
123  ATH_CHECK( m_topoSignalContainerKey.initialize() ); // topo-signal (topo-cluster+topo-tower) output key
124  ATH_CHECK( m_cellLinkContainerKey.initialize() ); // cell link container key (ESD only)
125 
126  ATH_MSG_INFO( CaloRec::Helpers::fmtMsg("Topo_cluster with |y| < %.2f will be merged with topo-towers with |y| > %.2f",m_clusterRange,m_clusterRange) );
127 
128  return StatusCode::SUCCESS;
129 }
130 
131 StatusCode CaloTopoClusterTowerMerger::execute(const EventContext& ctx) const
132 {
133 
134  // collect input
135  rhandle_t clusterHandle(m_clusterContainerKey,ctx);
136  if ( !clusterHandle.isValid() ) {
137  ATH_MSG_WARNING( "Topo-cluster container with key <" << m_clusterContainerKey << "> not found" );
138  return StatusCode::SUCCESS;
139  }
140  rhandle_t towerHandle(m_towerContainerKey,ctx);
141  if ( !towerHandle.isValid() ) {
142  ATH_MSG_WARNING( "Topo-tower container with key <" << m_towerContainerKey << "> not found" );
143  return StatusCode::SUCCESS;
144  }
145 
146  // prepare output
147  whandle_t signalHandle(m_topoSignalContainerKey,ctx);
148  ATH_CHECK(this->addContainerWriteHandle(signalHandle));
149 
150  // fill output from topo-clusters
151  for ( const auto *pClus : *clusterHandle ) { if ( clusterFilter(*pClus) ) { CaloTopoClusterTowerMerger::makeDeepCopy(*pClus,signalHandle.ptr()); } }
152  // fill output from topo-towers
153  for ( const auto *pTowr : *towerHandle ) { if ( towerFilter(*pTowr) ) { CaloTopoClusterTowerMerger::makeDeepCopy(*pTowr,signalHandle.ptr()); } }
154 
155  // finalize the clusters/towers
156  lhandle_t linkHandle(m_cellLinkContainerKey,ctx);
157  ATH_CHECK(CaloClusterStoreHelper::finalizeClusters (linkHandle,signalHandle.ptr()));
158 
159  return StatusCode::SUCCESS;
160 }
161 
162 bool
164  xAOD::CaloClusterContainer* pClusCont)
165 {
166  auto* copyClus = new xAOD::CaloCluster();
167  // pass ownership
168  pClusCont->push_back(copyClus);
169  // then assign to
170  (*copyClus) = rClus;
171  return true;
172 }
173 
175 { return CaloClusterStoreHelper::AddContainerWriteHandle(signalHandle); }
176 // // get a new signal handle
177 // signalHandle = std::unique_ptr<xAOD::CaloClusterContainer>(new xAOD::CaloClusterContainer());
178 // if ( !signalHandle.isValid() ) { return StatusCode::FAILURE; }
179 // // get AUX container
180 // xAOD::CaloClusterAuxContainer* auxData = new xAOD::CaloClusterAuxContainer();
181 // std::string auxName(m_topoSignalContainerKey.key()+"Aux.");
182 // if ( evtStore()->overwrite(auxData,auxName).isFailure() ) {
183 // ATH_MSG_ERROR("Failed to record xAOD::CaloClusterAuxContainer with key <" << auxName << ">");
184 // delete auxData;
185 // return StatusCode::FAILURE;
186 // }
187 // // connect store with object container
188 // signalHandle.ptr()->setStore(auxData);
189 // return StatusCode::SUCCESS;
190 // }
CaloTopoClusterTowerMerger::m_clusterContainerKey
rhandlekey_t m_clusterContainerKey
Input topo-cluster container.
Definition: CaloTopoClusterTowerMerger.h:54
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
CaloTopoClusterTowerMerger::initialize
virtual StatusCode initialize() override
Initialization sets up read and write handle keys.
Definition: CaloTopoClusterTowerMerger.cxx:113
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloClusterStoreHelper::AddContainerWriteHandle
static StatusCode AddContainerWriteHandle(SG::WriteHandle< xAOD::CaloClusterContainer > &clusColl)
Creates a new xAOD::CaloClusterContainer in the given WriteHandle + CaloClusterAuxContainer and recor...
Definition: CaloClusterStoreHelper.cxx:53
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloTopoClusterTowerMerger::addContainerWriteHandle
static StatusCode addContainerWriteHandle(whandle_t &signalHandle)
Add a write handle for a container (in CaloClusterStoreHelper from r21.9)
Definition: CaloTopoClusterTowerMerger.cxx:174
CaloRec::Helpers::fmtMsg
std::string fmtMsg(const char *fmt,...)
Definition: CaloTopoClusterFromTowerHelpers.cxx:13
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloClusterAuxContainer.h
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloTopoClusterTowerMerger::towerFilter
bool towerFilter(const xAOD::CaloCluster &rTowr) const
Filter topo-tower.
Definition: CaloTopoClusterTowerMerger.h:73
CaloTopoClusterTowerMerger.h
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloTopoClusterTowerMerger::m_cellLinkContainerKey
lhandlekey_t m_cellLinkContainerKey
Output cell links for merged container.
Definition: CaloTopoClusterTowerMerger.h:57
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CL_RHMSG
#define CL_RHMSG(NAME)
Definition: CaloTopoClusterTowerMerger.cxx:15
CaloTopoClusterTowerMerger::m_clusterRange
double m_clusterRange
Rapidity range for topo-clusters.
Definition: CaloTopoClusterTowerMerger.h:58
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CaloTopoClusterTowerMerger::clusterFilter
bool clusterFilter(const xAOD::CaloCluster &rClus) const
Filter topo-cluster.
Definition: CaloTopoClusterTowerMerger.h:72
CaloTopoClusterTowerMerger::CaloTopoClusterTowerMerger
CaloTopoClusterTowerMerger(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm constructor.
Definition: CaloTopoClusterTowerMerger.cxx:95
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloTopoClusterTowerMerger::execute
virtual StatusCode execute(const EventContext &ctx) const override
Execution merges the container contents.
Definition: CaloTopoClusterTowerMerger.cxx:131
CaloTopoClusterTowerMerger::makeDeepCopy
static bool makeDeepCopy(const xAOD::CaloCluster &rClus, xAOD::CaloClusterContainer *pClusCont)
Attaches a deep copy to container, returns true if successful.
Definition: CaloTopoClusterTowerMerger.cxx:163
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloTopoClusterFromTowerHelpers.h
CaloTopoClusterTowerMerger::~CaloTopoClusterTowerMerger
virtual ~CaloTopoClusterTowerMerger()
Baseclass destructor.
CaloTopoClusterTowerMerger::m_topoSignalContainerKey
whandlekey_t m_topoSignalContainerKey
Output merged container.
Definition: CaloTopoClusterTowerMerger.h:56
ReadHandle.h
Handle class for reading from StoreGate.
CaloTopoClusterTowerMerger::m_towerContainerKey
rhandlekey_t m_towerContainerKey
Input topo-tower container.
Definition: CaloTopoClusterTowerMerger.h:55