ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
IDPVM::ResolutionHelper Class Reference

#include <ResolutionHelper.h>

Inheritance diagram for IDPVM::ResolutionHelper:
Collaboration diagram for IDPVM::ResolutionHelper:

Classes

struct  resolutionResultInBin
 package the output of a single bin resolution measurement More...
 

Public Types

enum  methods { iterRMS_convergence, Gauss_fit, fusion_iterRMS_Gaussfit, iterGaussFit_convergence }
 methods acc to which mean&RMS can be evaluated More...
 

Public Member Functions

 ResolutionHelper ()
 
 ~ResolutionHelper ()
 
void makeResolutions (const TH2 *h_input2D, TH1 *hwidth, TH1 *hmean, TH1 *hproj[], bool saveProjections, IDPVM::ResolutionHelper::methods theMethod=IDPVM::ResolutionHelper::iterRMS_convergence)
 extract 1D resolution plots from a 2D "residual vs observable" histogram. More...
 
void makeResolutions (const TH2 *h_input2D, TH1 *hwidth, TH1 *hmean, IDPVM::ResolutionHelper::methods theMethod=IDPVM::ResolutionHelper::iterRMS_convergence)
 extract 1D resolution plots from a 2D "residual vs observable" histogram. More...
 
resolutionResultInBin ResolutionHelperResultsModUnits (TH1D *p_input_hist, IDPVM::ResolutionHelper::methods theMethod=IDPVM::ResolutionHelper::iterRMS_convergence)
 single-bin resolution evaluation, also internally used by makeResolutions More...
 
void setResults (TH1 *p_input_hist, methods p_method)
 wrapper to set mean,rms,and fraction of events in tails nb: some of the methods are allowed to modify input histogram More...
 
double getMean ()
 results getters More...
 
double getMeanError ()
 
double getRMS ()
 
double getRMSError ()
 
double getFracOut ()
 fraction of events that is within the range of input histogram, but goes out-of range during width and mean evaluation if this is large, you should refine the method for width and mean evaluation can be done during post-processing, does not require new InDetPVM run More...
 
double getFracOutUnc ()
 
double getFracUOflow ()
 fraction of events in under- and over-flow bins of input histogram if this is large, the input histogram range needs to be increased requires InDetPVM code-change and re-run More...
 
const std::vector< std::string > & getDebugs ()
 return accumulated messages More...
 
const std::vector< std::string > & getInfos ()
 
const std::vector< std::string > & getWarnings ()
 
const std::vector< std::string > & getErrors ()
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Static Public Member Functions

static std::string reportUOBinVal (const std::string &p_histName, const std::vector< std::pair< unsigned int, double > > &p_vecBinVal)
 helper to report bin and fraction of under-/over- flow events, as accumulated by top-level pull or resolution histogram More...
 

Private Member Functions

int setGaussFit (TH1 *p_input_hist)
 
int setIterativeConvergence (TH1 *p_input_hist)
 iteratively change histogram range, until convergence return # remaining iterations before hitting the max. More...
 
int setIterativeGaussFitConvergence (TH1 *p_input_hist)
 same as above but performs a gaussian fit at avery iteration, until convergence More...
 
void setFout (double p_nsig, double p_ntot)
 evaluate the fraction of evens out of signal region and its uncertainty More...
 
void setLargeError ()
 set large mean and RMS errors in case we eg. exclude too many events during evaluation More...
 
bool initialize (TH1 *p_input_hist)
 helper to fill-in starting values of the results vector More...
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Static Private Member Functions

static void cloneHistogram (TH1D *h, TH1 *hcopy)
 

Private Attributes

double m_mean {0.}
 results/outputs: More...
 
double m_meanError {0.}
 
double m_RMS {0.}
 
double m_RMSError {0.}
 
double m_FracOut {0.}
 
double m_FracOutUnc {0.}
 
double m_FracUOflow {0.}
 
std::vector< std::string > m_debugs
 
std::vector< std::string > m_infos
 
std::vector< std::string > m_warnings
 
std::vector< std::string > m_errors
 
std::string m_inHistName {""}
 
double m_largeErrorFact {10.}
 
double m_maxUOflowFrac {0.05}
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Definition at line 28 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h.

Member Enumeration Documentation

◆ methods

methods acc to which mean&RMS can be evaluated

Enumerator
iterRMS_convergence 
Gauss_fit 
fusion_iterRMS_Gaussfit 
iterGaussFit_convergence 

