Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:09

0001 // @(#)root/hist:$Id$
0002 // Author: Benjamin Bannier, August 2016
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_THnChain
0013 #define ROOT_THnChain
0014 
0015 #include <TObject.h>
0016 
0017 #include <string>
0018 #include <vector>
0019 
0020 class TAxis;
0021 class TH1;
0022 class TH2;
0023 class TH3;
0024 class THnBase;
0025 
0026 /** \class THnChain
0027 A class to chain together multiple histograms.
0028 
0029 This class allows to chain together any `THnBase`-derived (`THn` or `THnSparse`)
0030 histograms from multiple files. Operations on the axes and projections are
0031 supported. The intent is to allow convenient merging merging of projections
0032 of high-dimensional histograms.
0033 
0034 \code{.cpp}
0035 // `file1.root` and `file2.root` contain a `THnSparse` named `hsparse`.
0036 THnChain hs("hsparse");
0037 hs.AddFile("file1.root");
0038 hs.AddFile("file2.root");
0039 
0040 // Project out axis 0, integrate over other axes.
0041 TH1* h0 = hs.Projection(0);
0042 
0043 // Project out axis 0, integrate over other axes in their active ranges.
0044 hs.GetAxis(1)->SetRangeUser(0, 0.1); // select a subrange
0045 TH1* h0 = hs.Projection(0);
0046 \endcode
0047 */
0048 
0049 class THnChain : public TObject
0050 {
0051  public:
0052    /// Default constructor.
0053    ///
0054    /// \param name name of the histogram to work on
0055    explicit THnChain(const char* name) : fName(name) {}
0056 
0057    void AddFile(const char* fileName);
0058 
0059    TAxis* GetAxis(Int_t i) const;
0060 
0061    TH1* Projection(Int_t xDim, Option_t* option = "") const;
0062 
0063    TH2* Projection(Int_t yDim, Int_t xDim, Option_t* option = "") const;
0064 
0065    TH3* Projection(Int_t xDim, Int_t yDim, Int_t zDim, Option_t* option = "") const;
0066 
0067    THnBase* ProjectionND(Int_t ndim, const Int_t* dim, Option_t* option = "") const;
0068 
0069  private:
0070    std::string fName;               ///< name of the histogram
0071 
0072    std::vector<std::string> fFiles; ///< a list of files to extract the histogram from
0073    std::vector<TAxis*> fAxes;       ///< the list of histogram axes
0074 
0075    TObject* ProjectionAny(Int_t ndim, const Int_t* dim, Option_t* option = "") const;
0076 
0077    THnBase* ReadHistogram(const char* fileName) const;
0078 
0079    void SetupAxes(THnBase& hs) const;
0080 
0081    static bool CheckConsistency(const THnBase& h, const std::vector<TAxis*>& axes);
0082 
0083    ClassDefOverride(THnChain, 0);
0084 };
0085 
0086 #endif