9 #include <dqm_core/AlgorithmConfig.h>
21 #include <dqm_core/AlgorithmManager.h>
41 const TObject &
object,
42 const dqm_core::AlgorithmConfig &
config)
47 if (
object.
IsA()->InheritsFrom(
"TH1")){
52 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 3 " );
55 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
59 ERS_DEBUG(1,
"Histogram " <<
histogram->GetName()<<
" is Empty");
76 catch( dqm_core::Exception & ex ) {
77 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
87 std::vector<double> binvals,binerrs;
88 std::vector<double> refvals,referrs;
89 double small_num = 1.e-05;
92 bool even_nbins = ((
range[1] -
range[0] + 1) % 2 == 0) ? true :
false;
93 int range_comp = (
range[1] -
range[0] + 1) / 2;
95 int start_bin_low =
range[1] - range_comp;
96 int start_bin_high =
range[0] + range_comp;
101 double xbin0 =
histogram->GetBinCenter(start_bin_low);
103 double bin0 =
histogram->GetBinContent(start_bin_low);
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);
112 double errmean_bins = std::sqrt(
std::pow(binerr1,2.)+
std::pow(binerr2,2.)/2.);
114 double diff = std::abs(bin0 - mean_bins);
118 if ((!ignorezero) || (bin0 != 0 && mean_bins != 0)){
120 binvals.push_back(bin0);
121 binerrs.push_back(binerr0);
123 refvals.push_back(mean_bins);
124 referrs.push_back(errmean_bins);
129 if (
sigma > bin_threshold && (std::abs(
diff) > mindiffabs)) {
133 if (publish &&
count <= maxpublish) {
135 std::ostringstream
os;
136 os <<
"Sigma(" << xbin0 <<
")(" << bin0 <<
"," << mean_bins <<
")";
137 std::string badbins =
os.str();
139 ERS_DEBUG(1,
"x bin" << start_bin_low <<
" value " << bin0 <<
" sigma difference " <<
sigma);
147 for (
int i = 0;
i < range_comp; ++
i){
149 double binhigh =
histogram->GetBinContent(start_bin_high+
i);
150 double binlow =
histogram->GetBinContent(start_bin_low-
i);
152 double xbinhigh =
histogram->GetBinCenter(start_bin_high+
i);
154 double binerrhigh =
histogram->GetBinError(start_bin_high+
i);
155 double binerrlow =
histogram->GetBinError(start_bin_low-
i);
157 double diff = std::abs(binlow - binhigh);
160 if ((!ignorezero) || (binlow != 0 && binhigh != 0)){
162 binvals.push_back(binhigh);
163 binerrs.push_back(binerrlow);
164 refvals.push_back(binlow);
165 referrs.push_back(binerrlow);
168 if (differr > small_num)
sigma =
diff/differr;
170 if (
sigma > bin_threshold && (std::abs(
diff) > mindiffabs)) {
173 if (publish &&
count <= maxpublish){
175 std::ostringstream
os;
176 os <<
"Sigma(" << xbinhigh <<
")" <<
"(" << binlow <<
"," << binhigh <<
")";
177 std::string badbins =
os.str();
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);
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) ");
191 result->tags_[
"SigmaChisq"] = chisq_prob.second;
195 double sigma_check = std::abs(chisq_prob.second);
196 if ( sigma_check <= gthreshold ) {
198 }
else if ( sigma_check < rthreshold ) {
199 result->status_ = dqm_core::Result::Yellow;
209 out<<
"BinsSymmetric: Checks if histogram is symmetric around mid-point of given range. works only for 1-D histograms \n"<<std::endl;
210 out<<
"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;