Typedefs | Functions
test_GausStepFitter.cxx File Reference
#include "../GausStepFitter.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_GausStepFitter (double satfrac)
 
int main (int narg, const char *argc[])
 

Typedef Documentation

using DoubleVector = std::vector<double>

Definition at line 29 of file test_GausStepFitter.cxx.

Function Documentation

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

Definition at line 91 of file test_GausStepFitter.cxx.

91  {
92  DoubleVector satfracs = {0.0, 0.1, 0.2, 0.5};
93  if ( narg > 1 ) {
94  string sarg = argc[1];
95  if ( sarg == "-h" ) {
96  cout << "Usage: " << argc[0] << " [F1 F2 ...]" << endl;
97  return 0;
98  }
99  satfracs.clear();
100  for ( int iarg=1; iarg<narg; ++iarg ) {
101  double satfrac = 0.0;
102  istringstream ssin(argc[iarg]);
103  ssin >> satfrac;
104  satfracs.push_back(satfrac);
105  }
106  }
107  int err = 0;
108  for ( double satfrac : satfracs ) err += test_GausStepFitter(satfrac);
109  return err;
110 }
std::vector< double > DoubleVector
Definition: fcldump.cxx:27
void err(const char *fmt,...)
Definition: message.cpp:226
int test_GausStepFitter(double satfrac)
QTextStream & endl(QTextStream &s)
int test_GausStepFitter ( double  satfrac)

Definition at line 33 of file test_GausStepFitter.cxx.

33  {
34  const string myname = "test_GausStepFitter: ";
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  GausStepFitter gsf(50, 3.0, 20, "ff");
64  assert( gsf.fit(ph) == 0 );
65  TF1* pffit = ph->GetFunction("ff");
66  if ( pffit == nullptr ) {
67  cout << myname << " Fit function not found!" << endl;
68  ph->GetListOfFunctions()->Print();
69  } else {
70  cout << myname << " Fit mean: " << pffit->GetParameter("Mean") << endl;
71  cout << myname << " Fit sigma: " << pffit->GetParameter("Sigma") << endl;
72  }
73 
74  cout << myname << line << endl;
75  TCanvas* pcan = new TCanvas;
76  ph->Draw();
77  ostringstream ssfnam;
78  static int ncan = 0;
79  ssfnam << "gausstep" << ncan << ".png";
80  ++ncan;
81  string fnam = ssfnam.str();
82  cout << myname << "Writing " << fnam << endl;
83  pcan->Print(fnam.c_str());
84  delete pcan;
85 
86  return 0;
87 }
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)