LDMX Software
framework::HistogramPool Class Reference

Class for holding an EventProcessor's histogram pointers and making sure that they all end up in the same directory in the output histogram file. More...

#include <HistogramPool.h>

Public Member Functions

 HistogramPool (std::function< TDirectory *()> get_directory)
 define how we can get the directory we need
 
void setWeight (double w)
 Set the weight for filling the histograms.
 
TH1 * get (const std::string &name)
 get a histogram from this pool by name
 
void create (const config::Parameters &p)
 Create a histogram from the input configuration parameters.
 
void create (const std::string &name, const std::string &x_label, const int &bins, const double &xmin, const double &xmax, bool weighted=false)
 Create a ROOT 1D histogram with uniform binning.
 
void create (const std::string &name, const std::string &x_label, const std::vector< double > &bins, bool weighted=false)
 Create a ROOT 1D histogram with variable binning.
 
void create (const std::string &name, const std::string &x_label, const std::vector< std::string > &categories, bool weighted=false)
 Create a ROOT 1D histogram with categorical binning.
 
void create (const std::string &name, const std::string &x_label, const int &xbins, const double &xmin, const double &xmax, const std::string &y_label, const int &ybins, const double &ymin, const double &ymax, bool weighted=false)
 Create a ROOT 2D histogram with both axes having uniform binning.
 
void create (const std::string &name, const std::string &x_label, const std::vector< double > &xbins, const std::string &y_label, const int &ybins, const double &ymin, const double &ymax, bool weighted=false)
 Create a ROOT 2D histogram with variable bins on the x axis and uniform bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const std::vector< std::string > &xcategories, const std::string &y_label, const int &ybins, const double &ymin, const double &ymax, bool weighted=false)
 Create a ROOT 2D histogram with category bins on the x axis and uniform bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const int &xbins, const double &xmin, const double &xmax, const std::string &y_label, const std::vector< double > &ybins, bool weighted=false)
 Create a ROOT 2D histogram with uniform bins on the x axis and variable bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const std::vector< double > &xbins, const std::string &y_label, const std::vector< double > &ybins, bool weighted=false)
 Create a ROOT 2D histogram with variable bins on the x axis and variable bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const std::vector< std::string > &xcategories, const std::string &y_label, const std::vector< double > &ybins, bool weighted=false)
 Create a ROOT 2D histogram with category bins on the x axis and variable bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const int &xbins, const double &xmin, const double &xmax, const std::string &y_label, const std::vector< std::string > &ycategories, bool weighted=false)
 Create a ROOT 2D histogram with uniform bins on the x axis and category bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const std::vector< double > &xbins, const std::string &y_label, const std::vector< std::string > &ycategories, bool weighted=false)
 Create a ROOT 2D histogram with variable bins on the x axis and category bins on the y axis.
 
void create (const std::string &name, const std::string &x_label, const std::vector< std::string > &xcategories, const std::string &y_label, const std::vector< std::string > &ycategories, bool weighted=false)
 Create a ROOT 2D histogram with category bins on the x axis and category bins on the y axis.
 
template<typename T >
void fill (const std::string &name, const T &val)
 Fill a 1D histogram.
 
template<typename T >
void fillw (const std::string &name, const T &val, double w)
 Fill a 1D histogram.
 
template<typename Tx , typename Ty >
void fill (const std::string &name, const Tx &valx, const Ty &valy)
 Fill a 2D histogram.
 
template<typename Tx , typename Ty >
void fillw (const std::string &name, const Tx &valx, const Ty &valy, double w)
 Fill a 2D histogram.
 

Private Member Functions

void insert (const std::string &name, std::function< TH1 *()> factory, bool weighted)
 insert a histogram into this pool by name
 

Private Attributes

double the_weight_ {1.}
 The weight to fill histograms with.
 
std::unordered_map< std::string, TH1 * > histograms_
 the pool of histogram pointers
 
std::function< TDirectory *()> get_directory_
 the callback to get the directory these histograms should go in
 

Detailed Description

Class for holding an EventProcessor's histogram pointers and making sure that they all end up in the same directory in the output histogram file.

