|
DAS
3.0
Das Analysis System
|
Go to the documentation of this file.
22 inline std::unique_ptr<TH1>
getHistSafe (std::unique_ptr<TFile>&
f,
23 const std::string&
name)
26 auto h = std::unique_ptr<TH1>(
f->Get<TH1>(
name.c_str()));
31 h->SetDirectory(
nullptr);
40 template<
class Object>
85 template<
class Object,
class... Context>
105 void operator() (Object&
object, const Context&... ctx) const;
106 void operator() (std::vector<Object>& objects, const Context&... ctx) const;
120 const std::string& histPath,
123 const std::string& histPath,
132 virtual bool passes (
const Object& obj,
const Context&... ctx)
const = 0;
142 const Context&... ctx,
143 const std::unique_ptr<TH1>& hist)
const = 0;
152 template<
class Object,
class... Context>
154 const std::filesystem::path& filePath,
157 : m_correction(correction)
158 , m_uncertainties(uncertainties)
160 namespace fs = std::filesystem;
166 if (!fs::exists(filePath))
167 BOOST_THROW_EXCEPTION(
168 fs::filesystem_error(
"Not found",
170 make_error_code(std::errc::no_such_file_or_directory)));
172 m_file = std::make_unique<TFile>(filePath.c_str(),
"READ");
179 template<
class Object,
class... Context>
181 Object& obj,
const Context&... ctx)
const
188 const float old =
weights.front().v;
189 if (old == 0)
return;
192 if (!passes(obj, ctx...)) {
198 if (!m_correction)
return;
200 const int bin = binIndex(obj, ctx..., m_nominal);
201 const float sf = m_nominal->GetBinContent(bin);
205 if (!m_uncertainties)
return;
208 for (
const auto& [_, hist] : m_bin_wise_uncs) {
209 const float variation = hist->GetBinContent(bin);
210 weights.push_back({old * (
sf + variation), bin});
211 weights.push_back({old * (
sf - variation), bin});
214 for (
const auto& [_, hist] : m_global_uncs) {
215 const float variation = hist->GetBinContent(bin);
216 weights.push_back({old * (
sf + variation), 0});
217 weights.push_back({old * (
sf - variation), 0});
224 template<
class Object,
class... Context>
226 std::vector<Object>& objects,
const Context&... ctx)
const
228 for (
auto& obj: objects) {
229 (*this)(obj, ctx...);
237 template<
class Object,
class... Context>
238 std::vector<std::string>
241 std::vector<std::string> names;
243 for (
const auto& [
name, _] : m_bin_wise_uncs) {
247 for (
const auto& [
name, _] : m_global_uncs) {
258 template<
class Object,
class... Context>
260 const std::string& histPath)
262 if (!m_correction)
return;
274 template<
class Object,
class... Context>
278 if (!m_correction || !m_uncertainties)
return;
280 if (intp == UseBinError)
281 for (
int i = 0; i <= hist->GetNcells(); ++i)
282 hist->SetBinContent(i, hist->GetBinError(i));
283 m_bin_wise_uncs[
name] = std::move(hist);
294 template<
class Object,
class... Context>
298 if (!m_correction || !m_uncertainties)
return;
300 if (intp == UseBinError)
301 for (
int i = 0; i <= hist->GetNcells(); ++i)
302 hist->SetBinContent(i, hist->GetBinError(i));
303 m_global_uncs[
name] = std::move(hist);
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
std::vector< Weight > Weights
Definition: Weight.h:41
cerr
Definition: Ntupliser_cfg.py:93
Definition: applyBTagSF.cc:31
GenericSFApplier(const std::filesystem::path &filePath, bool correction, bool uncertainties)
Constructor.
Definition: GenericSFApplier.h:153
virtual ~GenericSFApplier() noexcept=default
void loadNominal(const std::string &histPath)
Loads the histogram with the nominal scale factor. Has no effect when not applying the correction.
Definition: GenericSFApplier.h:259
virtual bool passes(const Object &obj, const Context &... ctx) const =0
Called to check whether an object passes the selection.
const std::string SysUp
Suffix used for "up" uncertainties. Follows the Combine convention.
Definition: Format.h:8
@ UseBinContent
The histogram contains the uncertainty in the scale factors.
Definition: GenericSFApplier.h:113
bool m_uncertainties
Calculate uncertainties?
Definition: GenericSFApplier.h:90
f
Definition: Ntupliser_cfg.py:252
Interpretation
How loaded histograms should be interpreted.
Definition: GenericSFApplier.h:111
virtual int binIndex(const Object &obj, const Context &... ctx, const std::unique_ptr< TH1 > &hist) const =0
Called to retrieve the bin to use in the scale factor histograms.
void loadBinWiseUnc(const std::string &name, const std::string &histPath, Interpretation intp=UseBinContent)
Loads a systematic with bin-by-bin correlations.
Definition: GenericSFApplier.h:275
std::map< std::string, std::unique_ptr< TH1 > > m_global_uncs
Histograms with uncertainties correlated.
Definition: GenericSFApplier.h:97
std::unique_ptr< TFile > m_file
SFs are loaded from this file.
Definition: GenericSFApplier.h:88
@ UseBinError
The histogram errors contain the uncertainty in the scale factors.
Definition: GenericSFApplier.h:115
std::unique_ptr< TH1 > m_nominal
Histogram with the nominal SFs.
Definition: GenericSFApplier.h:93
std::unique_ptr< TH1 > getHistSafe(std::unique_ptr< TFile > &f, const std::string &name)
Gets an histogram from a TFile.
Definition: GenericSFApplier.h:22
A generic base class to simplify applying scale factors.
Definition: GenericSFApplier.h:87
std::vector< std::string > weightNames() const
Retrieves the name of weights added by this applier. Returns an empty vector when uncertainties are d...
Definition: GenericSFApplier.h:239
std::map< std::string, std::unique_ptr< TH1 > > m_bin_wise_uncs
Histograms with uncertainties correlated bin-by-bin.
Definition: GenericSFApplier.h:95
const std::string SysDown
Suffix used for "down" uncertainties. Follows the Combine convention.
Definition: Format.h:10
bool m_correction
Apply the scale factors?
Definition: GenericSFApplier.h:89
sf
Definition: jercExample.py:112
void loadGlobalUnc(const std::string &name, const std::string &histPath, Interpretation intp=UseBinContent)
Loads a fully correlated systematic.
Definition: GenericSFApplier.h:295
Weights & weightsRef(Object &obj)
Customization point for how weights are retrieved from an object.
Definition: GenericSFApplier.h:41
DAS::Weights weights
Definition: classes.h:12
void operator()(Object &object, const Context &... ctx) const
Applies the selection and scale factors to a single object.
Definition: GenericSFApplier.h:180