ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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
23GepMETPufitAlg::GepMETPufitAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24 AthReentrantAlgorithm( name, pSvcLocator ){
25}
26
27
29
30
32 ATH_MSG_INFO ("Initializing " << name() << "...");
33 CHECK(m_caloClustersKey.initialize());
34 CHECK(m_outputMETPufitKey.initialize());
35 return StatusCode::SUCCESS;
36}
37
39 ATH_MSG_INFO ("Finalizing " << name() << "...");
40 return StatusCode::SUCCESS;
41}
42
43StatusCode 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;
66 GridParameters params{
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*std::sqrt(mav.second);
84 double threshold = mean + inputSigma*std::sqrt(variance);
85
86 // Apply the masks, store the masked towers and calculate the pileup
87 // quantities
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 =
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
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Provide a base class for the grids used in some pufit algorithms.
virtual void setFilterPassed(bool state, const EventContext &ctx) const
An algorithm that can be simultaneously executed in multiple threads.
StatusCode PufitMET(const xAOD::CaloClusterContainer &, float inputSigma, const EventContext &) const
virtual StatusCode initialize() override
SG::WriteHandleKey< xAOD::EnergySumRoI > m_outputMETPufitKey
virtual StatusCode execute(const EventContext &) const override
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
GepMETPufitAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode finalize() override
virtual ~GepMETPufitAlg()
Helper struct to build up MET values before moving them into the EDM.
Describes a single element of the grid.
Definition PufitGrid.h:48
Bins energy deposits into a grid.
Definition PufitGrid.h:38
METComponent sum(SumStrategy strategy=SumStrategy::All) const
Class to describe the kinematics of an object that can have negative energies.
static SignedKinematics fromEtEtaPhi(double et, double eta, double phi)
Factory function to construct from et, eta, phi (massless)
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="")
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.
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.
constexpr float maxEta
constexpr float caloResFloor
constexpr float constraintWeight
constexpr std::size_t nPhiBins
constexpr float trimFactor
constexpr float caloResSqrtTerm
constexpr float nSigma
constexpr std::size_t nEtaBins
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
EnergySumRoIAuxInfo_v2 EnergySumRoIAuxInfo
Declare the most recent version of the energy-sum auxiliary info.
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
Parameters describing a grid.
Helper struct to hold the sum over pileup objects and its covariance.
Definition PufitUtils.h:29
Eigen::Matrix2d covariance
The covariance matrix.
Definition PufitUtils.h:43
CovarianceSum & add(const SignedKinematics &kin, double sigma)
Add a new contribution to the sum.
Eigen::Vector2d sum
The sum.
Definition PufitUtils.h:41