Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FillEnergy.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FillEnergy.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 void FillEnergy()
26 {
27  gSystem->Load("libg4eval.so");
28  gSystem->Load("libqa_modules.so");
29  gSystem->Load("libPrototype3.so");
30  gStyle->SetOptFit(0);
31  gStyle->SetOptStat(0);
32 
33 double inteval = 1;
34 
35 double Xmin = 170;
36 double Xmax = 310.0;
37 
38 double Ymin = 60;
39 double Ymax = 245.0;
40 
41 int XBins =(Xmax - Xmin)/inteval;
42 int YBins = (Ymax - Ymin)/inteval;
43 
44 
45 
46 int Ini = 3543;
47 int Final = 3579;
48 
49  int step = 1;
50 
51 int num = (Final - Ini)/step;
52 
53 cout << "num = " << num << endl;
54 
55 const int N = 8;
56 
57 const int NTotal = N * N;
58 
59 double x;
60  double y;
61 char Filename[512];
62 /*
63 
64 double Horizontal[N];
65 double Vertical[N];
66 double Energy[N];
67 
68 */
69 char inputfile[512];
70 
71 int j;
72 
73 double xmax = 0;
74 double ymax = 0;
75 
76 double Energy;
77 double Energy_err;
78 double Width;
79 double Width_err;
80 double Center;
81 double Center_err;
82 
83 int index;
84 
85 
86 //
87 
88 for(int i =0; i < num; i ++)
89 {
90 index = 0;
91 
92  gStyle->SetOptFit(0);
93  gStyle->SetOptStat(0);
94 
95 TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,600);
96 c1->cd();
97 
98 
99 cout << " i = " << i << endl;
100 
101 
102 
103 j = i * step + Ini;
104 
105 cout << " j = " << j << endl;
106 
107 if(j != 3416 && j != 3418 && j != 3420 && j != 3421 && j != 3426)
108 {
109 
110 //sprintf(inputfile,"/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2017/Production_0128_WithHCalCalib/beam_0000%d-0000_DSTReader.root",j);
111 
112 sprintf(inputfile,"/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2017/Production_0130_WithEMCalCalib/beam_0000%d-0000_DSTReader.root",j);
113 
114 
115 cout << "Infile name = " << inputfile << endl;
116 
117 ifstream ifile(inputfile);
118 
119 
120 
121 if(ifile){
122 
123 TFile *fin = new TFile(inputfile);
124 
125 
126 
127 TTree *t = (TTree *)fin->Get("T");
128 
129  t->SetAlias("C2_Inner_e", "1*abs(TOWER_RAW_C2[2].energy)");
130  t->SetAlias("C2_Outer_e", "1*abs(TOWER_RAW_C2[3].energy)");
131 t->SetAlias("Average_column", "Sum$(TOWER_CALIB_CEMC.get_column() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
132  t->SetAlias("Average_HODO_HORIZONTAL", "Sum$(TOWER_CALIB_HODO_HORIZONTAL.towerid * (abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))/Sum$((abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))");
133  t->SetAlias("Valid_HODO_HORIZONTAL", "Sum$(abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) > 0");
134  t->SetAlias("No_Triger_VETO", "Sum$(abs(TOWER_RAW_TRIGGER_VETO.energy)>15)==0");
135  t->SetAlias("Valid_HODO_VERTICAL", "Sum$(abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) > 0");
136  t->SetAlias("C2_Sum_e", "C2_Inner_e + C2_Outer_e");
137  t->SetAlias("Average_HODO_VERTICAL","Sum$(TOWER_CALIB_HODO_VERTICAL.towerid * (abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))/Sum$((abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))");
138 //return;
139  t->SetAlias("Energy_Sum_CEMC", "1*Sum$(TOWER_CALIB_CEMC.get_energy())");
140 
141 //Cut on Events//
142 
143 // TCut event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO && C2_Sum_e > 200 && fmod(Entry$,10)==0";
144 TCut event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO && C2_Sum_e > 200";
145 
146  t->Draw(">>EventList", event_sel);
147 
148  TEventList * elist = gDirectory->GetObjectChecked("EventList", "TEventList");
149 
150 //cout << "Cut is " << event_sel.data() << endl;
151 
152  cout << elist->GetN() << " / " << T->GetEntriesFast() << " events selected" << endl;
153 
154  t->SetEventList(elist);
155 
156 
157 TH1D *h5= new TH1D("h5","",200, -1, 10);
158 
159 
160 /*
161 t->Draw("beam_2CH_mm >> h1");
162 t->Draw("beam_2CV_mm >> h2");
163 
164 
165 t->Draw("Average_column >> h5");
166 
167 t->Draw("Average_HODO_HORIZONTAL>>h3");
168 
169 t->Draw("Average_HODO_VERTICAL>>h4");
170 
171 
172 */
173 sprintf(Filename,"Hisfiles130/His%d.root",i);
174 
175 TFile *fout = new TFile(Filename,"RECREATE");
176 
177  t->SetAlias("XPos", "beam_2CH_mm - 5* int( Average_HODO_HORIZONTAL + 0.5)");
178  t->SetAlias("YPos", "beam_2CV_mm + 5* int(Average_HODO_VERTICAL + 0.5)");
179 
180 
181 
182 
183 //cout <<"Start the scan..."<<endl;
184 //t->Scan("XPos:YPos:Energy_Sum_CEMC");
185 TH3F *Energyhis = new TH3F("Energyhis","",200,0,20,YBins,Ymin,Ymax,XBins,Xmin,Xmax);
186 
187 // t->Draw("XPos:YPos:Energy_Sum_CEMC>>Energyhis(200,0,20,200,69.7,191.0,200,212,302.0)");
188 
189  t->Draw("XPos:YPos:Energy_Sum_CEMC>>Energyhis");
190 
191 
192 Energyhis->Write();
193 //fout->Print();
194 
195 /*
196 
197 new TCanvas();
198 t->Draw("XPos>>hXPos");
199 
200 new TCanvas();
201 t->Draw("YPos>>hYPos");
202 
203 new TCanvas();
204 t->Draw("Energy_Sum_CEMC>>hEnergy_CEMC");
205 
206  fout->Write();
207  fout->Print();
208 */
209 //t->Project("Energyhis","XPos:YPos:Energy_Sum_CEMC");
210 
211 //TF1 *f1 = new TF1("f1","[0]*TMath::Exp(-(x - [1] )*(x - [1] )/(2 * [2] * [2] ))",7,12);
212 
213 
214 //t->Draw("beam_2CV_mm >> h2");
215 
216 //t->Draw("TOWER_CALIB_CEMC.energy >> h3");
217 
218 //return;
219 //
220 //
221 /*
222 cout <<"n_eve = "<<n_eve<<", hist = "<<Energyhis->GetSum()<<endl;
223 gDirectory->Print();
224 
225 TCanvas *c22 = new TCanvas("c22", "c22",0,0,800,600);
226 
227 c22->cd();
228 
229 Energyhis->Draw();
230 
231  c22->Update();
232 
233  c22->SaveAs("Energy.png");
234 
235 
236 */
237 
238 
239 /*
240  Energyhis->Fit("gaus");
241 
242 c1->Update();
243 
244  c1->SaveAs("AVHis.png");
245 
246 
247 Energy = gaus->GetParameter(0);
248 Energy_err = gaus->GetParError(0);
249 Center = gaus->GetParameter(1);
250 Center_err = gaus->GetParError(1);
251 Width = gaus->GetParameter(2);
252 Width_err = gaus->GetParError(2);
253 
254 */
255 //cout << "Energy = " << Energy << endl;
256 /*
257 for(int j = 0; j < N; j++)
258 {
259 
260 for(int k = 0; k < N; k++)
261 {
262 
263 x = h1->GetMean()-0.5*j;
264 y = h2->GetMean()-0.5*k;
265 
266 
267 //E[i] = h3->GetMean();
268 
269 cout << "x = " << x << endl;
270 
271 cout << "y = " << y << endl;
272 
273 
274 Energyhis->Fill(x,y,Energy);
275 
276 index = index + 1;
277 
278 cout << "index = " << index << endl;
279 
280 }
281 
282 }
283 */
284 
285 
286 }
287 
288 if (!ifile) {
289 
290  i = i + 1;
291 
292 cout << "File " << i << "does not exist" << endl;
293 
294 }
295 
296 
297 }
298 
299 }
300 
301 /*
302 TCanvas *c11 = new TCanvas("c11", "c11",0,0,800,600);
303 c11->cd();
304  gStyle->SetEndErrorSize(0.01);
305  c11->SetFillColor(10);
306  c11->SetBorderMode(0);
307  c11->SetBorderSize(2);
308  c11->SetFrameFillColor(0);
309  c11->SetFrameBorderMode(0);
310 
311  c11->SetGridx();
312  c11->SetGridy();
313 
314  c11->SetLeftMargin(0.13);
315  c11->SetBottomMargin(0.13);
316  c11->SetTopMargin(0.02);
317  c11->SetRightMargin(0.06);
318 
319  double x1 = 0;
320  double x2 = xmax*1.2;
321  double y1 = 0;
322  double y2 = ymax*1.2;
323 
324  TH1D *d0 = new TH1D("d0","",100,x1,x2);
325  d0->SetMinimum(y1);
326  d0->SetMaximum(y2);
327  d0->GetXaxis()->SetNdivisions(208);
328  d0->GetXaxis()->SetTitle("x");
329  d0->GetXaxis()->SetTitleOffset(0.9);
330  d0->GetXaxis()->SetTitleSize(0.06);
331  d0->GetXaxis()->SetLabelOffset(0.01);
332  d0->GetXaxis()->SetLabelSize(0.045);
333  d0->GetXaxis()->SetLabelFont(42);
334  d0->GetXaxis()->SetTitleFont(42);
335  d0->GetYaxis()->SetNdivisions(205);
336  d0->GetYaxis()->SetTitle("Energy");
337  d0->GetYaxis()->SetTitleOffset(1.0);
338  d0->GetYaxis()->SetTitleSize(0.06);
339  d0->GetYaxis()->SetLabelOffset(0.005);
340  d0->GetYaxis()->SetLabelSize(0.045);
341  d0->GetYaxis()->SetLabelFont(42);
342  d0->GetYaxis()->SetTitleFont(42);
343  d0->SetLineWidth(2);
344  d0->Draw();
345 
346  TLine *l1 = new TLine(x1,y1,x2,y1);
347  l1->SetLineWidth(3);
348  l1->Draw("same");
349  TLine *l2 = new TLine(x1,y2,x2,y2);
350  l2->SetLineWidth(3);
351  l2->Draw("same");
352  TLine *l3 = new TLine(x1,y1,x1,y2);
353  l3->SetLineWidth(3);
354  l3->Draw("same");
355  TLine *l4 = new TLine(x2,y1,x2,y2);
356  l4->SetLineWidth(3);
357  l4->Draw("same");
358 
359 TGraph *gr = new TGraphErrors(N, x, y);
360 
361 
362 
363 
364  gr->SetMarkerSize(1.1);
365  gr->SetMarkerStyle(20);
366  gr->SetLineWidth(2);
367  gr->SetName("Energy vs x");
368 
369  gr->Draw("p");
370 
371  c11->Update();
372 
373  c11->SaveAs("AVCH.png");
374 */
375 
376 
377 
378 }