Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
calSampleFrac.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file calSampleFrac.C
1 #include "TString.h"
2 #include "TFile.h"
3 #include "TH1F.h"
4 #include "TH2F.h"
5 #include "TF1.h"
6 #include "TLegend.h"
7 #include "TCanvas.h"
8 #include <iostream>
9 #include <fstream>
10 
12 {
13  TFile *File_InPut_HCALIN = TFile::Open("/sphenix/user/xusun/software/data/beam/SampleFrac/Proto4SampleFrac_HCALIN.root");
14  TH1F *h_sf_in = (TH1F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_SF");
15  TH2F *h_mCal_in = (TH2F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_XY_cal");
16  TH2F *h_mAbs_in = (TH2F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_XY_abs");
17 
18  TFile *File_InPut_HCALOUT = TFile::Open("/sphenix/user/xusun/software/data/beam/SampleFrac/Proto4SampleFrac_HCALOUT.root");
19  TH1F *h_sf_out = (TH1F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_SF");
20  TH2F *h_mCal_out = (TH2F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_XY_cal");
21  TH2F *h_mAbs_out = (TH2F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_XY_abs");
22 
23  TH1F *h_play = new TH1F("h_play","h_play",500,0,500);
24  for(int i_bin = 0; i_bin < 500; ++i_bin)
25  {
26  h_play->SetBinContent(i_bin+1,-10000.0);
27  h_play->SetBinError(i_bin+1,1.0);
28  }
29  // h_play->SetTitle("G4Hit Display");
30  h_play->SetStats(0);
31  h_play->GetYaxis()->SetRangeUser(-100,100);
32  h_play->GetXaxis()->SetRangeUser(50,350);
33 
34  TCanvas *c_cal_in = new TCanvas("c_cal","c_cal",10,10,1000,1000);
35  c_cal->Divide(2,2);
36  for(int i_pad = 0; i_pad < 4; ++i_pad)
37  {
38  c_cal->cd(i_pad+1)->SetLeftMargin(0.15);
39  c_cal->cd(i_pad+1)->SetBottomMargin(0.15);
40  c_cal->cd(i_pad+1)->SetGrid(0,0);
41  c_cal->cd(i_pad+1)->SetTicks(1,1);
42  }
43 
44  c_cal->cd(1);
45  h_play->SetTitle("HCALIN Cal G4Hit Display");
46  h_play->DrawCopy("pE");
47  h_mCal_in->Draw("colz same");
48 
49  c_cal->cd(2);
50  h_play->SetTitle("HCALOUT Cal G4Hit Display");
51  h_play->DrawCopy("pE");
52  h_mCal_out->Draw("colz same");
53 
54  c_cal->cd(3);
55  h_play->SetTitle("HCALIN Abs G4Hit Display");
56  h_play->DrawCopy("pE");
57  h_mAbs_in->Draw("colz same");
58 
59  c_cal->cd(4);
60  h_play->SetTitle("HCALOUT Abs G4Hit Display");
61  h_play->DrawCopy("pE");
62  h_mAbs_out->Draw("colz same");
63 
64  c_cal->SaveAs("./figures/sPHENIX_CollMeeting/c_G4HitDisplay.eps");
65 
66  float nSigma = 1.5;
67 
68  TCanvas *c_play = new TCanvas("c_play","c_play",10,10,1600,800);
69  c_play->Divide(2,1);
70  for(int i_pad = 0; i_pad < 2; ++i_pad)
71  {
72  c_play->cd(i_pad+1)->SetLeftMargin(0.15);
73  c_play->cd(i_pad+1)->SetBottomMargin(0.15);
74  c_play->cd(i_pad+1)->SetGrid(0,0);
75  c_play->cd(i_pad+1)->SetTicks(1,1);
76  }
77 
78  c_play->cd(1);
79  h_sf_in->GetXaxis()->SetRangeUser(0.0,0.3);
80  h_sf_in->Draw("hE");
81  TF1 *f_sf_in = new TF1("f_sf_in","gaus",0.0,0.3);
82  f_sf_in->SetParameter(0,100);
83  f_sf_in->SetParameter(1,0.1);
84  f_sf_in->SetParameter(2,0.1);
85  f_sf_in->SetRange(0.0,0.3);
86  h_sf_in->Fit(f_sf_in,"NR");
87 
88  float mean_sf_in = f_sf_in->GetParameter(1);
89  float sigma_sf_in = f_sf_in->GetParameter(2);
90  f_sf_in->SetParameter(0,100);
91  f_sf_in->SetParameter(1,mean_sf_in);
92  f_sf_in->SetParameter(2,sigma_sf_in);
93  f_sf_in->SetRange(mean_sf_in-nSigma*sigma_sf_in,mean_sf_in+nSigma*sigma_sf_in);
94  h_sf_in->Fit(f_sf_in,"R");
95  float sf_in = f_sf_in->GetParameter(1);
96 
97  std::string label_sf_in = Form("inner sf: %1.4f",sf_in);
98  TLegend *leg_in = new TLegend(0.5,0.5,0.9,0.8);
99  leg_in->SetFillColor(0);
100  leg_in->SetBorderSize(0);
101  leg_in->AddEntry(f_sf_in,label_sf_in.c_str(),"L");
102  leg_in->Draw("same");
103 
104  c_play->cd(2);
105  h_sf_out->GetXaxis()->SetRangeUser(0.0,0.3);
106  h_sf_out->Draw("hE");
107  TF1 *f_sf_out = new TF1("f_sf_out","gaus",0.0,0.3);
108  f_sf_out->SetParameter(0,100);
109  f_sf_out->SetParameter(1,0.03);
110  f_sf_out->SetParameter(2,0.03);
111  f_sf_out->SetRange(0.0,0.3);
112  h_sf_out->Fit(f_sf_out,"NR");
113  float mean_sf_out = f_sf_out->GetParameter(1);
114  float sigma_sf_out = f_sf_out->GetParameter(2);
115  f_sf_out->SetParameter(0,100);
116  f_sf_out->SetParameter(1,mean_sf_out);
117  f_sf_out->SetParameter(2,sigma_sf_out);
118  f_sf_out->SetRange(mean_sf_out-nSigma*sigma_sf_out,mean_sf_out+nSigma*sigma_sf_out);
119  h_sf_out->Fit(f_sf_out,"R");
120  float sf_out = f_sf_out->GetParameter(1);
121 
122  std::string label_sf_out = Form("outer sf: %1.4f",sf_out);
123  TLegend *leg_out = new TLegend(0.4,0.5,0.8,0.8);
124  leg_out->SetFillColor(0);
125  leg_out->SetBorderSize(0);
126  leg_out->AddEntry(f_sf_out,label_sf_out.c_str(),"L");
127  leg_out->Draw("same");
128 
129  c_play->SaveAs("./figures/sPHENIX_CollMeeting/c_sf.eps");
130 
131  ofstream File_OutPut("samplefrac.txt");
132  File_OutPut << "inner sf = " << sf_in << endl;
133  File_OutPut << "outer sf = " << sf_out << endl;
134  File_OutPut.close();
135 }
136