CMS 3D CMS Logo

monitorPlot.py
Go to the documentation of this file.
1 
4 
5 import logging
6 import os
7 import cPickle
8 
9 import ROOT
10 ROOT.PyConfig.IgnoreCommandLineOptions = True
11 ROOT.gROOT.SetBatch()
12 
13 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
14 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
15 
16 
17 def plot(config):
18  logger = logging.getLogger("mpsvalidate")
19 
20  # adjust the plot style
21  # show the skewness in the legend
22  ROOT.gStyle.SetOptStat("emrs")
23  ROOT.gStyle.SetPadLeftMargin(0.07)
24 
25  # retrieve the weights of the different datasets
26  with open(os.path.join(config.jobDataPath, ".weights.pkl"), "rb") as f:
27  weight_conf = cPickle.load(f)
28 
29  # loop over all millepedemonitor_X.root files
30  for filename in os.listdir("{0}".format(config.jobDataPath)):
31  if (filename.endswith(".root") and filename.startswith("millepedemonitor_")):
32  # get X out of millepedemonitor_X.root files
33  inputname = os.path.splitext(filename.split("millepedemonitor_")[-1])[0]
34 
35  # open file
36  rootfile = ROOT.TFile(os.path.join(config.jobDataPath, filename))
37 
38  plotPaths = ["usedTrackHists/usedptTrack", "usedTrackHists/usedetaTrack",
39  "usedTrackHists/usedphiTrack", "usedTrackHists/usednHitTrack"]
40 
41  # loop over plots which should be plotted
42  for plotNumber, plotPath in enumerate(plotPaths):
43  # get plotname
44  plotName = plotPath.split("/")[1]
45  # get plot
46  plot = rootfile.Get(plotPath)
47 
48  if (plotNumber == 0):
49  # get number of used tracks
50  ntracks = int(plot.GetEntries())
51  weight = [item[1]
52  for item in weight_conf
53  if item[0] == inputname][0]
54  mpsv_classes.MonitorData(inputname.replace("_", " "), ntracks, weight)
55 
56  # create canvas
57  canvas = ROOT.TCanvas("canvas{0}_{1}".format(
58  inputname, plotName), "Monitor", 300, 0, 800, 600)
59  canvas.cd()
60 
61  # set statistics size
62  mpsv_style.setstatsize(canvas, plot, config)
63 
64  # draw
65  plot.Draw()
66 
67  # save as pdf
68  canvas.Print(
69  "{0}/plots/pdf/monitor_{1}_{2}.pdf".format(config.outputPath, inputname.replace(".","_"), plotName))
70 
71  # export as png
72  image = ROOT.TImage.Create()
73  image.FromPad(canvas)
74  image.WriteImage(
75  "{0}/plots/png/monitor_{1}_{2}.png".format(config.outputPath, inputname.replace(".","_"), plotName))
76 
77  # add to output list
78  output = mpsv_classes.OutputData(plottype="monitor", name=inputname.replace("_", " "), number=plotName, filename="monitor_{1}_{2}".format(
79  config.outputPath, inputname.replace(".","_"), plotName))
80  config.outputList.append(output)
81 
82  # reset the plot style
83  ROOT.gStyle.SetOptStat(0)
84  ROOT.gStyle.SetPadLeftMargin(0.17)
createfilelist.int
int
Definition: createfilelist.py:10
monitorPlot.plot
def plot(config)
Definition: monitorPlot.py:17
format