ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/JSON/JSONSampleLoader.C
Revision: 1.9
Committed: Fri Jun 28 15:02:21 2013 UTC (11 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +2 -1 lines
Log Message:
Updated files for migration to git (sync)

File Contents

# Content
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(JSONColor=="wg_color") return kGreen;
18 if(JSONColor=="tth_color") return TColor::GetColor("#D8F781");
19 if(Contains(JSONColor,"#")) return TColor::GetColor(JSONColor.c_str());
20 write_error(__FUNCTION__,"Invalid color requested: "+JSONColor);
21 assert(0);
22 return 0;
23 }
24
25 float GetCrossSection8TeV(string JSONXS) {
26 if(JSONXS=="Data") return 1.0;
27
28 // at 8 TeV: 3503.71 (https://twiki.cern.ch/twiki/bin/view/CMS/Zpt8TeV)
29 if(JSONXS=="ZJetsCrossSection") return 3532.8;
30 if(JSONXS=="LowZJetsCrossSection") return 11050*0.069*1.15; // LO xs * filter eff * k-factor (same as ZJets)
31 if(JSONXS=="TTbarCrossSection") return 225.197;
32 if(JSONXS=="WJetsCrossSection") return 37509.0;
33 if(JSONXS=="LeptonicTTbarCrossSection") return 22.05;
34 if(JSONXS=="PartialLeptonicTTbarCrossSection") return GetCrossSection8TeV("LeptonicTTbarCrossSection")*0.25;
35 if(JSONXS=="PartialTTbarCrossSection") return GetCrossSection8TeV("TTbarCrossSection")*0.25; // mixing four samples together with equal weight
36
37 if(JSONXS=="SingleTop_T_SChannel") return 3.79;
38 if(JSONXS=="SingleTop_Tbar_SChannel") return 1.76;
39 if(JSONXS=="SingleTop_Tbar_TChannel") return 30.7;
40 if(JSONXS=="SingleTop_T_TChannel") return 56.4;
41 if(JSONXS=="SingleTop_T_TWChannel") return 11.1;
42 if(JSONXS=="SingleTop_Tbar_TWChannel") return 11.1;
43
44 if(JSONXS=="ZZJetsTo2L2Q") return 2.449;
45 if(JSONXS=="ZZJetsTo4L") return 0.1769;
46 if(JSONXS=="WZJetsTo3LNu") return 1.06;
47 if(JSONXS=="WWJetsTo2L2Nu") return 5.81;
48 if(JSONXS=="ZZJetsTo2L2Nu") return 0.3;
49 if(JSONXS=="LM3") return 5.21678;
50 if(JSONXS=="LM4") return 2.88199;
51 if(JSONXS=="LM6") return 0.501773;
52 if(JSONXS=="LM9") return 9.24573;
53 if(JSONXS=="ETHEdge1") return 1.0; // UNKNOWN
54
55 if(JSONXS=="TTWCrossSection") return 0.232;
56 if(JSONXS=="TTZCrossSection") return 0.208;
57 if(JSONXS=="TTGCrossSection") return 2.166;
58 if(JSONXS=="TTHCrossSection") return 0.130;
59
60
61 if(JSONXS=="TTbarCrossSectionMatchingUp")return 236.9;
62 if(JSONXS=="TTbarCrossSectionMatchingDown")return 223.2;
63 if(JSONXS=="TTbarCrossSectionScaleUp")return 167.7;
64 if(JSONXS=="TTbarCrossSectionScaleDown")return 391.4;
65 if(JSONXS=="TTbarCrossSectionM166")return 277.6;
66 if(JSONXS=="TTbarCrossSectionM169")return 256.0;
67 if(JSONXS=="TTbarCrossSectionM175")return 215.6;
68 if(JSONXS=="TTbarCrossSectionM178")return 192.6;
69
70 if(JSONXS=="ZJetsHerwig2030") return 0.864 * 77.49882;
71 if(JSONXS=="ZJetsHerwig5080") return 0.612 * 28.70784;
72 if(JSONXS=="ZJetsHerwig100") return 1.08 * 14.0;
73
74 if(JSONXS=="GVJetsCrossSection") return 211.4;
75 write_error(__FUNCTION__,"Invalid cross section requested : "+JSONXS);
76 assert(0);
77 }
78
79 float GetCrossSection7TeV(string JSONXS) {
80 if(JSONXS=="Data") return 1.0;
81
82 // at 8 TeV: 3503.71 (https://twiki.cern.ch/twiki/bin/view/CMS/Zpt8TeV)
83 if(JSONXS=="ZJetsCrossSection") return 3048.0;
84 if(JSONXS=="LowZJetsCrossSection") return 11908; // LO xs * filter eff * k-factor (same as ZJets)
85 if(JSONXS=="TTbarCrossSection") return 165.0;
86 if(JSONXS=="WJetsCrossSection") return 31314.0;
87 if(JSONXS=="ZToNuNu") return 5760.0;
88
89
90 if(JSONXS=="SingleTop_T_SChannel") return 4.63;
91 if(JSONXS=="SingleTop_T_TChannel") return 64.57;
92 if(JSONXS=="SingleTop_T_TWChannel") return 15.74;
93
94 if(JSONXS=="VVJets") return 4.8;
95
96 if(JSONXS=="LM3") return 0.0;
97 if(JSONXS=="LM4") return 1.879*1.35;
98 if(JSONXS=="LM6") return 0.3104*1.30;
99 if(JSONXS=="LM8") return 0.7300*1.41;
100
101 write_error(__FUNCTION__,"Invalid cross section requested : "+JSONXS);
102 assert(0);
103 }
104
105 float GetCrossSection(string JSONXS, string Year) {
106 if(Year=="2012") {
107 return GetCrossSection8TeV(JSONXS);
108 }
109 if(Year=="2011") {
110 return GetCrossSection7TeV(JSONXS);
111 }
112 write_error(__FUNCTION__,"Invalid year requested: "+Year);
113 assert(0);
114 }
115
116 int LoadSamplesFromJSON(string SampleListPath, bool SplitByJetFlavors, bool SplitByLeptonFlavors, bool SplitDibosons, bool SplitOthers=true) {
117 cout << "Going to load samples from " << SampleListPath << endl;
118 SampleListPath="Modules/JSON/"+SampleListPath;
119 Json::Value root;
120 Json::Reader reader;
121
122 stringstream filecontent;
123 ifstream infile;
124 infile.open (SampleListPath.c_str());
125 if(!(infile.good())) {
126 cout << "There was a problem opening the file " << SampleListPath << endl;
127 assert(infile.good());
128 }
129
130 string currline;
131 while(getline(infile,currline)) {
132 filecontent<<currline; // Prints our STRING.
133 }
134
135 infile.close();
136 string FileContent=filecontent.str();
137 bool parsingSuccessful = reader.parse( FileContent, root );
138 if ( !parsingSuccessful ) {
139 cout << "Failed to parse sample list at " << SampleListPath << endl;
140 cout << reader.getFormattedErrorMessages();
141 cout << "If you don't see the the problem in your configuration right away, you could paste it here to visualize it: http://chris.photobooks.com/json/default.htm " << endl;
142 assert(parsingSuccessful);
143 }
144
145 string CMSSW_version="undefined";
146 string Year="undefined";
147
148 map<string,int> DYmap;
149 DYmap["Z+Jets"]=90;
150 //only by jet flavor
151 DYmap["Z+b"]=93;
152 DYmap["Z+c"]=92;
153 DYmap["Z+l"]=91;
154 //only by lepton flavor
155 DYmap["Z+ee,#mu#mu"]=94;
156 DYmap["Z+#tau#tau"]=95;
157 int OtherGroup=91;
158 int DibosonGroupNumber=90;
159
160
161 bool BeVerboseWhenReordering=false;
162
163 if( root.size() > 0 ) {
164 set_treename();
165
166 Year = root["Year"].asString();
167 CMSSW_version = root["CMSSWv"].asString();
168 const Json::Value samplecollections = root["samplecollections"];
169 for (int icoll = 0; icoll < samplecollections.size(); ++icoll) {
170 for (int iprocess=0; iprocess < root["samplecollections"][icoll]["samples"].size(); ++iprocess) {
171 for(int isrc=0; isrc < root["samplecollections"][icoll]["samples"][iprocess]["source"].size();isrc++) {
172 int groupNumber = iprocess;
173 string groupName = root["samplecollections"][icoll]["samples"][iprocess]["groupname"].asString();
174 bool IsSignal = root["samplecollections"][icoll]["samples"][iprocess]["IsSignal"]=="No"?0:1;
175 bool IsActive = root["samplecollections"][icoll]["samples"][iprocess]["IsActive"]=="No"?0:1;
176 Color_t groupColor = GetColor(root["samplecollections"][icoll]["samples"][iprocess]["groupcolor"].asString());
177 bool IsData = root["samplecollections"][icoll]["samples"][iprocess]["grouptype"]=="MC"?0:1;
178 string FileName = root["samplecollections"][icoll]["samples"][iprocess]["source"][isrc]["filename"].asString();
179 string SampleColl = samplecollections[icoll]["samplecollection"].asString();
180 float CrossSection = GetCrossSection(root["samplecollections"][icoll]["samples"][iprocess]["source"][isrc]["crosssection"].asString(),Year);
181
182 if(!IsActive) continue;
183
184 bool registered=false;
185 if(groupName=="") {
186 dout << "Found an empty group name for file " << FileName << " - panicking, good bye!" << endl;
187 assert(groupName!="");
188 }
189
190 if(Contains(groupName,"2l2q")) {// ZZ -> 2l2q
191 groupColor=TColor::GetColor("#FE9A2E");
192 }
193
194 if(Contains(groupName,"Z+Jets")) {
195 //may need to merge ...
196 if(BeVerboseWhenReordering) cout << groupName << endl;
197 if(!SplitByJetFlavors&&!SplitByLeptonFlavors) {
198 //merge everything
199 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+Jets" << endl;
200 groupName="Z+Jets";
201 groupNumber=DYmap["Z+Jets"];
202 }
203 if(!SplitByJetFlavors&&SplitByLeptonFlavors) {
204 //arrange them by lepton flavor
205 if(Contains(groupName,"ZToEEMM")) {
206 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+ee,mm" << endl;
207 groupName="Z(ee,#mu#mu)+Jets";
208 groupNumber=DYmap["Z+ee,#mu#mu"];
209 }
210 if(Contains(groupName,"ZToTauTau")) {
211 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+tautau" << endl;
212 groupName="Z(#tau#tau)+Jets";
213 groupNumber=DYmap["Z+#tau#tau"];
214 groupColor=kRed;
215 }
216 }
217
218 if(!SplitByLeptonFlavors&&SplitByJetFlavors) {
219 //arrange them by jet flavor
220 if(Contains(groupName,"Z+b")) {
221 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+b" << endl;
222 groupName="Z+b";
223 groupNumber=DYmap["Z+b"];
224 }
225 if(Contains(groupName,"Z+c")) {
226 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+c" << endl;
227 groupName="Z+c";
228 groupNumber=DYmap["Z+c"];
229 groupColor=kViolet+7;
230 }
231 if(Contains(groupName,"Z+l")) {
232 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Z+l" << endl;
233 groupName="Z+l";
234 groupNumber=DYmap["Z+l"];
235 groupColor=kPink;
236 }
237 }
238 }
239
240 if((Contains(groupName,"ZZ")||Contains(groupName,"WZ")||Contains(groupName,"WW")||Contains(groupName,"Dibosons")) && !SplitDibosons) {
241 if(BeVerboseWhenReordering) cout << groupName << endl;
242 //merge everything
243 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Dibosons" << endl;
244 groupName="Dibosons";
245 groupNumber=DibosonGroupNumber;
246 }
247
248 if((Contains(groupName,"Dibosons")||Contains(groupName,"W+Jets")||Contains(groupName,"Single-top")||Contains(groupName,"TTV")||Contains(groupName,"TTH"))&&!SplitOthers) {
249 if(BeVerboseWhenReordering) cout << groupName << endl;
250 //merge everything
251 if(BeVerboseWhenReordering) cout << " thrown " << groupName << " to Others" << endl;
252 groupName="Others";
253 groupNumber=OtherGroup;
254 groupColor=kGreen+2;//same as diboson
255 }
256
257 if(SampleColl=="allsamples") {
258 PlottingSetup::allsamples.AddSample(FileName,groupName,0,CrossSection,IsData,IsSignal,groupNumber,groupColor);
259 registered=true;
260 }
261
262 if(SampleColl=="systsamples") {
263 PlottingSetup::systsamples.AddSample(FileName,groupName,0,CrossSection,IsData,IsSignal,groupNumber,groupColor);
264 registered=true;
265 }
266
267 if(SampleColl=="SingleLeptonData") {
268 PlottingSetup::SingleLeptonData.AddSample(FileName,groupName,0,CrossSection,IsData,IsSignal,groupNumber,groupColor);
269 registered=true;
270 }
271
272
273
274 if(!registered) {
275 write_error(__FUNCTION__,"The sample collection specified in the JSON, "+SampleColl+", is not known");
276 }
277
278 assert(registered);
279 }
280 }
281 }
282
283 // PlottingSetup::allsamples.ListSamples();
284 // PlottingSetup::systsamples.ListSamples();
285
286 } else {
287 cout << "Problem with JSON file. " << endl;
288 assert(root.size() > 0);
289 }
290 }