CMS 3D CMS Logo

PhysVarHisto.h

Go to the documentation of this file.
00001 #ifndef TK_PhysVarHisto_h
00002 #define TK_PhysVarHisto_h 1
00003 
00004 // &&& Design comments:
00005 //     Here's a list of types accepted by ROOT:
00006 //             - C : a character string terminated by the 0 character
00007 //             - B : an 8 bit signed integer (Char_t)
00008 //             - b : an 8 bit unsigned integer (UChar_t)
00009 //             - S : a 16 bit signed integer (Short_t)
00010 //             - s : a 16 bit unsigned integer (UShort_t)
00011 //             - I : a 32 bit signed integer (Int_t)
00012 //             - i : a 32 bit unsigned integer (UInt_t)
00013 //             - F : a 32 bit floating point (Float_t)
00014 //             - D : a 64 bit floating point (Double_t)
00015 //             - L : a 64 bit signed integer (Long64_t)
00016 //             - l : a 64 bit unsigned integer (ULong64_t)
00017 
00018 
00019 // STL include files
00020 #include <string>
00021 #include <vector>
00022 
00023 // ROOT include files
00024 #include <TH1D.h>
00025 #include <TH1F.h>
00026 
00027 // &&& Alert!  Is this a dependence on full framework?
00028 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00029 
00030 namespace pat {
00031 
00032   class PhysVarHisto
00033   {
00034   public:
00035     PhysVarHisto( std::string name,
00036                std::string title,
00037                int         nbins,
00038                double      xlow,
00039                double      xhigh,
00040                TFileDirectory * currDir = 0,
00041                std::string units = "",
00042                std::string type  = "D",
00043                bool        saveHist = true,
00044                bool        saveNtup = false );
00045 
00046     virtual ~PhysVarHisto() { };  
00047 
00048     //--- Make one TH1 (may need more than one); all decorations should be done in this call.
00049     virtual void makeTH1();
00050 
00051     //--- Fill one of the histograms in histos_ vector.
00052     virtual void fill( double x,
00053                        unsigned int imulti = 1,
00054                        double weight = 1.0 );
00055 
00056     //--- Inline accessors.
00057     inline std::string name() { return name_ ; } 
00058     inline std::string type() { return type_ ; } 
00059     inline double value() { return value_ ; }    
00060 
00061     template <class T>
00062       void vec(std::vector<T> & retVec)
00063     {
00064       retVec.resize( valueColl_.size() );
00065       for ( unsigned int i = 0; i < valueColl_.size(); i++ )
00066         retVec[i] = static_cast<T>( valueColl_[i] );
00067     } 
00068 
00069     inline bool   saveHist() { return saveHist_ ; }
00070     inline bool   saveNtup() { return saveNtup_ ; }
00071 
00072     inline void   setSaveHist(bool flag) { saveHist_ = flag; } 
00073     inline void   setSaveNtup(bool flag) { saveNtup_ = flag; } 
00074 
00075     inline void   setTFileDirectory(TFileDirectory * dir) { currDir_ = dir; };
00076 
00077     inline void   clearVec() { valueColl_.clear(); }
00078 
00079   private:
00080     //--- Stuff needed to book one histogram
00081     TFileDirectory * currDir_ ;  
00082     std::string name_ ;   
00083     std::string type_ ;   
00084     std::string title_ ;  
00085     int         nbins_ ;  
00086     double      xlow_ ;   
00087     double      xhigh_ ;  
00088     std::string units_ ;  
00089 
00090     //--- Cache to make histograms
00091     std::vector<TH1D *> histos_ ;   // maybe use a base class TH1* ?
00092     // &&& Should we template all this?
00093 
00094     //--- Internal cache
00095     double      value_ ;        // our own cache
00096     void *      value_ext_ ;    // cache is in a struct elsewhere, for TBranch
00097     std::vector<double> valueColl_; // our own cache of a list of values
00098 
00099     //--- Flags to control behavior
00100     // bool        active_ ;    // no clear use case to have this flag...
00101     bool        saveHist_ ;     // save info into a histogram
00102     bool        saveNtup_ ;     // save info into a ntuple
00103 
00104     int         verboseLevel_ ; // how much verbosity
00105   };
00106 
00107 }
00108 
00109 #endif

Generated on Tue Jun 9 17:41:52 2009 for CMSSW by  doxygen 1.5.4