ATLAS Offline Software
GepMETPufitAlg.cxx
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "./GepMETPufitAlg.h"
5 
11 
12 namespace PUfitVar{
13  constexpr float maxEta = 4.8;
14  constexpr float caloResSqrtTerm = 15.81;
15  constexpr float caloResFloor = 50;
16  constexpr float nSigma = 5.0;
17  constexpr float constraintWeight = 1.;
18  constexpr float trimFactor = 0.9;
19  constexpr std::size_t nEtaBins = 14;
20  constexpr std::size_t nPhiBins = 8;
21 }
22 
23 GepMETPufitAlg::GepMETPufitAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24  AthReentrantAlgorithm( name, pSvcLocator ){
25 }
26 
27 
29 
30 
32  ATH_MSG_INFO ("Initializing " << name() << "...");
34  CHECK(m_outputMETPufitKey.initialize());
35  return StatusCode::SUCCESS;
36 }
37 
39  ATH_MSG_INFO ("Finalizing " << name() << "...");
40  return StatusCode::SUCCESS;
41 }
42 
43 StatusCode GepMETPufitAlg::execute(const EventContext& context) const {
44  ATH_MSG_DEBUG ("Executing " << name() << "...");
45  setFilterPassed(false, context); //optional: start with algorithm not passed
46 
47  // read in clusters
48  auto h_caloClusters = SG::makeHandle(m_caloClustersKey, context);
49  CHECK(h_caloClusters.isValid());
50  ATH_MSG_DEBUG("Read in " << h_caloClusters->size() << " clusters");
51  const auto& caloClusters = *h_caloClusters;
52 
53  ATH_CHECK(PufitMET(caloClusters,
55  context));
56 
57  setFilterPassed(true, context); //if got here, assume that means algorithm passed
58  return StatusCode::SUCCESS;
59 }
60 
62  float inputSigma,
63  const EventContext& context) const {
64 
65  using namespace HLT::MET;
68  PufitGrid grid(params);
69 
70 
71  // Start by filling the grid with the towers
72  for ( const auto* cluster : caloClusters ) {
73  grid += SignedKinematics::fromEtEtaPhi(cluster->et(), cluster->eta(), cluster->phi() );
74  }
75  // Then calculate mean and variance
76  double mean;
77  double variance;
80  mean,
81  variance);
82  // Calculate the threshold
83  // double threshold = mav.first + inputSigma*sqrt(mav.second);
84  double threshold = mean + inputSigma*sqrt(variance);
85 
86  // Apply the masks, store the masked towers and calculate the pileup
87  // quantities
88  PufitUtils::CovarianceSum pileupSum;
89  std::vector<SignedKinematics> masked;
90  for (PufitGrid::Tower& tower : grid) {
91  if (tower.sumEt() > threshold) {
92  tower.mask(true);
93  masked.push_back(tower);
94  }
95  else {
96  double sigma =
98  tower.kinematics().absPt()*PUfitVar::caloResSqrtTerm*PUfitVar::caloResSqrtTerm;
99  pileupSum.add(tower, sigma);
100  }
101  }
102 
103  // Now derive the corrections
104  std::vector<SignedKinematics> corrections = PufitUtils::pufit(
105  pileupSum.sum,
106  pileupSum.covariance,
107  mean,
108  variance,
109  masked,
111 
112  // Sum over the masked towers
113  METComponent sum = grid.sum(PufitGrid::SumStrategy::Masked);
114  // Now add the corrections - the function above returned them with the right
115  // sign for this to work
116  for (const SignedKinematics& kin : corrections){
117  sum += kin;
118  }
119 
120 
121  // write out the MET object
122  auto h_outputMET = SG::makeHandle(m_outputMETPufitKey, context);
123 
124  auto METObj = std::make_unique<xAOD::EnergySumRoI>();
125  METObj->setStore(new xAOD::EnergySumRoIAuxInfo());
126 
127  METObj->setEnergyX(sum.mpx);
128  METObj->setEnergyY(sum.mpy);
129  METObj->setEnergyT(sum.met());
130 
131  h_outputMET = std::move(METObj);
132 
133  ATH_MSG_DEBUG("No of MET objects: 1");
134 
135  return StatusCode::SUCCESS;
136 
137 }
METComponent.h
HLT::MET::PufitGrid
Bins energy deposits into a grid.
Definition: PufitGrid.h:50
GepMETPufitAlg::m_caloClustersKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
Definition: GepMETPufitAlg.h:28
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
PUfitVar::caloResSqrtTerm
constexpr float caloResSqrtTerm
Definition: GepMETPufitAlg.cxx:14
HLT::MET::PufitUtils::CovarianceSum::sum
Eigen::Vector2d sum
The sum.
Definition: PufitUtils.h:61
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
GepMETPufitAlg.h
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
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GepMETPufitAlg::m_outputMETPufitKey
SG::WriteHandleKey< xAOD::EnergySumRoI > m_outputMETPufitKey
Definition: GepMETPufitAlg.h:31
PufitGrid.h
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
EnergySumRoIAuxInfo.h
GepMETPufitAlg::GepMETPufitAlg
GepMETPufitAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GepMETPufitAlg.cxx:23
PUfitVar::maxEta
constexpr float maxEta
Definition: GepMETPufitAlg.cxx:13
PUfitVar::caloResFloor
constexpr float caloResFloor
Definition: GepMETPufitAlg.cxx:15
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PUfitVar::nEtaBins
constexpr std::size_t nEtaBins
Definition: GepMETPufitAlg.cxx:19
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::EnergySumRoIAuxInfo_v2
Auxiliary store for an EnergySum RoI object.
Definition: EnergySumRoIAuxInfo_v2.h:34
PUfitVar::nSigma
constexpr float nSigma
Definition: GepMETPufitAlg.cxx:16
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
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
PufitUtils.h
HLT::MET::PufitGrid::Tower
Describes a single element of the grid.
Definition: PufitGrid.h:60
GepMETPufitAlg::PufitMET
StatusCode PufitMET(const xAOD::CaloClusterContainer &, float inputSigma, const EventContext &) const
Definition: GepMETPufitAlg.cxx:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
GepMETPufitAlg::~GepMETPufitAlg
virtual ~GepMETPufitAlg()
Definition: GepMETPufitAlg.cxx:28
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
GepMETPufitAlg::finalize
virtual StatusCode finalize() override
Definition: GepMETPufitAlg.cxx:38
HLT::MET
Definition: METComponent.cxx:8
PUfitVar
Definition: GepMETPufitAlg.cxx:12
GepMETPufitAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: GepMETPufitAlg.cxx:43
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
HLT::MET::METComponent
Helper struct to build up MET values before moving them into the EDM.
Definition: METComponent.h:40
PeriodicGridBase.h
Provide a base class for the grids used in some pufit algorithms.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
PUfitVar::trimFactor
constexpr float trimFactor
Definition: GepMETPufitAlg.cxx:18
threshold
Definition: chainparser.cxx:74
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::GridParameters
Parameters describing a grid.
Definition: PeriodicGridBase.h:43
GepMETPufitAlg::initialize
virtual StatusCode initialize() override
Definition: GepMETPufitAlg.cxx:31
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
PUfitVar::constraintWeight
constexpr float constraintWeight
Definition: GepMETPufitAlg.cxx:17
PUfitVar::nPhiBins
constexpr std::size_t nPhiBins
Definition: GepMETPufitAlg.cxx:20
AthReentrantAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Definition: AthReentrantAlgorithm.h:139