ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
aggregate_bins.cxx
Go to the documentation of this file.
1 #include "aggregate_bins.hpp"
2 
3 #include <string>
4 #include <set>
5 #include <limits>
6 #include <sstream>
7 #include <iomanip>
8 
9 #include <unistd.h>
10 #include <getopt.h>
11 
12 #include "bin.hpp"
13 #include "process.hpp"
14 #include "utilities.hpp"
15 #include "systematic.hpp"
16 #include "cut.hpp"
17 #include "cross_sections.hpp"
18 
19 #include "workspace_generator.hpp"
20 
21 using namespace std;
22 
23 namespace{
24  string out_dir = "/net/top/homes/ald77/ra4_stats/wspaces";
25  string syst_file = "txt/systematics/simple.txt";
26  double lumi = 35.9;
27  bool do_track_veto = true;
28  double met_low = 200.;
29  double met_high = -1.;
30  double njets_low = 5.5;
31  double njets_high = -1.;
32  double nbm_low = 0.5;
33  double nbm_high = -1.;
34  int mglu = 1800.;
35  int mlsp = 100.;
36  bool use_r4 = true;
37 }
38 
39 int main(int argc, char *argv[]){
40  GetOptions(argc, argv);
41 
42  string hostname = execute("echo $HOSTNAME");
43  string basefolder("/net/cms2/cms2r0/babymaker/");
44  if(Contains(hostname, "lxplus")) basefolder = "/afs/cern.ch/user/m/manuelf/work/";
45  string foldermc(basefolder+"babies/2017_01_27/mc/merged_mcbase_abcd/");
46  string foldersig(basefolder+"babies/2017_02_22_grooming/T1tttt/merged_mcbase_abcd/");
47  string folderdata(basefolder+"babies/2017_02_14/data/merged_database_abcd/");
48 
49  //Define processes. Try to minimize splitting
50  string stitch_cuts("stitch_met&&pass");
51 
52  Process ttbar{"ttbar", set<string>{
53  foldermc+"/*_TTJets*Lept*.root/tree"
54  },stitch_cuts};
55  Process other{"other", {
56  {foldermc+"/*_WJetsToLNu*.root/tree",
57  foldermc+"/*_ST_*.root/tree",
58  foldermc+"/*_TTW*.root/tree",
59  foldermc+"/*_TTZ*.root/tree",
60  foldermc+"/*DYJetsToLL*.root/tree",
61  foldermc+"/*_ZJet*.root/tree",
62  foldermc+"/*_ttHJetTobb*.root/tree",
63  foldermc+"/*_TTGJets*.root/tree",
64  foldermc+"/*_TTTT*.root/tree",
65  foldermc+"/*_WH_HToBB*.root/tree",
66  foldermc+"/*_ZH_HToBB*.root/tree",
67  foldermc+"/*_WWTo*.root/tree",
68  foldermc+"/*_WZ*.root/tree",
69  foldermc+"/*_ZZ_*.root/tree",
70  foldermc+"/*QCD_HT*0_Tune*.root/tree",
71  foldermc+"/*QCD_HT*Inf_Tune*.root/tree"}
72  },stitch_cuts};
73 
74  string data_cuts("trig_ra4&&pass");
75 
76  Process data{"data", {
77  {folderdata+"/*.root/tree"}
78  }, data_cuts, true};
79 
80  Process signal{"signal", {
81  {foldersig+"/*SMS-T1tttt_mGluino-"+to_string(mglu)+"_mLSP-"+to_string(mlsp)+"_*.root/tree"}
82  }, "stitch", false, true};
83 
84  Cut baseline("met/met_calo<5.&&pass_ra2_badmu&&st>500&&met>200&&nleps==1&&nbm>=1&&njets>=6&&mj14>250.");
85 
86  string met = "&&met>"+to_string(met_low);
87  if(met_high > met_low) met += "&&met<=" + to_string(met_high);
88  string njets_nbm = "&&njets>"+to_string(njets_low)+"&&nbm>"+to_string(nbm_low);
89  if(njets_high > njets_low) njets_nbm += "&&njets<=" + to_string(njets_high);
90  if(nbm_high > nbm_low) njets_nbm += "&&nbm<=" + to_string(nbm_high);
91  string tkveto = "&&nveto==0";
92 
93  Bin r1("r1", "mt<=140.&&mj14<=400."+met+tkveto, false);
94  Bin r2("r2", "mt<=140.&&mj14>400."+met+njets_nbm+tkveto, false);
95  Bin r3("r3", "mt>140.&&mj14<=400."+met+tkveto, false);
96  Bin r4("r4", "mt>140.&&mj14>400."+met+njets_nbm+tkveto, false);
97 
98  set<Block> blocks = {{"all", {{r1, r2}, {r3, r4}}}};
99 
100  WorkspaceGenerator wg(baseline, blocks, {ttbar, other}, signal, data,
101  syst_file, use_r4, 0., 1.);
102  wg.UseGausApprox(false);
103  wg.SetRMax(10.);
104  wg.SetKappaCorrected(true);
105  wg.SetDoSystematics(true);
106  wg.SetLuminosity(lumi);
107 
108  ostringstream oss;
109  oss << setprecision(numeric_limits<double>::digits10) << out_dir << "/wspace_aggbin_"
110  << "t1tttt_" << mglu << '_' << mlsp << "_lumi_" << lumi
111  << "_met_" << met_low << '_';
112  if(met_high > met_low) oss << met_high;
113  else oss << "inf";
114  oss << "_njets_" << ceil(njets_low) << '_';
115  if(njets_high > njets_low) oss << floor(njets_high);
116  else oss << "inf";
117  oss << "_nbm_" << ceil(nbm_low) << '_';
118  if(nbm_high > nbm_low) oss << floor(nbm_high);
119  else oss << "inf";
120  oss << "_tkveto_" << (do_track_veto ? "true" : "false")
121  << ".root" << flush;
122  string outname = oss.str();
123  if(!use_r4) ReplaceAll(outname, "wspace_aggbin_", "wspace_aggbin_nor4_");
124  wg.WriteToFile(outname);
125 }
126 
127 void GetOptions(int argc, char *argv[]){
128  while(true){
129  static struct option long_options[] = {
130  {"out_dir", required_argument, 0, 0},
131  {"syst_file", required_argument, 0, 0},
132  {"lumi", required_argument, 0, 0},
133  {"mglu", required_argument, 0, 0},
134  {"mlsp", required_argument, 0, 0},
135  {"do_track_veto", required_argument, 0, 0},
136  {"met_low", required_argument, 0, 0},
137  {"met_high", required_argument, 0, 0},
138  {"njets_low", required_argument, 0, 0},
139  {"njets_high", required_argument, 0, 0},
140  {"nbm_low", required_argument, 0, 0},
141  {"nbm_high", required_argument, 0, 0},
142  {"no_r4", no_argument, 0, 0},
143  {0, 0, 0, 0}
144  };
145 
146  char opt = -1;
147  int option_index;
148  opt = getopt_long(argc, argv, "", long_options, &option_index);
149  if( opt == -1) break;
150 
151  string optname;
152  switch(opt){
153  case 0:
154  optname = long_options[option_index].name;
155  if(optname == "out_dir"){
156  out_dir = optarg;
157  }else if(optname == "syst_file"){
158  syst_file = optarg;
159  }else if(optname == "lumi"){
160  lumi = atof(optarg);
161  }else if(optname == "do_track_veto"){
162  do_track_veto = atoi(optarg);
163  }else if(optname == "met_low"){
164  met_low = atof(optarg);
165  }else if(optname == "met_high"){
166  met_high = atof(optarg);
167  }else if(optname == "njets_low"){
168  njets_low = atof(optarg);
169  }else if(optname == "njets_high"){
170  njets_high = atof(optarg);
171  }else if(optname == "nbm_low"){
172  nbm_low = atof(optarg);
173  }else if(optname == "nbm_high"){
174  nbm_high = atof(optarg);
175  }else if(optname == "mglu"){
176  mglu = atoi(optarg);
177  }else if(optname == "mlsp"){
178  mlsp = atoi(optarg);
179  }else if(optname == "no_r4"){
180  use_r4 = false;
181  }else{
182  printf("Bad option! Found option name %s\n", optname.c_str());
183  }
184  break;
185  default:
186  printf("Bad option! getopt_long returned character code 0%o\n", opt);
187  break;
188  }
189  }
190 }
WorkspaceGenerator & SetLuminosity(double luminosity)
int main(int argc, char *argv[])
Definition: bin.hpp:12
WorkspaceGenerator & SetRMax(double rmax)
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
Definition: cut.hpp:8
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:34
STL namespace.
bool Contains(const std::string &str, const std::string &pat)
Definition: utilities.cpp:26
std::string execute(const std::string &cmd)
Definition: utilities.cpp:87
WorkspaceGenerator & SetKappaCorrected(bool do_kappa_correction)
void WriteToFile(const std::string &file_name)
SYSTEMATIC dilep PROCESSES ttbar
Definition: high_met.txt:2
void GetOptions(int argc, char *argv[])