From 974877839367f31224ec220d64fe1df933caa5f5 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 7 May 2019 13:30:45 +0200 Subject: [PATCH] Root ex3 --- root/macro.C | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/root/macro.C b/root/macro.C index 832b782..45b6a44 100644 --- a/root/macro.C +++ b/root/macro.C @@ -1,14 +1,32 @@ #include "TCanvas.h" #include "TROOT.h" #include "TH1D.h" +#include "TF1.h" #include "TFile.h" +#include + +using namespace std; void macro() { TFile* f = new TFile("data.root"); TH1D* h; f->GetObject("combined", h); - std::cout << h->GetEntries() << std::endl; - h->Draw(" A "); + TF1* background = new TF1("background", "[0] + x*[1] + [2] * exp(-[3] * x)", + 1, 299); + TF1* gauss = new TF1("gauss", "[0]*exp(-0.5 * (x-[1])^2/[2]^2)", + 140, 210); + TF1* combined = new TF1("combined", "background+gauss", 0, 300); + h->Fit(combined, "", "", 0, 300); + gauss->SetParameters(0.013, 170, 20); + combined->SetParameter(4, 0.004); + combined->SetParameter(5, 173); + combined->SetParameter(6, 10); + cout << "X^2: " << h->Chisquare(combined) << endl; + //cout << background->GetParameters() << endl; + background->SetLineColor(kRed); + h->Draw(); + //gauss->Draw("Same"); + combined->Draw("Same"); } int main() {