ATLAS Offline Software
TCPufitFex.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /******************************************************************************
6  * @package Trigger/TrigAlgorithms/TrigEFMissingET
7  * @file TCPufitFex.cxx
8  *
9  * Implementation of the pufit fex class
10  * @author Jon Burr
11  *****************************************************************************/
12 
13 #include "TCPufitFex.h"
17 
18 namespace HLT
19 {
20  namespace MET
21  {
22  TCPufitFex::TCPufitFex(const std::string &name, ISvcLocator *pSvcLocator) : FexBase(name, pSvcLocator)
23  {
24  }
25 
27  {
28  CHECK(m_clusterKey.initialize());
29  return initializeBase({"AllTowers", "UncorrSelTowers"});
30  }
31 
34  const EventContext &context,
35  MonGroupBuilder &) const
36  {
37  // Retrieve the inputs
38  auto clusters = SG::makeHandle(m_clusterKey, context);
39  if (!clusters.isValid())
40  {
41  ATH_MSG_ERROR("Failed to retrieve " << m_clusterKey);
42  return StatusCode::FAILURE;
43  }
44 
45  // Create the pufit grids
46  PufitGridSet gridset(m_maxEta, m_nEtaBins, m_nPhiBins);
47 
48  // Fill the grids from the input clusters
49  for (const xAOD::CaloCluster *iclus : *clusters)
50  gridset += SignedKinematics::fromEnergyEtaPhi(
51  iclus->e(), iclus->eta(), iclus->phi());
52 
53  // We calculate the mean and variance from the 'nominal' grid
54  double mean;
55  double variance;
57  gridset[NoDisplacement], m_trimFraction, mean, variance);
58  // Calculate the threshold
59  float threshold = mean + m_nSigma * sqrt(variance);
60 
61  // Apply the masks
62  for (PufitGrid &grid : gridset.grids)
63  for (PufitGrid::Tower &tower : grid)
64  tower.mask(tower.sumEt() > threshold);
65 
66  // Select the right grid
68  const PufitGrid &grid = gridset[idx];
69 
70  // Build the pileup sum and prepare the vector of corrections
71  PufitUtils::CovarianceSum pileupSum;
72  std::vector<SignedKinematics> masked;
73  for (const PufitGrid::Tower &tower : grid)
74  {
75  if (!tower.masked())
76  {
77  float sigma =
78  m_caloNoise * m_caloNoise +
79  tower.kinematics().absPt() * m_caloStoch * m_caloStoch;
80  pileupSum.add(tower, sigma);
81  }
82  else
83  masked.push_back(tower);
84  }
85 
86  // Save the sum over all towers to the corresponding component
87  grid.sum(PufitGrid::SumStrategy::All).fillMETComponent(0, met);
88  // Get the sum over the selected towers
89  METComponent sum = grid.sum(PufitGrid::SumStrategy::Masked);
90  // Save this uncorrected sum to the corresponding component
91  sum.fillMETComponent(1, met);
92 
93  // If variance is 0 then there are no towers in the trimmed mean calculation with energy > 0
94  // This will cause the fit to fail!
95  if (variance != 0)
96  {
97  // Perform the fit
98  std::vector<SignedKinematics> corrections = PufitUtils::pufit(
99  pileupSum.sum,
100  pileupSum.covariance,
101  mean,
102  variance,
103  masked,
104  m_constraintImportance);
105 
106  // Apply the corrections
107  for (const SignedKinematics &kin : corrections)
108  sum += kin;
109  }
110  sum.fillMET(met);
111  return StatusCode::SUCCESS;
112  }
113  } // namespace MET
114 } // namespace HLT
METComponent.h
HLT::MET::PufitGrid
Bins energy deposits into a grid.
Definition: PufitGrid.h:50
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
HLT::MET::PufitUtils::CovarianceSum::sum
Eigen::Vector2d sum
The sum.
Definition: PufitUtils.h:61
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
PufitGrid.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
HLT::MET::PufitGridSet
Helper struct to contain a full set of grids.
Definition: PufitGrid.h:252
HLT::MET::PufitUtils::CovarianceSum::covariance
Eigen::Matrix2d covariance
The covariance matrix.
Definition: PufitUtils.h:63
HLT::MET::PufitUtils::CovarianceSum
Helper struct to hold the sum over pileup objects and its covariance.
Definition: PufitUtils.h:44
HLT::MET::NoDisplacement
@ NoDisplacement
The grid is not shifted.
Definition: PeriodicGridBase.h:25
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLT::MET::GridDisplacement
GridDisplacement
Enum to describe the positioning of the grid.
Definition: PeriodicGridBase.h:23
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
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
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PufitUtils.h
HLT::MET::PufitGrid::Tower
Describes a single element of the grid.
Definition: PufitGrid.h:60
HLT::MET::PufitUtils::selectGrid
GridDisplacement selectGrid(const PufitGridSet &grids)
Select the grid with the highest masked sumEt.
Definition: PufitUtils.cxx:95
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HLT::MET::PufitUtils::trimmedMeanAndVariance
void trimmedMeanAndVariance(const std::vector< double > &sorted, double trimFraction, double &mean, double &variance)
Calculate the trimmed mean and variance for a vector of tower sumEts.
Definition: PufitUtils.cxx:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MET
Definition: MET.py:1
threshold
Definition: chainparser.cxx:74
HLT::MET::MonGroupBuilder
Definition: MonGroupBuilder.h:45
HLT::MET::PufitUtils::CovarianceSum::add
CovarianceSum & add(const SignedKinematics &kin, double sigma)
Add a new contribution to the sum.
Definition: PufitUtils.cxx:25
HLT::MET::TCPufitFex::TCPufitFex
TCPufitFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: TCPufitFex.cxx:34
xAOD::TrigMissingET_v1
Class holding the Missing ET trigger fex results.
Definition: TrigMissingET_v1.h:32
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
met::fillMET
StatusCode fillMET(xAOD::MissingET *&met, xAOD::MissingETContainer *metCont, const std::string &metKey, const MissingETBase::Types::bitmask_t metSource)
Definition: METHelpers.cxx:123
TCPufitFex.h
PUClassification.All
All
Definition: PUClassification.py:17