Histograms

There are three generic levels to include when building up an analysis that involves plotting: * HistogramManager * JetHists, ElectronHists, MuonHists, etc… * JetHistsAlgo, ElectronHistsAlgo, MuonHistsAlgo, etc…

In order: HistogramManager should rarely be changed. This manages the histograms for you in EventLoop algorithms by initializing histograms and adding it to the worker. JetHists, etc are plotting classes to pre-define the set of plots you want to use for a given set of objects – as well as how to plot them. Finally, JetHistsAlgo, etc… are EventLoop algorithms that you would include in your jobs and run to actually apply those plots.

HistogramManager

This is the base class from which all histogram management classes are made for Muons, Jets, Electrons, etcetera. It is meant to be flexible enough for someone to use it to create their own set of histograms to produce for an algorithm from scratch using the class.

In particular, the book() functions are overloaded for good reason - they all do the same thing except the number of arguments supplied tells us what kind of histogram you want to make: 1D, 2D, or 3D. All histograms take in a name and a title which get concatenated to provide the stored name of the histogram (name+title). If you wish to use TDirectoryFiles automagically, append a forward-slash to the end of the name, such as "AntiKt10/". The book() function will create the histogram, set up the title, the labels, append it to m_allHists, and returns a pointer to the newly created histogram. The last argument is sumw2 which tells the function whether to enable sumw2() for the histogram or not, this defaults to true. The order of the arguments are listed in the table.

class HistogramManager

This is used by any class extending to pre-define a set of histograms to book by default.

We expect the user to create a new group of histograms, such as for jets:

class JetHists : public HistogramManager
{
  public:
    JetHists(std::string name, std::string detailStr);
    virtual ~JetHists() ;

    bool m_debug;
    StatusCode initialize();
    StatusCode execute( const xAOD::JetContainer  jets, float eventWeight, int pvLoc = -1);
    StatusCode execute( const xAOD::Jet  jet, float eventWeight, int pvLoc = -1 );
    using HistogramManager::book; // make other overloaded version of book() to show up in subclass
    using HistogramManager::execute; // overload
};

The above example is taken from our implementation in JetHists.

Note

The expectation is that the user does not directly use this class but rather inherits from it.

Subclassed by MetHists

Public Types

typedef std::unordered_map<std::string, TH1*> HistMap_t

Typedef for convenience.

Public Functions

HistogramManager(std::string name, std::string detailStr)

Initialization.

Parameters
  • name – The top-level path in which all histograms are stored under (think of TDirectory)

  • detailStr – Specify the various details of which to plot. For example, jets might want "kinematic substructure".

virtual ~HistogramManager()

Destructor, allows the user to delete histograms that are not being recorded.

inline virtual StatusCode initialize()

Initialize and book all histograms.

Example implementation:

StatusCode JetHists::initialize() {
  m_jetPt          = book(m_name, "jetPt",  "jet p_{T} [GeV]", 120, 0, 3000.);
  return StatusCode::SUCCESS;
}

Note

This should call the overloaded functions HistogramManager::book() to create the histograms so that the user can call hists->record(wk()) to record all histograms to the EventLoop worker.

inline virtual StatusCode execute()

Execute by filling in the histograms.

Example implementation:

StatusCode JetHists::execute( const xAOD::JetContainer  jets, float eventWeight ){
  for(const auto& jet:  jets)
    m_jetPt->Fill( jet->pt()/1.e3, eventWeight );
  return StatusCode::SUCCESS;
}

inline virtual StatusCode finalize()

Finalize anything that needs to be finalized.

Warning

This should rarely be used. There is not a good use case for this functionality but it needs to exist in the off-chance that a user comes along and needs it for their histogram class.

TH1F *book(std::string name, std::string title, std::string xlabel, int xbins, double xlow, double xhigh)

record a histogram and call various functions

Note

This is an overloaded function. It will build the right histogram given the correct number of input arguments.

