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