Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extractShowerCalibFactor.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file extractShowerCalibFactor.C
1 #include <string>
2 #include "TString.h"
3 #include "TFile.h"
4 #include "TH2F.h"
5 #include "TH1F.h"
6 #include "TCanvas.h"
7 #include "TLegend.h"
8 #include "TF1.h"
9 #include <iostream>
10 #include <fstream>
11 
12 void extractShowerCalibFactor() // use 8 GeV & run 422 for shower calbrtion
13 {
14  string inputfile = "/sphenix/user/xusun/TestBeam/ShowerCalibAna/Proto4ShowerInfoRAW_0422.root";
15  TFile *File_InPut = TFile::Open(inputfile.c_str());
16  TH2F *h_mAsymmEnergy_pion_levl = (TH2F*)File_InPut->Get("h_mAsymmEnergy_pion_leveling");
17  TH1F *h_mEnergy_pion_levl = (TH1F*)h_mAsymmEnergy_pion_levl->ProjectionY()->Clone("h_mEnergy_pion_levl");
18 
19  TCanvas *c_shower = new TCanvas("c_shower","c_shower",1600,800);
20  c_shower->Divide(2,1);
21  for(int i_pad = 0; i_pad < 2; ++i_pad)
22  {
23  c_shower->cd(i_pad+1);
24  c_shower->cd(i_pad+1)->SetLeftMargin(0.15);
25  c_shower->cd(i_pad+1)->SetBottomMargin(0.15);
26  c_shower->cd(i_pad+1)->SetTicks(1,1);
27  c_shower->cd(i_pad+1)->SetGrid(0,0);
28  }
29 
30  string energy_cut = "E_{in} > 1 MeV & E_{out} > 1 MeV && E > MIP+3#sigma";
31 
32  c_shower->cd(1);
33  h_mAsymmEnergy_pion_levl->SetStats(0);
34  h_mAsymmEnergy_pion_levl->SetTitle(energy_cut.c_str());
35  h_mAsymmEnergy_pion_levl->GetYaxis()->SetTitle("Energy (GeV)");
36  h_mAsymmEnergy_pion_levl->GetYaxis()->CenterTitle();
37  h_mAsymmEnergy_pion_levl->GetYaxis()->SetNdivisions(505);
38  h_mAsymmEnergy_pion_levl->GetXaxis()->SetTitle("E_{Asymm}");
39  h_mAsymmEnergy_pion_levl->GetXaxis()->CenterTitle();
40  h_mAsymmEnergy_pion_levl->Draw("colz");
41 
42  TLegend *leg = new TLegend(0.35,0.7,0.75,0.85);
43  leg->SetBorderSize(0);
44  leg->SetFillColor(10);
45  leg->AddEntry(h_mAsymmEnergy_pion_levl,"8 GeV","h");
46  leg->Draw();
47 
48  c_shower->cd(2);
49  h_mEnergy_pion_levl->SetStats(0);
50  h_mEnergy_pion_levl->SetTitle("8 GeV & #pi^{-}");
51  h_mEnergy_pion_levl->GetXaxis()->SetTitle("Energy (GeV)");
52  h_mEnergy_pion_levl->GetXaxis()->CenterTitle();
53  h_mEnergy_pion_levl->GetXaxis()->SetNdivisions(505);
54  h_mEnergy_pion_levl->Draw("hE");
55 
56  TF1 *f_gaus = new TF1("f_gaus","gaus",0,100);
57  f_gaus->SetParameter(0,1.0);
58  f_gaus->SetParameter(1,h_mEnergy_pion_levl->GetMean());
59  f_gaus->SetParameter(2,1.0);
60  f_gaus->SetRange(1.0,7.0);
61  h_mEnergy_pion_levl->Fit(f_gaus,"NR");
62 
63  float norm = f_gaus->GetParameter(0);
64  float mean = f_gaus->GetParameter(1); // extract calibrated energy
65  float sigma = f_gaus->GetParameter(2); // extract calibrated energy
66  f_gaus->SetParameter(0,norm);
67  f_gaus->SetParameter(1,mean);
68  f_gaus->SetParameter(2,sigma);
69  f_gaus->SetRange(mean-3.0*sigma,mean+3.0*sigma);
70  // f_gaus->SetRange(1.5,7.0);
71  h_mEnergy_pion_levl->Fit(f_gaus,"MNR");
72  float energy_twrcalib = f_gaus->GetParameter(1);
73 
74  f_gaus->SetLineColor(2);
75  f_gaus->SetLineStyle(2);
76  f_gaus->SetLineWidth(2);
77  f_gaus->Draw("l same");
78 
79  const float showercalib = 8.0/energy_twrcalib;
80  cout << "showercalib = " << showercalib << endl;
81 
82  ofstream File_OutPut("showercalib.txt");
83  File_OutPut << "8 GeV: showercalib = " << showercalib << endl;
84  File_OutPut.close();
85 }