ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
dilepton_wspace.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 #include <ctime>
11 
12 #include <unistd.h>
13 #include <getopt.h>
14 
15 #include "TString.h"
16 
17 #include "bin.hpp"
18 #include "process.hpp"
19 #include "utilities.hpp"
20 #include "systematic.hpp"
21 #include "cut.hpp"
22 
23 #include "workspace_generator.hpp"
24 
25 using namespace std;
26 
27 
28 namespace{
29  double lumi = 0.815;
30  double sig_strength = 0.;
32  bool no_kappa = false;
33  bool do_syst = false;
34  bool use_r4 = false;
35  TString method("m2lveto");
36  string minjets("6");
37  string hijets("9");
38  string himet("400");
39  string mjthresh("400");
40  unsigned n_toys = 0;
41  string identifier = "";
42 }
43 
44 int main(int argc, char *argv[]){
45  time_t begtime, endtime;
46  time(&begtime);
47  cout << fixed << setprecision(2);
48  GetOptions(argc, argv);
49  string midjets(""); midjets += to_string(atoi(hijets.c_str())-1);
50  string minjets2l(""); minjets2l += to_string(atoi(minjets.c_str())-1);
51  string midjets2l(""); midjets2l += to_string(atoi(midjets.c_str())-1);
52 
53  string hostname = execute("echo $HOSTNAME");
54  string bfolder("/net/cms2/cms2r0/babymaker/");
55  if(Contains(hostname, "lxplus")) bfolder = "/afs/cern.ch/user/m/manuelf/work/";
56  TString foldermc(bfolder+"babies/2016_06_14/mc/merged_standard/");
57  TString folderdata(bfolder+"babies/2016_06_14/data/skim_standard/");
58  if(method.Contains("met150")){
59  foldermc = bfolder+"babies/2016_06_14/mc/merged_1lht500met150nj5/";
60  folderdata = bfolder+"babies/2016_06_14/data/merged_1lht500met150nj5/";
61  }
62 
63  cout<<"folderdata is "<<folderdata<<endl;
64  cout<<"foldermc is "<<foldermc<<endl;
65  //Define processes. Try to minimize splitting
66  string stitch_cuts("stitch");
67  Process ttbar{"ttbar", {
68  {foldermc+"/*TTJets*Lept*.root/tree"},
69  {foldermc+"/*TTJets_HT*.root/tree"}
70  },stitch_cuts};
71  Process other{"other", {
72  {foldermc+"/*_WJetsToLNu*.root/tree"},
73  {foldermc+"/*_TTWJets*.root/tree"},
74  {foldermc+"/*_TTZTo*.root/tree"},
75  {foldermc+"/*_ST_*.root/tree"},
76  {foldermc+"/*DYJetsToLL*.root/tree"},
77  {foldermc+"/*QCD_HT*.root/tree"},
78  {foldermc+"/*_WWTo*.root/tree"},
79  {foldermc+"/*_TTGJets*.root/tree"},
80  {foldermc+"/*_TTTT*.root/tree"},
81  {foldermc+"/*_WZ*.root/tree"},
82  {foldermc+"/*_ZZ*.root/tree"},
83  {foldermc+"/*_ZJet*.root/tree"},
84  {foldermc+"/*_WH_HToBB*.root/tree"},
85  {foldermc+"/*_ZH_HToBB*.root/tree"},
86  // {foldermc+"/*ggZH_HToBB*.root/tree"},
87  {foldermc+"/*ttHJetTobb*.root/tree"}
88  },stitch_cuts};
89  Process signal_nc{"signal", {
90  {foldermc+"/*T1tttt*1500*-100_*.root/tree"}
91  }, Cut(), false, true};
92  Process signal_c{"signal", {
93  {foldermc+"/*T1tttt*1200*800*.root/tree"}
94  }, Cut(), false, true};
95 
96  string data_cuts("(trig[4]||trig[8]||trig[13]||trig[33])&&nonblind");
97  Process data{"data", {
98  {folderdata+"/*.root/tree"}
99  }, data_cuts, true};
100 
101  //Make list of all backgrounds. Backgrounds assumed to be orthogonal
102  set<Process> backgrounds{ttbar, other};
103 
104  //Baseline selection applied to all bins and processes
105  Cut baseline2l{"pass&&ht>500&&met>150&&met<=500"};
106 
107  // Cuts regions
108  string c_r1="mt<=140 && mj14>250&&mj14<=400";
109  string c_r2="mt<=140 && mj14>400";
110  string c_r3="mj14>250&&mj14<=400"; // mt>140 cut only applied to nveto==1
111  string c_r4="mj14>400"; // mt>140 cut only applied to nveto==1
112 
113  // Cuts MET
114  string c_lowmet="&&met>200&&met<=350";
115  string c_midmet="&&met>350&&met<=500";
116  if (method.Contains("met150")){
117  c_lowmet="&&met>150&&met<=200";
118  }
119  cout<<"c_lowmet is "<<c_lowmet<<endl;
120  // Cuts njets
121  string c_allnj="&&njets>="+minjets;
122  string c_lownj="&&njets>="+minjets+"&&njets<="+midjets;
123  string c_hignj="&&njets>"+midjets;
124  string c_allnj2l="&&njets>="+minjets2l;
125  string c_lownj2l="&&njets>="+minjets2l+"&&njets<="+midjets2l;
126  string c_hignj2l="&&njets>"+midjets2l;
127 
128  // Cuts leptons, veto, nbm
129  string c_1l="&&nleps==1&&nveto==0&&nbm>=1";
130  string c_2l="nleps==2&&nbm<=2";
131  string c_veto="nleps==1&&nveto==1&&nbm>=1&&nbm<=2&&mt>140";
132 
133  // Cuts combination 2l + veto
134  string c_2lvetoallnj="&&(("+c_2l+c_allnj2l+")||("+c_veto+c_allnj+"))";
135  string c_2lvetolownj="&&(("+c_2l+c_lownj2l+")||("+c_veto+c_lownj+"))";
136  string c_2lvetohignj="&&(("+c_2l+c_hignj2l+")||("+c_veto+c_hignj+"))";
137  c_2l = "&&"+c_2l; c_veto = "&&"+c_veto;
138 
139  // Methods m2l, mveto, m2lveto
140  string c_2ltotallnj = c_2l+c_allnj2l, c_2ltotlownj = c_2l+c_lownj2l, c_2ltothignj = c_2l+c_hignj2l;
141  if(method.Contains("mveto")) {
142  c_2ltotallnj = c_veto+c_allnj;
143  c_2ltotlownj = c_veto+c_lownj;
144  c_2ltothignj = c_veto+c_hignj;
145  }
146  if(method.Contains("m2lveto")) {
147  c_2ltotallnj = c_2lvetoallnj;
148  c_2ltotlownj = c_2lvetolownj;
149  c_2ltothignj = c_2lvetohignj;
150  }
151 
152  cout<<c_r1 + c_1l + c_lowmet + c_allnj<<endl;
153  cout<<c_r2 + c_1l + c_lowmet + c_lownj<<endl;
154  cout<<c_r2 + c_1l + c_lowmet + c_hignj<<endl;
155  cout<< c_r3 + c_2ltotallnj + c_lowmet<<endl;
156  cout<< c_r4 + c_2ltotlownj + c_lowmet<<endl;
157  cout<< c_r4 + c_2ltothignj + c_lowmet<<endl;
158 
159 
161  // Low MET: 200 < MET <= 350
162  Bin r1_lowmet_allnj{"r1_lowmet_allnj", c_r1 + c_1l + c_lowmet + c_allnj, blind_level>=BlindLevel::blinded};
163 
164  Bin r2_lowmet_lownj{"r2_lowmet_lownj", c_r2 + c_1l + c_lowmet + c_lownj, blind_level>=BlindLevel::blinded};
165  Bin r2_lowmet_hignj{"r2_lowmet_hignj", c_r2 + c_1l + c_lowmet + c_hignj, blind_level>=BlindLevel::blinded};
166 
167  Bin d3_lowmet_allnj{"d3_lowmet_allnj", c_r3 + c_2ltotallnj + c_lowmet, blind_level>=BlindLevel::blinded};
168 
169  Bin d4_lowmet_lownj{"d4_lowmet_lownj", c_r4 + c_2ltotlownj + c_lowmet, blind_level>=BlindLevel::blinded};
170  Bin d4_lowmet_hignj{"d4_lowmet_hignj", c_r4 + c_2ltothignj + c_lowmet, blind_level>=BlindLevel::blinded};
171 
172 
173  // Mid MET: 350 < MET <= 500
174  Bin r1_midmet_allnj{"r1_midmet_allnj", c_r1 + c_1l + c_midmet + c_allnj, blind_level>=BlindLevel::blinded};
175 
176  Bin r2_midmet_lownj{"r2_midmet_lownj", c_r2 + c_1l + c_midmet + c_lownj, blind_level>=BlindLevel::blinded};
177  Bin r2_midmet_hignj{"r2_midmet_hignj", c_r2 + c_1l + c_midmet + c_hignj, blind_level>=BlindLevel::blinded};
178 
179  Bin d3_midmet_allnj{"d3_midmet_allnj", c_r3 + c_2ltotallnj + c_midmet, blind_level>=BlindLevel::blinded};
180 
181  Bin d4_midmet_lownj{"d4_midmet_lownj", c_r4 + c_2ltotlownj + c_midmet, blind_level>=BlindLevel::blinded};
182  Bin d4_midmet_hignj{"d4_midmet_hignj", c_r4 + c_2ltothignj + c_midmet, blind_level>=BlindLevel::blinded};
183 
184 
185 
186 
188  set<Block> blocks_2l{
189  {"lowmet", {{r1_lowmet_allnj, r2_lowmet_lownj, r2_lowmet_hignj},
190  {d3_lowmet_allnj, d4_lowmet_lownj, d4_lowmet_hignj}}},
191  {"midmet", {{r1_midmet_allnj, r2_midmet_lownj, r2_midmet_hignj},
192  {d3_midmet_allnj, d4_midmet_lownj, d4_midmet_hignj}}}
193  };
194 
195  if(method.Contains("met150")){
196  blocks_2l = {
197  {"lowmet", {{r1_lowmet_allnj, r2_lowmet_lownj, r2_lowmet_hignj},
198  {d3_lowmet_allnj, d4_lowmet_lownj, d4_lowmet_hignj}}}
199  };
200  }
201 
202  Cut *pbaseline(&baseline2l);
203  set<Block> *pblocks(&blocks_2l);
204  string sysfile("txt/systematics/m1bk.txt");
205  if(method == "m2l"){
206  pbaseline = &baseline2l;
207  pblocks = &blocks_2l;
208  sysfile = "txt/systematics/m2l.txt";
209  }
210 
211  TString lumi_s("_lumi"); lumi_s += lumi; lumi_s.ReplaceAll(".","p");
212  lumi_s.ReplaceAll("00000000000001",""); lumi_s.ReplaceAll("39999999999999","4"); lumi_s.ReplaceAll("499999999999995","5");
213  TString sig_s("_sig"); sig_s += sig_strength; sig_s.ReplaceAll(".","p");
214  sig_s.ReplaceAll("00000000000001","");
215  string blind_name = "";
217  blind_name = "_unblinded";
218  }else if(blind_level == BlindLevel::unblind_1b){
219  blind_name = "_1bunblinded";
220  }else if(blind_level == BlindLevel::r4_blinded){
221  blind_name = "_r4blinded";
222  }
223  if(identifier != "") identifier = "_" + identifier;
224  string outname(method+(do_syst ? "" : "_nosys")+(use_r4 ? "" : "_nor4")
225  +(no_kappa ? "_nokappa" : "")+string("_c_met")
226  +himet+"_mj"+mjthresh+"_nj"+minjets+hijets
227  +sig_s+lumi_s.Data()+blind_name+identifier+".root");
228 
229  // Compressed SUSY
230  WorkspaceGenerator wgc(*pbaseline, *pblocks, backgrounds, signal_c, data, sysfile, use_r4, sig_strength);
231  wgc.SetKappaCorrected(!no_kappa);
232  wgc.SetDoSystematics(do_syst);
233  wgc.SetLuminosity(lumi);
234  wgc.SetDoDilepton(false); // Applying dilep syst in text file
235  wgc.SetDoSystematics(do_syst);
236  wgc.AddToys(n_toys);
237  ReplaceAll(outname, "_nc_", "_c_");
238  wgc.WriteToFile(outname);
239 
240  // Non-compressed SUSY
241  ReplaceAll(sysfile, "_c", "_nc");
242  WorkspaceGenerator wgnc(*pbaseline, *pblocks, backgrounds, signal_nc, data, sysfile, use_r4, sig_strength);
245  wgnc.SetLuminosity(lumi);
246  wgnc.SetDoDilepton(false); // Applying dilep syst in text file
248  wgnc.AddToys(n_toys);
249  ReplaceAll(outname, "_c_", "_nc_");
250  wgnc.WriteToFile(outname);
251 
252  time(&endtime);
253  cout<<"Finding workspaces took "<<difftime(endtime, begtime)<<" seconds"<<endl<<endl;
254 }
255 
256 void GetOptions(int argc, char *argv[]){
257  while(true){
258  static struct option long_options[] = {
259  {"lumi", required_argument, 0, 'l'},
260  {"unblind", required_argument, 0, 'u'},
261  {"do_syst", no_argument, 0, 0},
262  {"lowj", required_argument, 0, 'j'},
263  {"hij", required_argument, 0, 'h'},
264  {"himet", required_argument, 0, 'm'},
265  {"mj", required_argument, 0, 's'},
266  {"nokappa", no_argument, 0, 'k'},
267  {"method", required_argument, 0, 't'},
268  {"use_r4", no_argument, 0, '4'},
269  {"toys", required_argument, 0, 0},
270  {"sig_strength", required_argument, 0, 'g'},
271  {"identifier", required_argument, 0, 'i'},
272  {0, 0, 0, 0}
273  };
274 
275  char opt = -1;
276  int option_index;
277  opt = getopt_long(argc, argv, "l:u:j:h:m:s:kt:4g:i:", long_options, &option_index);
278  if( opt == -1) break;
279 
280  string optname;
281  switch(opt){
282  case 'l':
283  lumi = atof(optarg);
284  break;
285  case 'g':
286  sig_strength = atof(optarg);
287  break;
288  case 'u':
289  if(string(optarg)=="all"){
291  }else if(string(optarg)=="sideband"){
293  }else if(string(optarg)=="1b"){
295  }else{
297  }
298  break;
299  case 'j':
300  minjets = optarg;
301  break;
302  case 'h':
303  hijets = optarg;
304  break;
305  case 'm':
306  himet = optarg;
307  break;
308  case 'k':
309  no_kappa = true;
310  break;
311  case '4':
312  use_r4 = true;
313  break;
314  case 's':
315  mjthresh = optarg;
316  break;
317  case 't':
318  method = optarg;
319  break;
320  case 'i':
321  identifier = optarg;
322  break;
323  case 0:
324  optname = long_options[option_index].name;
325  if(optname == "do_syst"){
326  do_syst = true;
327  }else if(optname == "toys"){
328  n_toys = atoi(optarg);
329  }else{
330  printf("Bad option! Found option name %s\n", optname.c_str());
331  }
332  break;
333  default:
334  printf("Bad option! getopt_long returned character code 0%o\n", opt);
335  break;
336  }
337  }
338 }
WorkspaceGenerator & SetLuminosity(double luminosity)
Definition: bin.hpp:12
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
int main(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 GetOptions(int argc, char *argv[])
void WriteToFile(const std::string &file_name)
SYSTEMATIC dilep PROCESSES ttbar
Definition: high_met.txt:2
size_t AddToys(size_t num_toys=0)
BlindLevel