ATLAS Offline Software
Loading...
Searching...
No Matches
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
18namespace 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
47
48 // Fill the grids from the input clusters
49 for (const xAOD::CaloCluster *iclus : *clusters)
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
72 std::vector<SignedKinematics> masked;
73 for (const PufitGrid::Tower &tower : grid)
74 {
75 if (!tower.masked())
76 {
77 float sigma =
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
88 // Get the sum over the selected towers
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,
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
#define ATH_MSG_ERROR(x)
#define CHECK(...)
Evaluate an expression and check for errors.
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.
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 fromEnergyEtaPhi(double energy, double eta, double phi)
Factory function to construct from energy, eta, phi (massless)
Gaudi::Property< float > m_nSigma
The sigma threshold.
Definition TCPufitFex.h:45
virtual StatusCode fillMET(xAOD::TrigMissingET &met, const EventContext &context, MonGroupBuilder &monitors) const override
Calculate and fill the output MET value.
TCPufitFex(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Property< float > m_caloNoise
The coefficient of the noise term in the calo resolution estimate.
Definition TCPufitFex.h:61
Gaudi::Property< float > m_constraintImportance
The relative constraint importance.
Definition TCPufitFex.h:69
Gaudi::Property< std::size_t > m_nEtaBins
The number of bins in eta.
Definition TCPufitFex.h:51
Gaudi::Property< float > m_maxEta
The eta range of the grid.
Definition TCPufitFex.h:48
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterKey
Input clusters.
Definition TCPufitFex.h:42
Gaudi::Property< float > m_caloStoch
The coefficient of the stochastic term in the calo resolution estimate.
Definition TCPufitFex.h:65
Gaudi::Property< float > m_trimFraction
The trimming fraction.
Definition TCPufitFex.h:57
Gaudi::Property< std::size_t > m_nPhiBins
The number of bins in phi.
Definition TCPufitFex.h:54
virtual StatusCode initialize() override
Initialize the fex.
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.
GridDisplacement selectGrid(const PufitGridSet &grids)
Select the grid with the highest masked sumEt.
GridDisplacement
Enum to describe the positioning of the grid.
@ NoDisplacement
The grid is not shifted.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrigMissingET_v1 TrigMissingET
Define the most recent version of the TrigMissingET class.
Helper struct to contain a full set of grids.
Definition PufitGrid.h:240
std::array< PufitGrid, 4 > grids
Definition PufitGrid.h:242
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