Note
In v4.5.1 of ldmx-sw and earlier, all of the processors shared the same pool of histograms, so the naming was a little funky. If a processor's name was "myProc" and a histogram's name was "myHist", the histogram would be written to "myProc/myProc_myHist" in the output histogram file. After v4.5.2, this central pool was abandoned and the output histograms are written to the more obvious location "myProc/myHist" in the output histogram file.

Usage

Each of the EventProcessors have a histograms_ member variable that developers can use within their producers and analyzers. You need to create the histograms before filling them. There are three different ways to specify the bins of a histogram:

  • uniform bins: provide the number of bins, the minimum, and the maximum
  • variable bins: provide the full list of bin edges (as a std::vector)
  • categories: provide a list of named categories (as a std::vector<std::string>)

With these three different ways to specify bins, there are three different ways to create a 1D histogram and nine different ways to create a 2D histogram. (Future developer note: if we want to increase the number of ways to specify the bins – "axis type" – * or increase the number of dimensions again, we probably just want to use a builder pattern like Boost.Histogram or just use Boost.Histogram under-the-hood and copy the resulting histograms into ROOT histograms at end of run time.)

In onProcessStart() or in the Python configuration, you create the histograms that you will want to fill. For example,

histograms_.create("my_variable", "Label for Axis", 10, 0.0, 1.0);
std::unordered_map< std::string, TH1 * > histograms_
the pool of histogram pointers

or

analyzer.build1DHistogram("my_variable", "Label for Axis", 10, 0.0, 1.0)

And then in analyze or produce you fill the histograms.

histograms_.fill("my_variable", the_value);

Attempting to create histograms without the Python configuration providing an output histogram file will fail because then there is no place for the histograms to be saved.

The fill function uses the current setting of the weight in the histograms_object. This is helpful if, for example, you are putting one entry in the histogram for each event and you want the histogram to use the event weights. In order to do this event weighting for histograms, you would add the following line and all of the histograms that are filled after this line will use the event weight.

histograms_.setWeight(event.getEventWeight());

If you don't want to use special weighting, that's fine. The default weight is 1 and you may even have separate histograms in your processor that use different weights for example.

histograms_setWeight(1);
histograms_.fill("h_without_event_weight", value);
histograms_.setWeight(event.getEventWeight());
histograms_.fill("h_with_event_weight", value);

Additionally, if you want to use individual weights for the different histograms, you can use the fillw function to provide a weight when calling fill.

Note
By default, the histograms do not store the sum of the square weights in order to save space. If you are filling histograms with weights that are not 1 and you care about correct error estimates using those histograms, make sure to create the histogram with the weighted argument set to true.

Definition at line 107 of file HistogramPool.h.

Constructor & Destructor Documentation

◆ HistogramPool()

framework::HistogramPool::HistogramPool ( std::function< TDirectory *()> get_directory)
inline

define how we can get the directory we need

Definition at line 147 of file HistogramPool.h.

148 : get_directory_{get_directory} {}
std::function< TDirectory *()> get_directory_
the callback to get the directory these histograms should go in

Member Function Documentation

◆ create() [1/13]

void framework::HistogramPool::create ( const config::Parameters & p)

Create a histogram from the input configuration parameters.

Definition at line 69 of file HistogramPool.cxx.

69 {
70 auto name{p.get<std::string>("name")};
71 auto x_label{p.get<std::string>("xlabel")};
72 auto y_label{p.get<std::string>("ylabel")};
73 auto weighted{p.get<bool>("weighted")};
74 auto numeric_xbins{p.get<std::vector<double>>("xbins")};
75 auto category_xbins{p.get<std::vector<std::string>>("xcategories", {})};
76 auto numeric_ybins{p.get<std::vector<double>>("ybins", {})};
77 auto category_ybins{p.get<std::vector<std::string>>("ycategories", {})};
78
79 bool one_dim = (numeric_ybins.empty() and category_ybins.empty());
80 bool x_is_category = (not category_xbins.empty());
81 bool y_is_category = (not category_ybins.empty());
82 if (one_dim) {
83 // assume 1D histogram
84 if (x_is_category) {
85 create(name, x_label, category_xbins, weighted);
86 } else {
87 create(name, x_label, numeric_xbins, weighted);
88 }
89 } else {
90 if (x_is_category and y_is_category) {
91 create(name, x_label, category_xbins, y_label, category_ybins, weighted);
92 } else if (x_is_category and not y_is_category) {
93 create(name, x_label, category_xbins, y_label, numeric_ybins, weighted);
94 } else if (not x_is_category and y_is_category) {
95 create(name, x_label, numeric_xbins, y_label, category_ybins, weighted);
96 } else /* not x_is_category and not y_is_category */ {
97 create(name, x_label, numeric_xbins, y_label, numeric_ybins, weighted);
98 }
99 }
100}
void create(const config::Parameters &p)
Create a histogram from the input configuration parameters.

