-
Notifications
You must be signed in to change notification settings - Fork 3
/
collect_systematics.cc
212 lines (162 loc) · 4.7 KB
/
collect_systematics.cc
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "TFile.h"
#include "TProfile.h"
#include "TGraphErrors.h"
#include "TGraph2D.h"
#include "TMatrixD.h"
#include <string>
using namespace std;
//----------------------------------------------------------------------------------------------------
TGraphErrors* MakeDiff(const TProfile *p1, const TProfile *p2)
{
TGraphErrors *g = new TGraphErrors;
for (int bi = 1; bi <= p1->GetNbinsX(); ++bi)
{
const double xi = p1->GetBinCenter(bi);
const double xi_unc = p1->GetBinWidth(bi) / 2.;
const double c1 = p1->GetBinContent(bi);
const double c1_unc = p1->GetBinError(bi);
const double c2 = p2->GetBinContent(bi);
int idx = g->GetN();
g->SetPoint(idx, xi, c1 - c2);
g->SetPointError(idx, xi_unc, c1_unc);
}
return g;
}
//----------------------------------------------------------------------------------------------------
TGraphErrors* MakeCombination(const vector<TGraphErrors *> &vp)
{
TGraphErrors *g = new TGraphErrors(*vp[0]);
for (int i = 0; i <= g->GetN(); ++i)
{
double s2 = 0.;
for (unsigned int ci = 0; ci < vp.size(); ++ci)
{
const double c = vp[ci]->GetY()[i];
s2 += c*c;
}
g->GetY()[i] = sqrt(s2);
}
return g;
}
//----------------------------------------------------------------------------------------------------
TGraph2D* MakeCorrelation(const vector<TGraphErrors *> &vp)
{
TGraph *g_ref = vp[0];
int dim = g_ref->GetN();
TMatrixD V(dim, dim);
for (const auto c : vp)
{
for (int i = 0; i < dim; ++i)
{
for (int j = 0; j < dim; ++j)
{
const double ci = c->GetY()[i];
const double cj = c->GetY()[j];
V(i, j) += ci * cj;
}
}
}
TMatrixD C(dim, dim);
for (int i = 0; i < dim; ++i)
{
for (int j = 0; j < dim; ++j)
{
const double denom = V(i, i) * V(j, j);
C(i, j) = (denom > 0.) ? V(i, j) / sqrt(denom) : 0.;
}
}
TGraph2D *g2_corr = new TGraph2D();
g2_corr->SetTitle(";#xi;#xi");
for (int i = 0; i < dim; ++i)
{
for (int j = 0; j < dim; ++j)
{
const double xi = g_ref->GetX()[i];
const double xj = g_ref->GetX()[j];
const int idx = g2_corr->GetN();
g2_corr->SetPoint(idx, xi, xj, C(i, j));
}
}
return g2_corr;
}
//----------------------------------------------------------------------------------------------------
void PrintUsage()
{
printf("USAGE: collect_systematics <period>\n");
}
//----------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
// parse command line
if (argc != 2)
{
PrintUsage();
return 1;
}
string period = argv[1];
// config
string dir = "./";
struct Scenario
{
string name;
string simu_eff, simu_none;
};
vector<Scenario> scenarios = {
{ "alig-x-sym", "proton_reco_misalignment/misalignment_x_sym_validation.root", "proton_reco_misalignment/misalignment_none_validation.root" },
{ "alig-x-asym", "proton_reco_misalignment/misalignment_x_asym_validation.root", "proton_reco_misalignment/misalignment_none_validation.root" },
{ "opt-Lx", "proton_reco_optics/optics_Lx_1_validation.root", "proton_reco_optics/optics_none_1_validation.root" },
{ "opt-Lpx", "proton_reco_optics/optics_Lpx_1_validation.root", "proton_reco_optics/optics_none_1_validation.root" },
{ "opt-xd", "proton_reco_optics/optics_xd_1_validation.root", "proton_reco_optics/optics_none_1_validation.root" },
};
vector<string> elements = {
"single rp/2",
"single rp/3",
"single rp/23",
"single rp/102",
"single rp/103",
"single rp/123",
"multi rp/0",
"multi rp/1",
};
// prepare output
TFile *f_out = TFile::Open("collect_systematics.root", "recreate");
// process all elements
for (const auto &el : elements)
{
string dn_el = el;
dn_el.replace(dn_el.find('/'), 1, "-");
printf("* %s\n", dn_el.c_str());
TDirectory *d_el = f_out->mkdir(dn_el.c_str());
vector<TGraphErrors *> graphs;
for (const auto &sc : scenarios)
{
TFile *f_in_eff = TFile::Open((dir + sc.simu_eff).c_str());
TFile *f_in_none = TFile::Open((dir + sc.simu_none).c_str());
if (!f_in_eff || !f_in_none)
{
printf("ERROR: cannot open input files\n");
continue;
}
TProfile *p_eff = (TProfile *) f_in_eff->Get((el + "/p_de_xi_vs_xi_simu").c_str());
TProfile *p_none = (TProfile *) f_in_none->Get((el + "/p_de_xi_vs_xi_simu").c_str());
if (!p_eff || !p_none)
{
printf("ERROR: cannot load input objects (scenario %s)\n", sc.name.c_str());
continue;
}
gDirectory = d_el;
TGraphErrors *g_diff = MakeDiff(p_eff, p_none);
g_diff->Write(sc.name.c_str());
graphs.push_back(g_diff);
}
if (!graphs.empty())
{
TGraphErrors *g_comb = MakeCombination(graphs);
g_comb->Write("combined");
MakeCorrelation(graphs)->Write("g2_correlation");
}
}
// clean up
delete f_out;
return 0;
}