10 #include <dqm_core/AlgorithmConfig.h>
14 #include <dqm_core/AlgorithmManager.h>
38 const TObject&
object,
39 const dqm_core::AlgorithmConfig&
config ){
42 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
45 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 2 " );
48 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
68 if (
histogram->GetEntries() < minstat ) {
79 }
catch( dqm_core::Exception & ex ) {
80 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
84 std::vector<double> stripsSize;
85 std::vector<double> stripsMedian;
86 std::vector<double> stripsAvg;
87 std::vector<double> stripsVariance;
90 if ( (
int)
range.size() < 4 ){
91 throw dqm_core::BadConfig( ERS_HERE,
name,
"BinRange vector <4 " );
95 std::vector<double> onestrip;
98 float binvalue =
histogram->GetBinContent(
i,j);
99 if (std::abs(binvalue- ignoreval1)<0.0001 || std::abs(binvalue - ignoreval2)<0.0001)
continue;
100 onestrip.push_back(binvalue);
101 stripSum += binvalue;
102 if(binvalue > maxInMap) {
106 if(onestrip.size()!=0 ) {
107 stripsAvg.push_back(stripSum/onestrip.size());
109 stripsAvg.push_back(0);
111 FindStripMedianOnline(
name,onestrip,stripsMedian);
112 stripsSize.push_back(onestrip.size());
116 if ((
int)stripsAvg.size() <=
i-
range[0] ){
117 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
119 float strip_avg = stripsAvg[
i-
range[0]];
121 for (
int j =
range[2]; j <=
range[3]; ++j ) {
122 if (std::abs(
histogram->GetBinContent(
i,j)-ignoreval1)<0.0001 || std::abs(
histogram->GetBinContent(
i,j)-ignoreval2)<0.0001)
continue;
123 double binvalue =
histogram->GetBinContent(
i,j);
124 double diff=binvalue-strip_avg;
130 stripsVariance.push_back(variance);
134 std::vector<binOnline> redbins;
135 std::vector<binOnline> yellowbins;
136 std::vector<binOnline> Allbins;
140 if ((
int)stripsSize.size() <=
q ){
141 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsSize range " );
143 if(stripsSize[
q]<minstatperstrip)
continue;
144 if ((
int)stripsMedian.size() <=
q ){
145 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsMedian range " );
147 if ((
int)stripsVariance.size() <=
q){
148 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsVariance range " );
150 if ((
int)stripsAvg.size() <=
q ){
151 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
153 double strip_median = stripsMedian[
q];
154 double strip_variance = stripsVariance[
q];
155 double strip_avg = stripsAvg[
q];
157 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)<0.0001){
160 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)>0.0001) {
161 strip_median = strip_avg;
163 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)<0.0001)
continue;
170 if (std::abs(binvalue-ignoreval1)<0.0001 || std::abs(binvalue-ignoreval2)<0.0001)
continue;
171 double outstandingRatio=0;
172 if(std::abs(strip_median) > 0.0001 ){
173 outstandingRatio= (binvalue-strip_median)/std::sqrt(std::abs(strip_median));
180 Allbins.push_back(onebin);
181 if(std::abs(outstandingRatio) > rthreshold ) {
182 if( VisualMode && (binvalue / maxInMap < suppressRedFactor) ){
185 redbins.push_back(onebin);
186 }
else if(std::abs(outstandingRatio) > gthreshold ){
187 if( VisualMode && (binvalue / maxInMap < suppressFactor) ){
190 yellowbins.push_back(onebin);
195 int count_yellow_c = 0;
196 std::vector<std::vector<colorbinOnline> > ColorBinMap;
200 for (
int q = 0;
q <=
limit; ++
q ) {
202 std::vector<colorbinOnline> oneColorStrip;
205 oneColorStrip.push_back(oneColorBin);
207 ColorBinMap.push_back(std::move(oneColorStrip));
211 for(
unsigned int i=0;
i<redbins.size();
i++){
213 int q=redbins[
i].m_ix -
range[0];
214 int p = redbins[
i].m_iy-
range[2];
216 if ((
int)ColorBinMap.size() <=
q){
217 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
220 if ((
int)ColorBinMap[
q].
size() <=
p ){
221 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
224 ColorBinMap[
q][
p].m_eta = redbins[
i].m_eta;
226 ColorBinMap[
q][
p].m_phi = redbins[
i].m_phi;
227 ColorBinMap[
q][
p].m_value = redbins[
i].m_value;
228 ColorBinMap[
q][
p].m_color =
red;
233 for(
unsigned int i=0;
i<yellowbins.size();
i++){
234 int q=yellowbins[
i].m_ix -
range[0];
235 int p = yellowbins[
i].m_iy-
range[2];
237 if ((
int)ColorBinMap.size() <=
q ){
238 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
241 if ((
int)ColorBinMap[
q].
size() <=
p ){
242 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
245 ColorBinMap[
q][
p].m_eta = yellowbins[
i].m_eta;
246 ColorBinMap[
q][
p].m_phi = yellowbins[
i].m_phi;
247 ColorBinMap[
q][
p].m_value = yellowbins[
i].m_value;
253 std::vector<colorclusterOnline > clusterArray;
254 for(
unsigned int i=0;
i<redbins.size();
i++){
256 int q=redbins[
i].m_ix -
range[0];
257 int p = redbins[
i].m_iy-
range[2];
259 if ((
int)ColorBinMap.size() <=
q ){
260 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
263 if ((
int)ColorBinMap[
q].
size() <=
p ){
264 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
267 if(ColorBinMap[
q][
p].m_color !=
green){
269 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
272 for(
unsigned int i=0;
i<yellowbins.size();
i++){
273 int q=yellowbins[
i].m_ix -
range[0];
274 int p = yellowbins[
i].m_iy-
range[2];
276 if ((
int)ColorBinMap.size() <=
q ){
277 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
280 if ((
int)ColorBinMap[
q].
size() <=
p ){
281 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
284 if(ColorBinMap[
q][
p].m_color !=
green){
286 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
291 for(
unsigned int i=0;
i<clusterArray.size();
i++){
293 if(clusterArray[
i].m_color==
red){
294 snprintf(
tmp,500,
"CR%i-(eta,phi)(r)(size)=(%0.3f,%0.3f)(%0.3f)(%i)",count_red_c,clusterArray[
i].m_eta,clusterArray[
i].m_phi,clusterArray[
i].m_radius,clusterArray[
i].m_size);
296 }
else if(clusterArray[
i].m_color==
yellow){
297 snprintf(
tmp,500,
"CY%i-(eta,phi)(r)(size)=(%0.3f,%0.3f)(%0.3f)(%i)",count_yellow_c,clusterArray[
i].m_eta,clusterArray[
i].m_phi,clusterArray[
i].m_radius,clusterArray[
i].m_size);
303 result->tags_[
"NRedClusters"] = count_red_c;
304 result->tags_[
"NYellowClusters"] = count_yellow_c;
308 std::sort(redbins.begin(),redbins.end());
309 std::sort(yellowbins.begin(),yellowbins.end());
310 std::sort(Allbins.begin(),Allbins.end());
313 for(
unsigned int i=0;
i<redbins.size();
i++){
315 int q = redbins[
i].m_ix-
range[0];
316 int p = redbins[
i].m_iy-
range[2];
319 if(
q<(
int)ColorBinMap.size()){
320 if(
p<(
int)ColorBinMap[
q].
size()){
321 if( ColorBinMap[
q][
p].m_status==0 )
continue;
328 snprintf(
tmp,500,
"R%i-(eta,phi)[OSRatio]=(%0.3f,%0.3f)[%0.2e]",count_red,redbins[
i].m_eta,redbins[
i].m_phi,redbins[
i].m_outstandingRatio);
334 if(count_red > NpublishRed)
break;
340 for(
unsigned int i=0;
i<yellowbins.size();
i++){
341 int q = yellowbins[
i].m_ix-
range[0];
342 int p = yellowbins[
i].m_iy-
range[2];
345 if(
q<(
int)ColorBinMap.size()){
346 if(
p<(
int)ColorBinMap[
q].
size()){
347 if(ColorBinMap[
q][
p].m_status==0)
continue;
351 if(publish && (count_red+count_yellow) < Nmaxpublish ){
353 snprintf(
tmp,500,
"Y%i-(eta,phi)[OSRatio]=(%0.3f,%0.3f)[%.2e]",count_yellow,yellowbins[
i].m_eta,yellowbins[
i].m_phi,yellowbins[
i].m_outstandingRatio);
359 result->tags_[
"NRedBins"] = count_red;
360 result->tags_[
"NYellowBins"] = count_yellow;
362 if(count_red+count_yellow==0 && (
int)Allbins.size()>=5 ){
363 for(
int i=0;
i<5;
i++){
365 snprintf(tmptmp,500,
"LeadingBin%i-(eta,phi)=(%0.3f,%0.3f)",
i,Allbins[
i].m_eta,Allbins[
i].m_phi);
366 std::string tagtag(tmptmp);
367 result->tags_[tagtag] = Allbins[
i].m_value;
374 if(count_red>0 || count_red_c>0) {
377 if (count_yellow>0||count_yellow_c>0) {
378 result->status_ = dqm_core::Result::Yellow;
382 if(count_red>=Nred_red){
384 }
else if (count_red>=Nred_yellow || count_yellow>=Nyellow_yellow || (count_red+count_yellow)>=Nredyellow_yellow){
385 result->status_ = dqm_core::Result::Yellow;
398 std::sort(onestrip_tmp.begin(),onestrip_tmp.end());
399 int index1=(
int)(onestrip_tmp.size()/4.);
401 int index2=(
int)(onestrip_tmp.size()/2.);
402 int index3=(
int) (3.*onestrip_tmp.size()/4.);
403 if(onestrip_tmp.size()>0){
404 if ((
int)onestrip_tmp.size() <=
index1 || (
int)onestrip_tmp.size() <=
index2 || (
int)onestrip_tmp.size() <=
index3){
405 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of onestrip_tmp range " );
410 stripsMedian.push_back(
median);
415 if(
i-r0<0 || i-r0>=(
int)ColorBinMap.size())
return;
416 if( j-r2<0 || j-r2>=(
int)ColorBinMap[
i-r0].
size() )
return;
418 std::vector<colorbinOnline>
tmp;
420 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
421 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
422 if(ColorBinMap[
i-1-r0][j-1-r2].m_status==1){
423 tmp.push_back(ColorBinMap[
i-1-r0][j-1-r2]);
424 ColorBinMap[
i-1-r0][j-1-r2].m_status=0;
428 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
429 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-r0].
size()){
430 if(ColorBinMap[
i-r0][j-1-r2].m_status==1){
431 tmp.push_back(ColorBinMap[
i-r0][j-1-r2]);
432 ColorBinMap[
i-r0][j-1-r2].m_status=0;
437 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
438 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
439 if(ColorBinMap[
i+1-r0][j-1-r2].m_status==1){
440 tmp.push_back(ColorBinMap[
i+1-r0][j-1-r2]);
441 ColorBinMap[
i+1-r0][j-1-r2].m_status=0;
446 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
447 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i-1-r0].
size()){
448 if(ColorBinMap[
i-1-r0][j-r2].m_status==1){
449 tmp.push_back(ColorBinMap[
i-1-r0][j-r2]);
450 ColorBinMap[
i-1-r0][j-r2].m_status=0;
456 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
457 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i+1-r0].
size()){
458 if(ColorBinMap[
i+1-r0][j-r2].m_status==1){
459 tmp.push_back(ColorBinMap[
i+1-r0][j-r2]);
460 ColorBinMap[
i+1-r0][j-r2].m_status=0;
466 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
467 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
468 if(ColorBinMap[
i-1-r0][j+1-r2].m_status==1){
469 tmp.push_back(ColorBinMap[
i-1-r0][j+1-r2]);
470 ColorBinMap[
i-1-r0][j+1-r2].m_status=0;
475 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
476 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-r0].
size()){
477 if(ColorBinMap[
i-r0][j+1-r2].m_status==1){
478 tmp.push_back(ColorBinMap[
i-r0][j+1-r2]);
479 ColorBinMap[
i-r0][j+1-r2].m_status=0;
484 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
485 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
486 if(ColorBinMap[
i+1-r0][j+1-r2].m_status==1){
487 tmp.push_back(ColorBinMap[
i+1-r0][j+1-r2]);
488 ColorBinMap[
i+1-r0][j+1-r2].m_status=0;
493 for(
unsigned int k=0;
k<
tmp.size();
k++){
495 LookAtList.push_back(
tmp[
k]);
506 for(
unsigned int i=0;
i<LookAtList.size();
i++){
507 double eta = LookAtList[
i].m_eta;
508 double n = LookAtList[
i].m_value;
522 for(
unsigned int i=0;
i<LookAtList.size();
i++){
523 double phi = LookAtList[
i].m_phi;
524 double n = LookAtList[
i].m_value;
537 for(
unsigned int i=0;
i<LookAtList.size();
i++){
538 double n = LookAtList[
i].m_value;
544 if(LookAtList.size()<2)
return 0;
546 for(
unsigned int i=0;
i<LookAtList.size();
i++){
557 if ((
int)ColorBinMap.size() <= (onebin.
m_ix-r0) ){
558 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
561 if ((
int)ColorBinMap[onebin.
m_ix-r0].size() <= (onebin.
m_iy-r2) ){
562 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
565 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status==0)
567 std::vector<colorbinOnline> LookAtList;
568 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color!=
green){
569 LookAtList.push_back(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2]);
570 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=0;
572 if(LookAtList.size()>1){
573 onecluster.
m_size = LookAtList.size();
575 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color==
red){
584 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=1;
592 out<<
"BinsDiffFromStripMedianOnline: Calculates smoothed strip median and then find out bins which are aliens "<<std::endl;
594 out<<
"Mandatory Green/Red Threshold is the value of outstandingRatio=(bin value)/(strip median) based on which to give Green/Red result\n"<<std::endl;
596 out<<
"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
597 out<<
"Optional Parameter: MinStatPerstrip: Minimum strip statistics needed to perform Algorithm"<<std::endl;
598 out<<
"Optional Parameter: ignoreval0: values to be ignored for being processed"<<std::endl;
599 out<<
"Optional Parameter: ignoreval1: values to be ignored for being processed"<<std::endl;
600 out<<
"Optional Parameter: PublishBins: Save bins which are different from average in Result (on:1,off:0,default is 1)"<<std::endl;
601 out<<
"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
602 out<<
"Optional Parameter: VisualMode: is to make the evaluation process similar to the shift work, so one will get resonable result efficiently."<<std::endl;
604 out<<
"Optional Parameter: PublishRedBins: Max number of red bins to save."<<std::endl;
605 out<<
"Optional Parameter: ClusterResult: to cluster close bad bins together."<<std::endl;
606 out<<
"Optional Parameter: SuppressFactor: if the ratio of the bin contennt to max one in the histogram is smaller than SuppressFactor, don't set the bin as red or yellow ."<<std::endl;
607 out<<
"Optional Parameter: SuppressRedFactor: if the ratio of the bin contennt to max one in the histogram is smaller than SuppressRedFactor, don't set the bin as red ."<<std::endl;
608 out<<
"Optional Parameter: OnlineMode: switch on when running online."<<std::endl;
609 out<<
"Optional Parameter: Nred_red: minimum number of red bins needed to label the histogram as red."<<std::endl;
610 out<<
"Optional Parameter: Nyellow_yellow: minimum number of yellow bins needed to label the histogram as yellow."<<std::endl;
611 out<<
"Optional Parameter: Nred_yellow: minimum number of red bins needed to label the histogram as yellow."<<std::endl;
612 out<<
"Optional Parameter: Nredyellow_yellow: minimum number of yellow+red bins needed to label the histogram as yellow."<<std::endl;