DAS  3.0
Das Analysis System
Plots.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <memory>
5 #include <vector>
6 
7 #include <TH2F.h>
8 
12 
14 
15 namespace DAS::PUstaub {
16 
17 static const std::vector<double> pthat_edges = {0, 1e-6, 15, 30, 50, 80, 120, 170, 300, 470, 600, 800, 1000, 1400, 1800, 2400, 3200, 6500};
18 static const int nPtHatBins = pthat_edges.size()-1;
19 
20 struct Plots {
21 
22  TString name;
23 
24  std::unique_ptr<TH1F> pthatME, pthatPU, pthatMax, genht, recht;
26 
27  Plots (const char * Name) :
28  name(Name),
29  pthatME(std::make_unique<TH1F>("pthatME", ";#hat{p}_{T}^{ME} [GeV];N_{eff}^{collisions}", nPtHatBins, pthat_edges.data())),
30  pthatPU(std::make_unique<TH1F>("pthatPU", ";#hat{p}_{T}^{PU} [GeV];N_{eff}^{collisions}", nPtHatBins, pthat_edges.data())),
31  pthatMax(std::make_unique<TH1F>("pthatMax", ";max #hat{p}_{T}^{ME+PU} [GeV];N_{eff}^{bx}", nPtHatBins, pthat_edges.data())),
32  genht(std::make_unique<TH1F>("genht", ";H_{T}^{gen} [GeV];N_{eff}^{j}", nPtBins, pt_edges.data())),
33  recht(std::make_unique<TH1F>("recht", ";H_{T}^{rec} [GeV];N_{eff}^{j}", nPtBins, pt_edges.data())),
34  pthatLogw(std::make_unique<TH2F>("pthatLogw", ";#hat{p}_{T} [GeV];log(w);N_{eff}^{j}", nPtHatBins, pthat_edges.data(), 400, -30, 20)),
35  genptLogw(std::make_unique<TH2F>("genptLogw", ";Jet p_{T}^{gen} [GeV];log(w);N_{eff}^{j}", nPtBins, pt_edges.data(), 400, -30, 20)),
36  genhtLogw(std::make_unique<TH2F>("genhtLogw", ";H_{T}^{gen} [GeV];log(w);N_{eff}^{j}", nPtBins, pt_edges.data(), 400, -30, 20)),
37  genmjjLogw(std::make_unique<TH2F>("genmjjLogw", ";m_{jj}^{gen} [GeV];log(w);N_{eff}^{jj}", nMjjBins, Mjj_edges.data(), 400, -30, 20)),
38  recptLogw(std::make_unique<TH2F>("recptLogw", ";Jet p_{T}^{rec} [GeV];log(w);N_{eff}^{j}", nPtBins, pt_edges.data(), 400, -30, 20)),
39  rechtLogw(std::make_unique<TH2F>("rechtLogw", ";H_{T}^{rec} [GeV];log(w);N_{eff}^{j}", nPtBins, pt_edges.data(), 400, -30, 20)),
40  recmjjLogw(std::make_unique<TH2F>("recmjjLogw", ";m_{jj}^{rec} [GeV];log(w);N_{eff}^{jj}", nMjjBins, Mjj_edges.data(), 400, -30, 20))
41  { }
42 
43 private:
44 
45  float FillPtHat (const GenEvent& event, const PileUp& pileup)
46  {
47  float gW = event.weights.front();
48 
49  pthatME->Fill(event.hard_scale, gW);
50  float maxpthat = event.hard_scale;
51  for (auto pthat: pileup.pthats) {
52  pthatPU->Fill(pthat, gW);
53  maxpthat = std::max(maxpthat, pthat);
54  }
55  pthatMax->Fill(maxpthat, gW);
56 
57  return maxpthat;
58  }
59 
60  template<typename Jet> void FillObsWgt (std::unique_ptr<TH2F>& ptLogw,
61  std::unique_ptr<TH2F>& mjjLogw,
62  std::unique_ptr<TH2F>& htLogw,
63  std::unique_ptr<TH1F>& ht,
64  const std::vector<Jet>& jets, float evW)
65  {
66  auto pt_sum = 0;
67  auto weight_sum = 0;
68  for (const auto& jet: jets) {
69  auto jW = log(jet.weights.front());
70  weight_sum = weight_sum + jW;
71  ptLogw->Fill(jet.p4.Pt(), evW + jW);
72  pt_sum += jet.p4.Pt();
73  }
74  ht->Fill(pt_sum);
75 
76  htLogw->Fill(pt_sum, evW + weight_sum);
77 
78  if (jets.size() < 2) return;
79  const auto& j0 = jets.at(0),
80  j1 = jets.at(1);
81 
82  if (j0.p4.Pt() < 100. || j1.p4.Pt() < 50.) return;
83  if (std::max(j0.AbsRap(), j1.AbsRap()) >= 3.0) return;
84  auto dijet = j0 + j1;
85  auto djW = log(j0.weights.front()) + log(j1.weights.front());
86  mjjLogw->Fill(dijet.CorrP4().M(), evW + djW);
87  }
88 
89 public:
90 
91  void operator() (const std::vector<GenJet>& genjets,
92  const std::vector<RecJet>& recjets,
93  const GenEvent& genEvt,
94  const RecEvent& recEvt,
95  const PileUp& pileup)
96  {
97  float maxpthat = FillPtHat(genEvt, pileup);
98 
99  float logw = log(genEvt.weights.front());
100  pthatLogw->Fill(maxpthat, logw);
101  FillObsWgt<GenJet>(genptLogw, genmjjLogw, genhtLogw, genht, genjets, logw);
102 
103  logw += log(recEvt.weights.front());
104  FillObsWgt<RecJet>(recptLogw, recmjjLogw, rechtLogw, recht, recjets, logw);
105 
106  }
107 
108  void Write (TDirectory * d)
109  {
110  d->cd();
111  TDirectory * dd = d->mkdir(name);
112  dd->cd();
113  std::vector<TH1*> hists {pthatME.get(), pthatPU.get(), pthatMax.get(), genht.get(), recht.get(),
114  dynamic_cast<TH1*>(pthatLogw.get()),
115  dynamic_cast<TH1*>(genptLogw.get()),
116  dynamic_cast<TH1*>(genhtLogw.get()),
117  dynamic_cast<TH1*>(genmjjLogw.get()),
118  dynamic_cast<TH1*>(recptLogw.get()),
119  dynamic_cast<TH1*>(rechtLogw.get()),
120  dynamic_cast<TH1*>(recmjjLogw.get())};
121  for (auto h: hists) {
122  h->SetDirectory(dd);
123  TString hname = h->GetName();
124  hname.ReplaceAll(name, "");
125  h->Write(hname);
126  }
127  }
128 };
129 
130 }
DAS::PUstaub::Plots::Plots
Plots(const char *Name)
Definition: Plots.h:27
DAS::PUstaub::pthat_edges
static const std::vector< double > pthat_edges
Definition: Plots.h:17
DAS::PUstaub::Plots::FillPtHat
float FillPtHat(const GenEvent &event, const PileUp &pileup)
Definition: Plots.h:45
DAS::PUstaub::Plots::pthatPU
std::unique_ptr< TH1F > pthatPU
Definition: Plots.h:24
DAS::PUstaub::Plots::pthatLogw
std::unique_ptr< TH2F > pthatLogw
Definition: Plots.h:25
DAS::pt_edges
static const std::vector< double > pt_edges
Definition: binnings.h:33
DAS::RecEvent
Definition: Event.h:52
DAS::PUstaub::Plots::pthatMax
std::unique_ptr< TH1F > pthatMax
Definition: Plots.h:24
DAS::nMjjBins
static const int nMjjBins
Definition: binnings.h:40
Event.h
DAS::AbstractEvent::weights
Weights weights
e.g. cross section normalisation
Definition: Event.h:23
DAS::PUstaub::Plots::genht
std::unique_ptr< TH1F > genht
Definition: Plots.h:24
Jet.h
DAS::PUstaub::Plots::Write
void Write(TDirectory *d)
Definition: Plots.h:108
DAS::PUstaub::Plots::genptLogw
std::unique_ptr< TH2F > genptLogw
Definition: Plots.h:25
btvExample_106X.data
data
Definition: btvExample_106X.py:10
DAS::PUstaub::Plots::rechtLogw
std::unique_ptr< TH2F > rechtLogw
Definition: Plots.h:25
DAS::PileUp
Definition: Event.h:98
Ntupliser_cfg.genjets
genjets
Definition: Ntupliser_cfg.py:272
Ntupliser_cfg.jets
string jets
Definition: Ntupliser_cfg.py:41
DAS::PUstaub::Plots::FillObsWgt
void FillObsWgt(std::unique_ptr< TH2F > &ptLogw, std::unique_ptr< TH2F > &mjjLogw, std::unique_ptr< TH2F > &htLogw, std::unique_ptr< TH1F > &ht, const std::vector< Jet > &jets, float evW)
Definition: Plots.h:60
DAS::PUstaub::Plots::genhtLogw
std::unique_ptr< TH2F > genhtLogw
Definition: Plots.h:25
binnings.h
DAS::PUstaub::Plots::operator()
void operator()(const std::vector< GenJet > &genjets, const std::vector< RecJet > &recjets, const GenEvent &genEvt, const RecEvent &recEvt, const PileUp &pileup)
Definition: Plots.h:91
DAS::PUstaub::Plots
Definition: Plots.h:20
DAS::PUstaub
Definition: applyPUcleaning.cc:36
DAS::PUstaub::nPtHatBins
static const int nPtHatBins
Definition: Plots.h:18
Ntupliser_cfg.recjets
recjets
Definition: Ntupliser_cfg.py:273
DAS::Mjj_edges
static const std::vector< double > Mjj_edges
Definition: binnings.h:34
DAS::PUstaub::Plots::recht
std::unique_ptr< TH1F > recht
Definition: Plots.h:24
Di.h
DAS::nPtBins
static const int nPtBins
Definition: binnings.h:39
pileup
DAS::PileUp pileup
Definition: classes.h:27
DAS::PUstaub::Plots::pthatME
std::unique_ptr< TH1F > pthatME
Definition: Plots.h:24
DAS::PUstaub::Plots::recptLogw
std::unique_ptr< TH2F > recptLogw
Definition: Plots.h:25
DAS::PileUp::pthats
std::vector< float > pthats
all hard scales found in PU
Definition: Event.h:106
DAS::GenEvent::hard_scale
float hard_scale
hard scale, corresponding to pthat in Pythia 8
Definition: Event.h:41
DAS::PUstaub::Plots::name
TString name
Definition: Plots.h:22
DAS::PUstaub::Plots::genmjjLogw
std::unique_ptr< TH2F > genmjjLogw
Definition: Plots.h:25
DAS::PUstaub::Plots::recmjjLogw
std::unique_ptr< TH2F > recmjjLogw
Definition: Plots.h:25
DAS::GenEvent
Definition: Event.h:38