ATLAS Offline Software
Loading...
Searching...
No Matches
RunKLFitterAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#ifndef KLFITTERANALYSISALGORITHMS_RUNKLFITTERALG_H_
9#define KLFITTERANALYSISALGORITHMS_RUNKLFITTERALG_H_
10
11#include <algorithm>
12#include <numeric>
13#include <optional>
14
15// Algorithm includes
22
23// Framework includes
29
32
33// Externals
37#include "KLFitter/BoostedLikelihoodTopLeptonJets.h"
38#include "KLFitter/DetectorAtlas_8TeV.h"
39#include "KLFitter/Fitter.h"
40#include "KLFitter/LikelihoodTTHLeptonJets.h"
41#include "KLFitter/LikelihoodTTZTrilepton.h"
42#include "KLFitter/LikelihoodTopAllHadronic.h"
43#include "KLFitter/LikelihoodTopLeptonJets.h"
44#include "KLFitter/LikelihoodTopLeptonJets_Angular.h"
45#include "KLFitter/LikelihoodTopLeptonJets_JetAngles.h"
46#include "KLFitter/Permutations.h"
47
48namespace EventReco {
49
50class RunKLFitterAlg final : public EL::AnaAlgorithm {
51
52 public:
54 virtual StatusCode initialize() final;
55 virtual StatusCode execute(const EventContext& ctx) final;
56
57 private:
58 StatusCode execute_syst(const CP::SystematicSet &sys,
59 const EventContext &ctx);
60 StatusCode add_leptons(
61 const std::vector<const xAOD::Electron *> &selected_electrons,
62 const std::vector<const xAOD::Muon *> &selected_muons,
63 KLFitter::Particles *myParticles);
64
65 StatusCode add_jets(const std::vector<const xAOD::Jet *> &selected_jets,
66 KLFitter::Particles *myParticles);
67
68 StatusCode setJetskLeadingN(const std::vector<const xAOD::Jet *> &jets,
69 KLFitter::Particles *inputParticles,
70 const size_t njets);
71
72 StatusCode getBTagDecision(const xAOD::Jet &jet, bool &isTagged) const;
73
74 StatusCode addJet(const xAOD::Jet *jet, const size_t index,
75 const bool isTagged, KLFitter::Particles *inputParticles);
76
77 StatusCode retrieveEfficiencies(const xAOD::Jet *jet, float *eff,
78 float *ineff);
79
80 StatusCode setJetskBtagPriority(const std::vector<const xAOD::Jet *> &jets,
81 KLFitter::Particles *inputParticles,
82 const size_t maxJets);
83
84 StatusCode evaluatePermutations(const CP::SystematicSet &sys,
85 const EventContext &ctx,
86 const std::vector<size_t> &electron_indices,
87 const std::vector<size_t> &muon_indices,
88 const std::vector<size_t> &jet_indices);
89
90 template <typename T>
91 std::vector<const T *> sortPt(const std::vector<const T *> &particles,
92 std::vector<size_t> &indices) {
93 indices.resize(particles.size());
94 std::iota(indices.begin(), indices.end(), size_t{0});
95 std::sort(indices.begin(), indices.end(),
96 [&particles](const size_t i, const size_t j) {
97 return particles[i]->pt() > particles[j]->pt();
98 });
99 std::vector<const T *> sorted_particles;
100 sorted_particles.reserve(particles.size());
101 for (const size_t i : indices) {
102 sorted_particles.push_back(particles[i]);
103 }
104 return sorted_particles;
105 }
106
107 // systematics
109
110 // inputs needed for reconstruction
112 this, "electrons", "", "the electron container to use"};
114 this, "electronSelection", "", "the selection on the input electrons"};
115
117 this, "muons", "", "the muon container to use"};
119 this, "muonSelection", "", "the selection on the input muons"};
120
122 this, "jets", "", "the jet container to use"};
124 "the selection on the input jets"};
125
127 this, "met", "", "the MET container to use"};
128
130 this, "eventInfo", "EventInfo",
131 "the EventInfo container to read selection decisions from"};
132
133 // output container
136 m_outHandle{this, "result", "KLFitterResult_%SYS%",
137 "the output KLFitterResultContainer"};
138
139 CP::SysReadSelectionHandle m_selection{this, "selectionDecorationName", "",
140 "Name of the selection on which this "
141 "KLFitter instance is allowed to run"};
142
143 // configurable properties
144 Gaudi::Property<std::string> m_leptonType{this, "LeptonType", "kUndefined",
145 "Define the lepton type"};
146 Gaudi::Property<std::string> m_LHType{this, "LHType", "kUndefined",
147 "Define the Likelihood type"};
148 Gaudi::Property<std::string> m_transferFunctionsPath{
149 this, "TransferFunctionsPath",
150 "dev/AnalysisTop/KLFitterTFs/mc12a/akt4_LCtopo_PP6/",
151 "Path to transfer functions"};
152 Gaudi::Property<std::string> m_jetSelectionMode{
153 this, "JetSelectionMode", "kBtagPriorityFourJets",
154 "Define the behavior for selecting jets"};
155 Gaudi::Property<std::string> m_bTaggingMethod{
156 this, "BTaggingMethod", "kNotag",
157 "Method for accounting b-tagging information"};
158 Gaudi::Property<std::string> m_bTagDecoration{
159 this, "BTaggingDecoration", "",
160 "Name of the btag decision decoration for jets"};
161 Gaudi::Property<std::string> m_METterm{this, "METterm", "Final",
162 "Which MET term should be used"};
163 Gaudi::Property<float> m_massTop{
164 this, "TopMass", 172.5,
165 "The mass of top quark used in KLFitter likelihood (assuming the fixed "
166 "m_top mode is used)"};
167 Gaudi::Property<bool> m_fixedTopMass{
168 this, "TopMassFixed", true,
169 "If the top quark mass is fixed in the likelihood to the value of "
170 "TopMass parameter"};
171 Gaudi::Property<bool> m_saveAllPermutations{
172 this, "SaveAllPermutations", false,
173 "Whether to store only the permutation with highest KLFitter event "
174 "probability, or all"};
175 Gaudi::Property<bool> m_failOnLessThanXJets{
176 this, "FailOnLessThanXJets", false,
177 "Fail if kLeadingX or kBtagPriorityXJets is set and the number of jets "
178 "in the event is less than X"};
179
183
184 bool m_useBtagPriority{false};
186
187 std::unique_ptr<KLFitter::Fitter> m_myFitter;
188 std::unique_ptr<KLFitter::DetectorAtlas_8TeV> m_myDetector;
189 KLFitter::LikelihoodBase::BtaggingMethod m_bTaggingMethodEnum{};
190
191 std::unique_ptr<KLFitter::LikelihoodBase> m_likelihood;
192
193 ToolHandle<IBTaggingEfficiencyTool> m_btagging_eff_tool{
194 this, "btagEffTool", "", "the b-tagging efficiency tool"};
195
196 std::optional<SG::ConstAccessor<char>> m_bTagDecoAcc;
197
198 // single-jet container used to query the b-tagging efficiencies
202};
203} // namespace EventReco
204
205#endif
std::vector< std::vector< int64_t > > indices
a class managing the property to configure the list of systematics to process
a data handle for reading systematics varied input data
a data handle for reading systematically varied selection properties from objects
a data handle for writing systematics varied input data
Class to wrap a set of SystematicVariations.
the (new) base class for EventLoop algorithms
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
virtual::StatusCode execute()
execute this algorithm
std::optional< SG::ConstAccessor< char > > m_bTagDecoAcc
CP::SysWriteHandle< xAOD::KLFitterResultContainer, xAOD::KLFitterResultAuxContainer > m_outHandle
virtual StatusCode initialize() final
StatusCode retrieveEfficiencies(const xAOD::Jet *jet, float *eff, float *ineff)
StatusCode addJet(const xAOD::Jet *jet, const size_t index, const bool isTagged, KLFitter::Particles *inputParticles)
CP::SysReadHandle< xAOD::EventInfo > m_eventInfoHandle
Gaudi::Property< std::string > m_transferFunctionsPath
StatusCode setJetskLeadingN(const std::vector< const xAOD::Jet * > &jets, KLFitter::Particles *inputParticles, const size_t njets)
CP::SysListHandle m_systematicsList
std::unique_ptr< KLFitter::DetectorAtlas_8TeV > m_myDetector
CP::SysReadSelectionHandle m_muonSelection
StatusCode evaluatePermutations(const CP::SystematicSet &sys, const EventContext &ctx, const std::vector< size_t > &electron_indices, const std::vector< size_t > &muon_indices, const std::vector< size_t > &jet_indices)
CP::SysReadHandle< xAOD::ElectronContainer > m_electronsHandle
KLFEnums::JetSelectionMode m_jetSelectionModeEnum
KLFEnums::LeptonType m_leptonTypeEnum
std::vector< const T * > sortPt(const std::vector< const T * > &particles, std::vector< size_t > &indices)
Gaudi::Property< bool > m_fixedTopMass
CP::SysReadHandle< xAOD::JetContainer > m_jetsHandle
Gaudi::Property< std::string > m_leptonType
xAOD::JetContainer m_effJets
StatusCode getBTagDecision(const xAOD::Jet &jet, bool &isTagged) const
Gaudi::Property< std::string > m_bTaggingMethod
StatusCode add_leptons(const std::vector< const xAOD::Electron * > &selected_electrons, const std::vector< const xAOD::Muon * > &selected_muons, KLFitter::Particles *myParticles)
Gaudi::Property< bool > m_saveAllPermutations
Gaudi::Property< std::string > m_METterm
CP::SysReadHandle< xAOD::MissingETContainer > m_metHandle
KLFEnums::Likelihood m_LHTypeEnum
CP::SysReadSelectionHandle m_selection
KLFitter::LikelihoodBase::BtaggingMethod m_bTaggingMethodEnum
ToolHandle< IBTaggingEfficiencyTool > m_btagging_eff_tool
Gaudi::Property< std::string > m_bTagDecoration
std::unique_ptr< KLFitter::LikelihoodBase > m_likelihood
xAOD::JetAuxContainer m_effJetsAux
StatusCode setJetskBtagPriority(const std::vector< const xAOD::Jet * > &jets, KLFitter::Particles *inputParticles, const size_t maxJets)
CP::SysReadHandle< xAOD::MuonContainer > m_muonsHandle
Gaudi::Property< bool > m_failOnLessThanXJets
CP::SysReadSelectionHandle m_electronSelection
Gaudi::Property< std::string > m_jetSelectionMode
StatusCode add_jets(const std::vector< const xAOD::Jet * > &selected_jets, KLFitter::Particles *myParticles)
CP::SysReadSelectionHandle m_jetSelection
Gaudi::Property< std::string > m_LHType
StatusCode execute_syst(const CP::SystematicSet &sys, const EventContext &ctx)
std::unique_ptr< KLFitter::Fitter > m_myFitter
Gaudi::Property< float > m_massTop
Auxiliary container for xAOD::KLFitterResultContainer.
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
JetAuxContainer_v1 JetAuxContainer
Definition of the current jet auxiliary container.
DataVector< xAOD::KLFitterResult > KLFitterResultContainer
Definition of the KLFitterResultContainer type.
JetContainer_v1 JetContainer
Definition of the current "jet container version".