18 bool hasEntry(
const std::string &sample,
const std::string &bin,
const int nB);
27 int main(
int argc,
char *argv[])
29 bool includePDFUncert =
true;
30 bool includeLowMJ =
false;
34 std::vector<std::string> processes = {
"qcd",
"ttbar",
"wjets",
"other"};
35 std::vector<std::string> shapeSysts = {
"btag_bc",
"btag_udsg",
36 "gs45",
"gs67",
"gs89",
"gs10Inf",
38 "pileup",
"lep_eff",
"ttbar_pt",
40 "qcd_muf",
"qcd_mur",
"qcd_murf",
42 "ttbar_muf",
"ttbar_mur",
"ttbar_murf",
43 "wjets_muf",
"wjets_mur",
"wjets_murf",
44 "other_muf",
"other_mur",
"other_murf",
45 "fs_btag_bc",
"fs_btag_udsg",
"fs_lep_eff"};
47 std::string gluinoMass;
48 std::string signalBinName;
51 std::cout <<
"Syntax: make_rpv_datacard.exe [gluino mass, in GeV] [default/control]" << std::endl;
57 ss <<
"signal_M" << gluinoMass;
58 signalBinName = ss.str();
60 processes.insert(processes.begin(), signalBinName);
63 if(cardType!=
"control" && cardType!=
"default" && cardType!=
"mconly") {
64 std::cout <<
"Syntax: make_rpv_datacard.exe [gluino mass, in GeV] [default/control/mconly]" << std::endl;
76 std::vector<std::string> bins = {
"bin0",
"bin1",
"bin2",
77 "bin3",
"bin4",
"bin5"};
80 bins.push_back(
"bin6");
81 bins.push_back(
"bin7");
82 bins.push_back(
"bin8");
83 bins.push_back(
"bin9");
85 if(cardType==
"default" || cardType==
"mconly") {
86 bins.push_back(
"bin10");
87 bins.push_back(
"bin11");
88 bins.push_back(
"bin12");
89 bins.push_back(
"bin13");
90 bins.push_back(
"bin14");
91 bins.push_back(
"bin15");
92 bins.push_back(
"bin16");
93 bins.push_back(
"bin17");
97 std::string dataCardPath = gSystem->pwd();
98 if(cardType==
"mconly") dataCardPath +=
"/variations/sum_rescaled_mconly.root";
99 else dataCardPath +=
"/variations/sum_rescaled.root";
100 TFile *variations = TFile::Open(dataCardPath.c_str());
102 std::string filename(
"datacard_M");
103 filename+=gluinoMass;
104 if(cardType==
"control") filename+=
"_control";
105 else if(cardType==
"mconly") filename+=
"_mconly";
107 if(includePDFUncert) {
108 for(
unsigned int i=0; i<100; i++) {
109 TString pdf(Form(
"w_pdf%d", i));
110 shapeSysts.push_back(pdf.Data());
120 file <<
"imax " <<
nbins <<
" number of bins" << std::endl;
122 file <<
"kmax * number of nuisance parameters" << std::endl;
123 file <<
"------------------------------------" << std::endl;
125 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
126 file <<
"shapes * " << bins.at(ibin) <<
" " << dataCardPath <<
" " << bins.at(ibin)
127 <<
"/$PROCESS " << bins.at(ibin) <<
"/$PROCESS_$SYSTEMATIC" << std::endl;
129 file <<
"------------------------------------" << std::endl;
132 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
133 variations->cd(bins.at(ibin).c_str());
134 file << bins.at(ibin) <<
" ";
137 file <<
"observation ";
138 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
139 TString binName(bins.at(ibin));
140 TH1F *
hist =
static_cast<TH1F*
>(variations->Get(Form(
"%s/data_obs",binName.Data())));
141 file << hist->Integral() <<
" ";
145 file <<
"------------------------------------" << std::endl;
147 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
148 for(
unsigned int iprocess=0; iprocess<
nprocesses; iprocess++) {
149 file << bins.at(ibin) <<
" ";
154 for(
unsigned int index=0; index<nbins*
nprocesses; index++) file << processes.at(index%nprocesses) <<
" ";
157 for(
unsigned int index=0; index<nbins*
nprocesses; index++) file << index%nprocesses <<
" ";
161 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
162 for(
unsigned int iprocess=0; iprocess<
nprocesses; iprocess++) {
163 TString histName(Form(
"%s/%s", bins.at(ibin).c_str(), processes.at(iprocess).c_str()));
164 TH1F *
hist =
static_cast<TH1F*
>(variations->Get(histName));
165 file << hist->Integral() <<
" ";
168 file <<
"\n------------------------------------" << std::endl;
190 map<string, int> bindex;
191 for(uint ibin=0; ibin<
nbins; ibin++)
192 bindex[bins[ibin]]=ibin;
204 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
205 tmpLine.Prepend(
"normqcd_bin0 lnU ");
206 file << tmpLine.Data() << endl;
208 else if(jbin==
"bin1"){
209 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
210 tmpLine.Replace(2*(bindex[
"bin2"]*
nprocesses+1),1,
"5");
211 tmpLine.Prepend(
"normqcd_bin1_2 lnU ");
212 file << tmpLine.Data() << endl;
214 else if(jbin==
"bin2"){
215 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
216 tmpLine.Replace(2*(bindex[
"bin0"]*
nprocesses+2),1,
"5");
217 tmpLine.Replace(2*(bindex[
"bin1"]*
nprocesses+2),1,
"5");
218 tmpLine.Prepend(
"normtt_bin2_0_1 lnU ");
219 file << tmpLine.Data() << endl;
221 else if(jbin==
"bin3"){
222 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
223 tmpLine.Prepend(
"normqcd_bin3 lnU ");
224 file << tmpLine.Data() << endl;
226 else if(jbin==
"bin4"){
227 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
228 tmpLine.Replace(2*(bindex[
"bin5"]*
nprocesses+1),1,
"5");
229 tmpLine.Prepend(
"normqcd_bin4_5 lnU ");
230 file << tmpLine.Data() << endl;
232 else if(jbin==
"bin5"){
233 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
234 tmpLine.Replace(2*(bindex[
"bin3"]*
nprocesses+2),1,
"5");
235 tmpLine.Replace(2*(bindex[
"bin4"]*
nprocesses+2),1,
"5");
236 tmpLine.Prepend(
"normtt_bin5_3_4 lnU ");
237 file << tmpLine.Data() << endl;
239 else if(jbin==
"bin10"){
240 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
241 tmpLine.Replace(2*(bindex[
"bin12"]*
nprocesses+1),1,
"5");
242 tmpLine.Prepend(
"normqcd_bin10_12 lnU ");
243 file << tmpLine.Data() << endl;
245 else if(jbin==
"bin11"){
246 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
247 tmpLine.Replace(2*(bindex[
"bin16"]*
nprocesses+2),1,
"5");
248 tmpLine.Prepend(
"normtt_bin11_16 lnU ");
249 file << tmpLine.Data() << endl;
251 else if(jbin==
"bin12"){
252 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
253 tmpLine.Replace(2*(bindex[
"bin10"]*
nprocesses+2),1,
"5");
254 tmpLine.Prepend(
"normtt_bin12_10 lnU ");
255 file << tmpLine.Data() << endl;
257 else if(jbin==
"bin13"){
258 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
259 tmpLine.Replace(2*(bindex[
"bin15"]*
nprocesses+1),1,
"5");
260 tmpLine.Prepend(
"normqcd_bin13_15 lnU ");
261 file << tmpLine.Data() << endl;
263 else if(jbin==
"bin14"){
264 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
265 tmpLine.Replace(2*(bindex[
"bin17"]*
nprocesses+2),1,
"5");
266 tmpLine.Prepend(
"normtt_bin14_17 lnU ");
267 file << tmpLine.Data() << endl;
269 else if(jbin==
"bin15"){
270 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+2),1,
"5");
271 tmpLine.Replace(2*(bindex[
"bin13"]*
nprocesses+2),1,
"5");
272 tmpLine.Prepend(
"normtt_bin15_13 lnU ");
273 file << tmpLine.Data() << endl;
275 else if(jbin==
"bin16"){
276 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
277 tmpLine.Replace(2*(bindex[
"bin11"]*
nprocesses+1),1,
"5");
278 tmpLine.Prepend(
"normqcd_bin16_11 lnU ");
279 file << tmpLine.Data() << endl;
281 else if(jbin==
"bin17"){
282 tmpLine.Replace(2*(bindex[jbin]*
nprocesses+1),1,
"5");
283 tmpLine.Replace(2*(bindex[
"bin14"]*
nprocesses+1),1,
"5");
284 tmpLine.Prepend(
"normqcd_bin17_14 lnU ");
285 file << tmpLine.Data() << endl;
294 for(
unsigned int ibin=0; ibin<
nbins; ibin++) {
295 file <<
"1.027 - - 1.027 1.027 ";
303 for(
unsigned int isyst=0; isyst<shapeSysts.size(); isyst++) {
304 file << shapeSysts.at(isyst) <<
" shape ";
305 if(shapeSysts.at(isyst).find(
"pdf")!=std::string::npos) {
307 for(
unsigned int index=0; index<
nbins; index++) file <<
"0.1 0.1 0.1 0.1 0.1 ";
310 for(
unsigned int index=0; index<
nbins*
nprocesses; index++) file << 1.0 <<
" ";
320 const unsigned int maxB=4;
323 std::vector<std::string> samples = {signalBinName,
"qcd",
"ttbar"};
324 for(
auto isample : samples) {
325 for(
unsigned int ibin = 0; ibin<bins.size(); ibin++) {
326 for(
unsigned int ibbin=1; ibbin<maxB+1; ibbin++) {
327 if(!
hasEntry(isample, bins.at(ibin), ibbin))
continue;
328 file <<
"mcstat_" << isample <<
"_" << bins.at(ibin) <<
"_nb" << ibbin <<
" shape ";
329 for(
unsigned int ientry = 0; ientry<bins.size(); ientry++) {
330 if(ientry == ibin ) {
331 if( isample.find(
"signal")!=std::string::npos) file <<
"1 - - - - ";
332 else if( isample ==
"qcd") file <<
"- 1 - - - ";
333 else if( isample ==
"ttbar" ) file <<
"- - 1 - - ";
334 else if( isample ==
"wjets" ) file <<
"- - - 1 - ";
335 else if( isample ==
"other" ) file <<
"- - - - 1 ";
337 else file <<
"- - - - - ";
355 bool hasEntry(
const std::string &sample,
const std::string &bin,
const int nB)
357 if(sample.find(
"signal_M1000")!=std::string::npos) {
358 if(bin==
"bin2" && nB==4)
return false;
359 if(bin==
"bin3" && nB==1)
return false;
360 if(bin==
"bin3" && nB==3)
return false;
361 if(bin==
"bin3" && nB==4)
return false;
363 if(sample.find(
"signal_M1100")!=std::string::npos) {
364 if(bin==
"bin3" && nB==4)
return false;
365 if(bin==
"bin5" && nB==4)
return false;
367 if(sample.find(
"signal_M1200")!=std::string::npos) {
368 if(bin==
"bin0" && nB==4)
return false;
369 if(bin==
"bin2" && nB==4)
return false;
370 if(bin==
"bin3" && nB==4)
return false;
371 if(bin==
"bin5" && nB==4)
return false;
373 if(sample.find(
"signal_M1300")!=std::string::npos) {
374 if(bin==
"bin2" && nB==4)
return false;
375 if(bin==
"bin3" && nB==1)
return false;
377 if(sample.find(
"signal_M1400")!=std::string::npos) {
378 if(bin==
"bin0" && nB==4)
return false;
380 if(sample==
"ttbar") {
381 if(bin==
"bin0" && nB==4)
return false;
382 if(bin==
"bin5" && nB==4)
return false;
385 if(bin==
"bin5" && nB==3)
return false;
386 if(bin==
"bin5" && nB==4)
return false;
387 if(bin==
"bin11" && nB==4)
return false;
388 if(bin==
"bin14" && nB==4)
return false;
389 if(bin==
"bin15" && nB==4)
return false;
void outputShapeSystematics(std::ofstream &file, const std::vector< std::string > shapeSysts)
void outputLognormalSystematics(std::ofstream &file)
void outputMCStatisticsSyst(std::ofstream &file, const std::vector< std::string > &bins, const std::string &signalBinName)
bool hasEntry(const std::string &sample, const std::string &bin, const int nB)
void outputNormSharing(std::ofstream &file, const std::vector< std::string > &bins)
int main(int argc, char *argv[])