9 #include <dqm_core/AlgorithmConfig.h>
19 #include <dqm_core/AlgorithmManager.h>
52 const TObject &
object,
53 const dqm_core::AlgorithmConfig &
config )
57 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
60 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 2 " );
63 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
76 std::vector<int> hotColumns, hotRows;
77 std::vector<std::vector<int>> hotBins;
79 parseVetoList(ignoreBins, hotRows, hotColumns, hotBins);
81 bool vetoHotRows =
false;
if (hotRows.size() > 0) vetoHotRows =
true;
82 bool vetoHotBins =
false;
if (hotBins.size() > 0) vetoHotBins =
true;
83 bool vetoHotColumns =
false;
if (hotColumns.size() > 0) vetoHotColumns =
true;
99 catch ( dqm_core::Exception & ex ) {
100 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
110 }
else if (
histogram->InheritsFrom(
"TH1")) {
113 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
116 resulthisto->Reset();
117 if(
m_name.find(
"Median")!=std::string::npos){
118 std::vector<double> bin_vals;
120 for (
int j =
range[2]; j <=
range[3]; ++j ) {
121 if(
histogram -> GetBinContent(
i,j) > 0) bin_vals . push_back(
histogram -> GetBinContent(
i,j) );
124 std::sort(bin_vals.begin(), bin_vals.end());
125 unsigned bin_vals_size = bin_vals.size();
127 if(bin_vals_size%2==0 && bin_vals_size>1)
median = (bin_vals.at(bin_vals_size/2-1)+bin_vals.at(bin_vals_size/2))/2;
128 else if(bin_vals_size%2==1 && bin_vals_size>1)
median = bin_vals.at(bin_vals_size/2-1);
129 else if(bin_vals_size==1)
median = bin_vals.at(0);
133 bin_threshold=
median*bin_threshold;
135 bin_threshold =
std::max(bin_threshold, min_bin_threshold);
136 if(max_bin_threshold > -1 ) bin_threshold =
std::min(bin_threshold, max_bin_threshold);
138 result->tags_[
"Effective_BinThreshold"] = bin_threshold;
142 bool skipColumn =
false;
143 bool skipRow =
false;
144 bool skipBin =
false;
148 for (
int column : hotColumns){
149 if (vetoHotColumns && (
column ==
i || skipColumn ==
true)) skipColumn =
true;
152 if (skipColumn)
continue;
158 for (
int j =
range[2]; j <=
range[3]; ++j ) {
159 skipRow =
false; skipBin =
false;
160 for (
int row : hotRows){
161 if (vetoHotRows && (
row == j || skipRow ==
true)) skipRow =
true;
163 for (
const auto& pair : hotBins){
164 if (vetoHotBins && ( (pair[0] ==
i && pair[1] == j) || skipBin ==
true)) skipBin =
true;
167 if (skipBin)
continue;
169 if (skipRow)
continue;
178 resulthisto->SetBinContent(
i,j,
content);
179 if (publish &&
count< maxpublish){
186 ERS_DEBUG(1,
"Number of bins " <<
m_name <<
" treshold of " << bin_threshold <<
" is " <<
count );
187 ERS_DEBUG(1,
"Green threshold: "<< gthreshold <<
" bin(s); Red threshold : " << rthreshold <<
" bin(s) ");
193 if(
m_name.find(
"LessThan")!=std::string::npos)
result->tags_[
"NBins_%"] = 100.*effectiveCount/TotalBins;
194 else result->tags_[
"NBins_%"] = 100.*
count/TotalBins;
198 result->object_ = (boost::shared_ptr<TObject>)(TObject*)(resulthisto);
199 if (gthreshold > rthreshold) {
200 if (
count >= gthreshold ) {
202 }
else if (
count > rthreshold ) {
203 result->status_ = dqm_core::Result::Yellow;
208 if (
count <= gthreshold ) {
210 }
else if (
count < rthreshold ) {
211 result->status_ = dqm_core::Result::Yellow;
225 if (
type ==
"GreaterThanAbs")
return (std::abs(bincontent) >
threshold);
226 if (
type ==
"GreaterThanNonZeroMedian")
return (bincontent >
threshold);
228 if (
type ==
"LessThanAbs")
return (std::abs(bincontent) <
threshold);
229 if (
type ==
"LessThanNonZeroMedian")
return (bincontent <
threshold);
230 if (
type ==
"LessThanEqual")
return (bincontent <=
threshold);
231 if (
type ==
"GreaterThanEqual")
return (bincontent >=
threshold);
240 std::string inputNoQuotes;
241 for (
char c : input)
if (
c !=
'"') inputNoQuotes +=
c;
243 std::stringstream
ss(inputNoQuotes);
246 while (std::getline(
ss, token,
',')) {
247 std::stringstream pairStream(token);
250 if (std::getline(pairStream,
first,
':') && std::getline(pairStream,
second,
':')) {
253 }
else if (
second ==
"*") {
266 out<<
"Bins_"+
m_name+
"_Threshold: Checks for number of bins "+
m_name+
" threshold value\n"<<std::endl;
268 out<<
"Mandatory Parameter: BinThreshold: Look for bins "+
m_name+
" BinTreshold; Count number of bins satifying requirement \n"<<std::endl;
270 out<<
"Mandatory Green/Red Threshold: NBins: Number of bins satifying "+
m_name+
" BinThreshold constraint to give Green/Red result\n"<<std::endl;
272 out<<
"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)\n"<<std::endl;
273 out<<
"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
274 out<<
"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
275 out<<
"Optional Parameter: xmin: minimum x range"<<std::endl;
276 out<<
"Optional Parameter: xmax: maximum x range"<<std::endl;
277 out<<
"Optional Parameter: ymin: minimum y range"<<std::endl;
278 out<<
"Optional Parameter: ymax: maximum y range\n"<<std::endl;
279 out<<
"Optional Parameter: ignoreBins: list of bins to ignore in the threshold comparison (x,y) in a string, separated by comas and semicolons. Ex: 1:3,6:7. It also allows to pass rows and columns like *:4 and *:4 respectively \n"<<std::endl;