References create(), and framework::config::Parameters::get().

Referenced by create(), dqm::SimObjects::createCalorimeterHists(), dqm::SimObjects::createTrackerHists(), dqm::HCalRawDigi::onProcessStart(), dqm::SimObjects::onProcessStart(), dqm::Trigger::onProcessStart(), dqm::TrigScintClusterDQM::onProcessStart(), dqm::TrigScintDQM::onProcessStart(), dqm::TrigScintHitDQM::onProcessStart(), dqm::TrigScintTrackDQM::onProcessStart(), ldmx::ecal::TrigPrimResolutionAnalyzer::onProcessStart(), Standalone::onProcessStart(), and TEST_CASE().

◆ create() [2/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const int & bins,
const double & xmin,
const double & xmax,
bool weighted = false )

Create a ROOT 1D histogram with uniform binning.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
binsTotal number of histogram bins.
xminThe lower histogram limit.
xmaxThe upper histogram limit.
weightedwhether to track the sum of squared weights separately

Definition at line 117 of file HistogramPool.cxx.

119 {
120 insert(
121 name,
122 [&]() {
123 auto hist = new TH1F(name.c_str(), "", bins, xmin, xmax);
124 hist->GetXaxis()->SetTitle(x_label.c_str());
125 return hist;
126 },
127 weighted);
128}
void insert(const std::string &name, std::function< TH1 *()> factory, bool weighted)
insert a histogram into this pool by name

References insert().

◆ create() [3/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const int & xbins,
const double & xmin,
const double & xmax,
const std::string & y_label,
const int & ybins,
const double & ymin,
const double & ymax,
bool weighted = false )

Create a ROOT 2D histogram with both axes having uniform binning.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsTotal number of histogram bins in x.
xminThe lower histogram limit in x.
xmaxThe upper histogram limit in x.
y_labelTitle of the x axis.
ybinsTotal number of histogram bins in y.
yminThe lower histogram limit in y.
ymaxThe upper histogram limit in y.
weightedwhether to track the sum of squared weights separately

Definition at line 142 of file HistogramPool.cxx.

146 {
147 insert(
148 name,
149 [&]() {
150 auto hist =
151 new TH2F(name.c_str(), "", xbins, xmin, xmax, ybins, ymin, ymax);
152 hist->GetXaxis()->SetTitle(x_label.c_str());
153 hist->GetYaxis()->SetTitle(y_label.c_str());
154 return hist;
155 },
156 weighted);
157}

References insert().

◆ create() [4/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const int & xbins,
const double & xmin,
const double & xmax,
const std::string & y_label,
const std::vector< double > & ybins,
bool weighted = false )

Create a ROOT 2D histogram with uniform bins on the x axis and variable bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsTotal number of histogram bins in x.
xminThe lower histogram limit in x.
xmaxThe upper histogram limit in x.
y_labelTitle of the x axis.
ybinsvector of bin edges
weightedwhether to track the sum of squared weights separately

Definition at line 195 of file HistogramPool.cxx.

198 {
199 insert(
200 name,
201 [&]() {
202 auto hist = new TH2F(name.c_str(), "", xbins, xmin, xmax,
203 ybins.size() - 1, ybins.data());
204 hist->GetXaxis()->SetTitle(x_label.c_str());
205 hist->GetYaxis()->SetTitle(y_label.c_str());
206 return hist;
207 },
208 weighted);
209}

