CMS 3D CMS Logo

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