ATLAS Offline Software
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"
13 #include "StoreGate/ReadHandle.h"
20 
21 namespace
22 {
23  const static SG::AuxElement::ConstAccessor<float> accArea("ActiveArea4vec_pt");
24  const static SG::AuxElement::ConstAccessor<float> accDetectorEta("DetectorEta");
25 } // namespace
26 
27 namespace 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;
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
LVL1::gFEX::towerArea
float towerArea(float eta)
Get the GCaloTower areas from their eta bins.
Definition: GTowerHelpers.cxx:59
METComponent.h
HLT::MET::PufitGrid
Bins energy deposits into a grid.
Definition: PufitGrid.h:50
SG::contKeyFromKey
std::string contKeyFromKey(const std::string &key)
Extract the container part of key.
Definition: DecorKeyHelpers.cxx:26
HLT::MET::PufitUtils::pufit
Eigen::VectorXd pufit(const Eigen::Vector2d &pileupSum, const Eigen::Matrix2d &pileupCovariance, const Eigen::VectorXd &towerExpectations, const Eigen::VectorXd &towerVariances, const Eigen::VectorXd &correctionDirections, double constraintImportance)
Perform the pile-up fit.
Definition: PufitUtils.cxx:114
PufitGrid.h
HLT::MET::MHTPufitFex::m_useDetectorEta
Gaudi::Property< bool > m_useDetectorEta
Definition: MHTPufitFex.h:129
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
HLT::MET::MHTPufitFex::m_rhoKey
SG::ReadHandleKey< xAOD::EventShape > m_rhoKey
Definition: MHTPufitFex.h:87
HLT::MET::MHTPufitFex::m_constraintImportance
Gaudi::Property< float > m_constraintImportance
The relative constraint importance.
Definition: MHTPufitFex.h:114
MHTPufitFex.h
HLT::MET::MHTPufitFex::m_centralEta
Gaudi::Property< float > m_centralEta
Definition: MHTPufitFex.h:127
HLT::MET::PeriodicGridBase::getIndex
std::size_t getIndex(double eta, double phi, bool &outOfRange) const
Get the index for the given eta, phi values.
Definition: PeriodicGridBase.cxx:79
HLT::MET::FexBase
Definition: FexBase.h:47
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
HLT::MET::MHTPufitFex::m_nPhiBins
Gaudi::Property< std::size_t > m_nPhiBins
Definition: MHTPufitFex.h:99
HLT::MET::MHTPufitFex::getSigma
double getSigma(const SignedKinematics &kin) const
Calculate the estimate on the variance of a tower.
Definition: MHTPufitFex.cxx:31
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
DecorKeyHelpers.h
Some common helper functions used by decoration handles.
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
HLT::MET::SignedKinematics::absPt
double absPt() const
unsigned pt
Definition: SignedKinematics.cxx:115
HLT::MET::MHTPufitFex::MHTPufitFex
MHTPufitFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: MHTPufitFex.cxx:36
HLT::MET::MHTPufitFex::m_jvtCut
Gaudi::Property< float > m_jvtCut
Definition: MHTPufitFex.h:118
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
HLT::MET::MHTPufitFex::m_forwardPt
Gaudi::Property< float > m_forwardPt
Definition: MHTPufitFex.h:125
HLT::MET::PeriodicGridBase::phiWidth
double phiWidth() const
The bin width in phi.
Definition: PeriodicGridBase.cxx:150
HLT::MET::MHTPufitFex::m_jetCalibIncludesAreaSub
Gaudi::Property< bool > m_jetCalibIncludesAreaSub
Definition: MHTPufitFex.h:84
HLT::MET::MHTPufitFex::m_caloStoch
Gaudi::Property< float > m_caloStoch
The coefficient of the stochastic term in the calo resolution estimate.
Definition: MHTPufitFex.h:110
met
Definition: IMETSignificance.h:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
HLT::MET::SignedKinematics
Class to describe the kinematics of an object that can have negative energies.
Definition: SignedKinematics.h:42
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
HLT::MET::MHTPufitFex::m_maxPt
Gaudi::Property< float > m_maxPt
Definition: MHTPufitFex.h:122
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HLT::MET::MHTPufitFex::m_inputJvtKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_inputJvtKey
The input JVT decoration.
Definition: MHTPufitFex.h:79
PufitUtils.h
HLT::MET::MHTPufitFex::m_minPt
Gaudi::Property< float > m_minPt
Definition: MHTPufitFex.h:120
HLT::MET::PufitGrid::Tower
Describes a single element of the grid.
Definition: PufitGrid.h:60
TCS::MET
@ MET
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:16
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::MET::MHTPufitFex::fillMET
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
Definition: MHTPufitFex.cxx:60
HLT::MET::METComponent::fillMETComponent
void fillMETComponent(std::size_t idx, xAOD::TrigMissingET &met) const
Fill a component of the MET with this.
Definition: METComponent.cxx:101
HLT::MET::SignedKinematics::fromEnergyEtaPhi
static SignedKinematics fromEnergyEtaPhi(double energy, double eta, double phi)
Factory function to construct from energy, eta, phi (massless)
Definition: SignedKinematics.cxx:26
HLT::MET::FexBase::initializeBase
StatusCode initializeBase(const std::vector< std::string > &componentNames)
Initialize the base class.
Definition: FexBase.cxx:48
HLT::MET::METComponent
Helper struct to build up MET values before moving them into the EDM.
Definition: METComponent.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
HLT::MET::PufitUtils::unmaskedMeanAndVariance
void unmaskedMeanAndVariance(const PufitGrid &grid, double &mean, double &variance)
Calculate the mean and variance of unmasked towers.
Definition: PufitUtils.cxx:72
HLT::MET::MonGroupBuilder
Definition: MonGroupBuilder.h:45
HLT::MET::MHTPufitFex::m_caloNoise
Gaudi::Property< float > m_caloNoise
The coefficient of the noise term in the calo resolution estimate.
Definition: MHTPufitFex.h:106
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TrigMissingET_v1
Class holding the Missing ET trigger fex results.
Definition: TrigMissingET_v1.h:32
HLT::MET::MHTPufitFex::initialize
virtual StatusCode initialize() override
Initialize the fex.
Definition: MHTPufitFex.cxx:41
HLT::MET::MHTPufitFex::m_nEtaBins
Gaudi::Property< std::size_t > m_nEtaBins
The number of bins in eta.
Definition: MHTPufitFex.h:97
HLT::MET::MHTPufitFex::m_maxEta
Gaudi::Property< float > m_maxEta
The eta range of the grid.
Definition: MHTPufitFex.h:94
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
HLT::MET::MHTPufitFex::m_inputJetsKey
SG::ReadHandleKey< xAOD::JetContainer > m_inputJetsKey
Input objects.
Definition: MHTPufitFex.h:76
ReadDecorHandle.h
Handle class for reading a decoration on an object.
HLT::MET::SignedKinematics::phi
double phi() const
Definition: SignedKinematics.cxx:66
IParticleHelpers.h
xAOD::getOriginalObject
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...
Definition: IParticleHelpers.cxx:140
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
ReadHandle.h
Handle class for reading from StoreGate.
HLT::MET::PufitGrid::Tower::mask
void mask(bool value=true)
Set the mask on this tower.
Definition: PufitGrid.cxx:37
HLT::MET::PeriodicGridBase::etaWidth
double etaWidth() const
The bin width in eta.
Definition: PeriodicGridBase.cxx:149
HLT::MET::MHTPufitFex::m_inputKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_inputKey
The input clusters or PFOs.
Definition: MHTPufitFex.h:82
fitman.rho
rho
Definition: fitman.py:532
HLT::MET::SignedKinematics::eta
double eta() const
Direction.
Definition: SignedKinematics.cxx:62