21 #include "dqm_core/exceptions.h"
22 #include "dqm_core/AlgorithmConfig.h"
23 #include "dqm_core/AlgorithmManager.h"
24 #include "dqm_core/Result.h"
40 : m_name(
"MDTcluster")
64 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
66 if (
hist->GetDimension() >= 2 ){
67 throw dqm_core::BadConfig( ERS_HERE,
name,
"dimension >= 2 " );
70 throw dqm_core::BadConfig( ERS_HERE,
name,
"does not inherit from TH1" );
84 catch ( dqm_core::Exception & ex ) {
85 throw dqm_core::BadConfig( ERS_HERE,
name, ex.what(), ex );
88 double cluster_size=greenTh;
93 ref =
static_cast<TH1*
>(
config.getReference() );
95 catch ( dqm_core::Exception & ex ) {
96 throw dqm_core::BadRefHist(ERS_HERE,
name,
" Could not retrieve reference");
98 if (
hist->GetDimension() !=
ref->GetDimension() ) {
99 throw dqm_core::BadRefHist( ERS_HERE,
name,
"Reference VS histo: Different dimension!" );
101 if (
hist->GetNbinsX() !=
ref->GetNbinsX() ) {
102 throw dqm_core::BadRefHist( ERS_HERE,
name,
"Reference VS histo: Different bin number in X axis!" );
106 if (
hist->GetEntries() < minstat ) {
107 ERS_INFO(
"Histogram does not satisfy MinStat requirement " <<
hist->GetName());
109 result->tags_[
"InsufficientEntries"] =
hist->GetEntries();
112 ERS_DEBUG(1,
"Statistics: "<<
hist->GetEntries()<<
" entries ");
119 N=
hist->GetEntries();
120 N_ref=
ref->GetEntries();
123 ERS_INFO(
"Histogram has no entries" <<
hist->GetName());
125 result->tags_[
"InsufficientEntries"] =
hist->GetEntries();
130 ERS_INFO(
"Reference histogram has no entries" <<
hist->GetName());
132 result->tags_[
"InsufficientRefEntries"] =
ref->GetEntries();
145 std::vector<double>
diff;
147 for(j=1;j<=
hist->GetNbinsX();j++){
148 diff.push_back(
hist->GetBinContent(j)-
ref->GetBinContent(j));
159 bool cluster_open=
false;
160 std::pair<int,int> bin_start_end;
161 std::pair<int , std::pair<int,int> > cluster_size_binStart_binEnd;
162 std::vector< std::pair< int , std::pair< int, int> > >
clusters;
166 if(std::abs(
diff[
i])>n_sigma*std::sqrt(
hist->GetBinContent(
i+1)+
ref->GetBinContent(
i+1)*
norm)){
172 if(
size>=cluster_size){
173 bin_start_end.second=
i;
174 cluster_size_binStart_binEnd.first=
size;
175 cluster_size_binStart_binEnd.second=bin_start_end;
176 clusters.push_back(cluster_size_binStart_binEnd);
181 ERS_INFO(
"Cluster searching fail");
191 bin_start_end.first=
i+1;
196 if(std::abs(
diff[
i])<=n_sigma*std::sqrt(
hist->GetBinContent(
i+1)+
ref->GetBinContent(
i+1)*
norm)){
198 if(
size>=cluster_size){
199 bin_start_end.second=
i;
200 cluster_size_binStart_binEnd.first=
size;
201 cluster_size_binStart_binEnd.second=bin_start_end;
202 clusters.push_back(cluster_size_binStart_binEnd);
207 if(
i==
diff.size()-1){
209 if(
size>=cluster_size){
210 bin_start_end.second=
i+1;
211 cluster_size_binStart_binEnd.first=
size;
212 cluster_size_binStart_binEnd.second=bin_start_end;
213 clusters.push_back(cluster_size_binStart_binEnd);
226 std::string Cluster=
"Cluster_";
228 std::string
Size=
"_info_1_size";
229 std::string start_at_bin=
"_info_2_start_at_bin";
230 std::string finish_at_bin=
"_info_3_finish_at_bin";
231 std::string message1;
232 std::string message2;
233 std::string message3;
237 sprintf(
num,
"0%u",(
i+1));
241 sprintf(
num,
"%u",(
i+1));
244 message1 = Cluster + (std::string)
num +
Size;
245 message2 = Cluster + (std::string)
num + start_at_bin;
246 message3 = Cluster + (std::string)
num + finish_at_bin;
264 ERS_DEBUG(1,
"Green");
266 result->status_ = dqm_core::Result::Yellow;
267 ERS_DEBUG(1,
"Yellow");
268 }
else if (
flag>=2) {
283 message +=
"Description: look for clusters of adiacent bins where each bin differ from reference more then n sigma\n";
284 message +=
"Mandatory Green/Red Threshold: ClusterSize: the green threshold is the minimum cluster size, each cluster\n";
285 message +=
" smaller than this size will not recorded as cluster by this algorithm\n";
286 message +=
" red threshold is the limit size of a cluster, if there is just one cluster\n";
287 message +=
" bigger then this limit the flag will be red;\n";
288 message +=
" otherwise the flag will be red if it find more at last 2 clusters\n";
289 message +=
" N_sigma : maximum distance in standard deviation of a bin of the histo from the reference one\n";
290 message +=
"Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";