quietHistFit.cxx
Go to the documentation of this file.
1 // quietHistFit.cxx
2 
4 #include "TFitResult.h"
5 
6 #include "TF1.h"
7 #include "TH1F.h"
8 
9 //**********************************************************************
10 
11 namespace {
12 
13 // Convert fit result to an int that is 0 for success.
14 int get(TFitResultPtr pres) {
15  if ( pres.Get() == nullptr ) return pres;
16  if ( pres->IsValid() ) return 0;
17  if ( pres->Status() ) return pres->Status();
18  return 99;
19 }
20 
21 }
22 
23 //**********************************************************************
24 
26  // Block Root info message for new Canvas produced in fit.
27  int levelSave = gErrorIgnoreLevel;
28  gErrorIgnoreLevel = 1002;
29  // Block non-default (e.g. art) from handling the Root "error".
30  // We switch to the Root default handler while making the call to Print.
31  ErrorHandlerFunc_t pehSave = nullptr;
32  ErrorHandlerFunc_t pehDefault = DefaultErrorHandler;
33  if ( GetErrorHandler() != pehDefault ) {
34  pehSave = SetErrorHandler(pehDefault);
35  }
36  int fstat = get(ph->Fit(fname.c_str(), fopt.c_str()));
37  if ( pehSave != nullptr ) SetErrorHandler(pehSave);
38  gErrorIgnoreLevel = levelSave;
39  return fstat;
40 }
41 
42 //**********************************************************************
43 
44 int quietHistFit(TH1* ph, TF1* pf, std::string fopt) {
45  // Block Root info message for new Canvas produced in fit.
46  int levelSave = gErrorIgnoreLevel;
47  gErrorIgnoreLevel = 1002;
48  // Block non-default (e.g. art) from handling the Root "error".
49  // We switch to the Root default handler while making the call to Print.
50  ErrorHandlerFunc_t pehSave = nullptr;
51  ErrorHandlerFunc_t pehDefault = DefaultErrorHandler;
52  if ( GetErrorHandler() != pehDefault ) {
53  pehSave = SetErrorHandler(pehDefault);
54  }
55  int fstat = get(ph->Fit(pf, fopt.c_str()));
56  if ( pehSave != nullptr ) SetErrorHandler(pehSave);
57  gErrorIgnoreLevel = levelSave;
58  return fstat;
59 }
60 
61 //**********************************************************************
std::string string
Definition: nybbler.cc:12
int quietHistFit(TH1 *ph, std::string fname, std::string fopt)