CMS 3D CMS Logo

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