DAS  3.0
Das Analysis System
Conservative.h
Go to the documentation of this file.
1 #include <cassert>
2 
3 #include <limits>
4 #include <filesystem>
5 #include <memory>
6 #include <vector>
7 
8 #include <TFile.h>
9 #include <TH2.h>
10 #include <TString.h>
11 
12 #include "exceptions.h"
13 
17 
18 static const auto feps = std::numeric_limits<float>::epsilon();
19 
20 namespace DAS::JetVeto {
21 
33 struct Conservative {
34 
35  std::unique_ptr<TH2> h;
36 
37  Conservative (const std::filesystem::path& jetveto_file)
38  {
39  using namespace std;
40  namespace fs = filesystem;
41  namespace DE = Darwin::Exceptions;
42  if (!fs::exists(jetveto_file))
43  BOOST_THROW_EXCEPTION( fs::filesystem_error("No such file.", jetveto_file,
44  make_error_code(errc::no_such_file_or_directory)) );
45 
46  auto f = make_unique<TFile>(jetveto_file.c_str(), "READ");
47  h = unique_ptr<TH2>(f->Get<TH2>("h2hot2"));
48  if (!h) BOOST_THROW_EXCEPTION( DE::BadInput("Veto maps can't be found in input ROOT file.", f) );
49 
50  if (h->Integral() < feps)
51  BOOST_THROW_EXCEPTION( DE::BadInput("Empty histogram.", h) );
52 
53  for (int x = 1; x <= h->GetNbinsX(); ++x)
54  for (int y = 1; y <= h->GetNbinsY(); ++y) {
55  float eff = h->GetBinContent(x,y);
56  if (0 <= eff && eff <= 1) continue;
57  BOOST_THROW_EXCEPTION( DE::BadInput("The content of the histogram does "
58  "not seem to correspond to efficiencies.", h) );
59  }
60  }
61 
63  {
64  int x = h->GetXaxis()->FindBin(jet.p4.Eta()),
65  y = h->GetYaxis()->FindBin(jet.p4.Phi());
66  float eff = h->GetBinContent(x,y);
67  jet.weights *= eff;
68  }
69 
70  void Write (TDirectory * dir)
71  {
72  dir->cd();
73  h->SetDirectory(dir);
74  h->Write("jetvetomap");
75  }
76 
77 };
78 
79 }
DAS::JetVeto::Conservative::Conservative
Conservative(const std::filesystem::path &jetveto_file)
Definition: Conservative.h:37
DAS::PhysicsObject::p4
FourVector p4
raw four-momentum directly after reconstruction
Definition: PhysicsObject.h:50
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
DAS::RecJet
Definition: Jet.h:37
DAS::JetVeto::Conservative::h
std::unique_ptr< TH2 > h
jet veto map
Definition: Conservative.h:35
Jet.h
binnings.h
Darwin::Exceptions
Handling of exceptions.
Definition: darwin.h:36
DAS::JetVeto::Conservative::operator()
void operator()(DAS::RecJet &jet)
Definition: Conservative.h:62
toolbox.h
DAS::JetVeto
Definition: applyConservativeVetoMap.cc:31
DAS::PhysicsObject::weights
Weights weights
object weights
Definition: PhysicsObject.h:52
DAS::JetVeto::Conservative
Definition: Conservative.h:33
Darwin::Exceptions::BadInput
Generic exception for ill-defined input (before the event loop).
Definition: exceptions.h:83
feps
static const auto feps
Definition: Conservative.h:18
DAS::JetVeto::Conservative::Write
void Write(TDirectory *dir)
Definition: Conservative.h:70