ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_closure.cxx
Go to the documentation of this file.
1 
3 #include <fstream>
4 #include <iostream>
5 #include <vector>
6 #include <chrono>
7 
8 #include <unistd.h>
9 #include <stdlib.h>
10 #include <getopt.h>
11 
12 #include "TError.h" // Controls error level reporting
13 
14 #include "core/utilities.hpp"
15 #include "core/baby.hpp"
16 #include "core/process.hpp"
17 #include "core/plot_maker.hpp"
18 #include "core/plot_opt.hpp"
19 #include "core/hist1d.hpp"
20 
21 using namespace std;
22 using namespace PlotOptTypes;
23 
24 int main(){
25  gErrorIgnoreLevel=6000; // Turns off ROOT errors due to missing branches
26 
27  chrono::high_resolution_clock::time_point begTime;
28  begTime = chrono::high_resolution_clock::now();
29 
32  string bfolder("");
33  string hostname = execute("echo $HOSTNAME");
34  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
35  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
36 
37  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_higmc_higloose/");
38 
39  // Cuts in baseline speed up the yield finding
40  string baseline = "pass && stitch && hig_drmax<2.2&&ntks==0&&njets>=4&&njets<=5&&!low_dphi&&nvleps==0";
42  string c_2b="nbt==2&&nbm==2";
43  string c_3b="nbt>=2&&nbm==3&&nbl==3";
44  string c_4b="nbt>=2&&nbm>=3&&nbl>=4";
45 
46  auto proc_tt_2b = Process::MakeShared<Baby_full>("t#bar{t}, 2b", Process::Type::background, kBlue,
47  {foldermc+"*_TTJets*.root"}, baseline+"&&"+c_2b);
48  auto proc_tt_3b = Process::MakeShared<Baby_full>("t#bar{t}, 3b", Process::Type::background, kRed+1,
49  {foldermc+"*_TTJets*.root"}, baseline+"&&"+c_3b);
50  auto proc_tt_4b = Process::MakeShared<Baby_full>("t#bar{t}, 4b", Process::Type::background, kGreen+1,
51  {foldermc+"*_TTJets*.root"}, baseline+"&&"+c_4b);
52 
53 
55  vector<string> vnames_bkg({"_TTJets", "_WJetsToLNu", "_TTW", "_TTZ", "DYJetsToLL",
56  "_ZJet", "_ttHJetTobb", "_TTGJets", "_TTTT",
57  "_WH_HToBB", "_ZH_HToBB", "_WWTo", "_WZ", "_ZZ_"});//,
58  //"QCD_HT*to1000_Tune", "QCD_HT*to1500_Tune", "QCD_HT*to2000_Tune", "QCD_HT*Inf_Tune"});
59  set<string> names_bkg;
60  for(auto name : vnames_bkg)
61  names_bkg.insert(name = foldermc + "*" + name + "*.root");
62 
63  auto proc_bkg_2b = Process::MakeShared<Baby_full>("All bkg (no QCD), 2b", Process::Type::background, kBlue,
64  names_bkg, baseline+"&&"+c_2b);
65  auto proc_bkg_3b = Process::MakeShared<Baby_full>("All bkg (no QCD), 3b", Process::Type::background, kOrange+1,
66  names_bkg, baseline+"&&"+c_3b);
67  auto proc_bkg_4b = Process::MakeShared<Baby_full>("All bkg (no QCD), 4b", Process::Type::background, kGreen+2,
68  names_bkg, baseline+"&&"+c_4b);
69 
70 
71  vector<shared_ptr<Process> > procs_tt = {proc_tt_2b, proc_tt_3b, proc_tt_4b};
72  vector<shared_ptr<Process> > procs_bkg = {proc_bkg_2b, proc_bkg_3b, proc_bkg_4b};
73 
74  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
75  log_lumi.Title(TitleType::preliminary)
76  .Bottom(BottomType::ratio)
77  .YAxis(YAxisType::log)
78  .Stack(StackType::data_norm);
79  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
80  PlotOpt log_shapes = log_lumi().Stack(StackType::shapes)
81  .ShowBackgroundError(false);
82  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
83  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
84  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
85  PlotOpt log_shapes_info = log_shapes().Title(TitleType::info);
86  PlotOpt lin_shapes_info = lin_shapes().Title(TitleType::info);
87  vector<PlotOpt> all_plot_types = {lin_shapes_info};
88 
90  PlotMaker pm;
91 
92  NamedFunc cuts = "nvleps==0&&met>100&&!low_dphi&&hig_drmax<2.2&&ntks==0&&njets>=4&&njets<=5";
93  pm.Push<Hist1D>(Axis(22,0,110,"hig_dm", "#Deltam_{jj} [GeV]", {40.}),
94  cuts, procs_tt, all_plot_types).Tag("tt");
95  pm.Push<Hist1D>(Axis(25,0,250,"hig_am", "<m_{jj}> [GeV]", {100., 140.}),
96  cuts, procs_tt, all_plot_types).Tag("tt");
97  pm.Push<Hist1D>(Axis(22,0,110,"hig_dm", "#Deltam_{jj} [GeV]", {40.}),
98  cuts, procs_bkg, all_plot_types).Tag("bkg");
99  pm.Push<Hist1D>(Axis(25,0,250,"hig_am", "<m_{jj}> [GeV]", {100., 140.}),
100  cuts, procs_bkg, all_plot_types).Tag("bkg");
101 
102  pm.min_print_ = true;
103  pm.MakePlots(40.);
104 
105  double seconds = (chrono::duration<double>(chrono::high_resolution_clock::now() - begTime)).count();
106  TString hhmmss = HoursMinSec(seconds);
107  cout<<endl<<"Making plots took "<<round(seconds)<<" seconds ("<<hhmmss<<")"<<endl<<endl;
108 } // main
109 
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
TString HoursMinSec(float fseconds)
Definition: utilities.cpp:337
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
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
int main()
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
PlotOpt & ShowBackgroundError(bool show_background_error)
Definition: plot_opt.cpp:386
A full 1D plot with stacked/overlayed histograms.
Definition: hist1d.hpp:23
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