10 #include <dqm_core/AlgorithmConfig.h>
14 #include <dqm_core/AlgorithmManager.h>
39 const TObject&
object,
40 const dqm_core::AlgorithmConfig&
config ){
43 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
46 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 2 " );
49 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
69 if (
histogram->GetEntries() < minstat ) {
80 }
catch( dqm_core::Exception & ex ) {
81 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
85 std::vector<double> stripsSize;
86 std::vector<double> stripsMedian;
87 std::vector<double> stripsAvg;
88 std::vector<double> stripsVariance;
91 if ( (
int)
range.size() < 4 ){
92 throw dqm_core::BadConfig( ERS_HERE,
name,
"BinRange vector <4 " );
96 std::vector<double> onestrip;
99 float binvalue =
histogram->GetBinContent(
i,j);
100 if (std::abs(binvalue- ignoreval1)<0.0001 || std::abs(binvalue - ignoreval2)<0.0001)
continue;
101 onestrip.push_back(binvalue);
102 stripSum += binvalue;
103 if(binvalue > maxInMap) {
107 if(onestrip.size()!=0 ) {
108 stripsAvg.push_back(stripSum/onestrip.size());
110 stripsAvg.push_back(0);
112 FindStripMedianOnline(
name,onestrip,stripsMedian);
113 stripsSize.push_back(onestrip.size());
117 if ((
int)stripsAvg.size() <=
i-
range[0] ){
118 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
120 float strip_avg = stripsAvg[
i-
range[0]];
122 for (
int j =
range[2]; j <=
range[3]; ++j ) {
123 if (std::abs(
histogram->GetBinContent(
i,j)-ignoreval1)<0.0001 || std::abs(
histogram->GetBinContent(
i,j)-ignoreval2)<0.0001)
continue;
124 double binvalue =
histogram->GetBinContent(
i,j);
125 double diff=binvalue-strip_avg;
131 stripsVariance.push_back(variance);
135 std::vector<binOnline> redbins;
136 std::vector<binOnline> yellowbins;
137 std::vector<binOnline> Allbins;
141 if ((
int)stripsSize.size() <=
q ){
142 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsSize range " );
144 if(stripsSize[
q]<minstatperstrip)
continue;
145 if ((
int)stripsMedian.size() <=
q ){
146 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsMedian range " );
148 if ((
int)stripsVariance.size() <=
q){
149 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsVariance range " );
151 if ((
int)stripsAvg.size() <=
q ){
152 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of stripsAvg range " );
154 double strip_median = stripsMedian[
q];
155 double strip_variance = stripsVariance[
q];
156 double strip_avg = stripsAvg[
q];
158 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)<0.0001){
161 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)>0.0001) {
162 strip_median = strip_avg;
164 if(std::abs(strip_median)<0.0001 && std::abs(strip_variance)>0.0001 && std::abs(strip_avg)<0.0001)
continue;
171 if (std::abs(binvalue-ignoreval1)<0.0001 || std::abs(binvalue-ignoreval2)<0.0001)
continue;
172 double outstandingRatio=0;
173 if(std::abs(strip_median) > 0.0001 ){
174 outstandingRatio= (binvalue-strip_median)/std::sqrt(std::abs(strip_median));
178 double eta =
histogram->GetXaxis()->GetBinCenter(
k);
179 double phi =
histogram->GetYaxis()->GetBinCenter(
l);
180 binOnline onebin = {eta,phi,
k,
l,binvalue,outstandingRatio};
181 Allbins.push_back(onebin);
182 if(std::abs(outstandingRatio) > rthreshold ) {
183 if( VisualMode && (binvalue / maxInMap < suppressRedFactor) ){
186 redbins.push_back(onebin);
187 }
else if(std::abs(outstandingRatio) > gthreshold ){
188 if( VisualMode && (binvalue / maxInMap < suppressFactor) ){
191 yellowbins.push_back(onebin);
196 int count_yellow_c = 0;
197 std::vector<std::vector<colorbinOnline> > ColorBinMap;
201 for (
int q = 0;
q <=
limit; ++
q ) {
203 std::vector<colorbinOnline> oneColorStrip;
206 oneColorStrip.push_back(oneColorBin);
208 ColorBinMap.push_back(oneColorStrip);
212 for(
unsigned int i=0;
i<redbins.size();
i++){
214 int q=redbins[
i].m_ix -
range[0];
215 int p = redbins[
i].m_iy-
range[2];
217 if ((
int)ColorBinMap.size() <=
q){
218 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
221 if ((
int)ColorBinMap[
q].
size() <=
p ){
222 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
225 ColorBinMap[
q][
p].m_eta = redbins[
i].m_eta;
227 ColorBinMap[
q][
p].m_phi = redbins[
i].m_phi;
228 ColorBinMap[
q][
p].m_value = redbins[
i].m_value;
229 ColorBinMap[
q][
p].m_color =
red;
234 for(
unsigned int i=0;
i<yellowbins.size();
i++){
235 int q=yellowbins[
i].m_ix -
range[0];
236 int p = yellowbins[
i].m_iy-
range[2];
238 if ((
int)ColorBinMap.size() <=
q ){
239 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
242 if ((
int)ColorBinMap[
q].
size() <=
p ){
243 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
246 ColorBinMap[
q][
p].m_eta = yellowbins[
i].m_eta;
247 ColorBinMap[
q][
p].m_phi = yellowbins[
i].m_phi;
248 ColorBinMap[
q][
p].m_value = yellowbins[
i].m_value;
254 std::vector<colorclusterOnline > clusterArray;
255 for(
unsigned int i=0;
i<redbins.size();
i++){
257 int q=redbins[
i].m_ix -
range[0];
258 int p = redbins[
i].m_iy-
range[2];
260 if ((
int)ColorBinMap.size() <=
q ){
261 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
264 if ((
int)ColorBinMap[
q].
size() <=
p ){
265 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
268 if(ColorBinMap[
q][
p].m_color !=
green){
270 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
273 for(
unsigned int i=0;
i<yellowbins.size();
i++){
274 int q=yellowbins[
i].m_ix -
range[0];
275 int p = yellowbins[
i].m_iy-
range[2];
277 if ((
int)ColorBinMap.size() <=
q ){
278 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
281 if ((
int)ColorBinMap[
q].
size() <=
p ){
282 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
285 if(ColorBinMap[
q][
p].m_color !=
green){
287 if((
int)onecluster.
m_size > 1) clusterArray.push_back(onecluster);
292 for(
unsigned int i=0;
i<clusterArray.size();
i++){
294 if(clusterArray[
i].m_color==
red){
295 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);
297 }
else if(clusterArray[
i].m_color==
yellow){
298 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);
304 result->tags_[
"NRedClusters"] = count_red_c;
305 result->tags_[
"NYellowClusters"] = count_yellow_c;
309 std::sort(redbins.begin(),redbins.end());
310 std::sort(yellowbins.begin(),yellowbins.end());
311 std::sort(Allbins.begin(),Allbins.end());
314 for(
unsigned int i=0;
i<redbins.size();
i++){
316 int q = redbins[
i].m_ix-
range[0];
317 int p = redbins[
i].m_iy-
range[2];
320 if(
q<(
int)ColorBinMap.size()){
321 if(
p<(
int)ColorBinMap[
q].
size()){
322 if( ColorBinMap[
q][
p].m_status==0 )
continue;
329 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);
335 if(count_red > NpublishRed)
break;
341 for(
unsigned int i=0;
i<yellowbins.size();
i++){
342 int q = yellowbins[
i].m_ix-
range[0];
343 int p = yellowbins[
i].m_iy-
range[2];
346 if(
q<(
int)ColorBinMap.size()){
347 if(
p<(
int)ColorBinMap[
q].
size()){
348 if(ColorBinMap[
q][
p].m_status==0)
continue;
352 if(publish && (count_red+count_yellow) < Nmaxpublish ){
354 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);
360 result->tags_[
"NRedBins"] = count_red;
361 result->tags_[
"NYellowBins"] = count_yellow;
363 if(count_red+count_yellow==0 && (
int)Allbins.size()>=5 ){
364 for(
int i=0;
i<5;
i++){
366 snprintf(tmptmp,500,
"LeadingBin%i-(eta,phi)=(%0.3f,%0.3f)",
i,Allbins[
i].m_eta,Allbins[
i].m_phi);
367 std::string tagtag(tmptmp);
368 result->tags_[tagtag] = Allbins[
i].m_value;
375 if(count_red>0 || count_red_c>0) {
378 if (count_yellow>0||count_yellow_c>0) {
379 result->status_ = dqm_core::Result::Yellow;
383 if(count_red>=Nred_red){
385 }
else if (count_red>=Nred_yellow || count_yellow>=Nyellow_yellow || (count_red+count_yellow)>=Nredyellow_yellow){
386 result->status_ = dqm_core::Result::Yellow;
399 std::sort(onestrip_tmp.begin(),onestrip_tmp.end());
400 int index1=(
int)(onestrip_tmp.size()/4.);
402 int index2=(
int)(onestrip_tmp.size()/2.);
403 int index3=(
int) (3.*onestrip_tmp.size()/4.);
404 if(onestrip_tmp.size()>0){
405 if ((
int)onestrip_tmp.size() <=
index1 || (
int)onestrip_tmp.size() <=
index2 || (
int)onestrip_tmp.size() <=
index3){
406 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of onestrip_tmp range " );
411 stripsMedian.push_back(
median);
416 if(
i-r0<0 || i-r0>=(
int)ColorBinMap.size())
return;
417 if( j-r2<0 || j-r2>=(
int)ColorBinMap[
i-r0].
size() )
return;
419 std::vector<colorbinOnline>
tmp;
421 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
422 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
423 if(ColorBinMap[
i-1-r0][j-1-r2].m_status==1){
424 tmp.push_back(ColorBinMap[
i-1-r0][j-1-r2]);
425 ColorBinMap[
i-1-r0][j-1-r2].m_status=0;
429 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
430 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i-r0].
size()){
431 if(ColorBinMap[
i-r0][j-1-r2].m_status==1){
432 tmp.push_back(ColorBinMap[
i-r0][j-1-r2]);
433 ColorBinMap[
i-r0][j-1-r2].m_status=0;
438 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
439 if(j-1-r2>=0 && j-1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
440 if(ColorBinMap[
i+1-r0][j-1-r2].m_status==1){
441 tmp.push_back(ColorBinMap[
i+1-r0][j-1-r2]);
442 ColorBinMap[
i+1-r0][j-1-r2].m_status=0;
447 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
448 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i-1-r0].
size()){
449 if(ColorBinMap[
i-1-r0][j-r2].m_status==1){
450 tmp.push_back(ColorBinMap[
i-1-r0][j-r2]);
451 ColorBinMap[
i-1-r0][j-r2].m_status=0;
457 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
458 if(j-r2>=0 && j-r2<(
int)ColorBinMap[
i+1-r0].
size()){
459 if(ColorBinMap[
i+1-r0][j-r2].m_status==1){
460 tmp.push_back(ColorBinMap[
i+1-r0][j-r2]);
461 ColorBinMap[
i+1-r0][j-r2].m_status=0;
467 if(
i-1-r0>=0 &&
i-1-r0<(
int)ColorBinMap.size()){
468 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-1-r0].
size()){
469 if(ColorBinMap[
i-1-r0][j+1-r2].m_status==1){
470 tmp.push_back(ColorBinMap[
i-1-r0][j+1-r2]);
471 ColorBinMap[
i-1-r0][j+1-r2].m_status=0;
476 if(
i-r0>=0 &&
i-r0<(
int)ColorBinMap.size()){
477 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i-r0].
size()){
478 if(ColorBinMap[
i-r0][j+1-r2].m_status==1){
479 tmp.push_back(ColorBinMap[
i-r0][j+1-r2]);
480 ColorBinMap[
i-r0][j+1-r2].m_status=0;
485 if(
i+1-r0>=0 &&
i+1-r0<(
int)ColorBinMap.size()){
486 if(j+1-r2>=0 && j+1-r2<(
int)ColorBinMap[
i+1-r0].
size()){
487 if(ColorBinMap[
i+1-r0][j+1-r2].m_status==1){
488 tmp.push_back(ColorBinMap[
i+1-r0][j+1-r2]);
489 ColorBinMap[
i+1-r0][j+1-r2].m_status=0;
494 for(
unsigned int k=0;
k<
tmp.size();
k++){
496 LookAtList.push_back(
tmp[
k]);
507 for(
unsigned int i=0;
i<LookAtList.size();
i++){
508 double eta = LookAtList[
i].m_eta;
509 double n = LookAtList[
i].m_value;
523 for(
unsigned int i=0;
i<LookAtList.size();
i++){
524 double phi = LookAtList[
i].m_phi;
525 double n = LookAtList[
i].m_value;
538 for(
unsigned int i=0;
i<LookAtList.size();
i++){
539 double n = LookAtList[
i].m_value;
545 if(LookAtList.size()<2)
return 0;
547 for(
unsigned int i=0;
i<LookAtList.size();
i++){
558 if ((
int)ColorBinMap.size() <= (onebin.
m_ix-r0) ){
559 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
562 if ((
int)ColorBinMap[onebin.
m_ix-r0].size() <= (onebin.
m_iy-r2) ){
563 throw dqm_core::BadConfig( ERS_HERE,
name,
"out of ColorBinMap range " );
566 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status==0)
568 std::vector<colorbinOnline> LookAtList;
569 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color!=
green){
570 LookAtList.push_back(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2]);
571 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=0;
573 if(LookAtList.size()>1){
574 onecluster.
m_size = LookAtList.size();
576 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color==
red){
585 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=1;
593 out<<
"BinsDiffFromStripMedianOnline: Calculates smoothed strip median and then find out bins which are aliens "<<std::endl;
595 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;
597 out<<
"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
598 out<<
"Optional Parameter: MinStatPerstrip: Minimum strip statistics needed to perform Algorithm"<<std::endl;
599 out<<
"Optional Parameter: ignoreval0: values to be ignored for being processed"<<std::endl;
600 out<<
"Optional Parameter: ignoreval1: values to be ignored for being processed"<<std::endl;
601 out<<
"Optional Parameter: PublishBins: Save bins which are different from average in Result (on:1,off:0,default is 1)"<<std::endl;
602 out<<
"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
603 out<<
"Optional Parameter: VisualMode: is to make the evaluation process similar to the shift work, so one will get resonable result efficiently."<<std::endl;
605 out<<
"Optional Parameter: PublishRedBins: Max number of red bins to save."<<std::endl;
606 out<<
"Optional Parameter: ClusterResult: to cluster close bad bins together."<<std::endl;
607 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;
608 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;
609 out<<
"Optional Parameter: OnlineMode: switch on when running online."<<std::endl;
610 out<<
"Optional Parameter: Nred_red: minimum number of red bins needed to label the histogram as red."<<std::endl;
611 out<<
"Optional Parameter: Nyellow_yellow: minimum number of yellow bins needed to label the histogram as yellow."<<std::endl;
612 out<<
"Optional Parameter: Nred_yellow: minimum number of red bins needed to label the histogram as yellow."<<std::endl;
613 out<<
"Optional Parameter: Nredyellow_yellow: minimum number of yellow+red bins needed to label the histogram as yellow."<<std::endl;