61 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
62 hist =
static_cast<const TH1*
>(&
object);
63 if (hist->GetDimension() >= 2 ){
64 throw dqm_core::BadConfig( ERS_HERE, name,
"dimension >= 2 " );
67 throw dqm_core::BadConfig( ERS_HERE, name,
"does not inherit from TH1" );
73 ref =
static_cast<const TH1*
>(
config.getReference() );
75 catch ( dqm_core::Exception & ex ) {
76 throw dqm_core::BadRefHist(ERS_HERE,name,
" Could not retreive reference");
78 if (hist->GetDimension() !=
ref->GetDimension() ) {
79 throw dqm_core::BadRefHist( ERS_HERE, name,
"Reference VS histo: Different dimension!" );
84 double thresh_on_difference=75;
85 double thresh_on_peak_content=15;
106 catch ( dqm_core::Exception & ex ) {
107 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
111 if (hist->GetEntries() < minstat ) {
112 ERS_INFO(
"Histogram does not satisfy MinStat requirement " <<hist->GetName());
113 dqm_core::Result *
result =
new dqm_core::Result(dqm_core::Result::Undefined);
114 result->tags_[
"InsufficientEntries"] = hist->GetEntries();
117 ERS_DEBUG(1,
"Statistics: "<< hist->GetEntries()<<
" entries ");
122 std::vector<double> derivate;
123 std::vector<double> peak_candidate;
124 std::vector<double> peak;
125 std::vector<double> valley;
127 std::vector<double> derivate_ref;
128 std::vector<double> peak_candidate_ref;
129 std::vector<double> peak_ref;
130 std::vector<double> valley_ref;
133 for(i=1;i<=(
unsigned int)hist->GetNbinsX();i++){
134 if((i+1)<=(
unsigned int)hist->GetNbinsX()) derivate.push_back(hist->GetBinContent(i+1)-hist->GetBinContent(i));
135 if((i+1)<=(
unsigned int)
ref->GetNbinsX() && ref_y_n==1) derivate_ref.push_back(
ref->GetBinContent(i+1)-
ref->GetBinContent(i));
141 Double_t highest_peak=0;
142 Double_t peak_content;
143 Double_t first_valley_content;
144 Double_t second_valley_content;
145 Double_t highest_peak_ref=0;
146 Double_t peak_content_ref;
147 Double_t first_valley_content_ref;
148 Double_t second_valley_content_ref;
150 if(derivate[0]>=0) valley.push_back(0);
152 peak_candidate.push_back(0);
153 highest_peak=hist->GetBinContent(1);
156 if(derivate_ref[0]>=0) valley_ref.push_back(0);
157 if(derivate_ref[0]<0){
158 peak_candidate_ref.push_back(0);
159 highest_peak_ref=
ref->GetBinContent(1);
163 for(i=0;i<(derivate.size()-1);i++){
164 if(derivate[i]>0 && derivate[i+1]<0){
165 peak_candidate.push_back(i+1);
166 peak_content=hist->GetBinContent(i+2);
167 if(peak_content>highest_peak) highest_peak=peak_content;
168 }
else if(derivate[i]<0 && derivate[i+1]>0){
169 valley.push_back(i+1);
173 if(derivate_ref[i]>0 && derivate_ref[i+1]<0){
174 peak_candidate_ref.push_back(i+1);
175 peak_content_ref=
ref->GetBinContent(i+2);
176 if(peak_content_ref>highest_peak_ref) highest_peak_ref=peak_content_ref;
177 }
else if(derivate_ref[i]<0 && derivate_ref[i+1]>0){
178 valley_ref.push_back(i+1);
183 valley.push_back(hist->GetNbinsX());
184 valley_ref.push_back(hist->GetNbinsX());
189 for(i=0;i<peak_candidate.size();i++){
190 peak_content=hist->GetBinContent((Int_t)peak_candidate[i]+1);
191 first_valley_content=hist->GetBinContent((Int_t)valley[i]+1);
192 second_valley_content=hist->GetBinContent((Int_t)valley[i+1]+1);
193 if(first_valley_content==0) first_valley_content=1;
194 if(second_valley_content==0) second_valley_content=1;
196 if((first_valley_content<=second_valley_content) && (peak_content>(thresh_on_peak_content*highest_peak/100)) && (first_valley_content<(thresh_on_difference*peak_content/100))){
197 peak.push_back(peak_candidate[i]);
198 }
else if((first_valley_content>second_valley_content) && (peak_content>(thresh_on_peak_content*highest_peak/100)) && (second_valley_content<(thresh_on_difference*peak_content/100))){
199 peak.push_back(peak_candidate[i]);
205 for(i=0;i<peak_candidate_ref.size();i++){
206 peak_content_ref=
ref->GetBinContent((Int_t)peak_candidate_ref[i]+1);
207 first_valley_content_ref=
ref->GetBinContent((Int_t)valley_ref[i]+1);
208 second_valley_content_ref=
ref->GetBinContent((Int_t)valley_ref[i+1]+1);
209 if(first_valley_content_ref==0) first_valley_content_ref=1;
210 if(second_valley_content_ref==0) second_valley_content_ref=1;
212 if((first_valley_content_ref<=second_valley_content_ref) && (peak_content_ref>(thresh_on_peak_content*highest_peak_ref/100)) && (first_valley_content_ref<(thresh_on_difference*peak_content_ref/100))){
213 peak_ref.push_back(peak_candidate_ref[i]);
214 }
else if((first_valley_content_ref>second_valley_content_ref) && (peak_content_ref>(thresh_on_peak_content*highest_peak_ref/100)) && (second_valley_content_ref<(thresh_on_difference*peak_content_ref/100))){
215 peak_ref.push_back(peak_candidate_ref[i]);
222 dqm_core::Result*
result =
new dqm_core::Result();
234 for(i=0;i<peak.size();i++){
235 if(std::abs(peak[i]-pos1)<=diff1){
237 diff1=std::abs(peak[i]-pos1);
239 if(std::abs(peak[i]-pos2)<=diff2){
241 diff2=std::abs(peak[i]-pos2);
243 if(std::abs(peak[i]-pos3)<=diff3 && pos3>0){
245 diff3=std::abs(peak[i]-pos3);
249 if(diff1>greenTh)
count++;
250 if(diff2>greenTh)
count++;
251 if(diff3>greenTh && pos3>0)
count++;
252 if(diff1>redTh)
count+=2;
253 if(diff2>redTh)
count+=2;
254 if(diff3>redTh && pos3>0)
count+=2;
256 result->tags_[
"00-Number_of_found_peaks"] = peak.size();
257 for(
size_t p=0; p<peak.size(); p++){
258 result->tags_[std::format (
"{:02d}-Peak", p+1)] = peak[p];
265 std::vector<double>
diff;
266 std::vector<double> peak_correspondence;
267 for(i=0;i<peak.size();i++){
269 peak_correspondence.push_back(99999);
270 diff.push_back(99999);
271 for(k=0;k<peak_ref.size();k++){
272 if(std::abs(peak[i]-peak_ref[k])<=diff1){
273 peak_correspondence[i]=k;
274 diff[i]=std::abs(peak[i]-peak_ref[k]);
275 diff1=std::abs(peak[i]-peak_ref[k]);
280 for(i=0;i<peak.size();i++){
285 result->tags_[
"a-00-Number_of_found_peaks"] = peak.size();
286 result->tags_[
"b-00-Number_of_found_peaks_ref"] = peak_ref.size();
288 for(
size_t p=0; p<peak.size(); p++){
289 result->tags_[std::format (
"a-{:02d}Peak", p+1)] = peak[p];
291 for(
size_t p=0; p<peak_ref.size(); p++){
292 result->tags_[std::format (
"b-{:02d}Peak", p+1)] = peak_ref[p];
297 result->status_ = dqm_core::Result::Green;
300 result->status_ = dqm_core::Result::Yellow;
303 result->status_ = dqm_core::Result::Red;