ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::BinsSymmetric Struct Reference

#include <BinsSymmetric.h>

Inheritance diagram for dqm_algorithms::BinsSymmetric:
Collaboration diagram for dqm_algorithms::BinsSymmetric:

Public Member Functions

 BinsSymmetric ()
 ~BinsSymmetric ()
BinsSymmetricclone ()
dqm_core::Result * execute (const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
void printDescription (std::ostream &out)

Detailed Description

Definition at line 18 of file BinsSymmetric.h.

Constructor & Destructor Documentation

◆ BinsSymmetric()

dqm_algorithms::BinsSymmetric::BinsSymmetric ( )

Definition at line 25 of file BinsSymmetric.cxx.

26{
27 dqm_core::AlgorithmManager::instance().registerAlgorithm("BinsSymmetric",this);
28}

◆ ~BinsSymmetric()

dqm_algorithms::BinsSymmetric::~BinsSymmetric ( )

Definition at line 30 of file BinsSymmetric.cxx.

31{
32}

Member Function Documentation

◆ clone()

dqm_algorithms::BinsSymmetric * dqm_algorithms::BinsSymmetric::clone ( )

Definition at line 34 of file BinsSymmetric.cxx.

35{
36 return new BinsSymmetric();
37}

◆ execute()

dqm_core::Result * dqm_algorithms::BinsSymmetric::execute ( const std::string & name,
const TObject & object,
const dqm_core::AlgorithmConfig & config )

Definition at line 40 of file BinsSymmetric.cxx.

43{
44
45 const TH1 * histogram;
46
47 if (object.IsA()->InheritsFrom("TH1")){
48
49 histogram = static_cast<const TH1*>(&object);
50
51 if (histogram->GetDimension() > 3 ){
52 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 3 " );
53 }
54 } else {
55 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
56 }
57
58 if (histogram->GetEntries() == 0) {
59 ERS_DEBUG(1, "Histogram " <<histogram->GetName()<<" is Empty");
60 return new dqm_core::Result(dqm_core::Result::Red);
61 }
62
63 const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
64 const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
65 const double mindiffabs = (double) dqm_algorithms::tools::GetFirstFromMap( "MaxDiffAbs", config.getParameters(), 0);
66 const double bin_threshold = (double) dqm_algorithms::tools::GetFirstFromMap( "NSigmaBin", config.getParameters(), 3);
67 const bool ignorezero = (bool) dqm_algorithms::tools::GetFirstFromMap("IgnoreZero",config.getParameters(), 0);
68
69 double gthreshold;
70 double rthreshold;
71
72 try {
73 rthreshold = dqm_algorithms::tools::GetFromMap( "NSigma", config.getRedThresholds() );
74 gthreshold = dqm_algorithms::tools::GetFromMap( "NSigma", config.getGreenThresholds() );
75 }
76 catch( dqm_core::Exception & ex ) {
77 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
78 }
79
80 int count = 0;
81
82 std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
83
84 dqm_core::Result* result = new dqm_core::Result();
85
86 // vectors for global chisq calculation
87 std::vector<double> binvals,binerrs;
88 std::vector<double> refvals,referrs;
89 double small_num = 1.e-05;
90
91 // logic to see if there is a bin at the central value. If so compare central to average of two bins on either side
92 bool even_nbins = ((range[1] - range[0] + 1) % 2 == 0) ? true : false;
93 int range_comp = (range[1] - range[0] + 1) / 2;
94
95 int start_bin_low = range[1] - range_comp;
96 int start_bin_high = range[0] + range_comp;
97
98 // check central bin if there is one
99 if (!even_nbins){
100
101 double xbin0 = histogram->GetBinCenter(start_bin_low);
102
103 double bin0 = histogram->GetBinContent(start_bin_low);
104 double bin1 = histogram->GetBinContent(start_bin_low + 1);
105 double bin2 = histogram->GetBinContent(start_bin_low - 1);
106
107 double binerr0 = histogram->GetBinError(start_bin_low);
108 double binerr1 = histogram->GetBinError(start_bin_low + 1);
109 double binerr2 = histogram->GetBinError(start_bin_low - 1);
110
111 double mean_bins = (bin1+bin2)/2.;
112 double errmean_bins = std::sqrt(std::pow(binerr1,2.)+std::pow(binerr2,2.)/2.);
113
114 double diff = std::abs(bin0 - mean_bins);
115 double differr = std::sqrt(std::pow(binerr0,2.)+std::pow(errmean_bins,2));
116 double sigma = 1.;
117
118 if ((!ignorezero) || (bin0 != 0 && mean_bins != 0)){
119
120 binvals.push_back(bin0);
121 binerrs.push_back(binerr0);
122 // use reference bin for chisq calculation as the combined bin from neighbours
123 refvals.push_back(mean_bins);
124 referrs.push_back(errmean_bins);
125
126 if (differr/diff > small_num) sigma = diff/differr;
127
128 // sigma threshold used to highlight potentially problematic bins
129 if (sigma > bin_threshold && (std::abs(diff) > mindiffabs)) {
130
131 ++count;
132
133 if (publish && count <= maxpublish) {
134
135 std::ostringstream os;
136 os << "Sigma(" << xbin0 << ")(" << bin0 << "," << mean_bins << ")";
137 std::string badbins = os.str();
138 result->tags_[badbins.c_str()] = sigma;
139 ERS_DEBUG(1,"x bin" << start_bin_low << " value " << bin0 << " sigma difference " << sigma);
140
141 }
142 }
143 }
144 }
145
146 // now loop over all the other bins
147 for (int i = 0; i < range_comp; ++i){
148
149 double binhigh = histogram->GetBinContent(start_bin_high+i);
150 double binlow = histogram->GetBinContent(start_bin_low-i);
151
152 double xbinhigh = histogram->GetBinCenter(start_bin_high+i);
153
154 double binerrhigh = histogram->GetBinError(start_bin_high+i);
155 double binerrlow = histogram->GetBinError(start_bin_low-i);
156
157 double diff = std::abs(binlow - binhigh);
158 double differr = std::sqrt(std::pow(binerrlow,2.)+std::pow(binerrhigh,2));
159
160 if ((!ignorezero) || (binlow != 0 && binhigh != 0)){
161
162 binvals.push_back(binhigh);
163 binerrs.push_back(binerrlow);
164 refvals.push_back(binlow);
165 referrs.push_back(binerrlow);
166
167 double sigma = 1.;
168 if (differr > small_num) sigma = diff/differr;
169
170 if (sigma > bin_threshold && (std::abs(diff) > mindiffabs)) {
171
172 ++count;
173 if (publish && count <= maxpublish){
174
175 std::ostringstream os;
176 os << "Sigma(" << xbinhigh << ")" << "(" << binlow << "," << binhigh << ")";
177 std::string badbins = os.str();
178 result->tags_[badbins.c_str()] = sigma;
179 ERS_DEBUG(1,"x bin " << start_bin_high+i << " value " << binhigh);
180 ERS_DEBUG(1,"x bin " << start_bin_low-i << " value " << binlow << " sigma difference " << sigma);
181 }
182 }
183 }
184 }
185
186 std::pair<double,double> chisq_prob = dqm_algorithms::tools::CalcBinsProbChisq(binvals,binerrs,refvals,referrs);
187
188 ERS_DEBUG(1, "Number of bins " << bin_threshold << " Sigma away from reference bin is " << count);
189 ERS_DEBUG(1, "Green threshold: "<< gthreshold << " bin(s); Red threshold : " << rthreshold << " bin(s) ");
190 result->tags_["NBins"] = count;
191 result->tags_["SigmaChisq"] = chisq_prob.second;
192
193 // cut on sigma, this can be eventually modified to cut on prob as well
194
195 double sigma_check = std::abs(chisq_prob.second);
196 if ( sigma_check <= gthreshold ) {
197 result->status_ = dqm_core::Result::Green;
198 } else if ( sigma_check < rthreshold ) {
199 result->status_ = dqm_core::Result::Yellow;
200 } else {
201 result->status_ = dqm_core::Result::Red;
202 }
203 return result;
204
205}
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
std::string histogram
Definition chains.cxx:52
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
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)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
setBGCode setTAP setLVL2ErrorBits bool
#define IsA
Declare the TObject style functions.

