Typedefs | Functions
test_GausRmsFitter.cxx File Reference
#include "../GausRmsFitter.h"
#include "../gausTF1.h"
#include "TH1F.h"
#include "TF1.h"
#include "TCanvas.h"
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cassert>
#include <vector>

Go to the source code of this file.

Typedefs

using DoubleVector = std::vector< double >
 

Functions

int test_GausRmsFitter (int dbg, double satfrac)
 
int main (int narg, const char *argc[])
 

Typedef Documentation

using DoubleVector = std::vector<double>

Definition at line 29 of file test_GausRmsFitter.cxx.

Function Documentation

int main ( int  narg,
const char *  argc[] 
)

Definition at line 98 of file test_GausRmsFitter.cxx.

98  {
99  int dbg = 0;
100  DoubleVector satfracs = {0.0, 0.1, 0.2, 0.5};
101  if ( narg > 1 ) {
102  string sarg = argc[1];
103  if ( sarg == "-h" ) {
104  cout << "Usage: " << argc[0] << " [DBG] [F1 F2 ...]" << endl;
105  return 0;
106  }
107  istringstream ssin(sarg);
108  ssin >> dbg;
109  }
110  if ( narg > 2 ) {
111  string sarg = argc[2];
112  satfracs.clear();
113  for ( int iarg=2; iarg<narg; ++iarg ) {
114  double satfrac = 0.0;
115  istringstream ssin(argc[iarg]);
116  ssin >> satfrac;
117  satfracs.push_back(satfrac);
118  }
119  }
120  int err = 0;
121  for ( double satfrac : satfracs ) err += test_GausRmsFitter(dbg, satfrac);
122  return err;
123 }
bool dbg
int test_GausRmsFitter(int dbg, double satfrac)
std::vector< double > DoubleVector
Definition: fcldump.cxx:27
void err(const char *fmt,...)
Definition: message.cpp:226
QTextStream & endl(QTextStream &s)
int test_GausRmsFitter ( int  dbg,
double  satfrac 
)

Definition at line 33 of file test_GausRmsFitter.cxx.

33  {
34  const string myname = "test_GausRmsFitter: ";
35  cout << myname << "Starting test" << endl;
36 #ifdef NDEBUG
37  cout << myname << "NDEBUG must be off." << endl;
38  abort();
39 #endif
40  string line = "-----------------------------";
41  string scfg;
42 
43  cout << myname << line << endl;
44  cout << myname << "Test data" << endl;
45  ostringstream ssttl;
46  ssttl << "Test data with frac " << satfrac << endl;
47  TH1* ph = new TH1F("hdat", ssttl.str().c_str(), 100, 0, 100);
48  ph->SetDirectory(nullptr);
49  TF1* pf1 = gausTF1(1.0, 50.0, 4.0, "f1");
50  cout << myname << "Created function " << pf1->GetName() << endl;
51  TF1* pf2 = gausTF1(1.0, 30.0, 4.0, "f2");
52  cout << myname << "Created function " << pf2->GetName() << endl;
53  int npt = 1000;
54  ph->FillRandom("f1", npt);
55  ph->FillRandom("f2", satfrac*npt);
56  ph->GetListOfFunctions()->Clear();
57  cout << myname << " Hist mean: " << ph->GetMean() << endl;
58  cout << myname << " Hist RMS: " << ph->GetRMS() << endl;
59  delete pf1;
60  delete pf2;
61 
62  cout << myname << line << endl;
63  GausRmsFitter gsf(4.0, 4.0, "ff");
64  if ( dbg > 0 ) gsf.setLogLevel(dbg);
65  assert( gsf.fit(ph, 50) == 0 );
66  TF1* pffit = ph->GetFunction("ff");
67  if ( pffit == nullptr ) {
68  cout << myname << " Fit function not found!" << endl;
69  ph->GetListOfFunctions()->Print();
70  } else {
71  double x1, x2;
72  pffit->GetRange(x1, x2);
73  double sum = pffit->Integral(x1, x2);
74  cout << myname << " Fit name: " << pffit->GetName() << endl;
75  cout << myname << " Fit mean: " << pffit->GetParameter("Mean") << endl;
76  cout << myname << " Fit sigma: " << pffit->GetParameter("Sigma") << endl;
77  cout << myname << " Fit range: (" << x1 << ", " << x2 << ")" << endl;
78  cout << myname << " Fit integral: " << sum << endl;
79  }
80 
81  cout << myname << line << endl;
82  TCanvas* pcan = new TCanvas;
83  ph->Draw();
84  ostringstream ssfnam;
85  static int ncan = 0;
86  ssfnam << "gausstep" << ncan << ".png";
87  ++ncan;
88  string fnam = ssfnam.str();
89  cout << myname << "Writing " << fnam << endl;
90  pcan->Print(fnam.c_str());
91  delete pcan;
92 
93  return 0;
94 }
bool dbg
TF1 * gausTF1(double heightIn, double meanIn, double sigmaIn, std::string fname)
Definition: gausTF1.cxx:28
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)