Definition at line 36 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h.

Constructor & Destructor Documentation

◆ ResolutionHelper()

IDPVM::ResolutionHelper::ResolutionHelper ( )

Definition at line 25 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

25  :
26  AthMessaging("ResolutionHelper")
27  {
28  }

◆ ~ResolutionHelper()

IDPVM::ResolutionHelper::~ResolutionHelper ( )
inline

Member Function Documentation

◆ cloneHistogram()

void IDPVM::ResolutionHelper::cloneHistogram ( TH1D *  h,
TH1 *  hcopy 
)
staticprivate

Definition at line 417 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

417  {
418  unsigned int nbin = h->GetNbinsX();
419 
420  for (unsigned int ibin = 0; ibin < nbin; ibin++) {
421  hcopy->SetBinContent(ibin + 1, h->GetBinContent(ibin + 1));
422  hcopy->SetBinError(ibin + 1, h->GetBinError(ibin + 1));
423  }
424 }

◆ getDebugs()

const std::vector<std::string>& IDPVM::ResolutionHelper::getDebugs ( )
inline

return accumulated messages

Definition at line 100 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h.

100 { return m_debugs; };

◆ getErrors()

const std::vector<std::string>& IDPVM::ResolutionHelper::getErrors ( )
inline

◆ getFracOut()

double IDPVM::ResolutionHelper::getFracOut ( )
inline

fraction of events that is within the range of input histogram, but goes out-of range during width and mean evaluation if this is large, you should refine the method for width and mean evaluation can be done during post-processing, does not require new InDetPVM run

Definition at line 87 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h.

87 { return m_FracOut; };

◆ getFracOutUnc()

double IDPVM::ResolutionHelper::getFracOutUnc ( )
inline

◆ getFracUOflow()

double IDPVM::ResolutionHelper::getFracUOflow ( )
inline

fraction of events in under- and over-flow bins of input histogram if this is large, the input histogram range needs to be increased requires InDetPVM code-change and re-run

Definition at line 93 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h.

93 { return m_FracUOflow; };

◆ getInfos()

const std::vector<std::string>& IDPVM::ResolutionHelper::getInfos ( )
inline

◆ getMean()

double IDPVM::ResolutionHelper::getMean ( )
inline

◆ getMeanError()

double IDPVM::ResolutionHelper::getMeanError ( )
inline

◆ getRMS()

double IDPVM::ResolutionHelper::getRMS ( )
inline

◆ getRMSError()

double IDPVM::ResolutionHelper::getRMSError ( )
inline

◆ getWarnings()

const std::vector<std::string>& IDPVM::ResolutionHelper::getWarnings ( )
inline

◆ initialize()

bool IDPVM::ResolutionHelper::initialize ( TH1 *  p_input_hist)
private

helper to fill-in starting values of the results vector

Definition at line 30 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

30  {
31 
32  if ( !m_debugs.empty())
33  m_debugs.clear();
34  if ( !m_infos.empty())
35  m_infos.clear();
36  if ( !m_warnings.empty())
37  m_warnings.clear();
38  if ( !m_errors.empty())
39  m_errors.clear();
40 
41  if (!p_input_hist) {
42  m_errors.emplace_back("ResolutionHelper::initialize: empty input histogram passed: ");
44  return false;
45  }
46 
47  m_inHistName = p_input_hist->GetName();
48 
49  if ( 0==p_input_hist->GetEntries() ) {
50  m_debugs.push_back("ResolutionHelper::initialize: got input histogram with 0 entries: "+ m_inHistName);
52  return false;
53  }
54 
55  m_RMS = p_input_hist->GetRMS();
56  m_RMSError = p_input_hist->GetRMSError();
57  m_mean = p_input_hist->GetMean();
58  m_meanError = p_input_hist->GetMeanError();
59  m_FracOut = 0.;
60  m_FracOutUnc = 0.;
61  double nExclUOflow = p_input_hist->Integral(1,p_input_hist->GetNbinsX());
62  double nInclUOflow = p_input_hist->Integral(0,p_input_hist->GetNbinsX()+1);
63  double fUOflow = (nExclUOflow>0.) ? (nInclUOflow-nExclUOflow)/nExclUOflow : -1.;
64  m_FracUOflow = (fUOflow>m_maxUOflowFrac) ? fUOflow : -1;
65 
66  return true;
67  }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ makeResolutions() [1/2]

