Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
loop_ana.C
Go to the documentation of this file.
1 #include <TStyle.h>
2 #include <TFile.h>
3 #include <TTree.h>
4 #include <TCanvas.h>
5 #include <TH1D.h>
6 #include <TLorentzVector.h>
7 
8 #include <iostream>
9 
10 using namespace std;
11 
12 namespace {
13  int nfiles = 1;
14  const char* inputs [] = {
15  "trk_eval.root"
16  };
17 
18  float gap_size[] = {0, 1, 2, 5, 10};
19  float gap_size_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
20 }
21 
22 double binom_error(
23  const double a,
24  const double b
25  ){
26  double r=a/b;
27  return sqrt(r*(1-r)/b);
28 }
29 
30 TH1D * getEffHist(
31  const char* hname,
32  const TH1D* h1,
33  const TH1D* h2
34  ) {
35  TH1D *h = (TH1D*)h1->Clone(hname);
36  int nbin = h->GetNbinsX();
37  for(int ibin=1; ibin<=nbin; ++ibin) {
38  double a = h1->GetBinContent(ibin);
39  double b = h2->GetBinContent(ibin);
40 
41  if(b <= 0) {
42  h->SetBinContent(ibin, 0);
43  h->SetBinError(ibin, 0);
44  continue;
45  }
46 
47  double r = a/b;
48  double e = binom_error(a, b);
49  h->SetBinContent(ibin, r);
50  h->SetBinError(ibin, e);
51  }
52 
53  return h;
54 }
55 
56 void drawAccMass() {
57  TCanvas *c0 = new TCanvas("c0","c0"); c0->SetGrid();
58  TCanvas *c1 = new TCanvas("c1","c1"); c1->SetGrid();
59  TCanvas *c2 = new TCanvas("c2","c2"); c2->SetGrid();
60  TCanvas *c3 = new TCanvas("c3","c3"); c3->SetGrid();
61 
62  float mod[] = {0, 0, 0, 0, 0, 0, 0, 0};
63  float mod_error[] = {0, 0, 0, 0, 0, 0, 0, 0};
64  TH1D* hrelrat0 = NULL;
65 
66  for (int i=0; i<nfiles; ++i) {
67  float xbins[] = {4, 5, 7, 10, 20};
68  TH1D *hnum = new TH1D("hnum","hnum",4, xbins);
69  TH1D *hden = new TH1D("hden","hden",4, xbins);
70 
71  //
72  // Loop a TTree in a file
73  //
74 
75  TFile *f = TFile::Open(inputs[i],"read");
76  TTree *T = (TTree*) f->Get("T");
77 
78 #define MAX_PARTICLES 100
79  int gnhodo[MAX_PARTICLES];
80  float gpx[MAX_PARTICLES], gpy[MAX_PARTICLES], gpz[MAX_PARTICLES];
81  int n_particles;
82 
83  T->SetBranchAddress("gnhodo", &gnhodo);
84  T->SetBranchAddress("gpx", &gpx);
85  T->SetBranchAddress("gpy", &gpy);
86  T->SetBranchAddress("gpz", &gpz);
87  T->SetBranchAddress("n_particles", &n_particles);
88 
89  float mu_mass = .105658;
90  for(int ientry=0; ientry<T->GetEntries(); ++ientry) {
91  T->GetEntry(ientry);
92 
93  if(n_particles!=2) { cout << "n_particles!=2 @ " << ientry << endl; continue;}
94 
95  TLorentzVector mu0, mu1;
96  mu0.SetXYZM(gpx[0], gpy[0], gpz[0], mu_mass);
97  mu1.SetXYZM(gpx[1], gpy[1], gpz[1], mu_mass);
98 
99  TLorentzVector dimu = mu0+mu1;
100  float dimu_gmass = dimu.M();
101 
102  hden->Fill(dimu_gmass);
103 
104  if(gnhodo[0]>=8 && gnhodo[1]>=8)
105  hnum->Fill(dimu_gmass);
106  }
107 
108  // End of loop
109 
110  TH1D* hrat = getEffHist("hrat", hnum, hden);
111  TH1D* hrelrat = (TH1D*) hrat->Clone("hrelrat");
112 
113  hnum->SetMarkerStyle(20);
114  hden->SetMarkerStyle(20);
115  hrat->SetMarkerStyle(20);
116  hrelrat->SetMarkerStyle(20);
117 
118  int color = kBlack;
119 
120  if(i==0) {
121 
122  color = kBlack;
123 
124  c0->cd();
125  c0->SetLogy();
126  hnum->SetTitle("nDimu-trig. vs. M_{#mu#mu}; M_{#mu#mu} [GeV/c^{2}]; nDimu-trig.");
127  hnum->SetMarkerColor(color);
128  hnum->SetLineColor(color);
129  hnum->SetMinimum(1);
130  hnum->Draw("e");
131  hnum->SetStats(0);
132 
133  c1->cd();
134  c1->SetLogy();
135  hden->SetTitle("nDimu-gen. vs. M_{#mu#mu}; M_{#mu#mu} [GeV/c^{2}]; nDimu-gen.");
136  hden->SetMarkerColor(color);
137  hden->SetLineColor(color);
138  hden->SetMinimum(1);
139  hden->Draw("e");
140  hden->SetStats(0);
141 
142  c2->cd();
143  hrat->SetTitle("Acc. vs. M_{#mu#mu}; M_{#mu#mu} [GeV/c^{2}]; Acc.");
144  hrat->SetMarkerColor(color);
145  hrat->SetLineColor(color);
146  hrat->SetMinimum(0.);
147  hrat->SetMaximum(1.1);
148  hrat->Draw("e");
149  hrat->SetStats(0);
150 
151  hrelrat0 = (TH1D*) hrelrat->Clone("hrelrat0");
152  }
153  else {
154  color = i+1;
155 
156  c0->cd();
157  hnum->SetMarkerColor(color);
158  hnum->SetLineColor(color);
159  hnum->Draw("esame");
160 
161  c1->cd();
162  hden->SetMarkerColor(color);
163  hden->SetLineColor(color);
164  hden->Draw("esame");
165 
166  c2->cd();
167  hrat->SetMarkerColor(color);
168  hrat->SetLineColor(color);
169  hrat->Draw("esame");
170 
171  c3->cd();
172  for(int ibin=1;ibin<=hrelrat->GetNbinsX();++ibin ){
173  double relrat0_val = hrelrat0->GetBinContent(ibin);
174  if(relrat0_val<=0) {
175  hrelrat->SetBinContent(ibin,0);
176  hrelrat->SetBinError(ibin,0);
177  continue;
178  }
179  hrelrat->SetBinContent(ibin,
180  hrelrat->GetBinContent(ibin)/relrat0_val);
181  hrelrat->SetBinError(ibin,
182  hrelrat->GetBinError(ibin)/relrat0_val);
183  }
184  hrelrat->SetTitle("Rel. Acc. vs. M_{#mu#mu}; M_{#mu#mu} [GeV/c^{2}]; Rel. Acc.");
185  hrelrat->SetMarkerColor(color);
186  hrelrat->SetLineColor(color);
187  hrelrat->SetStats(0);
188  if(i==1)
189  hrelrat->Draw("e");
190  else
191  hrelrat->Draw("esame");
192  }
193  }
194 }
195 
196 void loop_ana() {
197  gStyle->SetOptFit();
198 
199  drawAccMass();
200 }
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
#define MAX_PARTICLES
void loop_ana()
Definition: loop_ana.C:196
#define NULL
Definition: Pdb.h:9
void drawAccMass()
Definition: loop_ana.C:56
TCanvas * c1
Definition: Fun4SimTree.C:5