9std::shared_ptr<TH2D>
MonteCarlo(std::function<std::pair<double, double>(TH1 *, TRandom3 &)> func, TH1 *system,
10 size_t ntoys, Bool_t draw,
const Bool_t weight, TCanvas *c1)
13 rndgen.SetSeed(0430204771);
16 c1 =
new TCanvas(
"montecarlo",
"Monte-Carlo Experiment", 1280, 720);
20 auto UpdateCanvas = [&]() {
24 gSystem->ProcessEvents();
35 auto pad_input = std::make_unique<TPad>(
"pad_input",
"Experiment", 0, 0, 0.5, 1);
37 auto pad_results = std::make_unique<TPad>(
"pad_results",
"Observations", 0.5, 0, 1, 1);
39 auto hist_results = std::make_shared<TH2D>(
"mc_results",
"Monte-Carlo Results", 100, 0, 0, 100, 0, 0);
40 hist_results->SetCanExtend(TH1::kAllAxes);
41 hist_results->Sumw2();
43 for (
size_t i = 0; i < ntoys; ++i) {
44 TH1 *copy =
static_cast<TH1 *
>(system->Clone());
45 std::pair<double, double> result = func(copy, rndgen);
47 hist_results->Fill(result.first, result.second, result.second);
49 hist_results->Fill(result.first, result.second);
52 if ((i && (i % 200 == 0)) || i == ntoys) {
54 double min = system->GetMinimum() == 0 ? system->GetMinimum(0) : system->GetMinimum();
55 double max = system->GetMaximum() == 0 ? system->GetMaximum(0) : system->GetMaximum();
57 system->GetBinWithContent(min, minbin);
59 system->GetBinWithContent(max, maxbin);
60 copy->SetMinimum(min - 5 * system->GetBinError(minbin));
61 copy->SetMaximum(max + 3 * system->GetBinError(maxbin));
78 hist_results->Draw(
"COLZ 0");
std::shared_ptr< TH2D > MonteCarlo(std::function< std::pair< double, double >(TH1 *, TRandom3 &)> func, TH1 *system, size_t ntoys, Bool_t draw, const Bool_t weight, TCanvas *c1)