ATLAS Offline Software
Loading...
Searching...
No Matches
DecoratePromptLeptonImproved.h
Go to the documentation of this file.
1// This is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef PROMPT_DECORATEPROMPTLEPTONRNN_H
8#define PROMPT_DECORATEPROMPTLEPTONRNN_H
9
10/**********************************************************************************
11 * @Package: LeptonTaggers
12 * @Class : DecoratePromptLeptonImproved
13 * @Author : Fudong He
14 * @Author : Rustem Ospanov
15 *
16 * @Brief :
17 *
18 * Decorate leptons with prompt BDT output
19 *
20 **********************************************************************************/
21
22// Local
23#include "VarHolder.h"
24
25// Tools
27
28// Athena
30#include "GaudiKernel/ToolHandle.h"
33
34// xAOD
39#include "xAODTracking/Vertex.h"
40
41// ROOT
42#include "TMVA/Reader.h"
43#include "TStopwatch.h"
44#include "TH1.h"
45
46#include <unordered_map>
47#include <optional>
48
49namespace Prompt
50{
52 {
53 /*
54 This class is mainly used to calculate and decorate the PromptLeptonImproved BDT to the lepton, workflow like:
55 1. Calculate the input variables of the BDT:
56 1.1 Find the track jet nearby and calculate the variables relate to the track jet.
57 1.2 Calculate the secondary vertex variables with the vertices that associate to the lepton.
58 1.3 Get the dedicated RNN score of the lepton
59 2. Predict the PromptLeptonImproved for electrons or muons by TMVA
60 3. Decorate the PromptLeptonImproved BDT and its input variables to the leptons
61
62 */
63
64 public:
65
66 DecoratePromptLeptonImproved(const std::string& name, ISvcLocator *pSvcLocator);
67
68 virtual StatusCode initialize() override;
69 virtual StatusCode execute() override;
70 virtual StatusCode finalize() override;
71
72 private:
75
77
78 StatusCode initializeDecorators();
80
81 void decorateElec(
82 const xAOD::Electron &electron,
83 const xAOD::JetContainer &trackJets,
84 const xAOD::CaloClusterContainer &clusters,
85 const xAOD::Vertex *primaryVertex,
86 std::vector<decoratorFloatH_t>& floatDecors,
87 std::vector<decoratorShortH_t>& shortDecors
88 );
89
90 void decorateMuon(
91 const xAOD::Muon &muon,
92 const xAOD::JetContainer &trackJets,
93 const xAOD::Vertex *primaryVertex,
94 std::vector<decoratorFloatH_t>& floatDecors,
95 std::vector<decoratorShortH_t>& shortDecors
96 );
97
99 const xAOD::IParticle &particle,
100 const xAOD::Jet &track_jet,
101 const xAOD::TrackParticle *track,
103 ) const;
104
106 const xAOD::Muon &muon,
107 Prompt::VarHolder &vars,
108 const xAOD::Vertex *primaryVertex
109 ) const;
110
112 const xAOD::Electron &elec,
113 const xAOD::CaloClusterContainer &clusters,
114 Prompt::VarHolder &vars,
115 const xAOD::Vertex *primaryVertex
116 );
117
118 float accessIsolation(const SG::ConstAccessor<float> &isoAccessor,
119 const xAOD::IParticle &particle) const;
120
122
123 void fillVarDefault(Prompt::VarHolder &vars) const;
124
126 const xAOD::IParticle &particle,
127 Prompt::VarHolder &vars,
128 std::vector<decoratorFloatH_t>& floatDecors,
129 std::vector<decoratorShortH_t>& shortDecors
130 ) const;
131
132 template<class T> std::pair<double, const xAOD::Jet*> findTrackJet(const T &part, const xAOD::JetContainer &jets);
133
135 const xAOD::Vertex *secondaryVertex,
136 const xAOD::Vertex *primaryVertex) const;
137
138 double getVertexCosThetaWithLepDir(const xAOD::IParticle &lepton,
139 const xAOD::Vertex *secondaryVertex,
140 const xAOD::Vertex *primaryVertex) const;
141
144
145 using floatAccessorMap = std::map<Prompt::Def::Var, AccessFloat>;
146
147 // Properties:
148 Gaudi::Property<std::string> m_leptonsName {
149 this, "LeptonContainerName", "",
150 "Container's name of the lepton that you want to decorate. Also need to set ElectronContainerKey or MuonContainerKey accordingly"
151 };
152
153 Gaudi::Property<std::string> m_configFileVersion {this, "ConfigFileVersion", "", "BDT weight file version"};
154 Gaudi::Property<std::string> m_configPathOverride {this, "ConfigPathOverride", "", "Path of the local BDT weight file you want to study/test"};
155 Gaudi::Property<std::string> m_inputVarDecoratePrefix {this, "InputVarDecoratePrefix", "", "Prefix of the variables that will be decorated into the lepton"};
156 Gaudi::Property<std::string> m_BDTName {this, "BDTName", "", "BDT name"};
157 Gaudi::Property<std::string> m_methodTitleMVA {this, "MethodTitleMVA", "BDT", "Help to config the path of the BDT xml file"};
158
159 Gaudi::Property<std::vector<std::string>> m_accessorRNNVars {this, "accessorRNNVars", {}, "Name of the RNN accessor of the lepton"};
160 Gaudi::Property<std::vector<std::string>> m_stringIntVars {this, "stringIntVars", {}, "Vector of the BDT int variables' names and they will be decorated into lepton if not in the veto list"};
161 Gaudi::Property<std::vector<std::string>> m_stringFloatVars {this, "stringFloatVars", {}, "Vector of the BDT float variables' names and they will be decorated into lepton if not in the veto list"};
162 Gaudi::Property<std::vector<std::string>> m_extraDecoratorFloatVars {this, "extraDecoratorFloatVars", {}, "Extra float variables' names you want to compute and decorate into the lepton"};
163 Gaudi::Property<std::vector<std::string>> m_extraDecoratorShortVars {this, "extraDecoratorShortVars", {}, "Extra short variables' names you want to compute and decorate into the lepton"};
164 Gaudi::Property<std::vector<std::string>> m_vetoDecoratorFloatVars {this, "vetoDecoratorFloatVars", {}, "Vector of the float variables' names you do not want to save"};
165 Gaudi::Property<std::vector<std::string>> m_vetoDecoratorShortVars {this, "vetoDecoratorShortVars", {}, "Vector of the short variables' names you do not want to save"};
166 Gaudi::Property<std::vector<double>> m_leptonPtBinsVector {this, "leptonPtBinsVector", {}, "pT bin edges that are used for MVABin calculation"};
167
168 Gaudi::Property<bool> m_printTime {this, "PrintTime", false, "Whether to print current time"};
169
170 Gaudi::Property<std::string> m_vertexLinkName {this, "VertexLinkName", "", "ElementLink name of the secondary vertices"};
171 Gaudi::Property<double> m_vertexMinChiSquaredProb {this, "VertexMinChiSquaredProb", 0.03, "Vertex chi2 cut"};
172 Gaudi::Property<double> m_vertexMinThetaBarrElec {this, "VertexMinThetaBarrElec", 0.002, "Vertex theta between lepton and the direction of sv-pv cut for barrel electrons"};
173 Gaudi::Property<double> m_vertexMinThetaEcapElec {this, "VertexMinThetaEcapElec", 0.001, "Vertex theta between lepton and the direction of sv-pv cut for central electrons"};
174 Gaudi::Property<double> m_vertexBarrEcapAbsEtaAt {this, "VertexBarrEcapAbsEtaAt", 1.37, "Relate to the vertex cut above, define the barrel and central electrons by abs(eta)"};
175 Gaudi::Property<double> m_elecMinCalErelConeSize {this, "ElecMinCalErelConeSize", 0.15, "Cut of the cluster for calculating the core energy of the lepton"};
176 Gaudi::Property<double> m_maxLepTrackJetDR {this, "maxLepTrackJetDR", 0.4, "Maximum distance between lepton and track jet for track jet matching"};
177
178 // Read/write handles
180 this, "TrackJetContainerName", "", "Track Jet container name"
181 };
183 this, "PrimaryVertexContainerName", "", "Primary vertex container name"
184 };
186 this, "ClusterContainerName", "",
187 "Container name of the Clusters which are used to calculate the input variables for the PromptLeptonImproved"
188 };
189
191 this, "ElectronContainerKey", "Electrons",
192 "Container's name of the electrons that you want to decorate"
193 };
195 this, "MuonContainerKey", "Muons",
196 "Container's name of the muons that you want to decorate"
197 };
198
199
200 // Variables:
201 std::vector<Prompt::Def::Var> m_intVars;
202 std::vector<Prompt::Def::Var> m_floatVars;
203 std::vector<Prompt::Def::Var> m_allVars;
204
205 std::unique_ptr<Prompt::VarHolder> m_vars;
206
208
209 std::unique_ptr<TMVA::Reader> m_TMVAReader;
210 std::vector<Float_t> m_varTMVA;
211
212 std::optional<AccessVertex> m_accessDeepSecondaryVertex;
213
215
216 std::unique_ptr<TH1D> m_leptonPtBinHist;
217
218 TStopwatch m_timerAll;
219 TStopwatch m_timerExec;
220 TStopwatch m_timerMuon;
221 TStopwatch m_timerElec;
222
227
228 using DecorMap_t = std::unordered_map<Def::Var, size_t>;
231
232 };
233}
234
235#endif // PROMPT_DECORATEPROMPTLEPTON_H
Helper class to provide constant type-safe access to aux data.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
SG::WriteDecorHandle< xAOD::IParticleContainer, short > decoratorShortH_t
std::pair< double, const xAOD::Jet * > findTrackJet(const T &part, const xAOD::JetContainer &jets)
Gaudi::Property< std::string > m_configFileVersion
Gaudi::Property< std::vector< double > > m_leptonPtBinsVector
Gaudi::Property< std::vector< std::string > > m_vetoDecoratorShortVars
void getMutualVariables(const xAOD::IParticle &particle, const xAOD::Jet &track_jet, const xAOD::TrackParticle *track, Prompt::VarHolder &vars) const
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVertexKey
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > m_shortDecorHandleKeys
Gaudi::Property< std::vector< std::string > > m_stringFloatVars
SG::WriteDecorHandle< xAOD::IParticleContainer, float > decoratorFloatH_t
std::unordered_map< Def::Var, size_t > DecorMap_t
SG::ConstAccessor< std::vector< ElementLink< xAOD::VertexContainer > > > AccessVertex
Gaudi::Property< std::vector< std::string > > m_extraDecoratorShortVars
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > m_floatDecorHandleKeys
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
double getVertexCosThetaWithLepDir(const xAOD::IParticle &lepton, const xAOD::Vertex *secondaryVertex, const xAOD::Vertex *primaryVertex) const
void fillVarDefault(Prompt::VarHolder &vars) const
Gaudi::Property< std::string > m_inputVarDecoratePrefix
SG::ReadHandleKey< xAOD::ElectronContainer > m_electronsKey
void decorateElec(const xAOD::Electron &electron, const xAOD::JetContainer &trackJets, const xAOD::CaloClusterContainer &clusters, const xAOD::Vertex *primaryVertex, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors)
DecoratePromptLeptonImproved(const std::string &name, ISvcLocator *pSvcLocator)
void getMuonAnpVariables(const xAOD::Muon &muon, Prompt::VarHolder &vars, const xAOD::Vertex *primaryVertex) const
Gaudi::Property< std::vector< std::string > > m_extraDecoratorFloatVars
std::map< Prompt::Def::Var, AccessFloat > floatAccessorMap
void getElectronAnpVariables(const xAOD::Electron &elec, const xAOD::CaloClusterContainer &clusters, Prompt::VarHolder &vars, const xAOD::Vertex *primaryVertex)
Gaudi::Property< std::vector< std::string > > m_accessorRNNVars
double getVertexLongitudinalNormDist(const xAOD::IParticle &lepton, const xAOD::Vertex *secondaryVertex, const xAOD::Vertex *primaryVertex) const
SG::ReadHandleKey< xAOD::MuonContainer > m_muonsKey
void decorateAuxLepton(const xAOD::IParticle &particle, Prompt::VarHolder &vars, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors) const
std::unique_ptr< Prompt::VarHolder > m_vars
Gaudi::Property< std::vector< std::string > > m_vetoDecoratorFloatVars
std::optional< AccessVertex > m_accessDeepSecondaryVertex
Gaudi::Property< std::string > m_configPathOverride
Gaudi::Property< std::vector< std::string > > m_stringIntVars
float accessIsolation(const SG::ConstAccessor< float > &isoAccessor, const xAOD::IParticle &particle) const
SG::ReadHandleKey< xAOD::JetContainer > m_trackJetsKey
void decorateMuon(const xAOD::Muon &muon, const xAOD::JetContainer &trackJets, const xAOD::Vertex *primaryVertex, std::vector< decoratorFloatH_t > &floatDecors, std::vector< decoratorShortH_t > &shortDecors)
Helper class to provide constant type-safe access to aux data.
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for adding a decoration to an object.
Class providing the definition of the 4-vector interface.
DecorHandleKeyArray< WriteDecorHandle< T, S >, WriteDecorHandleKey< T >, Gaudi::DataHandle::Writer > WriteDecorHandleKeyArray
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
Muon_v1 Muon
Reference the current persistent version:
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Electron_v1 Electron
Definition of the current "egamma version".