gausTF1.cxx
Go to the documentation of this file.
1 // gausTF1.h
2 //
3 // David Adams
4 // May 2018
5 //
6 // Create TF1 for Gaussian distribution.
7 //
8 // Normalized so that height = pf->Eval(0).
9 
10 #ifndef gausTF1_H
11 #define gausTF1_H
12 
13 #include "TF1.h"
14 #include <string>
15 
16 using std::string;
17 
18 double gausFunction(double* x, double* pars) {
19  double pos = x[0];
20  double height = pars[0];
21  double mean = pars[1];
22  double sigma = pars[2];
23  if ( sigma <= 0.0 ) return 0;
24  double rat = (pos-mean)/sigma;
25  return height*exp(-0.5*rat*rat);
26 }
27 
28 TF1* gausTF1(double heightIn, double meanIn, double sigmaIn, std::string fname) {
29  double height = heightIn != 0.0 ? heightIn : 1.0;
30  double sigma = sigmaIn > 0.0 ? sigmaIn : 1.0;
31  double mean = meanIn;
32  string sform = "[0]*exp(-0.5*((x-[1])/[2])*((x-[1])/[2]))";
33  TF1* pf = new TF1(fname.c_str(), sform.c_str(), -10, 10);
34  //TF1* pf = new TF1(fname.c_str(), gausFunction, -10, 10, 3);
35  pf->SetParName(0, "Height");
36  pf->SetParName(1, "Mean");
37  pf->SetParName(2, "Sigma");
38  pf->SetParameter(0, height);
39  pf->SetParameter(1, mean);
40  pf->SetParameter(2, sigma);
41  double sigmaMin = 0.0;
42  double sigmaMax = 1.e10;
43  if ( sigmaIn > 0.0 ) {
44  sigmaMin = 0.1*sigmaIn;
45  sigmaMax = 10.0*sigmaIn;
46  }
47  pf->SetParLimits(2, sigmaMin, sigmaMax);
48  if ( sigmaIn > 0.0 ) pf->SetParLimits(2, 0.1*sigma, 10*sigma);
49  return pf;
50 }
51 
52 
53 #endif
std::string string
Definition: nybbler.cc:12
TF1 * gausTF1(double heightIn, double meanIn, double sigmaIn, std::string fname)
Definition: gausTF1.cxx:28
list x
Definition: train.py:276
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:16
double gausFunction(double *x, double *pars)
Definition: gausTF1.cxx:18