References insert().

◆ create() [5/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const int & xbins,
const double & xmin,
const double & xmax,
const std::string & y_label,
const std::vector< std::string > & ycategories,
bool weighted = false )

Create a ROOT 2D histogram with uniform bins on the x axis and category bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsTotal number of histogram bins in x.
xminThe lower histogram limit in x.
xmaxThe upper histogram limit in x.
y_labelTitle of the x axis.
ycategoriesvector of string categories
weightedwhether to track the sum of squared weights separately

Definition at line 211 of file HistogramPool.cxx.

215 {
216 insert(
217 name,
218 [&]() {
219 auto [nybins, ymin, ymax] = categoryBins(ycategories);
220 auto hist =
221 new TH2F(name.c_str(), "", xbins, xmin, xmax, nybins, ymin, ymax);
222 labelAxis(hist->GetYaxis(), ycategories);
223 hist->GetXaxis()->SetTitle(x_label.c_str());
224 hist->GetYaxis()->SetTitle(y_label.c_str());
225 return hist;
226 },
227 weighted);
228}

References insert().

◆ create() [6/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< double > & bins,
bool weighted = false )

Create a ROOT 1D histogram with variable binning.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
binsvector of bin edges
weightedwhether to track the sum of squared weights separately

Definition at line 130 of file HistogramPool.cxx.

131 {
132 insert(
133 name,
134 [&]() {
135 auto hist = new TH1F(name.c_str(), "", bins.size() - 1, bins.data());
136 hist->GetXaxis()->SetTitle(x_label.c_str());
137 return hist;
138 },
139 weighted);
140}

References insert().

◆ create() [7/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< double > & xbins,
const std::string & y_label,
const int & ybins,
const double & ymin,
const double & ymax,
bool weighted = false )

Create a ROOT 2D histogram with variable bins on the x axis and uniform bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsvector of bin edges
y_labelTitle of the x axis.
ybinsTotal number of histogram bins in y.
yminThe lower histogram limit in y.
ymaxThe upper histogram limit in y.
weightedwhether to track the sum of squared weights separately

Definition at line 159 of file HistogramPool.cxx.

163 {
164 insert(
165 name,
166 [&]() {
167 auto hist = new TH2F(name.c_str(), "", xbins.size() - 1, xbins.data(),
168 ybins, ymin, ymax);
169 hist->GetXaxis()->SetTitle(x_label.c_str());
170 hist->GetYaxis()->SetTitle(y_label.c_str());
171 return hist;
172 },
173 weighted);
174}

References insert().

◆ create() [8/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< double > & xbins,
const std::string & y_label,
const std::vector< double > & ybins,
bool weighted = false )

Create a ROOT 2D histogram with variable bins on the x axis and variable bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsvector of bin edges
y_labelTitle of the x axis.
ybinsvector of bin edges
weightedwhether to track the sum of squared weights separately

Definition at line 230 of file HistogramPool.cxx.

233 {
234 insert(
235 name,
236 [&]() {
237 auto hist = new TH2F(name.c_str(), "", xbins.size() - 1, xbins.data(),
238 ybins.size() - 1, ybins.data());
239 hist->GetXaxis()->SetTitle(x_label.c_str());
240 hist->GetYaxis()->SetTitle(y_label.c_str());
241 return hist;
242 },
243 weighted);
244}

References insert().

◆ create() [9/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< double > & xbins,
const std::string & y_label,
const std::vector< std::string > & ycategories,
bool weighted = false )

Create a ROOT 2D histogram with variable bins on the x axis and category bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xbinsvector of bin edges
y_labelTitle of the x axis.
ycategoriesvector of string categories
weightedwhether to track the sum of squared weights separately

Definition at line 246 of file HistogramPool.cxx.

250 {
251 insert(
252 name,
253 [&]() {
254 auto [nybins, ymin, ymax] = categoryBins(ycategories);
255 auto hist = new TH2F(name.c_str(), "", xbins.size() - 1, xbins.data(),
256 nybins, ymin, ymax);
257 labelAxis(hist->GetYaxis(), ycategories);
258 hist->GetXaxis()->SetTitle(x_label.c_str());
259 hist->GetYaxis()->SetTitle(y_label.c_str());
260 return hist;
261 },
262 weighted);
263}

