CMS 3D CMS Logo

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

Functions

def plot
 

Function Documentation

def monitorPlot.plot (   config)

Definition at line 20 of file monitorPlot.py.

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