ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
utilities_macros.hpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // utilities_macros - Various functions used accross the code
3 //----------------------------------------------------------------------------
4 
5 #ifndef H_UTILITIES_MACROS
6 #define H_UTILITIES_MACROS
7 
8 #include <vector>
9 
10 #include "TString.h"
11 #include "TH1D.h"
12 #include "TRandom3.h"
13 #include "TChain.h"
14 #include "small_tree_full.hpp"
15 
16 namespace ra4{
17  // Had to define the TColor objects in the cpp
18  enum {
19  c_t1tttt = 2,
20  c_tt_1l = 2000, // ucsb_blue
21  c_tt_2l = 2006, // tar_heel_blue
22  c_wjets = 2001, // ucsb_gold
23  c_singlet = kGreen+3,
24  c_ttv = 2002, // penn_red
25  c_other = kBlue+4
26  };
27 
28 }
29 
30 namespace dps{
31  // Had to define the TColor objects in the cpp
32  enum {
33  c_tt_1l = 2012, // ucsb_blue
34  c_tt_2l = 2011, // tar_heel_blue
35  c_wjets = 2018, // ucsb_gold
36  c_singlet = 2015,
37  c_qcd = 2020,
38  c_other = 2019
39  };
40 
41 }
42 
43 struct pfeats{
44  pfeats(const std::vector<int> &isamples, const TString &icut = "1", const TString &itagname="");
45 
46  std::vector<int> samples;
47  TString cut, tagname;
48 };
49 
50 class hfeats {
51 public:
52  hfeats(TString ivarname, int inbins, float iminx, float imaxx, std::vector<int> isamples,
53  TString ititle="", TString icuts="1", float icut=-1, TString itagname="",bool iskiplog=false,
54  std::vector<double> inevents= std::vector<double>(1,-1.));
55  hfeats(TString ivarname, int inbins, float* ibinning, std::vector<int> isamples,
56  TString ititle="", TString icuts="1", float icut=-1, TString itagname="",bool iskiplog=false,
57  std::vector<double> inevents= std::vector<double>(1,-1.));
58  hfeats(TString ivarnamex, TString ivarnamey, int inbinsx, float iminx, float imaxx, int inbinsy, float iminy, float imaxy, std::vector<int> isamples,
59  TString ititlex, TString ititley, TString icuts, float icutx, float icuty, TString itagname);
60  TString title, titlex, titley, varname, varnamex, varnamey, tag, cuts, unit;
61  int nbins, nbinsx, nbinsy;
62  float *binning;
63  float minx, maxx, miny, maxy, cut, cutx, cuty, maxYaxis, maxRatio;
64  std::vector<int> samples;
65  TString tagname;
66  void format_tag();
67  std::vector<double> nevents; //Added for track veto study. Useful to display number of events when hist is filled N times per event
68  bool skiplog;
69  TString whichPlots; // String that determines which of the [log_]lumi and [log_]shapes plots to make
70  bool normalize; //normalizes isData to sum of histograms
71  bool PU_reweight;
72  float moveRLegend; // Moves the right legend by this amount
73  bool addOverflow; // If true, the overflow is added to the last bin
74 
75 };
76 
77 class sfeats {
78 public:
79  sfeats(std::vector<TString> ifile, TString ilabel, int icolor=1, int istyle=1, TString icut="1",
80  TString samVariable="noPlot");
81  std::vector<TString> file;
82  TString label, cut, factor,tag;
83  int color, style;
84  bool isSig, doStack, isData, mcerr, doBand;
85  TString samVariable; // Used to plot different variables in the same histogram
86 };
87 
88 class sysfeats {
89 public:
90  sysfeats(TString iname, TString ititle);
91  TString name;
92  TString title;
93  std::vector<TString> bincuts;
94  std::vector<double> weights;
95  void push_back(TString bincut, double weight);
96  TString bincut(unsigned i);
97  double weight(unsigned i);
98  unsigned size();
99 };
100 
101 
102 void calc_chi2_diff(TH1D *histo1, TH1D *histo2, float &chi2, int &ndof, float &pvalue, float *average);
103 void calc_chi2(TH1D *histo, float &chi2, int &ndof, float &pvalue, float &average);
104 void dump_event(small_tree_full &tree, int entry);
105 long getYieldErr(TChain& tree, TString cut, double& yield, double& uncertainty);
106 
107 void plot_distributions(std::vector<sfeats> Samples, std::vector<hfeats> vars, TString luminosity="10",
108  TString filetype=".eps", TString namestyle="LargeLabels", TString dir = "1d",
109  bool doRatio=false, bool showcuts=false);
110 void plot_2D_distributions(std::vector<sfeats> Samples, std::vector<hfeats> vars, TString luminosity,
111  TString filetype, TString namestyle, TString dir);
112 TString cuts2title(TString title);
113 TString invertcut(TString cut);
114 TString format_tag(TString tag);
115 double gsl_ran_gamma (const double a, const double b, TRandom3 &rand);
116 double intGaus(double mean, double sigma, double minX, double maxX);
117 // yields[Nobs][Nsam] has the entries for each sample for each observable going into kappa
118 // weights[Nobs][Nsam] has the average weight of each observable for each sample
119 // powers[Nobs] defines kappa = Product_obs{ Sum_sam{yields[sam][obs]*weights[sam][obs]}^powers[obs] }
120 double calcKappa(std::vector<std::vector<float> > &entries, std::vector<std::vector<float> > &weights,
121  std::vector<float> &powers, float &mSigma, float &pSigma, bool do_data=false,
122  bool verbose=false, bool do_plot=false, int nrep=100000);
123 float Efficiency(float den, float num, float &errup, float &errdown);
124 
125 #endif
void plot_distributions(std::vector< sfeats > Samples, std::vector< hfeats > vars, TString luminosity="10", TString filetype=".eps", TString namestyle="LargeLabels", TString dir="1d", bool doRatio=false, bool showcuts=false)
std::vector< double > weights
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
TString luminosity
std::vector< double > nevents
TString tagname
void dump_event(small_tree_full &tree, int entry)
TString cuts2title(TString title)
TString tagname
float * binning
float moveRLegend
TString whichPlots
double intGaus(double mean, double sigma, double minX, double maxX)
bool PU_reweight
TString format_tag(TString tag)
std::vector< int > samples
std::vector< TString > file
bool addOverflow
std::vector< int > samples
void calc_chi2(TH1D *histo, float &chi2, int &ndof, float &pvalue, float &average)
std::vector< TString > bincuts
float Efficiency(float den, float num, float &errup, float &errdown)
TString samVariable
void calc_chi2_diff(TH1D *histo1, TH1D *histo2, float &chi2, int &ndof, float &pvalue, float *average)
TString varnamey
TString tag
double calcKappa(std::vector< std::vector< float > > &entries, std::vector< std::vector< float > > &weights, std::vector< float > &powers, float &mSigma, float &pSigma, bool do_data=false, bool verbose=false, bool do_plot=false, int nrep=100000)
TString invertcut(TString cut)
void plot_2D_distributions(std::vector< sfeats > Samples, std::vector< hfeats > vars, TString luminosity, TString filetype, TString namestyle, TString dir)
double gsl_ran_gamma(const double a, const double b, TRandom3 &rand)