Root ex3
This commit is contained in:
parent
e65ae076ac
commit
9748778393
22
root/macro.C
22
root/macro.C
|
|
@ -1,14 +1,32 @@
|
||||||
#include "TCanvas.h"
|
#include "TCanvas.h"
|
||||||
#include "TROOT.h"
|
#include "TROOT.h"
|
||||||
#include "TH1D.h"
|
#include "TH1D.h"
|
||||||
|
#include "TF1.h"
|
||||||
#include "TFile.h"
|
#include "TFile.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void macro() {
|
void macro() {
|
||||||
TFile* f = new TFile("data.root");
|
TFile* f = new TFile("data.root");
|
||||||
TH1D* h;
|
TH1D* h;
|
||||||
f->GetObject("combined", h);
|
f->GetObject("combined", h);
|
||||||
std::cout << h->GetEntries() << std::endl;
|
TF1* background = new TF1("background", "[0] + x*[1] + [2] * exp(-[3] * x)",
|
||||||
h->Draw(" A ");
|
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() {
|
int main() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user