LDMX Software
Public Member Functions | Private Attributes | List of all members
framework::HistogramHelper Class Reference

Interface class between an EventProcessor and the HistogramPool. More...

#include <Histograms.h>

Public Member Functions

 HistogramHelper (const std::string &name)
 Constructor.
 
void setWeight (double w)
 Set the weight for filling the histograms.
 
void create (const std::string &name, const std::string &xLabel, const double &bins, const double &xmin, const double &xmax)
 Create a ROOT 1D histogram of type TH1F and pool it for later use.
 
void create (const std::string &name, const std::string &xLabel, const std::vector< double > &bins)
 Create a ROOT 1D histogram of type TH1F and pool it for later use.
 
void create (const std::string &name, const std::string &xLabel, const double &xbins, const double &xmin, const double &xmax, const std::string &yLabel, const double &ybins, const double &ymin, const double &ymax)
 Create a ROOT 2D histogram of type TH2F and pool it for later use.
 
void create (const std::string &name, const std::string &xLabel, const std::vector< double > &xbins, const std::string &yLabel, const std::vector< double > &ybins)
 Create a ROOT 2D histogram of type TH2F and pool it for later use.
 
void fill (const std::string &name, const double &val)
 Fill a 1D histogram.
 
void fill (const std::string &name, const double &valx, const double &valy)
 Fill a 2D histogram.
 
TH1 * get (const std::string &name)
 Get a pointer to a histogram by name.
 

Private Attributes

double theWeight_ {1.}
 The weight to fill histograms with.
 
std::string name_
 The name of the processor that this helper is assigned to.
 

Detailed Description

Interface class between an EventProcessor and the HistogramPool.

Definition at line 72 of file Histograms.h.

Constructor & Destructor Documentation

◆ HistogramHelper()

framework::HistogramHelper::HistogramHelper ( const std::string &  name)
inline

Constructor.

Sets the name

Definition at line 86 of file Histograms.h.

86: name_(name) {}
std::string name_
The name of the processor that this helper is assigned to.
Definition Histograms.h:78

Member Function Documentation

◆ create() [1/4]

void framework::HistogramHelper::create ( const std::string &  name,
const std::string &  xLabel,
const double &  bins,
const double &  xmin,
const double &  xmax 
)

Create a ROOT 1D histogram of type TH1F and pool it for later use.

Note
Does not check if another histogram of the same name is in use.
Parameters
nameName of the histogram. This will also be used as a title.
xLabelTitle of the x axis.
binsTotal number of histogram bins.
xminThe lower histogram limit.
xmaxThe upper histogram limit.

Definition at line 55 of file Histograms.cxx.

57 {
58 std::string fullName = name_ + "_" + name;
59
60 // Create a histogram of type T
61 auto hist = new TH1F(fullName.c_str(), fullName.c_str(), bins, xmin, xmax);
62
63 // Set the title
64 hist->SetTitle("");
65
66 // Set the x-axis label
67 hist->GetXaxis()->SetTitle(xLabel.c_str());
68 hist->GetXaxis()->CenterTitle();
69
70 // Insert it into the pool of histograms for later use
71 HistogramPool::getInstance().insert(fullName, hist);
72}
static HistogramPool & getInstance()
Access the single instance of HistogramPool by reference.
void insert(const std::string &name, TH1 *hist)
Insert a histogram into the pool.
Definition Histograms.h:54

References framework::HistogramPool::getInstance(), framework::HistogramPool::insert(), and name_.

Referenced by dqm::SimObjects::createCalorimeterHists(), framework::EventProcessor::createHistograms(), dqm::SimObjects::createTrackerHists(), dqm::SimObjects::onProcessStart(), dqm::Trigger::onProcessStart(), dqm::TrigScintClusterDQM::onProcessStart(), dqm::TrigScintDQM::onProcessStart(), dqm::TrigScintHitDQM::onProcessStart(), dqm::TrigScintTrackDQM::onProcessStart(), and dqm::HCalRawDigi::onProcessStart().

◆ create() [2/4]

void framework::HistogramHelper::create ( const std::string &  name,
const std::string &  xLabel,
const double &  xbins,
const double &  xmin,
const double &  xmax,
const std::string &  yLabel,
const double &  ybins,
const double &  ymin,
const double &  ymax 
)

Create a ROOT 2D histogram of type TH2F and pool it for later use.

Note
Does not check if another histogram of the same name is in use.
Parameters
nameName of the histogram. This will also be used as a title.
xLabelTitle of the x axis.
xbinsTotal number of histogram bins in x.
xminThe lower histogram limit in x.
xmaxThe upper histogram limit in x.
yLabelTitle of the x axis.
ybinsTotal number of histogram bins in y.
yminThe lower histogram limit in y.
ymaxThe upper histogram limit in y.

Definition at line 99 of file Histograms.cxx.

103 {
104 std::string fullName = name_ + "_" + name;
105
106 // Create a histogram of type T
107 auto hist = new TH2F(fullName.c_str(), fullName.c_str(), xbins, xmin, xmax,
108 ybins, ymin, ymax);
109
110 // Set the title
111 hist->SetTitle("");
112
113 // Set the x-axis label
114 hist->GetXaxis()->SetTitle(xLabel.c_str());
115 hist->GetXaxis()->CenterTitle();
116
117 // Set the x-axis label
118 hist->GetYaxis()->SetTitle(yLabel.c_str());
119 hist->GetYaxis()->CenterTitle();
120
121 // Insert it into the pool of histograms for later use
122 HistogramPool::getInstance().insert(fullName, hist);
123}

References framework::HistogramPool::getInstance(), framework::HistogramPool::insert(), and name_.

