1 |
buchmann |
1.1 |
#include <iostream>
|
2 |
|
|
#include <sstream>
|
3 |
|
|
#include <fstream>
|
4 |
|
|
#include "jsoncpp.cpp"
|
5 |
|
|
#include "TColor.h"
|
6 |
|
|
|
7 |
|
|
using namespace std;
|
8 |
|
|
|
9 |
|
|
Color_t GetColor(string JSONColor) {
|
10 |
|
|
if(JSONColor=="dy_color") return kYellow;
|
11 |
|
|
if(JSONColor=="wjets_color") return kGray;
|
12 |
|
|
if(JSONColor=="ttbar_color") return kMagenta+2;
|
13 |
|
|
if(JSONColor=="singletop_color") return kBlue;
|
14 |
|
|
if(JSONColor=="qcd_color") return kPink;
|
15 |
|
|
if(JSONColor=="diboson_color") return kGreen+2;
|
16 |
|
|
if(JSONColor=="lm_color") return kViolet+7;
|
17 |
|
|
if(Contains(JSONColor,"#")) return TColor::GetColor(JSONColor.c_str());
|
18 |
|
|
write_error(__FUNCTION__,"Invalid color requested: "+JSONColor);
|
19 |
|
|
assert(0);
|
20 |
|
|
return 0;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
float GetCrossSection8TeV(string JSONXS) {
|
24 |
|
|
if(JSONXS=="Data") return 1.0;
|
25 |
|
|
|
26 |
|
|
// at 8 TeV: 3503.71 (https://twiki.cern.ch/twiki/bin/view/CMS/Zpt8TeV)
|
27 |
|
|
if(JSONXS=="ZJetsCrossSection") return 3532.8;
|
28 |
|
|
if(JSONXS=="LowZJetsCrossSection") return 11050*0.069*1.15; // LO xs * filter eff * k-factor (same as ZJets)
|
29 |
|
|
if(JSONXS=="TTbarCrossSection") return 225.197;
|
30 |
|
|
if(JSONXS=="WJetsCrossSection") return 37509.0;
|
31 |
|
|
|
32 |
|
|
if(JSONXS=="SingleTop_T_SChannel") return 3.79;
|
33 |
|
|
if(JSONXS=="SingleTop_Tbar_SChannel") return 1.76;
|
34 |
|
|
if(JSONXS=="SingleTop_Tbar_TChannel") return 30.7;
|
35 |
|
|
if(JSONXS=="SingleTop_T_TChannel") return 56.4;
|
36 |
|
|
if(JSONXS=="SingleTop_T_TWChannel") return 11.1;
|
37 |
|
|
if(JSONXS=="SingleTop_Tbar_TWChannel") return 11.1;
|
38 |
|
|
|
39 |
|
|
if(JSONXS=="ZZJetsTo2L2Q") return 2.449;
|
40 |
|
|
if(JSONXS=="ZZJetsTo4L") return 0.1769;
|
41 |
|
|
if(JSONXS=="WZJetsTo3LNu") return 1.06;
|
42 |
|
|
if(JSONXS=="WWJetsTo2L2Nu") return 5.81;
|
43 |
|
|
if(JSONXS=="ZZJetsTo2L2Nu") return 0.3;
|
44 |
|
|
if(JSONXS=="LM4") return 2.88199;
|
45 |
|
|
|
46 |
|
|
write_error(__FUNCTION__,"Invalid cross section requested : "+JSONXS);
|
47 |
|
|
assert(0);
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
float GetCrossSection7TeV(string JSONXS) {
|
51 |
|
|
write_error(__FUNCTION__,"NOT IMPLEMENTED YET");
|
52 |
|
|
assert(0);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
float GetCrossSection(string JSONXS, string Year) {
|
56 |
|
|
if(Year=="2012") {
|
57 |
|
|
return GetCrossSection8TeV(JSONXS);
|
58 |
|
|
}
|
59 |
|
|
if(Year=="2011") {
|
60 |
|
|
return GetCrossSection7TeV(JSONXS);
|
61 |
|
|
}
|
62 |
|
|
write_error(__FUNCTION__,"Invalid year requested: "+Year);
|
63 |
|
|
assert(0);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
int LoadSamplesFromJSON(string SampleListPath, bool SplitByJetFlavors, bool SplitByLeptonFlavors) {
|
67 |
|
|
Json::Value root;
|
68 |
|
|
Json::Reader reader;
|
69 |
|
|
|
70 |
|
|
stringstream filecontent;
|
71 |
|
|
ifstream infile;
|
72 |
|
|
infile.open (SampleListPath.c_str());
|
73 |
|
|
string currline;
|
74 |
|
|
while(!infile.eof()) {
|
75 |
|
|
getline(infile,currline); // Saves the line in STRING.
|
76 |
|
|
filecontent<<currline; // Prints our STRING.
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
infile.close();
|
80 |
|
|
string FileContent=filecontent.str();
|
81 |
|
|
bool parsingSuccessful = reader.parse( FileContent, root );
|
82 |
|
|
if ( !parsingSuccessful ) {
|
83 |
|
|
cout << "Failed to parse sample list at " << SampleListPath << endl;
|
84 |
|
|
cout << reader.getFormattedErrorMessages();
|
85 |
|
|
assert(parsingSuccessful);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
string CMSSW_version="undefined";
|
89 |
|
|
string Year="undefined";
|
90 |
|
|
|
91 |
|
|
map<string,int> DYmap;
|
92 |
|
|
DYmap["Z+Jets"]=90;
|
93 |
|
|
//only by jet flavor
|
94 |
|
|
DYmap["Z+b"]=91;
|
95 |
|
|
DYmap["Z+c"]=92;
|
96 |
|
|
DYmap["Z+l"]=93;
|
97 |
|
|
//only by lepton flavor
|
98 |
|
|
DYmap["Z+ee,#mu#mu"]=94;
|
99 |
|
|
DYmap["Z+#tau#tau"]=95;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
bool BeVerboseWhenReordering=false;
|
103 |
|
|
|
104 |
|
|
if( root.size() > 0 ) {
|
105 |
|
|
set_treename();
|
106 |
|
|
|
107 |
|
|
Year = root["Year"].asString();
|
108 |
|
|
CMSSW_version = root["CMSSWv"].asString();
|
109 |
|
|
const Json::Value samplecollections = root["samplecollections"];
|
110 |
|
|
for (int icoll = 0; icoll < samplecollections.size(); ++icoll) {
|
111 |
|
|
for (int iprocess=0; iprocess < root["samplecollections"][icoll]["samples"].size(); ++iprocess) {
|
112 |
|
|
for(int isrc=0; isrc < root["samplecollections"][icoll]["samples"][iprocess]["source"].size();isrc++) {
|
113 |
|
|
int groupNumber = iprocess;
|
114 |
|
|
string groupName = root["samplecollections"][icoll]["samples"][iprocess]["groupname"].asString();
|
115 |
|
|
bool IsSignal = root["samplecollections"][icoll]["samples"][iprocess]["IsSignal"]=="No"?0:1;
|
116 |
|
|
Color_t groupColor = GetColor(root["samplecollections"][icoll]["samples"][iprocess]["groupcolor"].asString());
|
117 |
|
|
bool IsData = root["samplecollections"][icoll]["samples"][iprocess]["grouptype"]=="MC"?0:1;
|
118 |
|
|
string FileName = root["samplecollections"][icoll]["samples"][iprocess]["source"][isrc]["filename"].asString();
|
119 |
|
|
string SampleColl = samplecollections[icoll]["samplecollection"].asString();
|
120 |
|
|
float CrossSection = GetCrossSection(root["samplecollections"][icoll]["samples"][iprocess]["source"][isrc]["crosssection"].asString(),Year);
|
121 |
|
|
|
122 |
|
|
bool registered=false;
|
123 |
|
|
if(groupName=="") {
|
124 |
|
|
dout << "Found an empty group name for file " << FileName << " - panicking, good bye!" << endl;
|
125 |
|
|
assert(groupName!="");
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
if(Contains(groupName,"Z+Jets")) {
|
129 |
|
|
//may need to merge ...
|
130 |
|
|
if(BeVerboseWhenReordering) cout << groupName << endl;
|
131 |
|
|
if(!SplitByJetFlavors&&!SplitByLeptonFlavors) {
|
132 |
|
|
//merge everything
|
133 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+Jets" << endl;
|
134 |
|
|
groupName="Z+Jets";
|
135 |
|
|
groupNumber=DYmap["Z+Jets"];
|
136 |
|
|
}
|
137 |
|
|
if(!SplitByJetFlavors&&SplitByLeptonFlavors) {
|
138 |
|
|
//arrange them by lepton flavor
|
139 |
|
|
if(Contains(groupName,"ZToEEMM")) {
|
140 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+ee,mm" << endl;
|
141 |
|
|
groupName="Z->ee,mm";
|
142 |
|
|
groupNumber=DYmap["Z+ee,#mu#mu"];
|
143 |
|
|
}
|
144 |
|
|
if(Contains(groupName,"ZToTauTau")) {
|
145 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+tautau" << endl;
|
146 |
|
|
groupName="Z->#tau#tau";
|
147 |
|
|
groupNumber=DYmap["Z+#tau#tau"];
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
if(!SplitByLeptonFlavors&&SplitByJetFlavors) {
|
152 |
|
|
//arrange them by jet flavor
|
153 |
|
|
if(Contains(groupName,"Z+b")) {
|
154 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+b" << endl;
|
155 |
|
|
groupName="Z+b";
|
156 |
|
|
groupNumber=DYmap["Z+b"];
|
157 |
|
|
}
|
158 |
|
|
if(Contains(groupName,"Z+c")) {
|
159 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+c" << endl;
|
160 |
|
|
groupName="Z+c";
|
161 |
|
|
groupNumber=DYmap["Z+c"];
|
162 |
|
|
}
|
163 |
|
|
if(Contains(groupName,"Z+l")) {
|
164 |
|
|
if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+l" << endl;
|
165 |
|
|
groupName="Z+l";
|
166 |
|
|
groupNumber=DYmap["Z+l"];
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
if(SampleColl=="allsamples") {
|
172 |
|
|
PlottingSetup::allsamples.AddSample(FileName,groupName,0,CrossSection,IsData,IsSignal,groupNumber,groupColor);
|
173 |
|
|
registered=true;
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
if(SampleColl=="systsamples") {
|
177 |
|
|
PlottingSetup::systsamples.AddSample(FileName,groupName,0,CrossSection,IsData,IsSignal,groupNumber,groupColor);
|
178 |
|
|
registered=true;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
if(!registered) {
|
182 |
|
|
write_error(__FUNCTION__,"The sample collection specified in the JSON, "+SampleColl+", is not known");
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
assert(registered);
|
186 |
|
|
}
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
PlottingSetup::allsamples.ListSamples();
|
191 |
|
|
PlottingSetup::systsamples.ListSamples();
|
192 |
|
|
|
193 |
|
|
} else {
|
194 |
|
|
cout << "Problem with JSON file. " << endl;
|
195 |
|
|
assert(root.size() > 0);
|
196 |
|
|
}
|
197 |
|
|
}
|