Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:54

0001 #ifndef Histos_H
0002 #define Histos_H
0003 
0004 /**
0005  * This class provides an interface to root histograms
0006  *
0007  * \author Patrick Janot
0008  * $Date: 16 Jan 2004 19:30 */
0009 // for debugging
0010 
0011 //#include "TROOT.h"
0012 #include "TObject.h"
0013 
0014 #include <string>
0015 #include <map>
0016 #include <iostream>
0017 //#include <sstream>
0018 
0019 class Histos {
0020 public:
0021   typedef std::map<std::string, TObject*>::const_iterator HistoItr;
0022 
0023   static Histos* instance();
0024 
0025   /// Destructor
0026   virtual ~Histos();
0027 
0028   /// Book an histogram (1D or 2D)
0029   void book(const std::string& name, int nx, float xmin, float xmax, int ny = 0, float ymin = 0., float ymax = 0.);
0030 
0031   // Same as before. Creates n2-n1 histos with name name+n1 ... name+n2
0032   void bookByNumber(const std::string& name,
0033                     int n1,
0034                     int n2,
0035                     int nx,
0036                     float xmin,
0037                     float xmax,
0038                     int ny = 0,
0039                     float ymin = 0.,
0040                     float ymax = 0.);
0041 
0042   /// Book a TProfile
0043   /// option="S" -> spread
0044   ///        ""  -> error on mean (from Root documentation)
0045   void book(const std::string& name, int nx, float xmin, float xmax, const std::string& option);
0046 
0047   /// Write one or all histogram(s) in a file
0048   void put(const std::string& file, std::string name = "");
0049 
0050   /// Divide two histograms and put the result in the first
0051   void divide(const std::string& h1, const std::string& h2, const std::string& h3);
0052 
0053   /// Fill an histogram
0054   void fill(const std::string& name, float val1, float val2 = 1., float val3 = 1.);
0055 
0056   // Fill a series of histos. The name is name+number
0057   void fillByNumber(const std::string& name, int number, float val1, float val2 = 1., float val3 = 1.);
0058 
0059   /// Add any object
0060   void addObject(const std::string& name, TObject* obj);
0061 
0062   ///
0063   void debug(std::string p = "") const { std::cout << " Histos myMap : " << &theHistos << " " << p << std::endl; }
0064 
0065 private:
0066   // The constructor is hidden as we do not want to construct
0067   // more than one instance.
0068   Histos();
0069 
0070   // The instance
0071   static Histos* myself;
0072 
0073   // The histos booked
0074   TObject* theHisto;
0075   std::map<std::string, TObject*> theHistos;
0076   std::map<std::string, unsigned> theTypes;
0077   std::map<std::string, TObject*> theObjects;
0078 };
0079 #endif