test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
beamerCreator.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Creates beamer out of the histograms, parsed data and a given template.
5 ##
6 
7 import logging
8 import os
9 import string
10 
11 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes import MonitorData, PedeDumpData
12 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry import Alignables, Structure
13 
14 
15 # create class to have delimiter %% which is not used in latex
16 
17 
18 class TexTemplate(string.Template):
19  delimiter = "%%"
20 
21 
22 class Out:
23 
24  def __init__(self):
25  self.text = ""
26 
27  def addSlide(self, head, text):
28  self.text += "\\begin{{frame}}[t]{{{0}}}\n".format(head)
29  self.text += text
30  self.text += """\\vfill
31  \\rule{0.9\paperwidth}{1pt}
32  \insertnavigation{0.89\paperwidth}
33  \\end{frame}\n"""
34 
35  def addSlide_fragile(self, head, text):
36  self.text += "\\begin{{frame}}[fragile=singleslide]{{{0}}}\n".format(head)
37  self.text += text
38  self.text += """\\vfill
39  \\rule{0.9\paperwidth}{1pt}
40  \insertnavigation{0.89\paperwidth}
41  \\end{frame}\n"""
42 
43  def add(self, text):
44  self.text += text + "\n"
45 
46 
47 def create(alignables, pedeDump, additionalData, outputFile, config):
48  logger = logging.getLogger("mpsvalidate")
49 
50  # load template
51  with open(os.path.join(config.mpspath, "beamer_template.tex"), "r") as template:
52  data = template.read()
53  template.close()
54 
55  # create object where data could be substituted
56  data = TexTemplate(data)
57 
58  # output string
59  out = Out()
60  text = ""
61 
62  # title page
63  if (config.message):
64  text += """\centering
65  \\vspace*{{4cm}}
66  \Huge\\bfseries Alignment Validation\par
67  \\vspace{{2cm}}
68  \scshape\huge Alignment Campaign\\\\ {{{0}}}\par
69  \\vfill
70  \large \\today\par""".format(config.message)
71  else:
72  text += """\centering
73  \\vspace*{4cm}
74  \Huge\\bfseries Alignment Validation\par
75  \\vfill
76  \large \\today\par"""
77  out.addSlide("", text)
78 
79  # table of contents
80  text = "\\tableofcontents"
81  out.addSlide("Overview", text)
82 
83  # general information
84  out.add("\section{General information}")
85  text = ""
86  if (config.message):
87  text = "Project: {{{0}}}\\\\\n".format(config.message)
88  text += "Input-Path:\n"
89  text += "\\begin{verbatim}\n"
90  text += config.jobDataPath+"\n"
91  text += "\\end{verbatim}\n"
92  out.addSlide_fragile("General information", text)
93 
94  # alignment_merge.py
95  try:
96  out.add("\subsection{Alignment Configuration}")
97  text = "\\textbf{{PedeSteerer method:}} {{{0}}}\\\\\n".format(
98  additionalData.pedeSteererMethod)
99  text += "\\textbf{{PedeSteerer options:}}\\\\\n"
100  for line in additionalData.pedeSteererOptions:
101  text += "{{{0}}}\\\\\n".format(line)
102  text += "\\textbf{{PedeSteerer command:}} {0}\\\\\n".format(
103  additionalData.pedeSteererCommand)
104  out.addSlide("Alignment Configuration", text)
105  except Exception as e:
106  logger.error("data not found - {0} {1}".format(type(e), e))
107 
108  # table of input files with number of tracks
109  if (config.showmonitor):
110  out.add("\subsection{Datasets with tracks}")
111  text = """\\begin{table}[h]
112  \centering
113  \caption{Datasets with tracks}
114  \\begin{tabular}{cc}
115  \hline
116  Dataset & Number of used tracks \\\\
117  \hline \n"""
118  try:
119  for monitor in MonitorData.monitors:
120  text += "{0} & {1}\\\\\n".format(monitor.name, monitor.ntracks)
121  except Exception as e:
122  logger.error("data not found - {0} {1}".format(type(e), e))
123  if (pedeDump.nrec):
124  text += "Number of records & {0}\\\\\n".format(pedeDump.nrec)
125  text += """\hline
126  \end{tabular}\n
127  \end{table}\n"""
128  text += "The information in this table is based on the monitor root files. Note that the number of tracks which where used in the pede step can differ from this table.\n"
129  out.addSlide("Datasets with tracks", text)
130 
131  # pede.dump.gz
132  out.add("\subsection{Pede monitoring information}")
133  try:
134  if (pedeDump.sumValue != 0):
135  text = r"\begin{{align*}}Sum(Chi^2)/Sum(Ndf) &= {0}\\ &= {1}\end{{align*}}".format(
136  pedeDump.sumSteps, pedeDump.sumValue)
137  else:
138  text = r"\begin{{align*}}Sum(W*Chi^2)/Sum(Ndf)/<W> &= {0}\\ &= {1}\end{{align*}}".format(
139  pedeDump.sumSteps, pedeDump.sumWValue)
140  text += r"with correction for down-weighting: {0}\\".format(
141  pedeDump.correction)
142  text += r"Peak dynamic memory allocation: {0} GB\\".format(pedeDump.memory)
143  text += r"Total time: {0} h {1} m {2} s\\".format(
144  pedeDump.time[0], pedeDump.time[1], pedeDump.time[2])
145  text += r"Number of records: {0}\\".format(pedeDump.nrec)
146  text += r"Total number of parameters: {0}\\".format(pedeDump.ntgb)
147  text += r"Number of variable parameters: {0}\\".format(pedeDump.nvgb)
148  out.addSlide("Pede monitoring information", text)
149  except Exception as e:
150  logger.error("data not found - {0} {1}".format(type(e), e))
151 
152  # Parameter plots
153  out.add("\section{Parameter plots}")
154 
155  # high level Structures
156  out.add("\subsection{High-level parameters}")
157  big = [x for x in config.outputList if (x.plottype == "big")]
158 
159  for i in big:
160  text = "\includegraphics[height=0.85\\textheight]{{{0}/plots/pdf/{1}.pdf}}\n".format(
161  config.outputPath, i.filename)
162 
163  out.addSlide("High-level parameters", text)
164 
165  # time (IOV) dependent plots
166  out.add("\subsection{High-level parameters versus time (IOV)}")
167  time = [x for x in config.outputList if (x.plottype == "time")]
168 
169  if time:
170  # get list with names of the structures
171  for structure in [x.name for x in time if x.parameter == "xyz"]:
172  for mode in ["xyz", "rot"]:
173  text = "\\framesubtitle{{{0}}}\n".format(structure)
174  if any([x.filename for x in time if (x.parameter == mode and x.name == structure)]):
175  filename = [x.filename for x in time if (x.parameter == mode and x.name == structure)][0]
176  text += "\includegraphics[height=0.85\\textheight]{{{0}/plots/pdf/{1}.pdf}}\n".format(
177  config.outputPath, filename)
178 
179  out.addSlide("High-level parameters versus time (IOV)", text)
180 
181  # hole modules
182  out.add("\subsection{Module-level parameters}")
183  # check if there are module plots
184  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "")):
185 
186  # loop over all structures
187  for moduleName in [x.name for x in alignables.structures]:
188 
189  # check if there is a plot for this module
190  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "" and x.name == moduleName)):
191 
192  # loop over modes
193  for mode in ["xyz", "rot", "dist"]:
194 
195  # get module plot
196  module = [x for x in config.outputList if (
197  x.plottype == "mod" and x.number == "" and x.name == moduleName and x.parameter == mode)]
198  # get list of sub module plots
199  moduleSub = [x for x in config.outputList if (
200  x.plottype == "subMod" and x.number != "" and x.name == moduleName and x.parameter == mode)]
201 
202  # check if plot there is a plot in this mode
203  if module:
204  text = "\\framesubtitle{{{0}}}\n".format(moduleName)
205  text += "\includegraphics[height=0.85\\textheight]{{{0}/plots/pdf/{1}.pdf}}\n".format(
206  config.outputPath, module[0].filename)
207 
208  out.addSlide("Module-level parameters", text)
209 
210  # loop over submodules
211  for plot in moduleSub:
212  text = "\\framesubtitle{{{0}}}\n".format(
213  moduleName)
214  text += "\includegraphics[height=0.85\\textheight]{{{0}/plots/pdf/{1}.pdf}}\n".format(
215  config.outputPath, plot.filename)
216 
217  out.addSlide("Module-level parameters", text)
218 
219  # plot taken from the millePedeMonitor_merge.root file
220  out.add("\section{Monitor plots}")
221  for plot in [x for x in config.outputList if x.plottype == "monitor"]:
222  text = "\\framesubtitle{{{0}}}\n".format(plot.name)
223  text += "\includegraphics[height=0.85\\textheight]{{{0}/plots/pdf/{1}.pdf}}\n".format(
224  config.outputPath, plot.filename)
225  out.addSlide("Monitor", text)
226 
227  data = data.substitute(out=out.text)
228 
229  with open(os.path.join(config.outputPath, outputFile), "w") as output:
230  output.write(data)
231  output.close()
232 
233  # TODO run pdflatex
234  for i in range(2):
235  os.system("pdflatex -output-directory={0} {1}/{2}".format(
236  config.outputPath, config.outputPath, outputFile))
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34