Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReadHis2.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ReadHis2.C
1 #include <cmath>
2 #include <TFile.h>
3 #include <TString.h>
4 #include <TLine.h>
5 #include <TTree.h>
6 #include <TLatex.h>
7 #include <TGraphErrors.h>
8 #include <cassert>
9 #include "SaveCanvas.C"
10 #include "SetOKStyle.C"
11 #include <iostream>
12 #include <fstream>
13 #include "TROOT.h"
14 #include "TH1.h"
15 #include "TTree.h"
16 using namespace std;
17 
18 
19 
20 using std::cout;
21 using std::endl;
22 #endif
23 
24 
25 
26 
27 void ReadHis2()
28 {
29 
30 int Method = 0;
31 
32 
33  gSystem->Load("libg4eval.so");
34  gSystem->Load("libqa_modules.so");
35  gSystem->Load("libPrototype3.so");
36  gStyle->SetOptFit(0);
37  gStyle->SetOptStat(0);
38 
39  double step = 1;
40 
41 // Fitting: Method = 1; Mean: Method = 0//
42 
43 
44  int Ini = 3543;
45 int Final = 3579;
46 
47 
48 double Xmin = 170;
49 double Xmax = 310.0;
50 
51 double Ymin = 60;
52 double Ymax = 245.0;
53 
54 
55 /*
56 int Xmin = 170;
57 int Xmax = 340.0;
58 
59 int Ymin = 60;
60 int Ymax = 245.0;
61 */
62 
63 double Energy;
64 double Energy_err;
65 double Width;
66 double Width_err;
67 double Center;
68 double Center_err;
69 
70 double x;
71 double y;
72 double xhigh;
73 double yhigh;
74 int binxhigh;
75 int binyhigh;
76 
77 int binx;
78 int biny;
79 int XBins = (Xmax - Xmin)/step;
80 int YBins = (Ymax - Ymin)/step;
81 
82 //int XBins = 200;
83 //int YBins = 200;
84 char Name[512];
85 
86 int index = 0;
87 double average;
88 int indexmax = XBins * YBins;
89 char Filename[512];
90 char inputfile[512];
91 
92 //sprintf(inputfile,"Hisfiles130/HisAll.root");
93 
94 sprintf(inputfile,"His2.root");
95 //sprintf(inputfile,"His3.root");
96 
97 TFile *fin = new TFile(inputfile);
98 TH2D *EnPo= new TH2D("EnPo","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
99 
100 TF1 *f1 = new TF1("f1","gaus",6,11);
101 cout << "XBins = " << XBins << endl;
102 cout << "YBins = " << YBins << endl;
103 
104 char hisname[512];
105 
106 for(int i = 0; i < XBins; i++)
107 {
108 
109 x = Xmin + step*i;
110 
111 xhigh = Xmin + step*(i+1);
112 
113 
114 for(int j = 0; j < YBins; j++)
115 {
116 
117 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
118  y = Ymin + step*j;
119 yhigh = Ymin + step*(j+1);
120 
121 //etTitle("Total Energy vs Position by Fitting");
122 
123 
124 binx = Energyhis->GetXaxis()->FindBin(x+0.0001);
125 biny = Energyhis->GetYaxis()->FindBin(y+0.0001);
126 
127 //binxhigh = binx +1;
128 //binyhigh = biny +1;
129 
130 
131 
132 binxhigh = Energyhis->GetXaxis()->FindBin(xhigh-0.0001);
133 binyhigh = Energyhis->GetYaxis()->FindBin(yhigh-0.0001);
134 
135 
136 TH1D *h5= new TH1D("h5","",25,4,10);
137 
138 
139 
140 
141 h5 = Energyhis->ProjectionZ("h5",binx,binxhigh,biny,binyhigh);
142 
143 //return;
144 
145 
146 
147 //return;
148 //
149 
150 //Fitting Method //
151 if(Method ==1){
152 
153 //h5->Rebin(4);
154 
155 
156 average = h5->GetMean();
157 
158 if(average > 1)
159 {
160 
161  h5->Fit(f1,"R");
162 
163 c1->Update();
164 
165 
166 
167 Energy = f1->GetParameter(0);
168 Energy_err = f1->GetParError(0);
169 Center = f1->GetParameter(1);
170 Center_err = f1->GetParError(1);
171 Width = f1->GetParameter(2);
172 Width_err = f1->GetParError(2);
173 
174 
175 // Center = h5->GetMean();
176 
177 // cout << "x = " << x << endl;
178 
179 //cout << "y = " << y << endl;
180 
181 if(Center > 11 || Center < 4){
182 
183  cout << "Old Center = " << Center << endl;
184 
185 
186 Center = h5->GetMean();
187 
188 cout << "New Center = " << Center << endl;
189 }
190 
191 
192 
193 if(5.5 < Center < 6.5){
194 h5->Draw();
195 
196  h5->Fit(f1,"R");
197 
198 sprintf(Name,"EMCAL -10 Degree Energy Distribution in x = %d mm and y = %d mm ",x,y)
199 h5->GetXaxis()->SetTitle("Energy (GeV)");
200 h5->GetYaxis()->SetTitle("Counts");
201 h5->SetTitle(Name);
202 c1->Update();
203 
204 
205 sprintf(hisname,"pngfiles/Plot%d-%d.png",x,y);
206 
207  c1->SaveAs(hisname);
208 }
209 
210 }
211 
212 
213 if(average < 1) Center = 0;
214 
215 
216 }
217 
218 
219 
220 //Direct Mean Method//
221 
222 if(Method == 0) Center = h5->GetMean();
223 
224 
225 cout << "Mean = " << Center << endl;
226 
227 EnPo->SetBinContent(binx,biny,Center);
228 
229 
230 index = index + 1;
231 
232 }
233 
234 }
235 
236 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
237 
238 c22->cd();
239 
240 EnPo->Draw();
241 
242  c22->Update();
243 
244  c22->SaveAs("EnPo.png");
245 
246 
247 //sprintf(Filename,"EnergyPosition.root");
248 
249 sprintf(Filename,"EnergyPosition2.root");
250 //sprintf(Filename,"EnergyPosition3.root");
251 
252  TFile *fout = new TFile(Filename,"RECREATE");
253 EnPo->Write();
254 
255 
256 }