CMS 3D CMS Logo

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