ATLAS Offline Software
Loading...
Searching...
No Matches
PFUnifiedSubtractionOnlyTruthTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "PFData.h"
7
8#include "eflowCaloObject.h"
12#include "eflowRecTrack.h"
15
19
20using namespace eflowSubtract;
21
23= default;
24
25
27{
28
29 ATH_CHECK(m_theEOverPTool.retrieve());
30
31 ATH_CHECK(m_theEOverPTool->fillBinnedParameters(m_binnedParameters.get()));
32
34 if (!m_trkpos)
35 {
36 ATH_MSG_ERROR("Failed to get TrackPositionProvider for cluster preselection!");
37 return StatusCode::FAILURE;
38 }
39
41
43
44
45 //Set the level of the helpers to the same as the tool here
46 m_pfSubtractionStatusSetter.msg().setLevel(this->msg().level());
47 m_pfSubtractionEnergyRatioCalculator.msg().setLevel(this->msg().level());
48 m_subtractor.m_facilitator.msg().setLevel(this->msg().level());
49
50
51 return StatusCode::SUCCESS;
52
53}
54
56 const EventContext& ctx,
57 PFData &data
58) const
59{
60 if (!data.caloObjects) {
61 ATH_MSG_ERROR("PFData::caloObjects is null; caller must set it before invoking the truth subtraction tool");
62 return StatusCode::FAILURE;
63 }
64
65 performSubtraction(ctx, data.nMatches, 0, data);
66 return StatusCode::SUCCESS;
67}
68
69
70void PFUnifiedSubtractionOnlyTruthTool::performSubtraction(const EventContext& ctx, const unsigned int& startingPoint, const unsigned int& nCaloObj, PFData &data ) const{
71
72 //starting point is defined in the base class API and used in other derived API.
73 //It is not used here, so we silence compiler warnings about it being unused
74 (void)startingPoint;
75
76 ATH_MSG_DEBUG("In performTruthSubtraction");
77
78 const double gaussianRadius = 0.032;
79 const double gaussianRadiusError = 1.0e-3;
80 const double maximumRadiusSigma = 3.0;
81
82 eflowLayerIntegrator integrator(gaussianRadius, gaussianRadiusError, maximumRadiusSigma, m_isHLLHC);
83
85 if (!m_recoverSplitShowers && 0 != nCaloObj) ATH_MSG_WARNING("Not in Split Showers Mode and already have " << nCaloObj << " eflowCaloObjects");
86
87 //For each eflowCaloObject we calculate the expected energy deposit in the calorimeter and cell ordering for subtraction.
88 for (unsigned int iCalo = nCaloObj; iCalo < data.caloObjects->size(); ++iCalo) {
89 eflowCaloObject* thisEflowCaloObject = data.caloObjects->at(iCalo);
90 thisEflowCaloObject->simulateShower(ctx, &integrator, m_binnedParameters.get(), m_useNNEnergy ? &(*m_NNEnergyPredictorTool) : nullptr, m_useLegacyEBinIndex);
91 m_theTruthShowerSimulator->simulateShower(*thisEflowCaloObject);
92
93 }
94
95 unsigned int nEFCaloObs = data.caloObjects->size();
96
97 for (unsigned int iCalo = 0; iCalo < nEFCaloObs; ++iCalo) {
98 eflowCaloObject* thisEflowCaloObject = data.caloObjects->at(iCalo);
99 this->performSubtraction(*thisEflowCaloObject);
100 }
101
102}
103
105
106 for (unsigned iTrack = 0; iTrack < thisEflowCaloObject.nTracks(); ++iTrack){
107 eflowRecTrack *thisEfRecTrack = thisEflowCaloObject.efRecTrack(iTrack);
108
109 //although we are subtracting the truth, to be consistent we only do it if a reco
110 //e/p lookup bin exists for this track
111 if (!thisEfRecTrack->hasBin()) continue;
112
113 //Similarly we skip tracks in a dense environment
114 if (thisEfRecTrack->isInDenseEnvironment()) continue;
115
116 thisEfRecTrack->setSubtracted();
117
118 //get the set of matched clusters
119 std::vector<eflowTrackClusterLink *> links = thisEfRecTrack->getClusterMatches();
120
121 for (auto thisLink : links){
122 xAOD::CaloCluster *thisCluster = thisLink->getCluster()->getCluster();
123 CaloClusterCellLink* theCellLinks = thisCluster->getOwnCellLinks();
124 CaloClusterCellLink::iterator theCell = theCellLinks->begin();
125 CaloClusterCellLink::iterator lastCell = theCellLinks->end();
126
127 //loop over the cells in this cluster and subtract shower using truth information
128 //We can either remove a cell entireley if it has any truth deposit (closer to what the real
129 //reco algorithm does) or reweight the cells contribution based on subtracting the truth
130 //energy from the reco cell energy
131 //We only advance the iterator, theCell, if we *dont* call removeCell to avoid issues with
132 //invalid iterators
133 //We also have to reset the lastCell iterator after each call to ensure the loop exits at the end,
134 //instead of being stuck in an infinite loop.
135 for (; theCell != lastCell;){
136 //get the truth energy for this cell
137 double truthEnergy = thisEfRecTrack->getCellTruthEnergy(*theCell);
138 //reweight the cell such that energy*weight gives the new energy
139 double oldCellEnergy = theCell->energy()*(theCell.weight());
140 double subtractedCellWeight = (oldCellEnergy - truthEnergy)/oldCellEnergy;
141
142 if (0.0 != truthEnergy && m_useFullCellTruthSubtraction) {
143 thisCluster->removeCell(*theCell);
144 lastCell = theCellLinks->end();
145 }
147 theCell.reweight(subtractedCellWeight);
148 ++theCell;
149 }
150 else ++theCell;
151
152 }//cell loop
153
154 float oldEnergy = thisCluster->e();
155 CaloClusterKineHelper::calculateKine(thisCluster, true, true);
156 if (0.0 != oldEnergy) {
157 float energyAdjustment = thisCluster->e() / oldEnergy;
158 thisCluster->setRawE(thisCluster->rawE() * energyAdjustment);
159 thisCluster->setRawEta(thisCluster->eta());
160 thisCluster->setRawPhi(thisCluster->phi());
161 }
162 }
163
164 }//eflowCaloObject track loop
165
166}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
double energy() const
get energy (data member)
Definition CaloCell.h:327
static void calculateKine(xAOD::CaloCluster *clu, const bool useweight=true, const bool updateLayers=true, const bool useGPUCriteria=false)
Helper class to calculate cluster kinematics based on cells.
static std::unique_ptr< IPositionProvider > Get(const std::string &positionType)
Gaudi::Property< bool > m_recoverSplitShowers
Toggle whether we are recovering split showers or not.
Gaudi::Property< bool > m_isHLLHC
Toggle whether we have the HLLHC setup.
Gaudi::Property< bool > m_useLegacyEBinIndex
Further discussion about why this flag exists can be found in https://its.cern.ch/jira/browse/ATLJETM...
std::unique_ptr< eflowEEtaBinnedParameters > m_binnedParameters
ToolHandle< IEFlowCellEOverPTool > m_theEOverPTool
Tool for getting e/p values and hadronic shower cell ordering principle parameters.
PFSubtractionStatusSetter m_pfSubtractionStatusSetter
ToolHandle< PFEnergyPredictorTool > m_NNEnergyPredictorTool
Tool for getting predictiing the energy using an ONNX model.
std::unique_ptr< PFMatch::TrackEtaPhiInFixedLayersProvider > m_trkpos
Track position provider to be used to preselect clusters.
PFSubtractionEnergyRatioCalculator m_pfSubtractionEnergyRatioCalculator
Gaudi::Property< bool > m_useNNEnergy
Toggle whether we use the neural net energy.
ToolHandle< PFSimulateTruthShowerTool > m_theTruthShowerSimulator
Gaudi::Property< bool > m_useFullCellTruthSubtraction
Toggle whether we fully remove a cell with a truth deposit or reweight it based on truth contribution...
virtual StatusCode processPFlowData(const EventContext &ctx, PFData &thePFData) const override
void performSubtraction(const EventContext &ctx, const unsigned int &startingPoint, const unsigned int &nCaloObj, PFData &data) const override
An internal EDM object which stores information about systems of associated tracks and calorimeter cl...
void simulateShower(const EventContext &ctx, eflowLayerIntegrator *integrator, const eflowEEtaBinnedParameters *binnedParameters, const PFEnergyPredictorTool *energyP, bool useLegacyEnergyBinIndexing)
const eflowRecTrack * efRecTrack(int i) const
unsigned nTracks() const
This class calculates the LHED (Layer of Highest Energy Density) in a cluster or group of clusters.
This class extends the information about a xAOD::Track.
const std::vector< eflowTrackClusterLink * > & getClusterMatches() const
bool hasBin() const
double getCellTruthEnergy(const CaloCell *cell) const
bool isInDenseEnvironment() const
void setRawEta(flt_t)
Set for signal state UNCALIBRATED.
flt_t rawE() const
void setRawPhi(flt_t)
Set for signal state UNCALIBRATED.
void setRawE(flt_t)
Set Energy for signal state UNCALIBRATED.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
virtual double phi() const
The azimuthal angle ( ) of the particle.
CaloClusterCellLink * getOwnCellLinks()
Get a pointer to the owned CaloClusterCellLink object (non-const version).
bool removeCell(const CaloCell *ptr)
Method to remove a cell to the cluster (slow!) (Beware: Kinematics not updated!).
static std::string release
Definition computils.h:50
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
MsgStream & msg
Definition testRead.cxx:32