StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
plReweight.C
1 //determine vertex z reweighting for embedded simulation samples
2 const int maxFiles=5;
3 
4 void plReweight(){
5 
6  gStyle->SetOptStat(00000);
7  gStyle->SetOptDate(0);
8 
9  char* iPath="./outEmb/";
10  char* fileName[maxFiles]={"Wplus","Wminus","Wtau","Zany","Ze+e-Interf"};
11  TH1F* h[maxFiles];
12  for(int i=0; i<maxFiles; i++){
13  TString file=iPath; file+=fileName[i];
14  h[i]=plReweightX(file,fileName[i]);
15  }
16 
17  //write file with ratio histo to use in analysis code
18  outf=new TFile("zVertReweight.root","recreate");
19  for(int j=0;j<maxFiles;j++)
20  h[j]->Write();
21 }
22 
23 
24 TH1F* plReweightX(TString file, char* name){
25 
26  //load embedding sample file
27  file+=".wana.hist.root";
28  fd=new TFile(file);
29 
30  //load data file
31  fdata=new TFile("/star/data01/pwg/stevens4/wAnalysis/xSecPaper/sl11b/data/run9setABCD.wana.hist.root");
32 
33  //get histos
34  TH1F* simZ=fd->Get("muZv"); simZ->Rebin();
35  TH1F* dataZ=fdata->Get("muZv"); dataZ->Rebin();
36 
37  assert(simZ); assert(dataZ);
38 
39  //take ratio of data/embedding and scale to 1 at z=0
40  TH1F* ratio=dataZ->Clone();
41  ratio->Divide(simZ);
42  ratio->Scale(1./ratio->GetBinContent(24));
43  ratio->SetName(name);
44  //ratio->Draw();
45  //cout<<ratio->Integral(24,25)<<endl;
46 
47  //scale embedded sample with ratio histo (like in analysis)
48  TH1F* test= simZ->Clone();
49  for(int i=1; i<=test->GetNbinsX(); i++){
50  float z=test->GetBinCenter(i);
51  test->SetBinContent(i,test->GetBinContent(i)*ratio->GetBinContent(ratio->FindBin(z)));
52  }
53  //check that re-weighted sample agrees with data
54  TCanvas *c1=new TCanvas("aa","bb",600,400);
55  dataZ->Draw(); dataZ->SetTitle("; Z_{vertex} (cm)");
56  test->SetLineColor(2);
57  test->DrawNormalized("same",dataZ->Integral());
58  simZ->SetLineColor(4);
59  simZ->DrawNormalized("same",dataZ->Integral());
60  //gPad->SetLogy();
61 
62  TLegend *leg = new TLegend(0.6,0.65,0.9,0.9);
63  leg->SetFillColor(0);
64  leg->AddEntry(dataZ," Data Z_{vertex}","l");
65  leg->AddEntry(simZ," Thrown MC Z_{vertex}","l");
66  leg->AddEntry(test," Re-weighted MC Z_{vertex}","l");
67  leg->Draw("same");
68  c1->Print(Form("plots/vertReweight/%s.png",name));
69  c1->Print(Form("plots/vertReweight/%s.eps",name));
70 
71  return ratio;
72 
73  //look at histos before weighting
74  dataZ->Draw();
75  simZ->SetLineColor(2);
76  simZ->DrawNormalized("same",dataZ->GetEntries());
77  dataZ->SetMinimum(1);
78  gPad->SetLogy();
79 
80 }