10 #include "../GausRmsFitter.h" 11 #include "../gausTF1.h" 27 using std::ostringstream;
28 using std::istringstream;
34 const string myname =
"test_GausRmsFitter: ";
35 cout << myname <<
"Starting test" <<
endl;
37 cout << myname <<
"NDEBUG must be off." <<
endl;
40 string line =
"-----------------------------";
43 cout << myname << line <<
endl;
44 cout << myname <<
"Test data" <<
endl;
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;
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;
62 cout << myname << line <<
endl;
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();
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;
81 cout << myname << line <<
endl;
82 TCanvas* pcan =
new TCanvas;
86 ssfnam <<
"gausstep" << ncan <<
".png";
88 string fnam = ssfnam.str();
89 cout << myname <<
"Writing " << fnam <<
endl;
90 pcan->Print(fnam.c_str());
98 int main(
int narg,
const char* argc[]) {
102 string sarg = argc[1];
103 if ( sarg ==
"-h" ) {
104 cout <<
"Usage: " << argc[0] <<
" [DBG] [F1 F2 ...]" <<
endl;
107 istringstream ssin(sarg);
111 string sarg = argc[2];
113 for (
int iarg=2; iarg<narg; ++iarg ) {
114 double satfrac = 0.0;
115 istringstream ssin(argc[iarg]);
117 satfracs.push_back(satfrac);
int main(int narg, const char *argc[])
int test_GausRmsFitter(int dbg, double satfrac)
TF1 * gausTF1(double heightIn, double meanIn, double sigmaIn, std::string fname)
std::vector< double > DoubleVector
void err(const char *fmt,...)
Q_EXPORT QTSManip setw(int w)
int fit(TH1 *ph, double mean0) const
void line(double t, double *p, double &x, double &y, double &z)
QTextStream & endl(QTextStream &s)
void setLogLevel(Index lev)