File indexing completed on 2024-04-06 11:56:35
0001
0002
0003
0004
0005 import logging
0006 import os
0007 try:
0008 import cPickle as pickle
0009 except:
0010 import pickle
0011
0012 import ROOT
0013 ROOT.PyConfig.IgnoreCommandLineOptions = True
0014 ROOT.gROOT.SetBatch()
0015
0016 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
0017 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
0018
0019
0020 def plot(config):
0021 logger = logging.getLogger("mpsvalidate")
0022
0023
0024
0025 ROOT.gStyle.SetOptStat("emrs")
0026 ROOT.gStyle.SetPadLeftMargin(0.07)
0027
0028
0029 with open(os.path.join(config.jobDataPath, ".weights.pkl"), "rb") as f:
0030 weight_conf = pickle.load(f)
0031
0032
0033 for filename in os.listdir("{0}".format(config.jobDataPath)):
0034 if (filename.endswith(".root") and filename.startswith("millepedemonitor_")):
0035
0036 inputname = os.path.splitext(filename.split("millepedemonitor_")[-1])[0]
0037
0038
0039 rootfile = ROOT.TFile(os.path.join(config.jobDataPath, filename))
0040
0041 plotPaths = ["usedTrackHists/usedptTrack", "usedTrackHists/usedetaTrack",
0042 "usedTrackHists/usedphiTrack", "usedTrackHists/usednHitTrack"]
0043
0044
0045 for plotNumber, plotPath in enumerate(plotPaths):
0046
0047 plotName = plotPath.split("/")[1]
0048
0049 plot = rootfile.Get(plotPath)
0050
0051 if (plotNumber == 0):
0052
0053 ntracks = int(plot.GetEntries())
0054 weight = [item[1]
0055 for item in weight_conf
0056 if item[0] == inputname][0]
0057 mpsv_classes.MonitorData(inputname.replace("_", " "), ntracks, weight)
0058
0059
0060 canvas = ROOT.TCanvas("canvas{0}_{1}".format(
0061 inputname, plotName), "Monitor", 300, 0, 800, 600)
0062 canvas.cd()
0063
0064
0065 mpsv_style.setstatsize(canvas, plot, config)
0066
0067
0068 plot.Draw()
0069
0070
0071 canvas.Print(
0072 "{0}/plots/pdf/monitor_{1}_{2}.pdf".format(config.outputPath, inputname.replace(".","_"), plotName))
0073
0074
0075 image = ROOT.TImage.Create()
0076 image.FromPad(canvas)
0077 image.WriteImage(
0078 "{0}/plots/png/monitor_{1}_{2}.png".format(config.outputPath, inputname.replace(".","_"), plotName))
0079
0080
0081 output = mpsv_classes.OutputData(plottype="monitor", name=inputname.replace("_", " "), number=plotName, filename="monitor_{1}_{2}".format(
0082 config.outputPath, inputname.replace(".","_"), plotName))
0083 config.outputList.append(output)
0084
0085
0086 ROOT.gStyle.SetOptStat(0)
0087 ROOT.gStyle.SetPadLeftMargin(0.17)