ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::AveragePrint Class Reference

#include <AveragePrint.h>

Inheritance diagram for dqm_algorithms::AveragePrint:
Collaboration diagram for dqm_algorithms::AveragePrint:

Public Member Functions

 AveragePrint ()
virtual ~AveragePrint ()
virtual dqm_core::Algorithm * clone ()
virtual dqm_core::Result * execute (const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
virtual void printDescription (std::ostream &out)

Protected Attributes

std::string m_name

Detailed Description

Definition at line 16 of file AveragePrint.h.

Constructor & Destructor Documentation

◆ AveragePrint()

dqm_algorithms::AveragePrint::AveragePrint ( )

Definition at line 42 of file AveragePrint.cxx.

44 : m_name("AveragePrint")
45 {
46 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
47 }

◆ ~AveragePrint()

dqm_algorithms::AveragePrint::~AveragePrint ( )
virtual

Definition at line 50 of file AveragePrint.cxx.

52 {
53 }

Member Function Documentation

◆ clone()

dqm_core::Algorithm * dqm_algorithms::AveragePrint::clone ( )
virtual

Definition at line 57 of file AveragePrint.cxx.

59 {
60 return new AveragePrint(*this);
61 }

◆ execute()

dqm_core::Result * dqm_algorithms::AveragePrint::execute ( const std::string & name,
const TObject & data,
const dqm_core::AlgorithmConfig & config )
virtual

Definition at line 65 of file AveragePrint.cxx.

67 {
68 //No status flags are set
69 dqm_core::Result* result = new dqm_core::Result();
70 result->status_ = dqm_core::Result::Undefined;
71
72 if (!data.IsA()->InheritsFrom("TH1")) {
73 throw dqm_core::BadConfig(ERS_HERE, name, "does not inherit from TH1");
74 }
75 const TH1* h = static_cast<const TH1*>(&data); // h cannot be null
76 if (h->GetDimension() > 2) {
77 throw dqm_core::BadConfig(ERS_HERE, name, "dimension > 2 ");
78 }
79
80 //**********
81 // Profile case
82 //**********
83 if ( data.IsA()->InheritsFrom("TProfile") ) {
84 const TProfile* hp = static_cast<const TProfile*>(&data);
85 //ASSUME: dimension = 1
86 double Average_value = 0.;
87 double Total_entries = 0;
88 int NbinsX = h->GetNbinsX();
89 for(int binX = 0; binX < NbinsX; binX++) {
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;
94 }
95 if (Total_entries > 0) {
96 Average_value = Average_value / Total_entries;
97 }
98 std::string Average_name = Form("%s_Average", name.c_str());
99 result->tags_[Average_name.c_str()] = Average_value;
100 }
101
102 //**********
103 // 1D Histogram case
104 //**********
105 if((! data.IsA()->InheritsFrom("TProfile")) && h->GetDimension() == 1) {
106 double Average_value = 0.;
107 int NbinsX = h->GetNbinsX();
108 for(int binX = 0; binX < NbinsX; binX++) {
109 Average_value += h->GetBinContent(binX + 1);
110 }
111 std::string Average_name = Form("%s_Average", name.c_str());
112 result->tags_[Average_name.c_str()] = Average_value;
113 }
114
115 //**********
116 // 2D Histogram case
117 //**********
118 if((! data.IsA()->InheritsFrom("TProfile")) && h->GetDimension() == 2) {
119 double Average_value = 0.;
120 int NbinsX = h->GetNbinsX();
121 int NbinsY = h->GetNbinsY();
122 for(int binX = 0; binX < NbinsX; binX++) {
123 for(int binY = 0; binY < NbinsY; binY++) {
124 Average_value += h->GetBinContent(binY + 1, binY + 1);
125 }
126 }
127 std::string Average_name = Form("%s_Average", name.c_str());
128 result->tags_[Average_name.c_str()] = Average_value;
129 }
130
131 return result;
132 }
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
@ binX
Definition BinningType.h:47
@ binY
Definition BinningType.h:48

◆ printDescription()

void dqm_algorithms::AveragePrint::printDescription ( std::ostream & out)
virtual

Definition at line 28 of file AveragePrint.cxx.

30 {
31 std::string message;
32 message += "\n";
33 message += "Algorithm: \"" + m_name + "\"\n";
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";
37 message += "\n";
38
39 out << message;
40 }

Member Data Documentation

◆ m_name

std::string dqm_algorithms::AveragePrint::m_name
protected

Definition at line 31 of file AveragePrint.h.


The documentation for this class was generated from the following files: