ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_2016-09-09_datamc_datadata.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <memory>
5 
6 #include "TError.h"
7 #include "TColor.h"
8 #include "TVector2.h"
9 
10 #include "core/baby.hpp"
11 #include "core/process.hpp"
12 #include "core/named_func.hpp"
13 #include "core/plot_maker.hpp"
14 #include "core/plot_opt.hpp"
15 #include "core/palette.hpp"
16 #include "core/histo_stack.hpp"
17 #include "core/utilities.hpp"
18 #include "core/functions.hpp"
19 
20 using namespace std;
21 using namespace PlotOptTypes;
22 
23 namespace {
24  double lumi = 12.9;
25 }
26 
27 int main(){
28  gErrorIgnoreLevel = 6000;
29  string bfolder("");
30  string hostname = execute("echo $HOSTNAME");
31  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
32  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
33 
34  Palette colors("txt/colors.txt", "default");
35 
36  string ntupletag = "*.root";
37 
38  string fmc = bfolder+"/cms2r0/babymaker/babies/2016_08_10/mc/merged_mcbase_standard/";
39  string fdata = bfolder+"/cms2r0/babymaker/babies/2016_08_10/data/merged_database_standard/";
40 
41  auto tt1l = Process::MakeShared<Baby_full>("t#bar{t} (1l)", Process::Type::background, colors("tt_1l"),
42  {fmc+"*_TTJets*Lept"+ntupletag, fmc+"*_TTJets_HT"+ntupletag}, "ntruleps<=1&&stitch");
43  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t} (2l)", Process::Type::background, colors("tt_2l"),
44  {fmc+"*_TTJets*Lept"+ntupletag, fmc+"*_TTJets_HT"+ntupletag}, "ntruleps>=2&&stitch");
45  auto wjets = Process::MakeShared<Baby_full>("W+jets", Process::Type::background, colors("wjets"),
46  {fmc+"*_WJetsToLNu"+ntupletag},"stitch");
47  auto single_t = Process::MakeShared<Baby_full>("Single t", Process::Type::background, colors("single_t"),
48  {fmc+"*_ST_"+ntupletag});
49  auto ttv = Process::MakeShared<Baby_full>("t#bar{t}V", Process::Type::background, colors("ttv"),
50  {fmc+"*_TTWJets"+ntupletag, fmc+"*_TTZTo"+ntupletag});
51  auto other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
52  {fmc+"*DYJetsToLL"+ntupletag,
53  fmc+"*_QCD_HT*00_Tune"+ntupletag, fmc+"*_QCD_HT*Inf_Tune"+ntupletag,
54  fmc+"*_ZJet"+ntupletag, fmc+"*_WWTo"+ntupletag,
55  fmc+"*ggZH_HToBB"+ntupletag, fmc+"*ttHJetTobb"+ntupletag,
56  fmc+"*_TTGJets"+ntupletag, fmc+"*_TTTT_"+ntupletag,
57  fmc+"*_WH_HToBB"+ntupletag, fmc+"*_WZTo"+ntupletag,
58  fmc+"*_ZH_HToBB"+ntupletag, fmc+"_ZZ_"+ntupletag});
59 
60  auto data_highmt = Process::MakeShared<Baby_full>("Data 1l, m_{T} > 140", Process::Type::data, kBlack,
61  {fdata+ntupletag},"pass && json12p9 && trig_ra4 && st>500 && mt>140 && nleps==1 && nveto==0 && njets>=6 && nbm>=1");
62  auto data_lowmt = Process::MakeShared<Baby_full>("Data 1l, m_{T} #leq 140", Process::Type::background, kBlack,
63  {fdata+ntupletag},"pass && json12p9 && trig_ra4 && st>500 && mt<=140 && nleps==1 && nveto==0 && njets>=6 && nbm>=1");
64  data_lowmt->SetFillColor(kWhite);
65  data_lowmt->SetLineColor(kBlue-7);
66  data_lowmt->SetLineWidth(2);
67 
68  auto data2lveto = Process::MakeShared<Baby_full>("Data 2l or l+trk", Process::Type::data, kBlue+2,
69  {fdata+ntupletag},
70  "pass && json12p9 && trig_ra4 && st>500 && ((nleps==2 && njets>=5 && nbm<=2) || (nleps==1 && nveto==1 && njets>=6 && nbm>=1 && mt>140))");
71 
72  auto data2l = Process::MakeShared<Baby_full>("Data 2l", Process::Type::data, kMagenta+3,
73  {fdata+ntupletag},
74  "pass && json12p9 && trig_ra4 && st>500 && (nleps==2 && njets>=5 && nbm<=2)");
75 
76 
77  auto data = Process::MakeShared<Baby_full>("Data", Process::Type::data, kBlack,
78  {fdata+ntupletag},"pass && json12p9 && trig_ra4");
79 
80  vector<shared_ptr<Process> > all_procs;
81  all_procs = {data, tt1l, tt2l, wjets, single_t, ttv, other};
82 
83  vector<shared_ptr<Process> > data1l_procs = {data_highmt, data_lowmt};
84  vector<shared_ptr<Process> > data2lveto_procs = {data2lveto, data_lowmt};
85  vector<shared_ptr<Process> > data2l_procs = {data2l, data_lowmt};
86 
87  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
88  log_lumi.Title(TitleType::preliminary)
89  .Bottom(BottomType::ratio)
90  .YAxis(YAxisType::log)
91  .Stack(StackType::data_norm);
92  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
93  PlotOpt log_shapes = log_lumi().Stack(StackType::shapes)
94  .Bottom(BottomType::off)
95  .ShowBackgroundError(false);
96  PlotOpt lin_shapes = log_shapes().YAxis(YAxisType::linear);
97  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
98  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
99  PlotOpt log_shapes_info = log_shapes().Title(TitleType::info);
100  PlotOpt lin_shapes_info = lin_shapes().Title(TitleType::info);
101  vector<PlotOpt> log = {log_lumi_info};
102  vector<PlotOpt> lin = {lin_lumi_info};
103 
104  NamedFunc dphi_met_lep("dphi_met_lep",[](const Baby &b) -> NamedFunc::ScalarType{
105  return fabs(TVector2::Phi_mpi_pi(b.met_phi()-b.leps_phi()->at(0)));
106  });
107 
108  string baseline = "met>200 && nleps==1 && nveto==0 && st>500 && njets>=6 && nbm>=1";
109  PlotMaker pm;
110 
111  //MJ modeling
112  pm.Push<HistoStack>(HistoDef(20, 500., 2500., "st", "S_{T} [GeV]",
113  baseline, "weight"), all_procs, log);
114  pm.Push<HistoStack>(HistoDef(20, 0., 1000., "mj14", "M_{J} [GeV]",
115  baseline +"&&mt<=140", "weight", {250.,400.}), all_procs, lin);
116  pm.Push<HistoStack>(HistoDef(16, -0.5, 15.5, "njets", "N_{jets}",
117  CopyReplaceAll(baseline, "&& njets>=6", ""), "weight"), all_procs, lin);
118  pm.Push<HistoStack>(HistoDef(20, 0., 700., "fjets14_m[0]", "leading fat jet mass [GeV]",
119  baseline, "weight", {5.5, 8.5}), all_procs, lin);
120 
121  //mT modeling
122  pm.Push<HistoStack>(HistoDef(11, 150., 700., "met", "MET [GeV]",
123  CopyReplaceAll(baseline, "met>200", "met>150"), "weight", {200.,350.,500.}), all_procs, log);
124  pm.Push<HistoStack>(HistoDef(20, 20., 520., "leps_pt[0]", "lepton p_{T} [GeV]",
125  baseline, "weight"), all_procs, log);
126  pm.Push<HistoStack>(HistoDef(15, 0., 525., "mt", "m_{T} [GeV]",
127  baseline, "weight", {140.}), all_procs, log);
128  pm.Push<HistoStack>(HistoDef(15, 2, 3.2, Functions::max_dphi_met_jet, "max #Delta#phi(j,MET)",
129  baseline, "weight"), all_procs, log);
130  pm.Push<HistoStack>(HistoDef(15, 0., 1.5, Functions::min_dphi_met_jet, "min #Delta#phi(j,MET)",
131  baseline, "weight"), all_procs, log);
132  pm.Push<HistoStack>(HistoDef(16, 0., 3.2, dphi_met_lep, "#Delta#phi(l,MET)",
133  baseline, "weight"), all_procs, log);
134 
135  //other
136  pm.Push<HistoStack>(HistoDef(7, -0.5, 6.5, "nbm", "N_{b}",
137  CopyReplaceAll(baseline, "&& nbm>=1", ""), "weight", {0.5, 1.5, 2.5}), all_procs, lin);
138 
139  //data-to-data
140  vector<string> metbins = {"met>150 && met<=500", "met>150 && met<=200", "met>200 && met<=350", "met>350 && met<=500", "met>200 && met<=500","met>500","met>200"};
141  for (auto &imet: metbins){
142  pm.Push<HistoStack>(HistoDef("data1l1b", 20,0.,1000., "mj14", "M_{J} [GeV]",
143  imet + "&&nbm==1", "weight", {250.,400.}), data1l_procs, lin);
144  pm.Push<HistoStack>(HistoDef("data1l2b", 20,0.,1000., "mj14", "M_{J} [GeV]",
145  imet + "&&nbm>=2", "weight", {250.,400.}), data1l_procs, lin);
146  pm.Push<HistoStack>(HistoDef("data2l", 20,0.,1000., "mj14", "M_{J} [GeV]",
147  imet, "weight", {250.,400.}), data2l_procs, lin);
148  pm.Push<HistoStack>(HistoDef("data2lveto", 20,0.,1000., "mj14", "M_{J} [GeV]",
149  imet, "weight", {250.,400.}), data2lveto_procs, lin);
150  }
151 
152  pm.Push<HistoStack>(HistoDef(20, 0., 1000., "mj14", "M_{J} [GeV]",
153  baseline +"&&mt>140", "weight", {250.,400.}), all_procs, lin);
154  pm.Push<HistoStack>(HistoDef(20, 0., 1000., "mj14", "M_{J} [GeV]",
155  baseline +"&&mt>140 && nbm==1", "weight", {250.,400.}), all_procs, lin);
156  pm.Push<HistoStack>(HistoDef(20, 0., 1000., "mj14", "M_{J} [GeV]",
157  baseline +"&&mt>140 && nbm>=2", "weight", {250.,400.}), all_procs, lin);
158 
159  pm.min_print_ = true;
160  pm.MakePlots(lumi);
161 
162 }
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
std::vector< float > *const & leps_phi() const
Get leps_phi for current event and cache it.
Definition: baby.cpp:4481
Abstract base class for access to ntuple variables.
Definition: baby.hpp:16
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
float const & met_phi() const
Get met_phi for current event and cache it.
Definition: baby.cpp:4733
std::string execute(const std::string &cmd)
Definition: utilities.cpp:65
double ScalarType
Definition: named_func.hpp:15
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
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
const NamedFunc min_dphi_met_jet
PlotOpt & ShowBackgroundError(bool show_background_error)
Definition: plot_opt.cpp:386
const NamedFunc max_dphi_met_jet
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
std::string CopyReplaceAll(const std::string &str, const std::string &orig, const std::string &rep)
Loads colors from a text configuration file.
Definition: palette.hpp:8