CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
bigModule Namespace Reference

Functions

def plot
 

Function Documentation

def bigModule.plot (   MillePedeUser,
  alignables,
  config 
)

Definition at line 19 of file bigModule.py.

References funct.abs(), bitset_utilities.append(), HcalObjRepresent.Fill(), style.identification(), reco.if(), bookConverter.max, subModule.plot(), MultipleCompare.Rebin(), and style.setstatsize().

Referenced by HLTObjectMonitorProtonLead.analyze(), HLTObjectMonitor.analyze(), TaggingVariablePlotter.analyzeTag(), HLTObjectMonitorProtonLead.bookHistograms(), HLTObjectMonitor.bookHistograms(), MuonPFAnalyzer.bookHistos(), HLTObjectMonitorProtonLead.dqmBeginRun(), HLTObjectMonitor.dqmBeginRun(), DTNoiseAnalysisTest.dqmEndLuminosityBlock(), TauDQMHistEffProducer.endRun(), TauDQMHistPlotter.endRun(), FlavourHistograms< T >.epsPlot(), FlavourHistograms2D< T, G >.epsPlot(), lsbs_cert(), mps_validate.main(), SummaryPlotXmlParser.parseXML(), TauDQMHistPlotter::cfgEntryDrawJob.print(), TauDQMHistPlotter.TauDQMHistPlotter(), TaggingVariablePlotter::VariableConfig.VariableConfig(), and ListGroups.~ListGroups().

