ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetUncertainties
JetUncertainties
Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef JETUNCERTAINTIES_HELPERS_H
6
#define JETUNCERTAINTIES_HELPERS_H
7
8
#include <iostream>
9
#include <sstream>
10
#include <string>
11
#include <vector>
12
13
#include "TString.h"
14
#include "TObjString.h"
15
#include "TObjArray.h"
16
#include "TFile.h"
17
18
19
#include "
xAODJet/Jet.h
"
20
#include "
xAODJet/JetAccessors.h
"
21
22
#define JESUNC_ERROR_CODE -1234
23
#define JESUNC_NO_DEFAULT_CONSTRUCTOR ATH_MSG_FATAL("Default constructor is not supported");
24
#define JESUNC_SAFE_DELETE(T) { delete T; T = nullptr; }
25
26
class
TH1;
27
28
namespace
jet
29
{
38
class
JetFourMomAccessor:
public
xAOD::JetAttributeAccessor::AccessorWrapper
<xAOD::JetFourMom_t> {
39
public
:
40
using
xAOD::JetAttributeAccessor::AccessorWrapper
<
xAOD::JetFourMom_t
>
::AccessorWrapper
;
41
xAOD::JetFourMom_t
operator()
(
const
xAOD::Jet
&
jet
)
const
{
return
const_cast<
JetFourMomAccessor
*
>
(
this
)->
getAttribute
(
jet
);}
42
};
43
44
namespace
utils
45
{
46
// Check variable types from strings
47
template
<
typename
T>
48
bool
isTypeObjFromString
(
const
std::string&
str
);
49
template
<
typename
T>
50
bool
isTypeObjFromString
(
const
TString&
str
);
51
52
// Get variables from strings
53
template
<
typename
T>
54
bool
getTypeObjFromString
(
const
std::string&
str
, T& obj);
55
template
<
typename
T>
56
T
getTypeObjFromString
(
const
std::string&
str
);
57
template
<
typename
T>
58
bool
getTypeObjFromString
(
const
TString&
str
, T& obj);
59
template
<
typename
T>
60
T
getTypeObjFromString
(
const
TString&
str
);
61
62
// Specializations of getting variables from strings
63
template
<>
64
bool
getTypeObjFromString<std::string>
(
const
std::string&
str
, std::string& obj);
65
template
<>
66
bool
getTypeObjFromString<TString>
(
const
std::string&
str
, TString& obj);
67
template
<>
68
bool
getTypeObjFromString<bool>
(
const
std::string&
str
,
bool
& obj);
69
template
<>
70
bool
getTypeObjFromString<std::string>
(
const
TString&
str
, std::string& obj);
71
template
<>
72
bool
getTypeObjFromString<TString>
(
const
TString&
str
, TString& obj);
73
template
<>
74
bool
getTypeObjFromString<bool>
(
const
TString&
str
,
bool
& obj);
75
76
// Convert strings to vectors of objects
77
template
<
typename
T>
78
bool
vectorize
(
const
TString&
str
,
const
TString& sep, std::vector<T>& result);
79
template
<
typename
T>
80
std::vector<T>
vectorize
(
const
TString&
str
,
const
TString& sep);
81
82
// Check if a file exists
83
bool
fileExists
(
const
TString& fileName);
84
85
// Find a valid file path
86
TString
findFilePath
(
const
TString& fileName,
const
TString& path =
""
,
const
TString& calibArea =
""
);
87
88
// Open a root file
89
TFile*
readRootFile
(
const
TString& fileName,
const
TString& path =
""
,
const
TString& calibArea =
""
);
90
91
// Make bins easily
92
std::vector<double>
getLogBins
(
const
size_t
numBins,
const
double
minVal,
const
double
maxVal);
93
std::vector<double>
getUniformBins
(
const
size_t
numBins,
const
double
minVal,
const
double
maxVal);
94
95
// Scale the axis or axes of a histogram
96
void
scaleHistoAxes
(TH1* toScale,
const
double
factorX=1,
const
double
factorY=1,
const
double
factorZ=1);
97
}
98
99
template
<
typename
T>
100
bool
utils::isTypeObjFromString
(
const
std::string&
str
)
101
{
102
std::istringstream iss(
str
);
103
T obj;
104
return
!(iss >> obj).fail();
105
}
106
107
template
<
typename
T>
108
bool
utils::isTypeObjFromString
(
const
TString&
str
)
109
{
110
std::string stdstr =
str
.Data();
111
return
isTypeObjFromString<T>
(stdstr);
112
}
113
114
template
<
typename
T>
115
bool
utils::getTypeObjFromString
(
const
std::string&
str
, T& obj)
116
{
117
std::istringstream iss(
str
);
118
return
!(iss >> obj).fail();
119
}
120
template
<
typename
T>
121
T
utils::getTypeObjFromString
(
const
std::string&
str
)
122
{
123
T toReturn;
124
if
(!
getTypeObjFromString
(
str
,toReturn))
125
printf(
"Failed to convert object: %s\n"
,
str
.c_str());
126
127
return
toReturn;
128
}
129
template
<
typename
T>
130
bool
utils::getTypeObjFromString
(
const
TString&
str
, T& obj)
131
{
132
std::string stdstr =
str
.Data();
133
return
getTypeObjFromString
(stdstr,obj);
134
}
135
template
<
typename
T>
136
T
utils::getTypeObjFromString
(
const
TString&
str
)
137
{
138
T toReturn;
139
if
(!
getTypeObjFromString
(
str
,toReturn))
140
printf(
"ERROR: Failed to convert object: %s\n"
,
str
.Data());
141
142
return
toReturn;
143
}
144
145
template
<
typename
T>
146
bool
utils::vectorize
(
const
TString&
str
,
const
TString& sep, std::vector<T>& result)
147
{
148
bool
success =
true
;
149
result.clear();
150
151
TObjArray* tokens =
str
.Tokenize(sep);
152
TIter istr(tokens);
153
while
(TObjString* os=(TObjString*)istr())
154
{
155
T obj;
156
if
(!
getTypeObjFromString
(os->GetString(),obj))
157
{
158
success =
false
;
159
break
;
160
}
161
else
162
result.push_back(obj);
163
}
164
delete
tokens;
165
166
return
success;
167
}
168
169
template
<
typename
T>
170
std::vector<T>
utils::vectorize
(
const
TString&
str
,
const
TString& sep)
171
{
172
std::vector<T> result;
173
TObjArray* tokens =
str
.Tokenize(sep);
174
TIter istr(tokens);
175
176
while
(TObjString* os=(TObjString*)istr())
177
{
178
T obj;
179
if
(!
getTypeObjFromString
(os->GetString(),obj))
180
printf(
"ERROR: String \"%s\" is not the requested type\n"
,os->GetString().Data());
181
result.push_back(obj);
182
}
183
delete
tokens;
184
185
return
result;
186
}
187
188
}
// end jet namespace
189
190
#endif
Jet.h
JetAccessors.h
This header defines wrapper classes around SG::AuxElement::Accessor used internally in the Jet EDM.
jet::JetFourMomAccessor
JetFourMomAccessor is an extension of JetAttributeAccessor::AccessorWrapper<xAOD::JetFourMom_t> Acces...
Definition
JetCalibTools_PlotJESFactors.cxx:32
jet::JetFourMomAccessor::operator()
xAOD::JetFourMom_t operator()(const xAOD::Jet &jet) const
Definition
Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:41
xAOD::JetAttributeAccessor::AccessorWrapper
Definition
JetAccessors.h:49
xAOD::JetAttributeAccessor::AccessorWrapper< xAOD::JetFourMom_t >::AccessorWrapper
AccessorWrapper(const std::string &n)
Definition
JetAccessors.h:52
xAOD::JetAttributeAccessor::AccessorWrapper< xAOD::JetFourMom_t >::getAttribute
void getAttribute(const SG::AuxElement &p, xAOD::JetFourMom_t &v) const
Definition
JetAccessors.h:58
jet::utils::isTypeObjFromString
bool isTypeObjFromString(const std::string &str)
Definition
Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:100
jet::utils::getTypeObjFromString< TString >
bool getTypeObjFromString< TString >(const std::string &str, TString &obj)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:26
jet::utils::scaleHistoAxes
void scaleHistoAxes(TH1 *toScale, const double factorX=1, const double factorY=1, const double factorZ=1)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:178
jet::utils::fileExists
bool fileExists(const TString &fileName)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:94
jet::utils::getLogBins
std::vector< double > getLogBins(const size_t numBins, const double minVal, const double maxVal)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:153
jet::utils::getTypeObjFromString
bool getTypeObjFromString(const std::string &str, T &obj)
Definition
Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:115
jet::utils::getTypeObjFromString< bool >
bool getTypeObjFromString< bool >(const std::string &str, bool &obj)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:33
jet::utils::readRootFile
TFile * readRootFile(const TString &fileName, const TString &path="", const TString &calibArea="")
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:140
jet::utils::vectorize
bool vectorize(const TString &str, const TString &sep, std::vector< T > &result)
Definition
Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:146
jet::utils::getTypeObjFromString< std::string >
bool getTypeObjFromString< std::string >(const std::string &str, std::string &obj)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:19
jet::utils::findFilePath
TString findFilePath(const TString &fileName, const TString &path="", const TString &calibArea="")
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:99
jet::utils::getUniformBins
std::vector< double > getUniformBins(const size_t numBins, const double minVal, const double maxVal)
Definition
Reconstruction/Jet/JetUncertainties/Root/Helpers.cxx:165
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
str
Definition
BTagTrackIpAccessor.cxx:11
utils
Definition
Trigger/TrigMonitoring/TrigMinBiasMonitoring/python/utils.py:1
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition
JetTypes.h:17
Generated on
for ATLAS Offline Software by
1.17.0