CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
monitorPlot Namespace Reference

Functions

def plot
 

Function Documentation

def monitorPlot.plot (   config)

Definition at line 16 of file monitorPlot.py.

References style.setstatsize().

Referenced by mps_validate.main().

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