10 #include <dqm_core/AlgorithmConfig.h>
13 #include <dqm_core/AlgorithmManager.h>
46 const TObject&
object,
47 const dqm_core::AlgorithmConfig&
config )
51 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
54 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension > 2 " );
57 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
69 if (
histogram->GetEntries() < minstat ) {
81 catch( dqm_core::Exception & ex ) {
82 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
86 std::vector<double> stripsMedian;
87 std::vector<double> stripsAvg;
88 std::vector<double> stripsVariance;
91 std::vector<double> onestrip;
94 if (
histogram->GetBinContent(
i,j) == ignoreval)
continue;
95 float binvalue =
histogram->GetBinContent(
i,j);
96 onestrip.push_back(binvalue);
98 if(binvalue > maxInMap) {
102 stripsAvg.push_back(stripSum/onestrip.size());
103 FindStripMedian(onestrip,stripsMedian);
108 for (
int j =
range[2]; j <=
range[3]; ++j ) {
109 if (
histogram->GetBinContent(
i,j) == ignoreval)
continue;
110 double binvalue =
histogram->GetBinContent(
i,j);
117 stripsVariance.push_back(variance);
120 std::vector<bin> redbins;
121 std::vector<bin> yellowbins;
122 std::vector<bin> Allbins;
126 if (binvalue== ignoreval)
continue;
127 double strip_median = stripsMedian[
k-
range[0]];
128 if(stripsMedian[
k-
range[0]]==0 && stripsVariance[
k-
range[0]]==0)
continue;
129 else if(stripsMedian[
k-
range[0]]==0 && stripsVariance[
k-
range[0]]!=0 && stripsAvg[
k-
range[0]]!=0) strip_median = stripsAvg[
k-
range[0]];
130 else if(stripsMedian[
k-
range[0]]==0 && stripsVariance[
k-
range[0]]!=0 && stripsAvg[
k-
range[0]]==0)
continue;
131 double outstandingRatio=0;
132 if(std::abs(strip_median) > 0.00001 ) outstandingRatio= (binvalue-strip_median)/std::sqrt(std::abs(strip_median));
134 double eta =
histogram->GetXaxis()->GetBinCenter(
k);
135 double phi =
histogram->GetYaxis()->GetBinCenter(
l);
136 bin onebin = {eta,phi,
k,
l,binvalue,outstandingRatio};
137 Allbins.push_back(onebin);
138 if(std::abs(outstandingRatio) > rthreshold ) {
139 if( VisualMode && (binvalue / maxInMap < suppressRedFactor) )
141 redbins.push_back(onebin);
143 else if(std::abs(outstandingRatio) > gthreshold ){
144 if( VisualMode && (binvalue / maxInMap < suppressFactor) )
146 yellowbins.push_back(onebin);
151 int count_yellow_c = 0;
152 std::vector<std::vector<colorbin> > ColorBinMap;
156 std::vector<colorbin> oneColorStrip;
158 colorbin oneColorBin = {
static_cast<double>(
k),
static_cast<double>(
l), -1, -1, -1,
green, 1};
159 oneColorStrip.push_back(oneColorBin);
161 ColorBinMap.push_back(oneColorStrip);
165 for(
unsigned int i=0;
i<redbins.size();
i++){
166 int k=redbins[
i].m_ix;
167 int l=redbins[
i].m_iy;
169 ColorBinMap[
k-
range[0]][
l-
range[2]].m_eta = redbins[
i].m_eta;
171 ColorBinMap[
k-
range[0]][
l-
range[2]].m_phi = redbins[
i].m_phi;
172 ColorBinMap[
k-
range[0]][
l-
range[2]].m_value = redbins[
i].m_value;
178 for(
unsigned int i=0;
i<yellowbins.size();
i++){
179 int k=yellowbins[
i].m_ix;
180 int l=yellowbins[
i].m_iy;
181 ColorBinMap[
k-
range[0]][
l-
range[2]].m_eta = yellowbins[
i].m_eta;
182 ColorBinMap[
k-
range[0]][
l-
range[2]].m_phi = yellowbins[
i].m_phi;
183 ColorBinMap[
k-
range[0]][
l-
range[2]].m_value = yellowbins[
i].m_value;
189 std::vector<colorcluster > clusterArray;
190 for(
unsigned int i=0;
i<redbins.size();
i++){
191 const int k=redbins[
i].m_ix;
192 const int l=redbins[
i].m_iy;
195 if(onecluster.
m_size > 1) clusterArray.push_back(onecluster);
198 for(
unsigned int i=0;
i<yellowbins.size();
i++){
199 const int k=yellowbins[
i].m_ix;
200 const int l=yellowbins[
i].m_iy;
203 if(onecluster.
m_size > 1) clusterArray.push_back(onecluster);
208 for(
unsigned int i=0;
i<clusterArray.size();
i++){
210 if(clusterArray[
i].m_color==
red){
211 sprintf(
tmp,
"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);
214 else if(clusterArray[
i].m_color==
yellow){
215 sprintf(
tmp,
"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);
221 result->tags_[
"NRedClusters"] = count_red_c;
222 result->tags_[
"NYellowClusters"] = count_yellow_c;
227 std::sort(redbins.begin(),redbins.end(),
mySortfunc);
228 std::sort(yellowbins.begin(),yellowbins.end(),
mySortfunc);
232 for(
unsigned int i=0;
i<redbins.size();
i++){
233 if(ClusterResult && ColorBinMap[redbins[
i].m_ix-
range[0]][redbins[
i].m_iy-
range[2]].m_status==0 )
continue;
236 sprintf(
tmp,
"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);
242 if(count_red > NpublishRed)
break;
248 for(
unsigned int i=0;
i<yellowbins.size();
i++){
249 if(ClusterResult &&ColorBinMap[yellowbins[
i].m_ix-
range[0]][yellowbins[
i].m_iy-
range[2]].m_status==0)
continue;
250 if(publish && (count_red+count_yellow) < Nmaxpublish ){
252 sprintf(
tmp,
"Y%i-(eta,phi)[OSRatio]=(%0.3f,%0.3f)[%.2e]",count_yellow,yellowbins[
i].m_eta,yellowbins[
i].m_phi,yellowbins[
i].m_outstandingRatio);
258 result->tags_[
"NRedBins"] = count_red;
259 result->tags_[
"NYellowBins"] = count_yellow;
261 if(count_red+count_yellow==0 && Allbins.size()>=5 ){
262 for(
int i=0;
i<5;
i++){
264 sprintf(tmptmp,
"LeadingBin%i-(eta,phi)=(%0.3f,%0.3f)",
i,Allbins[
i].m_eta,Allbins[
i].m_phi);
265 std::string tagtag = tmptmp;
266 result->tags_[tagtag] = Allbins[
i].m_value;
273 else if (count_yellow>0||count_yellow_c>0)
result->status_ = dqm_core::Result::Yellow;
283 std::sort(onestrip_tmp.begin(),onestrip_tmp.end());
284 int index1=onestrip_tmp.size()/4;
286 int index2=onestrip_tmp.size()/2;
287 int index3=3*onestrip_tmp.size()/4;
289 stripsMedian.push_back(
median);
291 void AddToList(
const int r0,
const int r2,
int i,
int j,std::vector<std::vector<colorbin> > & ColorBinMap, std::vector<colorbin>& LookAtList){
293 if(
i-r0<0 || i-r0>=(
int)ColorBinMap.size()
294 || j-r2<0 ||j-r2>=(
int)ColorBinMap[0].size() )
return;
296 std::vector<colorbin>
tmp;
298 if(
i-1-r0>=0 && j-1-r2>=0 && ColorBinMap[
i-1-r0][j-1-r2].m_status==1){
299 tmp.push_back(ColorBinMap[
i-1-r0][j-1-r2]);
300 ColorBinMap[
i-1-r0][j-1-r2].m_status=0;
302 if(j-1-r2 >=0 && ColorBinMap[
i-r0][j-1-r2].m_status==1){
303 tmp.push_back(ColorBinMap[
i-r0][j-1-r2]);
304 ColorBinMap[
i-r0][j-1-r2].m_status=0;
306 if(
i+1-r0<(
int)ColorBinMap.size() && j-1-r2 >=0 && ColorBinMap[
i+1-r0][j-1-r2].m_status==1){
307 tmp.push_back(ColorBinMap[
i+1-r0][j-1-r2]);
308 ColorBinMap[
i+1-r0][j-1-r2].m_status=0;
310 if(
i-1-r0>=0 && ColorBinMap[
i-1-r0][j-r2].m_status==1){
311 tmp.push_back(ColorBinMap[
i-1-r0][j-r2]);
312 ColorBinMap[
i-1-r0][j-r2].m_status=0;
315 if(
i+1-r0<(
int)ColorBinMap.size() && ColorBinMap[
i+1-r0][j-r2].m_status==1){
316 tmp.push_back(ColorBinMap[
i+1-r0][j-r2]);
317 ColorBinMap[
i+1-r0][j-r2].m_status=0;
319 if(
i-1-r0>=0 && j+1-r2 < (
int)ColorBinMap[0].
size()
320 && ColorBinMap[
i-1-r0][j+1-r2].m_status==1){
321 tmp.push_back(ColorBinMap[
i-1-r0][j+1-r2]);
322 ColorBinMap[
i-1-r0][j+1-r2].m_status=0;
324 if(j+1-r2<(
int)ColorBinMap[0].
size()&& ColorBinMap[
i-r0][j+1-r2].m_status==1){
325 tmp.push_back(ColorBinMap[
i-r0][j+1-r2]);
326 ColorBinMap[
i-r0][j+1-r2].m_status=0;
328 if(
i+1-r0<(
int)ColorBinMap.size() && j+1-r2<(
int)ColorBinMap[0].size()&&ColorBinMap[
i+1-r0][j+1-r2].m_status==1){
329 tmp.push_back(ColorBinMap[
i+1-r0][j+1-r2]);
330 ColorBinMap[
i+1-r0][j+1-r2].m_status=0;
333 for(
unsigned int k=0;
k<
tmp.size();
k++){
335 LookAtList.push_back(
tmp[
k]);
343 double CalEta(std::vector<colorbin>& LookAtList){
346 for(
unsigned int i=0;
i<LookAtList.size();
i++){
347 double eta = LookAtList[
i].m_eta;
348 double n = LookAtList[
i].m_value;
352 if(sumN!=0)
return sumEta/sumN;
355 double CalPhi(std::vector<colorbin>& LookAtList){
358 for(
unsigned int i=0;
i<LookAtList.size();
i++){
359 double phi = LookAtList[
i].m_phi;
360 double n = LookAtList[
i].m_value;
364 if(sumN!=0)
return sumPhi/sumN;
367 double CalVal(std::vector<colorbin>& LookAtList){
369 for(
unsigned int i=0;
i<LookAtList.size();
i++){
370 double n = LookAtList[
i].m_value;
375 double CalR(std::vector<colorbin>& LookAtList,
double eta,
double phi){
376 if(LookAtList.size()<2)
return 0;
378 for(
unsigned int i=0;
i<LookAtList.size();
i++){
388 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status==0)
390 std::vector<colorbin> LookAtList;
391 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color!=
green){
392 LookAtList.push_back(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2]);
393 ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=0;
395 if(LookAtList.size()>1){
396 onecluster.
m_size = LookAtList.size();
398 if(ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_color==
red)
405 else ColorBinMap[onebin.
m_ix-r0][onebin.
m_iy-r2].m_status=1;
414 out<<
"BinsDiffFromStripMedian: Calculates smoothed strip median and then find out bins which are aliens "<<std::endl;
416 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;
418 out<<
"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
419 out<<
"Optional Parameter: ignoreval: valued to be ignored for being processed"<<std::endl;
420 out<<
"Optional Parameter: PublishBins: Save bins which are different from average in Result (on:1,off:0,default is 1)"<<std::endl;
421 out<<
"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
422 out<<
"Optional Parameter: VisualMode: is to make the evaluation process similar to the shift work, so one will get resonable result efficiently."<<std::endl;