Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:15:47

0001 #include "TString.h"
0002 #include "TFile.h"
0003 #include "TH1F.h"
0004 #include "TH2F.h"
0005 #include "TF1.h"
0006 #include "TLegend.h"
0007 #include "TCanvas.h"
0008 #include <iostream>
0009 #include <fstream>
0010 
0011 void calSampleFrac()
0012 {
0013   TFile *File_InPut_HCALIN = TFile::Open("/sphenix/user/xusun/software/data/beam/SampleFrac/Proto4SampleFrac_HCALIN.root");
0014   TH1F *h_sf_in = (TH1F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_SF");
0015   TH2F *h_mCal_in = (TH2F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_XY_cal");
0016   TH2F *h_mAbs_in = (TH2F*)File_InPut_HCALIN->Get("h_QAG4Sim_HCALIN_G4Hit_XY_abs");
0017 
0018   TFile *File_InPut_HCALOUT = TFile::Open("/sphenix/user/xusun/software/data/beam/SampleFrac/Proto4SampleFrac_HCALOUT.root");
0019   TH1F *h_sf_out = (TH1F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_SF");
0020   TH2F *h_mCal_out = (TH2F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_XY_cal");
0021   TH2F *h_mAbs_out = (TH2F*)File_InPut_HCALOUT->Get("h_QAG4Sim_HCALOUT_G4Hit_XY_abs");
0022 
0023   TH1F *h_play = new TH1F("h_play","h_play",500,0,500);
0024   for(int i_bin = 0; i_bin < 500; ++i_bin)
0025   {
0026     h_play->SetBinContent(i_bin+1,-10000.0);
0027     h_play->SetBinError(i_bin+1,1.0);
0028   }
0029   // h_play->SetTitle("G4Hit Display");
0030   h_play->SetStats(0);
0031   h_play->GetYaxis()->SetRangeUser(-100,100);
0032   h_play->GetXaxis()->SetRangeUser(50,350);
0033 
0034   TCanvas *c_cal_in = new TCanvas("c_cal","c_cal",10,10,1000,1000);
0035   c_cal->Divide(2,2);
0036   for(int i_pad = 0; i_pad < 4; ++i_pad)
0037   {
0038     c_cal->cd(i_pad+1)->SetLeftMargin(0.15);
0039     c_cal->cd(i_pad+1)->SetBottomMargin(0.15);
0040     c_cal->cd(i_pad+1)->SetGrid(0,0);
0041     c_cal->cd(i_pad+1)->SetTicks(1,1);
0042   }
0043 
0044   c_cal->cd(1);
0045   h_play->SetTitle("HCALIN Cal G4Hit Display");
0046   h_play->DrawCopy("pE");
0047   h_mCal_in->Draw("colz same");
0048 
0049   c_cal->cd(2);
0050   h_play->SetTitle("HCALOUT Cal G4Hit Display");
0051   h_play->DrawCopy("pE");
0052   h_mCal_out->Draw("colz same");
0053 
0054   c_cal->cd(3);
0055   h_play->SetTitle("HCALIN Abs G4Hit Display");
0056   h_play->DrawCopy("pE");
0057   h_mAbs_in->Draw("colz same");
0058 
0059   c_cal->cd(4);
0060   h_play->SetTitle("HCALOUT Abs G4Hit Display");
0061   h_play->DrawCopy("pE");
0062   h_mAbs_out->Draw("colz same");
0063 
0064   c_cal->SaveAs("./figures/sPHENIX_CollMeeting/c_G4HitDisplay.eps");
0065 
0066   float nSigma = 1.5;
0067 
0068   TCanvas *c_play = new TCanvas("c_play","c_play",10,10,1600,800);
0069   c_play->Divide(2,1);
0070   for(int i_pad = 0; i_pad < 2; ++i_pad)
0071   {
0072     c_play->cd(i_pad+1)->SetLeftMargin(0.15);
0073     c_play->cd(i_pad+1)->SetBottomMargin(0.15);
0074     c_play->cd(i_pad+1)->SetGrid(0,0);
0075     c_play->cd(i_pad+1)->SetTicks(1,1);
0076   }
0077 
0078   c_play->cd(1);
0079   h_sf_in->GetXaxis()->SetRangeUser(0.0,0.3);
0080   h_sf_in->Draw("hE");
0081   TF1 *f_sf_in = new TF1("f_sf_in","gaus",0.0,0.3);
0082   f_sf_in->SetParameter(0,100);
0083   f_sf_in->SetParameter(1,0.1);
0084   f_sf_in->SetParameter(2,0.1);
0085   f_sf_in->SetRange(0.0,0.3);
0086   h_sf_in->Fit(f_sf_in,"NR");
0087 
0088   float mean_sf_in = f_sf_in->GetParameter(1);
0089   float sigma_sf_in = f_sf_in->GetParameter(2);
0090   f_sf_in->SetParameter(0,100);
0091   f_sf_in->SetParameter(1,mean_sf_in);
0092   f_sf_in->SetParameter(2,sigma_sf_in);
0093   f_sf_in->SetRange(mean_sf_in-nSigma*sigma_sf_in,mean_sf_in+nSigma*sigma_sf_in);
0094   h_sf_in->Fit(f_sf_in,"R");
0095   float sf_in = f_sf_in->GetParameter(1);
0096 
0097   std::string label_sf_in = Form("inner sf: %1.4f",sf_in);
0098   TLegend *leg_in = new TLegend(0.5,0.5,0.9,0.8);                                                     
0099   leg_in->SetFillColor(0);
0100   leg_in->SetBorderSize(0);
0101   leg_in->AddEntry(f_sf_in,label_sf_in.c_str(),"L");
0102   leg_in->Draw("same");
0103 
0104   c_play->cd(2);
0105   h_sf_out->GetXaxis()->SetRangeUser(0.0,0.3);
0106   h_sf_out->Draw("hE");
0107   TF1 *f_sf_out = new TF1("f_sf_out","gaus",0.0,0.3);
0108   f_sf_out->SetParameter(0,100);
0109   f_sf_out->SetParameter(1,0.03);
0110   f_sf_out->SetParameter(2,0.03);
0111   f_sf_out->SetRange(0.0,0.3);
0112   h_sf_out->Fit(f_sf_out,"NR");
0113   float mean_sf_out = f_sf_out->GetParameter(1);
0114   float sigma_sf_out = f_sf_out->GetParameter(2);
0115   f_sf_out->SetParameter(0,100);
0116   f_sf_out->SetParameter(1,mean_sf_out);
0117   f_sf_out->SetParameter(2,sigma_sf_out);
0118   f_sf_out->SetRange(mean_sf_out-nSigma*sigma_sf_out,mean_sf_out+nSigma*sigma_sf_out);
0119   h_sf_out->Fit(f_sf_out,"R");
0120   float sf_out = f_sf_out->GetParameter(1);
0121 
0122   std::string label_sf_out = Form("outer sf: %1.4f",sf_out);
0123   TLegend *leg_out = new TLegend(0.4,0.5,0.8,0.8);                                                     
0124   leg_out->SetFillColor(0);
0125   leg_out->SetBorderSize(0);
0126   leg_out->AddEntry(f_sf_out,label_sf_out.c_str(),"L");
0127   leg_out->Draw("same");
0128 
0129   c_play->SaveAs("./figures/sPHENIX_CollMeeting/c_sf.eps");
0130 
0131   ofstream File_OutPut("samplefrac.txt");
0132   File_OutPut << "inner sf = " << sf_in << endl;
0133   File_OutPut << "outer sf = " << sf_out << endl;
0134   File_OutPut.close();
0135 }
0136