ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/additionalFiles/DataCards/IntermediateMassMakerZll.C
Revision: 1.3
Committed: Sun Oct 28 15:41:19 2012 UTC (12 years, 6 months ago) by madfish
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +103 -75 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 madfish 1.1 #include "TH1.h"
2     #include "TH1F.h"
3     #include "TTree.h"
4     #include "TFile.h"
5     #include "TString.h"
6     #include "TCut.h"
7     #include "TCanvas.h"
8     #include "TPad.h"
9     #include "TLatex.h"
10     #include "math.h"
11     #include "TMath.h"
12     #include <iostream>
13     #include <fstream>
14     #include "TLine.h"
15     #include "TROOT.h"
16     #include "TStyle.h"
17     #include "TPaveText.h"
18     #include "TLegend.h"
19     #include "THStack.h"
20     #include "TList.h"
21     #include "xsec7TeV.h"
22     #include "xsec8TeV.h"
23     #include "filesZll.h"
24     #include "RooArgList.h"
25     #include "RooRealVar.h"
26     #include "RooWorkspace.h"
27     #include "RooDataHist.h"
28     #include "RooHistPdf.h"
29     #include "tdrstyle.h"
30    
31 madfish 1.3 const int bins = 15;
32 madfish 1.1 int kount;
33     int kount2;
34     TString IFILE;
35     int maxCount;
36 madfish 1.3
37    
38     const int masspoints = 67;
39    
40    
41     std::string massS[masspoints]={
42     "110","110.5","111","111.5","112","112.5","113","113.5","114","114.5",
43     "115","115.5","116","116.5","117","117.5","118","118.5","119","119.5",
44     "120","120.5","121","121.5","122","122.5","123","123.5","124","124.5",
45     "125","125.5","126","126.5","127","127.5","128","128.5","129","129.5",
46     "130","130.5","131","131.5","132","132.5","133","133.5","134","134.5",
47     "135","124.6","124.7","124.8","124.9","125.1","125.2","125.3","125.4",
48     "125.6","125.7","125.8","125.9","126.1","126.2","126.3","126.4"
49     };
50    
51    
52     void Process(TString fname, TString myRooWS, int toMass, int fromMass)
53     {
54    
55    
56    
57    
58     std::string channels[] = {"data_obs", "ZH", "TT", "ZjLF", "ZjHF" , "VV" , "s_Top"};
59     std::string systs[] = {"eff_b", "fake_b_8TeV", "res_j", "scale_j" , "stat", "UEPS", "model" };
60    
61     kount = 0;
62    
63     gROOT->SetStyle("Plain");
64     setTDRStyle();
65    
66     TFile * file = new TFile(fname.Data(), "READ");
67     std::cout << "reading " << fname.Data() << std::endl;
68     TString fname2(fname.Data());
69     fname2.ReplaceAll("_WS_BDT_M110","");
70     fname2.ReplaceAll("_WS_BDT_M115","");
71     fname2.ReplaceAll("_WS_BDT_M120","");
72     fname2.ReplaceAll("_WS_BDT_M125","");
73     fname2.ReplaceAll("_WS_BDT_M130","");
74     fname2.ReplaceAll("_WS_BDT_M135","");
75     TString outname("./");
76     outname.Append(massS[toMass]);
77     outname.Append("/");
78     outname.Append(fname2.Data());
79     TFile * outfile = new TFile(outname.Data(), "RECREATE");
80    
81     using namespace RooFit;
82     RooWorkspace *myWS = new RooWorkspace(myRooWS.Data(),myRooWS.Data());
83     myWS->factory("CMS_vhbb_BDT_Zll_8TeV[-1.,1.]"); ///NEW VARIABLE NAME HERE
84    
85    
86    
87    
88     for (int c =0; c<7; c++)
89     {
90     kount2 = 0;
91     for (int s =0; s<7 ; s++ ){
92     makeSystPlot( file, myRooWS, myWS, channels[c], systs[s], toMass, fromMass );
93     }
94     }
95    
96    
97    
98    
99    
100    
101     myWS->writeToFile(outname.Data());
102     std::cout << std::endl << std::endl << std::endl << std::endl << "///////////////////////////" << std::endl;
103     std::cout << outname.Data() << " written" << std::endl;
104     std::cout << "///////////////////////////" << std::endl << std::endl << std::endl;
105    
106    
107     outfile->Write();
108     outfile->Close();
109    
110    
111     }
112    
113 madfish 1.1
114    
115 madfish 1.2 void makeSystPlot( TFile * f, TString myRooWS, RooWorkspace *WS, string channel, string syst, int toMassNo, int fromMassNo) //massNo 0-51, see xSec7TeV.h
116 madfish 1.1 {
117     RooArgList * hobs = new RooArgList("hobs");
118     RooRealVar BDT("CMS_vhbb_BDT_Zll_8TeV", "CMS_vhbb_BDT_Zll_8TeV", -1, 1);///OLD VARIABLE NAME HERE
119     hobs->add(*WS->var("CMS_vhbb_BDT_Zll_8TeV")); ///NEW VARIABLE NAME HERE
120 madfish 1.2 RooWorkspace *tempWS = (RooWorkspace*) f->Get(myRooWS.Data());
121 madfish 1.1 TString systT(syst);
122     TString chanT(channel);
123     bool writeIt = 1;
124    
125     if(chanT.Contains("QCD") || chanT.Contains("Wj"))
126     if(!(systT.Contains("stat"))) writeIt = 0;
127    
128    
129     if((kount < 3) && (channel=="data_obs"))
130     {
131     kount++;
132     std::string namen = channel;
133    
134 madfish 1.2 std::cout << "reading WS "<< myRooWS.Data() << std::endl;
135 madfish 1.1 std::cout << namen << std::endl;
136     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
137 madfish 1.3 TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,RooFit::Binning(bins));
138 madfish 1.1 std::cout << namen << std::endl;
139    
140     RooDataHist *DHnom = new RooDataHist(channel.c_str(),"",*hobs,tempHistNom);
141     WS->import(*(new RooHistPdf(channel.c_str(),"",*hobs,*DHnom)));
142    
143     }
144    
145     if (channel!="data_obs")
146     {
147     std::string nameUp;
148     std::string namen;
149     std::string nameDown;
150    
151    
152     if((syst == "stat"))
153     {
154 madfish 1.3
155 madfish 1.1 if(IFILE.Contains("7TeV"))
156     {
157 madfish 1.2 nameUp = channel + "CMS_vhbb_stats_" + channel + "_" + myRooWS.Data() + "Up";
158 madfish 1.1 namen = channel;
159 madfish 1.2 nameDown = channel + "CMS_vhbb_stats_" + channel + "_" + myRooWS.Data() + "Down";
160 madfish 1.1 }
161     if(IFILE.Contains("8TeV"))
162     {
163 madfish 1.2 nameUp = channel + "CMS_vhbb_stats_" + channel + "_" + myRooWS.Data() + "Up";
164 madfish 1.3 nameDown = channel + "CMS_vhbb_stats_" + channel + "_" + myRooWS.Data() + "Down";
165 madfish 1.1 namen = channel;
166     }
167 madfish 1.3 }
168 madfish 1.1
169 madfish 1.3 else if(syst == "UEPS")
170     {
171     nameUp = channel + syst + "Up";
172     namen = channel;
173     nameDown = channel + syst + "Down";
174     }
175     else if(syst == "model")
176     {
177     nameUp = channel + "CMS_vhbb_" + syst + "_" + channel + "Up";
178     namen = channel;
179     nameDown = channel + "CMS_vhbb_" + syst + "_" + channel + "Down";
180 madfish 1.1 }
181     else
182     {
183     nameUp = channel + "CMS_" + syst + "Up";
184     namen = channel;
185     nameDown = channel + "CMS_" + syst + "Down";
186     }
187     if((syst == "ZJModel"))
188     {
189     if(IFILE.Contains("7TeV"))
190     {
191 madfish 1.2 nameUp = channel + "CMS_vhbb_ZJModel_" + myRooWS.Data() + "_7TeVUp";
192 madfish 1.1 namen = channel;
193 madfish 1.2 nameDown = channel + "CMS_vhbb_ZJModel_" + myRooWS.Data() + "_7TeVDown";
194 madfish 1.1 }
195     if(IFILE.Contains("8TeV"))
196     {
197 madfish 1.2 nameUp = channel + "CMS_vhbb_ZJModel_" + myRooWS.Data() + "_8TeVUp";
198 madfish 1.1 namen = channel;
199 madfish 1.2 nameDown = channel + "CMS_vhbb_ZJModel_" + myRooWS.Data() + "_8TeVDown";
200 madfish 1.1 }
201    
202     }
203    
204     if(writeIt)
205     {
206     RooDataHist* tempRooDataHistUp = (RooDataHist*) tempWS->data(nameUp.c_str());
207     RooDataHist* tempRooDataHistDown = (RooDataHist*) tempWS->data(nameDown.c_str());
208     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
209    
210    
211    
212 madfish 1.2 std::cout << myRooWS.Data() << std::endl;
213 madfish 1.1 std::cout << nameUp.c_str() << std::endl;
214    
215 madfish 1.3 TH1 *tempHistUp = tempRooDataHistUp->createHistogram(nameUp.c_str(),BDT,RooFit::Binning(bins));
216     TH1 *tempHistDown = tempRooDataHistDown->createHistogram(nameDown.c_str(),BDT,RooFit::Binning(bins));
217 madfish 1.1 std::cout << namen.c_str() << std::endl;
218 madfish 1.3 TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,RooFit::Binning(bins));
219 madfish 1.1
220 madfish 1.3 if(chanT.Contains("ZH") && IFILE.Contains("7TeV"))
221 madfish 1.1 {
222     tempHistUp->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
223     tempHistDown->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
224     tempHistNom->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
225     }
226    
227 madfish 1.3 if(chanT.Contains("ZH") && IFILE.Contains("8TeV"))
228 madfish 1.1 {
229     tempHistUp->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
230     tempHistDown->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
231     tempHistNom->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
232     }
233    
234     std::cout<< "channel--> " << channel << std::endl;
235    
236    
237     tempHistUp->SetLineColor(kRed);
238     tempHistUp->SetLineWidth(3);
239     tempHistUp->SetFillColor(0);
240    
241     tempHistDown->SetLineColor(kBlue);
242     tempHistDown->SetFillColor(0);
243     tempHistDown->SetLineWidth(3);
244    
245     tempHistNom->SetFillColor(0);
246     tempHistNom->SetMarkerStyle(20);
247     tempHistUp->SetTitle((channel + syst).c_str());
248    
249    
250     RooDataHist *DHnom;
251     RooDataHist *DHup = new RooDataHist(nameUp.c_str(),"",*hobs,tempHistUp);
252     if(kount2 < 3) DHnom = new RooDataHist(namen.c_str(),"",*hobs,tempHistNom);
253     RooDataHist *DHdown = new RooDataHist(nameDown.c_str(),"",*hobs,tempHistDown);
254    
255     WS->import(*(new RooHistPdf(nameUp.c_str(),"",*hobs,*DHup)));
256     WS->import(*(new RooHistPdf(nameDown.c_str(),"",*hobs,*DHdown)));
257     if(kount2 < 3){ WS->import(*(new RooHistPdf(namen.c_str(),"",*hobs,*DHnom))); kount2++;}
258     }
259     }
260    
261     }
262    
263    
264    
265    
266    
267    
268    
269    
270    
271    
272     void IntermediateMassMakerZll()
273     {
274     maxCount=0;
275    
276    
277     for(int i = 0; i < n; i++)
278     {
279 madfish 1.2 TString myRooWS;
280 madfish 1.1 IFILE = files[i];
281    
282 madfish 1.2 if(IFILE.Contains ("Zee") && IFILE.Contains("Low") && IFILE.Contains("7TeV")) myRooWS = "ZeeLowPt_7TeV";
283     if(IFILE.Contains ("Zmm") && IFILE.Contains("Low") && IFILE.Contains("7TeV")) myRooWS = "ZmmLowPt7TeV";
284     if(IFILE.Contains ("Zee") && IFILE.Contains("High") && IFILE.Contains("7TeV")) myRooWS = "ZeeHighPt_7TeV";
285     if(IFILE.Contains ("Zmm") && IFILE.Contains("High") && IFILE.Contains("7TeV")) myRooWS = "ZmmHighPt_7TeV";
286    
287     if(IFILE.Contains ("Zee") && IFILE.Contains("Low") && IFILE.Contains("8TeV")) myRooWS = "ZeeLowPt_8TeV";
288     if(IFILE.Contains ("Zmm") && IFILE.Contains("Low") && IFILE.Contains("8TeV")) myRooWS = "ZmmLowPt_8TeV";
289     if(IFILE.Contains ("Zee") && IFILE.Contains("High") && IFILE.Contains("8TeV")) myRooWS = "ZeeHighPt_8TeV";
290     if(IFILE.Contains ("Zmm") && IFILE.Contains("High") && IFILE.Contains("8TeV")) myRooWS = "ZmmHighPt_8TeV";
291 madfish 1.1
292    
293     if((IFILE.Contains("110")))
294     {
295 madfish 1.2 Process(IFILE, myRooWS, 0,0);
296     Process(IFILE, myRooWS, 1,0);
297     Process(IFILE, myRooWS, 2,0);
298     Process(IFILE, myRooWS, 3,0);
299     Process(IFILE, myRooWS, 4,0);
300 madfish 1.1 }
301 madfish 1.3
302 madfish 1.1 if((IFILE.Contains("115")))
303     {
304 madfish 1.2 for(int to = 5; to < 15; to++) Process(IFILE, myRooWS, to , 10);
305 madfish 1.1 }
306    
307     if((IFILE.Contains("120")))
308     {
309 madfish 1.2 for(int to = 15; to < 25; to++) Process(IFILE, myRooWS,to , 20);
310 madfish 1.1 }
311 madfish 1.3 */
312 madfish 1.1 if((IFILE.Contains("125")))
313     {
314 madfish 1.2 for(int to = 25; to < 35; to++) Process(IFILE, myRooWS,to , 30);
315 madfish 1.3 for(int to = 51; to < 67; to++) Process(IFILE, myRooWS,to , 30);
316 madfish 1.1 }
317    
318 madfish 1.3
319 madfish 1.1 if((IFILE.Contains("130")))
320     {
321 madfish 1.2 for(int to = 35; to < 45; to++) Process(IFILE, myRooWS,to , 40);
322 madfish 1.1 }
323    
324     if((IFILE.Contains("135")))
325     {
326 madfish 1.2 for(int to = 45; to < 51; to++) Process(IFILE, myRooWS,to , 50);
327 madfish 1.1 }
328    
329 madfish 1.3
330 madfish 1.1
331    
332     }
333     }
334    
335