ATLAS Offline Software
PFClusterSelectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
8 #include <exception>
9 
10 PFClusterSelectorTool::PFClusterSelectorTool(const std::string& type,const std::string& name,const IInterface* parent):
11  base_class(type, name, parent)
12 {
13 }
14 
16 
18  if(!m_caloCalClustersReadHandleKey.key().empty()) {
20  }
21 
24  }
25 
27 
28  return StatusCode::SUCCESS;
29 }
30 
33  eflowRecClusterContainer& theEFlowRecClusterContainer,
34  xAOD::CaloClusterContainer& theCaloClusterContainer) const
35 {
36 
38 
39  /* Verify the read handle has a valid pointer, and if not return */
40  if (!caloClustersReadHandle.isValid()){
41  ATH_MSG_WARNING(" Invalid ReadHandle for xAOD::CaloCluster with key: " << caloClustersReadHandle.key());
42  return StatusCode::SUCCESS;
43  }
44 
45  const xAOD::CaloClusterContainer* calclusters = nullptr;
46  if (!m_caloCalClustersReadHandleKey.key().empty()) {
48  calclusters = caloCalClustersReadHandle.get();
49  }
50 
52  ATH_CHECK(caloMgrHandle.isValid());
53 
54  /* Fill the vector of eflowRecClusters */
55  unsigned int nClusters = caloClustersReadHandle->size();
56  for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) {
57  /* Create the eflowRecCluster and put it in the container */
58  std::unique_ptr<eflowRecCluster> thisEFRecCluster = std::make_unique<eflowRecCluster>(ElementLink<xAOD::CaloClusterContainer>(*caloClustersReadHandle, iCluster), theCaloClusterContainer);
59 
60  if (calclusters){
61  std::map<IdentifierHash,double> cellsWeightMap;
62  retrieveLCCalCellWeight(caloClustersReadHandle->at(iCluster)->e(), iCluster, cellsWeightMap, *calclusters,**caloMgrHandle);
63 
64  thisEFRecCluster->setCellsWeight(std::move(cellsWeightMap));
65  }
66 
68 
69  std::string decorHandleName = m_caloClusterReadDecorHandleKeyNLeadingTruthParticles.key();
70  std::string::size_type pos = decorHandleName.find(".");
71  std::string decorName = decorHandleName.substr(pos+1);
72 
74  accessor(*theCaloClusterContainer[iCluster]) = accessor(*caloClustersReadHandle->at(iCluster));
75  }
76 
77  thisEFRecCluster->setClusterId(iCluster);
78  theEFlowRecClusterContainer.push_back(std::move(thisEFRecCluster));
79  }
80 
81  return StatusCode::SUCCESS;
82 }
83 
85  return StatusCode::SUCCESS;
86 }
87 
88 void
90  const double& energy,
91  const unsigned& index,
92  std::map<IdentifierHash, double>& cellsWeight,
93  const xAOD::CaloClusterContainer& caloCalClustersContainer,
94  const CaloDetDescrManager& calo_dd_man) const
95 {
96  /* match CaloCluster with CaloCalCluster to obtain cell weight */
97  /* first try the position at 'index'. If we are lucky, the loop can be
98  * avoided. */
99  /* Note the read handle has been tested to be valid prior to the call of this
100  * function */
101  const xAOD::CaloCluster* matchedCalCluster = caloCalClustersContainer.at(index);
102  if (matchedCalCluster){
103  if (!(fabs(energy - matchedCalCluster->rawE()) < 0.001)) {
104  matchedCalCluster = nullptr;
105  for (const auto *iCalCalCluster : caloCalClustersContainer) {
106  matchedCalCluster = iCalCalCluster;
107  if (fabs(energy - matchedCalCluster->rawE()) < 0.001) {
108  break;
109  }
110  }
111  if (!matchedCalCluster) ATH_MSG_WARNING("Invalid pointer to matched cluster - failed to find cluster match");
112  }
113  if (not matchedCalCluster){
114  throw std::runtime_error("matchedCluster is a null pointer in PFClusterSelectorTool::retrieveLCCalCellWeight");
115  }
116  /* obtain cell index and cell weight */
117  const CaloCell_ID* calo_id = calo_dd_man.getCaloCell_ID();
118  xAOD::CaloCluster::const_cell_iterator itCell = matchedCalCluster->cell_begin();
119  xAOD::CaloCluster::const_cell_iterator endCell = matchedCalCluster->cell_end();
120  for (; itCell != endCell; ++itCell) {
121  const CaloCell* pCell = *itCell;
122  Identifier myId = pCell->ID();
123  IdentifierHash myHashId = calo_id->calo_cell_hash(myId);
124  cellsWeight[myHashId] = itCell.weight();
125  }
126  } else ATH_MSG_WARNING("Invalid pointer to matched cluster - could not look up local hadron cell weights");
127 }
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
PFClusterSelectorTool::m_caloClustersReadHandleKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClustersReadHandleKey
ReadHandleKey for the CaloClusterContainer to be used as input.
Definition: PFClusterSelectorTool.h:41
CaloCell_Base_ID::calo_cell_hash
IdentifierHash calo_cell_hash(const Identifier cellId) const
create hash id from 'global' cell id
PFClusterSelectorTool::finalize
StatusCode finalize()
Definition: PFClusterSelectorTool.cxx:84
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
eflowRecClusterContainer
Definition: eflowRecCluster.h:275
PFClusterSelectorTool::initialize
StatusCode initialize()
Gaudi AthAlgorithm hooks.
Definition: PFClusterSelectorTool.cxx:15
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
PFClusterSelectorTool::execute
StatusCode execute(eflowRecClusterContainer &theEFlowRecClusterContainer, xAOD::CaloClusterContainer &theCaloClusterContainer) const
Definition: PFClusterSelectorTool.cxx:32
CaloCell_ID.h
PFClusterSelectorTool.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloCluster.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
eflowRecCluster::setCellsWeight
void setCellsWeight(std::map< IdentifierHash, double > &&cellsWeight)
Definition: eflowRecCluster.h:81
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PFClusterSelectorTool::PFClusterSelectorTool
PFClusterSelectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Default constructor.
Definition: PFClusterSelectorTool.cxx:10
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
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
eflowRecCluster.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
PFClusterSelectorTool::retrieveLCCalCellWeight
void retrieveLCCalCellWeight(const double &energy, const unsigned &index, std::map< IdentifierHash, double > &cellsWeight, const xAOD::CaloClusterContainer &caloCalClustersContainer, const CaloDetDescrManager &calo_dd_man) const
for EM mode, LC weight for cells are retrieved before doing any subtraction; they will be used after ...
Definition: PFClusterSelectorTool.cxx:89
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCell::ID
Identifier ID() const
get ID (from cached data member) non-virtual and inline for fast access
Definition: CaloCell.h:279
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CaloDetDescrManager::getCaloCell_ID
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
Definition: CaloDetDescrManager.cxx:1590
PFClusterSelectorTool::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
ReadCondHandleKey for CaloDetDescrManager.
Definition: PFClusterSelectorTool.h:62
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
PFClusterSelectorTool::m_caloClusterReadDecorHandleKeyNLeadingTruthParticles
SG::ReadDecorHandleKey< xAOD::CaloClusterContainer > m_caloClusterReadDecorHandleKeyNLeadingTruthParticles
Read handle key to decorate CaloCluster with threeN leading truth particle barcode and energy.
Definition: PFClusterSelectorTool.h:59
PFClusterSelectorTool::m_caloCalClustersReadHandleKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloCalClustersReadHandleKey
ReadHandleKey for the CaloClusterContainer, at LC scale, to be used as input.
Definition: PFClusterSelectorTool.h:50
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
eflowRecCluster::setClusterId
void setClusterId(int clusterId)
Definition: eflowRecCluster.h:80
Identifier
Definition: IdentifierFieldParser.cxx:14