18 #include "dqm_core/exceptions.h"
19 #include "dqm_core/AlgorithmConfig.h"
20 #include "dqm_core/AlgorithmManager.h"
21 #include "dqm_core/Result.h"
61 if(
object.
IsA()->InheritsFrom(
"TH2" ) ) {
63 if (
hist->GetDimension() != 2 ){
64 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension != 2 " );
67 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH2" );
76 double using_ref_for_flag;
77 std::string thresholdname;
78 if (
m_name ==
"MDTOverview_Global") {
79 thresholdname=
"Percentage";
80 }
else if (
m_name ==
"MDTOverview_Station") {
81 thresholdname=
"Limits";
83 throw dqm_core::BadConfig( ERS_HERE,
"None",
m_name );
93 catch ( dqm_core::Exception & ex ) {
94 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
99 ref =
static_cast<const TH2 *
>(
config.getReference() );
101 catch ( dqm_core::Exception & ex ) {
102 throw dqm_core::BadRefHist(ERS_HERE,
name,
" Could not retreive reference");
104 if (
hist->GetDimension() !=
ref->GetDimension() ) {
105 throw dqm_core::BadRefHist( ERS_HERE,
name,
"Reference VS histo: Different dimension!" );
110 if (
hist->GetEntries() < minstat ) {
111 ERS_INFO(
"Histogram does not satisfy MinStat requirement " <<
hist->GetName());
113 result->tags_[
"InsufficientEntries"] =
hist->GetEntries();
116 ERS_DEBUG(1,
"Statistics: "<<
hist->GetEntries()<<
" entries ");
124 std::vector<int> hist_buffer;
125 std::vector<int> ref_buffer;
127 for(
int x_index=1;x_index<=
binX;x_index++){
128 for(
int y_index=1;y_index<=
binY;y_index++){
129 if(
hist->GetBinContent(x_index,y_index) != 0 ) hist_buffer.push_back((
int)
hist->GetBinContent(x_index,y_index));
130 if(
ref->GetBinContent(x_index,y_index) != 0 ) ref_buffer.push_back((
int)
ref->GetBinContent(x_index,y_index));
134 const char *htitle =
hist->GetTitle();
135 ERS_DEBUG(1,
"Histogram title: "<< htitle);
137 if (
m_name ==
"MDTOverview_Global") {
140 if (strstr(htitle,
"BA")) {
142 }
else if (strstr(htitle,
"BC")) {
144 }
else if (strstr(htitle,
"EA")) {
146 }
else if (strstr(htitle,
"EC")) {
150 }
else if (
m_name ==
"MDTOverview_Station") {
152 if (strstr(htitle,
"B")) {
153 if (strstr(htitle,
"Inner")) {
154 ERS_DEBUG(1,
"Station Inner ");
156 }
else if (strstr(htitle,
"Middle")) {
157 ERS_DEBUG(1,
"Station Middle ");
159 }
else if (strstr(htitle,
"Outer")) {
160 ERS_DEBUG(1,
"Station Outer ");
161 if (strstr(htitle,
"BA")) {
163 }
else if (strstr(htitle,
"BC")) {
168 }
else if (strstr(htitle,
"E")) {
170 if (strstr(htitle,
"Inner")) {
171 ERS_DEBUG(1,
"Station Inner ");
173 }
else if (strstr(htitle,
"Middle")) {
174 ERS_DEBUG(1,
"Station Middle ");
176 }
else if (strstr(htitle,
"Outer")) {
177 ERS_DEBUG(1,
"Station Outer ");
179 }
else if (strstr(htitle,
"extra")) {
180 ERS_DEBUG(1,
"Extra chambers (BEE, EEL, BIS7, BIS8)");
186 auto median=[](std::vector<int> &
v)->
int {
187 const auto midPoint =
v.begin()+
v.size()/2;
188 std::nth_element(
v.begin(), midPoint,
v.end());
189 return v[
v.size()/2];
194 int mediana_hist =
median(hist_buffer);
195 int mediana_ref =
median(ref_buffer);
196 const int size_hist = hist_buffer.size();
203 std::pair<int,int> empty_bin;
204 std::vector< std::pair<int,int> > new_empty_bins;
206 for(
int y_index=1;y_index<=
binY;y_index++){
214 for(
int x_index=1;x_index<=
binX;x_index++){
215 if(using_ref_for_flag) {
216 if(
hist->GetBinContent(x_index,y_index)< mediana_hist*
thresh/100 &&
ref->GetBinContent(x_index,y_index) >= mediana_ref*
thresh/100){
219 if(
hist->GetBinContent(x_index,y_index)>0) count_non_0++;
222 if(
hist->GetBinContent(x_index,y_index)< mediana_hist*
thresh/100){
229 if(ML_count==2 && sec_count>0){
230 empty_bin.first=sector;
231 empty_bin.second=sec_count;
232 new_empty_bins.push_back(empty_bin);
238 result->tags_[
"Configuration_ERROR_Setted_N_tot_ML"] = nML;
245 result->tags_[
"00-%_ML_ON"] = 100*((
double)(size_hist-count_non_0)/nML);
247 if(thresholdname ==
"Limits" ) {
251 std::string
tag1=
"Sector";
252 std::string
tag2=
"_number_of_ML_off";
254 for(
int j=0; j<(
int)new_empty_bins.size(); j++){
257 result->tags_[
tag] = new_empty_bins[j].second;
260 if (nML-
count-size_hist > 0)
result->tags_[
"02-KNOWN_ML_OFF"] = nML-
count-size_hist;
266 }
else if ( count <= redTh && count > greenTh ) {
267 result->status_ = dqm_core::Result::Yellow;
268 ERS_DEBUG(1,
"Yellow");
269 }
else if (
count <= greenTh) {
271 ERS_DEBUG(1,
"Green");
274 ERS_DEBUG(1,
"Undefined");
277 }
else if (thresholdname ==
"Percentage") {
279 if (100*((
double)size_hist/nML)<redTh) {
282 }
else if ( 100*((
double)size_hist/nML)>=redTh && 100*((
double)size_hist/nML)<greenTh ) {
283 result->status_ = dqm_core::Result::Yellow;
284 ERS_DEBUG(1,
"Yellow");
285 }
else if (100*((
double)size_hist/nML)>=greenTh) {
287 ERS_DEBUG(1,
"Green");
290 ERS_DEBUG(1,
"Undefined");
303 message +=
"Description: check if there are any bins with less then a thresh% of the entries of the median bin\n";
304 message +=
" and perform a comparison with reference.\n";
305 message +=
"MDTOverview_Global: Mandatory Green/Red Threshold: Percentage: of ML OFF\n";
306 message +=
"MDTOverview_Station: Mandatory Green/Red Threshold: Limits: number of ML OFF\n";
307 message +=
"Optional Parameters: thresh = min % of hits from the median chamber accepted\n";
308 message +=
" MinStat = Minimum histogram statistics needed to perform Algorithm\n";
309 message +=
" using_ref_for_flag = if enabled (1) it compares the OFF MLs with reference, if not enabled (0)\n";
310 message +=
" the flag is setted checking the absolute % of ML on in the detector\n";