◆ create() [3/4]

void framework::HistogramHelper::create ( const std::string &  name,
const std::string &  xLabel,
const std::vector< double > &  bins 
)

Create a ROOT 1D histogram of type TH1F and pool it for later use.

Note
Does not check if another histogram of the same name is in use.
Parameters
nameName of the histogram. This will also be used as a title.
xLabelTitle of the x axis.
binsvector of bin edges

Definition at line 74 of file Histograms.cxx.

75 {
76 std::string fullName = name_ + "_" + name;
77
78 // copy bin edges into a C98 form acceptable by ROOT
79 int nbins = bins.size() - 1;
80 double* binEdges = new double[bins.size()];
81 for (unsigned int iBin = 0; iBin < bins.size(); iBin++)
82 binEdges[iBin] = bins.at(iBin);
83
84 auto hist = new TH1F(fullName.c_str(), fullName.c_str(), nbins, binEdges);
85
86 delete[] binEdges; // cleanup
87
88 // Set the title
89 hist->SetTitle("");
90
91 // Set the x-axis label
92 hist->GetXaxis()->SetTitle(xLabel.c_str());
93 hist->GetXaxis()->CenterTitle();
94
95 // Insert it into the pool of histograms for later use
96 HistogramPool::getInstance().insert(fullName, hist);
97}

References framework::HistogramPool::getInstance(), framework::HistogramPool::insert(), and name_.

◆ create() [4/4]

void framework::HistogramHelper::create ( const std::string &  name,
const std::string &  xLabel,
const std::vector< double > &  xbins,
const std::string &  yLabel,
const std::vector< double > &  ybins 
)

Create a ROOT 2D histogram of type TH2F and pool it for later use.

Note
Does not check if another histogram of the same name is in use.
Parameters
nameName of the histogram. This will also be used as a title.
xLabelTitle of the x axis.
xbinsBin edges on x axis
yLabelTitle of the y axis.
ybinsBin edges on y axis

Definition at line 125 of file Histograms.cxx.

128 {
129 std::string fullName = name_ + "_" + name;
130
131 // copy bin edges into a C98 form acceptable by ROOT
132 int xNBins = xbins.size() - 1;
133 double* xBinEdges = new double[xbins.size()];
134 for (unsigned int iBin = 0; iBin < xbins.size(); iBin++)
135 xBinEdges[iBin] = xbins.at(iBin);
136
137 int yNBins = ybins.size() - 1;
138 double* yBinEdges = new double[ybins.size()];
139 for (unsigned int iBin = 0; iBin < ybins.size(); iBin++)
140 yBinEdges[iBin] = ybins.at(iBin);
141
142 auto hist = new TH2F(fullName.c_str(), fullName.c_str(), xNBins, xBinEdges,
143 yNBins, yBinEdges);
144
145 delete[] xBinEdges; // cleanup
146 delete[] yBinEdges; // cleanup
147
148 // Set the title
149 hist->SetTitle("");
150
151 // Set the x-axis label
152 hist->GetXaxis()->SetTitle(xLabel.c_str());
153 hist->GetXaxis()->CenterTitle();
154
155 // Set the x-axis label
156 hist->GetYaxis()->SetTitle(yLabel.c_str());
157 hist->GetYaxis()->CenterTitle();
158
159 // Insert it into the pool of histograms for later use
160 HistogramPool::getInstance().insert(fullName, hist);
161}

References framework::HistogramPool::getInstance(), framework::HistogramPool::insert(), and name_.

◆ fill() [1/2]

void framework::HistogramHelper::fill ( const std::string &  name,
const double &  val 
)
inline

◆ fill() [2/2]

void framework::HistogramHelper::fill ( const std::string &  name,
const double &  valx,
const double &  valy 
)
inline

Fill a 2D histogram.

Uses the current setting of theWeight_.

Parameters
namename of the histogram to fill
valxx value to fill
valyy value to fill

Definition at line 182 of file Histograms.h.

182 {
183 auto hist = dynamic_cast<TH2F*>(this->get(name));
184 if (hist) {
185 hist->Fill(valx, valy, theWeight_);
186 }
187 }

References get(), and theWeight_.

◆ get()

TH1 * framework::HistogramHelper::get ( const std::string &  name)
inline

Get a pointer to a histogram by name.

Parameters
namename of the histogram to get

Definition at line 194 of file Histograms.h.

194 {
195 return HistogramPool::getInstance().get(name_ + "_" + name);
196 }
TH1 * get(const std::string &name)
Get a histogram using its name.

References framework::HistogramPool::get(), framework::HistogramPool::getInstance(), and name_.

Referenced by fill(), fill(), dqm::SimObjects::onProcessStart(), dqm::PhotoNuclearDQM::onProcessStart(), dqm::SampleValidation::onProcessStart(), and dqm::DarkBremInteraction::setHistLabels().

◆ setWeight()

void framework::HistogramHelper::setWeight ( double  w)
inline

Set the weight for filling the histograms.

Definition at line 91 of file Histograms.h.

91{ theWeight_ = w; }

References theWeight_.

Referenced by dqm::DarkBremInteraction::produce().

Member Data Documentation

◆ name_

std::string framework::HistogramHelper::name_
private

The name of the processor that this helper is assigned to.

Definition at line 78 of file Histograms.h.

Referenced by create(), create(), create(), create(), and get().

◆ theWeight_

double framework::HistogramHelper::theWeight_ {1.}
private

The weight to fill histograms with.

Definition at line 75 of file Histograms.h.

75{1.};

Referenced by fill(), fill(), and setWeight().


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