ROOTANA
THistogramArrayBase.h
Go to the documentation of this file.
1 #ifndef THistogramArrayBase_h
2 #define THistogramArrayBase_h
3 
4 
5 #include <iostream>
6 #include <string>
7 #include <stdlib.h>
8 
9 #include "TCanvasHandleBase.hxx"
10 #include "TDataContainer.hxx"
11 #include "TH1F.h"
12 #include <vector>
13 
14 /// Base class for user to create an array of histograms.
15 /// Features of the histogram array
16 /// i) Histograms are all defined together.
17 /// ii) Histograms are updated together
18 ///
19 /// Users of this abstract base class should implement a class
20 /// derived from must THistogramArrayBase that
21 /// 1) define the histograms that you want in CreateHistogram() and calls CreateHistogram in your constructor.
22 /// 2) implement the UpdateHistograms(TDataContainer&) method.
23 ///
24 /// Most, though not all, of logic of this histogram array is based on it being
25 /// a set of similar histograms; if you use this class for
26 /// a set of dissimilar histograms (different binning, different quantities)
27 /// then the class will be less intuitive.
28 /// The array'ness is actually implemented as a vector of TH1s.
29 ///
30 /// The default representation is to have a 1D array of histograms.
31 /// But the user can also use the class a 2D array of histograms by specifying the functions
32 ///
33 /// Grouping histograms together like this is most beneficial when using the display programs.
34 class THistogramArrayBase : public std::vector<TH1*> {
35  public:
37  fDisableAutoUpdate(false),fHasAutoUpdate(false),fSubTabName("DEFAULT"),fTabName(""),
38  fUpdateWhenPlotted(false){};
39 
40  virtual ~THistogramArrayBase();
41 
42  /// Update the histograms for this canvas.
43  virtual void UpdateHistograms(TDataContainer& dataContainer) = 0;
44 
45  /// A helper method for accessing each histogram. Does bounds checking.
46  TH1* GetHistogram(unsigned i);
47 
48  /// Function to create histograms; users will want to implement this function
49  virtual void CreateHistograms(){};
50 
51  /// Take actions at begin run
52  virtual void BeginRun(int transition,int run,int time){ CreateHistograms();};
53 
54  /// Take actions at end run
55  virtual void EndRun(int transition,int run,int time){};
56 
57  /// Function to define the number of channels in group and
58  /// allow user to treat the array as 2D array.
59  void SetNumberChannelsInGroup(int numberChannelsInGroups){ fNumberChannelsInGroups = numberChannelsInGroups; }
61 
62  /// Set name for the 'group'.
63  void SetGroupName(std::string name){ fGroupName = name; }
64  const std::string GetGroupName(){ return fGroupName; }
65 
66  /// Set name for the 'channel'.
67  void SetChannelName(std::string name){ fChannelName = name; }
68  const std::string GetChannelName(){ return fChannelName; }
69 
70 
71 
72  /// Define whether the histogram gets automatically updated by rootana display.
73  /// 'True' means that rootana display will NOT call UpdateHistograms automatically.
74  void DisableAutoUpdate(bool DisableautoUpdate=true){ fDisableAutoUpdate = DisableautoUpdate; fHasAutoUpdate = true;}
75  const bool GetDisableAutoUpdate(){ return fDisableAutoUpdate; }
76  const bool HasAutoUpdate(){ return fHasAutoUpdate; }
77 
78 
79 
80  /// Get the name of the top-level tab for these plots, if running DaqDisplay.
81  virtual std::string GetTabName() {
82  return fTabName;
83  }
84 
85  /// Get the name of the sub-tab for these plots, if running DaqDisplay.
86  virtual std::string GetSubTabName() {
87  return fSubTabName;
88  }
89 
90  /// Get whether these histograms should be drawn by DaqDisplay::DrawCanvas()
91  /// rather than DaqAnalyzer::ProcessMidasEvent()
92  virtual bool IsUpdateWhenPlotted() {
93  return fUpdateWhenPlotted;
94  }
95 
96  /// If you are creating a specialized canvas (for example, showing several
97  /// different plots in the same canvas) you should implement this function.
98  /// If you are just creating a standard histogram canvas, you do not need
99  /// to implement this function.
100  virtual TCanvasHandleBase* CreateCanvas();
101 
102  protected:
103 
104  /// Set the name of the top-level tab for these plots, if running DaqDisplay.
105  virtual void SetTabName(std::string name) {
106  fTabName = name;
107  }
108 
109  /// Set the name of the sub-tab for these plots, if running DaqDisplay.
110  virtual void SetSubTabName(std::string name) {
111  fSubTabName = name;
112  }
113 
114  /// Set whether these histograms should be drawn by DrawCanvas()
115  /// rather than AProcessMidasEvent(). This should only be set
116  /// to true for histograms that only are plotting information
117  /// for a single event (ie, don't set this for any histogram that is cumulative).
118  virtual void SetUpdateOnlyWhenPlotted(bool whenupdate) {
119  fUpdateWhenPlotted = whenupdate;
120  }
121 
122 private:
123 
124  /// This is the number of channels in a given group.
125  /// This is mostly used by rootana display, but could
126  /// also be used to specify histograms as a 2D array of [group][channel.
128 
129  /// The name for the 'group'.
130  std::string fGroupName;
131 
132  /// The name for the 'channel'.
133  std::string fChannelName;
134 
135  /// Defines whether the histogram should be automatically updated
136  /// by TRootanaDisplay.
139 
140  // The tab and sub-tab name for when displaying
141  std::string fSubTabName;
142  std::string fTabName;
143 
144  // Some histograms should only get updated when they are being plotted
145  // This is mainly for histograms that show a single event (as opposed to cumulative histograms)
147 
148 };
149 
150 #endif
virtual void BeginRun(int transition, int run, int time)
Take actions at begin run.
virtual std::string GetSubTabName()
Get the name of the sub-tab for these plots, if running DaqDisplay.
void SetNumberChannelsInGroup(int numberChannelsInGroups)
virtual void SetSubTabName(std::string name)
Set the name of the sub-tab for these plots, if running DaqDisplay.
const std::string GetChannelName()
const int GetNumberChannelsInGroup()
const std::string GetGroupName()
virtual void UpdateHistograms(TDataContainer &dataContainer)=0
Update the histograms for this canvas.
void SetGroupName(std::string name)
Set name for the 'group'.
virtual void SetUpdateOnlyWhenPlotted(bool whenupdate)
std::string fGroupName
The name for the 'group'.
virtual void SetTabName(std::string name)
Set the name of the top-level tab for these plots, if running DaqDisplay.
virtual bool IsUpdateWhenPlotted()
virtual TCanvasHandleBase * CreateCanvas()
virtual void EndRun(int transition, int run, int time)
Take actions at end run
std::string fChannelName
The name for the 'channel'.
TH1 * GetHistogram(unsigned i)
A helper method for accessing each histogram. Does bounds checking.
void DisableAutoUpdate(bool DisableautoUpdate=true)
const bool GetDisableAutoUpdate()
virtual std::string GetTabName()
Get the name of the top-level tab for these plots, if running DaqDisplay.
virtual void CreateHistograms()
Function to create histograms; users will want to implement this function.
void SetChannelName(std::string name)
Set name for the 'channel'.