◆ printDescription()

void dqm_algorithms::BinsSymmetric::printDescription ( std::ostream & out)

Definition at line 207 of file BinsSymmetric.cxx.

207 {
208
209 out<<"BinsSymmetric: Checks if histogram is symmetric around mid-point of given range. works only for 1-D histograms \n"<<std::endl;
210out<<"Mandatory Green/Red Threshold: NSigma: N sigma for chisq global fit probability to be away from 0 from unit normal distribution. Thresholds are for Green/Red results\n"<<std::endl;
211 out<<"Optional Parameter: NSigmaBin: Number of sigma bins must be over opposite bin to be flagged and reported (default 3) \n"<<std::endl;
212 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
213 out<<"Optional Parameter: xmin: minimum x range"<<std::endl;
214 out<<"Optional Parameter: xmax: maximum x range"<<std::endl;
215 out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)"<<std::endl;
216 out<<"Optional Parameter: MaxDiffAbs: test fails if NBins more than NSigma away and NBins more than MaxDiffAbs (absolut difference) away"<<std::endl;
217 out<<"Optional Parameter: MaxDiffRel: test fails if NBins more than NSigma away and NBins more than MaxDiffRel (relative difference) away\n"<<std::endl;
218
219}

The documentation for this struct was generated from the following files: