ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_basic.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/hist1d.hpp"
23 #include "core/event_scan.hpp"
24 #include "core/utilities.hpp"
25 
26 using namespace std;
27 using namespace PlotOptTypes;
28 
29 namespace{
30  bool single_thread = false;
31 }
32 
33 int main(int argc, char *argv[]){
34  string bfolder("");
35  string hostname = execute("echo $HOSTNAME");
36  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
37  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
38  gErrorIgnoreLevel = 6000;
39  GetOptions(argc, argv);
40 
41  double lumi = 20;
42 
43  string trig_skim_mc = "/cms2r0/babymaker/babies/2016_08_10/mc/merged_higmc_higloose/";
44  string trig_skim_signal = "/cms2r0/babymaker/babies/2016_08_10/TChiHH/merged_higmc_higloose/";
45 
46  Palette colors("txt/colors.txt", "default");
47  auto tchi = Process::MakeShared<Baby_full>("TChiHH(400,1)", Process::Type::signal, kRed,
48  {trig_skim_signal+"*TChiHH_mGluino-400*.root"});
49  auto tt = Process::MakeShared<Baby_full>("t#bar{t}", Process::Type::background, colors("tt_1l"),
50  {trig_skim_mc+"*_TTJets*Lept*.root", trig_skim_mc+"*_TTJets_HT*.root"}, "stitch");
51  auto wjets = Process::MakeShared<Baby_full>("W+jets", Process::Type::background, colors("wjets"),
52  {trig_skim_mc+"*_WJetsToLNu*.root"});
53  // auto znunu = Process::MakeShared<Baby_full>("Z#rightarrow#nu#nu", Process::Type::background, colors("znunu"),
54  // {trig_skim_mc+"*ZJetsToNuNu_HT*.root"});
55  auto wt = Process::MakeShared<Baby_full>("W+top", Process::Type::background, kRed+3,
56  {trig_skim_mc+"*ST_tW*.root"});
57  auto qcd = Process::MakeShared<Baby_full>("QCD", Process::Type::background, colors("qcd"),
58  {trig_skim_mc+"*_QCD_HT*00_Tune*.root", trig_skim_mc+"*_QCD_HT*Inf_Tune*.root"});
59  auto other = Process::MakeShared<Baby_full>("Other", Process::Type::background, kViolet-6,
60  {trig_skim_mc+"*DYJetsToLL*.root", trig_skim_mc+"*TTTT*.root", trig_skim_mc+"*_TTWJets*.root",
61  trig_skim_mc+"*_WH_*.root", trig_skim_mc+"*_ttHJet*.root", trig_skim_mc+"*_ZH_*.root",
62  trig_skim_mc+"*_ST_*channel*.root", trig_skim_mc+"*_TTGJets*.root", trig_skim_mc+"*_TTZTo*.root"});
63 
64 
65  vector<shared_ptr<Process> > full_trig_skim = {tchi, tt, wjets, wt, qcd, other};
66 
67  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
68  log_lumi.Title(TitleType::preliminary)
69  .Bottom(BottomType::off)
70  .YAxis(YAxisType::log)
71  .Stack(StackType::data_norm);
72  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
73  PlotOpt log_shapes = log_lumi().Stack(StackType::shapes)
74  .ShowBackgroundError(false);
75  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
76  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
77  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
78  PlotOpt log_shapes_info = log_shapes().Title(TitleType::info);
79  PlotOpt lin_shapes_info = lin_shapes().Title(TitleType::info);
80  vector<PlotOpt> all_plot_types = {log_lumi_info};
81 
82  PlotMaker pm;
83 
84  vector<NamedFunc> nbcuts;
85  nbcuts.push_back(" nbt >= 2 && nbl <= 3");
86  nbcuts.push_back(" nbt >= 2 && nbl >= 4");
87  NamedFunc metskim("njets>=4&&njets<=5&&met>100&&nvleps==0");
88  NamedFunc trkskim("njets>=4&&njets<=5&&met>250&&nvleps==0");
89  NamedFunc skim("njets>=4&&njets<=5&&met>250&&nvleps==0&&ntks==0");
90  NamedFunc DeltaR("hig_drmax < 2.2");
91  NamedFunc AverageM("hig_am > 100 && hig_am < 140");
92  NamedFunc DeltaM("hig_dm < 40");
93  NamedFunc LDP("!low_dphi");
94 
95  pm.Push<Hist1D>(Axis(7,-0.5,6.5,"nbl", "N_{b-jet}^{L}", {100.}),
96  skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
97  pm.Push<Hist1D>(Axis(7,-0.5,6.5,"nbm", "N_{b-jet}^{M}", {100.}),
98  skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
99  pm.Push<Hist1D>(Axis(7,-0.5,6.5,"nbt", "N_{b-jet}^{T}", {100.}),
100  skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
101 
102  for(auto inb: nbcuts) {
103  pm.Push<Hist1D>(Axis(20,100,600,"met", "E_{T}^{miss} [GeV]", {150., 250.}),
104  inb&&metskim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
105  pm.Push<Hist1D>(Axis(32,0,160,"hig_dm", "#Deltam [GeV]", {40.}),
106  inb&&skim&&DeltaR&&AverageM&&LDP, full_trig_skim, all_plot_types);
107  pm.Push<Hist1D>(Axis(25,0,250,"hig_am", "<m> [GeV]", {100., 140.}),
108  inb&&skim&&DeltaR&&DeltaM&&LDP, full_trig_skim, all_plot_types);
109  pm.Push<Hist1D>(Axis(20,0,4,"hig_drmax", "#DeltaR_{max}", {2.2}),
110  inb&&skim&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
111  pm.Push<Hist1D>(Axis(28,0,1400,"ht", "H_{T} [GeV]"),
112  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
113  pm.Push<Hist1D>(Axis(5,2.5,7.5,"njets", "N_{jet}", {3.5, 5.5}),
114  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
115  pm.Push<Hist1D>(Axis(5,-.5,4.5,"ntks", "N_{track}", {0.5}),
116  inb&&trkskim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
117  pm.Push<Hist1D>(Axis(32,0,3.2,"dphi2", "#Delta#phi_{2}", {0.5}),
118  inb&&skim&&DeltaR&&AverageM&&DeltaM, full_trig_skim, all_plot_types);
119  pm.Push<Hist1D>(Axis(32,0,3.2,"dphi3", "#Delta#phi_{3}", {0.3}),
120  inb&&skim&&DeltaR&&AverageM&&DeltaM, full_trig_skim, all_plot_types);
121  pm.Push<Hist1D>(Axis(32,0,3.2,"dphi4", "#Delta#phi_{4}", {0.3}),
122  inb&&skim&&DeltaR&&AverageM&&DeltaM, full_trig_skim, all_plot_types);
123  pm.Push<Hist1D>(Axis(30,0,600,"jets_pt[0]", "Jet 1 p_{T} [GeV]", {50.}),
124  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
125  pm.Push<Hist1D>(Axis(35,0,350,"jets_pt[1]", "Jet 2 p_{T} [GeV]", {50.}),
126  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
127  pm.Push<Hist1D>(Axis(25,0,250,"jets_pt[2]", "Jet 3 p_{T} [GeV]"),
128  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
129  pm.Push<Hist1D>(Axis(20,0,200,"jets_pt[3]", "Jet 4 p_{T} [GeV]"),
130  inb&&skim&&DeltaR&&AverageM&&DeltaM&&LDP, full_trig_skim, all_plot_types);
131  }
132 
133  pm.Push<Table>("cutflow", vector<TableRow>{
134  TableRow("$MET > 100$, $\\text{2M b-tags}$, $\\text{4 or 5 jets}$, $0\\ell$", "1"),
135  TableRow("$\\Delta\\phi_{\\text{min}}$", LDP),
136  TableRow("$\\Delta m < 40$", DeltaM&&LDP,1,0),
137  TableRow("$\\left< m \\right> \\in (100,140)$", AverageM&&LDP),
138  TableRow("$\\Delta R_{\\text{max}} < 2.2$", DeltaR&&LDP)
139  },full_trig_skim,0);
140 
141  if(single_thread) pm.multithreaded_ = false;
142  pm.min_print_ = true;
143  pm.MakePlots(lumi);
144 }
145 
146 void GetOptions(int argc, char *argv[]){
147  while(true){
148  static struct option long_options[] = {
149  {"single_thread", no_argument, 0, 's'},
150  {0, 0, 0, 0}
151  };
152 
153  char opt = -1;
154  int option_index;
155  opt = getopt_long(argc, argv, "s", long_options, &option_index);
156 
157  if( opt == -1) break;
158 
159  string optname;
160  switch(opt){
161  case 's':
162  single_thread = true;
163  break;
164  case 0:
165  optname = long_options[option_index].name;
166  if(false){
167  }else{
168  printf("Bad option! Found option name %s\n", optname.c_str());
169  }
170  break;
171  default:
172  printf("Bad option! getopt_long returned character code 0%o\n", opt);
173  break;
174  }
175  }
176 }
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
int main(int argc, char *argv[])
Definition: plot_basic.cxx:33
STL namespace.
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
Definition: named_func.hpp:13
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
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
Definition: axis.hpp:12
bool min_print_
Definition: plot_maker.hpp:44
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
void GetOptions(int argc, char *argv[])
Definition: plot_basic.cxx:146
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
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
Loads colors from a text configuration file.
Definition: palette.hpp:8