#include "IntSpline.hh" #include "TStyle.h" #include "TLatex.h" #include "TCanvas.h" #include "TPaveStats.h" #include #include using namespace std; void IntSpline(TH1 &h, TSpline3 &s, int debuglevel) { stringstream oss; oss << h.GetName() << "_norm"; TH1* hcopy = (TH1*)h.Clone(oss.str().c_str()); if (debuglevel >= 1) { cout << "TTS fit started" << endl; } hcopy->Scale(1./hcopy->Integral()); //normalize to get the probability distribution double xleft = hcopy->GetBinLowEdge(1); double xright = hcopy->GetBinLowEdge(hcopy->GetNbinsX())+hcopy->GetBinWidth(hcopy->GetNbinsX()); /* Create the cumulative probability distribution. */ TGraph *g_int = new TGraph(); g_int->SetPoint(0,hcopy->GetBinLowEdge(1),0); for (int ii = 1; ii <= hcopy->GetNbinsX(); ii++){ g_int->SetPoint(g_int->GetN(),hcopy->GetBinLowEdge(ii+1),g_int->GetY()[g_int->GetN()-1]+hcopy->GetBinContent(ii)); } //For visual purposes - normalize histogram to account for the bin size hcopy->Scale(1./hcopy->GetBinWidth(1)); /* Create the spline for cumulative probability distribution. Left and right conditions - the derivative (probability distribution) is 0. This is OK since the background plateau is negligible (far from peak). */ _spline_int = new TSpline3("spline_int",g_int,"b2e2",0,0); _spline_int->SetLineColor(3); /* Here we get the numerical derivative from cubic spline. In principle, it is just quadratic spline, so it could be calculated numerically from _spline_int (cubic spline). However, it seems spline2 are not enough implemented in ROOT (spline creation with known coefficients is not possible, or derivative of spline3 does not exist etc), so it will take some time to implement this. */ /* First the function is created from spline */ TF1 *f_int = new TF1("f_int",funcfluxwrapper_spline_int,xleft,xright,0); f_int->SetLineColor(2); f_int->SetNpx(100); TGraph *g_h = new TGraph(f_int,"d"); //graph with derivative - probability distribution function! g_h->SetName("g_h"); stringstream oss_spline; oss_spline << hcopy->GetName() << "_spline"; TSpline3 *s_h = new TSpline3(oss_spline.str().c_str(),g_h,"b2e2",0,0); s_h->SetLineColor(3); s = *s_h; delete f_int; delete g_h; delete g_int; delete hcopy; delete s_h; //return *_spline_int; } Double_t funcfluxwrapper_spline_int(Double_t *x, Double_t *par){ if (x[0]<_spline_int->GetXmin()) return 0; if (x[0]>_spline_int->GetXmax()) return 0; return _spline_int->Eval(x[0]); }