ATLAS Offline Software
Loading...
Searching...
No Matches
InputVariable.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef JETTOOLHELPERS_INPUTVARIABLE_H
6#define JETTOOLHELPERS_INPUTVARIABLE_H
7
8
9#include "JetToolHelpers/JetContext.h" //used here
10#include "xAODJet/Jet.h" //used here
11#include "AthContainers/AuxElement.h" //member variable
12#include "JetAnalysisInterfaces/IInputVariable.h"//inheritance
13
14#include <memory> //std::unique_ptr
15#include <functional> //std::function
16#include <string>
17#include <stdexcept> //std::runtime_error
18
19
20namespace JetHelper {
21
25
27{
28
29 public:
30
32 static std::unique_ptr<InputVariable> createVariable(
33 const std::string& name,
34 const std::string& type,
35 const bool isJetVar
36 );
37
39 InputVariable(const std::string& name): m_name{name}, m_scale{1.} {}
41 const std::string& name,
42 std::function<float(const xAOD::Jet& jet, const JetContext& jc)> func
43 );
44
46 virtual ~InputVariable() = default;
47
49 [[nodiscard]] float getValue(const xAOD::Jet& jet, const JetContext& jc) const override {
50 return m_scale * getValue_prot(jet, jc);
51 }
52
54 const std::string& getName() const { return m_name; }
56 float getScale() const { return m_scale; }
58 void setScale(const float scale) { m_scale = scale; }
60 void setGeV() { m_scale = 1.e-3; }
62 void setMeV() { m_scale = 1.; }
63
64 InputVariable(const InputVariable&) = delete;
65
66 protected:
67 const std::string m_name;
68 float m_scale;
69
70 std::function<float(const xAOD::Jet& jet, const JetContext& jc)> m_customFunction;
71
72 [[nodiscard]] virtual float getValue_prot(const xAOD::Jet& jet, const JetContext& jc) const {
73 return (m_customFunction(jet, jc));
74 }
75};
76
78template <typename T> class InputVariableJetContext : public InputVariable {
79 public:
80 InputVariableJetContext(const std::string& name) : InputVariable(name) {}
81 // should be T
82 virtual float getValue(const xAOD::Jet&, const JetContext& event) const {
83 if (event.isAvailable(m_name)) {
84 return event.getValue<T>(m_name);
85 } else {
86 throw std::runtime_error("Value " + m_name + " is not available");
87 }
88 }
89};
90
91template <typename T> class InputVariableAttribute : public InputVariable {
92 public:
93 InputVariableAttribute(const std::string& name) : InputVariable(name), m_acc{name} {}
94 virtual float getValue(const xAOD::Jet& jet, const JetContext&) const {
95 if (m_acc.isAvailable(jet)) {
96 return m_acc(jet)*m_scale;
97 } else {
98 throw std::runtime_error("Value " + m_name + " is not available");
99 }
100 }
101 private:
103};
104} // namespace JetHelper
105
106#endif
107
Base class for elements of a container that can have aux data.
virtual float getValue(const xAOD::Jet &jet, const JetContext &) const
return the value of the variable choose by the user
InputVariableAttribute(const std::string &name)
SG::AuxElement::ConstAccessor< T > m_acc
InputVariableJetContext(const std::string &name)
virtual float getValue(const xAOD::Jet &, const JetContext &event) const
return the value of the variable choose by the user
void setGeV()
This function set the scale to GeV, assuming MeV by default.
void setMeV()
This function set the scale to MeV, assuming MeV by default (it does nothing)
InputVariable(const std::string &name, std::function< float(const xAOD::Jet &jet, const JetContext &jc)> func)
float getScale() const
This function return the scale of the variable.
std::function< float(const xAOD::Jet &jet, const JetContext &jc)> m_customFunction
InputVariable(const std::string &name)
Constructors.
virtual float getValue_prot(const xAOD::Jet &jet, const JetContext &jc) const
void setScale(const float scale)
This function set the scale of the variable.
const std::string & getName() const
This function return the name of the variable.
static std::unique_ptr< InputVariable > createVariable(const std::string &name, const std::string &type, const bool isJetVar)
This function specialize the variable to the one choose by the user.
const std::string m_name
virtual ~InputVariable()=default
Default destructor.
float getValue(const xAOD::Jet &jet, const JetContext &jc) const override
return the value of the variable choose by the user
InputVariable(const InputVariable &)=delete
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:24
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
class IJetCalibStep
Jet_v1 Jet
Definition of the current "jet version".