ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
wspace_sig.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 #include <sys/stat.h>
12 
13 #include <unistd.h>
14 #include <getopt.h>
15 
16 #include "TString.h"
17 #include "TSystem.h"
18 #include "TDirectory.h"
19 
20 #include "bin.hpp"
21 #include "process.hpp"
22 #include "utilities.hpp"
23 #include "systematic.hpp"
24 #include "cut.hpp"
25 #include "cross_sections.hpp"
26 
27 #include "workspace_generator.hpp"
28 
29 using namespace std;
30 
31 namespace{
32  double lumi = 35.9;
33  double sig_strength = 0.;
35  bool no_kappa = false;
36  bool do_syst = true;
37  bool use_r4 = true;
38  bool applyVeto = true;
39  string binning = "alternate";
40  string minjets("6");
41  string hijets("9");
42  string medmet("350");
43  string himet("400");
44  string vhimet("500");
45  string mjdef("mj14");
46  string lowmjthresh("250");
47  string mjthresh("400");
48  unsigned n_toys = 0;
49  string sigfile = "";
50  string injfile = "";
51  bool inject_other_model = false;
52  bool dummy_syst = false;
53  string dummy_syst_file = "";
54  string outfolder = "out/";
55  bool nom_only = false;
56  bool use_pois = false;
57 }
58 //nbm = Sum$(jets_csv>CSVM&&jets_pt>30&&!jets_islep)
59 int main(int argc, char *argv[]){
60  time_t begtime, endtime;
61  time(&begtime);
62  cout << fixed << setprecision(2);
63  GetOptions(argc, argv);
64  if(sigfile==""){
65  cout<<endl<<"You need to specify the input file with -f. Exiting"<<endl<<endl;
66  return 1;
67  }
68  string midjets = to_string(atoi(hijets.c_str())-1);
69  string minjets2l = to_string(atoi(minjets.c_str())-1);
70  string midjets2l = to_string(atoi(midjets.c_str())-1);
71 
72  string hostname = execute("echo $HOSTNAME");
73  string basefolder("/net/cms2/cms2r0/babymaker/");
74  if(Contains(hostname, "lxplus")) basefolder = "/afs/cern.ch/user/m/manuelf/work/";
75  string foldermc(basefolder+"babies/2017_01_27/mc/merged_mcbase_abcd/");
76  string folderdata(basefolder+"babies/2017_02_14/data/merged_database_abcd/");
77 
78  cout<<"binning is "<<binning<<endl;
79  if(applyVeto) cout<<"apply veto"<<endl;
80  else cout<<"no veto"<<endl;
81 
82  cout<<"mj is "<<mjdef<<endl;
83  cout<<"lumi is "<<to_string(lumi)<<endl;
84  cout<<"outfolder is "<<outfolder<<endl;
85 
86  //Define processes. Try to minimize splitting
87  string stitch_cuts("stitch_met&&pass");
88 
89  Process ttbar{"ttbar", set<string>{
90  foldermc+"/*_TTJets*Lept*.root/tree",
91  },stitch_cuts};
92  Process other{"other", {
93  {foldermc+"/*_WJetsToLNu*.root/tree",
94  foldermc+"/*_ST_*.root/tree",
95  foldermc+"/*_TTW*.root/tree",
96  foldermc+"/*_TTZ*.root/tree",
97  foldermc+"/*DYJetsToLL*.root/tree",
98  foldermc+"/*_ZJet*.root/tree",
99  foldermc+"/*_ttHJetTobb*.root/tree",
100  foldermc+"/*_TTGJets*.root/tree",
101  foldermc+"/*_TTTT*.root/tree",
102  foldermc+"/*_WH_HToBB*.root/tree",
103  foldermc+"/*_ZH_HToBB*.root/tree",
104  foldermc+"/*_WWTo*.root/tree",
105  foldermc+"/*_WZ*.root/tree",
106  foldermc+"/*_ZZ_*.root/tree",
107  foldermc+"/*QCD_HT*0_Tune*.root/tree",
108  foldermc+"/*QCD_HT*Inf_Tune*.root/tree"}
109  },stitch_cuts};
110  Process signal{"signal", {
111  {sigfile+"/tree"}
112  },"stitch", false, true};
113  Process injection{"injection", {
114  {injfile+"/tree"}
115  },"stitch", false, true};
116 
117  string data_cuts("trig_ra4&&pass");
118 
119  Process data{"data", {
120  {folderdata+"/*.root/tree"}
121  }, data_cuts, true};
122 
123  //Make list of all backgrounds. Backgrounds assumed to be orthogonal
124  set<Process> backgrounds{ttbar, other};
125 
126  //Baseline selection applied to all bins and processes
127  Cut baseline1b{"met/met_calo<5.&&pass_ra2_badmu&&st>500&&met>200&&nleps==1&&nbm>=1&&njets>="+minjets+"&&"+mjdef+">"+lowmjthresh};
128  string veto("");
129  if(applyVeto)
130  veto = "&&nveto==0";
131 
132  set<Block> blocks_1bk;
133 
134  //Declare bins
135  if(binning=="debug"){
136  Bin r1{"r1", "mt<=140&&"+mjdef+"<="+mjthresh+veto+"&&met>350&&met<=500",
138  Bin r2{"r2", "mt<=140&&"+mjdef+">"+mjthresh+veto+"&&met>350&&met<=500&&nbm==2&&njets>=6&&njets<=8",
140  Bin r3{"r3", "mt>140&&"+mjdef+"<="+mjthresh+veto+"&&met>350&&met<=500",
142  Bin r4{"r4", "mt>140&&"+mjdef+">"+mjthresh+veto+"&&met>350&&met<=500&&nbm==2&&njets>=6&&njets<=8",
144  blocks_1bk = {
145  {"inclusive", {{r1,r2},{r3,r4}}}
146  };
147  }else if(binning=="nominal"){
148  Bin r1_lowmet_allnb{"r1_lowmet_allnb", "mt<=140&&"+mjdef+"<="+mjthresh+"&&met<="+himet,
150  Bin r1_highmet_allnb{"r1_highmet_allnb", "mt<=140&&"+mjdef+"<="+mjthresh+"&&met>"+himet,
152 
153  Bin r2_lowmet_lownj_1b{"r2_lowmet_lownj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==1",
155  Bin r2_lowmet_highnj_1b{"r2_lowmet_highnj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==1",
157  Bin r2_lowmet_lownj_2b{"r2_lowmet_lownj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==2",
159  Bin r2_lowmet_lownj_3b{"r2_lowmet_lownj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm>2",
161  Bin r2_lowmet_highnj_2b{"r2_lowmet_highnj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==2",
163  Bin r2_lowmet_highnj_3b{"r2_lowmet_highnj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm>2",
165 
166  Bin r2_highmet_lownj_1b{"r2_highmet_lownj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm==1",
168  Bin r2_highmet_highnj_1b{"r2_highmet_highnj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm==1",
170  Bin r2_highmet_lownj_2b{"r2_highmet_lownj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm>=2",
172  Bin r2_highmet_highnj_2b{"r2_highmet_highnj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm>=2",
174 
175  Bin r3_lowmet_allnb{"r3_lowmet_allnb", "mt>140&&"+mjdef+"<="+mjthresh+"&&met<="+himet+veto,
177  Bin r3_highmet_allnb{"r3_highmet_allnb", "mt>140&&"+mjdef+"<="+mjthresh+"&&met>"+himet+veto,
179 
180  Bin r4_lowmet_lownj_1b{"r4_lowmet_lownj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==1"+veto,
182  Bin r4_lowmet_highnj_1b{"r4_lowmet_highnj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==1"+veto,
183  blind_level>BlindLevel::unblind_1b};
184  Bin r4_lowmet_lownj_2b{"r4_lowmet_lownj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm==2"+veto,
186  Bin r4_lowmet_lownj_3b{"r4_lowmet_lownj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets<="+midjets+"&&nbm>2"+veto,
187  blind_level>BlindLevel::unblinded};
188  Bin r4_lowmet_highnj_2b{"r4_lowmet_highnj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm==2"+veto,
189  blind_level>BlindLevel::unblinded};
190  Bin r4_lowmet_highnj_3b{"r4_lowmet_highnj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+himet+"&&njets>"+midjets+"&&nbm>2"+veto,
191  blind_level>BlindLevel::unblinded};
192 
193  Bin r4_highmet_lownj_1b{"r4_highmet_lownj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm==1"+veto,
194  blind_level>BlindLevel::unblind_1b};
195  Bin r4_highmet_highnj_1b{"r4_highmet_highnj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm==1"+veto,
196  blind_level>BlindLevel::unblind_1b};
197  Bin r4_highmet_lownj_2b{"r4_highmet_lownj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets<="+midjets+"&&nbm>=2"+veto,
198  blind_level>BlindLevel::unblinded};
199  Bin r4_highmet_highnj_2b{"r4_highmet_highnj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+himet+"&&njets>"+midjets+"&&nbm>=2"+veto,
200  blind_level>BlindLevel::unblinded};
201 
203  blocks_1bk = {
204  {"lowmet", {{r1_lowmet_allnb, r2_lowmet_lownj_1b, r2_lowmet_highnj_1b, r2_lowmet_lownj_2b, r2_lowmet_highnj_2b,
205  r2_lowmet_lownj_3b, r2_lowmet_highnj_3b},
206  {r3_lowmet_allnb, r4_lowmet_lownj_1b, r4_lowmet_highnj_1b, r4_lowmet_lownj_2b, r4_lowmet_highnj_2b,
207  r4_lowmet_lownj_3b, r4_lowmet_highnj_3b}}},
208  {"highmet", {{r1_highmet_allnb, r2_highmet_lownj_1b, r2_highmet_highnj_1b, r2_highmet_lownj_2b, r2_highmet_highnj_2b},
209  {r3_highmet_allnb, r4_highmet_lownj_1b, r4_highmet_highnj_1b, r4_highmet_lownj_2b, r4_highmet_highnj_2b}}}
210  };
211  }
212  else if(binning=="alternate"){
213 
214  Bin r1_lowmet_allnb{"r1_lowmet_allnb", "mt<=140&&"+mjdef+"<="+mjthresh+"&&met<="+medmet+veto,
216  Bin r1_medmet_allnb{"r1_medmet_allnb", "mt<=140&&"+mjdef+"<="+mjthresh+"&&met>"+medmet+"&&met<="+vhimet+veto,
218  Bin r1_highmet_allnb{"r1_highmet_allnb", "mt<=140&&"+mjdef+"<="+mjthresh+"&&met>"+vhimet+veto,
220 
221  Bin r2_lowmet_lownj_1b{"r2_lowmet_lownj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm==1"+veto,
223  Bin r2_lowmet_highnj_1b{"r2_lowmet_highnj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm==1"+veto,
225  Bin r2_lowmet_lownj_2b{"r2_lowmet_lownj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm==2"+veto,
227  Bin r2_lowmet_lownj_3b{"r2_lowmet_lownj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm>2"+veto,
229  Bin r2_lowmet_highnj_2b{"r2_lowmet_highnj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm==2"+veto,
231  Bin r2_lowmet_highnj_3b{"r2_lowmet_highnj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm>2"+veto,
233 
234 
235  Bin r2_medmet_lownj_1b{"r2_medmet_lownj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm==1"+veto,
237  Bin r2_medmet_highnj_1b{"r2_medmet_highnj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm==1"+veto,
239  Bin r2_medmet_lownj_2b{"r2_medmet_lownj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm==2"+veto,
241  Bin r2_medmet_lownj_3b{"r2_medmet_lownj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm>2"+veto,
243  Bin r2_medmet_highnj_2b{"r2_medmet_highnj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm==2"+veto,
245  Bin r2_medmet_highnj_3b{"r2_medmet_highnj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm>2"+veto,
247 
248  Bin r2_highmet_lownj_1b{"r2_highmet_lownj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm==1"+veto,
250  Bin r2_highmet_highnj_1b{"r2_highmet_highnj_1b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm==1"+veto,
252  Bin r2_highmet_lownj_2b{"r2_highmet_lownj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm==2"+veto,
254  Bin r2_highmet_lownj_3b{"r2_highmet_lownj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm>2"+veto,
256  Bin r2_highmet_highnj_2b{"r2_highmet_highnj_2b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm==2"+veto,
258  Bin r2_highmet_highnj_3b{"r2_highmet_highnj_3b", "mt<=140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm>2"+veto,
260 
261  Bin r3_lowmet_allnb{"r3_lowmet_allnb", "mt>140&&"+mjdef+"<="+mjthresh+"&&met<="+medmet+veto,
263  Bin r3_medmet_allnb{"r3_medmet_allnb", "mt>140&&"+mjdef+"<="+mjthresh+"&&met>"+medmet+"&&met<="+vhimet+veto,
265  Bin r3_highmet_allnb{"r3_highmet_allnb", "mt>140&&"+mjdef+"<="+mjthresh+"&&met>"+vhimet+veto,
267 
268  Bin r4_lowmet_lownj_1b{"r4_lowmet_lownj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm==1"+veto,
270  Bin r4_lowmet_highnj_1b{"r4_lowmet_highnj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm==1"+veto,
271  blind_level>BlindLevel::unblind_1b};
272  Bin r4_lowmet_lownj_2b{"r4_lowmet_lownj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm==2"+veto,
274  Bin r4_lowmet_lownj_3b{"r4_lowmet_lownj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets<="+midjets+"&&nbm>2"+veto,
275  blind_level>BlindLevel::unblinded};
276  Bin r4_lowmet_highnj_2b{"r4_lowmet_highnj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm==2"+veto,
277  blind_level>BlindLevel::unblinded};
278  Bin r4_lowmet_highnj_3b{"r4_lowmet_highnj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+medmet+"&&njets>"+midjets+"&&nbm>2"+veto,
279  blind_level>BlindLevel::unblinded};
280 
281 
282  Bin r4_medmet_lownj_1b{"r4_medmet_lownj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm==1"+veto,
283  blind_level>BlindLevel::unblind_1b};
284  Bin r4_medmet_highnj_1b{"r4_medmet_highnj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm==1"+veto,
285  blind_level>BlindLevel::unblind_1b};
286  Bin r4_medmet_lownj_2b{"r4_medmet_lownj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm==2"+veto,
287  blind_level>BlindLevel::unblinded};
288  Bin r4_medmet_lownj_3b{"r4_medmet_lownj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets<="+midjets+"&&nbm>2"+veto,
289  blind_level>BlindLevel::unblinded};
290  Bin r4_medmet_highnj_2b{"r4_medmet_highnj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm==2"+veto,
291  blind_level>BlindLevel::unblinded};
292  Bin r4_medmet_highnj_3b{"r4_medmet_highnj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met<="+vhimet+"&&met>"+medmet+"&&njets>"+midjets+"&&nbm>2"+veto,
293  blind_level>BlindLevel::unblinded};
294 
295  Bin r4_highmet_lownj_1b{"r4_highmet_lownj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm==1"+veto,
296  blind_level>BlindLevel::unblind_1b};
297  Bin r4_highmet_highnj_1b{"r4_highmet_highnj_1b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm==1"+veto,
298  blind_level>BlindLevel::unblind_1b};
299  Bin r4_highmet_lownj_2b{"r4_highmet_lownj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm==2"+veto,
300  blind_level>BlindLevel::unblinded};
301  Bin r4_highmet_lownj_3b{"r4_highmet_lownj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets<="+midjets+"&&nbm>2"+veto,
302  blind_level>BlindLevel::unblinded};
303  Bin r4_highmet_highnj_2b{"r4_highmet_highnj_2b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm==2"+veto,
304  blind_level>BlindLevel::unblinded};
305  Bin r4_highmet_highnj_3b{"r4_highmet_highnj_3b", "mt>140&&"+mjdef+">"+mjthresh+"&&met>"+vhimet+"&&njets>"+midjets+"&&nbm>2"+veto,
306  blind_level>BlindLevel::unblinded};
307 
308  blocks_1bk = {
309  {"lowmet", {{r1_lowmet_allnb, r2_lowmet_lownj_1b, r2_lowmet_lownj_2b, r2_lowmet_lownj_3b, r2_lowmet_highnj_1b,
310  r2_lowmet_highnj_2b, r2_lowmet_highnj_3b},
311  {r3_lowmet_allnb, r4_lowmet_lownj_1b, r4_lowmet_lownj_2b, r4_lowmet_lownj_3b, r4_lowmet_highnj_1b,
312  r4_lowmet_highnj_2b, r4_lowmet_highnj_3b}}},
313  {"medmet", {{r1_medmet_allnb, r2_medmet_lownj_1b, r2_medmet_lownj_2b, r2_medmet_lownj_3b, r2_medmet_highnj_1b,
314  r2_medmet_highnj_2b, r2_medmet_highnj_3b},
315  {r3_medmet_allnb, r4_medmet_lownj_1b, r4_medmet_lownj_2b, r4_medmet_lownj_3b, r4_medmet_highnj_1b,
316  r4_medmet_highnj_2b, r4_medmet_highnj_3b}}},
317  {"highmet", {{r1_highmet_allnb, r2_highmet_lownj_1b, r2_highmet_lownj_2b, r2_highmet_lownj_3b, r2_highmet_highnj_1b,
318  r2_highmet_highnj_2b, r2_highmet_highnj_3b},
319  {r3_highmet_allnb, r4_highmet_lownj_1b, r4_highmet_lownj_2b, r4_highmet_lownj_3b, r4_highmet_highnj_1b,
320  r4_highmet_highnj_2b, r4_highmet_highnj_3b}}}
321  };
322  }
323 
324 
326  int mglu, mlsp;
327  parseMasses(sigfile, mglu, mlsp);
328  string glu_lsp("mGluino-"+to_string(mglu)+"_mLSP-"+to_string(mlsp));
329 
331  Cut *pbaseline(&baseline1b);
332  set<Block> *pblocks(&blocks_1bk);
333  string model = "T1tttt";
334 
335  string sysfolder = "/net/cms2/cms2r0/babymaker/sys/2017_02_22/T1tttt_fakePU/";
336  //Protect default
337  if(binning=="nominal" && lumi < 3) sysfolder = "/net/cms2/cms2r0/babymaker/sys/2016_01_11/scan/";
338 
339  if(Contains(hostname, "lxplus")) sysfolder = "txt/systematics/";
340  if(Contains(sigfile, "T5tttt")) {
341  sysfolder = "/net/cms2/cms2r0/babymaker/sys/2017_02_22/T5tttt_fakePU/";
342  model = "T5tttt";
343  }
344  if(Contains(sigfile, "T2tt")) {
345  sysfolder = "/net/cms2/cms2r0/babymaker/sys/2016_02_09/T2tt/";
346  model = "T2tt";
347  }
348  if(Contains(sigfile, "T6ttWW")) {
349  sysfolder = "/net/cms2/cms2r0/babymaker/sys/2016_02_09/T6ttWW/";
350  model = "T6ttWW";
351  }
352  cout<<"sysfolder is "<<sysfolder<<endl;
353 
354  // string sysfile(sysfolder+"sys_SMS-"+model+"_"+glu_lsp+"_"+to_string(lumi)+"ifb");
355  string sysfile(sysfolder+"sys_SMS-"+model+"_"+glu_lsp+"_35.9ifb");
356  if(binning!="alternate") sysfile+="_nominal.txt";
357 
358  if(binning=="nominal" && lumi < 3) sysfile = sysfolder+"sys_SMS-"+model+"_"+glu_lsp+".txt";
359  if(dummy_syst) sysfile = dummy_syst_file;
360  cout<<"sysfile is "<<sysfile<<endl;
361  // If systematic file does not exist, use m1bk_nc for tests
362  struct stat buffer;
363  if(stat (sysfile.c_str(), &buffer) != 0) {
364  cout<<endl<<"WARNING: "<<sysfile<<" does not exist. Using ";
365  sysfile = "txt/systematics/m1bk_nc.txt";
366  cout<<sysfile<<" instead"<<endl<<endl;
367  }
368 
369  // Cross sections
370  float xsec, xsec_unc;
371  if(model=="T1tttt" || model=="T5tttt") xsec::signalCrossSection(mglu, xsec, xsec_unc);
372  else xsec::stopCrossSection(mglu, xsec, xsec_unc);
373  double rmax = 20.;
374  if(mglu <= 1500 && mlsp <= 800){
375  rmax = 5.;
376  if(mglu <= 1200 && mlsp <= 550){
377  rmax = 1.25;
378  if(mglu <= 900 && mlsp <= 350){
379  rmax = 0.5;
380  }
381  }
382  }
383 
384  gSystem->mkdir(outfolder.c_str(), kTRUE);
385  string outname(outfolder+"/wspace_"+model+"_"+glu_lsp+"_xsecNom.root");
386  if(!use_r4) ReplaceAll(outname, "wspace_","wspace_nor4_");
387  if(no_kappa) ReplaceAll(outname, "wspace_","wspace_nokappa_");
388  if(!do_syst) ReplaceAll(outname, "wspace_","wspace_nosyst_");
389 
390  WorkspaceGenerator wgNom(*pbaseline, *pblocks, backgrounds, signal, data, sysfile, use_r4, sig_strength, 1.);
391  wgNom.UseGausApprox(!use_pois);
392  wgNom.SetRMax(rmax);
393  wgNom.SetKappaCorrected(!no_kappa);
394  wgNom.SetLuminosity(lumi);
395  wgNom.SetDoSystematics(do_syst);
396  if(inject_other_model){
397  wgNom.SetInjectionModel(injection);
398  }
399  wgNom.AddToys(n_toys);
400  wgNom.WriteToFile(outname);
401 
402  if(!nom_only){
403  ReplaceAll(outname, "Nom", "Up");
404  WorkspaceGenerator wgUp(*pbaseline, *pblocks, backgrounds, signal, data, sysfile, use_r4, sig_strength, 1+xsec_unc);
405  wgUp.UseGausApprox(!use_pois);
406  wgUp.SetRMax(rmax);
408  wgUp.SetLuminosity(lumi);
410  if(inject_other_model){
411  wgUp.SetInjectionModel(injection);
412  }
413  wgUp.AddToys(n_toys);
414  wgUp.WriteToFile(outname);
415 
416  ReplaceAll(outname, "Up", "Down");
417  WorkspaceGenerator wgDown(*pbaseline, *pblocks, backgrounds, signal, data, sysfile, use_r4, sig_strength, 1-xsec_unc);
418  wgDown.UseGausApprox(!use_pois);
419  wgDown.SetRMax(rmax);
420  wgDown.SetKappaCorrected(!no_kappa);
421  wgDown.SetLuminosity(lumi);
422  wgDown.SetDoSystematics(do_syst);
423  if(inject_other_model){
424  wgDown.SetInjectionModel(injection);
425  }
426  wgDown.AddToys(n_toys);
427  wgDown.WriteToFile(outname);
428  }
429 
430  time(&endtime);
431  cout<<"Finding workspaces took "<<fixed<<setprecision(0)<<difftime(endtime, begtime)<<" seconds"<<endl<<endl;
432 }
433 
434 
435 
436 void GetOptions(int argc, char *argv[]){
437  while(true){
438  static struct option long_options[] = {
439  {"sigfile", required_argument, 0, 'f'},
440  {"lumi", required_argument, 0, 'l'},
441  {"unblind", required_argument, 0, 'u'},
442  {"no_syst", no_argument, 0, 0},
443  {"lowj", required_argument, 0, 'j'},
444  {"hij", required_argument, 0, 'h'},
445  {"himet", required_argument, 0, 'm'},
446  {"mj", required_argument, 0, 's'},
447  {"lowmjthresh", required_argument, 0, 'a'},
448  {"mj_var", required_argument, 0, 'd'},
449  {"nokappa", no_argument, 0, 'k'},
450  {"no_r4", no_argument, 0, '4'},
451  {"useVeto", required_argument, 0, 'v'},
452  {"alt_binning", required_argument, 0, 'b'},
453  {"toys", required_argument, 0, 0},
454  {"sig_strength", required_argument, 0, 'g'},
455  {"dummy_syst", required_argument, 0, 0},
456  {"outfolder", required_argument, 0, 'o'},
457  {"inject", required_argument, 0, 'i'},
458  {"nominal", no_argument, 0, 'n'},
459  {"poisson", no_argument, 0, 'p'},
460  {0, 0, 0, 0}
461  };
462 
463  char opt = -1;
464  int option_index;
465  opt = getopt_long(argc, argv, "l:u:j:h:m:s:a:d:k4b:v:g:f:o:i:nc:p", long_options, &option_index);
466 
467  if( opt == -1) break;
468 
469  string optname;
470  switch(opt){
471  case 'l':
472  lumi = atof(optarg);
473  break;
474  case 'g':
475  sig_strength = atof(optarg);
476  break;
477  case 'u':
478  if(string(optarg)=="all"){
480  }else if(string(optarg)=="sideband"){
482  }else if(string(optarg)=="1b"){
484  }else{
486  }
487  break;
488  case 'o':
489  outfolder = optarg;
490  break;
491  case 'f':
492  sigfile = optarg;
493  break;
494  case 'j':
495  minjets = optarg;
496  break;
497  case 'h':
498  hijets = optarg;
499  break;
500  case 'm':
501  himet = optarg;
502  break;
503  case 'k':
504  no_kappa = true;
505  break;
506  case '4':
507  use_r4 = false;
508  break;
509  case 'v':
510  if(string(optarg) =="on") applyVeto = true;
511  break;
512  case 'b':
513  binning = optarg;
514  break;
515  case 's':
516  mjthresh = optarg;
517  break;
518  case 'a':
519  lowmjthresh = optarg;
520  break;
521  case 'd':
522  mjdef = optarg;
523  break;
524  case 'i':
525  injfile = optarg;
526  inject_other_model = true;
527  break;
528  case 'n':
529  nom_only = true;
530  break;
531  case 'p':
532  use_pois = true;
533  break;
534  case 0:
535  optname = long_options[option_index].name;
536  if(optname == "no_syst"){
537  do_syst = false;
538  }else if(optname == "toys"){
539  n_toys = atoi(optarg);
540  }else if(optname == "dummy_syst"){
541  dummy_syst = true;
542  dummy_syst_file = optarg;
543  }else{
544  printf("Bad option! Found option name %s\n", optname.c_str());
545  }
546  break;
547  default:
548  printf("Bad option! getopt_long returned character code 0%o\n", opt);
549  break;
550  }
551  }
552 }
WorkspaceGenerator & SetLuminosity(double luminosity)
Definition: bin.hpp:12
WorkspaceGenerator & SetRMax(double rmax)
WorkspaceGenerator & SetDoSystematics(bool do_systematics)
void parseMasses(const std::string &str, int &mglu, int &mlsp)
Definition: utilities.cpp:21
WorkspaceGenerator & SetInjectionModel(const Process &injection)
Definition: cut.hpp:8
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:34
void stopCrossSection(int stop_mass, float &xsec, float &xsec_unc)
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)
int main(int argc, char *argv[])
Definition: wspace_sig.cxx:59
void WriteToFile(const std::string &file_name)
void signalCrossSection(int glu_mass, float &xsec, float &xsec_unc)
int rmax
Definition: change_r.py:20
SYSTEMATIC dilep PROCESSES ttbar
Definition: high_met.txt:2
tuple mlsp
Definition: change_r.py:18
tuple mglu
Definition: change_r.py:17
void GetOptions(int argc, char *argv[])
Definition: wspace_sig.cxx:436
size_t AddToys(size_t num_toys=0)
BlindLevel