AliPhysics  5eaf189 (5eaf189)
THistManager.h
Go to the documentation of this file.
1 #ifndef THISTMANAGER_H
2 #define THISTMANAGER_H
3 /* Copyright(c) 1998-2016, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice */
5 
6 #include <THashList.h>
7 #include <TIterator.h>
8 #include <TNamed.h>
9 #include <iterator>
10 
11 class TArrayD;
12 class TAxis;
13 class TBinning;
14 class TList;
15 class TH1;
16 class TH2;
17 class TH3;
18 class THnSparse;
19 class TProfile;
20 
99 class THistManager : public TNamed {
100 public:
101 
115  class iterator : public std::iterator<std::bidirectional_iterator_tag,
116  TObject, std::ptrdiff_t,
117  TObject **, TObject *&>{
118  public:
131  };
132 
142  iterator(const THistManager *hmgr, Int_t currentpos, THMIDirection_t dir = kTHMIforward);
143 
150  iterator(const iterator &ref);
151 
155  ~iterator() { }
156 
163  iterator &operator=(const iterator &rhs);
164 
173  Bool_t operator!=(const iterator &aIter) const;
174 
182  iterator &operator++();
183 
192  iterator operator++(int);
193 
201  iterator &operator--();
202 
211  iterator operator--(int);
212 
221  TObject *operator*() const;
222 
223  private:
228 
229  iterator();
230  };
231 
237  THistManager();
238 
245  THistManager(const char *name);
246 
252  ~THistManager();
253 
254  void ReleaseOwner() { fIsOwner = kFALSE; };
255 
266  THashList* CreateHistoGroup(const char *groupname);
267 
280  TH1* CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt = "");
281 
293  TH1* CreateTH1(const char *name, const char *title, int nbins, const double *xbins, Option_t *opt = "");
294 
305  TH1* CreateTH1(const char *name, const char *title, const TArrayD &xbins, Option_t *opt = "");
306 
317  TH1* CreateTH1(const char *name, const char *title, const TBinning &binning, Option_t *opt = "");
318 
333  TH2* CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt = "");
334 
349  TH2* CreateTH2(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, Option_t *opt = "");
350 
361  TH2* CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, Option_t *opt = "");
362 
373  TH2* CreateTH2(const char *name, const char *title, const TBinning &xbins, const TBinning &ybins, Option_t *opt = "");
374 
389  TH3* CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt = "");
390 
405  TH3* CreateTH3(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, int nbinsz, const double *zbins, Option_t *opt = "");
406 
418  TH3* CreateTH3(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, const TArrayD &zbins, Option_t *opt = "");
419 
431  TH3* CreateTH3(const char *name, const char *title, const TBinning &xbins, const TBinning &ybins, const TBinning &zbins, Option_t *opt = "");
432 
445  THnSparse* CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt = "");
446 
457  THnSparse* CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes, Option_t *opt = "");
458 
469  THnSparse* CreateTHnSparse(const char *name, const char *title, int ndim, const TBinning **axes, Option_t *opt = "");
470 
471 
484  void CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt = "");
485 
497  void CreateTProfile(const char *name, const char *title, int nbinsX, const double *xbins, Option_t *opt = "");
498 
509  void CreateTProfile(const char *name, const char *title, const TArrayD &xbins, Option_t *opt = "");
510 
521  void CreateTProfile(const char *name, const char *title, const TBinning &xbins, Option_t *opt = "");
522 
527  void SetObject(TObject * const o, const char *group = "/");
528 
539  void FillTH1(const char *hname, double x, double weight = 1., Option_t *opt = "");
540 
552  void FillTH1(const char *name, const char *label, double weight = 1., Option_t *opt = "");
553 
565  void FillTH2(const char *hname, double x, double y, double weight = 1., Option_t *opt = "");
566 
578  void FillTH2(const char *name, const char *labelX, const char *labelY, double weight = 1., Option_t *opt = "");
579 
590  void FillTH2(const char *hname, double *point, double weight = 1., Option_t *opt = "");
591 
604  void FillTH3(const char *hname, double x, double y, double z, double weight = 1., Option_t *opt = "");
605 
614  void FillTH3(const char *hname, const double *point, double weight = 1., Option_t *opt = "");
615 
624  void FillTHnSparse(const char *name, const double *x, double weight = 1., Option_t *opt = "");
625 
635  void FillProfile(const char *name, double x, double y, double weight = 1.);
636 
642  inline iterator begin() const;
643 
649  inline iterator end() const;
650 
657  inline iterator rbegin() const;
658 
665  inline iterator rend() const;
666 
671  THashList *GetListOfHistograms() const { return fHistos; }
672 
681  TObject *FindObject(const char *name) const;
682 
692  virtual TObject *FindObject(const TObject *obj) const;
693 
694 private:
695  THistManager(const THistManager &);
697 
698 
706  THashList *FindGroup(const char *dirname) const;
707 
713  TString basename(const TString &path) const;
714 
720  TString histname(const TString &path) const;
721 
722  THashList *fHistos;
723  bool fIsOwner;
724 
726  ClassDef(THistManager, 1); // Container for histograms
728 };
729 
731  return iterator(this, 0, iterator::kTHMIforward);
732 }
733 
735  return iterator(this, fHistos->GetEntries()-1, iterator::kTHMIbackward);
736 }
737 
739  return iterator(this, fHistos->GetEntries(), iterator::kTHMIforward);
740 }
741 
743  return iterator(this, -1, iterator::kTHMIbackward);
744 }
745 
751 namespace TestTHistManager {
752 
767 public:
768 
773 
778 
793  int TestBuildSimpleHistograms();
794 
812  int TestBuildGroupedHistograms();
813 
831  int TestFillSimpleHistograms();
832 
847  int TestFillGroupedHistograms();
848 };
849 
855 int TestRunAll();
856 
862 int TestRunBuildSimple();
863 
869 int TestRunBuildGrouped();
870 
876 int TestRunFillSimple();
877 
883 int TestRunFillGrouped();
884 
885 }
886 #endif
Collection of simple test for the THistManager.
Int_t fNext
Next position in the histmanager.
Definition: THistManager.h:226
iterator & operator=(const iterator &rhs)
THashList * CreateHistoGroup(const char *groupname)
Create a new group of histograms within a parent group.
const Double_t ymax
Definition: AddTaskCFDStar.C:7
const char * title
Definition: MakeQAPdf.C:27
Definition: External.C:244
bool fIsOwner
Set the ownership.
Definition: THistManager.h:723
Int_t nbinsy
THistManager()
Default constructor.
THashList * FindGroup(const char *dirname) const
Find histogram group.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
void FillTH3(const char *hname, double x, double y, double z, double weight=1., Option_t *opt="")
Fill a 3D histogram within the container.
const THistManager * fkArray
Underlying histmanager to iterate over.
Definition: THistManager.h:224
void SetObject(TObject *const o, const char *group="/")
Set a new group into the container into the parent group.
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
THMIDirection_t fDirection
Direction of the iterator.
Definition: THistManager.h:227
Bool_t operator!=(const iterator &aIter) const
Comparison operator for unequalness.
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
~THistManager()
Destructor.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
TObject * FindObject(const char *name) const
Find an object inside the container.
int Int_t
Definition: External.C:63
void CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt="")
Create a new TProfile within the container.
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
const Double_t zmin
void ReleaseOwner()
Definition: THistManager.h:254
void FillProfile(const char *name, double x, double y, double weight=1.)
THMIDirection_t
Direction for the iteration.
Definition: THistManager.h:128
stl-iterator for the histogram manager
Definition: THistManager.h:115
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
iterator rbegin() const
Create backward iterator starting behind the end of the container.
Definition: THistManager.h:734
iterator & operator++()
Prefix increment operator.
Int_t nbinsx
iterator begin() const
Create forward iterator starting at the beginning of the container.
Definition: THistManager.h:730
TString basename(const TString &path) const
Extracting the basename from a given histogram path.
Collection of tests for the THistManager.
Definition: THistManager.h:766
iterator & operator--()
Prefix decrement operator.
TString histname(const TString &path) const
Extracting the histogram name from a given histogram path.
Definition: External.C:220
TObject * operator*() const
Dereferncing operator.
iterator end() const
Create forward iterator starting at the end of the container.
Definition: THistManager.h:738
const Double_t ymin
Definition: AddTaskCFDStar.C:6
Container class for histograms.
Definition: THistManager.h:99
iterator rend() const
Create backward iterator starting before the beginning of the container.
Definition: THistManager.h:742
const char Option_t
Definition: External.C:48
const Double_t zmax
const Int_t nbins
bool Bool_t
Definition: External.C:53
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.
THashList * fHistos
List of histograms.
Definition: THistManager.h:722
Definition: External.C:196
TH3 * CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt="")
Create a new TH2 within the container.
Int_t fCurrentPos
Current position of the iterator in the histmanager.
Definition: THistManager.h:225
TDirectoryFile * dir