HighLAND
BinnedPDF.cxx
1 #include "BinnedPDF.hxx"
2 
3 ///Define the integral of a gaussian normalized to 1, inside each of the nbins
4 //********************************************************************
5 BinnedGaussian::BinnedGaussian(int nbins, Float_t mean, Float_t sigma){
6 //********************************************************************
7 
8  _params.clear();
9  _params.push_back(mean);
10  _params.push_back(sigma);
11 
12  Float_t bin_width = (6*sigma/((Float_t)(nbins-1)));
13  Float_t xmin=mean-3*sigma;
14  Float_t wt=0;
15  // std::cout<<" mean "<<mean<<" xmin "<<xmin<<" ?= "<<mean-nbins*0.5*bin_width<<" binwidth "<<bin_width<<std::endl;
16  for (Int_t i=0;i<nbins;i++){
17  //this is the interval where we want to calculate the integral of N(mean,sigma) =1/sqrt(2pi)sigma exp(-1/2 (t'-mean)^2/sigma^2)
18  Float_t x = xmin + bin_width*(i-1./2);
19  Float_t x1 = xmin + bin_width*(i+1./2);
20  //this is the corresponding interval for the erf function = 2/sqrt(pi) int_0^x exp(-t^2) dt
21  Float_t x_norm=(x-mean)/(sqrt(2)*sigma);
22  Float_t x1_norm=(x1-mean)/(sqrt(2)*sigma);
23  //because erf(infinity)=1 and erf(infinity) is defined as the integral from 0 to infinity,
24  //we must devide by 2 to get back to the chosen normal distribution.
25  Float_t w_erf=(TMath::Erf(x1_norm)-TMath::Erf(x_norm))/2;
26  w_erf /=0.999140440; // since we are considering only 3sigma we need to normalize to 1
27  if(sigma==0) w_erf=1;
28  wt +=w_erf;
29  //std::cout <<"i "<< i << " bincenter " << xmin+bin_width*i << " weight " << w_erf << " sumofweight " << wt << std::endl;
30  _binWeight.push_back(w_erf);
31  _binCenter.push_back(xmin+bin_width*i);
32  }
33 
34 }
std::vector< Float_t > _params
vector of parameters
Definition: BinnedPDF.hxx:40
std::vector< Float_t > _binCenter
vector of bin centers
Definition: BinnedPDF.hxx:37
BinnedGaussian(int nbins, Float_t mean, Float_t sigma)
Define the integral of a gaussian normalized to 1, inside each of the nbins.
Definition: BinnedPDF.cxx:5
std::vector< Float_t > _binWeight
vector of weights
Definition: BinnedPDF.hxx:34