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 = 2;
44  char* inputs [] = {
45  "without_sheilding.root",
46  "sheilding.root"
47  };
48 
49  float gap_size[] = {0, 1, 2, 5, 10};
50  float gap_size_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
51 }
52 
53 void drawRelAcc() {
54 
55  float mean[] = {0, 0, 0, 0, 0, 0, 0, 0};
56  float mean_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
57  float mean0 = 1;
58  float mean_error0 = 0;
59  for (int i=0; i<nfiles; ++i) {
60  TFile *f = TFile::Open(inputs[i],"read");
61  TH1D *h = new TH1D("h","h",3,0,3);
62  //T->Project("h","gnhodo>=8"); // single trk.
63  T->Project("h","Sum$(gnhodo>=8)>=2"); // two trk.
64  //T->Project("h","Sum$(ntruhits>0)>=2"); //two reco. trk.
65  mean[i] = h->GetMean();
66  mean_error[i] = h->GetMeanError();
67  if(i==0) {
68  mean0 = mean[i];
69  // mean0 = 0.04041;
70  //mean0 = 0.1524;
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(";Shielding; 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(";Shielding; 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 
192  TCanvas *c0 = new TCanvas("c0","c0"); c0->SetGrid();
193  TCanvas *c1 = new TCanvas("c1","c1"); c1->SetGrid();
194  TCanvas *c2 = new TCanvas("c2","c2"); c2->SetGrid();
195  TCanvas *c3 = new TCanvas("c3","c3"); c3->SetGrid();
196 
197  float mod[] = {0, 0, 0, 0, 0, 0, 0, 0};
198  float mod_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
199  TH1D* hrelrat0;
200 
201  for (int i=0; i<nfiles; ++i) {
202  TFile *f = TFile::Open(inputs[i],"read");
203  float xbins[] = {20, 30, 50, 70, 100};
204  TH1D *hnum = new TH1D("hnum","hnum",4, xbins);
205  TH1D *hden = new TH1D("hden","hden",4, xbins);
206 
207  //T->Project("hnum","dimu_gphi","dimu_nrec>=2");
208  T->Project("hnum","gpz","gnhodo>=8");
209  T->Project("hden","gpz");
210 
211  TH1D* hrat = getEffHist("hrat", hnum, hden);
212  TH1D* hrelrat = (TH1D*) hrat->Clone("hrelrat");
213 
214  hnum->SetMarkerStyle(20);
215  hden->SetMarkerStyle(20);
216  hrat->SetMarkerStyle(20);
217  hrelrat->SetMarkerStyle(20);
218 
219  int color = kBlack;
220 
221  if(i==0) {
222 
223  color = kBlack;
224 
225  c0->cd();
226  c0->SetLogy();
227  hnum->SetTitle("nDimu-trig. vs. pz; pz [GeV/c]; nDimu-trig.");
228  hnum->SetMarkerColor(color);
229  hnum->SetLineColor(color);
230  hnum->SetMinimum(900);
231  hnum->Draw("e");
232  hnum->SetStats(0);
233 
234  c1->cd();
235  c1->SetLogy();
236  hden->SetTitle("nDimu-gen. vs. pz; pz [GeV/c]; nDimu-gen.");
237  hden->SetMarkerColor(color);
238  hden->SetLineColor(color);
239  hden->SetMinimum(900);
240  hden->Draw("e");
241  hden->SetStats(0);
242 
243  c2->cd();
244  hrat->SetTitle("Acc. vs. pz; pz [GeV/c]; Acc.");
245  hrat->SetMarkerColor(color);
246  hrat->SetLineColor(color);
247  hrat->SetMinimum(0.);
248  hrat->SetMaximum(1.1);
249  hrat->Draw("e");
250  hrat->SetStats(0);
251 
252  hrelrat0 = (TH1D*) hrelrat->Clone("hrelrat0");
253  }
254  else {
255  color = i+1;
256 
257  c0->cd();
258  hnum->SetMarkerColor(color);
259  hnum->SetLineColor(color);
260  hnum->Draw("esame");
261 
262  c1->cd();
263  hden->SetMarkerColor(color);
264  hden->SetLineColor(color);
265  hden->Draw("esame");
266 
267  c2->cd();
268  hrat->SetMarkerColor(color);
269  hrat->SetLineColor(color);
270  hrat->Draw("esame");
271 
272  c3->cd();
273  for(int ibin==1;ibin<=hrelrat->GetNbinsX();++ibin ){
274  hrelrat->SetBinContent(ibin,
275  hrelrat->GetBinContent(ibin)/hrelrat0->GetBinContent(ibin));
276  hrelrat->SetBinError(ibin,
277  hrelrat->GetBinError(ibin)/hrelrat0->GetBinContent(ibin));
278  }
279  hrelrat->SetTitle("Rel. Acc. vs. pz; pz [GeV/c]; Rel. Acc.");
280  hrelrat->SetMarkerColor(color);
281  hrelrat->SetLineColor(color);
282  hrelrat->SetStats(0);
283  if(i==1)
284  hrelrat->Draw("e");
285  else
286  hrelrat->Draw("esame");
287  }
288  }
289 }
290 
291 void ana() {
292  gStyle->SetOptFit();
293 
294  //drawRelAcc();
295  //drawAccPhi();
296  drawSnglAccPz();
297 }
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 drawSnglAccPz()
Definition: ana.C:191
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