ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/additionalFiles/DataCards/IntermediateMassMakerWH.C
Revision: 1.1
Committed: Thu Oct 11 09:47:34 2012 UTC (12 years, 7 months ago) by madfish
Content type: text/plain
Branch: MAIN
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 "filesWH.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 = 25;
32     int kount;
33     int kount2;
34     TString IFILE;
35     int maxCount;
36     std::string massS[51]={
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"};
43    
44    
45     void makeSystPlot( TFile * f, TString oldFolder, RooWorkspace *WS, string channel, string syst, int toMassNo, int fromMassNo) //massNo 0-51, see xSec7TeV.h
46     {
47    
48     RooArgList * hobs = new RooArgList("hobs");
49     RooRealVar BDT("CMS_vhbb_BDT_Wln_8TeV", "CMS_vhbb_BDT_Wln_8TeV", -1, 1);///OLD VARIABLE NAME HERE
50     hobs->add(*WS->var("CMS_vhbb_BDT_Wln_8TeV")); ///NEW VARIABLE NAME HERE
51     RooWorkspace *tempWS = (RooWorkspace*) f->Get(oldFolder.Data());
52     TString systT(syst);
53     TString chanT(channel);
54    
55     bool writeIt = 1;
56    
57     if(chanT.Contains("QCD"))
58     if(!(systT.Contains("stat"))) writeIt = 0;
59    
60    
61     if((kount < 3) && (channel=="data_obs"))
62     {
63     kount++;
64     std::string namen = channel;
65    
66     std::cout << oldFolder.Data() << std::endl;
67     std::cout << namen << std::endl;
68     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
69     TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins));
70    
71     RooDataHist *DHnom = new RooDataHist(channel.c_str(),"",*hobs,tempHistNom);
72     WS->import(*(new RooHistPdf(channel.c_str(),"",*hobs,*DHnom)));
73    
74     }
75    
76     if (channel!="data_obs")
77     {
78     std::string nameUp;
79     std::string namen;
80     std::string nameDown;
81    
82    
83     if(syst == "stat")
84     {
85     if(oldFolder.Contains("Wen"))
86     {
87     nameUp = channel + "_CMS_vhbb_stat" + channel + "_WenuUp";
88     namen = channel;
89     nameDown = channel + "_CMS_vhbb_stat" + channel + "_WenuDown";
90    
91     if(channel == "s_Top")
92     {
93     nameUp = channel + "_CMS_vhbb_statsTop_WenuUp";
94     namen = channel;
95     nameDown = channel + "_CMS_vhbb_statsTop_WenuDown";
96     }
97    
98     }
99     else
100     {
101     nameUp = channel + "_CMS_vhbb_stat" + channel + "_WmunuUp";
102     namen = channel;
103     nameDown = channel + "_CMS_vhbb_stat" + channel + "_WmunuDown";
104    
105     if(channel == "s_Top")
106     {
107     nameUp = channel + "_CMS_vhbb_statsTop_WmunuUp";
108     namen = channel;
109     nameDown = channel + "_CMS_vhbb_statsTop_WmunuDown";
110     }
111    
112    
113     }
114     }
115     else
116     {
117     nameUp = channel + "_CMS_" + syst + "Up";
118     namen = channel;
119     nameDown = channel + "_CMS_" + syst + "Down";
120     }
121    
122     if((syst == "stat") && (oldFolder.Contains("High")))
123     {
124     if(oldFolder.Contains("Wen"))
125     {
126     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wenu2Up";
127     namen = channel;
128     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wenu2Down";
129    
130     if(channel == "s_Top")
131     {
132     nameUp = channel + "_CMS_vhbb_statsTop_Wenu2Up";
133     namen = channel;
134     nameDown = channel + "_CMS_vhbb_statsTop_Wenu2Down";
135     }
136    
137     }
138     else
139     {
140     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wmunu2Up";
141     namen = channel;
142     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wmunu2Down";
143    
144     if(channel == "s_Top")
145     {
146     nameUp = channel + "_CMS_vhbb_statsTop_Wmunu2Up";
147     namen = channel;
148     nameDown = channel + "_CMS_vhbb_statsTop_Wmunu2Down";
149     }
150    
151    
152     }
153     }
154    
155     if(systT.Contains("Model"))
156     {
157     nameUp = channel + "_CMS_vhbb_WModelUp";
158     namen = channel;
159     nameDown = channel + "_CMS_vhbb_WModelDown";
160     }
161    
162     if( systT.Contains("stat") && (oldFolder.Contains("Wen")) && IFILE.Contains("8TeV") && !(oldFolder.Contains("High")))
163     {
164     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wenu_8TeVUp";
165     namen = channel;
166     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wenu_8TeVDown";
167    
168     if(channel == "s_Top")
169     {
170     nameUp = channel + "_CMS_vhbb_statsTop_Wenu_8TeVUp";
171     namen = channel;
172     nameDown = channel + "_CMS_vhbb_statsTop_Wenu_8TeVDown";
173     }
174    
175    
176     }
177    
178     if( systT.Contains("stat") && (oldFolder.Contains("Wmn")) && IFILE.Contains("8TeV") && !(oldFolder.Contains("High")))
179     {
180     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wmunu_8TeVUp";
181     namen = channel;
182     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wmunu_8TeVDown";
183    
184     if(channel == "s_Top")
185     {
186     nameUp = channel + "_CMS_vhbb_statsTop_Wmunu_8TeVUp";
187     namen = channel;
188     nameDown = channel + "_CMS_vhbb_statsTop_Wmunu_8TeVDown";
189     }
190    
191    
192     }
193    
194    
195     if( systT.Contains("stat") && (oldFolder.Contains("Wen")) && IFILE.Contains("8TeV") && (oldFolder.Contains("High")))
196     {
197     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wenu2_8TeVUp";
198     namen = channel;
199     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wenu2_8TeVDown";
200    
201     if(channel == "s_Top")
202     {
203     nameUp = channel + "_CMS_vhbb_statsTop_Wenu2_8TeVUp";
204     namen = channel;
205     nameDown = channel + "_CMS_vhbb_statsTop_Wenu2_8TeVDown";
206     }
207    
208    
209     }
210    
211     if( systT.Contains("stat") && (oldFolder.Contains("Wmn")) && IFILE.Contains("8TeV") && (oldFolder.Contains("High")))
212     {
213     nameUp = channel + "_CMS_vhbb_stat" + channel + "_Wmunu2_8TeVUp";
214     namen = channel;
215     nameDown = channel + "_CMS_vhbb_stat" + channel + "_Wmunu2_8TeVDown";
216    
217     if(channel == "s_Top")
218     {
219     nameUp = channel + "_CMS_vhbb_statsTop_Wmunu2_8TeVUp";
220     namen = channel;
221     nameDown = channel + "_CMS_vhbb_statsTop_Wmunu2_8TeVDown";
222     }
223    
224    
225     }
226     if(writeIt)
227     {
228    
229    
230    
231    
232    
233    
234     RooDataHist* tempRooDataHistUp = (RooDataHist*) tempWS->data(nameUp.c_str());
235     RooDataHist* tempRooDataHistDown = (RooDataHist*) tempWS->data(nameDown.c_str());
236     RooDataHist* tempRooDataHistNom = (RooDataHist*) tempWS->data(namen.c_str());
237    
238    
239     std::cout << oldFolder.Data() << std::endl;
240     std::cout << nameUp.c_str() << std::endl;
241    
242    
243    
244    
245    
246     TH1 *tempHistUp = tempRooDataHistUp->createHistogram(nameUp.c_str(),BDT,Binning(bins));
247     TH1 *tempHistDown = tempRooDataHistDown->createHistogram(nameDown.c_str(),BDT,Binning(bins));
248     TH1 *tempHistNom = tempRooDataHistNom->createHistogram(namen.c_str(),BDT,Binning(bins));
249    
250     if(chanT.Contains("VH") && IFILE.Contains("7TeV"))
251     {
252     tempHistUp->Scale(xSec7WH[toMassNo]/xSec7WH[fromMassNo]);
253     tempHistDown->Scale(xSec7WH[toMassNo]/xSec7WH[fromMassNo]);
254     tempHistNom->Scale(xSec7WH[toMassNo]/xSec7WH[fromMassNo]);
255     }
256    
257     if(chanT.Contains("VH") && IFILE.Contains("8TeV"))
258     {
259     tempHistUp->Scale(xSec8WH[toMassNo]/xSec8WH[fromMassNo]);
260     tempHistDown->Scale(xSec8WH[toMassNo]/xSec8WH[fromMassNo]);
261     tempHistNom->Scale(xSec8WH[toMassNo]/xSec8WH[fromMassNo]);
262     }
263    
264     std::cout<< "channel--> " << channel << std::endl;
265    
266    
267    
268     tempHistUp->SetLineColor(kRed);
269     tempHistUp->SetLineWidth(3);
270     tempHistUp->SetFillColor(0);
271    
272     tempHistDown->SetLineColor(kBlue);
273     tempHistDown->SetFillColor(0);
274     tempHistDown->SetLineWidth(3);
275    
276     tempHistNom->SetFillColor(0);
277     tempHistNom->SetMarkerStyle(20);
278    
279     tempHistUp->SetTitle((channel + syst).c_str());
280    
281     RooDataHist *DHnom;
282     RooDataHist *DHup = new RooDataHist(nameUp.c_str(),"",*hobs,tempHistUp);
283     if(kount2 < 3) DHnom = new RooDataHist(namen.c_str(),"",*hobs,tempHistNom);
284     RooDataHist *DHdown = new RooDataHist(nameDown.c_str(),"",*hobs,tempHistDown);
285    
286     WS->import(*(new RooHistPdf(nameUp.c_str(),"",*hobs,*DHup)));
287     WS->import(*(new RooHistPdf(nameDown.c_str(),"",*hobs,*DHdown)));
288     if(kount2 < 3){ WS->import(*(new RooHistPdf(namen.c_str(),"",*hobs,*DHnom))); kount2++;}
289     }
290     }
291    
292    
293     }
294    
295    
296    
297    
298    
299    
300     void Process(TString fname, TString oldFolder, int toMass, int fromMass)
301     {
302    
303    
304    
305    
306     std::string channels[] = {"data_obs", "VH", "TT", "WjLF", "WjHF", "ZjLF", "ZjHF" , "VV" , "s_Top" };
307     std::string systs[] = {"eff_b", "fake_b_8TeV", "res_j", "scale_j" , "stat" };
308    
309     kount = 0;
310    
311     gROOT->SetStyle("Plain");
312     setTDRStyle();
313    
314     TFile * file = new TFile(fname.Data(), "READ");
315     std::cout << "reading " << fname.Data() << std::endl;
316     TString outname(massS[toMass]);
317     outname.Append(".root");
318     fname.ReplaceAll(".root",outname.Data());
319     TFile * outfile = new TFile(fname.Data(), "RECREATE");
320    
321     using namespace RooFit;
322     RooWorkspace *myWS = new RooWorkspace(oldFolder.Data(),oldFolder.Data());
323     myWS->factory("CMS_vhbb_BDT_Wln_8TeV[-1.,1.]"); ///NEW VARIABLE NAME HERE
324    
325    
326     for (int c =0; c<9; c++)
327     {
328     kount2 = 0;
329     for (int s =0; s<5 ; s++ ){
330     makeSystPlot( file, oldFolder, myWS, channels[c], systs[s], toMass, fromMass );
331     }
332     }
333    
334    
335     if(!(IFILE.Contains("8TeV")))
336     {
337     makeSystPlot(file, oldFolder, myWS, "WjLF", "WModel",toMass, fromMass);
338     makeSystPlot(file, oldFolder, myWS, "WjHF", "WModel",toMass, fromMass);
339     }
340    
341     myWS->writeToFile(fname.Data());
342     std::cout << std::endl << std::endl << std::endl << std::endl << "///////////////////////////" << std::endl;
343     std::cout << fname.Data() << " written" << std::endl;
344     std::cout << "///////////////////////////" << std::endl << std::endl << std::endl;
345     outfile->Write();
346     outfile->Close();
347    
348    
349     }
350    
351    
352    
353    
354    
355     void IntermediateMassMakerWH()
356     {
357    
358     maxCount=0;
359    
360    
361    
362    
363     for(int i = 0; i < n; i++)
364     {
365     TString oldFolder;
366     IFILE = files[i];
367    
368     if(IFILE.Contains("7TeV"))
369     {
370     if(IFILE.Contains("Wenu")) oldFolder = "Wenu";
371     if(IFILE.Contains("Wmn"))oldFolder = "Wmunu";
372     }
373    
374     if(IFILE.Contains ("Wmn") && IFILE.Contains("Low") && IFILE.Contains("8TeV")) oldFolder = "WmnLowPt_8TeV";
375     if(IFILE.Contains ("Wen") && IFILE.Contains("Low") && IFILE.Contains("8TeV")) oldFolder = "WenLowPt_8TeV";
376     if(IFILE.Contains ("Wmn") && IFILE.Contains("High") && IFILE.Contains("8TeV")) oldFolder = "WmnHighPt_8TeV";
377     if(IFILE.Contains ("Wen") && IFILE.Contains("High") && IFILE.Contains("8TeV")) oldFolder = "WenHighPt_8TeV";
378    
379     if((IFILE.Contains("110")))
380     {
381     Process(IFILE, oldFolder, 0,0);
382     Process(IFILE, oldFolder, 1,0);
383     Process(IFILE, oldFolder, 2,0);
384     Process(IFILE, oldFolder, 3,0);
385     Process(IFILE, oldFolder, 4,0);
386     }
387     if((IFILE.Contains("115")))
388     {
389     for(int to = 5; to < 15; to++) Process(IFILE, oldFolder, to , 10);
390     }
391    
392     if((IFILE.Contains("120")))
393     {
394     for(int to = 15; to < 25; to++) Process(IFILE, oldFolder,to , 20);
395     }
396    
397     if((IFILE.Contains("125")))
398     {
399     for(int to = 25; to < 35; to++) Process(IFILE, oldFolder,to , 30);
400     }
401    
402     if((IFILE.Contains("130")))
403     {
404     for(int to = 35; to < 45; to++) Process(IFILE, oldFolder,to , 40);
405     }
406    
407    
408     if((IFILE.Contains("135")))
409     {
410     for(int to = 45; to < 51; to++) Process(IFILE, oldFolder,to , 50);
411     }
412    
413    
414    
415     }
416     }
417    
418