19 
20 def plot(MillePedeUser, alignables, config):
21  logger = logging.getLogger("mpsvalidate")
22 
23  alignables.create_list(MillePedeUser)
24 
25  # number of bins to start
26  numberOfBins = 10000
27 
28  ######################################################################
29  # initialize data hierarchy
30  # plots[mode][struct]
31  #
32 
33  plots = []
34  # loop over mode
35  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
36  plots.append([])
37  # loop over structures
38  for structNumber, struct in enumerate(alignables.structures):
39  plots[modeNumber].append(PlotData(mode))
40 
41  # initialize histograms
42  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
43  for structNumber, struct in enumerate(alignables.structures):
44  # use a copy for shorter name
45  plot = plots[modeNumber][structNumber]
46 
47  for i in range(3):
48  if (mode == "xyz"):
49  plot.histo.append(TH1F("{0} {1} {2}".format(struct.get_name(), plot.xyz[
50  i], mode), "", numberOfBins, -1000, 1000))
51  else:
52  plot.histo.append(TH1F("{0} {1} {2}".format(struct.get_name(), plot.xyz[
53  i], mode), "", numberOfBins, -0.1, 0.1))
54 
55  if (plot.unit!=""):
56  plot.histo[i].SetXTitle("#Delta"+plot.xyz[i]+" ["+plot.unit+"]")
57  else:
58  plot.histo[i].SetXTitle("#Delta"+plot.xyz[i])
59  plot.histo[i].SetYTitle("number of alignables")
60  plot.histo[i].GetXaxis().SetTitleOffset(0.8)
61  plot.histoAxis.append(plot.histo[i].GetXaxis())
62 
63  # add labels
64  plot.title = TPaveLabel(
65  0.1, 0.8, 0.9, 0.9, "Module: {0} {1}".format(struct.get_name(), mode))
66  plot.text = TPaveText(0.05, 0.1, 0.95, 0.75)
67  plot.text.SetTextAlign(12)
68  plot.text.SetTextSizePixels(20)
69 
70  # save copy
71  plots[modeNumber][structNumber] = plot
72 
73  ######################################################################
74  # fill histogram
75  #
76 
77  for line in MillePedeUser:
78  # is module ?
79  if (line.ObjId == 1):
80  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
81  for structNumber, struct in enumerate(alignables.structures):
82  # use a copy for shorter name
83  plot = plots[modeNumber][structNumber]
84 
85  # module in struct ?
86  if (struct.contains_detid(line.Id)):
87  for i in range(3):
88  if (abs(line.Par[plot.data[i]]) != 999999):
89  # transform xyz data from cm to #mu m
90  if (mode == "xyz"):
91  plot.histo[i].Fill(
92  10000 * line.Par[plot.data[i]])
93  else:
94  plot.histo[i].Fill(line.Par[plot.data[i]])
95 
96  # save copy
97  plots[modeNumber][structNumber] = plot
98 
99  ######################################################################
100  # find the best range
101  #
102 
103  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
104  for structNumber, struct in enumerate(alignables.structures):
105  # use a copy for shorter name
106  plot = plots[modeNumber][structNumber]
107 
108  for i in range(3):
109  # get first and last bin with content and chose the one which
110  # has a greater distance to the center
111  if (abs(numberOfBins / 2 - plot.histo[i].FindFirstBinAbove()) > abs(plot.histo[i].FindLastBinAbove() - numberOfBins / 2)):
112  plot.maxBinShift[i] = abs(
113  numberOfBins / 2 - plot.histo[i].FindFirstBinAbove())
114  # set the maxShift value
115  plot.maxShift[i] = plot.histo[i].GetBinCenter(
116  plot.histo[i].FindFirstBinAbove())
117  else:
118  plot.maxBinShift[i] = abs(
119  plot.histo[i].FindLastBinAbove() - numberOfBins / 2)
120  # set the maxShift value
121  plot.maxShift[i] = plot.histo[i].GetBinCenter(
122  plot.histo[i].FindLastBinAbove())
123  # skip empty histogram
124  if (abs(plot.maxBinShift[i]) == numberOfBins / 2 + 1):
125  plot.maxBinShift[i] = 0
126 
127  # three types of ranges
128 
129  # 1. multiple of standard dev
130  if (config.rangemode == "stddev"):
131  for i in range(3):
132  if (plot.histo[i].GetEntries() != 0 and plot.histo[i].GetStdDev() != 0):
133  # if the plotrange is much bigger than the standard
134  # deviation use config.widthstdev * StdDev als Range
135  if (max(plot.maxShift) / plot.histo[i].GetStdDev() > config.defpeak):
136  # corresponding bin config.widthstdev*StdDev
137  binShift = int(plot.histo[i].FindBin(
138  config.widthstddev * plot.histo[i].GetStdDev()) - numberOfBins / 2)
139  else:
140  binShift = max(plot.maxBinShift)
141 
142  # save used binShift
143  plot.binShift[i] = binShift
144 
145  # 2. show all
146  if (config.rangemode == "all"):
147  for i in range(3):
148  plot.binShift[i] = plot.maxBinShift[i]
149 
150  # 3. use given ranges
151  if (config.rangemode == "given"):
152  for i in range(3):
153  if (mode == "xyz"):
154  valuelist = config.rangexyzM
155  if (mode == "rot"):
156  valuelist = config.rangerotM
157  if (mode == "dist"):
158  valuelist = config.rangedistM
159 
160  for value in valuelist:
161  # maximum smaller than given value
162  if (abs(plot.maxShift[i]) < value):
163  binShift = value
164  break
165  # if not possible, force highest
166  if (abs(plot.maxShift[i]) > valuelist[-1]):
167  binShift = valuelist[-1]
168  # calculate binShift
169  plot.binShift[i] = int(
170  binShift / plot.histo[i].GetBinWidth(1))
171 
172  # all plot the same range
173  if (config.samerange == 1):
174  for i in range(3):
175  plot.binShift[i] = max(plot.binShift)
176 
177  # save used range
178  for i in range(3):
179  plot.usedRange[i] = plot.binShift[i]
180 
181  # count entries which are not shown anymore
182  for i in range(3):
183  # bin 1 to begin of histogram
184  for j in range(1, numberOfBins / 2 - plot.binShift[i]):
185  plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
186  # from the end of shown bins to the end of histogram
187  for j in range(numberOfBins / 2 + plot.binShift[i], plot.histo[i].GetNbinsX()):
188  plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
189 
190  # apply new range
191  for i in range(3):
192  if (plot.histo[i].GetEntries() != 0):
193  # merge bins, ca. 100 should be visible in the resulting
194  # plot
195  mergeNumberBins = plot.binShift[i]
196  # skip empty histogram
197  if (mergeNumberBins != 0):
198  # the 2*maxBinShift bins should shrink to 100 bins
199  mergeNumberBins = int(
200  2. * mergeNumberBins / config.numberofbins)
201  # the total number of bins should be dividable by the
202  # bins shrinked together
203  if (mergeNumberBins == 0):
204  mergeNumberBins = 1
205  while (numberOfBins % mergeNumberBins != 0 and mergeNumberBins != 1):
206  mergeNumberBins -= 1
207 
208  # Rebin and save new created histogram and axis
209  plot.histo[i] = plot.histo[i].Rebin(mergeNumberBins)
210  plot.histoAxis[i] = plot.histo[i].GetXaxis()
211 
212  # set view range. it is important to note that the number of bins have changed with the rebinning
213  # the total number and the number of shift must be
214  # corrected with / mergeNumberBins
215  plot.histoAxis[i].SetRange(int(numberOfBins / (2 * mergeNumberBins) - plot.binShift[
216  i] / mergeNumberBins), int(numberOfBins / (2 * mergeNumberBins) + plot.binShift[i] / mergeNumberBins))
217 
218  # error if shift is bigger than limit
219  limit = config.limit[mode]
220  for i in range(3):
221  # skip empty
222  if (plot.histo[i].GetEntries() > 0):
223  if (plot.unit!=""):
224  plot.text.AddText("max. shift {0}: {1:.2} {2}".format(plot.xyz[i], plot.maxShift[i], plot.unit))
225  if (abs(plot.maxShift[i]) > limit):
226  plot.text.AddText("! {0} shift bigger than {1} {2}".format(plot.xyz[i], limit, plot.unit))
227  else:
228  plot.text.AddText("max. shift {0}: {1:.2}".format(plot.xyz[i], plot.maxShift[i]))
229  if (abs(plot.maxShift[i]) > limit):
230  plot.text.AddText("! {0} shift bigger than {1}".format(plot.xyz[i], limit))
231 
232  if (plot.hiddenEntries[i] != 0):
233  plot.text.AddText("! {0}: {1} outlier !".format(
234  plot.xyz[i], int(plot.hiddenEntries[i])))
235 
236  # save copy
237  plots[modeNumber][structNumber] = plot
238 
239  ######################################################################
240  # make the plots
241  #
242 
243  # show the skewness in the legend
244  gStyle.SetOptStat("emrs")
245 
246  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
247  for structNumber, struct in enumerate(alignables.structures):
248  # use a copy for shorter name
249  plot = plots[modeNumber][structNumber]
250 
251  canvas = TCanvas("canvasModules{0}_{1}".format(
252  struct.get_name(), mode), "Parameter", 300, 0, 800, 600)
253  canvas.Divide(2, 2)
254 
255  canvas.cd(1)
256  plot.title.Draw()
257  plot.text.Draw()
258 
259  # draw identification
260  ident = identification(config)
261  ident.Draw()
262 
263  # is there any plot?
264  plotNumber = 0
265 
266  # loop over coordinates
267  for i in range(3):
268  if(plot.histo[i].GetEntries() > 0):
269  plotNumber += 1
270  canvas.cd(i + 2)
271  setstatsize(canvas, plot.histo[i], config)
272  plot.histo[i].DrawCopy()
273 
274  if (plotNumber == 0):
275  break
276 
277  canvas.Update()
278 
279  # save as pdf
280  canvas.Print(
281  "{0}/plots/pdf/modules_{1}_{2}.pdf".format(config.outputPath, mode, struct.get_name()))
282 
283  # export as png
284  image = TImage.Create()
285  image.FromPad(canvas)
286  image.WriteImage(
287  "{0}/plots/png/modules_{1}_{2}.png".format(config.outputPath, mode, struct.get_name()))
288 
289  # add to output list
290  output = OutputData(plottype="mod", name=struct.get_name(),
291  parameter=mode, filename="modules_{0}_{1}".format(mode, struct.get_name()))
292  config.outputList.append(output)
293 
294  ######################################################################
295  # make plots with substructure
296  #
297 
298  if (config.showsubmodule == 1):
299  alignables.create_children_list()
300  for modeNumber, mode in enumerate(["xyz", "rot", "dist"]):
301  for structNumber, struct in enumerate(alignables.structures):
302  # use a copy for shorter name
303  plot = plots[modeNumber][structNumber]
304 
305  subModule.plot(MillePedeUser, alignables,
306  mode, struct, plot, config)
def identification
creates the identification text in the top left corner
Definition: style.py:16
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
def plot
Definition: bigModule.py:19
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def setstatsize
statistics size
Definition: style.py:31
def plot
Definition: subModule.py:18
if(dp >Float(M_PI)) dp-