Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
THnChain.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Benjamin Bannier, August 2016
3
4/*************************************************************************
5 * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_THnChain
13#define ROOT_THnChain
14
15#include <TObject.h>
16
17#include <string>
18#include <vector>
19
20class TAxis;
21class TH1;
22class TH2;
23class TH3;
24class THnBase;
25
26/** \class THnChain
27A class to chain together multiple histograms.
28
29This class allows to chain together any `THnBase`-derived (`THn` or `THnSparse`)
30histograms from multiple files. Operations on the axes and projections are
31supported. The intent is to allow convenient merging merging of projections
32of high-dimensional histograms.
33
34\code{.cpp}
35// `file1.root` and `file2.root` contain a `THnSparse` named `hsparse`.
36THnChain hs("hsparse");
37hs.AddFile("file1.root");
38hs.AddFile("file2.root");
39
40// Project out axis 0, integrate over other axes.
41TH1* h0 = hs.Projection(0);
42
43// Project out axis 0, integrate over other axes in their active ranges.
44hs.GetAxis(1)->SetRangeUser(0, 0.1); // select a subrange
45TH1* h0 = hs.Projection(0);
46\endcode
47*/
48
49class THnChain : public TObject
50{
51 public:
52 /// Default constructor.
53 ///
54 /// \param name name of the histogram to work on
55 explicit THnChain(const char* name) : fName(name) {}
56
57 void AddFile(const char* fileName);
58
59 TAxis* GetAxis(Int_t i) const;
60
61 TH1* Projection(Int_t xDim, Option_t* option = "") const;
62
63 TH2* Projection(Int_t yDim, Int_t xDim, Option_t* option = "") const;
64
65 TH3* Projection(Int_t xDim, Int_t yDim, Int_t zDim, Option_t* option = "") const;
66
67 THnBase* ProjectionND(Int_t ndim, const Int_t* dim, Option_t* option = "") const;
68
69 private:
70 std::string fName; ///< name of the histogram
71
72 std::vector<std::string> fFiles; ///< a list of files to extract the histogram from
73 std::vector<TAxis*> fAxes; ///< the list of histogram axes
74
75 TObject* ProjectionAny(Int_t ndim, const Int_t* dim, Option_t* option = "") const;
76
77 THnBase* ReadHistogram(const char* fileName) const;
78
79 void SetupAxes(THnBase& hs) const;
80
81 static bool CheckConsistency(const THnBase& h, const std::vector<TAxis*>& axes);
82
84};
85
86#endif
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
char name[80]
Definition TGX11.cxx:110
Class to manage histogram axis.
Definition TAxis.h:31
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
Service class for 2-D histogram classes.
Definition TH2.h:30
The 3-D histogram classes derived from the 1-D histogram classes.
Definition TH3.h:31
Multidimensional histogram base.
Definition THnBase.h:43
A class to chain together multiple histograms.
Definition THnChain.h:50
TAxis * GetAxis(Int_t i) const
Get an axis from the histogram.
Definition THnChain.cxx:59
std::vector< TAxis * > fAxes
the list of histogram axes
Definition THnChain.h:73
THnBase * ReadHistogram(const char *fileName) const
Retrieve a histogram from a file.
Definition THnChain.cxx:137
THnChain(const char *name)
Default constructor.
Definition THnChain.h:55
void SetupAxes(THnBase &hs) const
Copy the properties of all axes to a histogram.
Definition THnChain.cxx:157
THnBase * ProjectionND(Int_t ndim, const Int_t *dim, Option_t *option="") const
See THnBase::Projection for the intended behavior.
Definition THnChain.cxx:246
TObject * ProjectionAny(Int_t ndim, const Int_t *dim, Option_t *option="") const
Projects all histograms in the chain.
Definition THnChain.cxx:71
static bool CheckConsistency(const THnBase &h, const std::vector< TAxis * > &axes)
Ensure a histogram has axes similar to the ones we expect.
Definition THnChain.cxx:171
void AddFile(const char *fileName)
Add a new file to this chain.
Definition THnChain.cxx:27
TH1 * Projection(Int_t xDim, Option_t *option="") const
See THnBase::Projection for the intended behavior.
Definition THnChain.cxx:222
std::string fName
name of the histogram
Definition THnChain.h:70
std::vector< std::string > fFiles
a list of files to extract the histogram from
Definition THnChain.h:72
Mother of all ROOT objects.
Definition TObject.h:41