ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/JSON/JSONSampleLoader.C
Revision: 1.6
Committed: Fri Apr 26 06:50:17 2013 UTC (12 years ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -2 lines
Log Message:
Added herwig samples

File Contents

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