CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Validation/RecoJets/interface/CompMethods.h

Go to the documentation of this file.
00001 #ifndef CompMethods_h
00002 #define CompMethods_h
00003 
00004 #include <memory>
00005 #include <string>
00006 #include <fstream>
00007 #include <iostream>
00008 #include <cmath>
00009 
00010 #include "Validation/RecoJets/interface/RootSystem.h"
00011 #include "Validation/RecoJets/interface/RootHistograms.h"
00012 
00013 
00014 class MaximalValue {
00015 
00016  public:
00017 
00018   MaximalValue(double val, double err):val_(val), err_(err){};
00019   ~MaximalValue(){};
00020   double value(TH1F& hist){ return hist.GetBinCenter(hist.GetMaximumBin()); };
00021   double valueError(TH1F& hist) { return spread(hist, val_); };
00022   double spread(TH1F& hist) { return spread(hist, 0.5); };
00023   double spreadError(TH1F& hist){ return std::fabs(spread(hist, 0.5-err_)-spread(hist, 0.5+err_))/2; };
00024   
00025  private:
00026 
00027   std::pair<int,int> contour(TH1F&, double&);
00028   double spread(TH1F& hist, double frac){ return std::fabs(hist.GetBinCenter(contour(hist, frac).second)-hist.GetBinCenter(contour(hist, frac).first)); };
00029 
00030  private:
00031 
00032   double val_;
00033   double err_;
00034 };
00035 
00036 // ------------------------------------------------------------------------------------------------------------------
00037 
00038 class Quantile {
00039 
00040  public:
00041 
00042   Quantile(double central, double err):central_(central), err_(err){};
00043   ~Quantile(){};
00044   double value(TH1F& hist){ quantiles(hist, err_); return qnt_[1]; };
00045   double valueError(TH1F& hist) { quantiles(hist, err_); return distance(hist); };
00046   double spread(TH1F& hist) { quantiles(hist, 0.25); return distance(hist); };
00047   double spreadError(TH1F& hist);
00048 
00049  private:
00050   
00051   void evaluate(double& err){val_[0]=central_-err; val_[1]=central_; val_[2]=central_+err;};
00052   void quantiles(TH1F& hist, double err){ evaluate(err); hist.GetQuantiles(3, qnt_, val_); };
00053   double distance(TH1F& hist){ return std::fabs(qnt_[2]-qnt_[0]); };
00054   
00055  private:
00056 
00057   double central_;
00058   double err_;
00059   double val_[3];
00060   double qnt_[3];
00061 };
00062 
00063 // ------------------------------------------------------------------------------------------------------------------
00064 
00065 class HistogramMean {
00066 
00067  public:
00068 
00069   HistogramMean(){};
00070   ~HistogramMean(){};
00071   double value(TH1F& hist){ return hist.GetMean(); };
00072   double valueError(TH1F& hist) { return hist.GetMeanError(); };
00073   double spread(TH1F& hist) { return TMath::Sqrt(hist.GetRMS()); };
00074   double spreadError(TH1F& hist){ return hist.GetRMSError()/TMath::Sqrt(hist.GetRMS()); };
00075 };
00076 
00077 // ------------------------------------------------------------------------------------------------------------------
00078 
00079 class StabilizedGauss {
00080 
00081  public:
00082 
00083   StabilizedGauss(){ func_=new TF1(); };
00084   StabilizedGauss(const char* name):funcName_(name){ func_=new TF1(); };
00085   StabilizedGauss(const char*, int, double, double);
00086   ~StabilizedGauss(){ delete func_;};
00087   void fit(TH1F&);
00088   double value(TH1F& hist){ return value(hist, 1); };
00089   double valueError(TH1F& hist){ return error(hist, 1); };
00090   double spread(TH1F& hist){ return value(hist, 2); };
00091   double spreadError(TH1F& hist){ return error(hist, 2); };
00092 
00093  private:
00094 
00095   double value(TH1F& hist, int target){ return (hist.GetFunction( funcName_) ? hist.GetFunction( funcName_)->GetParameter(target) : 0.); }
00096   double error(TH1F& hist, int target){ return (hist.GetFunction( funcName_) ? hist.GetFunction( funcName_)->GetParError (target) : 0.); }
00097 
00098  private:
00099 
00100   TF1* func_;
00101   double mean_;
00102   double sigma_;
00103   int funcType_;
00104   const char* funcName_;
00105   double lowerBound_;
00106   double upperBound_;
00107 };
00108 
00109 #endif