ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
test.cxx
Go to the documentation of this file.
1 #include "core/test.hpp"
2 
3 #include <cstdlib>
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <memory>
8 
9 #include <unistd.h>
10 #include <getopt.h>
11 
12 #include "TError.h"
13 #include "TColor.h"
14 
15 #include "core/baby.hpp"
16 #include "core/process.hpp"
17 #include "core/named_func.hpp"
18 #include "core/plot_maker.hpp"
19 #include "core/plot_opt.hpp"
20 #include "core/palette.hpp"
21 #include "core/table.hpp"
22 #include "core/event_scan.hpp"
23 #include "core/hist1d.hpp"
24 #include "core/hist2d.hpp"
25 #include "core/utilities.hpp"
26 
27 using namespace std;
28 using namespace PlotOptTypes;
29 
30 namespace{
31  bool single_thread = false;
32 }
33 
34 int main(int argc, char *argv[]){
35  gErrorIgnoreLevel = 6000;
36  GetOptions(argc, argv);
37 
38  double lumi = 12.9;
39 
40  string base_path = "";
41  string hostname = execute("echo $HOSTNAME");
42  if(Contains(hostname, "cms") || Contains(hostname,"compute-")){
43  base_path = "/net/cms2";
44  }
45  string mc_dir = base_path+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_stdnj5/";
46 
47  Palette colors("txt/colors.txt", "default");
48 
49  auto tt1l = Process::MakeShared<Baby_full>("t#bar{t} (1l)", Process::Type::background, colors("tt_1l"),
50  {mc_dir+"*_TTJets*Lept*.root", mc_dir+"*_TTJets_HT*.root"},
51  "ntruleps<=1&&stitch");
52  tt1l->SetMarkerStyle(23);
53  tt1l->SetMarkerSize(0.8);
54  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t} (2l)", Process::Type::background, colors("tt_2l"),
55  {mc_dir+"*_TTJets*Lept*.root", mc_dir+"*_TTJets_HT*.root"},
56  "ntruleps>=2&&stitch");
57  tt1l->SetMarkerStyle(22);
58  tt1l->SetMarkerSize(0.8);
59  auto wjets = Process::MakeShared<Baby_full>("W+jets", Process::Type::background, colors("wjets"),
60  {mc_dir+"*_WJetsToLNu*.root"});
61  auto single_t = Process::MakeShared<Baby_full>("Single t", Process::Type::background, colors("single_t"),
62  {mc_dir+"*_ST_*.root"});
63  auto ttv = Process::MakeShared<Baby_full>("t#bar{t}V", Process::Type::background, colors("ttv"),
64  {mc_dir+"*_TTWJets*.root", mc_dir+"*_TTZTo*.root"});
65  auto other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
66  {mc_dir+"*DYJetsToLL*.root", mc_dir+"*_QCD_HT*.root",
67  mc_dir+"*_ZJet*.root", mc_dir+"*_WWTo*.root",
68  mc_dir+"*ggZH_HToBB*.root", mc_dir+"*ttHJetTobb*.root",
69  mc_dir+"*_TTGJets*.root", mc_dir+"*_TTTT_*.root",
70  mc_dir+"*_WH_HToBB*.root", mc_dir+"*_WZTo*.root",
71  mc_dir+"*_ZH_HToBB*.root", mc_dir+"*_ZZ_*.root"});
72 
73  auto t1tttt_nc = Process::MakeShared<Baby_full>("T1tttt(1500,100)", Process::Type::signal, colors("t1tttt"),
74  {mc_dir+"*SMS-T1tttt_mGluino-1500_mLSP-100*.root"});
75  t1tttt_nc->SetMarkerStyle(21);
76  t1tttt_nc->SetMarkerSize(0.9);
77  auto t1tttt_c = Process::MakeShared<Baby_full>("T1tttt(1200,800)", Process::Type::signal, colors("t1tttt"),
78  {mc_dir+"*SMS-T1tttt_mGluino-1200_mLSP-800*.root"});
79  t1tttt_c->SetLineStyle(2);
80  t1tttt_c->SetMarkerStyle(21);
81  t1tttt_c->SetMarkerSize(0.9);
82 
83  auto data = Process::MakeShared<Baby_full>("Data", Process::Type::data, kBlack,
84  {base_path+"/cms2r0/babymaker/babies/2016_08_10/data/merged_database_stdnj5/*.root"},"pass&&trig_ra4&&json12p9");
85  data->SetMarkerStyle(20);
86  data->SetMarkerSize(1.);
87 
88  vector<shared_ptr<Process> > full_trig_skim = {data, t1tttt_nc, t1tttt_c, tt1l, tt2l, wjets, single_t, ttv, other};
89 
90  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
91  log_lumi.Title(TitleType::preliminary)
92  .Bottom(BottomType::ratio)
93  .YAxis(YAxisType::log)
94  .Stack(StackType::data_norm);
95  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
96  PlotOpt log_shapes = log_lumi().Stack(StackType::shapes)
97  .ShowBackgroundError(false);
98  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
99  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
100  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
101  PlotOpt log_shapes_info = log_shapes().Title(TitleType::info);
102  PlotOpt lin_shapes_info = lin_shapes().Title(TitleType::info);
103  vector<PlotOpt> all_plot_types = {log_lumi, lin_lumi, log_shapes, lin_shapes,
104  log_lumi_info, lin_lumi_info, log_shapes_info, lin_shapes_info};
105  PlotOpt style2D("txt/plot_styles.txt", "Scatter");
106  vector<PlotOpt> bkg_hist = {style2D().Stack(StackType::data_norm).Title(TitleType::preliminary)};
107  vector<PlotOpt> bkg_pts = {style2D().Stack(StackType::lumi_shapes).Title(TitleType::info)};
108 
109  PlotMaker pm;
110  pm.Push<Hist1D>(Axis(7, -0.5, 6.5, "nleps", "Num. Leptons", {0.5, 1.5}),
111  "st>500&&met>200&&njets>=6&&nbm>=1", full_trig_skim, all_plot_types);
112  pm.Push<Hist1D>(Axis(40, 0, 2000., "st", "S_{T} [GeV]", {500.}),
113  "nleps==1&&met>200&&njets>=6&&nbm>=1", full_trig_skim, all_plot_types);
114  pm.Push<Hist1D>(Axis(40, 0, 1000., "met", "MET [GeV]", {200., 400.}),
115  "nleps==1&&st>500&&njets>=6&&nbm>=1", full_trig_skim, all_plot_types);
116  pm.Push<Hist1D>(Axis(16, -0.5, 15.5, "njets", "Num. AK4 Jets", {5.5, 8.5}),
117  "nleps==1&&st>500&&met>200&&nbm>=1", full_trig_skim, all_plot_types);
118  pm.Push<Hist1D>(Axis(11, -0.5, 10.5, "nbm", "Num. b-Tagged Jets", {0.5, 1.5, 2.5}),
119  "nleps==1&&st>500&&met>200&&njets>=6", full_trig_skim, all_plot_types);
120  pm.Push<Hist1D>(Axis(24, 0., 1200., "mj14", "M_{J} [GeV]", {250., 400.}),
121  "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1", full_trig_skim, all_plot_types);
122  pm.Push<Hist1D>(Axis(12, 0., 420., "mt", "m_{T} [GeV]", {140.}),
123  "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1", full_trig_skim, all_plot_types);
124  pm.Push<Hist1D>(Axis(15, 0., 1500., "mj14", "M_{J} [GeV]", {400.}),
125  "nleps==1&&st>500&&met>200", full_trig_skim, all_plot_types)
126  .Tag("changing_tags_and_weights").Weight("1.2345*weight").RatioTitle("Numerator","Denominator");
127  Table & cutflow = pm.Push<Table>("cutflow", vector<TableRow>{
128  TableRow("Baseline"),
129  TableRow("No Selection", "1"),
130  TableRow("$1\\ell$, $H_{T}>500$, $E_{\\text{T}}^{\\text{miss}}>200$", "nleps==1&&st>500&&met>200"),
131  TableRow("$N_{\\text{jets}}\\geq6$", "nleps==1&&st>500&&met>200&&njets>=6"),
132  TableRow("$N_{b}\\geq1$", "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1"),
133  TableRow("$M_{J}>250$", "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1&&mj14>250", 1, 0),
134  TableRow("ABCD Signal Region"),
135  TableRow("$m_{T}>140$", "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1&&mj14>250&&mt>140"),
136  TableRow("$M_{J}>400$", "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1&&mj14>400&&mt>140"),
137  TableRow("Binning"),
138  TableRow("$E_{\\text{T}}^{\\text{miss}}>500$", "nleps==1&&st>500&&met>500&&njets>=6&&nbm>=1&&mj14>400&&mt>140"),
139  TableRow("$N_{\\text{jets}}\\geq9$", "nleps==1&&st>500&&met>500&&njets>=9&&nbm>=1&&mj14>400&&mt>140"),
140  TableRow("$N_{b}\\geq3$", "nleps==1&&st>500&&met>500&&njets>=9&&nbm>=3&&mj14>400&&mt>140")
141  }, full_trig_skim);
142  pm.Push<EventScan>("scan", true, vector<NamedFunc>{"weight", "met"}, vector<shared_ptr<Process> >{tt1l});
143  pm.Push<Hist2D>(Axis(48, 0., 1200., "mj14", "M_{J} [GeV]", {250., 400.}),
144  Axis(25, 0., 700., "mt", "m_{T} [GeV]", {140.}),
145  "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1",
146  full_trig_skim, bkg_hist);
147  pm.Push<Hist2D>(Axis(48, 0., 1200., "mj14", "M_{J} [GeV]", {250., 400.}),
148  Axis(25, 0., 700., "mt", "m_{T} [GeV]", {140.}),
149  "nleps==1&&st>500&&met>200&&njets>=6&&nbm>=1",
150  vector<shared_ptr<Process> >{tt1l, tt2l, t1tttt_nc}, bkg_pts);
151 
152  if(single_thread) pm.multithreaded_ = false;
153  pm.MakePlots(lumi);
154 
155  vector<GammaParams> yields = cutflow.BackgroundYield(lumi);
156  for(const auto &yield: yields){
157  cout << yield << endl;
158  }
159 }
160 
161 void GetOptions(int argc, char *argv[]){
162  while(true){
163  static struct option long_options[] = {
164  {"single_thread", no_argument, 0, 's'},
165  {0, 0, 0, 0}
166  };
167 
168  char opt = -1;
169  int option_index;
170  opt = getopt_long(argc, argv, "s", long_options, &option_index);
171 
172  if( opt == -1) break;
173 
174  string optname;
175  switch(opt){
176  case 's':
177  single_thread = true;
178  break;
179  case 0:
180  optname = long_options[option_index].name;
181  if(false){
182  }else{
183  printf("Bad option! Found option name %s\n", optname.c_str());
184  }
185  break;
186  default:
187  printf("Bad option! getopt_long returned character code 0%o\n", opt);
188  break;
189  }
190  }
191 }
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
Hist1D & Weight(const NamedFunc &weight)
Definition: hist1d.cpp:507
STL namespace.
bool Contains(const std::string &str, const std::string &pat)
Definition: utilities.cpp:44
bool multithreaded_
Definition: plot_maker.hpp:43
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
Hist1D & RatioTitle(const std::string &numerator, const std::string &denominator)
Definition: hist1d.cpp:517
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
std::vector< GammaParams > BackgroundYield(double luminosity) const
Definition: table.cpp:175
Definition: axis.hpp:12
Organizes efficient production of plots with single loop over each process.
Definition: plot_maker.hpp:14
PlotOpt & Bottom(PlotOptTypes::BottomType bottom_type)
Definition: plot_opt.cpp:93
PlotOpt & ShowBackgroundError(bool show_background_error)
Definition: plot_opt.cpp:386
A full 1D plot with stacked/overlayed histograms.
Definition: hist1d.hpp:23
Definition: table.hpp:15
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
Hist1D & Tag(const std::string &tag)
Definition: hist1d.cpp:512
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
int main(int argc, char *argv[])
Definition: test.cxx:34
void GetOptions(int argc, char *argv[])
Definition: test.cxx:161
Loads colors from a text configuration file.
Definition: palette.hpp:8