Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReadHis.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ReadHis.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 ReadHis()
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+1;
76 int YBins = (Ymax - Ymin)/step+1;
77 int index = 0;
78 
79 int indexmax = XBins * YBins;
80 char Filename[512];
81 char inputfile[512];
82 
83 sprintf(inputfile,"Hisfiles130/HisAll.root");
84 
85 //sprintf(inputfile,"His2.root");
86 
87 
88 TFile *fin = new TFile(inputfile);
89 TH2D *EnPo= new TH2D("EnPo","",XBins,Xmin,Xmax,YBins,Ymin,Ymax);
90 
91 
92 cout << "XBins = " << XBins << endl;
93 cout << "YBins = " << YBins << endl;
94 
95 char hisname[512];
96 
97 for(int i = 0; i < XBins; i++)
98 {
99 
100 x = Xmin + step*i;
101 
102 xhigh = Xmin + step*(i+1);
103 
104 
105 for(int j = 0; j < YBins; j++)
106 {
107 
108 // TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
109  y = Ymin + step*j;
110 yhigh = Ymin + step*(j+1);
111 
112 
113 binxhigh = Energyhis->GetZaxis()->FindBin(xhigh);
114 binyhigh = Energyhis->GetYaxis()->FindBin(yhigh);
115 
116 
117 
118 binx = Energyhis->GetZaxis()->FindBin(x);
119 biny = Energyhis->GetYaxis()->FindBin(y);
120 
121 //binxhigh = binx +1;
122 //binyhigh = biny +1;
123 
124 
125 TH1D *h5= new TH1D("h5","",50,6,10);
126 
127  Energyhis->ProjectionX("h5",biny,binyhigh,binx,binxhigh);
128 
129 // h5->GetXaxis()->SetRange(6,10);
130  //h5->Rebin(2);
131 
132  //return;
133 //
134 /*
135  h5->Fit("gaus");
136 
137 c1->Update();
138 sprintf(hisname,"pngfiles/Plot%d-%d.png",i,j);
139 
140  c1->SaveAs(hisname);
141 
142 
143 Energy = gaus->GetParameter(0);
144 Energy_err = gaus->GetParError(0);
145 Center = gaus->GetParameter(1);
146 Center_err = gaus->GetParError(1);
147 Width = gaus->GetParameter(2);
148 Width_err = gaus->GetParError(2);
149 */
150 
151  Center = h5->GetMean();
152 
153 cout << "Mean = " << Center << endl;
154 
155 EnPo->SetBinContent(binx,biny,Center);
156 
157 
158 index = index + 1;
159 
160 }
161 
162 }
163 
164 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
165 
166 c22->cd();
167 
168 EnPo->Draw();
169 
170  c22->Update();
171 
172  c22->SaveAs("EnPo.png");
173 
174 
175 sprintf(Filename,"EnergyPosition.root");
176 
177 //sprintf(Filename,"EnergyPosition2.root");
178  TFile *fout = new TFile(Filename,"RECREATE");
179 EnPo->Write();
180 
181 
182 }