References insert().

◆ create() [10/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< std::string > & categories,
bool weighted = false )

Create a ROOT 1D histogram with categorical binning.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
categorieslist of string categories to name the bins
weightedwhether to track the sum of squared weights separately

Definition at line 102 of file HistogramPool.cxx.

104 {
105 insert(
106 name,
107 [&]() {
108 auto [nbins, xmin, xmax] = categoryBins(categories);
109 auto hist = new TH1F(name.c_str(), "", nbins, xmin, xmax);
110 hist->GetXaxis()->SetTitle(x_label.c_str());
111 labelAxis(hist->GetXaxis(), categories);
112 return hist;
113 },
114 weighted);
115}

References insert().

◆ create() [11/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< std::string > & xcategories,
const std::string & y_label,
const int & ybins,
const double & ymin,
const double & ymax,
bool weighted = false )

Create a ROOT 2D histogram with category bins on the x axis and uniform bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xcategoriesvector of string categories
y_labelTitle of the x axis.
ybinsTotal number of histogram bins in y.
yminThe lower histogram limit in y.
ymaxThe upper histogram limit in y.
weightedwhether to track the sum of squared weights separately

Definition at line 176 of file HistogramPool.cxx.

180 {
181 insert(
182 name,
183 [&]() {
184 auto [nxbins, xmin, xmax] = categoryBins(xcategories);
185 auto hist =
186 new TH2F(name.c_str(), "", nxbins, xmin, xmax, ybins, ymin, ymax);
187 labelAxis(hist->GetXaxis(), xcategories);
188 hist->GetXaxis()->SetTitle(x_label.c_str());
189 hist->GetYaxis()->SetTitle(y_label.c_str());
190 return hist;
191 },
192 weighted);
193}

References insert().

◆ create() [12/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< std::string > & xcategories,
const std::string & y_label,
const std::vector< double > & ybins,
bool weighted = false )

Create a ROOT 2D histogram with category bins on the x axis and variable bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xcategoriesvector of string categories
y_labelTitle of the x axis.
ybinsvector of bin edges
weightedwhether to track the sum of squared weights separately

Definition at line 265 of file HistogramPool.cxx.

268 {
269 insert(
270 name,
271 [&]() {
272 auto [nxbins, xmin, xmax] = categoryBins(xcategories);
273 auto hist = new TH2F(name.c_str(), "", nxbins, xmin, xmax,
274 ybins.size() - 1, ybins.data());
275 labelAxis(hist->GetXaxis(), xcategories);
276 hist->GetXaxis()->SetTitle(x_label.c_str());
277 hist->GetYaxis()->SetTitle(y_label.c_str());
278 return hist;
279 },
280 weighted);
281}

References insert().

◆ create() [13/13]

void framework::HistogramPool::create ( const std::string & name,
const std::string & x_label,
const std::vector< std::string > & xcategories,
const std::string & y_label,
const std::vector< std::string > & ycategories,
bool weighted = false )

Create a ROOT 2D histogram with category bins on the x axis and category bins on the y axis.

Parameters
nameName of the histogram.
x_labelTitle of the x axis.
xcategoriesvector of string categories
y_labelTitle of the x axis.
ycategoriesvector of string categories
weightedwhether to track the sum of squared weights separately

Definition at line 283 of file HistogramPool.cxx.

287 {
288 insert(
289 name,
290 [&]() {
291 auto [nybins, ymin, ymax] = categoryBins(ycategories);
292 auto [nxbins, xmin, xmax] = categoryBins(xcategories);
293 auto hist =
294 new TH2F(name.c_str(), "", nxbins, xmin, xmax, nybins, ymin, ymax);
295 labelAxis(hist->GetYaxis(), ycategories);
296 labelAxis(hist->GetXaxis(), xcategories);
297 hist->GetXaxis()->SetTitle(x_label.c_str());
298 hist->GetYaxis()->SetTitle(y_label.c_str());
299 return hist;
300 },
301 weighted);
302}

References insert().

◆ fill() [1/2]

