Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:19

0001 #! /usr/bin/env python
0002 from optparse import OptionParser
0003 import sys
0004 import os
0005 import datetime
0006 from array import *
0007 from ROOT import *
0008 import numpy
0009 import math
0010 import glob
0011 from plotUtil import GetHistogram
0012 
0013 TickSize = 0.03
0014 AxisTitleSize = 0.05
0015 AxisLabelSize = 0.04
0016 LeftMargin = 0.15
0017 RightMargin = 0.08
0018 TopMargin = 0.08
0019 BottomMargin = 0.13
0020 
0021 def Draw_2Dhist(hist, IsData, logz, norm1, rmargin, XaxisName, YaxisName, ZaxisName, drawopt, outname):
0022     c = TCanvas('c', 'c', 1000, 700)
0023     if logz:
0024         c.SetLogz()
0025     c.cd()
0026     if ZaxisName == '':
0027         gPad.SetRightMargin(rmargin)
0028     else:
0029         gPad.SetRightMargin(rmargin+0.03)
0030 
0031     gPad.SetTopMargin(TopMargin)
0032     gPad.SetLeftMargin(LeftMargin)
0033     gPad.SetBottomMargin(BottomMargin)
0034     if norm1:
0035         hist.Scale(1. / hist.Integral(-1, -1, -1, -1))
0036     hist.GetXaxis().SetTitle(XaxisName)
0037     hist.GetYaxis().SetTitle(YaxisName)
0038     hist.GetXaxis().SetTickSize(TickSize)
0039     hist.GetYaxis().SetTickSize(TickSize)
0040     hist.GetXaxis().SetTitleSize(AxisTitleSize)
0041     hist.GetYaxis().SetTitleSize(AxisTitleSize)
0042     hist.GetXaxis().SetLabelSize(AxisLabelSize)
0043     hist.GetYaxis().SetLabelSize(AxisLabelSize)
0044     if ZaxisName != '':
0045         hist.GetZaxis().SetTitle(ZaxisName)
0046         hist.GetZaxis().SetTitleSize(AxisTitleSize)
0047         hist.GetZaxis().SetTitleOffset(1.1)
0048         
0049     hist.GetXaxis().SetTitleOffset(1.1)
0050     hist.GetYaxis().SetTitleOffset(1.3)
0051     hist.GetZaxis().SetLabelSize(AxisLabelSize)
0052     hist.GetZaxis().SetRangeUser(hist.GetMinimum(0), hist.GetMaximum())
0053     hist.SetContour(1000)
0054     hist.Draw(drawopt)
0055 
0056     c.RedrawAxis()
0057     c.Draw()
0058     c.SaveAs(outname+'.pdf')
0059     c.SaveAs(outname+'.png')
0060     if(c):
0061         c.Close()
0062         gSystem.ProcessEvents()
0063         del c
0064         c = 0
0065 
0066 # gROOT.LoadMacro('./sPHENIXStyle/sPhenixStyle.C')
0067 # gROOT.ProcessLine('SetsPhenixStyle()')
0068 gROOT.SetBatch(True)
0069 
0070 if __name__ == '__main__':
0071     parser = OptionParser()
0072     parser.add_option("-f", "--histdir", dest="histdir", type="string", default='/sphenix/user/hjheng/TrackletAna/analysis_INTT/plot/hists/data_Run20869/Cluster', help="Input file name")
0073     parser.add_option("-d", "--plotdir", dest="plotdir", type="string", default='/sphenix/user/hjheng/TrackletAna/analysis_INTT/plot/RecoCluster/data_Run20869', help="Plot directory")
0074     parser.add_option("-s", "--isdata", dest="isdata", action="store_true", default=False, help="Is data")
0075     parser.add_option("-p", "--preliminary", dest="preliminary", action="store_true", default=False, help="Preliminary")
0076     (opt, args) = parser.parse_args()
0077     print('opt: {}'.format(opt))
0078 
0079     histdir = opt.histdir
0080     plotdir = opt.plotdir
0081     isdata = opt.isdata
0082     preliminary = opt.preliminary
0083     os.makedirs(plotdir, exist_ok=True)
0084 
0085     if os.path.isfile("{}/hists_merged.root".format(histdir)):
0086         os.system("rm {}/hists_merged.root".format(histdir))
0087         os.system("hadd {}/hists_merged.root {}/hists_*.root".format(histdir, histdir))
0088     else:
0089         os.system("hadd {}/hists_merged.root {}/hists_*.root".format(histdir, histdir))
0090 
0091     hM_hitmap_RowColumnFlatten_unwei = GetHistogram('{}/hists_merged.root'.format(histdir), 'hM_hitmap_RowColumnFlatten_unwei')
0092     hM_hitmap_RowColumnFlatten_weiADC = GetHistogram('{}/hists_merged.root'.format(histdir), 'hM_hitmap_RowColumnFlatten_weiADC')
0093     hM_hitmap_RowColumnFlatten_avgtrkrhitadc = GetHistogram('{}/hists_merged.root'.format(histdir), 'hM_hitmap_RowColumnFlatten_weiADC')
0094     
0095 
0096     # Draw_2Dhist(hist, IsData, logz, norm1, rmargin, XaxisName, YaxisName, drawopt, outname)
0097     gStyle.SetPalette(kRainBow)
0098     Draw_2Dhist(hM_hitmap_RowColumnFlatten_unwei, isdata, False, False, 0.15, '(z and layer) index', 'phi index', 'Entries', 'colz', '{}/TrkrHitRowColumnFlatten_unwei'.format(plotdir))
0099     Draw_2Dhist(hM_hitmap_RowColumnFlatten_weiADC, isdata, False, False, 0.15, '(z and layer) index', 'phi index', 'Entries (weighted by ADC)', 'colz', '{}/TrkrHitRowColumnFlatten_weiADC'.format(plotdir))
0100     hM_hitmap_RowColumnFlatten_avgtrkrhitadc.Divide(hM_hitmap_RowColumnFlatten_unwei)
0101     Draw_2Dhist(hM_hitmap_RowColumnFlatten_avgtrkrhitadc, isdata, False, False, 0.15, '(z and layer) index', 'phi index','Average TrkrHit ADC', 'colz', '{}/TrkrHitRowColumnFlatten_avgTrkrHitADC'.format(plotdir))
0102 
0103 
0104