ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/ZbTools.C
Revision: 1.1
Committed: Mon Jun 25 13:34:21 2012 UTC (12 years, 10 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Log Message:
Added Musich-type Z+b plots generator

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2     #include <vector>
3     #include <sys/stat.h>
4    
5     #include <TCut.h>
6     #include <TROOT.h>
7     #include <TCanvas.h>
8     #include <TMath.h>
9     #include <TColor.h>
10     #include <TPaveText.h>
11     #include <TRandom.h>
12     #include <TH1.h>
13     #include <TH2.h>
14     #include <TF1.h>
15     #include <TSQLResult.h>
16     #include <TProfile.h>
17     #include <TLegendEntry.h>
18    
19     using namespace std;
20    
21     using namespace PlottingSetup;
22    
23     namespace ZbData {
24     vector<float> data_over_mc;
25    
26     TCut ZplusBsel("pt1>20&&pt2>20&&mll>60&&mll<120");
27     TCut LeadingB("bTagProbCSVBP[0]>0.679");
28     TCut EtaB("abs(pfJetGoodEta[0])<1.3");
29     TCut PhiZcut("pfJetDphiZ[0]>2.7");
30    
31     }
32    
33     using namespace ZbData;
34    
35     void print_yield(TCut cut) {
36     TH1F *data = allsamples.Draw("data", "mll",1,0,10000000, "m_{ll} [GeV]", "events", cut,data,luminosity);
37     cout << " Yields for " << (const char*) cut << endl;
38     cout << " data: " << data->Integral() << endl;
39     THStack mcm = allsamples.DrawStack("mc", "mll",1,0,10000000, "m_{ll} [GeV}", "events", cut,mc,luminosity);
40     int nhists = mcm.GetHists()->GetEntries();
41     cout << "Going to loop over " << nhists << " histograms " << endl;
42     TFile *test = new TFile("test.root","RECREATE");
43     mcm.Write();
44     test->Close();
45     for (int i = 0; i < nhists; i++) {
46     TH1* hist = static_cast<TH1*>(mcm.GetHists()->At(i));
47     cout << " " << hist->GetName() << ": " << hist->Integral() << endl;
48     }
49     cout << endl << endl;
50     delete data;
51     }
52    
53     void draw_kin_variable(string variable, TCut cut, int nbins, float min, float max, string xlabel, string saveas, bool dologscale) {
54    
55     TCanvas *ckin = new TCanvas("ckin","kin variable canvas");
56     ckin->SetLogy(dologscale);
57     TH1F *datahisto = allsamples.Draw("datahisto",variable,nbins,min,max, xlabel, "events",cut,data,luminosity);
58     datahisto->SetMarkerSize(DataMarkerSize);
59     THStack mcstack = allsamples.DrawStack("mcstack",variable,nbins,min,max, xlabel, "events",cut,mc,luminosity);
60     datahisto->SetMaximum(5.3*datahisto->GetMaximum());
61     datahisto->Draw("e1");
62     ckin->Update();
63     mcstack.Draw("same");
64     datahisto->Draw("same,e1");
65     TLegend *kinleg = allsamples.allbglegend();
66     kinleg->Draw();
67    
68     TPad *kinpad = new TPad("kinpad","kinpad",0,0,1,1);
69     kinpad->cd();
70     kinpad->SetLogy(dologscale);
71     datahisto->Draw("e1");
72     mcstack.Draw("same");
73     datahisto->Draw("same,e1");
74     datahisto->Draw("same,axis");
75     kinleg->Draw();
76     DrawPrelim();
77     saveas="kin/"+saveas;
78     save_with_ratio(datahisto,mcstack,kinpad->cd(),saveas);
79    
80    
81    
82    
83     ZbData::data_over_mc.push_back(datahisto->Integral()/CollapseStack(mcstack)->Integral());
84    
85     datahisto->Delete();
86     delete ckin;
87    
88    
89    
90     write_warning(__FUNCTION__,"Not implemented yet");
91     write_warning(__FUNCTION__,"Need to store overall data_over_mc");
92     }
93    
94     Value getfrom2Dmap(TH2F *map, int ixbin, int iybin) {
95     Value sum(0,0);
96     for(int iy=1;iy<=iybin;iy++) {
97     sum=sum+Value(map->GetBinContent(ixbin,iy),map->GetBinError(ixbin,iy));
98     }
99     return sum;
100     }
101    
102    
103     void data_mc_agreement_2d() {
104    
105     vector<int> emptyvector;
106     float binX[5]={10,50,100,200,1000};
107     float binY[5]={0.0,0.1,0.15,0.2,0.3};
108     vector<float>binningx;
109     vector<float>binningy;
110     binningx.assign(binX,binX+5);
111     binningy.assign(binY,binY+5);
112    
113     TCut cut(ZplusBsel&&LeadingB&&EtaB&&PhiZcut);
114    
115     TCanvas *agrcan = new TCanvas("agrcan","agrcan");
116    
117     cout << "Drawing 2d for data " << endl;
118     TH2F *alphazptplane_data = allsamples.Draw("alphazptplane_data","alpha:pt",binningx,binningy,"Z p_{T}","#alpha",cut,data,luminosity,emptyvector,false);
119     cout << "Drawing 2d for MC " << endl;
120     TH2F *alphazptplane_mc = allsamples.Draw("alphazptplane_mc", "alpha:pt",binningx,binningy,"Z p_{T}","#alpha",cut,mc, luminosity,emptyvector,false);
121    
122    
123     TFile *f = new TFile("test.root","RECREATE");
124     alphazptplane_data->Write();
125     f->Close();
126    
127     for(int ix=1;ix<binningx.size();ix++) {
128     cout << "pt in " << binningx[ix-1] << " , " << binningx[ix] << endl;
129     TGraphErrors gr;
130     for(int iy=1;iy<binningy.size();iy++) {
131     Value mc = Value((getfrom2Dmap(alphazptplane_mc,ix,iy)).getValue(),0.0);// not taking MC statistics into account
132     Value data = getfrom2Dmap(alphazptplane_data,ix,iy);
133     cout << " For an alpha cut at " << binningy[iy] << " we get : mc (" << mc << ") , data (" << data << ") --> data/mc = " << data/mc << endl;
134     gr.SetPoint(iy-1,binningy[iy],(data/mc).getValue());
135     gr.SetPointError(iy-1,0,(data/mc).getError());
136     }
137    
138     gr.Draw("AP*");
139     gr.GetYaxis()->SetTitle("data / mc");
140     gr.GetYaxis()->CenterTitle();
141     gr.GetXaxis()->SetTitle("#alpha");
142     gr.GetXaxis()->CenterTitle();
143     gr.GetXaxis()->SetRangeUser(0,0.4);
144     gr.GetYaxis()->SetRangeUser(0.5,1.5);
145     gr.Draw("AP*");
146     DrawPrelim();
147     stringstream ptbin;
148     ptbin << binningx[ix-1] << " < p_{T}^{Z} < " << binningx[ix] << " GeV";
149     TText *ptt = write_title(ptbin.str());
150     ptt->SetX(0.7);
151     ptt->SetY(0.7);
152     ptt->SetTextSize(0.03);
153     ptt->Draw();
154     TLine *l = new TLine(0.0,1.0,0.4,1.0);
155     l->SetLineStyle(2);
156     l->SetLineColor(kBlue);
157     l->Draw();
158    
159     stringstream saveas;
160     saveas << "Zplusb_data_over_mc___" << binningx[ix-1] << "to" << binningx[ix];
161     CompleteSave(agrcan,saveas.str());
162     // agrcan->SaveAs("tester.png");
163     }
164    
165     delete agrcan;
166    
167     }
168    
169     void print_all_b_yields() {
170     cout << "Basic selection with a b jet" << endl;
171     print_yield(ZplusBsel&&"pfJetGoodNumBtag>0");
172     cout << "Leading jet is a b " << endl;
173     print_yield(ZplusBsel&&LeadingB);
174     cout << "|#eta_{b}|<1.3 " << endl;
175     print_yield(ZplusBsel&&LeadingB&&EtaB);
176     cout << "|#delta#phi(b<Z)|>2.7" << endl;
177     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut);
178     cout << "10<ptZ<100 GeV" << endl;
179     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000");
180     cout << "#alpha < 0.3" << endl;
181     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.3");
182     cout << "#alpha < 0.2" << endl;
183     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.2");
184     cout << "#alpha < 0.15" << endl;
185     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.15");
186     cout << "#alpha < 0.1" << endl;
187     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.1");
188     cout << "#alpha < 0.05" << endl;
189     print_yield(ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.05");
190     }
191    
192     void draw_Zb_kin_vars() {
193     draw_kin_variable("pfBJetDphiZ",ZplusBsel&&LeadingB,100,0,3.2,"#delta#phi (Z,b lead)","DeltaPhiZBlead",1);
194     draw_kin_variable("pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000",50,0,200,"Z p_{T}","Zpt",1);
195     draw_kin_variable("pfJetGoodPt[1]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000",50,0,200,"Sub-Leading Jet Pt","Jet2Pt",1);
196     draw_kin_variable("pfJetGoodPtlBtag[0]",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000",50,0,200,"Leading Jet Pt (B)","LeadingJetPt",1);
197     draw_kin_variable("alpha",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000",20,0,2,"#alpha","alpha",1);
198     }
199    
200     void draw_mpf_vars() {
201     ZbData::data_over_mc.clear();
202     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.3",20,0,2,"Z+b MPF","mpf_alpha_smaller_0p3",0);
203     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.2",20,0,2,"Z+b MPF","mpf_alpha_smaller_0p2",0);
204     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.15",20,0,2,"Z+b MPF","mpf_alpha_smaller_0p15",0);
205     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.1",20,0,2,"Z+b MPF","mpf_alpha_smaller_0p1",0);
206     draw_kin_variable("mpf",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.05",20,0,2,"Z+b MPF","mpf_alpha_smaller_0p05",0);
207    
208     draw_kin_variable("pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.3",20,0,2,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p3",0);
209     draw_kin_variable("pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.2",20,0,2,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p2",0);
210     draw_kin_variable("pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.15",20,0,2,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p15",0);
211     draw_kin_variable("pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.1",20,0,2,"p_{T} b-jet / p_{T} Z","ptb_over_ptz___alpha_smaller_0p1",0);
212     draw_kin_variable("pfJetGoodPt[0]/pt",ZplusBsel&&LeadingB&&EtaB&&PhiZcut&&"pt>10&&pt<1000"&&"alpha<0.05",20,0,2,"p_{T} b-jet / p_{T} Z","ptb_over_ptz__mpf_alpha_smaller_0p05",0);
213     }
214    
215     void do_basic_ZB_analysis() {
216    
217    
218    
219     data_mc_agreement_2d();
220    
221     write_warning(__FUNCTION__,"Replaced B jet dphi cut with jet dphi cut - need to put this back!");
222     }