template<typename T >
void framework::HistogramPool::fill ( const std::string & name,
const T & val )
inline

Fill a 1D histogram.

Uses the current setting of the weight.

Parameters
namename of the histogram to fill
valvalue to fill

Definition at line 367 of file HistogramPool.h.

367 {
368 auto hist = dynamic_cast<TH1F*>(this->get(name));
369 if (hist) {
370 hist->Fill(val, the_weight_);
371 } else {
372 // the `get` method handles checking if the histogram exists
373 // the only way that hist would be null at this point is if its not a TH1F
374 EXCEPTION_RAISE(
375 "BadHistSize",
376 "Attempting to 1D fill a histogram that is not actually 1D.");
377 }
378 }
TH1 * get(const std::string &name)
get a histogram from this pool by name
double the_weight_
The weight to fill histograms with.

References get(), and the_weight_.

Referenced by dqm::EcalClusterAnalyzer::analyze(), dqm::EcalDigiVerifier::analyze(), dqm::EcalMipTrackingFeatures::analyze(), dqm::EcalPnetVetoResults::analyze(), dqm::EcalShowerFeatures::analyze(), dqm::EcalSPTrackCompare::analyze(), dqm::EcalTrackAnalyzer::analyze(), dqm::EcalVetoResults::analyze(), dqm::EcalWABRecResults::analyze(), dqm::HcalGeometryVerifier::analyze(), dqm::HcalInefficiencyAnalyzer::analyze(), dqm::HCalRawDigi::analyze(), dqm::HcalVetoResults::analyze(), dqm::HgcrocPulseTruthAnalyzer::analyze(), dqm::SampleValidation::analyze(), dqm::SimObjects::analyze(), dqm::Trigger::analyze(), dqm::TrigScintClusterDQM::analyze(), dqm::TrigScintDigiVerifier::analyze(), dqm::TrigScintDQM::analyze(), dqm::TrigScintHitDQM::analyze(), dqm::TrigScintTrackDQM::analyze(), dqm::TrkDeDxMassEstFeatures::analyze(), dqm::VisiblesCutflow::analyze(), dqm::VisiblesFeatureProducer::analyze(), ldmx::ecal::TrigPrimResolutionAnalyzer::analyze(), Standalone::analyze(), tracking::dqm::DigiDQM::analyze(), tracking::dqm::RawSiStripDQM::analyze(), tracking::dqm::StraightTracksDQM::analyze(), tracking::dqm::TrackerDigiDQM::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), dqm::DarkBremInteraction::produce(), dqm::EcalSPElectronKinematics::produce(), and tracking::dqm::TrackingRecoDQM::trackStateMonitoring().

◆ fill() [2/2]

template<typename Tx , typename Ty >
void framework::HistogramPool::fill ( const std::string & name,
const Tx & valx,
const Ty & valy )
inline

Fill a 2D histogram.

Uses the current setting of the weight.

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

Definition at line 413 of file HistogramPool.h.

413 {
414 auto hist = dynamic_cast<TH2F*>(this->get(name));
415 if (hist) {
416 hist->Fill(valx, valy, the_weight_);
417 } else {
418 // the `get` method handles checking if the histogram exists
419 // the only way that hist would be null at this point is if its not a TH2F
420 EXCEPTION_RAISE(
421 "BadHistSize",
422 "Attempting to 2D fill a histogram that is not actually 2D.");
423 }
424 }

References get(), and the_weight_.

◆ fillw() [1/2]

template<typename T >
void framework::HistogramPool::fillw ( const std::string & name,
const T & val,
double w )
inline

Fill a 1D histogram.

Using the input weight.

Parameters
namename of the histogram to fill
valvalue to fill
wweight to fill with

Definition at line 390 of file HistogramPool.h.

390 {
391 auto hist = dynamic_cast<TH1F*>(this->get(name));
392 if (hist) {
393 hist->Fill(val, w);
394 } else {
395 // the `get` method handles checking if the histogram exists
396 // the only way that hist would be null at this point is if its not a TH1F
397 EXCEPTION_RAISE(
398 "BadHistSize",
399 "Attempting to 1D fill a histogram that is not actually 1D.");
400 }
401 }

