ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
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 <iostream>
26
27class TF1;
28class TAxis;
29
30namespace dqm_algorithms
31{
32 namespace tools
33 {
35
37
38 //Structure to hold the essence of a 2D histogram bin, and be sortable:
39 struct binContainer {
40 double value;
41 double error;
42 int test;
43 int ix;
44 int iy;
45 double x;
46 double y;
47 //Comparison function, for sorting
48 inline static bool comp(const binContainer &lhs, const binContainer &rhs) { return fabs(lhs.value) < fabs(rhs.value); }
49 };
50
51 struct binCluster {
52 double value;
53 double error;
54 double x;
55 double y;
56 double radius;
57 int n;
58 int ixmin;
59 int ixmax;
60 int iymin;
61 int iymax;
62 inline static bool comp(const binCluster &lhs, const binCluster &rhs) { return fabs(lhs.value) < fabs(rhs.value); }
63 };
64
65 std::map<std::string, double > GetFitParams(const TF1 * func);
66
67 std::map<std::string, double > GetFitParamErrors(const TF1 * func);
68
69 dqm_core::Result * MakeComparisons( const std::map<std::string,double> & algparams,
70 const std::map<std::string,double> & gthreshold,
71 const std::map<std::string,double> & rthreshold );
72
73 dqm_core::Result * CompareWithErrors( const std::map<std::string,double> & algparams,
74 const std::map<std::string,double> & paramErrors,
75 const std::map<std::string,double> & gthreshold,
76 const std::map<std::string,double> & rthreshold, double minSig);
77
78 dqm_core::Result * GetFitResult (const TF1 * func, const dqm_core::AlgorithmConfig & config, double minSig = 0) ;
79
80 double GetFirstFromMap(const std::string &paramName, const std::map<std::string, double > &params);
81 // mandatory: throws an exception if the parameter is not found
82
83 double GetFirstFromMap(const std::string &paramName, const std::map<std::string, double > &params, double defaultValue);
84 // optional: returns defaultValue if the parameter is not found
85
86 //string overloads
87 const std::string& GetFirstFromMap(const std::string &paramName, const std::map<std::string, std::string > &params);
88 // mandatory: throws an exception if the parameter is not found
89
90 const std::string& GetFirstFromMap(const std::string &paramName, const std::map<std::string, std::string > &params, const std::string& defaultValue);
91 // optional: returns defaultValue if the parameter is not found
92
93 std::vector<int> GetBinRange(const TH1* histogram, const std::map<std::string, double > & params);
94
95 void PublishBin(const TH1 * histogram, int xbin, int ybin, double content, dqm_core::Result *result);
96
97 TH1* DivideByHistogram(const TH1* hNumerator, const TH1* hDenominator);
98
99 void ModifyHistogram(TH1 * histogram, const dqm_core::AlgorithmConfig & config);
100
101 std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig& config);
102
103 dqm_core::Result * ExecuteNamedAlgorithm(const std::string & name, const TObject & object,
104 const dqm_core::AlgorithmConfig & config);
105
106 TH1* BookHistogramByExample(const TH1* histogram, const std::string& name, const std::string& title, AxisType axisType);
107
108 template <class T>
109 const T & GetFromMap( const std::string & pname, const std::map<std::string,T> & params )
110 {
111 typename std::map<std::string,T>::const_iterator it = params.find( pname );
112 if ( it != params.end() ){
113 return it->second;
114 }else {
115 throw dqm_core::BadConfig( ERS_HERE, "None", pname );
116 }
117 }
118
132 void handleReference( const TObject& inputReference , const TObject*& firstReference , TObject*& secondReference);
133
134 // Function to find outliers in input; iterates over values nIteration times, recalculating mean each time and
135 // removing values that are beyond threshold * scale, where:
136 //
137 // scale = ( sum_in[ abs( value - mean )^ exponent ] / (Nin - 1 - SBCF * Nout) ) ^ ( 1 / exponent ).
138 //
139 // If all bins are in, and the exponent is two, this is just and unbiased estimator of the standard variance.
140 // SBCF, or the Scale Bias Correction Factor, is an empirical quantity intended to correct for the bias induced from the
141 // bin exclusion process (in a sense, the act of excluding bins could be thought of as decreasing the number of degrees
142 // of freedom). In practice, the SBCF serves to impose an upper bound on the fraction of bins that can be excluded.
143
144
145 void findOutliers( std::vector<binContainer>& input, double& mean, double& scale, int& nIn, int nIterations,
146 double exponent, double threshold, double SBCF = 1., double nStop = 8. );
147
148 void findOutliersUsingErrors( std::vector<binContainer>& input, double& mean, double& meanError, int& nIn,
149 double mindiff = 0, int minNin = 4);
150
151 // Method for building a cluster:
152 binCluster buildCluster( binContainer& seed, const std::vector<std::vector<binContainer*> >& binMap,
153 const std::vector<double>& xValues, const std::vector<double>& yValues,
154 double threhold, int topology = CylinderX);
155
156 // Method for mapping binContainer object by their relative positions:
157 std::vector<std::vector<binContainer*> >
158 makeBinMap(std::vector<dqm_algorithms::tools::binContainer>& bins, int ixmax, int iymax, int topology = CylinderX);
159
160 dqm_core::Result::Status
161 WorstCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight = 1.0);
162
163 dqm_core::Result::Status
164 BestCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight = 1.0);
165
166 std::pair<double,double> CalcBinsProbChisq(const std::vector<double>& inputval,const std::vector<double>& inputerr,
167 double x0, double x0_err);
168 std::pair<double,double> CalcBinsProbChisq(const std::vector<double>& inputval,const std::vector<double>& inputerr,
169 const std::vector<double>& x0,const std::vector<double>& x0_err);
170
171 void MergePastMinStat(std::vector<std::vector<tools::binContainer> >& strips, int minStat);
172
173 void MakeBinTag( const binContainer& bin, std::string & tag );
174
175 void FormatToSize( double value, int size, std::string & str, bool showSign = true );
176
177 }
178}
179
180
181#endif // #ifndef DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_H
static const std::vector< std::string > bins
size_t size() const
Number of registered mappings.
std::string histogram
Definition chains.cxx:52
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="")
void FormatToSize(double value, int size, std::string &str, bool showSign=true)
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
dqm_core::Result::Status WorstCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
void findOutliersUsingErrors(std::vector< binContainer > &input, double &mean, double &meanError, int &nIn, double mindiff=0, int minNin=4)
std::pair< double, double > CalcBinsProbChisq(const std::vector< double > &inputval, const std::vector< double > &inputerr, double x0, double x0_err)
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
TH1 * DivideByHistogram(const TH1 *hNumerator, const TH1 *hDenominator)
std::vector< std::vector< binContainer * > > makeBinMap(std::vector< dqm_algorithms::tools::binContainer > &bins, int ixmax, int iymax, int topology=CylinderX)
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)
TH1 * BookHistogramByExample(const TH1 *histogram, const std::string &name, const std::string &title, AxisType axisType)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
void MakeBinTag(const binContainer &bin, std::string &tag)
void MergePastMinStat(std::vector< std::vector< tools::binContainer > > &strips, int minStat)
dqm_core::Result * GetFitResult(const TF1 *func, const dqm_core::AlgorithmConfig &config, double minSig=0)
std::string ExtractAlgorithmName(const dqm_core::AlgorithmConfig &config)
void findOutliers(std::vector< binContainer > &input, double &mean, double &scale, int &nIn, int nIterations, double exponent, double threshold, double SBCF=1., double nStop=8.)
std::map< std::string, double > GetFitParamErrors(const TF1 *func)
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)
dqm_core::Result::Status BestCaseAddStatus(dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
dqm_core::Result * ExecuteNamedAlgorithm(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
void ModifyHistogram(TH1 *histogram, const dqm_core::AlgorithmConfig &config)
std::map< std::string, double > GetFitParams(const TF1 *func)
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)
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...
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
static bool comp(const binCluster &lhs, const binCluster &rhs)
static bool comp(const binContainer &lhs, const binContainer &rhs)