Parameters
  • name – name of histogram, access it in ROOT file like h_jetPt->Draw()

  • title – usually pointless,put a description of the histogram in here

  • xlabel – label to put on the x-axis

  • xbins – number of xbins to use

  • xlow – lower bound on xbins

  • xhigh – upper bound on xbins

  • xbinsArr – variable xbins, test math \((x_1,y_1)\) and \((x_2,y_2)\)

  • ylabel – label to put on the y-axis

  • ylow – lower bound on ybins

  • yhigh – upper bound on ybins

  • ybinsArr – variable ybins

  • zlabel – label to put on the z-axix

  • zlow – lower bound on zbins

  • zhigh – upper bound on zbins

  • zbinsArr – variable zbins

TH2F *book(std::string name, std::string title, std::string xlabel, int xbins, double xlow, double xhigh, std::string xyabel, int ybins, double ylow, double yhigh)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH3F *book(std::string name, std::string title, std::string xlabel, int xbins, double xlow, double xhigh, std::string ylabel, int ybins, double ylow, double yhigh, std::string zlabel, int zbins, double zlow, double zhigh)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH1F *book(std::string name, std::string title, std::string xlabel, int xbins, const Double_t *xbinsArr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH2F *book(std::string name, std::string title, std::string xlabel, int xbins, const Double_t *xbinsArr, std::string ylabel, int ybins, double ylow, double yhigh)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH2F *book(std::string name, std::string title, std::string xyabel, int xbins, double xlow, double xhigh, std::string ylabel, int ybins, const Double_t *ybinsArr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH2F *book(std::string name, std::string title, std::string xyabel, int xbins, const Double_t *xbinsArr, std::string ylabel, int ybins, const Double_t *ybinsArr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TH3F *book(std::string name, std::string title, std::string xlabel, int xbins, const Double_t *xbinsArr, std::string ylabel, int ybins, const Double_t *ybinsArr, std::string zlabel, int zbins, const Double_t *zbinsArr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TProfile *book(std::string name, std::string title, std::string xlabel, int xbins, double xlow, double xhigh, std::string ylabel, double ylow, double yhigh, std::string option = "")

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TProfile *book(std::string name, std::string title, int xbins, const Double_t *xbinsArr, double ylow, double yhigh)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

TProfile *book(std::string name, std::string title, int xbins, double xlow, double xhigh, double ylow, double yhigh)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void record(EL::IWorker *wk)

record all histograms from HistogramManager::m_allHists to the worker

MsgStream &msg() const

the standard message stream for this algorithm

MsgStream &msg(int level) const

allow ANA_MSG_XXXX macros to be used within algorithms for a given level

TH1 *findHist(const std::string &histName)

Return the pointer to the histogram.

void fillHist(const std::string &histName, double value)

Fill a histogram by name. Can be overloaded with weight.

Parameters
  • histName – The name of the histogram to be filled

  • value – The value to fill the histogram with

void fillHist(const std::string &histName, double value, double weight)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void fillHist(const std::string &histName, double valueX, double valueY, double weight)
void fillHist(const std::string &histName, double valueX, double valueY, double valueZ, double weight)
void fillProfile(const std::string &histName, double valueX, double valueY, double weight)

Public Members

HistMap_t m_histMap

The map of histogram names to their pointers.

Protected Attributes

std::string m_name

generically the main name assigned to all histograms

std::string m_detailStr

a detail level in the form of a string

std::vector<TH1*> m_allHists

a container holding all generated histograms

mutable MsgStream m_msg

hold the MsgStream object

Private Functions

void Sumw2(TH1 *hist, bool flag = true)

Turn on Sumw2 for the histogram.

Parameters
  • hist – The histogram to modify

  • flag – Pass in whether to turn on Sumw2 or not

void record(TH1 *hist)

Push the new histogram to HistogramManager::m_allHists and add its name to HistogramManager::m_histMap.

void SetLabel(TH1 *hist, std::string xlabel)

Set the labels on a histogram.

Parameters
  • hist – The histogram to set the labels on

  • xlabel – The xlabel to set

  • ylabel – The ylabel to set

  • zlabel – The zlabel to set

void SetLabel(TH1 *hist, std::string xlabel, std::string ylabel)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void SetLabel(TH1 *hist, std::string xlabel, std::string ylabel, std::string zlabel)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Classes

This is a class that predefines all the histograms, defines the execute function which fills in the histograms for you, given an object or a collection of objects, and handles a lot of other logic. This class extends HistogramManager.

Algorithms

This is an EL Algorithm that incorporates the correspondingly-named class.