ra4_macros  bede988c286599a3a84b77a4d788ac0a971e89f9
utilities_macros_rohan.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_ROHAN
6 #define H_UTILITIES_MACROS_ROHAN
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 
44 struct pfeats{
45  pfeats(const std::vector<int> &isamples, const TString &icut = "1", const TString &itagname="");
46 
47  std::vector<int> samples;
48  TString cut, tagname;
49 };
50 
51 class hfeats {
52 public:
53  hfeats(TString ivarname, int inbins, float iminx, float imaxx, std::vector<int> isamples,
54  TString ititle="", TString icuts="1", float icut=-1, TString itagname="",bool iskiplog=false,
55  std::vector<double> inevents= std::vector<double>(1,-1.));
56  hfeats(TString ivarname, int inbins, float* ibinning, std::vector<int> isamples,
57  TString ititle="", TString icuts="1", float icut=-1, TString itagname="",bool iskiplog=false,
58  std::vector<double> inevents= std::vector<double>(1,-1.));
59  hfeats(TString ivarnamex, TString ivarnamey, int inbinsx, float iminx, float imaxx, int inbinsy, float iminy, float imaxy, std::vector<int> isamples,
60  TString ititlex, TString ititley, TString icuts, float icutx, float icuty, TString itagname);
61  TString title, titlex, titley, varname, varnamex, varnamey, tag, cuts, unit;
62  int nbins, nbinsx, nbinsy;
63  float *binning;
64  float minx, maxx, miny, maxy, cut, cutx, cuty, maxYaxis, maxRatio, hline;
65  std::vector<int> samples;
66  TString tagname;
67  void format_tag();
68  std::vector<double> nevents; //Added for track veto study. Useful to display number of events when hist is filled N times per event
69  bool skiplog;
70  TString whichPlots; // String that determines which of the [log_]lumi and [log_]shapes plots to make
71  bool normalize; //normalizes isData to sum of histograms
72  bool PU_reweight;
73 
74 };
75 
76 class sfeats {
77 public:
78  sfeats(std::vector<TString> ifile, TString ilabel, int icolor=1, int istyle=1, TString icut="1",
79  TString samVariable="noPlot");
80  std::vector<TString> file;
81  TString label, cut, factor,tag;
82  int color, style;
83  bool isSig, doStack, isData, mcerr;
84  TString samVariable; // Used to plot different variables in the same histogram
85 };
86 
87 class sysfeats {
88 public:
89  sysfeats(TString iname, TString ititle);
90  TString name;
91  TString title;
92  std::vector<TString> bincuts;
93  std::vector<double> weights;
94  void push_back(TString bincut, double weight);
95  TString bincut(unsigned i);
96  double weight(unsigned i);
97  unsigned size();
98 };
99 
100 
101 void calc_chi2_diff(TH1D *histo1, TH1D *histo2, float &chi2, int &ndof, float &pvalue, float *average);
102 void calc_chi2(TH1D *histo, float &chi2, int &ndof, float &pvalue, float &average);
103 void dump_event(small_tree_full &tree, int entry);
104 long getYieldErr(TChain& tree, TString cut, double& yield, double& uncertainty);
105 
106 void plot_distributions(std::vector<sfeats> Samples, std::vector<hfeats> vars, TString luminosity="10",
107  TString filetype=".eps", TString namestyle="LargeLabels", TString dir = "1d", bool doRatio=false);
108 void plot_2D_distributions(std::vector<sfeats> Samples, std::vector<hfeats> vars, TString luminosity,
109  TString filetype, TString namestyle, TString dir);
110 TString cuts2title(TString title);
111 TString invertcut(TString cut);
112 TString format_tag(TString tag);
113 double gsl_ran_gamma (const double a, const double b, TRandom3 &rand);
114 double intGaus(double mean, double sigma, double minX, double maxX);
115 // yields[Nobs][Nsam] has the entries for each sample for each observable going into kappa
116 // weights[Nobs][Nsam] has the average weight of each observable for each sample
117 // powers[Nobs] defines kappa = Product_obs{ Sum_sam{yields[sam][obs]*weights[sam][obs]}^powers[obs] }
118 double calcKappa(std::vector<std::vector<float> > &entries, std::vector<std::vector<float> > &weights,
119  std::vector<float> &powers, float &mSigma, float &pSigma, bool do_data=false,
120  bool verbose=false, bool do_plot=false, int nrep=100000);
121 float Efficiency(float den, float num, float &errup, float &errdown);
122 
123 #endif
TString invertcut(TString cut)
TString luminosity
void calc_chi2(TH1D *histo, float &chi2, int &ndof, float &pvalue, float &average)
double gsl_ran_gamma(const double a, const double b, TRandom3 &rand)
void dump_event(small_tree_full &tree, int entry)
long getYieldErr(TChain &tree, TString cut, double &yield, double &uncertainty)
tuple file
Definition: parse_card.py:238
TString format_tag(TString tag)
TString cuts2title(TString title)
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)
float Efficiency(float den, float num, float &errup, float &errdown)
double intGaus(double mean, double sigma, double minX, double maxX)
void plot_2D_distributions(std::vector< sfeats > Samples, std::vector< hfeats > vars, TString luminosity, TString filetype, TString namestyle, TString dir)
void calc_chi2_diff(TH1D *histo1, TH1D *histo2, float &chi2, int &ndof, float &pvalue, float *average)
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)