10 #include <dqm_core/AlgorithmConfig.h>
14 #include <dqm_core/AlgorithmManager.h>
43 const TObject&
object,
44 const dqm_core::AlgorithmConfig&
config ){
47 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
50 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 2 " );
53 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
73 if (
histogram->GetEntries() < minstat ) {
84 }
catch( dqm_core::Exception & ex ) {
85 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
89 std::vector<double> stripsSize;
90 std::vector<double> stripsMedian;
91 std::vector<double> stripsAvg;
92 std::vector<double> stripsVariance;
95 if ( (
int)
range.size() < 4 ){
96 throw dqm_core::BadConfig( ERS_HERE,
name,
"BinRange vector <4 " );
100 std::vector<double> onestrip;
102 for (
int j =
range[2]; j <=
range[3]; ++j ) {
103 float binvalue =
histogram->GetBinContent(
i,j);
104 if (std::abs(binvalue- ignoreval1)<0.0001 || std::abs(binvalue - ignoreval2)<0.0001)
continue;
105 onestrip.push_back(binvalue);
106 stripSum += binvalue;
107 if(binvalue > maxInMap) {
111 if(onestrip.size()!=0 ) {
112 stripsAvg.push_back(stripSum/onestrip.size());
114 stripsAvg.push_back(0);
116 FindStripMedianOnline(
name,onestrip,stripsMedian);
117 stripsSize.push_back(onestrip.size());
121 if ((
int)stripsAvg.size() <=
i-
range[0] ){
122 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
124 float strip_avg = stripsAvg[
i-
range[0]];
126 for (
int j =
range[2]; j <=
range[3]; ++j ) {
127 if (std::abs(
histogram->GetBinContent(
i,j)-ignoreval1)<0.0001 || std::abs(
histogram->GetBinContent(
i,j)-ignoreval2)<0.0001)
continue;
128 double binvalue =
histogram->GetBinContent(
i,j);
129 double diff=binvalue-strip_avg;
135 stripsVariance.push_back(variance);
139 std::vector<binOnline> redbins;
140 std::vector<binOnline> yellowbins;
141 std::vector<binOnline> Allbins;
145 if ((
int)stripsSize.size() <=
q ){
146 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsSize range " );
148 if(stripsSize[
q]<minstatperstrip)
continue;
149 if ((
int)stripsMedian.size() <=
q ){
150 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsMedian range " );
152 if ((
int)stripsVariance.size() <=
q){
153 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsVariance range " );
155 if ((
int)stripsAvg.size() <=
q ){
156 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
158 double strip_median = stripsMedian[
q];
159 double strip_variance = stripsVariance[
q];
160 double strip_avg = stripsAvg[
q];
162 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)<0.0001){
165 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)>0.0001) {
166 strip_median = strip_avg;
168 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)<0.0001)
continue;
175 if (std::abs(binvalue-ignoreval1)<0.0001 || std::abs(binvalue-ignoreval2)<0.0001)
continue;
176 double outstandingRatio=0;
177 if(std::abs(strip_median) > 0.0001 ){
178 outstandingRatio= (binvalue-strip_median)/std::sqrt(std::abs(strip_median));
185 Allbins.push_back(onebin);
187 if(std::abs(outstandingRatio) > rthreshold ) {
188 if( VisualMode && (binvalue / maxInMap < suppressRedFactor) ){
191 redbins.push_back(onebin);
192 }
else if(std::abs(outstandingRatio) > gthreshold ){
193 if( VisualMode && (binvalue / maxInMap < suppressFactor) ){
196 yellowbins.push_back(onebin);
201 int count_yellow_c = 0;
202 std::vector<std::vector<colorbinOnline> > ColorBinMap;
206 for (
int q = 0;
q <=
limit; ++
q ) {
208 std::vector<colorbinOnline> oneColorStrip;
212 oneColorStrip.push_back(oneColorBin);
214 ColorBinMap.push_back(oneColorStrip);
218 for(
unsigned int i=0;
i<redbins.size();
i++){
221 int q=redbins[
i].m_ix -
range[0];
222 int p = redbins[
i].m_iy-
range[2];
224 if ((
int)ColorBinMap.size() <=
q){
225 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
228 if ((
int)ColorBinMap[
q].
size() <=
p ){
229 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
232 ColorBinMap[
q][
p].m_eta = redbins[
i].m_eta;
234 ColorBinMap[
q][
p].m_phi = redbins[
i].m_phi;
235 ColorBinMap[
q][
p].m_value = redbins[
i].m_value;
236 ColorBinMap[
q][
p].m_color =
red;
241 for(
unsigned int i=0;
i<yellowbins.size();
i++){
244 int q=yellowbins[
i].m_ix -
range[0];
245 int p = yellowbins[
i].m_iy-
range[2];
247 if ((
int)ColorBinMap.size() <=
q ){
248 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
251 if ((
int)ColorBinMap[
q].
size() <=
p ){
252 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
255 ColorBinMap[
q][
p].m_eta = yellowbins[
i].m_eta;
256 ColorBinMap[
q][
p].m_phi = yellowbins[
i].m_phi;
257 ColorBinMap[
q][
p].m_value = yellowbins[
i].m_value;
263 std::vector<colorclusterOnline > clusterArray;
264 for(
unsigned int i=0;
i<redbins.size();
i++){
267 int q=redbins[
i].m_ix -
range[0];
268 int p = redbins[
i].m_iy-
range[2];
270 if ((
int)ColorBinMap.size() <=
q ){
271 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
274 if ((
int)ColorBinMap[
q].
size() <=
p ){
275 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
278 if(ColorBinMap[
q][
p].m_color !=
green){
281 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
284 for(
unsigned int i=0;
i<yellowbins.size();
i++){
287 int q=yellowbins[
i].m_ix -
range[0];
288 int p = yellowbins[
i].m_iy-
range[2];
290 if ((
int)ColorBinMap.size() <=
q ){
291 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
294 if ((
int)ColorBinMap[
q].
size() <=
p ){
295 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
298 if(ColorBinMap[
q][
p].m_color !=
green){
301 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
306 for(
unsigned int i=0;
i<clusterArray.size();
i++){
308 if(clusterArray[
i].m_color==
red){
309 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);
311 }
else if(clusterArray[
i].m_color==
yellow){
312 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);
318 result->tags_[
"NRedClusters"] = count_red_c;
319 result->tags_[
"NYellowClusters"] = count_yellow_c;
324 std::sort(redbins.begin(),redbins.end());
326 std::sort(yellowbins.begin(),yellowbins.end());
328 std::sort(Allbins.begin(),Allbins.end());
331 for(
unsigned int i=0;
i<redbins.size();
i++){
333 int q = redbins[
i].m_ix-
range[0];
334 int p = redbins[
i].m_iy-
range[2];
337 if(
q<(
int)ColorBinMap.size()){
338 if(
p<(
int)ColorBinMap[
q].
size()){
339 if( ColorBinMap[
q][
p].m_status==0 )
continue;
346 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);
352 if(count_red > NpublishRed)
break;
358 for(
unsigned int i=0;
i<yellowbins.size();
i++){
359 int q = yellowbins[
i].m_ix-
range[0];
360 int p = yellowbins[
i].m_iy-
range[2];
363 if(
q<(
int)ColorBinMap.size()){
364 if(
p<(
int)ColorBinMap[
q].
size()){
365 if(ColorBinMap[
q][
p].m_status==0)
continue;
369 if(publish && (count_red+count_yellow) < Nmaxpublish ){
371 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);
377 result->tags_[
"NRedBins"] = count_red;
378 result->tags_[
"NYellowBins"] = count_yellow;
380 if(count_red+count_yellow==0 && (
int)Allbins.size()>=5 ){
381 for(
int i=0;
i<5;
i++){
383 snprintf(tmptmp,500,
"LeadingBin%i-(eta,phi)=(%0.3f,%0.3f)",
i,Allbins[
i].m_eta,Allbins[
i].m_phi);
384 std::string tagtag(tmptmp);
385 result->tags_[tagtag] = Allbins[
i].m_value;
392 if(count_red>0 || count_red_c>0) {
395 if (count_yellow>0||count_yellow_c>0) {
396 result->status_ = dqm_core::Result::Yellow;
400 if(count_red>=Nred_red){
402 }
else if (count_red>=Nred_yellow || count_yellow>=Nyellow_yellow || (count_red+count_yellow)>=Nredyellow_yellow){
403 result->status_ = dqm_core::Result::Yellow;
417 std::sort(onestrip_tmp.begin(),onestrip_tmp.end());
418 int index1=(
int)(onestrip_tmp.size()/4.);
421 int index2=(
int)(onestrip_tmp.size()/2.);
422 int index3=(
int) (3.*onestrip_tmp.size()/4.);
424 if(onestrip_tmp.size()>0){
425 if ((
int)onestrip_tmp.size() <=
index1 || (
int)onestrip_tmp.size() <=
index2 || (
int)onestrip_tmp.size() <=
index3){
426 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of onestrip_tmp range " );
432 stripsMedian.push_back(
median);
438 if(
i-r0<0 || i-r0>=(
int)ColorBinMap.size())
return;
439 if( j-r2<0 || j-r2>=(
int)ColorBinMap[
i-r0].
size() )
return;
441 std::vector<colorbinOnline>
tmp;
443 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
444 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
445 if(ColorBinMap[
i-1-r0][j-1-r2].m_status==1){
446 tmp.push_back(ColorBinMap[
i-1-r0][j-1-r2]);
447 ColorBinMap[
i-1-r0][j-1-r2].m_status=0;
451 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
452 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-r0].
size()){
453 if(ColorBinMap[
i-r0][j-1-r2].m_status==1){
454 tmp.push_back(ColorBinMap[
i-r0][j-1-r2]);
455 ColorBinMap[
i-r0][j-1-r2].m_status=0;
460 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
461 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
462 if(ColorBinMap[
i+1-r0][j-1-r2].m_status==1){
463 tmp.push_back(ColorBinMap[
i+1-r0][j-1-r2]);
464 ColorBinMap[
i+1-r0][j-1-r2].m_status=0;
469 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
470 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i-1-r0].
size()){
471 if(ColorBinMap[
i-1-r0][j-r2].m_status==1){
472 tmp.push_back(ColorBinMap[
i-1-r0][j-r2]);
473 ColorBinMap[
i-1-r0][j-r2].m_status=0;
479 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
480 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i+1-r0].
size()){
481 if(ColorBinMap[
i+1-r0][j-r2].m_status==1){
482 tmp.push_back(ColorBinMap[
i+1-r0][j-r2]);
483 ColorBinMap[
i+1-r0][j-r2].m_status=0;
489 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
490 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
491 if(ColorBinMap[
i-1-r0][j+1-r2].m_status==1){
492 tmp.push_back(ColorBinMap[
i-1-r0][j+1-r2]);
493 ColorBinMap[
i-1-r0][j+1-r2].m_status=0;
498 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
499 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-r0].
size()){
500 if(ColorBinMap[
i-r0][j+1-r2].m_status==1){
501 tmp.push_back(ColorBinMap[
i-r0][j+1-r2]);
502 ColorBinMap[
i-r0][j+1-r2].m_status=0;
507 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
508 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
509 if(ColorBinMap[
i+1-r0][j+1-r2].m_status==1){
510 tmp.push_back(ColorBinMap[
i+1-r0][j+1-r2]);
511 ColorBinMap[
i+1-r0][j+1-r2].m_status=0;
516 for(
unsigned int k=0;
k<
tmp.size();
k++){
518 LookAtList.push_back(
tmp[
k]);
529 for(
unsigned int i=0;
i<LookAtList.size();
i++){
530 double eta = LookAtList[
i].m_eta;
531 double n = LookAtList[
i].m_value;
545 for(
unsigned int i=0;
i<LookAtList.size();
i++){
546 double phi = LookAtList[
i].m_phi;
547 double n = LookAtList[
i].m_value;
560 for(
unsigned int i=0;
i<LookAtList.size();
i++){
561 double n = LookAtList[
i].m_value;
567 if(LookAtList.size()<2)
return 0;
569 for(
unsigned int i=0;
i<LookAtList.size();
i++){
580 if ((
int)ColorBinMap.size() <= (onebin.
m_ix-r0) ){
581 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
584 if ((
int)ColorBinMap[onebin.
m_ix-r0].size() <= (onebin.
m_iy-r2) ){
585 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
588 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status==0)
590 std::vector<colorbinOnline> LookAtList;
591 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color!=
green){
592 LookAtList.push_back(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2]);
593 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=0;
595 if(LookAtList.size()>1){
596 onecluster.
m_size = LookAtList.size();
598 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color==
red){
607 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=1;
615 out<<
"BinsDiffFromStripMedianOnline: Calculates smoothed strip median and then find out bins which are aliens "<<std::endl;
617 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;
619 out<<
"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
620 out<<
"Optional Parameter: MinStatPerstrip: Minimum strip statistics needed to perform Algorithm"<<std::endl;
621 out<<
"Optional Parameter: ignoreval0: values to be ignored for being processed"<<std::endl;
622 out<<
"Optional Parameter: ignoreval1: values to be ignored for being processed"<<std::endl;
623 out<<
"Optional Parameter: PublishBins: Save bins which are different from average in Result (on:1,off:0,default is 1)"<<std::endl;
624 out<<
"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
625 out<<
"Optional Parameter: VisualMode: is to make the evaluation process similar to the shift work, so one will get resonable result efficiently."<<std::endl;
627 out<<
"Optional Parameter: PublishRedBins: Max number of red bins to save."<<std::endl;
628 out<<
"Optional Parameter: ClusterResult: to cluster close bad bins together."<<std::endl;
629 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;
630 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;
631 out<<
"Optional Parameter: OnlineMode: switch on when running online."<<std::endl;
632 out<<
"Optional Parameter: Nred_red: minimum number of red bins needed to label the histogram as red."<<std::endl;
633 out<<
"Optional Parameter: Nyellow_yellow: minimum number of yellow bins needed to label the histogram as yellow."<<std::endl;
634 out<<
"Optional Parameter: Nred_yellow: minimum number of red bins needed to label the histogram as yellow."<<std::endl;
635 out<<
"Optional Parameter: Nredyellow_yellow: minimum number of yellow+red bins needed to label the histogram as yellow."<<std::endl;