ATLAS Offline Software
AlgorithmHelper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #ifndef DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_H
10 #define DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_H
11 
12 #include <dqm_core/Result.h>
13 #include <dqm_core/AlgorithmConfig.h>
14 #include <dqm_core/exceptions.h>
15 
16 #include <map>
17 #include <vector>
18 #include <deque>
19 #include <list>
20 #include <utility>
21 
22 #include <TH1.h>
23 #include <TObject.h>
24 #include <TClass.h>
25 #include <boost/thread/once.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread/locks.hpp>
28 #include <boost/thread.hpp>
29 #include <boost/utility.hpp>
30 #include <iostream>
31 
32 class TF1;
33 class TAxis;
34 
35 namespace dqm_algorithms
36 {
37  namespace tools
38  {
40 
42 
43  //Structure to hold the essence of a 2D histogram bin, and be sortable:
44  struct binContainer {
45  double value;
46  double error;
47  int test;
48  int ix;
49  int iy;
50  double x;
51  double y;
52  //Comparison function, for sorting
53  inline static bool comp(const binContainer &lhs, const binContainer &rhs) { return fabs(lhs.value) < fabs(rhs.value); }
54  };
55 
56  struct binCluster {
57  double value;
58  double error;
59  double x;
60  double y;
61  double radius;
62  int n;
63  int ixmin;
64  int ixmax;
65  int iymin;
66  int iymax;
67  inline static bool comp(const binCluster &lhs, const binCluster &rhs) { return fabs(lhs.value) < fabs(rhs.value); }
68  };
69 
70  std::map<std::string, double > GetFitParams(const TF1 * func);
71 
72  std::map<std::string, double > GetFitParamErrors(const TF1 * func);
73 
74  dqm_core::Result * MakeComparisons( const std::map<std::string,double> & algparams,
75  const std::map<std::string,double> & gthreshold,
76  const std::map<std::string,double> & rthreshold );
77 
78  dqm_core::Result * CompareWithErrors( const std::map<std::string,double> & algparams,
79  const std::map<std::string,double> & paramErrors,
80  const std::map<std::string,double> & gthreshold,
81  const std::map<std::string,double> & rthreshold, double minSig);
82 
83  dqm_core::Result * GetFitResult (const TF1 * func, const dqm_core::AlgorithmConfig & config, double minSig = 0) ;
84 
85  double GetFirstFromMap(const std::string &paramName, const std::map<std::string, double > &params);
86  // mandatory: throws an exception if the parameter is not found
87 
88  double GetFirstFromMap(const std::string &paramName, const std::map<std::string, double > &params, double defaultValue);
89  // optional: returns defaultValue if the parameter is not found
90 
91  //string overloads
92  const std::string& GetFirstFromMap(const std::string &paramName, const std::map<std::string, std::string > &params);
93  // mandatory: throws an exception if the parameter is not found
94 
95  const std::string& GetFirstFromMap(const std::string &paramName, const std::map<std::string, std::string > &params, const std::string& defaultValue);
96  // optional: returns defaultValue if the parameter is not found
97 
98  std::vector<int> GetBinRange(const TH1* histogram, const std::map<std::string, double > & params);
99 
100  void PublishBin(const TH1 * histogram, int xbin, int ybin, double content, dqm_core::Result *result);
101 
102  TH1* DivideByHistogram(const TH1* hNumerator, const TH1* hDenominator);
103 
104  void ModifyHistogram(TH1 * histogram, const dqm_core::AlgorithmConfig & config);
105 
106  std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig& config);
107 
108  dqm_core::Result * ExecuteNamedAlgorithm(const std::string & name, const TObject & object,
109  const dqm_core::AlgorithmConfig & config);
110 
111  TH1* BookHistogramByExample(const TH1* histogram, const std::string& name, const std::string& title, AxisType axisType);
112 
113  template <class T>
114  const T & GetFromMap( const std::string & pname, const std::map<std::string,T> & params )
115  {
116  typename std::map<std::string,T>::const_iterator it = params.find( pname );
117  if ( it != params.end() ){
118  return it->second;
119  }else {
120  throw dqm_core::BadConfig( ERS_HERE, "None", pname );
121  }
122  }
123 
137  void handleReference( const TObject& inputReference , const TObject*& firstReference , TObject*& secondReference);
138 
139  // Function to find outliers in input; iterates over values nIteration times, recalculating mean each time and
140  // removing values that are beyond threshold * scale, where:
141  //
142  // scale = ( sum_in[ abs( value - mean )^ exponent ] / (Nin - 1 - SBCF * Nout) ) ^ ( 1 / exponent ).
143  //
144  // If all bins are in, and the exponent is two, this is just and unbiased estimator of the standard variance.
145  // SBCF, or the Scale Bias Correction Factor, is an empirical quantity intended to correct for the bias induced from the
146  // bin exclusion process (in a sense, the act of excluding bins could be thought of as decreasing the number of degrees
147  // of freedom). In practice, the SBCF serves to impose an upper bound on the fraction of bins that can be excluded.
148 
149 
150  void findOutliers( std::vector<binContainer>& input, double& mean, double& scale, int& nIn, int nIterations,
151  double exponent, double threshold, double SBCF = 1., double nStop = 8. );
152 
153  void findOutliersUsingErrors( std::vector<binContainer>& input, double& mean, double& meanError, int& nIn,
154  double mindiff = 0, int minNin = 4);
155 
156  // Method for building a cluster:
157  binCluster buildCluster( binContainer& seed, const std::vector<std::vector<binContainer*> >& binMap,
158  const std::vector<double>& xValues, const std::vector<double>& yValues,
159  double threhold, int topology = CylinderX);
160 
161  // Method for mapping binContainer object by their relative positions:
162  std::vector<std::vector<binContainer*> >
163  makeBinMap(std::vector<dqm_algorithms::tools::binContainer>& bins, int ixmax, int iymax, int topology = CylinderX);
164 
166  WorstCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight = 1.0);
167 
169  BestCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight = 1.0);
170 
171  std::pair<double,double> CalcBinsProbChisq(const std::vector<double>& inputval,const std::vector<double>& inputerr,
172  double x0, double x0_err);
173  std::pair<double,double> CalcBinsProbChisq(const std::vector<double>& inputval,const std::vector<double>& inputerr,
174  const std::vector<double>& x0,const std::vector<double>& x0_err);
175 
176  void MergePastMinStat(std::vector<std::vector<tools::binContainer> >& strips, int minStat);
177 
178  void MakeBinTag( const binContainer& bin, std::string & tag );
179 
180  void FormatToSize( double value, int size, std::string & str, bool showSign = true );
181 
182  }
183 }
184 
185 
186 #endif // #ifndef DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_H
dqm_algorithms::tools::FormatToSize
void FormatToSize(double value, int size, std::string &str, bool showSign=true)
Definition: AlgorithmHelper.cxx:1528
dqm_algorithms::tools::BookHistogramByExample
TH1 * BookHistogramByExample(const TH1 *histogram, const std::string &name, const std::string &title, AxisType axisType)
Definition: AlgorithmHelper.cxx:688
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
dqm_algorithms::tools::binCluster::y
double y
Definition: AlgorithmHelper.h:60
dqm_algorithms::tools::binContainer::comp
static bool comp(const binContainer &lhs, const binContainer &rhs)
Definition: AlgorithmHelper.h:53
dqm_algorithms::tools::findOutliers
void findOutliers(std::vector< binContainer > &input, double &mean, double &scale, int &nIn, int nIterations, double exponent, double threshold, double SBCF=1., double nStop=8.)
Definition: AlgorithmHelper.cxx:888
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
dqm_algorithms::tools::makeBinMap
std::vector< std::vector< binContainer * > > makeBinMap(std::vector< dqm_algorithms::tools::binContainer > &bins, int ixmax, int iymax, int topology=CylinderX)
Definition: AlgorithmHelper.cxx:1214
dqm_algorithms::tools::GetFitResult
dqm_core::Result * GetFitResult(const TF1 *func, const dqm_core::AlgorithmConfig &config, double minSig=0)
Definition: AlgorithmHelper.cxx:308
dqm_algorithms::tools::CalcBinsProbChisq
std::pair< double, double > CalcBinsProbChisq(const std::vector< double > &inputval, const std::vector< double > &inputerr, double x0, double x0_err)
Definition: AlgorithmHelper.cxx:1411
dqm_algorithms::tools::Torus
@ Torus
Definition: AlgorithmHelper.h:41
dqm_algorithms::tools::XYAxes
@ XYAxes
Definition: AlgorithmHelper.h:39
dqm_algorithms::tools::YZAxes
@ YZAxes
Definition: AlgorithmHelper.h:39
skel.it
it
Definition: skel.GENtoEVGEN.py:396
dqm_algorithms::tools::ModifyHistogram
void ModifyHistogram(TH1 *histogram, const dqm_core::AlgorithmConfig &config)
Definition: AlgorithmHelper.cxx:661
bin
Definition: BinsDiffFromStripMedian.h:43
dqm_algorithms::tools::CylinderY
@ CylinderY
Definition: AlgorithmHelper.h:41
athena.value
value
Definition: athena.py:124
dqm_algorithms::tools::ExecuteNamedAlgorithm
dqm_core::Result * ExecuteNamedAlgorithm(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: AlgorithmHelper.cxx:640
dqm_algorithms::tools::PublishBin
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
Definition: AlgorithmHelper.cxx:426
dqm_algorithms::tools::BestCaseAddStatus
dqm_core::Result::Status BestCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
Definition: AlgorithmHelper.cxx:1347
dqm_algorithms::tools::binCluster::error
double error
Definition: AlgorithmHelper.h:58
dqm_algorithms::tools::binCluster::iymin
int iymin
Definition: AlgorithmHelper.h:65
dqm_algorithms::tools::WorstCaseAddStatus
dqm_core::Result::Status WorstCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
Definition: AlgorithmHelper.cxx:1300
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
dqm_algorithms::tools::binCluster::value
double value
Definition: AlgorithmHelper.h:57
dqm_algorithms::tools::ExtractAlgorithmName
std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig &config)
Definition: AlgorithmHelper.cxx:615
dqm_algorithms::tools::binContainer::test
int test
Definition: AlgorithmHelper.h:47
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::tools::binContainer::value
double value
Definition: AlgorithmHelper.h:45
dqm_algorithms::tools::binContainer::x
double x
Definition: AlgorithmHelper.h:50
dqm_algorithms::tools::buildCluster
binCluster buildCluster(binContainer &seed, const std::vector< std::vector< binContainer * > > &binMap, const std::vector< double > &xValues, const std::vector< double > &yValues, double threhold, int topology=CylinderX)
Definition: AlgorithmHelper.cxx:1025
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
dqm_algorithms::tools::binContainer::y
double y
Definition: AlgorithmHelper.h:51
dqm_algorithms::tools::binCluster::n
int n
Definition: AlgorithmHelper.h:62
grepfile.content
string content
Definition: grepfile.py:56
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
dqm_algorithms::tools::XAxis
@ XAxis
Definition: AlgorithmHelper.h:39
dqm_algorithms::tools::MergePastMinStat
void MergePastMinStat(std::vector< std::vector< tools::binContainer > > &strips, int minStat)
Definition: AlgorithmHelper.cxx:1431
dqm_algorithms::tools::CylinderX
@ CylinderX
Definition: AlgorithmHelper.h:41
dqm_algorithms::tools::binCluster
Definition: AlgorithmHelper.h:56
dqm_algorithms::tools::GetFitParamErrors
std::map< std::string, double > GetFitParamErrors(const TF1 *func)
Definition: AlgorithmHelper.cxx:44
dqm_algorithms::tools::binContainer::error
double error
Definition: AlgorithmHelper.h:46
dqm_algorithms::tools::YAxis
@ YAxis
Definition: AlgorithmHelper.h:39
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
covarianceTool.title
title
Definition: covarianceTool.py:542
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
dqm_algorithms::tools::MakeComparisons
dqm_core::Result * MakeComparisons(const std::map< std::string, double > &algparams, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold)
Definition: AlgorithmHelper.cxx:60
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
dqm_algorithms::tools::binCluster::iymax
int iymax
Definition: AlgorithmHelper.h:66
dqm_algorithms::tools::Rectangle
@ Rectangle
Definition: AlgorithmHelper.h:41
dqm_algorithms::tools::AxisType
AxisType
Definition: AlgorithmHelper.h:39
dqm_algorithms::tools::binCluster::comp
static bool comp(const binCluster &lhs, const binCluster &rhs)
Definition: AlgorithmHelper.h:67
dqm_algorithms::tools::binContainer::ix
int ix
Definition: AlgorithmHelper.h:48
dqm_algorithms::tools::GetFitParams
std::map< std::string, double > GetFitParams(const TF1 *func)
Definition: AlgorithmHelper.cxx:30
dqm_algorithms::tools::DivideByHistogram
TH1 * DivideByHistogram(const TH1 *hNumerator, const TH1 *hDenominator)
Definition: AlgorithmHelper.cxx:446
tools
Definition: DataQuality/ZLumiScripts/python/tools/__init__.py:1
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
threshold
Definition: chainparser.cxx:74
dqm_algorithms::tools::binContainer
Definition: AlgorithmHelper.h:44
dqm_algorithms
Definition: AddReference.h:17
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
dqm_algorithms::tools::Topology
Topology
Definition: AlgorithmHelper.h:41
dqm_algorithms::tools::XZAxes
@ XZAxes
Definition: AlgorithmHelper.h:39
dqm_algorithms::tools::binCluster::ixmin
int ixmin
Definition: AlgorithmHelper.h:63
dqm_algorithms::tools::binCluster::ixmax
int ixmax
Definition: AlgorithmHelper.h:64
dqm_algorithms::tools::handleReference
void handleReference(const TObject &inputReference, const TObject *&firstReference, TObject *&secondReference)
Helper function used to handle complex reference histograms This function gets as input a reference o...
Definition: AlgorithmHelper.cxx:828
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
dqm_algorithms::tools::CompareWithErrors
dqm_core::Result * CompareWithErrors(const std::map< std::string, double > &algparams, const std::map< std::string, double > &paramErrors, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold, double minSig)
Definition: AlgorithmHelper.cxx:168
str
Definition: BTagTrackIpAccessor.cxx:11
dqm_algorithms::tools::binContainer::iy
int iy
Definition: AlgorithmHelper.h:49
dqm_algorithms::tools::binCluster::radius
double radius
Definition: AlgorithmHelper.h:61
dqm_algorithms::tools::XYZAxes
@ XYZAxes
Definition: AlgorithmHelper.h:39
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::tools::MakeBinTag
void MakeBinTag(const binContainer &bin, std::string &tag)
Definition: AlgorithmHelper.cxx:1514
dqm_algorithms::tools::binCluster::x
double x
Definition: AlgorithmHelper.h:59
histogram
std::string histogram
Definition: chains.cxx:52
dqm_algorithms::tools::ZAxis
@ ZAxis
Definition: AlgorithmHelper.h:39
dqm_algorithms::tools::findOutliersUsingErrors
void findOutliersUsingErrors(std::vector< binContainer > &input, double &mean, double &meanError, int &nIn, double mindiff=0, int minNin=4)
Definition: AlgorithmHelper.cxx:951