ATLAS Offline Software
PFlowCellCPDataDecoratorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 
10 #include <vector>
11 #include <utility> //for std::pair
12 
13 //initialize
15  ATH_MSG_DEBUG("Initializing " << name() << "...");
16 
19 
20  return StatusCode::SUCCESS;
21 }
22 
23 //execute
25  ATH_MSG_DEBUG("Executing " << name() << "...");
26 
28 
30 
31  for (auto thisFlowElement : *cellListWriteDecorHandle){
32 
33  std::vector<std::pair<const xAOD::IParticle*,float> > theOtherPairs_charged = thisFlowElement->otherObjectsAndWeights();
34  //list of CaloCell that we will decorate the charged FE object with
35  std::vector<ElementLink<CaloCellContainer> > cellsToDecorate;
36 
37  for (const auto & [theCluster_charged, weight] : theOtherPairs_charged){
38 
39 
40  for (auto thisNeutralFE : *neutralPFOReadHandle){
41  std::vector<std::pair<const xAOD::IParticle*,float> > theOtherPairs_neutral = thisNeutralFE->otherObjectsAndWeights();
42  if (1 != theOtherPairs_neutral.size()) ATH_MSG_WARNING("Expected neutral FE to have only 1 topocluster link");
43 
44  const xAOD::IParticle* theCluster_neutral = theOtherPairs_neutral.at(0).first;
45 
46  if (theCluster_charged == theCluster_neutral){
47  //get the list of calorimeter cells in the charged cluster
48  const xAOD::CaloCluster* chargedCluster = dynamic_cast<const xAOD::CaloCluster*>(theCluster_charged);
49  if (not chargedCluster){
50  ATH_MSG_WARNING("dynamic_cast to (charged) CaloCluster failed in execute");
51  continue;
52  }
53  const CaloClusterCellLink* chargedClusterCellLinks = chargedCluster->getCellLinks();
54  CaloClusterCellLink::const_iterator chargedClusterCellLinksItr = chargedClusterCellLinks->begin();
55 
56  //get the list of calorimeter cells in the neutral cluster
57  const xAOD::CaloCluster* neutralCluster = dynamic_cast<const xAOD::CaloCluster*>(theCluster_neutral);
58  if (not neutralCluster){
59  ATH_MSG_WARNING("dynamic_cast to (neutral) CaloCluster failed in execute");
60  continue;
61  }
62  const CaloClusterCellLink* neutralClusterCellLinks = neutralCluster->getCellLinks();
63 
64  //loop over the cells in the charged cluster
65  for ( ; chargedClusterCellLinksItr != chargedClusterCellLinks->end(); ++chargedClusterCellLinksItr ) {
66  //get the cell
67  const CaloCell* chargedCell = *chargedClusterCellLinksItr;
68 
69  //loop over the cells in the neutral cluster
70  //flag whether the charged cell is in the neutral cluster
71  bool cellInNeutralCluster = false;
72  for (auto neutralCell : *neutralClusterCellLinks){
73 
74  //if the cells are the same, set the flag to true
75  if (chargedCell == neutralCell) cellInNeutralCluster = true;
76 
77  }//loop over the cells in the neutral cluster
78 
79  //if the cell is not in the neutral cluster, store the cell in the list of cells to decorate the neutral FE object with
80  if (!cellInNeutralCluster) cellsToDecorate.push_back(ElementLink<CaloCellContainer>("AllCalo", chargedClusterCellLinksItr.index()));
81 
82  }//loop over the cells in the neutral cluster
83  }//if the clusters are the same
84  }//loop over the neutral FE objects
85  }//loop over the topoclusters linked to the charged FE objects
86 
87  cellListWriteDecorHandle(*thisFlowElement) = cellsToDecorate;
88 
89  }//loop over the charged FE objects
90 
91  return StatusCode::SUCCESS;
92 
93 }
94 
95 //finalize
97  ATH_MSG_DEBUG("Finalizing " << name() << "...");
98 
99  return StatusCode::SUCCESS;
100 }
PFlowCellCPDataDecoratorAlgorithm::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PFlowCellCPDataDecoratorAlgorithm.cxx:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
PFlowCellCPDataDecoratorAlgorithm::m_cellListWriteDecorHandleKey
SG::WriteDecorHandleKey< xAOD::FlowElementContainer > m_cellListWriteDecorHandleKey
Write handle key to decorate PFO with threeN leading truth particle barcode and energy.
Definition: PFlowCellCPDataDecoratorAlgorithm.h:37
PFlowCellCPDataDecoratorAlgorithm::finalize
virtual StatusCode finalize() override
Definition: PFlowCellCPDataDecoratorAlgorithm.cxx:96
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
PFlowCellCPDataDecoratorAlgorithm::initialize
virtual StatusCode initialize() override
Definition: PFlowCellCPDataDecoratorAlgorithm.cxx:14
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloCluster.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloCellContainer.h
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PFlowCellCPDataDecoratorAlgorithm::m_neutralPFOReadHandleKey
SG::ReadHandleKey< xAOD::FlowElementContainer > m_neutralPFOReadHandleKey
Read handle key to read in the neutral particle flow objects.
Definition: PFlowCellCPDataDecoratorAlgorithm.h:41
PFlowCellCPDataDecoratorAlgorithm.h