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  gSystem->Load("libg4eval.so");
31  gSystem->Load("libqa_modules.so");
32  gSystem->Load("libPrototype3.so");
33  gStyle->SetOptFit(0);
34  gStyle->SetOptStat(0);
35 
36  double step = 1;
37 
38 int Ini = 3543;
39 int Final = 3579;
40 
41 
42 double Xmin = 170;
43 double Xmax = 310.0;
44 
45 double Ymin = 60;
46 double Ymax = 245.0;
47 
48 
49 /*
50 
51 double Xmin = 150;
52 double Xmax = 310.0;
53 
54 double Ymin = 20;
55 double Ymax = 200.0;
56 */
57 
58 
59 double Energy;
60 double Energy_err;
61 double Width;
62 double Width_err;
63 double Center;
64 double Center_err;
65 
66 double x;
67 double y;
68 double xhigh;
69 double yhigh;
70 int binxhigh;
71 int binyhigh;
72 
73 int binx;
74 int biny;
75 int XBins = (Xmax - Xmin)/step;
76 int YBins = (Ymax - Ymin)/step;
77 
78 //int XBins = 200;
79 //int YBins = 200;
80 
81 
82 int index = 0;
83 
84 int indexmax = XBins * YBins;
85 char Filename[512];
86 char inputfile[512];
87 
88 //sprintf(inputfile,"Hisfiles130/HisAll.root");
89 
90 sprintf(inputfile,"His2.root");
91 
92 TFile *fin = new TFile(inputfile);
93 TH2D *EnPo= new TH2D("EnPo","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
94 
95 
96 cout << "XBins = " << XBins << endl;
97 cout << "YBins = " << YBins << endl;
98 
99 char hisname[512];
100 
101 for(int i = 0; i < XBins; i++)
102 {
103 
104 x = Xmin + step*i;
105 
106 xhigh = Xmin + step*(i+1);
107 
108 
109 for(int j = 0; j < YBins; j++)
110 {
111 
112 // TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
113  y = Ymin + step*j;
114 yhigh = Ymin + step*(j+1);
115 
116 
117 
118 
119 binx = Energyhis->GetXaxis()->FindBin(x+0.0001);
120 biny = Energyhis->GetYaxis()->FindBin(y+0.0001);
121 
122 //binxhigh = binx +1;
123 //binyhigh = biny +1;
124 
125 
126 
127 binxhigh = Energyhis->GetXaxis()->FindBin(xhigh-0.0001);
128 binyhigh = Energyhis->GetYaxis()->FindBin(yhigh-0.0001);
129 
130 
131 TH1D *h5= new TH1D("h5","",50,6,10);
132 
133 
134 
135 
136  Energyhis->ProjectionZ("h5",binx,binxhigh,biny,binyhigh);
137 
138 // h5->GetXaxis()->SetRange(6,10);
139  //h5->Rebin(2);
140 
141  //return;
142 //
143 /*
144  h5->Fit("gaus");
145 
146 c1->Update();
147 sprintf(hisname,"pngfiles/Plot%d-%d.png",i,j);
148 
149  c1->SaveAs(hisname);
150 
151 
152 Energy = gaus->GetParameter(0);
153 Energy_err = gaus->GetParError(0);
154 Center = gaus->GetParameter(1);
155 Center_err = gaus->GetParError(1);
156 Width = gaus->GetParameter(2);
157 Width_err = gaus->GetParError(2);
158 */
159 
160  Center = h5->GetMean();
161 
162 // cout << "x = " << x << endl;
163 
164 //cout << "y = " << y << endl;
165 cout << "Mean = " << Center << endl;
166 
167 EnPo->SetBinContent(binx,biny,Center);
168 
169 
170 index = index + 1;
171 
172 }
173 
174 }
175 
176 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
177 
178 c22->cd();
179 
180 EnPo->Draw();
181 
182  c22->Update();
183 
184  c22->SaveAs("EnPo.png");
185 
186 
187 //sprintf(Filename,"EnergyPosition.root");
188 
189 sprintf(Filename,"EnergyPosition2.root");
190  TFile *fout = new TFile(Filename,"RECREATE");
191 EnPo->Write();
192 
193 
194 }