StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
prd2009WdataMCetaSidebySide.C
1 TH1F *hBase;
2 TCanvas *c;
3 
4 bool colorPlot;
5 TString iPathMC,iPathData;
6 
7 void prd2009WdataMCetaSidebySide(bool x=false,TString y="/star/u/stevens4/wAnalysis/efficXsec/outEmb/gainUp2/",TString z="/star/data01/pwg/stevens4/wAnalysis/xSecPaper/sl11b/data/",float canvasScale=1.0){
8 
9  colorPlot=x;
10  iPathMC=y;
11  iPathData=z;
12 
13  c=new TCanvas("aa","bb",500*canvasScale,300*canvasScale);
14  if(!colorPlot) c->SetGrayscale();
15 
16  TPad *cT = new TPad("padT","padT",0,0,0.5,1.); cT->Draw();
17  TPad *cB = new TPad("padB","padB",0.5,0,1.,1.0); cB->Draw();
18  //c->Divide(1,2);
19 
20  //both charges
21  cT->cd();
22  prd2009WdataMCetaX("Wplus","pos",128.6,270.0,1,canvasScale);
23  cB->cd();
24  prd2009WdataMCetaX("Wminus","neg",385.0,85.0,2,canvasScale);
25 
26  if(colorPlot) {
27  c->Print("/star/u/stevens4/wAnalysis/xSecPaper/plots/color/wEtaColor.eps");
28  c->Print("/star/u/stevens4/wAnalysis/xSecPaper/plots/color/wEtaColor.png");
29  }
30  else {
31  c->Print("/star/u/stevens4/wAnalysis/xSecPaper/plots/bw/wEtaBW.eps");
32  c->Print("/star/u/stevens4/wAnalysis/xSecPaper/plots/bw/wEtaBW.png");
33  }
34 
35  return;
36 
37 }
38 
39 void prd2009WdataMCetaX(string charge, string charge2,float wlumi,float max,int pad,float canvasScale) {
40 
41  gStyle->SetOptStat(0);
42  gStyle->SetOptDate(0);
43 
44  float lumi[4] = {13.18,wlumi,96.2,531.9};
45 
46  TFile *f[4]; TH2F *h[4];
47  TString name[4]={"run9setABCD",Form("%s",charge),"Wtau","Ze+e-Interf"};
48  TString path[4]={iPathData,iPathMC,iPathMC,iPathMC};
49  for(int i=0; i<4; i++){
50  f[i]=new TFile(Form("%s%s.wana.hist.root",path[i].Data(),name[i].Data())); assert(f[i]->IsOpen());
51  h[i]=(TH2F*)f[i]->Get(Form("%s_muclustpTbal_wE_etaBin",charge2));
52  h[i]->Scale(13.18/lumi[i]);
53  }
54 
55  //c->cd(pad);
56  if(pad==1){
57  gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0.15);
58  gPad->SetLeftMargin(0.2); gPad->SetRightMargin(0.03);
59  }
60  if(pad==2){
61  gPad->SetTopMargin(0.01); gPad->SetBottomMargin(0.15);
62  gPad->SetLeftMargin(0.2); gPad->SetRightMargin(0.03);
63  }
64  gPad->SetGridy(false); gPad->SetGridx(false);
65  initHisto();
66  hBase->SetMinimum(0.0); hBase->SetMaximum(max);
67  //if(pad==1) hBase->SetMinimum(0.001);
68  hBase->GetXaxis()->SetTitleSize(0.07);
69  hBase->GetXaxis()->SetTitleOffset(0.98);
70  hBase->GetXaxis()->CenterTitle();
71  hBase->GetXaxis()->SetNdivisions(4);
72  hBase->GetXaxis()->SetLabelSize(0.06);
73  hBase->GetYaxis()->CenterTitle();
74  hBase->GetYaxis()->SetTitleSize(0.07);
75  hBase->GetYaxis()->SetTitleOffset(1.3);
76  hBase->GetYaxis()->SetLabelSize(0.06);
77  hBase->GetYaxis()->SetLabelOffset(0.012);
78  hBase->GetYaxis()->SetNdivisions(6);
79  if(pad==2) {
80  hBase->GetYaxis()->SetTitleOffset(1.2);
81  }
82  hBase->Draw();
83  THStack *hs = new THStack("hs","test");
84 
85  //write histos with yields in each bin
86  TH1F* hEta[6];
87 
88  //define QCD piece by hand from background macro output
89  hEta[4]=(TH1F*)hBase->Clone(); hEta[4]->SetName("bin4");
90  hEta[5]=(TH1F*)hBase->Clone(); hEta[5]->SetName("bin5");
91  if(charge=="Wplus") {
92  //second EEMC
93  hEta[4]->SetBinContent(1,0.13); hEta[4]->SetBinContent(2,2.71);
94  hEta[4]->SetBinContent(3,0.88); hEta[4]->SetBinContent(4,5.35);
95  //QCD
96  hEta[5]->SetBinContent(1,2.28); hEta[5]->SetBinContent(2,3.02);
97  hEta[5]->SetBinContent(3,0.0); hEta[5]->SetBinContent(4,2.00);
98  }
99  else if(charge=="Wminus"){
100  //second EEMC
101  hEta[4]->SetBinContent(1,3.31); hEta[4]->SetBinContent(2,3.28);
102  hEta[4]->SetBinContent(3,0.21); hEta[4]->SetBinContent(4,2.45);
103  //QCD
104  hEta[5]->SetBinContent(1,2.27); hEta[5]->SetBinContent(2,2.34);
105  hEta[5]->SetBinContent(3,0.82); hEta[5]->SetBinContent(4,0.68);
106  }
107 
108  //int style[5]={1,1001,3144,1001};
109  if(colorPlot) {
110  int color[6]={1,kMagenta,kGreen,kBlue,kRed,kOrange};
111  hEta[4]->SetLineColor(color[4]);
112  hEta[4]->SetFillColor(color[4]);
113  hEta[5]->SetLineColor(color[5]);
114  hEta[5]->SetFillColor(color[5]);
115  }
116  else {
117  int color[6]={1,kMagenta,kYellow+2,kYellow+4,kYellow};
118  hEta[4]->SetLineColor(1); hEta[4]->SetFillColor(color[4]);//color[5]);
119  hEta[5]->SetFillStyle(3344); hEta[5]->SetLineColor(1); hEta[5]->SetFillColor(1);
120  }
121 
122 
123  float low[4]={-.99,-.49,0.01,0.51};
124  float high[4]={-.51,-.01,0.49,0.99};
125  for(int j=3; j>=0; j--) { //loop over samples
126  hEta[j]=(TH1F*)hBase->Clone(); hEta[j]->SetName(Form("bin%d",j));
127  for(int ieta=0; ieta<4; ieta++) { //loop over eta bins
128  int etaLow=h[j]->GetXaxis()->FindBin(low[ieta]);
129  int etaHigh=h[j]->GetXaxis()->FindBin(high[ieta]);
130  float yield=h[j]->Integral(etaLow,etaHigh,26,100);
131  //cout<<"etaLow="<<etaLow<<" etaHigh="<<etaHigh<<" yield="<<yield<<endl;
132  hEta[j]->SetBinContent(ieta+1,yield);
133  if(j==0) hEta[j]->SetBinError(ieta+1,sqrt(yield));
134  }
135 
136  hEta[j]->SetLineColor(color[j]);
137  if(j==1) hEta[j]->SetLineStyle(2);
138  if(j>1) {
139  hEta[j]->SetFillColor(color[j]); //don't fill data
140  //hEta[j]->SetFillStyle(style[j]);
141  }
142  else
143  hEta[j]->SetLineWidth(2);
144 
145  if(j>0) hs->Add(hEta[j]);
146 
147  if(j==2) {
148  hs->Add(hEta[4]); //add EEMC on top of Z and Wtau
149  hs->Add(hEta[5]); //add QCD on top of EEMC
150  }
151  }
152  hs->Draw("same");
153  hEta[0]->Draw("same e");
154 
155  //make legend
156  float textSize=0.047; if(canvasScale>1.0) textSize=0.044;
157  if(charge=="Wplus") {
158  TLegend *leg = new TLegend(0.25,0.75,0.8,0.97);
159  leg->SetEntrySeparation(0.01);
160  leg->SetMargin(0.2);
161  leg->SetFillColor(kWhite);
162  leg->SetTextSize(textSize);
163  leg->SetLineColor(kWhite);
164  leg->SetHeader("#scale[1.25]{Positron E^{e}_{T}>25 GeV}");
165  leg->AddEntry(hEta[0]," STAR 2009 Data","l");
166  leg->AddEntry(hEta[1]," W #rightarrow e #nu MC","l");
167  leg->AddEntry(hEta[5]," Data-driven QCD","f");
168  leg->Draw();
169  }
170  else {
171  TLegend *leg = new TLegend(0.25,0.75,0.8,0.97);
172  leg->SetEntrySeparation(0.01);
173  leg->SetMargin(0.2);
174  leg->SetFillColor(kWhite);
175  leg->SetTextSize(textSize);
176  leg->SetLineColor(kWhite);
177  leg->SetHeader("#scale[1.25]{Electron E^{e}_{T}>25 GeV}");
178  leg->AddEntry(hEta[4]," Second EEMC","f");
179  leg->AddEntry(hEta[2]," W #rightarrow #tau #nu MC","f");
180  leg->AddEntry(hEta[3]," Z #rightarrow ee MC","f");
181  leg->Draw();
182  }
183 
184  return;
185 
186 
187 
188 }
189 
190 //------------------------------
191 void initHisto() {
192  char *txt0="h";
193  hBase=new TH1F(txt0, "; #eta_{e}; Counts", 4, -1.,1.);
194 }