test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
monitorPlot.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Draw the plots saved in the millePedeMonitor_merge.root file
5 #
6 
7 import logging
8 import os
9 
10 from ROOT import TH1F, TCanvas, TFile, TImage, gStyle
11 
12 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes import MonitorData, OutputData
13 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style import setstatsize
14 
15 
16 def plot(config):
17  logger = logging.getLogger("mpsvalidate")
18 
19  # adjust the plot style
20  # show the skewness in the legend
21  gStyle.SetOptStat("emrs")
22  gStyle.SetPadLeftMargin(0.07)
23 
24  # loop over all millepedemonitor_X.root files
25  for filename in os.listdir("{0}".format(config.jobDataPath)):
26  if (filename.endswith(".root") and filename.startswith("millepedemonitor_")):
27  # get X out of millepedemonitor_X.root files
28  inputname = filename[17:-5]
29 
30  # open file
31  rootfile = TFile("{0}/{1}".format(config.jobDataPath, filename))
32 
33  plotPaths = ["usedTrackHists/usedptTrack", "usedTrackHists/usedetaTrack",
34  "usedTrackHists/usedphiTrack", "usedTrackHists/usednHitTrack"]
35 
36  # loop over plots which should be plotted
37  for plotNumber, plotPath in enumerate(plotPaths):
38  # get plotname
39  plotName = plotPath.split("/")[1]
40  # get plot
41  plot = rootfile.Get(plotPath)
42 
43  if (plotNumber == 0):
44  # get number of used tracks
45  ntracks = int(plot.GetEntries())
46  MonitorData(inputname.replace("_", " "), ntracks)
47 
48  # create canvas
49  canvas = TCanvas("canvas{0}_{1}".format(
50  inputname, plotName), "Monitor", 300, 0, 800, 600)
51  canvas.cd()
52 
53  # set statistics size
54  setstatsize(canvas, plot, config)
55 
56  # draw
57  plot.Draw()
58 
59  # save as pdf
60  canvas.Print(
61  "{0}/plots/pdf/monitor_{1}_{2}.pdf".format(config.outputPath, inputname.replace(".","_"), plotName))
62 
63  # export as png
64  image = TImage.Create()
65  image.FromPad(canvas)
66  image.WriteImage(
67  "{0}/plots/png/monitor_{1}_{2}.png".format(config.outputPath, inputname.replace(".","_"), plotName))
68 
69  # add to output list
70  output = OutputData(plottype="monitor", name=inputname.replace("_", " "), number=plotName, filename="monitor_{1}_{2}".format(
71  config.outputPath, inputname.replace(".","_"), plotName))
72  config.outputList.append(output)
73 
74  # reset the plot style
75  gStyle.SetOptStat(0)
76  gStyle.SetPadLeftMargin(0.17)
def setstatsize
statistics size
Definition: style.py:31