ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
make_workspace.cxx
Go to the documentation of this file.
1 #include "make_workspace.hpp"
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <sstream>
6 #include <initializer_list>
7 #include <vector>
8 #include <string>
9 #include <stdlib.h>
10 
11 #include <unistd.h>
12 #include <getopt.h>
13 
14 #include "TString.h"
15 
16 #include "bin.hpp"
17 #include "process.hpp"
18 #include "utilities.hpp"
19 #include "systematic.hpp"
20 #include "cut.hpp"
21 
22 #include "workspace_generator.hpp"
23 
24 using namespace std;
25 
26 
27 namespace{
28  double lumi = 2.246;
29  double sig_strength = 0.;
31  bool no_kappa = false;
32  bool do_syst = true;
33  bool use_r4 = false;
34  string method("m135");
35  string minjets("6");
36  string hijets("9");
37  string himet("400");
38  string mjthresh("400");
39  unsigned n_toys = 0;
40  string identifier = "";
41 }
42 
43 int main(int argc, char *argv[]){
44  cout << fixed << setprecision(2);
45  GetOptions(argc, argv);
46  string midjets(""); midjets += to_string(atoi(hijets.c_str())-1);
47  string minjets2l(""); minjets2l += to_string(atoi(minjets.c_str())-1);
48  string midjets2l(""); midjets2l += to_string(atoi(midjets.c_str())-1);
49 
50  string hostname = execute("echo $HOSTNAME");
51  string basefolder("/net/cms2/cms2r0/babymaker/");
52  if(Contains(hostname, "lxplus")) basefolder = "/afs/cern.ch/user/m/manuelf/work/";
53  string skim("skim_1lht500met200/");
54  string foldermc(basefolder+"babies/2015_11_28/mc/"+skim);
55  string folderdata(basefolder+"babies/2016_02_04/data/singlelep/combined/"+skim);
56 
57  //Define processes. Try to minimize splitting
58  string stitch_cuts("stitch");
59  Process ttbar{"ttbar", {
60  {foldermc+"/*TTJets*Lept*.root/tree"},
61  {foldermc+"/*TTJets_HT*.root/tree"}
62  },stitch_cuts};
63  Process other{"other", {
64  {foldermc+"/*_WJetsToLNu*.root/tree"},
65  {foldermc+"/*_TTWJets*.root/tree"},
66  {foldermc+"/*_TTZTo*.root/tree"},
67  {foldermc+"/*_ST_*.root/tree"},
68  {foldermc+"/*DYJetsToLL*.root/tree"},
69  {foldermc+"/*QCD_HT*.root/tree"},
70  {foldermc+"/*_WWTo*.root/tree"},
71  {foldermc+"/*_TTGJets*.root/tree"},
72  {foldermc+"/*_TTTT*.root/tree"},
73  {foldermc+"/*_WZ*.root/tree"},
74  {foldermc+"/*ttHJetTobb*.root/tree"}
75  },stitch_cuts};
76  Process signal_nc{"signal", {
77  {foldermc+"/*T1tttt*1500*100*.root/tree"}
78  }, Cut(), false, true};
79  Process signal_c{"signal", {
80  {foldermc+"/*T1tttt*1200*800*.root/tree"}
81  }, Cut(), false, true};
82 
83  string data_cuts("(trig[4]||trig[8])&&pass&&nonblind");
84  if(method!="m135") {
85  data_cuts = "(trig[4]||trig[8])&&pass";
86  }
87  Process data{"data", {
88  {folderdata+"/*.root/tree"}
89  }, data_cuts, true};
90 
91  //Make list of all backgrounds. Backgrounds assumed to be orthogonal
92  set<Process> backgrounds{ttbar, other};
93 
94  //Baseline selection applied to all bins and processes
95  Cut baseline{"pass&&mj>250&&ht>500&&met>200&&njets>="+minjets+"&&nbm>=2&&nleps==1"};
96  Cut baseline1b{"pass&&mj>250&&ht>500&&met>200&&njets>="+minjets+"&&nbm>=1&&nleps==1"};
97  Cut baseline2l{"pass&&mj>250&&ht>500&&met>200&&met<=400"};
98  Cut baseline_135{"pass&&mj>250&&ht>450&&met>150"};
99 
100  //Declare bins
101  //Method 2, m1b, and m1bk
102  Bin r1_lowmet_1b{"r1_lowmet_1b", "mt<=140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm==1",
104  Bin r1_highmet_1b{"r1_highmet_1b", "mt<=140&&mj<="+mjthresh+"&&met>"+himet+"&&nbm==1",
106  Bin r1_lowmet_2b{"r1_lowmet_2b", "mt<=140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm==2",
108  Bin r1_lowmet_3b{"r1_lowmet_3b", "mt<=140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm>2",
110  Bin r1_highmet_2b{"r1_highmet_2b", "mt<=140&&mj<="+mjthresh+"&&met>"+himet+"&&nbm>=2",
112 
113  Bin r1_lowmet_allnb{"r1_lowmet_allnb", "mt<=140&&mj<="+mjthresh+"&&met<="+himet,
115  Bin r1_highmet_allnb{"r1_highmet_allnb", "mt<=140&&mj<="+mjthresh+"&&met>"+himet,
117  Bin r1_allnb{"r1_allnb", "mt<=140&&mj<="+mjthresh,
119 
120  Bin r2_lowmet_lownj_1b{"r2_lowmet_lownj_1b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==1",
122  Bin r2_highmet_lownj_1b{"r2_highmet_lownj_1b", "mt<=140&&mj>"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm==1",
124  Bin r2_lowmet_highnj_1b{"r2_lowmet_highnj_1b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==1",
126  Bin r2_highmet_highnj_1b{"r2_highmet_highnj_1b", "mt<=140&&mj>"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm==1",
128  Bin r2_lowmet_lownj_2b{"r2_lowmet_lownj_2b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==2",
130  Bin r2_lowmet_lownj_3b{"r2_lowmet_lownj_3b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm>2",
132  Bin r2_lowmet_highnj_2b{"r2_lowmet_highnj_2b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==2",
134  Bin r2_lowmet_highnj_3b{"r2_lowmet_highnj_3b", "mt<=140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm>2",
136  Bin r2_highmet_lownj_2b{"r2_highmet_lownj_2b", "mt<=140&&mj>"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm>=2",
138  Bin r2_highmet_highnj_2b{"r2_highmet_highnj_2b", "mt<=140&&mj>"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm>=2",
140 
141  Bin r3_lowmet_1b{"r3_lowmet_1b", "mt>140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm==1",
143  Bin r3_highmet_1b{"r3_highmet_1b", "mt>140&&mj<="+mjthresh+"&&met>"+himet+"&&nbm==1",
145  Bin r3_lowmet_2b{"r3_lowmet_2b", "mt>140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm==2",
147  Bin r3_lowmet_3b{"r3_lowmet_3b", "mt>140&&mj<="+mjthresh+"&&met<="+himet+"&&nbm>2",
149  Bin r3_highmet_2b{"r3_highmet_2b", "mt>140&&mj<="+mjthresh+"&&met>"+himet+"&&nbm>=2",
151 
152  Bin r3_lowmet_allnb{"r3_lowmet_allnb", "mt>140&&mj<="+mjthresh+"&&met<="+himet,
154  Bin r3_highmet_allnb{"r3_highmet_allnb", "mt>140&&mj<="+mjthresh+"&&met>"+himet,
156  Bin r3_allnb{"r3_allnb", "mt>140&&mj<="+mjthresh,
158 
159  Bin r4_lowmet_lownj_1b{"r4_lowmet_lownj_1b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==1",
161  Bin r4_highmet_lownj_1b{"r4_highmet_lownj_1b", "mt>140&&mj>"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm==1",
162  blind_level>BlindLevel::unblind_1b};
163  Bin r4_lowmet_highnj_1b{"r4_lowmet_highnj_1b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==1",
164  blind_level>BlindLevel::unblind_1b};
165  Bin r4_highmet_highnj_1b{"r4_highmet_highnj_1b", "mt>140&&mj>"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm==1",
166  blind_level>BlindLevel::unblind_1b};
167 
168  Bin r4_lowmet_lownj_2b{"r4_lowmet_lownj_2b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==2",
170  Bin r4_lowmet_lownj_3b{"r4_lowmet_lownj_3b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm>2",
171  blind_level>BlindLevel::unblinded};
172  Bin r4_lowmet_highnj_2b{"r4_lowmet_highnj_2b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==2",
173  blind_level>BlindLevel::unblinded};
174  Bin r4_lowmet_highnj_3b{"r4_lowmet_highnj_3b", "mt>140&&mj>"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm>2",
175  blind_level>BlindLevel::unblinded};
176  Bin r4_highmet_lownj_2b{"r4_highmet_lownj_2b", "mt>140&&mj>"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm>=2",
177  blind_level>BlindLevel::unblinded};
178  Bin r4_highmet_highnj_2b{"r4_highmet_highnj_2b", "mt>140&&mj>"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm>=2",
179  blind_level>BlindLevel::unblinded};
180 
181  // Dilepton blocks
182  Bin r1c_allnj{"r1c_allnj", "mt<=140&&mj<="+mjthresh+"&&nbm>=1&&njets>="+minjets+"&&nleps==1",
184 
185  Bin r2c_lownj{"r2c_lownj", "mt<=140&&mj>"+mjthresh+"&&nbm>=1&&njets>="+minjets+"&&njets<="+midjets+"&&nleps==1",
187  Bin r2c_highnj{"r2c_highnj", "mt<=140&&mj>"+mjthresh+"&&nbm>=1&&njets>"+midjets+"&&nleps==1",
189 
190  Bin d3_allnj{"d3_allnj", "mj<="+mjthresh+"&&njets>="+minjets2l+"&&nbm<=2&&nleps==2",
192 
193  Bin d4_lownj{"d4_lownj", "mj>"+mjthresh+"&&njets>="+minjets2l+"&&njets<="+midjets2l+"&&nbm<=2&&nleps==2",
195  Bin d4_highnj{"d4_highnj", "mj>"+mjthresh+"&&njets>="+minjets2l+"&&njets>"+midjets2l+"&&nbm<=2&&nleps==2",
197 
198  //Method 135
199  Bin r1{"r1", "mt<=140&&mj<="+mjthresh+"&&njets>="+minjets+"&&nbm>=1&&nleps==1",
201  Bin r2{"r2", "mt<=140&&mj>"+mjthresh+"&&njets>="+minjets+"&&nbm>=1&&nleps==1",
203  Bin r3{"r3", "mt>140&&mj<="+mjthresh+"&&njets>="+minjets+"&&nbm>=1&&nleps==1",
205  Bin r4{"r4", "mt>140&&mj>"+mjthresh+"&&njets>="+minjets+"&&nbm>=1&&nleps==1",
206  blind_level>BlindLevel::unblinded};
207  Bin d3{"d3", "mj<="+mjthresh+"&&njets>="+minjets2l+"&&nbm>=0&&nleps==2",
209  Bin d4{"d4", "mj>"+mjthresh+"&&njets>="+minjets2l+"&&nbm>=0&&nleps==2",
211 
213  set<Block> blocks_1bk{
214  {"lowmet", {{r1_lowmet_allnb, r2_lowmet_lownj_1b, r2_lowmet_highnj_1b, r2_lowmet_lownj_2b, r2_lowmet_highnj_2b,
215  r2_lowmet_lownj_3b, r2_lowmet_highnj_3b},
216  {r3_lowmet_allnb, r4_lowmet_lownj_1b, r4_lowmet_highnj_1b, r4_lowmet_lownj_2b, r4_lowmet_highnj_2b,
217  r4_lowmet_lownj_3b, r4_lowmet_highnj_3b}}},
218  {"highmet", {{r1_highmet_allnb, r2_highmet_lownj_1b, r2_highmet_highnj_1b, r2_highmet_lownj_2b, r2_highmet_highnj_2b},
219  {r3_highmet_allnb, r4_highmet_lownj_1b, r4_highmet_highnj_1b, r4_highmet_lownj_2b, r4_highmet_highnj_2b}}}
220  };
221 
223  set<Block> blocks_135{
224  {"all", {{r1, r2}, {r3, r4}}}
225  };
226 
227  set<Block> blocks_135_2l{
228  {"all", {{r1, r2}, {d3, d4}}}
229  };
230 
232  set<Block> blocks_2l{
233  {"all", {{r1c_allnj, r2c_lownj, r2c_highnj},
234  {d3_allnj, d4_lownj, d4_highnj}}}
235  };
236 
237  Cut *pbaseline(&baseline1b);
238  set<Block> *pblocks(&blocks_1bk);
239  string sysfile("txt/systematics/m1bk.txt");
240  if(method == "m1bk"){
241  pbaseline = &baseline1b;
242  pblocks = &blocks_1bk;
243  sysfile = "txt/systematics/m1bk_c.txt";
244  } else if(method == "m1bk_nodilep"){
245  pbaseline = &baseline1b;
246  pblocks = &blocks_1bk;
247  sysfile = "txt/systematics/m1bk_nodilep.txt";
248  } else if(method == "m1bk_onlydilep"){
249  pbaseline = &baseline1b;
250  pblocks = &blocks_1bk;
251  sysfile = "txt/systematics/m1bk_onlydilep.txt";
252  }else if(method == "m2l"){
253  pbaseline = &baseline2l;
254  pblocks = &blocks_2l;
255  sysfile = "txt/systematics/m2l.txt";
256  }else if(method == "m135"){
257  pbaseline = &baseline_135;
258  pblocks = &blocks_135;
259  sysfile = "txt/systematics/m135.txt";
260  }else if(method == "m135_2l"){
261  pbaseline = &baseline_135;
262  pblocks = &blocks_135_2l;
263  sysfile = "txt/systematics/m135_2l.txt";
264  }
265 
266  TString lumi_s("_lumi"); lumi_s += lumi; lumi_s.ReplaceAll(".","p");
267  lumi_s.ReplaceAll("00000000000001",""); lumi_s.ReplaceAll("39999999999999","4");
268  TString sig_s("_sig"); sig_s += sig_strength; sig_s.ReplaceAll(".","p");
269  sig_s.ReplaceAll("00000000000001","");
270  string blind_name = "";
271  if(blind_level == BlindLevel::unblinded){
272  blind_name = "_unblinded";
273  }else if(blind_level == BlindLevel::unblind_1b){
274  blind_name = "_1bunblinded";
275  }else if(blind_level == BlindLevel::r4_blinded){
276  blind_name = "_r4blinded";
277  }
278  if(identifier != "") identifier = "_" + identifier;
279  string outname(method+(do_syst ? "" : "_nosys")+(use_r4 ? "" : "_nor4")
280  +(no_kappa ? "_nokappa" : "")+string("_c_met")
281  +himet+"_mj"+mjthresh+"_nj"+minjets+hijets
282  +sig_s+lumi_s.Data()+blind_name+identifier+".root");
283 
284  // Compressed SUSY
285  WorkspaceGenerator wgc(*pbaseline, *pblocks, backgrounds, signal_c, data, sysfile, use_r4, sig_strength);
286  wgc.SetKappaCorrected(!no_kappa);
287  wgc.SetDoSystematics(do_syst);
288  wgc.SetLuminosity(lumi);
289  wgc.SetDoDilepton(false); // Applying dilep syst in text file
290  wgc.SetDoSystematics(do_syst);
291  wgc.AddToys(n_toys);
292  ReplaceAll(outname, "_nc_", "_c_");
293  wgc.WriteToFile(outname);
294 
295  // Non-compressed SUSY
296  ReplaceAll(sysfile, "_c", "_nc");
297  WorkspaceGenerator wgnc(*pbaseline, *pblocks, backgrounds, signal_nc, data, sysfile, use_r4, sig_strength);
300  wgnc.SetLuminosity(lumi);
301  wgnc.SetDoDilepton(false); // Applying dilep syst in text file
303  wgnc.AddToys(n_toys);
304  ReplaceAll(outname, "_c_", "_nc_");
305  wgnc.WriteToFile(outname);
306 }
307 
308 void GetOptions(int argc, char *argv[]){
309  while(true){
310  static struct option long_options[] = {
311  {"lumi", required_argument, 0, 'l'},
312  {"unblind", required_argument, 0, 'u'},
313  {"no_syst", no_argument, 0, 0},
314  {"lowj", required_argument, 0, 'j'},
315  {"hij", required_argument, 0, 'h'},
316  {"himet", required_argument, 0, 'm'},
317  {"mj", required_argument, 0, 's'},
318  {"nokappa", no_argument, 0, 'k'},
319  {"method", required_argument, 0, 't'},
320  {"use_r4", no_argument, 0, '4'},
321  {"toys", required_argument, 0, 0},
322  {"sig_strength", required_argument, 0, 'g'},
323  {"identifier", required_argument, 0, 'i'},
324  {0, 0, 0, 0}
325  };
326 
327  char opt = -1;
328  int option_index;
329  opt = getopt_long(argc, argv, "l:u:j:h:m:s:kt:4g:i:", long_options, &option_index);
330  if( opt == -1) break;
331 
332  string optname;
333  switch(opt){
334  case 'l':
335  lumi = atof(optarg);
336  break;
337  case 'g':
338  sig_strength = atof(optarg);
339  break;
340  case 'u':
341  if(string(optarg)=="all"){
343  }else if(string(optarg)=="sideband"){
345  }else if(string(optarg)=="1b"){
347  }else{
349  }
350  break;
351  case 'j':
352  minjets = optarg;
353  break;
354  case 'h':
355  hijets = optarg;
356  break;
357  case 'm':
358  himet = optarg;
359  break;
360  case 'k':
361  no_kappa = true;
362  break;
363  case '4':
364  use_r4 = true;
365  break;
366  case 's':
367  mjthresh = optarg;
368  break;
369  case 't':
370  method = optarg;
371  break;
372  case 'i':
373  identifier = optarg;
374  break;
375  case 0:
376  optname = long_options[option_index].name;
377  if(optname == "no_syst"){
378  do_syst = false;
379  }else if(optname == "toys"){
380  n_toys = atoi(optarg);
381  }else{
382  printf("Bad option! Found option name %s\n", optname.c_str());
383  }
384  break;
385  default:
386  printf("Bad option! getopt_long returned character code 0%o\n", opt);
387  break;
388  }
389  }
390 }
WorkspaceGenerator & SetLuminosity(double luminosity)
Definition: bin.hpp:12
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
void GetOptions(int argc, char *argv[])
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)
WorkspaceGenerator & SetDoDilepton(bool do_systematics)
void WriteToFile(const std::string &file_name)
SYSTEMATIC dilep PROCESSES ttbar
Definition: high_met.txt:2
int main(int argc, char *argv[])
size_t AddToys(size_t num_toys=0)
BlindLevel