18 def plot(MillePedeUser, alignables, config):
19 logger = logging.getLogger(
"mpsvalidate")
21 alignables.create_list(MillePedeUser)
33 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
36 for structNumber, struct
in enumerate(alignables.structures):
37 plots[modeNumber].
append(mpsv_classes.PlotData(mode))
40 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
41 for structNumber, struct
in enumerate(alignables.structures):
43 plot = plots[modeNumber][structNumber]
47 plot.histo.append(ROOT.TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
48 i], mode),
"", numberOfBins, -1000, 1000))
50 plot.histo.append(ROOT.TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
51 i], mode),
"", numberOfBins, -0.1, 0.1))
54 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i]+
" ["+plot.unit+
"]")
56 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i])
57 plot.histo[i].SetYTitle(
"number of alignables")
58 plot.histo[i].GetXaxis().SetTitleOffset(0.8)
59 plot.histoAxis.append(plot.histo[i].GetXaxis())
62 plot.title = ROOT.TPaveLabel(
63 0.1, 0.8, 0.9, 0.9,
"Module: {0} {1}".
format(struct.get_name(), mode))
64 plot.text = ROOT.TPaveText(0.05, 0.1, 0.95, 0.75)
65 plot.text.SetTextAlign(12)
66 plot.text.SetTextSizePixels(20)
69 plots[modeNumber][structNumber] = plot
75 for line
in MillePedeUser:
78 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
79 for structNumber, struct
in enumerate(alignables.structures):
81 plot = plots[modeNumber][structNumber]
84 if (struct.contains_detid(line.Id)):
86 if (
abs(line.Par[plot.data[i]]) != 999999):
90 10000 * line.Par[plot.data[i]])
92 plot.histo[i].
Fill(line.Par[plot.data[i]])
95 plots[modeNumber][structNumber] = plot
101 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
102 for structNumber, struct
in enumerate(alignables.structures):
104 plot = plots[modeNumber][structNumber]
109 if (
abs(numberOfBins // 2 - plot.histo[i].FindFirstBinAbove()) >
abs(plot.histo[i].FindLastBinAbove() - numberOfBins // 2)):
110 plot.maxBinShift[i] =
abs(
111 numberOfBins // 2 - plot.histo[i].FindFirstBinAbove())
113 plot.maxShift[i] = plot.histo[i].GetBinCenter(
114 plot.histo[i].FindFirstBinAbove())
116 plot.maxBinShift[i] =
abs(
117 plot.histo[i].FindLastBinAbove() - numberOfBins // 2)
119 plot.maxShift[i] = plot.histo[i].GetBinCenter(
120 plot.histo[i].FindLastBinAbove())
122 if (
abs(plot.maxBinShift[i]) == numberOfBins // 2 + 1):
123 plot.maxBinShift[i] = 0
128 if (config.rangemode ==
"stddev"):
130 if (plot.histo[i].GetEntries() != 0
and plot.histo[i].GetStdDev() != 0):
133 if (
max(plot.maxShift) / plot.histo[i].GetStdDev() > config.defpeak):
135 binShift =
int(plot.histo[i].FindBin(
136 config.widthstddev * plot.histo[i].GetStdDev()) - numberOfBins / 2)
138 binShift =
max(plot.maxBinShift)
141 plot.binShift[i] = binShift
144 if (config.rangemode ==
"all"):
146 plot.binShift[i] = plot.maxBinShift[i]
149 if (config.rangemode ==
"given"):
152 valuelist = config.rangexyzM
154 valuelist = config.rangerotM
156 valuelist = config.rangedistM
158 for value
in valuelist:
160 if (
abs(plot.maxShift[i]) < value):
164 if (
abs(plot.maxShift[i]) > valuelist[-1]):
165 binShift = valuelist[-1]
167 plot.binShift[i] =
int(
168 binShift / plot.histo[i].GetBinWidth(1))
171 if (config.samerange == 1):
173 plot.binShift[i] =
max(plot.binShift)
177 plot.usedRange[i] = plot.binShift[i]
182 for j
in range(1, numberOfBins // 2 - plot.binShift[i]):
183 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
185 for j
in range(numberOfBins // 2 + plot.binShift[i], plot.histo[i].GetNbinsX()):
186 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
190 if (plot.histo[i].GetEntries() != 0):
193 mergeNumberBins = plot.binShift[i]
195 if (mergeNumberBins != 0):
197 mergeNumberBins =
int(
198 2. * mergeNumberBins / config.numberofbins)
201 if (mergeNumberBins == 0):
203 while (numberOfBins % mergeNumberBins != 0
and mergeNumberBins != 1):
207 plot.histo[i] = plot.histo[i].
Rebin(mergeNumberBins)
208 plot.histoAxis[i] = plot.histo[i].GetXaxis()
213 plot.histoAxis[i].SetRange(
int(numberOfBins / (2 * mergeNumberBins) - plot.binShift[
214 i] / mergeNumberBins),
int(numberOfBins / (2 * mergeNumberBins) + plot.binShift[i] / mergeNumberBins))
217 limit = config.limit[mode]
220 if (plot.histo[i].GetEntries() > 0):
222 plot.text.AddText(
"max. shift {0}: {1:.2} {2}".
format(plot.xyz[i], plot.maxShift[i], plot.unit))
223 if (
abs(plot.maxShift[i]) > limit):
224 plot.text.AddText(
"! {0} shift bigger than {1} {2}".
format(plot.xyz[i], limit, plot.unit))
226 plot.text.AddText(
"max. shift {0}: {1:.2}".
format(plot.xyz[i], plot.maxShift[i]))
227 if (
abs(plot.maxShift[i]) > limit):
228 plot.text.AddText(
"! {0} shift bigger than {1}".
format(plot.xyz[i], limit))
230 if (plot.hiddenEntries[i] != 0):
231 plot.text.AddText(
"! {0}: {1} outlier !".
format(
232 plot.xyz[i],
int(plot.hiddenEntries[i])))
235 plots[modeNumber][structNumber] = plot
242 ROOT.gStyle.SetOptStat(
"emrs")
244 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
245 for structNumber, struct
in enumerate(alignables.structures):
247 plot = plots[modeNumber][structNumber]
249 canvas = ROOT.TCanvas(
"canvasModules{0}_{1}".
format(
250 struct.get_name(), mode),
"Parameter", 300, 0, 800, 600)
258 ident = mpsv_style.identification(config)
266 if(plot.histo[i].GetEntries() > 0):
269 mpsv_style.setstatsize(canvas, plot.histo[i], config)
270 plot.histo[i].DrawCopy()
272 if (plotNumber == 0):
279 "{0}/plots/pdf/modules_{1}_{2}.pdf".
format(config.outputPath, mode, struct.get_name()))
282 image = ROOT.TImage.Create()
283 image.FromPad(canvas)
285 "{0}/plots/png/modules_{1}_{2}.png".
format(config.outputPath, mode, struct.get_name()))
288 output = mpsv_classes.OutputData(plottype=
"mod", name=struct.get_name(),
289 parameter=mode, filename=
"modules_{0}_{1}".
format(mode, struct.get_name()))
290 config.outputList.append(output)
296 if config.showsubmodule:
297 alignables.create_children_list()
298 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
299 for structNumber, struct
in enumerate(alignables.structures):
301 plot = plots[modeNumber][structNumber]
303 mpsv_subModule.plot(MillePedeUser, alignables,
304 mode, struct, plot, config)
305
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
def plot(MillePedeUser, alignables, config)