ATLAS Offline Software
Loading...
Searching...
No Matches
IsolationLowPtPLVTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4
8
9// Tools includes:
10#include <cmath>
11
13#include "TMVA/MethodBDT.h"
14#include "TMVA/Reader.h"
15#include "TMVA/Tools.h"
16
17namespace CP {
18 // Accessors for input variables
19 static const ShortAccessor s_acc_TrackJetNTrack("PromptLeptonInput_TrackJetNTrack");
20 static const FloatAccessor s_acc_DRlj("PromptLeptonInput_DRlj");
21 static const FloatAccessor s_acc_PtRel("PromptLeptonInput_PtRel");
22 static const FloatAccessor s_acc_PtFrac("PromptLeptonInput_PtFrac");
23 static const FloatAccessor s_acc_topoetcone20("topoetcone20");
24 static const FloatAccessor s_acc_ptvarcone20("ptvarcone20");
25 static const FloatAccessor s_acc_ptvarcone30("ptvarcone30");
26 static const FloatDecorator s_dec_iso_PLT("LowPtPLV");
27
28 constexpr int N_VARIABLES = 6;
29
30 IsolationLowPtPLVTool::IsolationLowPtPLVTool(const std::string& toolName) : asg::AsgTool(toolName) {}
31
33 TMVA::Tools::Instance();
34
35 std::string fullPathToFile_Muon = PathResolverFindCalibFile(m_muonCalibFile);
36 std::string fullPathToFile_Elec = PathResolverFindCalibFile(m_elecCalibFile);
37
38 std::vector<std::string> BDT_vars_Muon{"TrackJetNTrack", "PtRel", "PtFrac", "DRlj", "TopoEtCone20Rel", "PtVarCone30Rel"};
39
40 std::vector<std::string> BDT_vars_Elec{"TrackJetNTrack", "PtRel", "PtFrac", "DRlj", "TopoEtCone20Rel", "PtVarCone20Rel"};
41 m_TMVAReader_Muon = std::make_unique<TMVA::Reader>(BDT_vars_Muon, "!Silent:Color");
42 m_TMVAReader_Elec = std::make_unique<TMVA::Reader>(BDT_vars_Elec, "!Silent:Color");
43
44 if (fullPathToFile_Muon.empty()) {
45 ATH_MSG_ERROR("Error! No xml file found for Muon LowPtPLV");
46 return StatusCode::FAILURE;
47 }
48 m_TMVAReader_Muon->BookMVA(m_muonMethodName.value(), fullPathToFile_Muon);
49 TMVA::MethodBDT* method_Muon_bdt = dynamic_cast<TMVA::MethodBDT*>(m_TMVAReader_Muon->FindMVA(m_muonMethodName.value()));
50 if (!method_Muon_bdt) {
51 ATH_MSG_ERROR("Error! No method found for Muon LowPtPLV");
52 return StatusCode::FAILURE;
53 }
54
55 if (fullPathToFile_Elec.empty()) {
56 ATH_MSG_ERROR("Error! No xml file found for Electron LowPtPLV");
57 return StatusCode::FAILURE;
58 }
59 m_TMVAReader_Elec->BookMVA(m_elecMethodName.value(), fullPathToFile_Elec);
60 TMVA::MethodBDT* method_Elec_bdt = dynamic_cast<TMVA::MethodBDT*>(m_TMVAReader_Elec->FindMVA(m_elecMethodName.value()));
61 if (!method_Elec_bdt) {
62 ATH_MSG_ERROR("Error! No method found for Electron LowPtPLV");
63 return StatusCode::FAILURE;
64 }
65
66 ATH_MSG_INFO("Initialized IsolationLowPtPLVTool");
67 return StatusCode::SUCCESS;
68 }
69
71 // Check if input variables exist
72 bool inputvar_missing = false;
73 if (!s_acc_TrackJetNTrack.isAvailable(Particle)) {
74 ATH_MSG_ERROR("TrackJetNTrack not available");
75 inputvar_missing = true;
76 }
77
78 if (!s_acc_DRlj.isAvailable(Particle)) {
79 ATH_MSG_ERROR("DRlj not available");
80 inputvar_missing = true;
81 }
82
83 if (!s_acc_PtRel.isAvailable(Particle)) {
84 ATH_MSG_ERROR("PtRel not available");
85 inputvar_missing = true;
86 }
87
88 if (!s_acc_PtFrac.isAvailable(Particle)) {
89 ATH_MSG_ERROR("PtFrac not available");
90 inputvar_missing = true;
91 }
92
93 if (!s_acc_topoetcone20.isAvailable(Particle)) {
94 ATH_MSG_ERROR("topoetcone20 not available");
95 inputvar_missing = true;
96 }
97
99 ATH_MSG_ERROR("ptvarcone20 not available");
100 inputvar_missing = true;
101 }
102
103 if (Particle.type() == xAOD::Type::ObjectType::Muon && !s_acc_ptvarcone30.isAvailable(Particle)) {
104 ATH_MSG_ERROR("ptvarcone30 not available");
105 inputvar_missing = true;
106 }
107
108 if (inputvar_missing) {
109 ATH_MSG_ERROR("input variable(s) missing, augmenting fixed value 1.1");
110 s_dec_iso_PLT(Particle) = 1.1;
111 return StatusCode::FAILURE;
112 }
113
114 short TrackJetNTrack = s_acc_TrackJetNTrack(Particle);
115 float DRlj = s_acc_DRlj(Particle);
116 float PtRel = s_acc_PtRel(Particle);
117 float PtFrac = s_acc_PtFrac(Particle);
119 float ptvarcone30 = 0;
120 float ptvarcone20 = 0;
121
122 float pt = Particle.pt();
123 float score = 1.1;
124 std::vector<double> var_vector(N_VARIABLES, 0);
127 var_vector[0] = TrackJetNTrack;
128 var_vector[1] = PtRel;
129 var_vector[2] = PtFrac;
130 var_vector[3] = DRlj;
131 var_vector[4] = topoetcone20 / pt;
132 var_vector[5] = ptvarcone30 / pt;
133 score = m_TMVAReader_Muon->EvaluateMVA(var_vector, m_muonMethodName.value());
134 } else if (Particle.type() == xAOD::Type::ObjectType::Electron) {
136 var_vector[0] = TrackJetNTrack;
137 var_vector[1] = PtRel;
138 var_vector[2] = PtFrac;
139 var_vector[3] = DRlj;
140 var_vector[4] = topoetcone20 / pt;
141 var_vector[5] = ptvarcone20 / pt;
142 score = m_TMVAReader_Elec->EvaluateMVA(var_vector, m_elecMethodName.value());
143 } else {
144 ATH_MSG_ERROR("The function needs either a muon or an electron!");
145 return StatusCode::FAILURE;
146 }
148
149 return StatusCode::SUCCESS;
150 }
151} // namespace CP
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Property< std::string > m_elecMethodName
Gaudi::Property< std::string > m_muonCalibFile
Gaudi::Property< std::string > m_elecCalibFile
IsolationLowPtPLVTool(const std::string &name)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual StatusCode augmentPLV(const xAOD::IParticle &particle) override
This method adds the lowPT PLV score as decoration to the lepton.
std::unique_ptr< TMVA::Reader > m_TMVAReader_Elec
Gaudi::Property< std::string > m_muonMethodName
std::unique_ptr< TMVA::Reader > m_TMVAReader_Muon
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
static const FloatDecorator s_dec_iso_PLT("LowPtPLV")
static const FloatAccessor s_acc_PtRel("PromptLeptonInput_PtRel")
static const FloatAccessor s_acc_ptvarcone30("ptvarcone30")
static const ShortAccessor s_acc_TrackJetNTrack("PromptLeptonInput_TrackJetNTrack")
static const FloatAccessor s_acc_ptvarcone20("ptvarcone20")
static const FloatAccessor s_acc_topoetcone20("topoetcone20")
static const FloatAccessor s_acc_DRlj("PromptLeptonInput_DRlj")
constexpr int N_VARIABLES
static const FloatAccessor s_acc_PtFrac("PromptLeptonInput_PtFrac")
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
@ topoetcone20
Topo-cluster ET-sum.
@ ptvarcone20
Mini-Isolation http://arxiv.org/abs/1007.2221.
setRcore setEtHad setFside pt
Particle_v1 Particle
Define the latest version of the particle class.