ATLAS Offline Software
Loading...
Searching...
No Matches
MHTPufitFex.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4/******************************************************************************
5 * @package Trigger/TrigAlgorithms/TrigEFMissingET
6 * @file MHTPufitFex.cxx
7 *
8 * Implementation of mhtpufit fex class
9 * @author Jon Burr
10 *****************************************************************************/
11
12#include "MHTPufitFex.h"
20
21namespace
22{
23 const static SG::AuxElement::ConstAccessor<float> accArea("ActiveArea4vec_pt");
24 const static SG::AuxElement::ConstAccessor<float> accDetectorEta("DetectorEta");
25} // namespace
26
27namespace HLT
28{
29 namespace MET
30 {
31 double MHTPufitFex::getSigma(const SignedKinematics &kin) const
32 {
34 }
35
36 MHTPufitFex::MHTPufitFex(const std::string &name, ISvcLocator *pSvcLocator)
37 : FexBase(name, pSvcLocator)
38 {
39 }
40
42 {
43 CHECK(m_inputJetsKey.initialize());
44 if (m_inputJvtKey.key().find(".") == std::string::npos)
45 m_inputJvtKey = m_inputJetsKey.key() + "." + m_inputJvtKey.key();
46 else if (SG::contKeyFromKey(m_inputJvtKey.key()) != m_inputJvtKey.key())
47 {
48 ATH_MSG_ERROR("Input JVT key does not match the input jet key!");
49 return StatusCode::FAILURE;
50 }
51 CHECK(m_inputJvtKey.initialize());
52
53 CHECK(m_inputKey.initialize());
54
56
57 return initializeBase({"UncorrJets"});
58 }
59
62 const EventContext &context,
63 MonGroupBuilder &) const
64 {
65 using namespace PufitUtils;
66 // Retrieve the input
67 auto inputJets = SG::makeHandle(m_inputJetsKey, context);
68 if (!inputJets.isValid())
69 {
70 ATH_MSG_ERROR("Failed to retrieve " << m_inputJetsKey);
71 return StatusCode::FAILURE;
72 }
73 auto jvtAcc = SG::makeHandle<float>(m_inputJvtKey, context);
74 auto inputs = SG::makeHandle(m_inputKey, context);
75 if (!inputs.isValid())
76 {
77 ATH_MSG_ERROR("Failed to retrieve " << m_inputKey);
78 return StatusCode::FAILURE;
79 }
80
81 double rho = 0;
83 {
84 auto rhoHandle = SG::makeHandle(m_rhoKey, context);
85 if (!rhoHandle->getDensity(xAOD::EventShape::Density, rho))
86 {
87 ATH_MSG_ERROR("EventShape density not available!");
88 return StatusCode::FAILURE;
89 }
90 }
91
92 // Create the grid
94 CovarianceSum pileupSum;
95 METComponent sum;
96 METComponent uncorrSum;
97
98 // Keep track of which clusters/PFOs we have decided are included in a HS jet
99 std::set<const xAOD::IParticle *> hardScatterInputs;
100 std::vector<SignedKinematics> hardScatterJets;
101 std::vector<float> jetAreas;
102 for (const xAOD::Jet *ijet : *inputJets)
103 {
104 float eta = m_useDetectorEta ? accDetectorEta(*ijet) : ijet->eta();
105 if (std::abs(eta) > m_centralEta)
106 {
107 if (ijet->pt() < m_forwardPt)
108 continue;
109 }
110 else
111 {
112 if (ijet->pt() < m_minPt)
113 continue;
114 else if (ijet->pt() < m_maxPt && jvtAcc(*ijet) < m_jvtCut)
115 continue;
116 }
117 // If we're here then the jet has passed the selection
118 hardScatterJets.push_back(*ijet);
119 jetAreas.push_back(accArea(*ijet));
120 for (const auto &link : ijet->constituentLinks())
121 {
122 if (link.isValid())
123 {
124 const xAOD::IParticle *constituent = *link;
125 if (const xAOD::IParticle *original = xAOD::getOriginalObject(*constituent))
126 hardScatterInputs.insert(original);
127 else
128 hardScatterInputs.insert(constituent);
129 }
130 else
131 ATH_MSG_WARNING("Invalid constituent link!");
132 }
133 } //> end loop over jets
134
135 if (hardScatterJets.size() > 0)
136 {
137 for (const xAOD::IParticle *ipart : *inputs)
138 {
139 const xAOD::IParticle *original = xAOD::getOriginalObject(*ipart);
140 if (!original)
141 original = ipart;
142 bool isHS = hardScatterInputs.count(original);
144 ipart->e(), ipart->eta(), ipart->phi());
145 if (!isHS)
146 pileupSum.add(kin, getSigma(kin));
147
148 // Figure out which tower this particle belongs in
149 bool outOfRange = false;
150 std::size_t idx = grid.getIndex(ipart->eta(), ipart->phi(), outOfRange);
151 if (!outOfRange)
152 {
153 PufitGrid::Tower &tower = grid[idx];
154 tower += kin;
155 if (isHS)
156 // mask a tower that has *any* clusters from HS jets in it
157 tower.mask();
158 }
159 }
160
161 // Calculate the expected PU contributions to each jet
162 double towerMean = 0;
163 double towerVariance = 0;
164 unmaskedMeanAndVariance(grid, towerMean, towerVariance);
165 float towerArea = grid.etaWidth() * grid.phiWidth();
166 std::vector<double> means;
167 std::vector<double> variances;
168 means.reserve(jetAreas.size());
169 variances.reserve(jetAreas.size());
170 for (float area : jetAreas)
171 {
172 means.push_back(towerMean * area / towerArea);
173 variances.push_back(towerVariance * area / towerArea);
174 }
175
176 std::vector<SignedKinematics> corrections = pufit(
177 pileupSum.sum,
178 pileupSum.covariance,
179 means,
180 variances,
181 hardScatterJets,
183
184 for (std::size_t ii = 0; ii < hardScatterJets.size(); ++ii)
185 {
186 SignedKinematics kin = hardScatterJets.at(ii);
187 uncorrSum += kin;
189 // Add back the energy that was subtracted by the rho sub part of the
190 // calibration otherwise pufit will overcount this effect
192 jetAreas.at(ii) * rho, kin.eta(), kin.phi());
193 sum += kin;
194 sum += corrections.at(ii);
195 }
196 }
197
198 uncorrSum.fillMETComponent(0, met);
199 sum.fillMET(met);
200
201 return StatusCode::SUCCESS;
202 }
203 } // namespace MET
204} // namespace HLT
Scalar eta() const
pseudorapidity method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
double area(double R)
Some common helper functions used by decoration handles.
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
FexBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition FexBase.cxx:43
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition FexBase.cxx:48
Helper struct to build up MET values before moving them into the EDM.
void fillMETComponent(std::size_t idx, xAOD::TrigMissingET &met) const
Fill a component of the MET with this.
Gaudi::Property< float > m_minPt
Definition MHTPufitFex.h:94
virtual StatusCode initialize() override
Initialize the fex.
Gaudi::Property< bool > m_useDetectorEta
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
Gaudi::Property< bool > m_jetCalibIncludesAreaSub
Definition MHTPufitFex.h:58
Gaudi::Property< float > m_caloStoch
The coefficient of the stochastic term in the calo resolution estimate.
Definition MHTPufitFex.h:84
Gaudi::Property< float > m_forwardPt
Definition MHTPufitFex.h:99
Gaudi::Property< float > m_centralEta
Gaudi::Property< float > m_caloNoise
The coefficient of the noise term in the calo resolution estimate.
Definition MHTPufitFex.h:80
Gaudi::Property< float > m_constraintImportance
The relative constraint importance.
Definition MHTPufitFex.h:88
SG::ReadDecorHandleKey< xAOD::JetContainer > m_inputJvtKey
The input JVT decoration.
Definition MHTPufitFex.h:53
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Definition MHTPufitFex.h:61
SG::ReadHandleKey< xAOD::IParticleContainer > m_inputKey
The input clusters or PFOs.
Definition MHTPufitFex.h:56
Gaudi::Property< float > m_maxEta
The eta range of the grid.
Definition MHTPufitFex.h:68
Gaudi::Property< std::size_t > m_nPhiBins
Definition MHTPufitFex.h:73
Gaudi::Property< std::size_t > m_nEtaBins
The number of bins in eta.
Definition MHTPufitFex.h:71
Gaudi::Property< float > m_jvtCut
Definition MHTPufitFex.h:92
double getSigma(const SignedKinematics &kin) const
Calculate the estimate on the variance of a tower.
MHTPufitFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
SG::ReadHandleKey< xAOD::JetContainer > m_inputJetsKey
Input objects.
Definition MHTPufitFex.h:50
Gaudi::Property< float > m_maxPt
Definition MHTPufitFex.h:96
std::size_t getIndex(double eta, double phi, bool &outOfRange) const
Get the index for the given eta, phi values.
double phiWidth() const
The bin width in phi.
double etaWidth() const
The bin width in eta.
Describes a single element of the grid.
Definition PufitGrid.h:48
void mask(bool value=true)
Set the mask on this tower.
Definition PufitGrid.cxx:37
Bins energy deposits into a grid.
Definition PufitGrid.h:38
Class to describe the kinematics of an object that can have negative energies.
double eta() const
Direction.
double absPt() const
unsigned pt
static SignedKinematics fromEnergyEtaPhi(double energy, double eta, double phi)
Factory function to construct from energy, eta, phi (massless)
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
Class providing the definition of the 4-vector interface.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Jet_v1 Jet
Definition of the current "jet version".
const IParticle * getOriginalObject(const IParticle &copy)
This function can be used to conveniently get a pointer back to the original object from which a copy...
TrigMissingET_v1 TrigMissingET
Define the most recent version of the TrigMissingET class.