CMS 3D CMS Logo

plottingOptions.py
Go to the documentation of this file.
1 import os
2 import random
3 
4 import globalDictionaries
5 import configTemplates
6 
7 from genericValidation import ValidationMetaClass, ValidationWithComparison, ValidationWithPlots
8 from helperFunctions import getCommandOutput2, replaceByMap, cppboolstring
9 from offlineValidation import OfflineValidation
10 from primaryVertexValidation import PrimaryVertexValidation
11 from TkAlExceptions import AllInOneError
12 from trackSplittingValidation import TrackSplittingValidation
13 from zMuMuValidation import ZMuMuValidation
14 
16  __metaclass__ = ValidationMetaClass
17  defaults = {
18  "cmssw" : os.environ["CMSSW_BASE"],
19  "publicationstatus" : "",
20  "customtitle" : "",
21  "customrighttitle" : "",
22  "era" : "NONE",
23  "legendheader" : "",
24  "legendoptions":"all",
25  }
26  mandatories = set()
27  needpackages = {"Alignment/OfflineValidation"}
28  def __init__(self, config, valType):
29  import random
30  self.type = valType
31  self.general = config.getGeneral()
32  self.randomWorkdirPart = "%0i"%random.randint(1,10e9)
33  self.config = config
34 
35  theUpdate = config.getResultingSection("plots:"+self.type,
36  defaultDict = self.defaults,
37  demandPars = self.mandatories)
38  self.general.update(theUpdate)
39 
40  self.cmssw = self.general["cmssw"]
41  badcharacters = r"\'"
42  for character in badcharacters:
43  if character in self.cmssw:
44  raise AllInOneError("The bad characters " + badcharacters + " are not allowed in the cmssw\n"
45  "path name. If you really have it in such a ridiculously named location,\n"
46  "try making a symbolic link somewhere with a decent name.")
47  try:
48  os.listdir(self.cmssw)
49  except OSError:
50  raise AllInOneError("Your cmssw release " + self.cmssw + ' does not exist')
51 
52  if self.cmssw == os.environ["CMSSW_BASE"]:
53  self.scramarch = os.environ["SCRAM_ARCH"]
54  self.cmsswreleasebase = os.environ["CMSSW_RELEASE_BASE"]
55  else:
56  command = ("cd '" + self.cmssw + "' && eval `scramv1 ru -sh 2> /dev/null`"
57  ' && echo "$CMSSW_BASE\n$SCRAM_ARCH\n$CMSSW_RELEASE_BASE"')
58  commandoutput = getCommandOutput2(command).split('\n')
59  self.cmssw = commandoutput[0]
60  self.scramarch = commandoutput[1]
61  self.cmsswreleasebase = commandoutput[2]
62 
63  for package in self.needpackages:
64  for placetolook in self.cmssw, self.cmsswreleasebase:
65  pkgpath = os.path.join(placetolook, "src", package)
66  if os.path.exists(pkgpath):
67  self.general[package] = pkgpath
68  break
69  else:
70  raise AllInOneError("Package {} does not exist in {} or {}!".format(package, self.cmssw, self.cmsswreleasebase))
71 
72  self.general["publicationstatus"] = self.general["publicationstatus"].upper()
73  self.general["era"] = self.general["era"].upper()
74 
75  if not self.general["publicationstatus"] and not self.general["customtitle"]:
76  self.general["publicationstatus"] = "INTERNAL"
77  if self.general["customtitle"] and not self.general["publicationstatus"]:
78  self.general["publicationstatus"] = "CUSTOM"
79 
80  if self.general["publicationstatus"] != "CUSTOM" and self.general["customtitle"]:
81  raise AllInOneError("If you would like to use a custom title, please leave out the 'publicationstatus' parameter")
82  if self.general["publicationstatus"] == "CUSTOM" and not self.general["customtitle"]:
83  raise AllInOneError("If you want to use a custom title, you should provide it using 'customtitle' in the [plots:%s] section" % valType)
84 
85  if self.general["era"] != "NONE" and self.general["customrighttitle"]:
86  raise AllInOneError("If you would like to use a custom right title, please leave out the 'era' parameter")
87 
88  publicationstatusenum = ["INTERNAL", "INTERNAL_SIMULATION", "PRELIMINARY", "PUBLIC", "SIMULATION", "UNPUBLISHED", "CUSTOM"]
89  eraenum = ["NONE", "CRUZET15", "CRAFT15", "COLL0T15"]
90  if self.general["publicationstatus"] not in publicationstatusenum:
91  raise AllInOneError("Publication status must be one of " + ", ".join(publicationstatusenum) + "!")
92  if self.general["era"] not in eraenum:
93  raise AllInOneError("Era must be one of " + ", ".join(eraenum) + "!")
94 
95  knownOpts = set(self.defaults.keys())|self.mandatories|self.optionals
96  ignoreOpts = []
97  config.checkInput("plots:"+self.type,
98  knownSimpleOptions = knownOpts,
99  ignoreOptions = ignoreOpts)
100 
101  def getRepMap(self):
102  result = self.general
103  result.update({
104  "workdir": os.path.join(self.general["workdir"],
105  self.randomWorkdirPart),
106  "datadir": self.general["datadir"],
107  "logdir": self.general["logdir"],
108  "CMSSW_BASE": self.cmssw,
109  "SCRAM_ARCH": self.scramarch,
110  "CMSSW_RELEASE_BASE": self.cmsswreleasebase,
111  "validationId": self.validationclass.__name__,
112  })
113  if issubclass(self.validationclass, ValidationWithPlots):
114  result["plottingscriptname"] = self.validationclass.plottingscriptname()
115  result["plottingscriptpath"] = ".oO[scriptsdir]Oo./.oO[plottingscriptname]Oo."
116  result["PlotsDirName"] = self.validationclass.plotsdirname()
117  if issubclass(self.validationclass, ValidationWithComparison):
118  result["compareAlignmentsPath"] = self.validationclass.comparealignmentspath()
119  result["compareAlignmentsName"] = self.validationclass.comparealignmentsname()
120  return result
121 
123  defaults = {
124  "outliercut": "-1.0",
125  "subdetector": "none",
126  }
127  needpackages = {"Alignment/CommonAlignmentProducer"}
128  validationclass = TrackSplittingValidation
129  def __init__(self, config):
130  super(PlottingOptionsTrackSplitting, self).__init__(config, "split")
131  validsubdets = self.validsubdets()
132  if self.general["subdetector"] not in validsubdets:
133  raise AllInOneError("'%s' is not a valid subdetector!\n" % self.general["subdetector"] + "The options are: " + ", ".join(validsubdets))
134 
135  def validsubdets(self):
136  filename = replaceByMap(".oO[Alignment/CommonAlignmentProducer]Oo./python/AlignmentTrackSelector_cfi.py", self.getRepMap())
137  with open(filename) as f:
138  trackselector = f.read()
139 
140  minhitspersubdet = trackselector.split("minHitsPerSubDet")[1].split("(",1)[1]
141 
142  parenthesesdepth = 0
143  i = 0
144  for character in minhitspersubdet:
145  if character == "(":
146  parenthesesdepth += 1
147  if character == ")":
148  parenthesesdepth -= 1
149  if parenthesesdepth < 0:
150  break
151  i += 1
152  minhitspersubdet = minhitspersubdet[0:i]
153 
154  results = minhitspersubdet.split(",")
155  empty = []
156  for i in range(len(results)):
157  results[i] = results[i].split("=")[0].strip().replace("in", "", 1)
158 
159  results.append("none")
160 
161  return [a for a in results if a]
162 
164  defaults = {
165  "resonance": "Z",
166  "switchONfit": "false",
167  "rebinphi": "4",
168  "rebinetadiff": "2",
169  "rebineta": "2",
170  "rebinpt": "8",
171  }
172  needpackages = {"MuonAnalysis/MomentumScaleCalibration"}
173  validationclass = ZMuMuValidation
174  def __init__(self, config):
175  super(PlottingOptionsZMuMu, self).__init__(config, "zmumu")
176  self.general["switchONfit"] = cppboolstring(self.general["switchONfit"], "switchONfit")
177 
179  defaults = {
180  "DMRMethod":"median,rmsNorm",
181  "DMRMinimum":"30",
182  "DMROptions":"",
183  "OfflineTreeBaseDir":"TrackHitFilter",
184  "SurfaceShapes":"coarse",
185  "bigtext":"false",
186  "mergeOfflineParJobsScriptPath": ".oO[scriptsdir]Oo./TkAlOfflineJobsMerge.C",
187  "usefit": "false",
188  }
189  validationclass = OfflineValidation
190  def __init__(self, config):
191  super(PlottingOptionsOffline, self).__init__(config, "offline")
192  for name in "usefit", "bigtext":
193  self.general[name] = cppboolstring(self.general[name], name)
194 
195 
197  defaults = {
198  "autoLimits":"false",
199  "doMaps":"false",
200  "stdResiduals":"true",
201  "m_dxyPhiMax":"40",
202  "m_dzPhiMax":"40",
203  "m_dxyEtaMax":"40",
204  "m_dzEtaMax":"40",
205  "m_dxyPhiNormMax":"0.5",
206  "m_dzPhiNormMax":"0.5",
207  "m_dxyEtaNormMax":"0.5",
208  "m_dzEtaNormMax":"0.5",
209  "w_dxyPhiMax":"150",
210  "w_dzPhiMax":"150",
211  "w_dxyEtaMax":"150",
212  "w_dzEtaMax":"1000",
213  "w_dxyPhiNormMax":"1.8",
214  "w_dzPhiNormMax":"1.8",
215  "w_dxyEtaNormMax":"1.8",
216  "w_dzEtaNormMax":"1.8",
217  }
218  validationclass = PrimaryVertexValidation
219  def __init__(self, config):
220  super(PlottingOptionsPrimaryVertex, self).__init__(config, "primaryvertex")
221  for name in "autoLimits", "doMaps", "stdResiduals":
222  self.general[name] = cppboolstring(self.general[name], name)
223 
224 def PlottingOptions(config, valType):
225  plottingOptionsClasses = {
226  "offline": PlottingOptionsOffline,
227  "split": PlottingOptionsTrackSplitting,
228  "zmumu": PlottingOptionsZMuMu,
229  "primaryvertex": PlottingOptionsPrimaryVertex,
230  }
231  if isinstance(valType, type):
232  valType = valType.valType
233 
234  if valType not in globalDictionaries.plottingOptions:
235  if config is None:
236  raise ValueError("Have to provide a config the first time you call PlottingOptions for {}".format(valType))
237  globalDictionaries.plottingOptions[valType] = plottingOptionsClasses[valType](config)
238  return globalDictionaries.plottingOptions[valType].getRepMap()
def replace(string, replacements)
def getCommandOutput2(command)
def cppboolstring(string, name)
def __init__(self, config, valType)
def PlottingOptions(config, valType)
def replaceByMap(target, the_map)
— Helpers —############################
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139