2050 std::map<int, TH1*> data_hists
2058 for (
auto it = data_hists.begin(); it != data_hists.end(); ++it ) {
2074 nBins += it->second->GetNbinsX();
2077 TH2D selection_cov(
"SelectionCov",
"", nBins, 0, nBins, nBins, 0, nBins);
2080 std::map<int, size_t> sample_bins;
2082 nBins += it->second[0].size();
2083 sample_bins[it->first] = it->second[0].size();
2087 std::map<int, std::vector<double>> best_fit_errs;
2092 best_fit_errs[it->first]
2093 = std::vector<double>(sample_bins[it->first], 0.);
2105 TH2D interaction_cov(
"interaction_cov",
"", nBins, 0, nBins, nBins, 0, nBins);
2106 std::map<int, std::vector<double>> best_fit_inc_truth;
2107 std::map<int, std::vector<double>> best_fit_xsec_truth;
2108 std::map<int, std::vector<double>> best_fit_inc_errs;
2109 std::map<int, std::vector<double>> best_fit_xsec_errs;
2112 std::map<int, size_t> xsec_bins;
2115 nBins += it->second->GetNbinsX();
2116 xsec_bins[
s] = it->second->GetNbinsX();
2118 best_fit_inc_truth[
s] = std::vector<double>(xsec_bins[
s], 0.);
2119 best_fit_xsec_truth[
s] = std::vector<double>(xsec_bins[
s], 0.);
2120 best_fit_inc_errs[
s] = std::vector<double>(xsec_bins[
s], 0.);
2121 best_fit_xsec_errs[
s] = std::vector<double>(xsec_bins[
s], 0.);
2123 for (
size_t i = 0; i < xsec_bins[
s]; ++i) {
2124 best_fit_inc_truth[
s][i] = it->second->GetBinContent(i+1);
2130 TH2D xsec_cov(
"xsec_cov",
"", nBins, 0, nBins, nBins, 0, nBins);
2131 TH2D xsec_corr(
"xsec_corr",
"", nBins, 0, nBins, nBins, 0, nBins);
2132 xsec_cov.SetTitle(
";Cross Section Bin;Cross section Bin");
2133 xsec_cov.SetTitleSize(.05,
"XY");
2134 xsec_cov.GetXaxis()->SetTitleOffset(.8);
2135 xsec_corr.SetTitle(
";Cross Section Bin;Cross section Bin");
2136 xsec_corr.SetTitleSize(.05,
"XY");
2137 xsec_corr.GetXaxis()->SetTitleOffset(.8);
2138 xsec_corr.SetMaximum(1.);
2139 xsec_corr.SetMinimum(-1.);
2140 TMatrixD xsec_cov_matrix(nBins, nBins);
2142 std::map<int, std::vector<double>> mean_xsecs;
2144 for (
auto it = truth_xsec_hists.begin(); it != truth_xsec_hists.end(); ++it) {
2145 std::vector<TH1 *> xsec_hists_i = it->second;
2147 mean_xsecs[it->first] = std::vector<double>(xsec_bins[it->first], 0.);
2148 for (
size_t i = 0; i < xsec_bins[it->first]; ++i) {
2149 mean_xsecs[it->first][i] += xsec_hists_i[
z]->GetBinContent(i+1)/
fNThrows;
2158 TH1D * best_fit = it->second;
2160 std::vector<TH1*> & temp_throws = throw_hists[
selection_ID];
2161 for (
int i = 1; i <= best_fit->GetNbinsX(); ++i) {
2162 double best_fit_val_i = best_fit->GetBinContent(i);
2167 TH1D * best_fit_2 = it2->second;
2168 int selection_ID_2 = it2->first;
2169 std::vector<TH1*> & temp_throws_2 = throw_hists[selection_ID_2];
2170 for (
int j = 1; j <= best_fit_2->GetNbinsX(); ++j) {
2171 double best_fit_val_j = best_fit_2->GetBinContent(j);
2172 double val = (best_fit_val_i - temp_throws[
z]->GetBinContent(i))*
2173 (best_fit_val_j - temp_throws_2[
z]->GetBinContent(j));
2174 selection_cov.SetBinContent(
2175 bin_i, bin_j, (val/temp_throws.size() +
2176 selection_cov.GetBinContent(bin_i, bin_j)));
2186 std::vector<TH1 *> throw_hists_i = truth_throw_hists[it->first];
2188 for (
size_t i = 0; i < sample_bins[it->first]; ++i) {
2193 std::vector<TH1 *> throw_hists_j = truth_throw_hists[it2->first];
2194 for (
size_t j = 0; j < sample_bins[it2->first]; ++j) {
2198 = (throw_hists_i[
z]->GetBinContent(i+1) - best_fit_val_i)*
2199 (throw_hists_j[
z]->GetBinContent(j+1) - best_fit_val_j);
2200 interaction_cov.SetBinContent(
2202 (interaction_cov.GetBinContent(bin_i, bin_j) +
2203 val/throw_hists_i.size()));
2204 if (bin_i == bin_j && (
z == fNThrows - 1)) {
2205 best_fit_errs[it->first][i]
2206 = sqrt(interaction_cov.GetBinContent(bin_i, bin_j));
2220 for (
auto it = truth_inc_hists.begin(); it != truth_inc_hists.end(); ++it) {
2221 std::vector<TH1 *> xsec_hists_i = truth_xsec_hists[it->first];
2222 for (
size_t i = 0; i < xsec_bins[it->first]; ++i) {
2224 double best_fit_xsec_i = best_fit_xsec_truth[it->first][i];
2227 for (
auto it2 = truth_inc_hists.begin(); it2 != truth_inc_hists.end();
2229 std::vector<TH1 *> xsec_hists_j = truth_xsec_hists[it2->first];
2230 for (
size_t j = 0; j < xsec_bins[it2->first]; ++j) {
2232 double best_fit_xsec_j = best_fit_xsec_truth[it2->first][j];
2235 = (xsec_hists_i[
z]->GetBinContent(i+1) - best_fit_xsec_i)*
2236 (xsec_hists_j[
z]->GetBinContent(j+1) - best_fit_xsec_j);
2237 xsec_cov.SetBinContent(
2239 (xsec_cov.GetBinContent(bin_i, bin_j) +
2241 if (bin_i == bin_j && (
z == fNThrows - 1)) {
2242 best_fit_xsec_errs[it->first][i]
2243 = sqrt(xsec_cov.GetBinContent(bin_i, bin_j));
2253 for (
int i = 0; i <
nBins; ++i) {
2254 for (
int j = 0; j <
nBins; ++j) {
2255 xsec_cov_matrix[i][j] = xsec_cov.GetBinContent(i+1, j+1);
2257 xsec_cov.GetBinContent(i+1, j+1)/
2258 sqrt(xsec_cov.GetBinContent(i+1, i+1)*
2259 xsec_cov.GetBinContent(j+1, j+1));
2260 xsec_corr.SetBinContent(i+1, j+1, corr_val);
2263 xsec_cov_matrix.Invert();
2267 selection_cov.Write();
2268 interaction_cov.Write();
2272 TCanvas cXSecCorr(
"cXSecCorr",
"");
2273 xsec_corr.Draw(
"colz");
2278 double nominal_xsec_chi2 = 0.;
2279 double fake_xsec_chi2 = 0.;
2281 for (
auto it = best_fit_xsec_truth.
begin(); it != best_fit_xsec_truth.end();
2283 for (
size_t i = 0; i < it->second.size(); ++i) {
2284 double measured_val_i = it->second[i];
2285 double mc_val_i =
fNominalXSecs[it->first]->GetBinContent(i+1);
2290 for (
auto it2 = best_fit_xsec_truth.
begin();
2291 it2 != best_fit_xsec_truth.end();
2293 for (
size_t j = 0; j < it2->second.size(); ++j) {
2294 double measured_val_j = it2->second[j];
2295 double mc_val_j =
fNominalXSecs[it2->first]->GetBinContent(j+1);
2299 nominal_xsec_chi2 += ((measured_val_i - mc_val_i)*
2300 xsec_cov_matrix[bin_i][bin_j]*
2301 (measured_val_j - mc_val_j));
2303 fake_xsec_chi2 += ((measured_val_i - fake_val_i)*
2304 xsec_cov_matrix[bin_i][bin_j]*
2305 (measured_val_j - fake_val_j));
2317 for (
auto it = data_hists.begin(); it != data_hists.end(); ++it) {
2318 int selection_ID = it->first;
2319 std::vector<TH1*>
hists = throw_hists.at(selection_ID);
2323 TCanvas cThrow(canvas_name.c_str(),
"");
2327 auto data_hist = it->second;
2328 std::vector<double> xs, xs_width;
2329 std::vector<double>
ys, errs;
2335 sqrt(selection_cov.GetBinContent(bin_count+i, bin_count+i)));
2336 xs.push_back(data_hist->GetBinCenter(i));
2337 xs_width.push_back(data_hist->GetBinWidth(i)/2.);
2340 TGraphAsymmErrors throw_gr(data_hist->GetNbinsX(),
2342 &xs_width[0], &xs_width[0], &errs[0], &errs[0]);
2345 throw_gr.GetXaxis()->SetTitle(data_hist->GetXaxis()->GetTitle());
2346 throw_gr.SetFillStyle(3144);
2347 throw_gr.SetFillColor(kRed);
2349 throw_gr.Draw(
"same a2");
2350 data_hist->Draw(
"same e1");
2354 bin_count += data_hist->GetNbinsX();
2358 for (
auto it = truth_throw_hists.begin(); it != truth_throw_hists.end(); ++it) {
2359 int sample_ID = it->first;
2361 std::vector<double> xs, xs_width;
2362 for (
size_t i = 0; i < sample_bins[it->first]; ++i) {
2363 xs.push_back(i + 0.5);
2364 xs_width.push_back(.5);
2368 TH1D temp_nominal(name.c_str(),
"", xs.size(), 0, xs.size());
2370 TH1D
dummy(dummy_name.c_str(),
"", xs.size(), 0, xs.size());
2372 dummy.GetXaxis()->SetBinLabel(1,
"Underflow");
2373 dummy.GetXaxis()->SetBinLabel(
dummy.GetNbinsX(),
"Overflow");
2374 for (
int i = 2; i <
dummy.GetNbinsX(); ++i) {
2375 std::ostringstream low_stream, high_stream;
2376 low_stream.precision(2);
2377 high_stream.precision(2);
2378 low_stream << std::fixed <<
2379 fSamples[sample_ID][0][i-1].RangeLowEnd();
2382 fSamples[sample_ID][0][i-1].RangeHighEnd();
2385 label += high_stream.str();
2390 dummy.GetXaxis()->SetBinLabel(i, label.c_str());
2394 dummy.GetXaxis()->SetBinLabel(1,
"");
2398 std::vector<std::vector<ThinSliceSample>> & samples_vec_2D
2400 for (
size_t i = 0; i < samples_vec_2D.size(); ++i) {
2401 for (
size_t j = 0; j < samples_vec_2D[i].size(); ++j) {
2402 temp_nominal.AddBinContent(j+1, samples_vec_2D[i][j].GetNominalFlux());
2407 for (
size_t i = 0; i < sample_bins[it->first]; ++i) {
2411 if (temp_nominal.GetBinContent(i+1) >
max)
2412 max = temp_nominal.GetBinContent(i+1);
2417 TCanvas cThrow(canvas_name.c_str(),
"");
2419 TGraphAsymmErrors throw_gr(xs.size(),
2421 &xs_width[0], &xs_width[0],
2422 &best_fit_errs[it->first][0],
2423 &best_fit_errs[it->first][0]);
2424 throw_gr.SetFillStyle(3144);
2425 throw_gr.SetFillColor(kRed);
2426 throw_gr.SetMinimum(0.);
2427 throw_gr.SetMaximum(1.5*max);
2428 dummy.SetMaximum(1.5*max);
2431 throw_gr.Draw(
"same 2");
2434 temp_nominal.SetMarkerColor(kBlue);
2435 temp_nominal.SetMarkerStyle(20);
2436 temp_nominal.Draw(
"same p");
2439 leg.AddEntry(&throw_gr,
"Throws",
"lpf");
2440 leg.AddEntry(&temp_nominal,
"Nominal",
"p");
2443 name =
"hVaried" +
fSamples[sample_ID][0][0].GetName();
2444 TH1D * temp_varied = (TH1D*)temp_nominal.Clone(name.c_str());
2445 for (
size_t i = 0; i < xs.size(); ++i) {
2446 temp_varied->SetBinContent(
2449 temp_varied->SetMarkerColor(kBlack);
2450 temp_varied->SetMarkerStyle(20);
2451 temp_varied->Draw(
"same p");
2452 leg.AddEntry(temp_varied,
"Fake Data",
"p");
2458 bin_count += xs.size();
2461 for (
auto it = best_fit_xsec_truth.begin(); it != best_fit_xsec_truth.end();
2463 int sample_ID = it->first;
2465 std::vector<double> xs, xs_width;
2466 for (
size_t i = 0; i < xsec_bins[sample_ID]; ++i) {
2467 xs.push_back(i + 0.5);
2468 xs_width.push_back(.5);
2474 TCanvas cThrow(canvas_name.c_str(),
"");
2478 TH1D
dummy(dummy_name.c_str(),
"", xs.size(), 0, xs.size());
2479 for (
int i = 1; i <=
dummy.GetNbinsX(); ++i) {
2480 std::ostringstream low_stream, high_stream;
2481 low_stream.precision(2);
2482 high_stream.precision(2);
2483 low_stream << std::fixed <<
2484 fSamples[sample_ID][0][i].RangeLowEnd();
2487 fSamples[sample_ID][0][i].RangeHighEnd();
2490 label += high_stream.str();
2495 dummy.GetXaxis()->SetBinLabel(i, label.c_str());
2498 TGraphAsymmErrors throw_gr(xs.size(),
2499 &xs[0], &best_fit_xsec_truth[it->first][0],
2500 &xs_width[0], &xs_width[0],
2501 &best_fit_xsec_errs[it->first][0],
2502 &best_fit_xsec_errs[it->first][0]);
2505 for (
size_t i = 0; i < best_fit_xsec_truth[it->first].size(); ++i) {
2506 if ((best_fit_xsec_truth[it->first][i] +
2507 best_fit_xsec_errs[it->first][0]) >
max) {
2508 max = (best_fit_xsec_truth[it->first][i] +
2509 best_fit_xsec_errs[it->first][0]);
2514 throw_gr.SetMarkerStyle(20);
2515 throw_gr.SetMinimum(0.);
2516 dummy.SetMaximum(1.5*max);
2517 dummy.SetMinimum(0.);
2519 dummy.GetXaxis()->SetTitle(
"Kinetic Energy (MeV)");
2520 dummy.GetYaxis()->SetTitle(
"#sigma (mb)");
2522 throw_gr.Draw(
"same 2");
2526 std::vector<double> nominal_xsec_vals;
2527 for (
size_t i = 0; i < xs.size(); ++i) {
2528 nominal_xsec_vals.push_back(
2531 TGraph nominal_gr(xs.size(), &xs[0], &nominal_xsec_vals[0]);
2532 nominal_gr.SetMarkerColor(kBlue);
2533 nominal_gr.SetMarkerStyle(20);
2534 nominal_gr.Draw(
"same p");
2537 leg.AddEntry(&throw_gr,
"Measured",
"lpf");
2539 leg.AddEntry(&nominal_gr,
"Nominal",
"p");
2543 std::vector<double> fake_xsec_vals;
2545 for (
size_t i = 0; i < xs.size(); ++i) {
2550 fake_xsec_vals.push_back(
2554 TGraph * fake_gr =
new TGraph(xs.size(), &xs[0], &fake_xsec_vals[0]);
2556 fake_gr->SetMarkerColor(kRed);
2557 fake_gr->SetMarkerStyle(20);
2558 fake_gr->Draw(
"same p");
2559 leg.AddEntry(fake_gr,
"Fake Data",
"p");
2563 chi2_str.Form(
"Nominal #chi^{2} = %.2f", nominal_xsec_chi2);
2564 leg.AddEntry((TObject*)0x0, chi2_str,
"");
2572 TString fake_chi2_str;
2573 fake_chi2_str.Form(
"Fake Data #chi^{2} = %.2f", fake_xsec_chi2);
2574 leg.AddEntry((TObject*)0x0, fake_chi2_str,
"");
2579 throw_gr.Write(gr_name.c_str());
2582 TVectorD fake_chi2_out(1);
2583 fake_chi2_out[0] = fake_xsec_chi2;
2584 fake_chi2_out.Write(
"FakeDataChi2");
2586 TVectorD nominal_chi2_out(1);
2587 nominal_chi2_out[0] = nominal_xsec_chi2;
2588 nominal_chi2_out.Write(
"NominalChi2");
std::map< int, TH1 * > fBestFitXSecs
std::map< int, std::vector< std::vector< ThinSliceSample > > > fSamples
std::map< int, TH1 * > fFakeDataXSecs
std::map< int, TH1D * > fBestFitSelectionHists
std::map< int, TH1 * > fNominalXSecs
std::map< int, TH1 * > & GetSelectionHists()
std::map< int, std::vector< double > > fBestFitTruthVals
std::map< int, TH1 * > fBestFitIncs
std::string fFakeDataRoutine
std::map< int, TH1 * > & GetRebinnedSelectionHists()
static int max(int a, int b)
std::string & GetSelectionName(int id)
cet::LibraryManager dummy("noplugin")
std::map< int, std::vector< double > > fFakeDataScales
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::map< int, bool > fIsSignalSample
static constexpr double ys
ThinSliceDataSet fDataSet