-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot2DSlice.cpp
More file actions
100 lines (84 loc) · 2.74 KB
/
Plot2DSlice.cpp
File metadata and controls
100 lines (84 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include "json.hh"
#include "TH1D.h"
#include "Plot.h"
#include "Plot2D.h"
#include "Plot2DSlice.h"
#include "Generator.h"
void Plot2DSlice::add(Generator* gen) {
// Discover slices by looping over available keys. Note: The case for these
// keys is not consistent across measurements.
std::string mc_name = sample + "_MC_Slice";
std::string mc_name_lower = sample + "_mc_slice";
std::string data_name = sample + "_data_Slice";
std::string data_name_lower = sample + "_data_slice";
std::vector<std::string> mc_slice_objs;
std::vector<std::string> data_slice_objs;
for (std::string& key : gen->keys) {
if (key.rfind(mc_name, 0) == 0 || key.rfind(mc_name_lower, 0) == 0) {
mc_slice_objs.push_back(key);
}
if (key.rfind(data_name, 0) == 0 || key.rfind(data_name_lower, 0) == 0) {
data_slice_objs.push_back(key);
}
}
assert(mc_slice_objs.size() == data_slice_objs.size());
size_t nfound = mc_slice_objs.size();
// Make sure the requested grid is big enough
assert(nfound <= nrows * ncols);
// Check consistency of slices across generators
if (nslices < 0) {
std::cout << sample << ": Found " << nfound << " slices." << std::endl;
nslices = nfound;
}
else {
assert(nfound == nslices);
}
// Check number of annotations (if there are any) matches
if (!annotate.empty()) {
assert(nfound == annotate.size());
}
// Sort by name
std::sort(mc_slice_objs.begin(), mc_slice_objs.end());
std::sort(data_slice_objs.begin(), data_slice_objs.end());
// Populate initial slice plots
if (plots.empty()) {
plots.resize(nslices);
for (size_t i=0; i<nslices; i++) {
if (!annotate.empty()) {
json::Value va(annotate[i]);
subplot_config.setMember("annotate", va);
}
json::Value vf(fontsize);
subplot_config.setMember("fontsize", vf);
plots[i] = new Plot1D(subplot_config);
TH1D* h = (TH1D*) gen->getHistogram(data_slice_objs[i]);
h->SetLineColor(kBlack);
h->SetLineWidth(1);
if (ymax > -1) {
plots[i]->ymax = ymax;
}
// Set axis labels automatically
if (ylabel.empty()) {
ylabel = h->GetYaxis()->GetTitle();
}
if (xlabel.empty()) {
xlabel = h->GetXaxis()->GetTitle();
}
h->GetXaxis()->SetTitle("");
h->GetYaxis()->SetTitle("");
plots[i]->hdata = h;
}
}
// Add MC histograms
for (size_t i=0; i<nslices; i++) {
TH1D* hmc = dynamic_cast<TH1D*>(gen->getHistogram(mc_slice_objs[i]));
std::string title = gen->title + " (#chi^{2}=" + gen->getChi2String(sample) + ")";
hmc->SetTitle(title.c_str());
hmc->SetLineWidth(1);
plots[i]->lines.push_back(hmc);
}
}