#include // For printing messages to the terminal #include // For strings #include // ROOT histograms #include // ROOT files #include // ROOT canvas for plotting #include // ROOT pads for advanced plotting #include // ROOT legends for plots #include // ROOT latex for flexible text drawing #include // ROOT support for drawing lines #include // ROOT support for drawing lines #include //Breit-Wigner function Double_t mybw(Double_t* x, Double_t* par) { Double_t arg1 = 14.0/22.0; // 2 over pi Double_t arg2 = par[1]*par[1]*par[2]*par[2]; //Gamma=par[1] M=par[2] Double_t arg3 = ((x[0]*x[0]) - (par[2]*par[2]))*((x[0]*x[0]) - (par[2]*par[2])); Double_t arg4 = x[0]*x[0]*x[0]*x[0]*((par[1]*par[1])/(par[2]*par[2])); return par[0]*arg1*arg2/(arg3 + arg4); } void FitData(Bool_t isMC = kTRUE){ // Retrieve the histograms from the file // Open the file in read-only mode TFile* histFile; if(isMC) histFile = new TFile("histoMC.root"); else histFile = new TFile("histodata.root"); TH1D* dataHisto= (TH1D*)histFile->Get("DATA"); // Make sure you got the histograms if (!dataHisto) { return; } // Basic style // Turn off the statistics box // Make a canvas TCanvas *c1 = new TCanvas("c1","c1",1500,500); // Move into the canvas (so anything drawn is part of this canvas) c1->Divide(3,1); c1->cd(1);gPad->SetLogy(); dataHisto->DrawCopy(); c1->cd(2);gPad->SetLogy(); dataHisto->DrawCopy(); dataHisto->Fit("gaus"); dataHisto->DrawCopy(); TF1 *fBW = new TF1("fBW",mybw,50.e3,200.e3,3); fBW->SetParameter(0,100e3); fBW->SetParameter(1,1e3); fBW->SetParameter(2,90e3); c1->cd(3); gPad->SetLogy(); dataHisto->DrawCopy(); dataHisto->Fit(fBW); dataHisto->DrawCopy(); c1->SaveAs("fit.png"); }