File indexing completed on 2023-03-17 11:00:43
0001
0002
0003 import configparser as ConfigParser
0004 import argparse
0005 import numpy
0006
0007 import ROOT
0008
0009 parser = argparse.ArgumentParser(description="Calculate the scale factors used to correct the energy response of the ECAL in FastSim.")
0010 parser.add_argument("--cfg", help="Name of the configuration file.", default="calculateECALresponceScales.cfg")
0011 args = parser.parse_args()
0012
0013 config = ConfigParser.SafeConfigParser()
0014 config.readfp( open(args.cfg) )
0015
0016
0017 title = ";"+";".join( [config.get("xAxis", "title"),config.get("yAxis", "title"),config.get("zAxis", "title")] )
0018
0019 binEdges = {}
0020 for axis in "xAxis", "yAxis", "zAxis":
0021 if config.has_option(axis, "binCenters"):
0022 binCenters = [ float(i) for i in config.get(axis, "binCenters").split(",") ]
0023
0024
0025
0026 binEdgeList = [0]
0027 for i in range(len(binCenters)-1):
0028 binEdgeList.append( 0.5*(binCenters[i]+binCenters[i+1] ) )
0029 binEdgeList.append( max([1e4, 10*binEdgeList[-1]]) )
0030
0031 binEdges[axis] = numpy.array( binEdgeList )
0032 else:
0033 binEdges[axis] = numpy.linspace(
0034 config.getfloat(axis, "min"),
0035 config.getfloat(axis, "max"),
0036 num=config.getint(axis,"bins") )
0037
0038
0039 h3 = ROOT.TH3F(
0040 config.get("output", "histogramName"),
0041 title,
0042 len( binEdges["xAxis"] )-1, binEdges["xAxis"],
0043 len( binEdges["yAxis"] )-1, binEdges["yAxis"],
0044 len( binEdges["zAxis"] )-1, binEdges["zAxis"]
0045 )
0046
0047
0048 ROOT.gROOT.LoadMacro("calculateECALresponceScales.C+")
0049
0050 fac = ROOT.KKFactorsFactory( h3,
0051 config.get("input", "fileNameFast"),
0052 config.get("input", "fileNameFull"),
0053 config.get("input", "treeName")
0054 )
0055
0056 fac.calculate()
0057
0058 fout = ROOT.TFile( config.get("output", "fileName"), "recreate" )
0059 fac.GetH3().Write()
0060 fout.Close()
0061
0062