ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_app_dilep.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <memory>
5 
6 #include <unistd.h>
7 #include <getopt.h>
8 
9 #include "TError.h"
10 #include "TColor.h"
11 
12 #include "core/baby.hpp"
13 #include "core/process.hpp"
14 #include "core/named_func.hpp"
15 #include "core/plot_maker.hpp"
16 #include "core/plot_opt.hpp"
17 #include "core/palette.hpp"
18 #include "core/table.hpp"
19 #include "core/hist1d.hpp"
20 #include "core/utilities.hpp"
21 
22 using namespace std;
23 using namespace PlotOptTypes;
24 
25 namespace{
26  bool single_thread = true;
27  TString method = "";
28 }
29 
30 void GetOptions(int argc, char *argv[]);
31 
32 int main(int argc, char *argv[]){
33  gErrorIgnoreLevel = 6000;
34  GetOptions(argc, argv);
35 
36  double lumi = 2.6;
37 
38  string bfolder("");
39  string hostname = execute("HOSTNAME");
40  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
41  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
42  string lowmet_fndata(bfolder+"/cms2r0/babymaker/babies/2016_06_26/data/merged_met150/");
43  string himet_fndata(bfolder+"/cms2r0/babymaker/babies/2016_06_26/data/merged_standard/");
44  string himet_fodata(bfolder+"/cms2r0/babymaker/babies/2016_04_29/data/merged_1lht500met200/");
45  string lowmet_fmc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_met150/");
46  string himet_fmc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/merged_standard/");
47 
48  string baseline("nleps>=1 && ht>500 && met>150 && met<500 && pass && njets>=5");
49 
50  // vector<TString> abcdcuts_veto = {"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && njets>=6",
51  // "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && njets>=6 && njets<=8",
52  // "mt>140 && mj14<=400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && njets>=6",
53  // "mt>140 && mj14>400 && nleps==1 && nveto==1 && nbm>=1 && nbm<=2 && njets>=6 && njets<=8"};
54 
55  vector<string> abcdcuts_2l = {"mt<=140 && mj14<=400 && nleps==1 && nveto==0 && nbm>=1 && njets>=6",
56  "mt<=140 && mj14>400 && nleps==1 && nveto==0 && nbm>=1 && njets>=6",
57  " mj14<=400 && nels==1 && nmus==1 && nbm<=2 && njets>=5",
58  " mj14>400 && nels==1 && nmus==1 && nbm<=2 && njets>=5"};
59 
60  Palette colors("txt/colors.txt", "default");
61 
62  // auto r1data = Process::MakeShared<Baby_full>("R1 data", Process::Type::background, kAzure+1, {himet_fndata, lowmet_fndata}, baseline+"&&"+abcdcuts_2l[0]);
63 
64  // auto r2data = Process::MakeShared<Baby_full>("R2 data", Process::Type::background, kOrange, {himet_fndata, lowmet_fndata}, baseline+"&&"+abcdcuts_2l[1]);
65 
66  // auto d3data = Process::MakeShared<Baby_full>("D3 data", Process::Type::background, kGreen+2, {himet_fndata, lowmet_fndata}, baseline+"&&"+abcdcuts_2l[2]);
67 
68  // auto d4data = Process::MakeShared<Baby_full>("D4 data", Process::Type::background, kRed+1, {himet_fndata, lowmet_fndata}, baseline+"&&"+abcdcuts_2l[3]);
69 
70  // vector<shared_ptr<Process> > all_regs = {r1data, d3data, r2data, d4data};
71 
72  auto ndata = Process::MakeShared<Baby_full>("Data (2016, 2.6 fb^{-1})", Process::Type::data, kBlack, {lowmet_fndata+"/*.root", himet_fndata+"/*.root"},
73  baseline+"&&json2p6 && (trig[4]||trig[8]||trig[13]||trig[33])");
74  auto odata = Process::MakeShared<Baby_full>("Data (2015, 2.3 fb^{-1})", Process::Type::data, kRed+1, {himet_fodata+"/*.root"},
75  baseline+" && (trig[4]||trig[8]||trig[28]||trig[14])");
76 
77  auto tt1l = Process::MakeShared<Baby_full>("tt 1lep", Process::Type::background, colors("tt_1l"),
78  {lowmet_fmc+"*_TTJets*Lept*.root", lowmet_fmc+"*_TTJets_HT*.root",
79  himet_fmc+"*_TTJets*Lept*.root", himet_fmc+"*_TTJets_HT*.root"},
80  baseline+" && stitch && ntruleps==1");
81  auto tt2l = Process::MakeShared<Baby_full>("tt 2lep", Process::Type::background, colors("tt_2l"),
82  {lowmet_fmc+"*_TTJets*Lept*.root", lowmet_fmc+"*_TTJets_HT*.root",
83  himet_fmc+"*_TTJets*Lept*.root", himet_fmc+"*_TTJets_HT*.root"},
84  baseline+" && stitch && ntruleps==2");
85  auto other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
86  {lowmet_fmc+"*_WJetsToLNu*.root",lowmet_fmc+"*_ST_*.root",
87  lowmet_fmc+"*_TTW*.root",lowmet_fmc+"*_TTZ*.root",
88  lowmet_fmc+"*DYJetsToLL*.root",lowmet_fmc+"*QCD_HT*.root",
89  lowmet_fmc+"*_ZJet*.root",lowmet_fmc+"*_ttHJetTobb*.root",
90  lowmet_fmc+"*_TTGJets*.root",lowmet_fmc+"*_TTTT*.root",
91  lowmet_fmc+"*_WH_HToBB*.root",lowmet_fmc+"*_ZH_HToBB*.root",
92  lowmet_fmc+"*_WWTo*.root",lowmet_fmc+"*_WZ*.root",lowmet_fmc+"*_ZZ_*.root",
93  himet_fmc+"*_WJetsToLNu*.root",himet_fmc+"*_ST_*.root",
94  himet_fmc+"*_TTW*.root",himet_fmc+"*_TTZ*.root",
95  himet_fmc+"*DYJetsToLL*.root",himet_fmc+"*QCD_HT*.root",
96  himet_fmc+"*_ZJet*.root",himet_fmc+"*_ttHJetTobb*.root",
97  himet_fmc+"*_TTGJets*.root",himet_fmc+"*_TTTT*.root",
98  himet_fmc+"*_WH_HToBB*.root",himet_fmc+"*_ZH_HToBB*.root",
99  himet_fmc+"*_WWTo*.root",himet_fmc+"*_WZ*.root",himet_fmc+"*_ZZ_*.root"},
100  baseline+" && stitch");
101 
102  vector<shared_ptr<Process> > lowmet_procs = {ndata, tt1l, tt2l, other};
103  vector<shared_ptr<Process> > himet_procs = {ndata, odata, tt1l, tt2l, other};
104  vector<shared_ptr<Process> > allmet_procs = {ndata, odata, tt1l, tt2l, other};
105 
106  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
107  log_lumi.Title(TitleType::preliminary)
108  .Bottom(BottomType::ratio)
109  .YAxis(YAxisType::log)
110  .Stack(StackType::data_norm);
111  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
112  PlotOpt log_shapes = log_lumi().Stack(StackType::shapes)
113  .Bottom(BottomType::off)
114  .ShowBackgroundError(false);
115  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
116  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
117  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
118  PlotOpt log_shapes_info = log_shapes().Title(TitleType::info);
119  PlotOpt lin_shapes_info = lin_shapes().Title(TitleType::info);
120  // vector<PlotOpt> all_plot_types = {log_lumi, lin_lumi, log_shapes, lin_shapes,
121  // log_lumi_info, lin_lumi_info, log_shapes_info, lin_shapes_info};
122 
123  vector<PlotOpt> plot_types = {lin_lumi_info};
124 
125  PlotMaker pm;
126  // pm.Push<Hist1D>(Axis(25, 0., 600., "mus_pt[0]", "Muon pT"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
127  // pm.Push<Hist1D>(Axis(20, 0., 0.1, "mus_pterr[0]/mus_pt[0]", "Muon relative pT error"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
128  // pm.Push<Hist1D>(Axis(20, 0., 20, "mus_trk_algo[0]", "Muon reco algorithm"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
129  // pm.Push<Hist1D>(Axis(3, 0., 3, "mus_trk_nholes_in[0]", "Holes in inner track"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
130  // pm.Push<Hist1D>(Axis(5, 0., 5, "mus_trk_nholes_out[0]", "Holes in outer track"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
131  // pm.Push<Hist1D>(Axis(2, 0., 2, "mus_trk_quality[0]", "Muon is high purity"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
132  // pm.Push<Hist1D>(Axis(2, 0., 2, "mus_tight[0]", "Muon is tight"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
133  // pm.Push<Hist1D>(Axis(3, -1., 2, "mus_charge[0]", "Muon charge"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
134  // pm.Push<Hist1D>(Axis(30, 0., 5., "mus_em_e[0]", "Muon E deposited in ECAL"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
135  // pm.Push<Hist1D>(Axis(30, 0., 20., "mus_had_e[0]", "Muon E deposited in HCAL"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
136 
137  // pm.Push<Hist1D>(Axis(15, 0., 600., "elmu_m", "elmu_m"), true, all_regs, plot_types).Weight(1./2.6);
138  // pm.Push<Hist1D>(Axis(15, 0., 600., "elmu_pt", "elmu_pt"), true, all_regs, plot_types).Weight(1./2.6);
139  // pm.Push<Hist1D>(Axis(16, 0., 3.2, "dphi_lmet", "dphi_lmet"), true, all_regs, plot_types).Weight(1./2.6);
140  // pm.Push<Hist1D>(Axis(10, 0., 1000, "jetsys_pt", "jetsys_pt"), true, all_regs, plot_types).Weight(1./2.6);
141  // pm.Push<Hist1D>(Axis(10, 0., 1000, "jetsys_nob_pt", "jetsys_nob_pt"), true, all_regs, plot_types).Weight(1./2.6);
142  // pm.Push<Hist1D>(Axis(20, 0., 1, "mus_miniso[0]", "mus_miniso"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
143  // pm.Push<Hist1D>(Axis(20, 0., 1, "mus_reliso[0]", "mus_reliso"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
144  // pm.Push<Hist1D>(Axis(20, 0., 200, "mus_reliso[0]*mus_pt[0]", "mus_absiso"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
145  // pm.Push<Hist1D>(Axis(21, 0, 21, "run-274400", "Run number"), "nmus==1", all_regs, plot_types).Weight(1./2.6);
146  // pm.Push<Hist1D>(Axis(30, 274100, 274421, "run", "Run number"), true, all_regs, plot_types).Weight(1./2.6);
147 
148  // ------------------- MET 150-200 ----------------------
149  pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]", {250.,400.}), "met>150&&met<200 && nels==1 && nmus==1 && nbm<=2 && njets>=5", lowmet_procs, plot_types);
150  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]", {250.,400.}), "met>150&&met<200 && nels==2 && nbm<=2 && njets>=5", lowmet_procs, plot_types);
151  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]", {250.,400.}), "met>150&&met<200 && nmus==2 && nbm<=2 && njets>=5", lowmet_procs, plot_types);
152  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]", {250.,400.}), "met>150&&met<200 && nleps==2 && nbm<=2 && njets>=5", lowmet_procs, plot_types);
153 
154  pm.Push<Hist1D>(Axis(10,0.,280., "mt", "m_{T} [GeV]", {140.}), "met>150&&met<200 && nels==1 && nmus==1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
155  pm.Push<Hist1D>(Axis(10,0.,280., "mt", "m_{T} [GeV]", {140.}), "mj14>400 && met>150&&met<200 && nels==1 && nmus==1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
156  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]", {140.}), "met>150&&met<200 && nels==2 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
157  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]", {140.}), "met>150&&met<200 && nmus==2 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
158  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]", {140.}), "met>150&&met<200 && nleps==2 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
159 
160  pm.Push<Hist1D>(Axis(10,0.,400., "mus_pt[0]", "p_{T} (#mu) [GeV]"),"met>150&&met<200 && nleps==2 && nmus>=1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
161  pm.Push<Hist1D>(Axis(10,0.,400., "els_pt[0]", "p_{T} (e)[GeV]"),"met>150&&met<200 && nleps==2 && nels>=1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
162  pm.Push<Hist1D>(Axis(10,0.,400., "mus_pt[0]", "p_{T} (#mu) [GeV]"),"mj14>400 && met>150&&met<200 && nleps==2 && nmus>=1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
163  pm.Push<Hist1D>(Axis(10,0.,400., "els_pt[0]", "p_{T} (e)[GeV]"),"mj14>400 && met>150&&met<200 && nleps==2 && nels>=1 && nbm<=2 && njets>=5",lowmet_procs, plot_types);
164 
165  // ------------------- MET 200-350 ----------------------
166  pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]",{250.,400.}),"met>200&&met<350 && nels==1 && nmus==1 && nbm<=2 && njets>=5",himet_procs, plot_types);
167  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]",{250.,400.}),"met>200&&met<350 && nels==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
168  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]",{250.,400.}),"met>200&&met<350 && nmus==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
169  // pm.Push<Hist1D>(Axis(13, 25, 1000, "mj14", "M_{J} [GeV]",{250.,400.}),"met>200&&met<350 && nleps==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
170 
171  pm.Push<Hist1D>(Axis(10,0.,280., "mt", "m_{T} [GeV]",{140.}),"met>200&&met<350 && nels==1 && nmus==1 && nbm<=2 && njets>=5",himet_procs, plot_types);
172  pm.Push<Hist1D>(Axis(10,0.,280., "mt", "m_{T} [GeV]",{140.}),"mj14>400 && met>200&&met<350 && nels==1 && nmus==1 && nbm<=2 && njets>=5",himet_procs, plot_types);
173  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]",{140.}),"met>200&&met<350 && nels==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
174  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]",{140.}),"met>200&&met<350 && nmus==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
175  // pm.Push<Hist1D>(Axis(6,0.,280., "mt", "m_{T} [GeV]",{140.}),"met>200&&met<350 && nleps==2 && nbm<=2 && njets>=5",himet_procs, plot_types);
176 
177  pm.Push<Hist1D>(Axis(10,0.,400., "mus_pt[0]", "p_{T} (#mu) [GeV]"),"met>200&&met<350 && nleps==2 && nmus>=1 && nbm<=2 && njets>=5",himet_procs, plot_types);
178  pm.Push<Hist1D>(Axis(10,0.,400., "els_pt[0]", "p_{T} (e)[GeV]"),"met>200&&met<350 && nleps==2 && nels>=1 && nbm<=2 && njets>=5",himet_procs, plot_types);
179  pm.Push<Hist1D>(Axis(10,0.,400., "mus_pt[0]", "p_{T} (#mu) [GeV]"),"mj14>400 && met>200&&met<350 && nleps==2 && nmus>=1 && nbm<=2 && njets>=5",himet_procs, plot_types);
180  pm.Push<Hist1D>(Axis(10,0.,400., "els_pt[0]", "p_{T} (e)[GeV]"),"mj14>400 && met>200&&met<350 && nleps==2 && nels>=1 && nbm<=2 && njets>=5",himet_procs, plot_types);
181 
182  // ------------------- MET 150-500 ----------------------
183  pm.Push<Hist1D>(Axis(12,200.,500., "met", "MET[GeV]",{350.}),"met>200 && nels==1 && nmus==1 && nbm<=2 && njets>=5",allmet_procs, plot_types);
184  pm.Push<Hist1D>(Axis(12,200.,500., "met", "MET[GeV]",{350.}),"mj14>400 && met>200 && nels==1 && nmus==1 && nbm<=2 && njets>=5",allmet_procs, plot_types);
185  // pm.Push<Hist1D>(Axis(12,200.,500., "met", "MET[GeV]",{350.}),"met>200 && nleps==2 && nels>=1 && nbm<=2 && njets>=5",allmet_procs, plot_types);
186  // pm.Push<Hist1D>(Axis(12,200.,500., "met", "MET[GeV]",{350.}),"met>200 && nleps==2 && nmus>=1 && nbm<=2 && njets>=5",allmet_procs, plot_types);
187 
188  if(single_thread) pm.multithreaded_ = false;
189  pm.MakePlots(lumi);
190 
191 }
192 
193 void GetOptions(int argc, char *argv[]){
194  while(true){
195  static struct option long_options[] = {
196  {"single_thread", no_argument, 0, 's'},
197  {0, 0, 0, 0}
198  };
199 
200  char opt = -1;
201  int option_index;
202  opt = getopt_long(argc, argv, "s", long_options, &option_index);
203 
204  if( opt == -1) break;
205 
206  string optname;
207  switch(opt){
208  case 's':
209  single_thread = true;
210  break;
211  case 0:
212  optname = long_options[option_index].name;
213  if(false){
214  }else{
215  printf("Bad option! Found option name %s\n", optname.c_str());
216  }
217  break;
218  default:
219  printf("Bad option! getopt_long returned character code 0%o\n", opt);
220  break;
221  }
222  }
223 }
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
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
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
Definition: axis.hpp:12
int main(int argc, char *argv[])
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[])
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
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
Loads colors from a text configuration file.
Definition: palette.hpp:8