Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ana.C
Go to the documentation of this file.
1 using namespace std;
2 
3 double ratio_error(
4  const double a,
5  const double b,
6  const double ea,
7  const double eb
8  ) {
9  double r = a/b;
10  double er = r*sqrt(
11  (ea/a)*(ea/a) + (eb/b)*(eb/b)
12  );
13  return er;
14 }
15 
16 double binom_error(
17  const double a,
18  const double b
19  ){
20  double r=a/b;
21  return sqrt(r*(1-r)/b);
22 }
23 
24 TH1D * getEffHist(
25  const char* hname,
26  const TH1D* h1,
27  const TH1D* h2
28  ) {
29  TH1D *h = h1->Clone(hname);
30  int nbin = h->GetNbinsX();
31  for(int ibin=1; ibin<=nbin; ++ibin) {
32  double a = h1->GetBinContent(ibin);
33  double b = h2->GetBinContent(ibin);
34  double r = a/b;
35  double e = binom_error(a, b);
36  h->SetBinContent(ibin, r);
37  h->SetBinError(ibin, e);
38  }
39 
40  return h;
41 }
42 namespace {
43  int nfiles = 4;
44  char* inputs [] = {
45  //"eval_gap_0.root",
46  "eval_gap_1.root",
47  "eval_gap_2.root",
48  "eval_gap_5.root",
49  "eval_gap_10.root"
50  };
51 
52  float gap_size[] = { 1, 2, 5, 10};
53  float gap_size_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
54 }
55 
56 void drawRelAcc() {
57 
58  float mean[] = {0, 0, 0, 0, 0, 0, 0, 0};
59  float mean_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
60  float mean0 = 1;
61  float mean_error0 = 0;
62  for (int i=0; i<nfiles; ++i) {
63  TFile *f = TFile::Open(inputs[i],"read");
64  TH1D *h = new TH1D("h","h",3,0,3);
65  //T->Project("h","Sum$(gnhodo>=8)>=2");
66  T->Project("h","Sum$(ntruhits>0)>=2");
67  mean[i] = h->GetMean();
68  mean_error[i] = h->GetMeanError();
69  if(i==0) {
70  mean0 = mean[i];
71  mean_error0 = mean_error[i];
72  }
73  mean[i] = mean[i]/mean0;
74  mean_error[i] = mean_error[i]/mean0;
75  }
76 
77  TCanvas *drawRelAcc_c0 = new TCanvas("drawRelAcc_c0","drawRelAcc_c0");
78  drawRelAcc_c0->SetGrid();
79 
80  TGraphErrors* gr = new TGraphErrors(nfiles, gap_size, mean, gap_size_error, mean_error);
81  gr->SetTitle(";H1 gap size (cm); Drell-Yan Acc.");
82  gr->SetMarkerStyle(20);
83  gr->Draw("ap");
84  gr->GetXaxis()->SetRangeUser(-5,11);
85 
86  float data_mean[] = {1, 0.982, 0.954, 0.917};
87  float data_gap[] = {1, 2, 4, 6};
88  TGraph* data_gr = new TGraph(4, data_gap, data_mean);
89  data_gr->SetMarkerStyle(4);
90  data_gr->SetMarkerColor(kRed);
91  data_gr->Draw("same,p");
92 }
93 
94 void drawAccPhi() {
95  TCanvas *c0 = new TCanvas("c0","c0"); c0->SetGrid();
96  TCanvas *c1 = new TCanvas("c1","c1"); c1->SetGrid();
97  TCanvas *c2 = new TCanvas("c2","c2"); c2->SetGrid();
98  TCanvas *c3 = new TCanvas("c3","c3"); c3->SetGrid();
99 
100  float mod[] = {0, 0, 0, 0, 0, 0, 0, 0};
101  float mod_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
102 
103  for (int i=0; i<nfiles; ++i) {
104  TFile *f = TFile::Open(inputs[i],"read");
105  TH1D *hnum = new TH1D("hnum","hnum",16, -3.14, 3.14);
106  TH1D *hden = new TH1D("hden","hden",16, -3.14, 3.14);
107 
108  //T->Project("hnum","dimu_gphi","dimu_nrec>=2");
109  T->Project("hnum","dimu_gphi","Sum$(gnhodo>=8)>=2");
110  T->Project("hden","dimu_gphi");
111 
112  TH1D* hrat = getEffHist("hrat", hnum, hden);
113  //TH1D* hrat = hden->Clone("hrat");;
114  //TH1D* hrat = hnum->Clone("hrat");;
115 
116  hnum->SetMarkerStyle(20);
117  hden->SetMarkerStyle(20);
118  hrat->SetMarkerStyle(20);
119 
120  int color = kBlack;
121 
122  if(i==0) {
123 
124  color = kBlack;
125 
126  c0->cd();
127  hnum->SetTitle("nDimu-trig. vs. #phi; #phi [rad]; nDimu-trig.");
128  hnum->SetMarkerColor(color);
129  hnum->SetLineColor(color);
130  hnum->SetMinimum(0);
131  hnum->Draw("e");
132 
133  c1->cd();
134  hden->SetTitle("nDimu-gen. vs. #phi; #phi [rad]; nDimu-gen.");
135  hden->SetMarkerColor(color);
136  hden->SetLineColor(color);
137  hden->SetMinimum(0);
138  hden->Draw("e");
139 
140  c2->cd();
141  hrat->SetTitle("Acc. vs. #phi; #phi [rad]; Acc.");
142  hrat->SetMarkerColor(color);
143  hrat->SetLineColor(color);
144  hrat->SetMinimum(0);
145  hrat->SetMaximum(0.1);
146  hrat->Draw("e");
147  //hrat->SetStats(0);
148  TF1 *cos = new TF1("cos","[0]*cos(2*x)+[1]");
149  cos->SetLineColor(color);
150  hrat->Fit("cos");
151  mod[i] = cos->GetParameter(0);
152  mod_error[i] = cos->GetParError(0);
153  }
154  else {
155  color = i+1;
156 
157  c0->cd();
158  hnum->SetMarkerColor(color);
159  hnum->SetLineColor(color);
160  hnum->Draw("esame");
161 
162  c1->cd();
163  hden->SetMarkerColor(color);
164  hden->SetLineColor(color);
165  hden->Draw("esame");
166 
167  c2->cd();
168  hrat->SetMarkerColor(color);
169  hrat->SetLineColor(color);
170  hrat->Draw("esame");
171  TF1 *cos = new TF1("cos","[0]*cos(2*x)+[1]");
172  cos->SetLineColor(color);
173  hrat->Fit("cos");
174  mod[i] = cos->GetParameter(0);
175  mod_error[i] = cos->GetParError(0);
176  }
177  }
178 
179 
180  c3->cd();
181  TGraphErrors* gr = new TGraphErrors(nfiles, gap_size, mod, gap_size_error, mod_error);
182  gr->SetTitle(";H1 gap size (cm); Cos(2x) Mod. Str.");
183  gr->SetMarkerStyle(20);
184  gr->Draw("ap");
185  gr->GetXaxis()->SetRangeUser(-5,11);
186  gr->GetYaxis()->SetRangeUser(-0.01, 0);
187 
188 }
189 
190 void ana() {
191  gStyle->SetOptFit();
192 
193  drawRelAcc();
194  //drawAccPhi();
195 }
TH1D * getEffHist(const char *hname, const TH1D *h1, const TH1D *h2)
Definition: ana.C:24
double binom_error(const double a, const double b)
Definition: ana.C:16
void drawAccPhi()
Definition: ana.C:94
void drawRelAcc()
Definition: ana.C:53
void ana()
Definition: ana.C:291
double ratio_error(const double a, const double b, const double ea, const double eb)
Definition: ana.C:3
TCanvas * c1
Definition: Fun4SimTree.C:5