test
CMS 3D CMS Logo

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