57{
60
61 if(
object.
IsA()->InheritsFrom(
"TH2" ) ) {
63 if (
hist->GetDimension() != 2 ){
64 throw dqm_core::BadConfig( ERS_HERE, name, "dimension != 2 " );
65 }
66 } else {
67 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
68 }
69
70
71
72 double greenTh;
73 double redTh;
74 double minstat;
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";
82 } else {
83 throw dqm_core::BadConfig( ERS_HERE,
"None",
m_name );
84 }
85
86 try {
92 }
93 catch ( dqm_core::Exception & ex ) {
94 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
95 }
96
97
98 try {
99 ref =
static_cast<const TH2 *
>(
config.getReference() );
100 }
101 catch ( dqm_core::Exception & ex ) {
102 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
103 }
104 if (
hist->GetDimension() !=
ref->GetDimension() ) {
105 throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
106 }
107
108
109
110 if (
hist->GetEntries() < minstat ) {
111 ERS_INFO(
"Histogram does not satisfy MinStat requirement " <<
hist->GetName());
112 dqm_core::Result *
result =
new dqm_core::Result(dqm_core::Result::Undefined);
113 result->tags_[
"InsufficientEntries"] =
hist->GetEntries();
115 }
116 ERS_DEBUG(1,
"Statistics: "<<
hist->GetEntries()<<
" entries ");
117
118
119
122 double nML=0;
123
124 std::vector<int> hist_buffer;
125 std::vector<int> ref_buffer;
126
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));
131 };
132 };
133
134 const char *htitle =
hist->GetTitle();
135 ERS_DEBUG(1,"Histogram title: "<< htitle);
136
137 if (
m_name ==
"MDTOverview_Global") {
138
139
140 if (strstr(htitle, "BA")) {
141 nML = 594;
142 } else if (strstr(htitle, "BC")) {
143 nML = 590;
144 } else if (strstr(htitle, "EA")) {
145 nML = 502;
146 } else if (strstr(htitle, "EC")) {
147 nML = 502;
148 }
149
150 }
else if (
m_name ==
"MDTOverview_Station") {
151
152 if (strstr(htitle, "B")) {
153 if (strstr(htitle,"Inner")) {
154 ERS_DEBUG(1,"Station Inner ");
155 nML = 212;
156 } else if (strstr(htitle,"Middle")) {
157 ERS_DEBUG(1,"Station Middle ");
158 nML = 178;
159 } else if (strstr(htitle,"Outer")) {
160 ERS_DEBUG(1,"Station Outer ");
161 if (strstr(htitle, "BA")) {
162 nML = 204;
163 } else if (strstr(htitle, "BC")) {
164 nML = 200;
165 }
166 }
167
168 } else if (strstr(htitle, "E")) {
169
170 if (strstr(htitle,"Inner")) {
171 ERS_DEBUG(1,"Station Inner ");
172 nML = 124;
173 } else if (strstr(htitle,"Middle")) {
174 ERS_DEBUG(1,"Station Middle ");
175 nML = 160;
176 } else if (strstr(htitle,"Outer")) {
177 ERS_DEBUG(1,"Station Outer ");
178 nML = 192;
179 } else if (strstr(htitle,"extra")) {
180 ERS_DEBUG(1,"Extra chambers (BEE, EEL, BIS7, BIS8)");
181 nML = 26;
182 }
183 }
184 }
185
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];
190 };
191
192
193
194 int mediana_hist =
median(hist_buffer);
195 int mediana_ref =
median(ref_buffer);
196 const int size_hist = hist_buffer.size();
197
199 int count_non_0=0;
200 int sec_count=0;
201 int ML_count=0;
202 int sector=1;
203 std::pair<int,int> empty_bin;
204 std::vector< std::pair<int,int> > new_empty_bins;
205
206 for(
int y_index=1;y_index<=
binY;y_index++){
207 if(ML_count==2){
208 ML_count=0;
209 sec_count=0;
210 sector++;
211 };
212 ML_count++;
213
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){
217 sec_count++;
219 if(
hist->GetBinContent(x_index,y_index)>0) count_non_0++;
220 }
221 } else {
222 if(
hist->GetBinContent(x_index,y_index)< mediana_hist*thresh/100){
223 sec_count++;
225 };
226 }
227 };
228
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);
233 }
234 };
235
236 if(nML<=0){
237 dqm_core::Result*
result =
new dqm_core::Result();
238 result->tags_[
"Configuration_ERROR_Setted_N_tot_ML"] = nML;
239 result->status_ = dqm_core::Result::Undefined;
241 };
242
243
244 dqm_core::Result*
result =
new dqm_core::Result();
245 result->tags_[
"00-%_ML_ON"] = 100*((
double)(size_hist-count_non_0)/nML);
246
247 if(thresholdname == "Limits" ) {
248
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++){
255 std::string formatted = std::format("{:02d}", new_empty_bins[j].first);
257 result->tags_[
tag] = new_empty_bins[j].second;
258 };
259 }
260 if (nML-
count-size_hist > 0)
result->tags_[
"02-KNOWN_ML_OFF"] = nML-
count-size_hist;
261
262
264 result->status_ = dqm_core::Result::Red;
265 ERS_DEBUG(1,"Red");
267 result->status_ = dqm_core::Result::Yellow;
268 ERS_DEBUG(1,"Yellow");
269 }
else if (
count <= greenTh) {
270 result->status_ = dqm_core::Result::Green;
271 ERS_DEBUG(1,"Green");
272 } else {
273 result->status_ = dqm_core::Result::Undefined;
274 ERS_DEBUG(1,"Undefined");
275 }
276
277 } else if (thresholdname == "Percentage") {
278
279 if (100*((double)size_hist/nML)<redTh) {
280 result->status_ = dqm_core::Result::Red;
281 ERS_DEBUG(1,"Red");
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) {
286 result->status_ = dqm_core::Result::Green;
287 ERS_DEBUG(1,"Green");
288 } else {
289 result->status_ = dqm_core::Result::Undefined;
290 ERS_DEBUG(1,"Undefined");
291 }
292 }
294}
const boost::regex ref(r_ef)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
float median(std::vector< float > &Vec)
#define IsA
Declare the TObject style functions.