Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DrawEcal_BlockCalibration.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DrawEcal_BlockCalibration.C
1 // $Id: $
2 
11 #include <TFile.h>
12 #include <TGraphAsymmErrors.h>
13 #include <TGraphErrors.h>
14 #include <TLatex.h>
15 #include <TLine.h>
16 #include <TString.h>
17 #include <TTree.h>
18 #include <cassert>
19 #include <cmath>
20 #include "SaveCanvas.C"
21 #include "sPhenixStyle.C"
22 
23 using namespace std;
24 
26  const TString infile =
27  "/phenix/u/jinhuang/links/sPHENIX_work/prod_analysis/EMCal_photon_calib/EMCalAna.root")
28 {
30  TVirtualFitter::SetDefaultFitter("Minuit2");
31 
32  TFile* f =
33  TFile::Open(infile);
34 
35  assert(f);
36  assert(f->IsOpen());
37 
38  TH1* EMCalAna_h_CEMC_BLOCK_ETotal = f->Get("EMCalAna_h_CEMC_BLOCK_ETotal");
39  assert(EMCalAna_h_CEMC_BLOCK_ETotal);
40  TH1* EMCalAna_h_CEMC_BLOCK_EVis = f->Get("EMCalAna_h_CEMC_BLOCK_EVis");
41  assert(EMCalAna_h_CEMC_BLOCK_EVis);
42 
43  TH1* hSamplingFraction =
44  EMCalAna_h_CEMC_BLOCK_EVis->Clone("hSamplingFraction");
45 
46  hSamplingFraction->Divide(EMCalAna_h_CEMC_BLOCK_ETotal);
47 
48  hSamplingFraction->SetTitle("CEMC visible sampling fraction, 4 GeV photon, |z|<10 cm; EMCal block ID; Sampling Fraction");
49  hSamplingFraction->GetXaxis()->SetRangeUser(-.5, 47.5);
50  hSamplingFraction->GetYaxis()->SetRangeUser(0.01, 0.03);
51  hSamplingFraction->SetFillColor(kBlue - 3);
52  hSamplingFraction->SetFillStyle(1001);
53 
54  TCanvas* c1 = new TCanvas("DrawEcal_BlockCalibration", "DrawEcal_BlockCalibration", 900, 600);
55  c1->Divide(1, 1);
56  int idx = 1;
57  TPad* p;
58 
59  p = (TPad*) c1->cd(idx++);
60  c1->Update();
61 
62  hSamplingFraction->Draw();
63 
64  TLegend* leg = new TLegend(.0, .7, .95, .93);
65  leg->SetFillStyle(0);
66  leg->AddEntry("", "#it{#bf{sPHENIX}} Geant4 Simulation", "");
67  leg->AddEntry("", "CEMC visible sampling fraction for 4 GeV photon, |z|<10 cm", "");
68  // leg->AddEntry("", "CEMC visible sampling fraction", "");
69  // leg->AddEntry("", "4 GeV photon, |z|<10 cm", "");
70  leg->AddEntry("", "2017 projective SPACAL design", "");
71  leg->AddEntry("", "1-D projective blocks for #21-26, rest are 2-D projective blocks", "");
72  leg->Draw();
73 
74  SaveCanvas(c1, infile + "_" + TString(c1->GetName()), kTRUE);
75 
76  //Save result
77  gSystem->Load("libg4detectors.so");
78 
79  PHParameters* param = new PHParameters("CEMC");
80 
81  param->set_string_param("description",
82  Form(
83  "2017 projective SPACAL design, Calibration based on CEMC visible sampling fraction for 4 GeV photon, source file: %s",
84  infile.Data()));
85 
86  // additional scale for the calibration constant
87  // negative pulse -> positive with -1
88  // param->set_double_param("calib_const_scale", 1 / 0.02); // overall scale the calibration constant to near 1.0
89  const double calib_const_scale = 0.02; // overall scale the calibration constant to near 1.0
90 
91  // use channel by channel stuff
92  param->set_int_param("use_chan_calibration", 1);
93 
94  for (int eta = 0; eta < 96; ++eta)
95  {
96  for (int phi = 0; phi < 256; ++phi)
97  {
98  const int block_eta_id = eta / 2;
99 
100  string calib_const_name(Form("calib_const_eta%d_phi%d", eta, phi));
101  param->set_double_param(calib_const_name,
102  calib_const_scale / hSamplingFraction->GetBinContent(hSamplingFraction->GetXaxis()->FindBin(block_eta_id)));
103  }
104  }
105 
106  param->WriteToFile("xml", "/phenix/u/jinhuang/links/sPHENIX_work/prod_analysis/EMCal_photon_calib/");
107 }