ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
plot_tru_isr.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 = false;
27  bool verbose = false;
28  TString method = "";
29 }
30 
32 bool isGoodJet(const Baby &b, size_t ijet);
33 void GetOptions(int argc, char *argv[]);
34 
35 int main(int argc, char *argv[]){
36  gErrorIgnoreLevel = 6000;
37  GetOptions(argc, argv);
38 
39  double lumi = 2.6;
40 
41  string bfolder("");
42  string hostname = execute("echo $HOSTNAME");
43  if(Contains(hostname, "cms") || Contains(hostname, "compute-"))
44  bfolder = "/net/cms2"; // In laptops, you can't create a /net folder
45 
46  string foldermc(bfolder+"/cms2r0/babymaker/babies/2016_06_14/mc/unskimmed/");
47  string folderb(bfolder+"/cms2r0/babymaker/babies/2016_07_18/mc/benchmarks/");
48  string baseline = "1";
49  Palette colors("txt/colors.txt", "default");
50 
51  auto proc_tt = Process::MakeShared<Baby_full>("t#bar{t} 2l", Process::Type::signal, colors("tt_2l"),
52  {folderb+"*TT*DiLep*.root"}, baseline);//+" && ntruleps==0 && nleps==0");
53  auto proc_t1c = Process::MakeShared<Baby_full>("T1tttt(1200,800)", Process::Type::signal, kRed,
54  {folderb+"*SMS-T1tttt_mGluino-1200_mLSP-800*.root"}, baseline);//+" && ntruleps==0 && nleps==0");
55  auto proc_t1nc = Process::MakeShared<Baby_full>("T1tttt(1500,100)", Process::Type::signal, kRed,
56  {folderb+"*SMS-T1tttt_mGluino-1500_mLSP-100*.root"}, baseline);
57  // auto proc_t1nc_3l = Process::MakeShared<Baby_full>("T1tttt(1500,100) 3l", Process::Type::signal, kGreen+3,
58  // {folderb+"*SMS-T1tttt_mGluino-1500_mLSP-100*PUSpring16_80*.root"}, baseline+" && ntruleps==4 && nleps==4");
59  proc_t1c->SetLineStyle(2);
60 
61  auto proc_t14qc = Process::MakeShared<Baby_full>("T1qqqq(1000,800)", Process::Type::signal, kAzure+2 ,
62  {folderb+"*SMS-T1qqqq_mGluino-1000_mLSP-800*.root"}, baseline);
63  auto proc_t14qnc = Process::MakeShared<Baby_full>("T1qqqq(1400,100)", Process::Type::signal, kAzure+2 ,
64  {folderb+"*SMS-T1qqqq_mGluino-1400_mLSP-100*.root"}, baseline);
65  proc_t14qc->SetLineStyle(2);
66 
67  auto proc_t2ttvc = Process::MakeShared<Baby_full>("T2tt(425,325)", Process::Type::signal, kGreen+2,
68  {folderb+"*SMS-T2tt_mStop-425_mLSP-325*.root"}, baseline);
69  proc_t2ttvc->SetLineStyle(3);
70  auto proc_t2ttc = Process::MakeShared<Baby_full>("T2tt(500,325)", Process::Type::signal, kGreen+2,
71  {folderb+"*SMS-T2tt_mStop-500_mLSP-325*.root"}, baseline);
72  proc_t2ttc->SetLineStyle(2);
73  auto proc_t2ttnc = Process::MakeShared<Baby_full>("T2tt(850,100)", Process::Type::signal, kGreen+2,
74  {folderb+"*SMS-T2tt_mStop-850_mLSP-100*.root"}, baseline);
75 
76  vector<shared_ptr<Process> > tt_procs = {proc_tt};
77  vector<shared_ptr<Process> > proc_isrpt = {proc_t14qc, proc_t14qnc, proc_t1c, proc_t1nc, proc_t2ttvc, proc_t2ttc, proc_t2ttnc, proc_tt};
78  vector<shared_ptr<Process> > proc_isrpt_nolep = {proc_t14qc, proc_t14qnc, proc_t1c, proc_t1nc, proc_t2ttvc, proc_t2ttc, proc_t2ttnc};
79 
80  PlotOpt log_lumi("txt/plot_styles.txt", "CMSPaper");
81  log_lumi.Title(TitleType::preliminary)
82  .Bottom(BottomType::off)
83  .YAxis(YAxisType::log)
84  .Stack(StackType::shapes);
85  PlotOpt lin_lumi = log_lumi().YAxis(YAxisType::linear);
86  PlotOpt log_lumi_info = log_lumi().Title(TitleType::info);
87  PlotOpt lin_lumi_info = lin_lumi().Title(TitleType::info);
88  vector<PlotOpt> plot_types = {log_lumi_info, lin_lumi_info};
89 
90  NamedFunc nisr_match("nisr_match",nisrMatch);
91 
92  PlotMaker pm;
93 
94  float minx(0), maxx(460);
95  int nbins(static_cast<int>((maxx-minx)/10));
96 
97  minx = 0; maxx = 800; nbins = static_cast<int>((maxx-minx)/25);
98  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "isr_tru_pt", "True ISR p_{T} [GeV]"),
99  "(ntrutaush+ntrutausl)==0", proc_isrpt, plot_types);
100 
101  minx = -0.5; maxx = 7.5; nbins = static_cast<int>((maxx-minx)/1);
102  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "nisr", "Number of ISR jets"),
103  true, proc_isrpt, plot_types).Weight(1.);
104 
105  minx = -0.5; maxx = 7.5; nbins = static_cast<int>((maxx-minx)/1);
106  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "nisr", "Number of ISR jets"),
107  "(ntrutaush+ntrutausl)==0", proc_isrpt_nolep, plot_types).Weight(1.);
108 
109  minx = -0.5; maxx = 7.5; nbins = static_cast<int>((maxx-minx)/1);
110  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "nisr", "Number of ISR jets"),
111  "ntruleps==0", proc_isrpt_nolep, plot_types).Weight(1.);
112 
113  minx = -2.5; maxx =2.5; nbins = static_cast<int>((maxx-minx)/1);
114  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "nisr-(njets-2)", "true - reco ISR multiplicity"),
115  "nbm==2&&nleps==2", tt_procs, plot_types).Weight(1.);
116  minx = -2; maxx = 2; nbins = static_cast<int>((maxx-minx)/0.1);
117  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "(jetsys_nob_pt-isr_tru_pt)/isr_tru_pt", "(Reco-True)/True ISR p_{T} [GeV]"),
118  "nbm>=2", tt_procs, plot_types);
119 
120  minx = -300; maxx = 200; nbins = static_cast<int>((maxx-minx)/10);
121  pm.Push<Hist1D>(Axis(nbins, minx, maxx, "jetsys_nob_pt-isr_tru_pt", "Reco-True ISR p_{T} [GeV]"),
122  "nbm>=2", tt_procs, plot_types);
123 
124  if(single_thread || verbose) pm.multithreaded_ = false;
125  pm.MakePlots(lumi);
126 
127 }
128 
129 void GetOptions(int argc, char *argv[]){
130  while(true){
131  static struct option long_options[] = {
132  {"single_thread", no_argument, 0, 's'},
133  {0, 0, 0, 0}
134  };
135 
136  char opt = -1;
137  int option_index;
138  opt = getopt_long(argc, argv, "s", long_options, &option_index);
139 
140  if( opt == -1) break;
141 
142  string optname;
143  switch(opt){
144  case 's':
145  single_thread = true;
146  break;
147  case 0:
148  optname = long_options[option_index].name;
149  if(false){
150  }else{
151  printf("Bad option! Found option name %s\n", optname.c_str());
152  }
153  break;
154  default:
155  printf("Bad option! getopt_long returned character code 0%o\n", opt);
156  break;
157  }
158  }
159 }
160 
162  int Nisr=0;
163  for (size_t ijet(0); ijet<b.jets_pt()->size(); ijet++){
164  if(!isGoodJet(b, ijet) || b.jets_pt()->at(ijet)<30) continue;
165  bool matched=false;
166  for (size_t imc(0); imc<b.mc_pt()->size(); imc++){
167  if(b.mc_status()->at(imc)!=23 || abs(b.mc_id()->at(imc))>5) continue;
168  if(!(abs(b.mc_mom()->at(imc))==6 || abs(b.mc_mom()->at(imc))==23 ||
169  abs(b.mc_mom()->at(imc))==24 || abs(b.mc_mom()->at(imc))==15 || abs(b.mc_mom()->at(imc))>1e6)) continue; // In our ntuples where all taus come from W
170  float dR = deltaR(b.jets_eta()->at(ijet), b.jets_phi()->at(ijet), b.mc_eta()->at(imc), b.mc_phi()->at(imc));
171  if(dR<0.3){
172  if (verbose) cout<<"Jet: ("<<b.jets_pt()->at(ijet)<<", "<<b.jets_eta()->at(ijet)<<", "<<b.jets_phi()->at(ijet)<<"), MC: ("
173  <<b.mc_pt()->at(imc)<<", "<<b.mc_eta()->at(imc)<<", "<<b.mc_phi()->at(imc)<<"), ID "<<b.mc_id()->at(imc)<<". dR "<<dR <<endl;
174  matched = true;
175  break;
176  }
177  } // Loop over MC particles
178  if(!matched) {
179  Nisr++;
180  if (verbose) cout<<"Jet: ("<<b.jets_pt()->at(ijet)<<", "<<b.jets_eta()->at(ijet)<<", "<<b.jets_phi()->at(ijet)<<" not matched"<<endl;
181  }
182  } // Loop over jets
183  if (verbose){
184  for (size_t imc(0); imc<b.mc_pt()->size(); imc++){
185  if(b.mc_status()->at(imc)!=23 || abs(b.mc_id()->at(imc))>5) continue;
186  if(!(abs(b.mc_mom()->at(imc))==6 || abs(b.mc_mom()->at(imc))==23 ||
187  abs(b.mc_mom()->at(imc))==24 || abs(b.mc_mom()->at(imc))==15 || abs(b.mc_mom()->at(imc))>1e6)) continue; // In our ntuples where all taus come from W
188  cout<<" MC: ("
189  <<b.mc_pt()->at(imc)<<", "<<b.mc_eta()->at(imc)<<", "<<b.mc_phi()->at(imc)<<"), ID "<<b.mc_id()->at(imc)<<endl;
190  }
191  cout<<" ======== New event: njets "<<b.njets()<<", Nisr "<<Nisr<<endl<<endl;
192  }
193  return Nisr;
194 }
195 
196 bool isGoodJet(const Baby &b, size_t ijet){
197  return ijet<b.jets_pt()->size()
198  && fabs(b.jets_eta()->at(ijet))<2.4
199  && !b.jets_islep()->at(ijet);
200 }
std::vector< int > *const & mc_status() const
Get mc_status for current event and cache it.
Definition: baby.cpp:4625
PlotOpt & Stack(PlotOptTypes::StackType stack_type)
Definition: plot_opt.cpp:120
PlotOpt & YAxis(PlotOptTypes::YAxisType y_axis_type)
Definition: plot_opt.cpp:102
bool isGoodJet(const Baby &b, size_t ijet)
int const & njets() const
Get njets for current event and cache it.
Definition: baby.cpp:5981
std::vector< float > *const & jets_phi() const
Get jets_phi for current event and cache it.
Definition: baby.cpp:4277
Abstract base class for access to ntuple variables.
Definition: baby.hpp:16
NamedFunc::ScalarType nisrMatch(const Baby &b)
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
double ScalarType
Definition: named_func.hpp:15
std::vector< int > *const & mc_mom() const
Get mc_mom for current event and cache it.
Definition: baby.cpp:4577
std::vector< float > *const & mc_pt() const
Get mc_pt for current event and cache it.
Definition: baby.cpp:4613
FigureType & Push(Args &&...args)
Definition: plot_maker.hpp:24
Definition: axis.hpp:12
int main(int argc, char *argv[])
std::vector< float > *const & jets_eta() const
Get jets_eta for current event and cache it.
Definition: baby.cpp:4121
Organizes efficient production of plots with single loop over each process.
Definition: plot_maker.hpp:14
float deltaR(float eta1, float phi1, float eta2, float phi2)
Definition: utilities.cpp:420
PlotOpt & Bottom(PlotOptTypes::BottomType bottom_type)
Definition: plot_opt.cpp:93
std::vector< int > *const & mc_id() const
Get mc_id for current event and cache it.
Definition: baby.cpp:4553
A full 1D plot with stacked/overlayed histograms.
Definition: hist1d.hpp:23
std::vector< float > *const & jets_pt() const
Get jets_pt for current event and cache it.
Definition: baby.cpp:4289
void GetOptions(int argc, char *argv[])
std::vector< float > *const & mc_eta() const
Get mc_eta for current event and cache it.
Definition: baby.cpp:4541
std::vector< bool > *const & jets_islep() const
Get jets_islep for current event and cache it.
Definition: baby.cpp:4253
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::vector< float > *const & mc_phi() const
Get mc_phi for current event and cache it.
Definition: baby.cpp:4601
Loads colors from a text configuration file.
Definition: palette.hpp:8