void IDPVM::ResolutionHelper::makeResolutions ( const TH2 *  h_input2D,
TH1 *  hwidth,
TH1 *  hmean,
IDPVM::ResolutionHelper::methods  theMethod = IDPVM::ResolutionHelper::iterRMS_convergence 
)

extract 1D resolution plots from a 2D "residual vs observable" histogram.

Parameters
[in]h_input2Dinput histogram (x = observable, y = residuals)
[out]hwidthoutput histogram, will be filled with the width of the residuals (-> resolution)
[out]hmeanoutput histogram, will be filled with the mean of the residuals (-> bias)
[out]hprojarray of histograms, will be populated by an array of 1-dimensional projections of Y within bins in X
[in]saveProjectionssteers the filling of hpoj
[in]theMethodthe method used to extract the width and mean. Default is iterative RMS.

Definition at line 351 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

351  {
352 
353  // warnings in case input histograms have large % events in under- and over- flow bins
354  std::vector< std::pair<unsigned int,double> > warnUOBinFrac;
355 
356  if (h_input2D->GetNbinsX() != hwidth->GetNbinsX() || h_input2D->GetNbinsX() != hmean->GetNbinsX()){
357  ATH_MSG_ERROR("Inconsistent binnings between 1D and 2D histos - please fix your config!");
358  return;
359  }
360  for (int ibin = 0; ibin < h_input2D->GetNbinsX(); ibin++) {
361  std::string tmpName = h_input2D->GetName() + std::string("py_bin") + std::to_string(ibin + 1);
362  std::shared_ptr<TH1D> tmp {static_cast<TH1D*>(h_input2D->ProjectionY(tmpName.c_str(), ibin + 1, ibin + 1))};
363  if (tmp->Integral() < 1) {
364  continue;
365  }
366  const resolutionResultInBin & result = ResolutionHelperResultsModUnits(tmp.get(), theMethod);
367  hwidth->SetBinContent(ibin + 1, result.width);
368  hwidth->SetBinError(ibin + 1, result.widthError);
369  hmean->SetBinContent(ibin + 1, result.mean);
370  hmean->SetBinError(ibin + 1, result.meanError);
371  if (result.outlierFrac > m_maxUOflowFrac) {
372  warnUOBinFrac.emplace_back(ibin + 1,result.outlierFrac);
373  }
374  }
375  if (!warnUOBinFrac.empty()) {
376  ATH_MSG_WARNING(reportUOBinVal(hwidth->GetName(),warnUOBinFrac));
377  ATH_MSG_WARNING(reportUOBinVal(hwidth->GetName(),warnUOBinFrac));
378  }
379 }

◆ makeResolutions() [2/2]

void IDPVM::ResolutionHelper::makeResolutions ( const TH2 *  h_input2D,
TH1 *  hwidth,
TH1 *  hmean,
TH1 *  hproj[],
bool  saveProjections,
IDPVM::ResolutionHelper::methods  theMethod = IDPVM::ResolutionHelper::iterRMS_convergence 
)

extract 1D resolution plots from a 2D "residual vs observable" histogram.

Parameters
[in]h_input2Dinput histogram (x = observable, y = residuals)
[out]hwidthoutput histogram, will be filled with the width of the residuals (-> resolution)
[out]hmeanoutput histogram, will be filled with the mean of the residuals (-> bias)
[out]hprojarray of histograms, will be populated by an array of 1-dimensional projections of Y within bins in X
[in]saveProjectionssteers the filling of hpoj
[in]theMethodthe method used to extract the width and mean. Default is iterative RMS.

Definition at line 382 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

