13 #include "dqm_core/exceptions.h"
14 #include "dqm_core/AlgorithmManager.h"
15 #include "dqm_core/AlgorithmConfig.h"
16 #include "dqm_core/Result.h"
34 message +=
"Description: Prints out the average of the histogram or profile bins\n";
35 message +=
" In the case of a TProfile each bin is weighted by its fraction of the entries\n";
36 message +=
" Overflow (and Underflow) bins are not included\n";
44 : m_name(
"AveragePrint")
66 execute(
const std::string&
name,
const TObject&
data,
const dqm_core::AlgorithmConfig& )
72 if (!
data.IsA()->InheritsFrom(
"TH1")) {
73 throw dqm_core::BadConfig(ERS_HERE,
name,
"does not inherit from TH1");
75 const TH1*
h =
static_cast<const TH1*
>(&
data);
76 if (
h->GetDimension() > 2) {
77 throw dqm_core::BadConfig(ERS_HERE,
name,
"dimension > 2 ");
83 if (
data.IsA()->InheritsFrom(
"TProfile") ) {
86 double Average_value = 0.;
87 double Total_entries = 0;
88 int NbinsX =
h->GetNbinsX();
90 double Bin_entries = hp->GetBinEntries(
binX + 1);
91 double Bin_value = Bin_entries * (hp->GetBinContent(
binX + 1));
92 Total_entries += Bin_entries;
93 Average_value += Bin_value;
95 Average_value = Average_value / Total_entries;
96 std::string Average_name = Form(
"%s_Average",
name.c_str());
97 result->tags_[Average_name.c_str()] = Average_value;
103 if((!
data.IsA()->InheritsFrom(
"TProfile")) &&
h->GetDimension() == 1) {
104 double Average_value = 0.;
105 int NbinsX =
h->GetNbinsX();
107 Average_value +=
h->GetBinContent(
binX + 1);
109 std::string Average_name = Form(
"%s_Average",
name.c_str());
110 result->tags_[Average_name.c_str()] = Average_value;
116 if((!
data.IsA()->InheritsFrom(
"TProfile")) &&
h->GetDimension() == 2) {
117 double Average_value = 0.;
118 int NbinsX =
h->GetNbinsX();
119 int NbinsY =
h->GetNbinsY();
122 Average_value +=
h->GetBinContent(
binY + 1,
binY + 1);
125 std::string Average_name = Form(
"%s_Average",
name.c_str());
126 result->tags_[Average_name.c_str()] = Average_value;