Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:15

0001 // $Id: $
0002 
0003 /*!
0004  * \file DrawEcal_BlockCalibration.C
0005  * \brief 
0006  * \author Jin Huang <jhuang@bnl.gov>
0007  * \version $Revision:   $
0008  * \date $Date: $
0009  */
0010 
0011 #include <TFile.h>
0012 #include <TGraphAsymmErrors.h>
0013 #include <TGraphErrors.h>
0014 #include <TLatex.h>
0015 #include <TLine.h>
0016 #include <TString.h>
0017 #include <TTree.h>
0018 #include <cassert>
0019 #include <cmath>
0020 #include "SaveCanvas.C"
0021 #include "sPhenixStyle.C"
0022 
0023 using namespace std;
0024 
0025 void DrawEcal_BlockCalibration(
0026     const TString infile =
0027         "/phenix/u/jinhuang/links/sPHENIX_work/prod_analysis/EMCal_photon_calib/EMCalAna.root")
0028 {
0029   SetsPhenixStyle();
0030   TVirtualFitter::SetDefaultFitter("Minuit2");
0031 
0032   TFile* f =
0033       TFile::Open(infile);
0034 
0035   assert(f);
0036   assert(f->IsOpen());
0037 
0038   TH1* EMCalAna_h_CEMC_BLOCK_ETotal = f->Get("EMCalAna_h_CEMC_BLOCK_ETotal");
0039   assert(EMCalAna_h_CEMC_BLOCK_ETotal);
0040   TH1* EMCalAna_h_CEMC_BLOCK_EVis = f->Get("EMCalAna_h_CEMC_BLOCK_EVis");
0041   assert(EMCalAna_h_CEMC_BLOCK_EVis);
0042 
0043   TH1* hSamplingFraction =
0044       EMCalAna_h_CEMC_BLOCK_EVis->Clone("hSamplingFraction");
0045 
0046   hSamplingFraction->Divide(EMCalAna_h_CEMC_BLOCK_ETotal);
0047 
0048   hSamplingFraction->SetTitle("CEMC visible sampling fraction, 4 GeV photon, |z|<10 cm; EMCal block ID; Sampling Fraction");
0049   hSamplingFraction->GetXaxis()->SetRangeUser(-.5, 47.5);
0050   hSamplingFraction->GetYaxis()->SetRangeUser(0.01, 0.03);
0051   hSamplingFraction->SetFillColor(kBlue - 3);
0052   hSamplingFraction->SetFillStyle(1001);
0053 
0054   TCanvas* c1 = new TCanvas("DrawEcal_BlockCalibration", "DrawEcal_BlockCalibration", 900, 600);
0055   c1->Divide(1, 1);
0056   int idx = 1;
0057   TPad* p;
0058 
0059   p = (TPad*) c1->cd(idx++);
0060   c1->Update();
0061 
0062   hSamplingFraction->Draw();
0063 
0064   TLegend* leg = new TLegend(.0, .7, .95, .93);
0065   leg->SetFillStyle(0);
0066   leg->AddEntry("", "#it{#bf{sPHENIX}}  Geant4 Simulation", "");
0067   leg->AddEntry("", "CEMC visible sampling fraction for 4 GeV photon, |z|<10 cm", "");
0068   //  leg->AddEntry("", "CEMC visible sampling fraction", "");
0069   //  leg->AddEntry("", "4 GeV photon, |z|<10 cm", "");
0070   leg->AddEntry("", "2017 projective SPACAL design", "");
0071   leg->AddEntry("", "1-D projective blocks for #21-26, rest are 2-D projective blocks", "");
0072   leg->Draw();
0073 
0074   SaveCanvas(c1, infile + "_" + TString(c1->GetName()), kTRUE);
0075 
0076   //Save result
0077   gSystem->Load("libg4detectors.so");
0078 
0079   PHParameters* param = new PHParameters("CEMC");
0080 
0081   param->set_string_param("description",
0082                           Form(
0083                               "2017 projective SPACAL design, Calibration based on CEMC visible sampling fraction for 4 GeV photon, source file: %s",
0084                               infile.Data()));
0085 
0086   // additional scale for the calibration constant
0087   // negative pulse -> positive with -1
0088   //  param->set_double_param("calib_const_scale", 1 / 0.02);  // overall scale the calibration constant to near 1.0
0089   const double calib_const_scale = 0.02;  // overall scale the calibration constant to near 1.0
0090 
0091   // use channel by channel stuff
0092   param->set_int_param("use_chan_calibration", 1);
0093 
0094   for (int eta = 0; eta < 96; ++eta)
0095   {
0096     for (int phi = 0; phi < 256; ++phi)
0097     {
0098       const int block_eta_id = eta / 2;
0099 
0100       string calib_const_name(Form("calib_const_eta%d_phi%d", eta, phi));
0101       param->set_double_param(calib_const_name,
0102                               calib_const_scale / hSamplingFraction->GetBinContent(hSamplingFraction->GetXaxis()->FindBin(block_eta_id)));
0103     }
0104   }
0105 
0106   param->WriteToFile("xml", "/phenix/u/jinhuang/links/sPHENIX_work/prod_analysis/EMCal_photon_calib/");
0107 }