ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_mj_reweight.cxx
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 
4 #include "TError.h"
5 
6 #include "core/baby_full.hpp"
7 #include "core/utilities.hpp"
8 #include "core/process.hpp"
9 #include "core/plot_maker.hpp"
10 #include "core/hist1d.hpp"
11 #include "core/palette.hpp"
12 #include "core/functions.hpp"
13 
14 using namespace std;
15 using namespace PlotOptTypes;
16 
17 namespace{
18  NamedFunc isr_weight("isr_weight", [](const Baby &b) -> NamedFunc::ScalarType{
19  if(b.ntrupv()<0) return b.weight();
20  return b.SampleType() == 20
22  : b.weight()/(b.eff_trig()*b.w_toppt());
23  });
24 
25  NamedFunc full_weight("full_weight", [](const Baby &b) -> NamedFunc::ScalarType{
26  if(b.ntrupv()<0) return b.weight();
27  double orig = isr_weight.GetScalar(b);
28  double mj = b.mj14();
29  if(mj <= 300.) return orig * (1.3 - 0.4*mj/300.);
30  else return orig*0.9;
31  });
32 }
33 
34 int main(){
35  gErrorIgnoreLevel = 6000;
36 
37  Palette colors("txt/colors.txt", "default");
38 
39  string folder_mc="/net/cms2/cms2r0/babymaker/babies/2016_06_14/mc/skim_nleps2/";
40 
41  NamedFunc mll = "mumuv_m*(mumuv_m>0&&mumu_pt1>25)+elelv_m*(elelv_m>0&&elel_pt1>30)";
42  NamedFunc baseline = mll>80. && mll<100. && "(nels>=2||nmus>=2)&&njets>=4&&ht>500&&pass";
43 
44  auto zjets = Process::MakeShared<Baby_full>("Z+jets", Process::Type::background, kGreen+1,
45  {folder_mc+"*_DYJetsToLL*.root"},
46  baseline);
47  auto tt1l = Process::MakeShared<Baby_full>("t#bar{t} (1l)", Process::Type::background, colors("tt_1l"),
48  {folder_mc+"*_TTJets*Lept*.root", folder_mc+"*_TTJets_HT*.root"},
49  baseline&&"ntruleps<=1&&stitch");
50  auto tt2l = Process::MakeShared<Baby_full>("t#bar{t} (2l)", Process::Type::background, colors("tt_2l"),
51  {folder_mc+"*_TTJets*Lept*.root", folder_mc+"*_TTJets_HT*.root"},
52  baseline&&"ntruleps>=2&&stitch");
53  auto ttv = Process::MakeShared<Baby_full>("t#bar{t}V", Process::Type::background, colors("ttv"),
54  {folder_mc+"*_TTWJetsTo*.root", folder_mc+"*_TTZTo*.root"},
55  baseline);
56  auto other = Process::MakeShared<Baby_full>("Other", Process::Type::background, colors("other"),
57  {folder_mc+"*_WJetsToLNu_HT-*.root", folder_mc+"*_QCD_HT*.root",
58  folder_mc+"*_TTGJets*.root", folder_mc+"*_TTTT*.root",
59  folder_mc+"*_WH_HToBB*.root", folder_mc+"*_WWTo*.root",
60  folder_mc+"*_WZTo*.root", folder_mc+"*_ZH*.root",
61  folder_mc+"*_ZZ*.root", folder_mc+"*_ttHJetTobb*.root",
62  folder_mc+"*_ST*channel*.root"},
63  baseline);
64  auto data = Process::MakeShared<Baby_full>("2016 Data", Process::Type::data, kBlack,
65  {"/net/cms2/cms2r0/babymaker/babies/2016_06_26/data/skim_nleps2/*.root"},
66  baseline&&"json2p6&&pass&&(trig[4]||trig[8]||trig[13]||trig[33])");
67  vector<shared_ptr<Process> > procs = {data, zjets, tt1l, tt2l, ttv, other};
68  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
69  log_lumi.Title(TitleType::info)
70  .Bottom(BottomType::ratio)
71  .YAxis(YAxisType::log)
72  .Stack(StackType::data_norm);
73  vector<PlotOpt> plot_types = {log_lumi};
74 
75  PlotMaker pm;
76  pm.Push<Hist1D>(Axis(24, 0., 600, "mj14", "M_{J} (with lep) [GeV]", {250., 400.}),
77  true, procs, plot_types).Tag("orig");
78  pm.Push<Hist1D>(Axis(24, 0., 600, "mj14", "M_{J} (with lep) [GeV]", {250., 400.}),
79  true, procs, plot_types).Tag("orig").Weight("weight/eff_trig*w_toppt");
80  pm.Push<Hist1D>(Axis(24, 0., 600, "mj14", "M_{J} (with lep) [GeV]", {250., 400.}),
81  true, procs, plot_types).Tag("orig").Weight(isr_weight);
82  pm.Push<Hist1D>(Axis(24, 0., 600, "mj14", "M_{J} (with lep) [GeV]", {250., 400.}),
83  true, procs, plot_types).Tag("orig").Weight(full_weight);
84  pm.MakePlots(2.6, "reweight");
85 }
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
const NamedFunc njets_weights_ttisr
float const & eff_trig() const
Get eff_trig for current event and cache it.
Definition: baby.cpp:2981
NamedFunc isr_weight("isr_weight", [](const Baby &b) -> NamedFunc::ScalarType{if(b.ntrupv()< 0) return b.weight();return b.SampleType()==20?Functions::njets_weights_ttisr.GetScalar(b):b.weight()/(b.eff_trig()*b.w_toppt());})
Abstract base class for access to ntuple variables.
Definition: baby.hpp:16
Hist1D & Weight(const NamedFunc &weight)
Definition: hist1d.cpp:507
ScalarType GetScalar(const Baby &b) const
Evaluate scalar function with b as argument.
Definition: named_func.cpp:460
STL namespace.
Combines a callable function taking a Baby and returning a scalar or vector with its string represent...
Definition: named_func.hpp:13
float const & w_toppt() const
Get w_toppt for current event and cache it.
Definition: baby.cpp:7505
float const & mj14() const
Get mj14 for current event and cache it.
Definition: baby.cpp:4913
double ScalarType
Definition: named_func.hpp:15
NamedFunc full_weight("full_weight", [](const Baby &b) -> NamedFunc::ScalarType{if(b.ntrupv()< 0) return b.weight();double orig=isr_weight.GetScalar(b);double mj=b.mj14();if(mj<=300.) return orig *(1.3-0.4 *mj/300.);else return orig *0.9;})
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
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
float const & weight() const
Get weight for current event and cache it.
Definition: baby.cpp:7517
A full 1D plot with stacked/overlayed histograms.
Definition: hist1d.hpp:23
int const & ntrupv() const
Get ntrupv for current event and cache it.
Definition: baby.cpp:6197
void MakePlots(double luminosity, const std::string &subdir="")
Prints all added plots with given luminosity.
Definition: plot_maker.cpp:54
int main()
Hist1D & Tag(const std::string &tag)
Definition: hist1d.cpp:512
PlotOpt & Title(PlotOptTypes::TitleType title_type)
Definition: plot_opt.cpp:111
int SampleType() const
Definition: baby.cpp:1681
Loads colors from a text configuration file.
Definition: palette.hpp:8