THistogramArrayBase.h

Go to the documentation of this file.
00001 #ifndef THistogramArrayBase_h
00002 #define THistogramArrayBase_h
00003 
00004 
00005 #include <iostream>
00006 #include <string>
00007 #include <stdlib.h>
00008 
00009 #include "TDataContainer.hxx"
00010 #include "TH1F.h"
00011 #include <vector>
00012 
00013 /// Base class for user to create an array of histograms.
00014 /// Features of the histogram array
00015 /// i) Histograms are all defined together.
00016 /// ii) Histograms are updated together
00017 /// 
00018 /// Users of this abstract base class should implement a class
00019 /// derived from must THistogramArrayBase that
00020 ///  1) define the histograms that you want in the constructor.
00021 ///  2) implement the UpdateHistograms(TDataContainer&) method.
00022 ///
00023 /// The logic of this histogram array is based on it being 
00024 /// a set of similar histograms; if you use this class for
00025 /// a set of dissimilar histograms (different binning, different quantities)
00026 /// the results will probably be unsatisfactory.
00027 /// The array'ness is actually implemented as a vector of TH1s.
00028 ///
00029 /// The default representation is to have a 1D array of histograms. 
00030 /// But the user can also use the class a 2D array of histograms by specifying the functions
00031 /// 
00032 ///
00033 class THistogramArrayBase : public std::vector<TH1*> {
00034  public:
00035   THistogramArrayBase():fNumberChannelsInGroups(-1),fGroupName(""),fChannelName(""),
00036     fDisableAutoUpdate(false),fHasAutoUpdate(false){}
00037 
00038   virtual ~THistogramArrayBase(){}
00039 
00040   /// Update the histograms for this canvas.
00041   virtual void UpdateHistograms(TDataContainer& dataContainer) = 0;
00042 
00043   /// A helper method for accessing each histogram.  Does bounds checking.
00044   TH1* GetHistogram(unsigned int i){
00045     if(i < 0 || i >= size()){
00046       std::cerr << "Invalid index (=" << i 
00047                 << ") requested in THistogramArrayBase::GetHistogram(int i) " << std::endl;
00048       return 0;
00049     }
00050     return (*this)[i];
00051   }
00052 
00053   /// Take actions at begin run
00054   virtual void BeginRun(int transition,int run,int time){};
00055 
00056   /// Take actions at end run  
00057   virtual void EndRun(int transition,int run,int time){};
00058 
00059   /// Function to define the number of channels in group and 
00060   /// allow user to treat the array as 2D array.
00061   void SetNumberChannelsInGroup(int numberChannelsInGroups){ fNumberChannelsInGroups = numberChannelsInGroups; }
00062   const int  GetNumberChannelsInGroup(){ return fNumberChannelsInGroups; }
00063   
00064   /// Set name for the 'group'.
00065   void SetGroupName(std::string name){  fGroupName = name;  }
00066   const std::string GetGroupName(){ return fGroupName;  }
00067 
00068   /// Set name for the 'channel'.
00069   void SetChannelName(std::string name){  fChannelName = name;  }
00070   const std::string GetChannelName(){ return fChannelName;  }
00071   
00072   /// Define whether the histogram gets automatically updated by rootana display.
00073   /// 'True' means that rootana display will NOT call UpdateHistograms automatically.
00074   void DisableAutoUpdate(bool DisableautoUpdate=true){ fDisableAutoUpdate = DisableautoUpdate; fHasAutoUpdate = true;}  
00075   const bool GetDisableAutoUpdate(){ return fDisableAutoUpdate; }  
00076   const bool HasAutoUpdate(){ return fHasAutoUpdate; }  
00077   
00078 private:
00079 
00080   /// This is the number of channels in a given group.
00081   /// This is mostly used by rootana display, but could 
00082   /// also be used to specify histograms as a 2D array of [group][channel.
00083   int fNumberChannelsInGroups;
00084   
00085   /// The name for the 'group'.
00086   std::string fGroupName;
00087 
00088   /// The name for the 'channel'.
00089   std::string fChannelName;
00090 
00091   /// Defines whether the histogram should be automatically updated 
00092   /// by TRootanaDisplay.
00093   bool fDisableAutoUpdate;
00094   bool fHasAutoUpdate;
00095 
00096 };
00097 
00098 #endif

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1