ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/additionalFiles/DataCards/IntermediateMassMakerZnunu.C
Revision: 1.2
Committed: Sat Oct 27 20:34:50 2012 UTC (12 years, 6 months ago) by madfish
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +49 -45 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 "filesZH.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     const int bins = 20;
32     int kount;
33     int kount2;
34     TString IFILE;
35     int maxCount;
36 madfish 1.2 std::string massS[masspoints]={
37     "110","110.5","111","111.5","112","112.5","113","113.5","114","114.5",
38     "115","115.5","116","116.5","117","117.5","118","118.5","119","119.5",
39     "120","120.5","121","121.5","122","122.5","123","123.5","124","124.5",
40     "125","125.5","126","126.5","127","127.5","128","128.5","129","129.5",
41     "130","130.5","131","131.5","132","132.5","133","133.5","134","134.5",
42     "135","124.6","124.7","124.8","124.9","125.1","125.2","125.3","125.4",
43     "125.6","125.7","125.8","125.9","126.1","126.2","126.3","126.4"
44     };
45 madfish 1.1
46    
47 madfish 1.2
48     void makeSystPlot( TFile * f, TString myRooWS, RooWorkspace *WS, string channel, string syst, int toMassNo, int fromMassNo) //massNo 0-51, see xSec7TeV.h
49 madfish 1.1 {
50    
51     RooArgList * hobs = new RooArgList("hobs");
52     RooRealVar BDT("CMS_vhbb_BDT_Znn_8TeV", "CMS_vhbb_BDT_Znn_8TeV", -1, 1);///OLD VARIABLE NAME HERE
53     hobs->add(*WS->var("CMS_vhbb_BDT_Znn_8TeV")); ///NEW VARIABLE NAME HERE
54 madfish 1.2 RooWorkspace *tempWS = (RooWorkspace*) f->Get(myRooWS.Data());
55 madfish 1.1 TString systT(syst);
56     TString chanT(channel);
57    
58     if((kount < 3) && (channel=="data_obs"))
59     {
60     kount++;
61     std::string namen = channel;
62    
63 madfish 1.2 std::cout << myRooWS.Data() << std::endl;
64 madfish 1.1 std::cout << namen << std::endl;
65     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
66     TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins));
67     std::cout << namen << std::endl;
68    
69     RooDataHist *DHnom = new RooDataHist(channel.c_str(),"",*hobs,tempHistNom);
70     WS->import(*(new RooHistPdf(channel.c_str(),"",*hobs,*DHnom)));
71    
72     }
73    
74     if (channel!="data_obs")
75     {
76     std::string nameUp;
77     std::string namen;
78     std::string nameDown;
79    
80    
81     if((syst == "stat"))
82     {
83     if(IFILE.Contains("7TeV"))
84     {
85 madfish 1.2 nameUp = channel + "_CMS_vhbb_stat" + channel + "_" + myRooWS.Data() + "_7TeVUp";
86 madfish 1.1 namen = channel;
87 madfish 1.2 nameDown = channel + "_CMS_vhbb_stat" + channel + "_" + myRooWS.Data() + "_7TeVDown";
88 madfish 1.1 }
89     if(IFILE.Contains("8TeV"))
90     {
91 madfish 1.2 nameUp = channel + "_CMS_vhbb_stat" + channel + "_" + myRooWS.Data() + "Up";
92 madfish 1.1 namen = channel;
93 madfish 1.2 nameDown = channel + "_CMS_vhbb_stat" + channel + "_" + myRooWS.Data() + "Down";
94 madfish 1.1 }
95    
96     }
97     else
98     {
99     nameUp = channel + "_CMS_" + syst + "Up";
100     namen = channel;
101     nameDown = channel + "_CMS_" + syst + "Down";
102     }
103     if((syst == "ZJModel"))
104     {
105     if(IFILE.Contains("7TeV"))
106     {
107 madfish 1.2 nameUp = channel + "_CMS_vhbb_ZJModel_" + myRooWS.Data() + "_7TeVUp";
108 madfish 1.1 namen = channel;
109 madfish 1.2 nameDown = channel + "_CMS_vhbb_ZJModel_" + myRooWS.Data() + "_7TeVDown";
110 madfish 1.1 }
111     if(IFILE.Contains("8TeV"))
112     {
113 madfish 1.2 nameUp = channel + "_CMS_vhbb_ZJModel_" + myRooWS.Data() + "Up";
114 madfish 1.1 namen = channel;
115 madfish 1.2 nameDown = channel + "_CMS_vhbb_ZJModel_" + myRooWS.Data() + "Down";
116 madfish 1.1 }
117    
118     }
119    
120    
121     RooDataHist* tempRooDataHistUp = (RooDataHist*) tempWS->data(nameUp.c_str());
122     RooDataHist* tempRooDataHistDown = (RooDataHist*) tempWS->data(nameDown.c_str());
123     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
124    
125    
126 madfish 1.2 std::cout << myRooWS.Data() << std::endl;
127 madfish 1.1 std::cout << nameUp.c_str() << std::endl;
128    
129     TH1 *tempHistUp = tempRooDataHistUp->createHistogram(nameUp.c_str(),BDT,Binning(bins));
130     TH1 *tempHistDown = tempRooDataHistDown->createHistogram(nameDown.c_str(),BDT,Binning(bins));
131     TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins));
132    
133     if(chanT.Contains("VH") && IFILE.Contains("7TeV"))
134     {
135     tempHistUp->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
136     tempHistDown->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
137     tempHistNom->Scale(xSec7ZH[toMassNo]/xSec7ZH[fromMassNo]);
138     }
139    
140     if(chanT.Contains("VH") && IFILE.Contains("8TeV"))
141     {
142     tempHistUp->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
143     tempHistDown->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
144     tempHistNom->Scale(xSec8ZH[toMassNo]/xSec8ZH[fromMassNo]);
145     }
146    
147     std::cout<< "channel--> " << channel << std::endl;
148    
149    
150     tempHistUp->SetLineColor(kRed);
151     tempHistUp->SetLineWidth(3);
152     tempHistUp->SetFillColor(0);
153    
154     tempHistDown->SetLineColor(kBlue);
155     tempHistDown->SetFillColor(0);
156     tempHistDown->SetLineWidth(3);
157    
158     tempHistNom->SetFillColor(0);
159     tempHistNom->SetMarkerStyle(20);
160    
161     tempHistUp->SetTitle((channel + syst).c_str());
162    
163     RooDataHist *DHnom;
164     RooDataHist *DHup = new RooDataHist(nameUp.c_str(),"",*hobs,tempHistUp);
165     if(kount2 < 3) DHnom = new RooDataHist(namen.c_str(),"",*hobs,tempHistNom);
166     RooDataHist *DHdown = new RooDataHist(nameDown.c_str(),"",*hobs,tempHistDown);
167    
168     WS->import(*(new RooHistPdf(nameUp.c_str(),"",*hobs,*DHup)));
169     WS->import(*(new RooHistPdf(nameDown.c_str(),"",*hobs,*DHdown)));
170     if(kount2 < 3){ WS->import(*(new RooHistPdf(namen.c_str(),"",*hobs,*DHnom))); kount2++;}
171    
172     }
173    
174    
175     }
176    
177    
178    
179    
180    
181    
182 madfish 1.2 void Process(TString fname, TString myRooWS, int toMass, int fromMass)
183 madfish 1.1 {
184    
185    
186    
187    
188     std::string channels[] = {"data_obs", "VH", "TT", "WjLF", "WjHF", "ZjLF", "ZjHF" , "VV" , "s_Top"};
189     std::string systs[] = {"eff_b", "fake_b_8TeV", "res_j", "scale_j" , "stat" };
190    
191     kount = 0;
192    
193     gROOT->SetStyle("Plain");
194     setTDRStyle();
195    
196     TFile * file = new TFile(fname.Data(), "READ");
197     std::cout << "reading " << fname.Data() << std::endl;
198     TString outname(massS[toMass]);
199 madfish 1.2 outname.Append("_File1.root");
200 madfish 1.1 fname.ReplaceAll(".root",outname.Data());
201     TFile * outfile = new TFile(fname.Data(), "RECREATE");
202    
203     using namespace RooFit;
204 madfish 1.2 RooWorkspace *myWS = new RooWorkspace(myRooWS.Data(),myRooWS.Data());
205 madfish 1.1 myWS->factory("CMS_vhbb_BDT_Znn_8TeV[-1.,1.]"); ///NEW VARIABLE NAME HERE
206    
207 madfish 1.2 TString myRooWS2(myRooWS.Data());
208     myRooWS2.ReplaceAll("Low","High");
209     RooWorkspace *myWS2 = new RooWorkspace(myRooWS2.Data(),myRooWS2.Data());
210 madfish 1.1 myWS2->factory("CMS_vhbb_BDT_Znn_8TeV[-1.,1.]"); ///NEW VARIABLE NAME HERE
211    
212    
213    
214     for (int c =0; c<9; c++)
215     {
216     kount2 = 0;
217     for (int s =0; s<5 ; s++ ){
218 madfish 1.2 makeSystPlot( file, myRooWS, myWS, channels[c], systs[s], toMass, fromMass );
219     makeSystPlot( file, myRooWS2, myWS2, channels[c], systs[s] , toMass, fromMass);
220 madfish 1.1 }
221     }
222    
223    
224    
225 madfish 1.2 // makeSystPlot(file, myRooWS, myWS, "ZjLF", "ZJModel",toMass, fromMass);
226     // makeSystPlot(file, myRooWS, myWS, "ZjHF", "ZJModel",toMass, fromMass);
227 madfish 1.1
228    
229 madfish 1.2 // makeSystPlot(file, myRooWS2, myWS2, "ZjLF", "ZJModel",toMass, fromMass);
230     // makeSystPlot(file, myRooWS2, myWS2, "ZjHF", "ZJModel",toMass, fromMass);
231 madfish 1.1
232     myWS->writeToFile(fname.Data());
233     std::cout << std::endl << std::endl << std::endl << std::endl << "///////////////////////////" << std::endl;
234     std::cout << fname.Data() << " written" << std::endl;
235     std::cout << "///////////////////////////" << std::endl << std::endl << std::endl;
236    
237    
238     outfile->Write();
239     outfile->Close();
240 madfish 1.2 fname.ReplaceAll("File1","File2");
241 madfish 1.1 TFile * outfile2 = new TFile(fname.Data(), "RECREATE");
242     myWS2->writeToFile(fname.Data());
243     std::cout << std::endl << std::endl << std::endl << std::endl << "///////////////////////////" << std::endl;
244     std::cout << fname.Data() << " written" << std::endl;
245     std::cout << "///////////////////////////" << std::endl << std::endl << std::endl;
246    
247    
248     }
249    
250    
251    
252    
253    
254     void IntermediateMassMakerZnunu()
255     {
256    
257     maxCount=0;
258    
259    
260    
261    
262     for(int i = 0; i < n; i++)
263     {
264 madfish 1.2 TString myRooWS;
265 madfish 1.1 IFILE = files[i];
266 madfish 1.2 myRooWS = "Znunu_1";
267 madfish 1.1 if(IFILE.Contains("8TeV"))
268     {
269 madfish 1.2 myRooWS = "ZnunuLowPt_8TeV";
270 madfish 1.1 }
271    
272     if((IFILE.Contains("110")))
273     {
274 madfish 1.2 Process(IFILE, myRooWS, 0,0);
275     Process(IFILE, myRooWS, 1,0);
276     Process(IFILE, myRooWS, 2,0);
277     Process(IFILE, myRooWS, 3,0);
278     Process(IFILE, myRooWS, 4,0);
279 madfish 1.1 }
280     if((IFILE.Contains("115")))
281     {
282 madfish 1.2 for(int to = 5; to < 15; to++) Process(IFILE, myRooWS, to , 10);
283 madfish 1.1 }
284    
285     if((IFILE.Contains("120")))
286     {
287 madfish 1.2 for(int to = 15; to < 25; to++) Process(IFILE, myRooWS,to , 20);
288 madfish 1.1 }
289    
290     if((IFILE.Contains("125")))
291     {
292 madfish 1.2 for(int to = 25; to < 35; to++) Process(IFILE, myRooWS,to , 30);
293     for(int to = 51; to < 67; to++) Process(IFILE, myRooWS,to , 30);
294 madfish 1.1 }
295    
296     if((IFILE.Contains("130")))
297     {
298 madfish 1.2 for(int to = 35; to < 45; to++) Process(IFILE, myRooWS,to , 40);
299 madfish 1.1 }
300    
301    
302     if((IFILE.Contains("135")))
303     {
304 madfish 1.2 for(int to = 45; to < 51; to++) Process(IFILE, myRooWS,to , 50);
305 madfish 1.1 }
306    
307    
308    
309     }
310     }
311    
312