References get().

◆ fillw() [2/2]

template<typename Tx , typename Ty >
void framework::HistogramPool::fillw ( const std::string & name,
const Tx & valx,
const Ty & valy,
double w )
inline

Fill a 2D histogram.

Using the input weight.

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

Definition at line 437 of file HistogramPool.h.

438 {
439 auto hist = dynamic_cast<TH2F*>(this->get(name));
440 if (hist) {
441 hist->Fill(valx, valy, w);
442 } else {
443 // the `get` method handles checking if the histogram exists
444 // the only way that hist would be null at this point is if its not a TH2F
445 EXCEPTION_RAISE(
446 "BadHistSize",
447 "Attempting to 2D fill a histogram that is not actually 2D.");
448 }
449 }

References get().

◆ get()

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

get a histogram from this pool by name

Definition at line 15 of file HistogramPool.cxx.

15 {
16 auto histo = histograms_.find(name);
17 if (histo == histograms_.end()) {
18 EXCEPTION_RAISE(
19 "InvalidArg",
20 "Histogram " + name +
21 " not found in pool."
22 "\nMake sure to `histograms_.create` in onProcessStart for any "
23 "histogram you want to `histograms_.fill`.");
24 }
25
26 return histograms_[name];
27}

References histograms_.

Referenced by tracking::dqm::RawSiStripDQM::analyze(), fill(), fill(), fillw(), fillw(), and tracking::dqm::RawSiStripDQM::getHists().

◆ insert()

void framework::HistogramPool::insert ( const std::string & name,
std::function< TH1 *()> factory,
bool weighted )
private

insert a histogram into this pool by name

Note
The fill method assumes we are creating TH1F or TH2F histograms which is what is implemented in the create methods.
Parameters
[in]namename to store histogram under in the pool, the create methods below ensure that the name in the pool and the name in the output file are the same
[in]factorythe function that creates the histogram which is called after we go into the appropriate output directory, the returned pointer is then put into the pool after checking that it doesn't exist yet.
[in]weightedtrue if histogram is weighted (we then call Sumw2) or false otherwise
Exceptions
framework::Exceptionif the passed name already exists

The histogram needs to be created after we cd into the appropriate output directory which is why we pass in the factory function that creates the histogram into this function rather than a pointer to the already created histogram itself.

Definition at line 29 of file HistogramPool.cxx.

30 {
31 if (histograms_.find(name) != histograms_.end()) {
32 EXCEPTION_RAISE(
33 "RepeatName",
34 "Histogram " + name +
35 " already exists in histogram pool."
36 "\nMake sure to use distinct names for your different histograms!"
37 "\nYou can use `histograms_.get` to retrieve a pointer to a "
38 "specific histogram "
39 "if you want to do some other customizations besides filling.");
40 }
41
42 get_directory_()->cd();
43
50 auto hist = factory();
51 if (weighted) hist->Sumw2();
52 histograms_[name] = hist;
53}

References get_directory_, and histograms_.

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

◆ setWeight()

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

Set the weight for filling the histograms.

Definition at line 153 of file HistogramPool.h.

153{ the_weight_ = w; }

References the_weight_.

Referenced by dqm::DarkBremInteraction::produce(), and dqm::EcalSPElectronKinematics::produce().

Member Data Documentation

◆ get_directory_

std::function<TDirectory*()> framework::HistogramPool::get_directory_
private

the callback to get the directory these histograms should go in

This needs to be dynamic so that the directory is only created upon request.

Note
the returned TDirectory pointer is immediately de-referenced, so we will get a segmentation fault if the function stored here returns an invalid address (such as nullptr).

Definition at line 123 of file HistogramPool.h.

Referenced by insert().

◆ histograms_

std::unordered_map<std::string, TH1*> framework::HistogramPool::histograms_
private

the pool of histogram pointers

Definition at line 112 of file HistogramPool.h.

Referenced by get(), and insert().

◆ the_weight_

double framework::HistogramPool::the_weight_ {1.}
private

The weight to fill histograms with.

Definition at line 110 of file HistogramPool.h.

110{1.};

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


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