382  {
383 
384  // warnings in case input histograms have large % events in under- and over- flow bins
385  std::vector< std::pair<unsigned int,double> > warnUOBinFrac;
386 
387  if (h_input2D->GetNbinsX() != hwidth->GetNbinsX() || h_input2D->GetNbinsX() != hmean->GetNbinsX()){
388  ATH_MSG_ERROR("Inconsistent binnings between 1D and 2D histos - please fix your config!");
389  return;
390  }
391 
392  for (int ibin = 0; ibin < hwidth->GetNbinsX(); ibin++) {
393  std::string tmpName = h_input2D->GetName() + std::string("py_bin") + std::to_string(ibin + 1);
394  std::shared_ptr<TH1D> tmp {static_cast<TH1D*>(h_input2D->ProjectionY(tmpName.c_str(), ibin+1, ibin+1))};
395  if (tmp->Integral() < 1) {
396  continue;
397  }
398  if (saveProjections) {
399  cloneHistogram(tmp.get(), hproj[ibin]);
400  }
401  const resolutionResultInBin & result = ResolutionHelperResultsModUnits(tmp.get(), theMethod);
402  hwidth->SetBinContent(ibin + 1, result.width);
403  hwidth->SetBinError(ibin + 1, result.widthError);
404  hmean->SetBinContent(ibin + 1, result.mean);
405  hmean->SetBinError(ibin + 1, result.meanError);
406  if (result.outlierFrac>m_maxUOflowFrac){
407  warnUOBinFrac.emplace_back(ibin + 1,result.outlierFrac);
408  }
409  }
410  if (!warnUOBinFrac.empty()) {
411  ATH_MSG_WARNING(reportUOBinVal(hwidth->GetName(),warnUOBinFrac));
412  ATH_MSG_WARNING(reportUOBinVal(hwidth->GetName(),warnUOBinFrac));
413  }
414 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ reportUOBinVal()

std::string IDPVM::ResolutionHelper::reportUOBinVal ( const std::string &  p_histName,
const std::vector< std::pair< unsigned int, double > > &  p_vecBinVal 
)
static

helper to report bin and fraction of under-/over- flow events, as accumulated by top-level pull or resolution histogram

Definition at line 78 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

78  {
79  std::ostringstream reportl;
80  if (!p_vecBinVal.empty()) {
81  reportl << "Errors scaled up for resol. hist. with large % of events in over- and under-flow: "
82  << p_histName<<": ";
83  for ( auto it : p_vecBinVal )
84  reportl << "bin"<<it.first << ": " << std::setprecision(2) << it.second*100. << "%, ";
85  }
86  return reportl.str();
87  }

◆ ResolutionHelperResultsModUnits()

ResolutionHelper::resolutionResultInBin IDPVM::ResolutionHelper::ResolutionHelperResultsModUnits ( TH1D *  p_input_hist,
IDPVM::ResolutionHelper::methods  theMethod = IDPVM::ResolutionHelper::iterRMS_convergence 
)

single-bin resolution evaluation, also internally used by makeResolutions

Parameters
p_input_histinput histogram, 1D distribution of the residual
theMethodmethod to use (default: iterative RMS)
Returns
resolutionResultInBin object packaging the mean and width of the distribution determined using the specified method as well as outlier bin fractions.

Definition at line 332 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

332  {
333  // LM: reason for using this function:
334  // orignial code was set up to only have resolution resuls in um,
335  // while inputs are in mm. Do not want to do a substantial rewrite.
336  TString vari = p_input_hist->GetName();
337  bool isInMicrons = ( !vari.Contains("pull") &&
338  (vari.Contains("d0") || vari.Contains("z0")) );
339  const double unitConversionFactor = isInMicrons ? 1000. : 1.; // mm measurements to um outputs
340  setResults(p_input_hist, theMethod);
341 
342  return {getRMS()*unitConversionFactor,
343  getRMSError()*unitConversionFactor,
344  getMean()*unitConversionFactor,
345  getMeanError()*unitConversionFactor,
346  getFracOut(),
347  getFracOutUnc()};
348 }

◆ setFout()

void IDPVM::ResolutionHelper::setFout ( double  p_nsig,
double  p_ntot 
)
private

evaluate the fraction of evens out of signal region and its uncertainty

Definition at line 89 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

89  {
90  m_FracOut=0.;
91  m_FracOutUnc=0.;
92  if (p_ntot>0.) {
93  double nout=p_ntot-p_nsig;
94  if (nout / p_ntot > 0.9) {
95  nout = 0.;
96  }
97  if (nout > 0.) {
98  m_FracOut=nout/p_nsig;
99  m_FracOutUnc=(nout / p_ntot) * std::sqrt(1. / nout + 1. / p_ntot);
100  }
101  }
102  }

◆ setGaussFit()

int IDPVM::ResolutionHelper::setGaussFit ( TH1 *  p_input_hist)
private

Definition at line 104 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

104  {
105 
106  int ret=0;
107 
108  // evaluate mean and with via the Gauss fit
109  TFitResultPtr r = p_input_hist->Fit("gaus", "QS0");
110  if ( r.Get() and (0 == (r->Status()%1000)) ) {
111  m_RMS=r->Parameter(2);//RMS
112  m_RMSError=r->ParError(2);//RMS_error
113  m_mean=r->Parameter(1);//mean
114  m_meanError=r->ParError(1);//mean_error
115  }
116  else
117  ret=1;
118 
119  // get fraction of events outside 3*RMS + its ~ uncertainty
120  double nSig = p_input_hist->Integral(p_input_hist->GetXaxis()->FindBin(-3.0 * m_RMS),
121  p_input_hist->GetXaxis()->FindBin(3.0 * m_RMS));
122  double nTot = p_input_hist->Integral(1,p_input_hist->GetNbinsX());
123  setFout(nSig,nTot);
124 
125  // return fit status
126  return ret;
127  }

◆ setIterativeConvergence()

int IDPVM::ResolutionHelper::setIterativeConvergence ( TH1 *  p_input_hist)
private

iteratively change histogram range, until convergence return # remaining iterations before hitting the max.

allowed

Definition at line 130 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

130  {
131 
132  // evaluate mean and RMS using iterative converfgence:
133  double mean=p_input_hist->GetMean();
134  double RMS = p_input_hist->GetRMS();
135 
136  // iteration parameters:
137  // max iteration steps
138  unsigned int ntries_max = 100;
139  // width of cutting range in [RMS]
140  double nRMS_width = 3.0;
141 
142  // iteration counters and helpers:
143  // min and max range of the histogram:
144  double xmin=0.;
145  double xmax=0.;
146  // min and max bins of the histogram in previous iteration
147  // 0-th iteration: range of the original histogram
148  int binmin_was = 1;
149  int binmax_was = p_input_hist->GetNbinsX();
150  // initial number of iteration steps
151  unsigned int ntries = 0;
152 
153  // iteratively cut tails untill the RMS gets stable about mean
154  // RMS stable: when input histogram range after cutting by
155  // +- 3*RMS is same as the range before cutting
156  while ( ntries<ntries_max ) {
157  ++ntries;
158  RMS = p_input_hist->GetRMS();
159  mean = p_input_hist->GetMean();
160  xmin = -1.0*nRMS_width*RMS + mean;
161  xmax = nRMS_width*RMS + mean;
162  // find bins corresponding to new range, disregard underflow
163  int binmin=std::max(1,p_input_hist->GetXaxis()->FindFixBin(xmin));
164  // find bins corresponding to new range, disregard overflow
165  int binmax=std::min(p_input_hist->GetNbinsX(),p_input_hist->GetXaxis()->FindFixBin(xmax));
166  // end iteration if these are same bins as in prev. iteration
167  if ( binmin_was==binmin && binmax_was==binmax ) {
168  break;
169  }
170  else {
171  // else set the new range and continue iteration
172  p_input_hist->GetXaxis()->SetRange(binmin,binmax);
173  binmin_was=binmin;
174  binmax_was=binmax;
175  }
176  } // end of ( ntries<ntries_max ) ; iterative convergence loop
177 
178  // set the iteration results that are accessible to clients:
179  m_RMS=RMS;
180  m_RMSError= p_input_hist->GetRMSError();
181  m_mean=mean;
182  m_meanError=p_input_hist->GetMeanError();
183 
184  // get fraction of excluded events + its ~ uncertainty
185  double nSig = p_input_hist->Integral(p_input_hist->GetXaxis()->FindBin(xmin),
186  p_input_hist->GetXaxis()->FindBin(xmax));
187  // disregard under- and over- flow
188  double nTot = p_input_hist->Integral(1,p_input_hist->GetNbinsX());
189  setFout(nSig,nTot);
190 
191  // return number of remaining allowed iteration steps
192  return(ntries_max-ntries);
193  }

◆ setIterativeGaussFitConvergence()

int IDPVM::ResolutionHelper::setIterativeGaussFitConvergence ( TH1 *  p_input_hist)
private

same as above but performs a gaussian fit at avery iteration, until convergence

First intialise mean and RMS to 0

iteration parameters: max iteration steps

width of cutting range in [RMS]

first perform a single Gauss fit across full range of histogram or in a specified range

performs a second fit with range determined by first fit i.e. mean +/- nRMS_width * RMS

now iteratively perform gaus fits until recomputed mean and RMS stabilise (differ by <= 0.0005 )

update fit results

refitting adjusting new range

refitting

set the iteration results that are accessible to clients:

get fraction of excluded events + its ~ uncertainty

disregard under- and over- flow

return number of remaining allowed iteration steps

Definition at line 196 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

196  {
198  double mean = 0.;
199  double meanError = 0.;
200  double RMS = 0.;
201  double RMSError = 0.;
202 
205  unsigned int ntries_max = 50;
207  double nRMS_width = 2.0;
208 
210  double xmin = p_input_hist->GetBinLowEdge(1);
211  double xmax = ( p_input_hist->GetBinLowEdge( p_input_hist->GetNbinsX() ) ) +
212  ( p_input_hist->GetBinWidth( p_input_hist->GetNbinsX() ) );
213  std::shared_ptr<TF1> fitA = std::make_shared<TF1>( "fitA", "gaus", xmin, xmax );
214  p_input_hist->Fit( "fitA", "ORQN", "same" );
215  mean = fitA->GetParameter(1);
216  meanError = fitA->GetParError(1);
217  RMS = fitA->GetParameter(2);
218  RMSError = fitA->GetParError(2);
219 
222  xmin = mean - ( RMS * nRMS_width );
223  xmax = mean + ( RMS * nRMS_width );
224  std::shared_ptr<TF1> fitB = std::make_shared<TF1>( "fitB", "gaus", xmin, xmax );
225  p_input_hist->Fit( "fitB", "ORQN", "same" );
226  mean = fitB->GetParameter(1);
227  meanError = fitB->GetParError(1);
228  RMS = fitB->GetParameter(2);
229  RMSError = fitB->GetParError(2);
230 
232  xmin = mean - ( RMS * nRMS_width );
233  xmax = mean + ( RMS * nRMS_width );
234  std::shared_ptr<TF1> fit = std::make_shared<TF1>( "fit", "gaus", xmin, xmax );
235  double mean_new = 99999.;
236  double meanError_new = 99999.;
237  double RMS_new = 99999.;
238  double RMSError_new = 99999.;
239  unsigned int ntries = 0;
240  while( std::abs( mean - mean_new ) > 0.0005 or std::abs( RMS - RMS_new ) > 0.0005 ) {
241  if( ntries > 0 ) {
243  mean = mean_new;
244  meanError = meanError_new;
245  RMS = RMS_new;
246  RMSError = RMSError_new;
247  }
248 
250  xmin = mean - ( RMS * nRMS_width );
251  xmax = mean + ( RMS * nRMS_width );
252  fit->SetRange( xmin, xmax );
254  p_input_hist->Fit( "fit", "ORQN", "same" );
255  mean_new = fit->GetParameter(1);
256  meanError_new = fit->GetParError(1);
257  RMS_new = fit->GetParameter(2);
258  RMSError_new = fit->GetParError(2);
259 
260  if( ntries > 50 ) {
261  ATH_MSG_WARNING( "terminate iterative gaus fit because of convergence problems" );
262  break;
263  }
264  ntries++;
265  } // end while
266 
268  m_RMS = RMS;
269  m_RMSError = RMSError;
270  m_mean = mean;
271  m_meanError = meanError;
272 
274  double nSig = p_input_hist->Integral( p_input_hist->GetXaxis()->FindBin(xmin),
275  p_input_hist->GetXaxis()->FindBin(xmax) );
277  double nTot = p_input_hist->Integral( 1, p_input_hist->GetNbinsX() );
278  setFout( nSig, nTot );
279 
281  return( ntries_max - ntries );
282  }

◆ setLargeError()

void IDPVM::ResolutionHelper::setLargeError ( )
private

set large mean and RMS errors in case we eg. exclude too many events during evaluation

Definition at line 69 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

69  {
70  std::ostringstream debugl;
71  debugl << __FILE__ << "\t\t" << m_inHistName
72  << ": scaling mean and RMS errors by factor: " << m_largeErrorFact;
73  m_debugs.push_back(debugl.str());
76  }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

◆ setResults()

void IDPVM::ResolutionHelper::setResults ( TH1 *  p_input_hist,
methods  p_method 
)

wrapper to set mean,rms,and fraction of events in tails nb: some of the methods are allowed to modify input histogram

Definition at line 287 of file InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx.

287  {
288 
289  // set start values of the results vector
290  // mean RMS etc as in the input histo prior to trimming
291  if (!initialize(p_input_hist))
292  return;
293 
294  if (iterRMS_convergence == p_method) {
295  if ( !setIterativeConvergence(p_input_hist) )
296  m_warnings.push_back("\t\t\t* ResolutionHelper::setIterativeConvergence did not converge for "+ m_inHistName);
297  }
298  else if (Gauss_fit == p_method) {
299  if ( !setGaussFit(p_input_hist) )
300  m_warnings.push_back("\t\t\t* ResolutionHelper::setGaussFit: fit failed for "+ m_inHistName);
301  }
302  else if (fusion_iterRMS_Gaussfit == p_method) {
303  if ( !setIterativeConvergence(p_input_hist) &&
304  !setGaussFit(p_input_hist) )
305  m_warnings.push_back("\t\t\t* ResolutionHelper::fusion_iterRMS_Gaussfit both methods failed for "+ m_inHistName);
306  }
307  else if ( iterGaussFit_convergence == p_method ) {
308  if ( !setIterativeGaussFitConvergence( p_input_hist ) )
309  m_warnings.push_back("\t\t\t* ResolutionHelper::setIterativeGaussFitConvergence: iter gauss fit did not converge for "+ m_inHistName);
310  }
311  else {
312  m_errors.push_back("\t\t\t* ResolutionHelper::setResults: method not supported. No evaluation for "+ m_inHistName);
313  }
314 
315  // check if large fraction of events was in over- and under-flow
316  if ( m_FracUOflow > 0. ) {
317  std::ostringstream debugl;
318  debugl << "\tResolutionHelper::setResults: too large fraction of out-of-range events for histogram ";
319  debugl << m_inHistName << ": " << m_FracUOflow << " > " << m_maxUOflowFrac;
320  m_debugs.push_back(debugl.str());
321  setLargeError();
322  m_debugs.push_back("\t\t\t* ResolutionHelper::setResults: scaling errors up for "
323  +m_inHistName+". Too many under- and over- flows.");
324  }
325 
326  // reset range metadata to state prior to iteration
327  // this gets changed in iterative or fusion)
328  p_input_hist->GetXaxis()->SetRange(1,p_input_hist->GetNbinsX());
329  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_debugs

std::vector<std::string> IDPVM::ResolutionHelper::m_debugs
private

◆ m_errors

std::vector<std::string> IDPVM::ResolutionHelper::m_errors
private

◆ m_FracOut

double IDPVM::ResolutionHelper::m_FracOut {0.}
private

◆ m_FracOutUnc

double IDPVM::ResolutionHelper::m_FracOutUnc {0.}
private

◆ m_FracUOflow

double IDPVM::ResolutionHelper::m_FracUOflow {0.}
private

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_infos

std::vector<std::string> IDPVM::ResolutionHelper::m_infos
private

◆ m_inHistName

std::string IDPVM::ResolutionHelper::m_inHistName {""}
private

◆ m_largeErrorFact

double IDPVM::ResolutionHelper::m_largeErrorFact {10.}
private

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_maxUOflowFrac

double IDPVM::ResolutionHelper::m_maxUOflowFrac {0.05}
private

◆ m_mean

double IDPVM::ResolutionHelper::m_mean {0.}
private

◆ m_meanError

double IDPVM::ResolutionHelper::m_meanError {0.}
private

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_RMS

double IDPVM::ResolutionHelper::m_RMS {0.}
private

◆ m_RMSError

double IDPVM::ResolutionHelper::m_RMSError {0.}
private

◆ m_warnings

std::vector<std::string> IDPVM::ResolutionHelper::m_warnings
private

The documentation for this class was generated from the following files:
IDPVM::ResolutionHelper::m_FracOutUnc
double m_FracOutUnc
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:128
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
beamspotman.r
def r
Definition: beamspotman.py:674
IDPVM::ResolutionHelper::iterRMS_convergence
@ iterRMS_convergence
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:36
IDPVM::ResolutionHelper::getRMS
double getRMS()
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:80
IDPVM::ResolutionHelper::initialize
bool initialize(TH1 *p_input_hist)
helper to fill-in starting values of the results vector
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:30
IDPVM::ResolutionHelper::m_meanError
double m_meanError
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:124
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
get_generator_info.result
result
Definition: get_generator_info.py:21
IDPVM::ResolutionHelper::getMean
double getMean()
results getters
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:78
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
IDPVM::ResolutionHelper::m_FracOut
double m_FracOut
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:127
IDPVM::ResolutionHelper::setResults
void setResults(TH1 *p_input_hist, methods p_method)
wrapper to set mean,rms,and fraction of events in tails nb: some of the methods are allowed to modify...
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:287
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
IDPVM::ResolutionHelper::m_maxUOflowFrac
double m_maxUOflowFrac
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:144
skel.it
it
Definition: skel.GENtoEVGEN.py:407
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
hmean
double hmean(TH1 *h)
Definition: computils.cxx:435
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
IDPVM::ResolutionHelper::getFracOutUnc
double getFracOutUnc()
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:88
AthMessaging::AthMessaging
AthMessaging()
Default constructor:
IDPVM::ResolutionHelper::getMeanError
double getMeanError()
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:79
IDPVM::ResolutionHelper::Gauss_fit
@ Gauss_fit
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:36
IDPVM::ResolutionHelper::m_errors
std::vector< std::string > m_errors
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:134
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xmin
double xmin
Definition: listroot.cxx:60
IDPVM::ResolutionHelper::m_RMSError
double m_RMSError
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:126
IDPVM::ResolutionHelper::m_FracUOflow
double m_FracUOflow
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:129
IDPVM::ResolutionHelper::getFracOut
double getFracOut()
fraction of events that is within the range of input histogram, but goes out-of range during width an...
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:87
IDPVM::ResolutionHelper::iterGaussFit_convergence
@ iterGaussFit_convergence
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:36
IDPVM::ResolutionHelper::m_infos
std::vector< std::string > m_infos
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:132
IDPVM::ResolutionHelper::setIterativeConvergence
int setIterativeConvergence(TH1 *p_input_hist)
iteratively change histogram range, until convergence return # remaining iterations before hitting th...
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:130
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
MuonValidation_CreateResolutionProfiles.fit
def fit(h, emin, emax)
Definition: MuonValidation_CreateResolutionProfiles.py:69
IDPVM::ResolutionHelper::m_debugs
std::vector< std::string > m_debugs
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:131
DiTauMassTools::HistInfo::RMS
@ RMS
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:35
IDPVM::ResolutionHelper::setGaussFit
int setGaussFit(TH1 *p_input_hist)
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:104
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IDPVM::ResolutionHelper::m_RMS
double m_RMS
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:125
IDPVM::ResolutionHelper::setFout
void setFout(double p_nsig, double p_ntot)
evaluate the fraction of evens out of signal region and its uncertainty
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:89
IDPVM::ResolutionHelper::m_warnings
std::vector< std::string > m_warnings
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:133
h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
IDPVM::ResolutionHelper::cloneHistogram
static void cloneHistogram(TH1D *h, TH1 *hcopy)
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:417
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
xmax
double xmax
Definition: listroot.cxx:61
IDPVM::ResolutionHelper::fusion_iterRMS_Gaussfit
@ fusion_iterRMS_Gaussfit
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:36
IDPVM::ResolutionHelper::m_mean
double m_mean
results/outputs:
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:123
IDPVM::ResolutionHelper::m_largeErrorFact
double m_largeErrorFact
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:142
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
IDPVM::ResolutionHelper::setLargeError
void setLargeError()
set large mean and RMS errors in case we eg. exclude too many events during evaluation
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:69
IDPVM::ResolutionHelper::getRMSError
double getRMSError()
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:81
IDPVM::ResolutionHelper::setIterativeGaussFitConvergence
int setIterativeGaussFitConvergence(TH1 *p_input_hist)
same as above but performs a gaussian fit at avery iteration, until convergence
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:196
IDPVM::ResolutionHelper::reportUOBinVal
static std::string reportUOBinVal(const std::string &p_histName, const std::vector< std::pair< unsigned int, double > > &p_vecBinVal)
helper to report bin and fraction of under-/over- flow events, as accumulated by top-level pull or re...
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:78
python.SystemOfUnits.ms
float ms
Definition: SystemOfUnits.py:148
IDPVM::ResolutionHelper::ResolutionHelperResultsModUnits
resolutionResultInBin ResolutionHelperResultsModUnits(TH1D *p_input_hist, IDPVM::ResolutionHelper::methods theMethod=IDPVM::ResolutionHelper::iterRMS_convergence)
single-bin resolution evaluation, also internally used by makeResolutions
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/src/ResolutionHelper.cxx:332
IDPVM::ResolutionHelper::m_inHistName
std::string m_inHistName
Definition: InnerDetector/InDetValidation/InDetPhysValMonitoring/InDetPhysValMonitoring/ResolutionHelper.h:139