CMS 3D CMS Logo

Classes | Functions

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/JetMETCorrections/MCJet/bin/Utilities.h File Reference

#include <string>
#include <vector>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include <cmath>
#include <TFile.h>
#include <TH1F.h>
#include <TF1.h>
#include <TStyle.h>
#include <TMath.h>

Go to the source code of this file.

Classes

class  CommandLine

Functions

void CalculateCorrection (bool UseRatioForResponse, double x, double ex, double y, double ey, double &c, double &e)
void CalculateResponse (bool UseRatioForResponse, double x, double ex, double y, double ey, double &r, double &e)
int getBin (double x, std::vector< double > boundaries)
void GetMEAN (TH1F *histo, double &peak, double &error, double &sigma)
void GetMPV (char name[100], TH1F *histo, TDirectory *Dir, double &peak, double &error, double &sigma, double &err_sigma)
bool HistoExists (std::vector< std::string > LIST, std::string hname)
void Invert (TF1 *f, double Min, double Max, double y, double &x)

Function Documentation

void CalculateCorrection ( bool  UseRatioForResponse,
double  x,
double  ex,
double  y,
double  ey,
double &  c,
double &  e 
)

Definition at line 474 of file Utilities.h.

References funct::pow(), mathSSE::sqrt(), and detailsBasic3DVector::y.

Referenced by main().

{
  if (x>0 && fabs(y)>0)
    {
      if (UseRatioForResponse)
        {
          c = 1./y;
          e = ey/(y*y);
        }
      else
        {  
          c = x/(x+y);
          e = (fabs(x*y)/pow(x+y,2))*sqrt(pow(ey/y,2)+pow(ex/x,2)); 
        }
    }
  else
    {
      c = 0;
      e = 0;
    }    
}
void CalculateResponse ( bool  UseRatioForResponse,
double  x,
double  ex,
double  y,
double  ey,
double &  r,
double &  e 
)

Definition at line 452 of file Utilities.h.

References funct::pow(), mathSSE::sqrt(), and detailsBasic3DVector::y.

Referenced by main().

{
  if (x>0 && fabs(y)>0)
    {
      if (UseRatioForResponse)
        {
          r = y;
          e = ey;
        }
      else
        {  
          r = (x+y)/x;
          e = fabs(r-1.)*sqrt(pow(ey/y,2)+pow(ex/x,2)); 
        }
    }
  else
    {
      r = 0;
      e = 0;
    }    
}
int getBin ( double  x,
std::vector< double >  boundaries 
)

Definition at line 512 of file Utilities.h.

References i, and n.

Referenced by main().

{
  int i;
  int n = boundaries.size()-1;
  if (n<=0) return -1;
  if (x<boundaries[0] || x>=boundaries[n])
    return -1;
  for(i=0;i<n;i++)
   {
     if (x>=boundaries[i] && x<boundaries[i+1])
       return i;
   }
  return 0; 
}
void GetMEAN ( TH1F *  histo,
double &  peak,
double &  error,
double &  sigma 
)

Definition at line 435 of file Utilities.h.

References MultiGaussianStateTransform::N.

Referenced by main().

{
  double N = histo->Integral();
  if (N>2)
    {
      peak  = histo->GetMean();
      sigma = histo->GetRMS();
      error = histo->GetMeanError();
    }
  else
    {
      peak = 0;
      sigma = 0;
      error = 0; 
    }  
}
void GetMPV ( char  name[100],
TH1F *  histo,
TDirectory *  Dir,
double &  peak,
double &  error,
double &  sigma,
double &  err_sigma 
)

Definition at line 368 of file Utilities.h.

References a, gather_cfg::cout, g, funct::integral(), gen::k, siStripFEDMonitor_P5_cff::Max, plotscripts::mean(), siStripFEDMonitor_P5_cff::Min, lumiNorm::norm, and plotscripts::rms().

Referenced by main().

{
  double norm,mean,rms,integral,lowlimit,highlimit,LowResponse,HighResponse,a;
  int k;
  LowResponse = histo->GetXaxis()->GetXmin();
  HighResponse = histo->GetXaxis()->GetXmax();
  Dir->cd();
  TF1 *g;
  TStyle *myStyle = new TStyle("mystyle","mystyle");
  myStyle->Reset();
  myStyle->SetOptFit(1111);
  myStyle->SetOptStat(2200);
  myStyle->SetStatColor(0);
  myStyle->SetTitleFillColor(0);
  myStyle->cd(); 
  integral = histo->Integral();
  mean = histo->GetMean();
  rms = histo->GetRMS();
  a = 1.5;
  if (integral>0)
    { 
      lowlimit = TMath::Max(LowResponse,mean-a*rms);
      highlimit= TMath::Min(mean+a*rms,HighResponse); 
      norm = histo->GetMaximumStored();
      peak = mean;
      sigma = rms;
      for (k=0; k<3; k++)
       {
         g = new TF1("g","gaus",lowlimit, highlimit);
         g->SetParNames("N","#mu","#sigma");
         g->SetParameter(0,norm);
         g->SetParameter(1,peak);
         g->SetParameter(2,sigma);
         lowlimit = TMath::Max(LowResponse,peak-a*sigma);
         highlimit= TMath::Min(peak+a*sigma,HighResponse);  
         g->SetRange(lowlimit,highlimit);
         histo->Fit(g,"RQ");
         norm = g->GetParameter(0);
         peak = g->GetParameter(1);
         sigma = g->GetParameter(2);  
       }
      if (g->GetNDF()>5)
        {
          peak = g->GetParameter(1);
          sigma = g->GetParameter(2);
          error = g->GetParError(1);
          err_sigma = g->GetParError(2);
        }
      else
        {
          std::cout<<"FIT FAILURE: histogram "<<name<<"...Using MEAN and RMS."<<std::endl;
          peak = mean;
          sigma = rms;
          error = histo->GetMeanError();
          err_sigma = histo->GetRMSError();
        }
    }
  else
    {
      peak = 0;
      sigma = 0;
      error = 0;
      err_sigma = 0;
    }
  histo->Write();
}
bool HistoExists ( std::vector< std::string >  LIST,
std::string  hname 
)

Definition at line 496 of file Utilities.h.

References gather_cfg::cout, newFWLiteAna::found, i, and MultiGaussianStateTransform::N.

Referenced by main().

{
  unsigned int i,N;
  bool found(false);
  N = LIST.size();
  if (N==0)
    std::cout<<"WARNING: empty file histogram list!!!!"<<std::endl;
  else
    for(i=0;i<N;i++)
     if (hname==LIST[i])
       found = true;
  if (!found)
    std::cout<<"Histogram: "<<hname<<" NOT FOUND!!! Check list of existing objects."<<std::endl;
  return found;
}
void Invert ( TF1 *  f,
double  Min,
double  Max,
double  y,
double &  x 
)