Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:13

0001 #ifndef __Validation_RecoParticleFlow_Comparator__
0002 #define __Validation_RecoParticleFlow_Comparator__
0003 
0004 #include <cmath>
0005 
0006 #include <TF1.h>
0007 #include <TFile.h>
0008 #include <TH1.h>
0009 #include <TLegend.h>
0010 
0011 /* #include <string> */
0012 
0013 class Style;
0014 
0015 class Comparator {
0016 public:
0017   enum Mode { NORMAL, SCALE, RATIO, GRAPH, EFF };
0018 
0019   Comparator() : rebin_(-1), xMin_(0), xMax_(0), resetAxis_(false), s0_(nullptr), s1_(nullptr), legend_(0, 0, 1, 1) {}
0020 
0021   Comparator(const char *file0, const char *dir0, const char *file1, const char *dir1)
0022       : rebin_(-1), xMin_(0), xMax_(0), resetAxis_(false), s0_(nullptr), s1_(nullptr), legend_(0, 0, 1, 1) {
0023     SetDirs(file0, dir0, file1, dir1);
0024   }
0025 
0026   /// set the 2 files, and the directory within each file, in which the
0027   /// histograms will be compared
0028   void SetDirs(const char *file0, const char *dir0, const char *file1, const char *dir1);
0029 
0030   // set the rebinning factor and the range
0031   void SetAxis(int rebin, float xmin, float xmax) {
0032     rebin_ = rebin;
0033     xMin_ = xmin;
0034     xMax_ = xmax;
0035     resetAxis_ = true;
0036   }
0037 
0038   // set the rebinning factor, unset the range
0039   void SetAxis(int rebin) {
0040     rebin_ = rebin;
0041     resetAxis_ = false;
0042   }
0043 
0044   // draws a Y projection of a slice along X
0045   void DrawSlice(const char *key, int binxmin, int binxmax, Mode mode);
0046 
0047   void DrawMeanSlice(const char *key, const int rebinFactor, Mode mode);
0048   void DrawSigmaSlice(const char *key, const int rebinFactor, Mode mode);
0049   void DrawGaussSigmaSlice(const char *key, const int rebinFactor, Mode mode);
0050   void DrawGaussSigmaSlice(
0051       const char *key, const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning, Mode mode);
0052   void DrawGaussSigmaOverMeanXSlice(
0053       const char *key, const int rebinFactor, const int binxmin, const int binxmax, const bool cst_binning, Mode mode);
0054   void DrawGaussSigmaOverMeanSlice(const char *key, const char *key2, const int rebinFactor, Mode mode);
0055 
0056   void Draw(const char *key, Mode mode);
0057 
0058   void Draw(const char *key0, const char *key1, Mode mode);
0059 
0060   // return the two temporary 1d histograms, that have just
0061   // been plotted
0062   TH1 *h0() { return h0_; }
0063   TH1 *h1() { return h1_; }
0064 
0065   TLegend &Legend() { return legend_; }
0066   const TLegend &Legend() const { return legend_; }
0067 
0068   // set the styles for further plots
0069   void SetStyles(Style *s0, Style *s1, const char *leg0, const char *leg1);
0070 
0071   TH1 *Histo(const char *key, unsigned dirIndex);
0072 
0073   TDirectory *dir0() { return dir0_; }
0074   TDirectory *dir1() { return dir1_; }
0075 
0076 private:
0077   // retrieve an histogram in one of the two directories
0078 
0079   // draw 2 1D histograms.
0080   // the histograms can be normalized to the same number of entries,
0081   // or plotted as a ratio.
0082   void Draw(TH1 *h0, TH1 *h1, Mode mode);
0083 
0084   int rebin_;
0085   float xMin_;
0086   float xMax_;
0087   bool resetAxis_;
0088 
0089   TFile *file0_;
0090   TDirectory *dir0_;
0091   TFile *file1_;
0092   TDirectory *dir1_;
0093 
0094   TH1 *h0_;
0095   TH1 *h1_;
0096 
0097   Style *s0_;
0098   Style *s1_;
0099 
0100   TLegend legend_;
0101 };
0102 
0103 #endif