56{
57
60
61 if(
object.
IsA()->InheritsFrom(
"TH1" ) ) {
63 if (
hist->GetDimension() >= 2 ){
64 throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
65 }
66 } else {
67 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
68 }
69
70
71
72 try {
73 ref =
static_cast<const TH1*
>(
config.getReference() );
74 }
75 catch ( dqm_core::Exception & ex ) {
76 throw dqm_core::BadRefHist(ERS_HERE,name," Could not retreive reference");
77 }
78 if (
hist->GetDimension() !=
ref->GetDimension() ) {
79 throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
80 }
81
82
83 double minstat;
84 double thresh_on_difference=75;
85 double thresh_on_peak_content=15;
86
87 double pos1=3;
88 double pos2=6;
89 double pos3=-1;
90 double greenTh=1;
91 double redTh=2;
92 double ref_y_n=1;
93
94 try {
98
105 }
106 catch ( dqm_core::Exception & ex ) {
107 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
108 }
109
110
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();
116 }
117 ERS_DEBUG(1,
"Statistics: "<<
hist->GetEntries()<<
" entries ");
118
119
122 std::vector<double> derivate;
123 std::vector<double> peak_candidate;
124 std::vector<double> peak;
125 std::vector<double> valley;
126
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;
131
132
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));
136 };
137
139
140
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;
149
150 if(derivate[0]>=0) valley.push_back(0);
151 if(derivate[0]<0){
152 peak_candidate.push_back(0);
153 highest_peak=
hist->GetBinContent(1);
154 }
155 if(ref_y_n==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);
160 }
161 };
162
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);
170 };
171
172 if(ref_y_n==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);
179 };
180 };
181 };
182
183 valley.push_back(
hist->GetNbinsX());
184 valley_ref.push_back(
hist->GetNbinsX());
185
186
188
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;
195
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]);
200 };
201 };
202
204 if(ref_y_n==1){
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;
211
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]);
216 };
217 };
218 };
219
220
221
222 dqm_core::Result*
result =
new dqm_core::Result();
223
225
226
227
228 double diff1=9999;
229 double diff2=9999;
230 double diff3=9999;
231
232 if(ref_y_n==0){
234 for(i=0;
i<peak.size();
i++){
235 if(std::abs(peak[i]-pos1)<=diff1){
236
237 diff1=std::abs(peak[i]-pos1);
238 };
239 if(std::abs(peak[i]-pos2)<=diff2){
240
241 diff2=std::abs(peak[i]-pos2);
242 };
243 if(std::abs(peak[i]-pos3)<=diff3 && pos3>0){
244
245 diff3=std::abs(peak[i]-pos3);
246 };
247 };
248
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;
255
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];
259 };
260 };
261
262 if(ref_y_n==1){
265 std::vector<double>
diff;
266 std::vector<double> peak_correspondence;
267 for(i=0;
i<peak.size();
i++){
268 diff1=9999;
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]);
276 };
277 };
278 };
280 for(i=0;
i<peak.size();
i++){
283 };
284
285 result->tags_[
"a-00-Number_of_found_peaks"] = peak.size();
286 result->tags_[
"b-00-Number_of_found_peaks_ref"] = peak_ref.size();
287
288 for(
size_t p=0;
p<peak.size();
p++){
289 result->tags_[std::format (
"a-{:02d}Peak", p+1)] = peak[
p];
290 };
291 for(
size_t p=0;
p<peak_ref.size();
p++){
292 result->tags_[std::format (
"b-{:02d}Peak", p+1)] = peak_ref[
p];
293 };
294 };
295
297 result->status_ = dqm_core::Result::Green;
298 };
300 result->status_ = dqm_core::Result::Yellow;
301 };
303 result->status_ = dqm_core::Result::Red;
304 };
305
306
308}
const boost::regex ref(r_ef)
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
#define IsA
Declare the TObject style functions.