Typedefs | Functions
test_shiftHistFit.cxx File Reference
#include "dunecore/DuneCommon/Utility/shiftHistFit.h"
#include "dunecore/DuneCommon/Utility/gausTF1.h"
#include "dunecore/DuneCommon/Utility/TPadManipulator.h"
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <cassert>
#include "TH1F.h"
#include "TF1.h"
#include "TRandom.h"

Go to the source code of this file.

Typedefs

using Index = unsigned int
 

Functions

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

Typedef Documentation

using Index = unsigned int

Definition at line 30 of file test_shiftHistFit.cxx.

Function Documentation

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

Definition at line 88 of file test_shiftHistFit.cxx.

88  {
89  double xshift = 1000.0;
90  if ( narg > 1 ) {
91  istringstream ssin(argc[1]);
92  ssin >> xshift;
93  }
94  return test_shiftHistFit(xshift);
95 }
int test_shiftHistFit(double xshift)
int test_shiftHistFit ( double  xshift)

Definition at line 34 of file test_shiftHistFit.cxx.

34  {
35  const string myname = "test_shiftHistFit: ";
36  cout << myname << "Starting test" << endl;
37  cout << myname << "Shift is " << xshift << endl;
38 #ifdef NDEBUG
39  cout << myname << "NDEBUG must be off." << endl;
40  abort();
41 #endif
42  string line = "-----------------------------";
43  string scfg;
44 
45  cout << myname << line << endl;
46  cout << "Testing shifHistFit." << endl;
47 
48  cout << myname << line << endl;
49  cout << "Build histogram" << endl;
50  // Truth parameters before shift.
51  double x0 = 50.0;
52  double sig0 = 10.0;
53  // Histogram range.
54  double hx1 = x0 + xshift - 50.0;
55  double hx2 = x0 + xshift + 50.0;
56  // Fit range.
57  double fx1 = x0 + xshift - 25.0;
58  double fx2 = x0 + xshift + 25.0;
59  // Fill histgram with data distributed around shifted truth.
60  TH1* ph = new TH1F("hgau", "My gaus", 100, hx1, hx2);
61  for ( int ient=0; ient<1000; ++ient ) {
62  ph->Fill(gRandom->Gaus(x0 + xshift, sig0));
63  }
64 
65  cout << myname << line << endl;
66  cout << "Build function." << endl;
67  TF1* pf = gausTF1(10.0, x0 + xshift + 0.3*sig0, 0.8*sig0, "mygaus");
68  pf->SetRange(fx1, fx2);
69  pf->Print();
70 
71  //ph->Fit(pf);
72  shiftHistFit(ph, pf, "R", "Mean", xshift);
73  pf->Print();
74 
75  TPadManipulator man;
76  man.add(ph, "hist");
77  man.add(pf, "same");
78  man.addAxis();
79  string fnout = "test_shiftHistFit.png";
80  cout << myname << "Printing " << fnout << endl;
81  man.print(fnout);
82 
83  return 0;
84 }
int add(unsigned int ipad, TObject *pobj, std::string sopt="", bool replace=false)
int shiftHistFit(TH1 *ph, TF1 *pf, std::string fopt, int ipar, double xshift)
TF1 * gausTF1(double heightIn, double meanIn, double sigmaIn, std::string fname)
Definition: gausTF1.cxx:28
int addAxis(bool flag=true)
void line(double t, double *p, double &x, double &y, double &z)
int print(std::string fname, std::string spat="{,}")
QTextStream & endl(QTextStream &s)