|
LDMX Software
|
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 | |
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.
"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.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:
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,
or
And then in analyze or produce you fill the histograms.
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.
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.
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.
create the histogram with the weighted argument set to true. Definition at line 107 of file HistogramPool.h.
|
inline |
define how we can get the directory we need
Definition at line 147 of file HistogramPool.h.
| void framework::HistogramPool::create | ( | const config::Parameters & | p | ) |
Create a histogram from the input configuration parameters.
Definition at line 71 of file HistogramPool.cxx.
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(), and TEST_CASE().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| bins | Total number of histogram bins. |
| xmin | The lower histogram limit. |
| xmax | The upper histogram limit. |
| weighted | whether to track the sum of squared weights separately |
Definition at line 119 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | Total number of histogram bins in x. |
| xmin | The lower histogram limit in x. |
| xmax | The upper histogram limit in x. |
| y_label | Title of the x axis. |
| ybins | Total number of histogram bins in y. |
| ymin | The lower histogram limit in y. |
| ymax | The upper histogram limit in y. |
| weighted | whether to track the sum of squared weights separately |
Definition at line 144 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | Total number of histogram bins in x. |
| xmin | The lower histogram limit in x. |
| xmax | The upper histogram limit in x. |
| y_label | Title of the x axis. |
| ybins | vector of bin edges |
| weighted | whether to track the sum of squared weights separately |
Definition at line 197 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | Total number of histogram bins in x. |
| xmin | The lower histogram limit in x. |
| xmax | The upper histogram limit in x. |
| y_label | Title of the x axis. |
| ycategories | vector of string categories |
| weighted | whether to track the sum of squared weights separately |
Definition at line 213 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| bins | vector of bin edges |
| weighted | whether to track the sum of squared weights separately |
Definition at line 132 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | vector of bin edges |
| y_label | Title of the x axis. |
| ybins | Total number of histogram bins in y. |
| ymin | The lower histogram limit in y. |
| ymax | The upper histogram limit in y. |
| weighted | whether to track the sum of squared weights separately |
Definition at line 161 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | vector of bin edges |
| y_label | Title of the x axis. |
| ybins | vector of bin edges |
| weighted | whether to track the sum of squared weights separately |
Definition at line 232 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xbins | vector of bin edges |
| y_label | Title of the x axis. |
| ycategories | vector of string categories |
| weighted | whether to track the sum of squared weights separately |
Definition at line 248 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| categories | list of string categories to name the bins |
| weighted | whether to track the sum of squared weights separately |
Definition at line 104 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xcategories | vector of string categories |
| y_label | Title of the x axis. |
| ybins | Total number of histogram bins in y. |
| ymin | The lower histogram limit in y. |
| ymax | The upper histogram limit in y. |
| weighted | whether to track the sum of squared weights separately |
Definition at line 178 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xcategories | vector of string categories |
| y_label | Title of the x axis. |
| ybins | vector of bin edges |
| weighted | whether to track the sum of squared weights separately |
Definition at line 267 of file HistogramPool.cxx.
References insert().
| 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.
| name | Name of the histogram. |
| x_label | Title of the x axis. |
| xcategories | vector of string categories |
| y_label | Title of the x axis. |
| ycategories | vector of string categories |
| weighted | whether to track the sum of squared weights separately |
Definition at line 285 of file HistogramPool.cxx.
References insert().
|
inline |
Fill a 1D histogram.
Uses the current setting of the weight.
| name | name of the histogram to fill |
| val | value to fill |
Definition at line 367 of file HistogramPool.h.
References get(), and the_weight_.
Referenced by dqm::EcalClusterAnalyzer::analyze(), dqm::EcalDigiVerifier::analyze(), dqm::EcalMipTrackingFeatures::analyze(), dqm::EcalPnetVetoResults::analyze(), dqm::EcalShowerFeatures::analyze(), dqm::EcalVetoResults::analyze(), dqm::EcalWABRecResults::analyze(), dqm::HcalGeometryVerifier::analyze(), dqm::HcalInefficiencyAnalyzer::analyze(), dqm::HCalRawDigi::analyze(), dqm::HcalVetoResults::analyze(), dqm::HgcrocPulseTruthAnalyzer::analyze(), dqm::PhotoNuclearDQM::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(), tracking::dqm::StraightTracksDQM::analyze(), tracking::dqm::TrackerDigiDQM::analyze(), tracking::dqm::TrackingRecoDQM::analyze(), dqm::PhotoNuclearDQM::findParticleKinematics(), dqm::PhotoNuclearDQM::findRecoilProperties(), dqm::PhotoNuclearDQM::findSubleadingKinematics(), dqm::DarkBremInteraction::produce(), and tracking::dqm::TrackingRecoDQM::trackStateMonitoring().
|
inline |
Fill a 2D histogram.
Uses the current setting of the weight.
| name | name of the histogram to fill |
| valx | x value to fill |
| valy | y value to fill |
Definition at line 413 of file HistogramPool.h.
References get(), and the_weight_.
|
inline |
Fill a 1D histogram.
Using the input weight.
| name | name of the histogram to fill |
| val | value to fill |
| w | weight to fill with |
Definition at line 390 of file HistogramPool.h.
References get().
|
inline |
Fill a 2D histogram.
Using the input weight.
| name | name of the histogram to fill |
| valx | x value to fill |
| valy | y value to fill |
| w | weight to fill with |
Definition at line 437 of file HistogramPool.h.
References get().
| TH1 * framework::HistogramPool::get | ( | const std::string & | name | ) |
get a histogram from this pool by name
Definition at line 17 of file HistogramPool.cxx.
References histograms_.
|
private |
insert a histogram into this pool by name
fill method assumes we are creating TH1F or TH2F histograms which is what is implemented in the create methods.| [in] | name | name 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] | factory | the 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] | weighted | true if histogram is weighted (we then call Sumw2) or false otherwise |
| framework::Exception | if 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 31 of file HistogramPool.cxx.
References get_directory_, and histograms_.
Referenced by create(), create(), create(), create(), create(), create(), create(), create(), create(), create(), create(), and create().
|
inline |
Set the weight for filling the histograms.
Definition at line 153 of file HistogramPool.h.
References the_weight_.
Referenced by dqm::DarkBremInteraction::produce().
|
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.
Definition at line 123 of file HistogramPool.h.
Referenced by insert().
|
private |
the pool of histogram pointers
Definition at line 112 of file HistogramPool.h.
|
private |
The weight to fill histograms with.
Definition at line 110 of file HistogramPool.h.
Referenced by fill(), fill(), and setWeight().