CMS 3D CMS Logo

mps_validate.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Create histograms out of treeFile_merge.root . The pede.dump.gz file is
5 # paresed. The histograms are plotted as PNG files. The output data is
6 # created as PDF, HTML, ...
7 
8 
9 import argparse
10 import glob
11 import logging
12 import os
13 import shutil
14 import sys
15 
16 from ROOT import PyConfig
17 PyConfig.IgnoreCommandLineOptions = True
18 
19 from ROOT import (TH1F, TCanvas, TFile, TImage, TPaveLabel, TPaveText, TTree,
20  gROOT, gStyle)
21 
22 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate import (additionalparser, beamerCreator, bigModule,
23  bigStructure, dumpparser, htmlCreator, monitorPlot,
24  pdfCreator, subModule, timeStructure, trackerTree)
25 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes import OutputData, PedeDumpData, PlotData
26 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry import Alignables, Structure
27 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.iniparser import ConfigData
28 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style import setgstyle
29 
30 
31 def main():
32  # config logging module
33  logging.basicConfig(level=logging.INFO, format="%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s", datefmt="%H:%M:%S")
34  logger = logging.getLogger("mpsvalidate")
35 
36  # run ROOT in batchmode
37  gROOT.SetBatch()
38 
39  # ArgumentParser
40  parser = argparse.ArgumentParser(description="Validate your Alignment.")
41  parser.add_argument(
42  "-j", "--job", help="chose jobmX directory (default: ini-file)", default=-1, type=int)
43  parser.add_argument(
44  "-t", "--time", help="chose MillePedeUser_X Tree (default: ini-file)", default=-1, type=int)
45  parser.add_argument("-i", "--ini", help="specify a ini file", default="-1")
46  parser.add_argument("-m", "--message",
47  help="identification on every plot", default="")
48  parser.add_argument("-p", "--jobdatapath",
49  help="path to the jobm directory", default="")
50  parser.add_argument("-o", "--outputpath",
51  help="outputpath", default="")
52  parser.add_argument("-l", "--logging",
53  help="if this argument is given a logging file (validation.log) is saved in the current directory", action="store_true")
54  parser.add_argument("-c", "--copy",
55  help="creates a copy of the validation_user.ini file in the current directory", action="store_true")
56  args = parser.parse_args()
57 
58  # create config object
59  config = ConfigData()
60 
61  # create logging handler
62  if(args.logging):
63  handler = logging.FileHandler("validation.log", mode="w")
64  handler.setLevel(logging.DEBUG)
65  formatter = logging.Formatter("%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s",
66  datefmt="%H:%M:%S")
67  handler.setFormatter(formatter)
68  logger.addHandler(handler)
69 
70  # parse default ini file
71  logger.info("start to parse the default.ini")
72  config.parseConfig(os.path.join(config.mpspath, "default.ini"))
73 
74  # copy of ini file in current directory
75  if (args.copy):
76  logger.info("create copy of validation_user.ini in current directory")
77  shutil.copy2(os.path.join(config.mpspath, "default.ini"), "validation_user.ini")
78  sys.exit()
79 
80 
81  # parse user ini file
82  if (args.ini != "-1"):
83  logger.info("start to parse the user ini: {0}".format(args.ini))
84  config.parseConfig(args.ini)
85 
86  # override ini configs with consol parameter
87  config.parseParameter(args)
88 
89  # create output directories
90  logger.info("create the output directories")
91  if not os.path.exists(os.path.join(config.outputPath, "plots/pdf")):
92  os.makedirs(os.path.join(config.outputPath, "plots/pdf"))
93  if not os.path.exists(os.path.join(config.outputPath, "plots/png")):
94  os.makedirs(os.path.join(config.outputPath, "plots/png"))
95 
96  # open root file and get TTree MillePedeUser_X
97  logger.info("try to open the root file: {0}".format(os.path.join(config.jobDataPath, "treeFile_merge.root")))
98  treeFile = TFile(os.path.join(config.jobDataPath, "treeFile_merge.root"))
99  MillePedeUser = treeFile.Get("MillePedeUser_{0}".format(config.jobTime))
100  if not MillePedeUser:
101  logger.error("Could not open TTree File MillePedeUser_{0} in {1}".format(
102  config.jobTime, os.path.join(config.jobDataPath, "treeFile_merge.root")))
103  return
104 
105  # set gStyle
106  setgstyle()
107 
108  # create alignables object
109  alignables = Alignables(config)
110 
111  # check if there is the TrackerTree.root file and if not create it
112  trackerTree.check(config)
113 
114  ##########################################################################
115  # draw the plots of the millePedeMonitor_merge.root file
116  #
117 
118  if (config.showmonitor == 1):
119  try:
120  logger.info("start to collect the plots of the millePedeMonitor_merge.root file")
121  monitorPlot.plot(config)
122  except Exception as e:
123  logging.error("millePedeMonitor_merge.root failure - {0} {1}".format(type(e), e))
124  raise
125 
126  ##########################################################################
127  # parse the alignment_merge.py file
128  #
129 
130  if (config.showadditional == 1):
131  logger.info("start to parse the alignment_merge.py file")
132  try:
133  additionalData = additionalparser.AdditionalData()
134  additionalData.parse(
135  config, os.path.join(config.jobDataPath, "alignment_merge.py"))
136  except Exception as e:
137  logging.error("alignment_merge.py parser failure - {0} {1}".format(type(e), e))
138  raise
139 
140  ##########################################################################
141  # parse the file pede.dump.gz and return a PedeDumpData Object
142  #
143 
144  if (config.showdump == 1):
145  try:
146  logger.info("start to parse the pede.dump.gz file")
147  pedeDump = dumpparser.parse(
148  os.path.join(config.jobDataPath, "pede.dump.gz"), config)
149  except Exception as e:
150  logging.error("pede.dump.gz parser failure - {0} {1}".format(type(e), e))
151  raise
152 
153  ##########################################################################
154  # time dependend big structures
155  #
156 
157  if (config.showtime == 1):
158  try:
159  logger.info("create the time dependent plots")
160  timeStructure.plot(treeFile, alignables, config)
161  except Exception as e:
162  logging.error("time dependent plots failure - {0} {1}".format(type(e), e))
163  raise
164 
165  ##########################################################################
166  # big structures
167  #
168 
169  if (config.showhighlevel == 1):
170  try:
171  logger.info("create the high level plots")
172  bigStructure.plot(MillePedeUser, alignables, config)
173  except Exception as e:
174  logging.error("high level plots failure - {0} {1}".format(type(e), e))
175  raise
176 
177  ##########################################################################
178  # modules of a hole structure
179  # and part of structure
180  #
181 
182  if (config.showmodule == 1):
183  try:
184  logger.info("create the module plots")
185  bigModule.plot(MillePedeUser, alignables, config)
186  except Exception as e:
187  logging.error("module plots failure - {0} {1}".format(type(e), e))
188  raise
189 
190  ##########################################################################
191  # create TEX, beamer
192  #
193 
194  if (config.showtex == 1):
195  try:
196  logger.info("create the latex file")
197  pdfCreator.create(alignables, pedeDump,
198  additionalData, config.latexfile, config)
199  except Exception as e:
200  logging.error("latex creation failure - {0} {1}".format(type(e), e))
201  raise
202 
203  if (config.showbeamer == 1):
204  try:
205  logger.info("create the latex beamer file")
206  beamerCreator.create(alignables, pedeDump, additionalData, "beamer.tex", config)
207  except Exception as e:
208  logging.error("beamer latex failure - {0} {1}".format(type(e), e))
209  raise
210 
211  # delete latex temporary files
212  for extension in ["aux", "log", "nav", "out", "snm", "toc"]:
213  extension = "*." + extension
214  pattern = os.path.join(config.outputPath, extension)
215  logger.info("Remove temporary latex files: "+pattern)
216  map(os.remove, glob.glob(pattern))
217 
218  if (config.showhtml == 1):
219  try:
220  logger.info("create the HTML file")
221  htmlCreator.create(alignables, pedeDump, additionalData, "html_file.html", config)
222  except Exception as e:
223  logging.error("HTML creation failure - {0} {1}".format(type(e), e))
224  raise
225 
226 if __name__ == "__main__":
227  main()
std::vector< Alignable * > Alignables
Definition: Alignable.h:274
def create(alignables, pedeDump, additionalData, outputFile, config)
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: htmlCreator.py:22
def plot(MillePedeUser, alignables, config)
Definition: bigStructure.py:18
def plot(MillePedeUser, alignables, config)
Definition: bigModule.py:19
def parse(path, config)
Definition: dumpparser.py:15
def plot(treeFile, alignables, config)
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: pdfCreator.py:22
if(dp >Float(M_PI)) dp-
def plot(config)
Definition: monitorPlot.py:16
Definition: main.py:1
def setgstyle()
set gstyle by https://github.com/mschrode/AwesomePlots/blob/master/Style.cc
Definition: style.py:50
def check(config)
Definition: trackerTree.py:12