CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Validation/RecoJets/interface/CompHist.h

Go to the documentation of this file.
00001 #ifndef CompHist_h
00002 #define CompHist_h
00003 
00004 #include <memory>
00005 #include <string>
00006 #include <vector>
00007 #include <sstream>
00008 #include <fstream>
00009 #include <iostream>
00010 
00011 #include "Validation/RecoJets/interface/ConfigFile.h"
00012 #include "Validation/RecoJets/interface/RootSystem.h"
00013 #include "Validation/RecoJets/interface/RootHistograms.h"
00014 
00015 
00016 namespace HistStyle{
00017   static const int Line   = 0;
00018   static const int Marker = 1;
00019   static const int Filled = 2; 
00020 }
00021 
00022 template <class T> 
00023 void readVector(std::string s, std::vector<T>& vec)
00024 {
00025   std::stringstream stream( s );
00026   T buffer;
00027   while (!stream.eof()) {
00028     stream >> buffer;
00029     if(!stream.str().empty()){
00030       vec.push_back( buffer );
00031     }
00032   }
00033 }
00034 
00035 class CompHist{
00036 
00037  public:
00038 
00039   enum RootOutput{ kFirstOnly, kLastOnly, kAll};
00040   enum HistFilter{ kBeginsWith, kEndsWith, kContains};
00041 
00042  public:
00043 
00044   CompHist():verbose_(false){};
00045   CompHist(bool verbose):verbose_(verbose){};
00046   //~CompHist(){ file_->Close(); };
00047   virtual ~CompHist(){};
00048   virtual void readConfig( std::string )=0;
00049 
00050   std::string writeAs(){return writeAs_;}
00051   void setVerbose(bool val) {verbose_=val; return;}
00052   bool verbose() {return verbose_;}
00053   void loadHistograms(std::vector<std::string>&, std::vector<TObjArray>&);
00054   void loadHistograms();
00055   void drawPs();
00056   void drawEps();
00057   void draw(TCanvas&, TLegend&, int&, int&);
00058   bool histFilter(TString&, std::vector<std::string>&);
00059   bool histFilter(TString&, std::vector<std::string>&, CompHist::HistFilter);
00060   void writeOutput(CompHist::RootOutput);
00061   void writeOutput(){writeOutput(kAll);};
00062 
00063  protected:
00064 
00065   // io helpers
00066   void configBlockIO(ConfigFile&);
00067   void configBlockHist(ConfigFile&);
00068   void readLabels(std::string, std::vector<std::string>&);
00069   bool isOutputRequested(){return rootOutDir_.size()>1;};
00070   void readHistogramList();
00071 
00072   // save way to get members
00073   std::string legend(int);
00074 
00075   // histogram manipulators
00076   void setLegendStyle(TLegend&);
00077   void setCanvasStyle(TCanvas&);
00078   void setCanvLog(TCanvas&, int);
00079   void setCanvGrid(TCanvas&, int);
00080   void setAxesStyle(TH1&, const char*, const char*);
00081   void setHistStyles(TH1F&, int, int);
00082   void setHistLabels(TH1F&, int);
00083   void setHistScale(TH1F&, int);
00084   void setHistMax(TH1F&, int);
00085   void setHistMin(TH1F&, int);
00086   void setLineWidth (TH1F&, int);
00087   void setLineStyle(TH1F&, int);
00088   void setLineColor(TH1F&, int);
00089   void setFillStyle(TH1F&, int);
00090   void setFillColor(TH1F&, int);
00091   void setMarkerStyle(TH1F&, int);
00092   void setMarkerColor(TH1F&, int);
00093   void setMarkerSize(TH1F&, int);
00094   double findMaximum(int);
00095 
00096  protected:
00097 
00098   //---------------------------------------------
00099   // Interface
00100   //---------------------------------------------
00101 
00102   // define input/output
00103   std::string filterOpt_;                    // filter option for different filtering types
00104   std::string histFile_;                     // name of .hist file
00105   std::vector<std::string> dirNameList_;     // list of directory names in .root file(s)
00106   std::vector<std::string> fileNameList_;    // list of .root files
00107   std::vector<std::string> plotFilterList_;  // list of filter patterns for histograms to be ploted
00108   std::vector<std::string> histFilterList_;  // list of filter patterns for histograms to be loaded
00109   std::string output_;                       // potential root output
00110   std::string rootOutDir_;                   // root directory for potential root output
00111   std::string writeTo_, writeAs_;            // type (ps/eps) and directory of output
00112   std::vector<std::string> outputLabelList_; // list of .root files
00113 
00114   // define histogram design
00115   std::vector<short int> gridX_, gridY_;     // grid in x/y to be set?
00116   std::vector<short int> logX_,  logY_;      // log  in x/y to be set? 
00117   std::vector<short int> histStyle_;         // line, marker, filled?
00118   std::vector<short int> histColor_;         // line/fill color?
00119   std::vector<short int> commonStyle_;       // fill or line style
00120   std::vector<short int> commonWidth_;       // line width 
00121   std::vector<short int> markerStyle_;       // marker style
00122   std::vector<double> markerSize_;           // marker size
00123   std::vector<std::string> xAxes_, yAxes_;   // x/y axes labels
00124   std::vector<double> min_, max_;            // min/max of histogram (to be set by hand)
00125   std::vector<double> scale_;                // scale if wanted
00126   std::vector<short int> errors_;            // show histogram with errors?
00127 
00128   // define legend design
00129   double legXLeft_,  legXRight_;             // legend boundaries (common to all histograms)
00130   double legYLower_, legYUpper_;             // legend boundaries (common to all histograms)
00131   std::vector<std::string> legendEntries_;   // list of legend entries
00132 
00133   //---------------------------------------------
00134   // Internals
00135   //---------------------------------------------
00136   bool verbose_;
00137   std::vector<TFile*> fileList_;
00138   std::vector<TObjArray> sampleList_;
00139   std::vector<std::string> histList_;
00140 };
00141 #endif