9 ROOT.PyConfig.IgnoreCommandLineOptions =
True 12 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.subModule
as mpsv_subModule
13 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes
as mpsv_classes
14 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style
as mpsv_style
17 def plot(MillePedeUser, alignables, config):
18 logger = logging.getLogger(
"mpsvalidate")
20 alignables.create_list(MillePedeUser)
32 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
35 for structNumber, struct
in enumerate(alignables.structures):
36 plots[modeNumber].
append(mpsv_classes.PlotData(mode))
39 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
40 for structNumber, struct
in enumerate(alignables.structures):
42 plot = plots[modeNumber][structNumber]
46 plot.histo.append(ROOT.TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
47 i], mode),
"", numberOfBins, -1000, 1000))
49 plot.histo.append(ROOT.TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
50 i], mode),
"", numberOfBins, -0.1, 0.1))
53 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i]+
" ["+plot.unit+
"]")
55 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i])
56 plot.histo[i].SetYTitle(
"number of alignables")
57 plot.histo[i].GetXaxis().SetTitleOffset(0.8)
58 plot.histoAxis.append(plot.histo[i].GetXaxis())
61 plot.title = ROOT.TPaveLabel(
62 0.1, 0.8, 0.9, 0.9,
"Module: {0} {1}".
format(struct.get_name(), mode))
63 plot.text = ROOT.TPaveText(0.05, 0.1, 0.95, 0.75)
64 plot.text.SetTextAlign(12)
65 plot.text.SetTextSizePixels(20)
68 plots[modeNumber][structNumber] = plot
74 for line
in MillePedeUser:
77 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
78 for structNumber, struct
in enumerate(alignables.structures):
80 plot = plots[modeNumber][structNumber]
83 if (struct.contains_detid(line.Id)):
85 if (
abs(line.Par[plot.data[i]]) != 999999):
89 10000 * line.Par[plot.data[i]])
91 plot.histo[i].
Fill(line.Par[plot.data[i]])
94 plots[modeNumber][structNumber] = plot
100 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
101 for structNumber, struct
in enumerate(alignables.structures):
103 plot = plots[modeNumber][structNumber]
108 if (
abs(numberOfBins / 2 - plot.histo[i].FindFirstBinAbove()) >
abs(plot.histo[i].FindLastBinAbove() - numberOfBins / 2)):
109 plot.maxBinShift[i] =
abs(
110 numberOfBins / 2 - plot.histo[i].FindFirstBinAbove())
112 plot.maxShift[i] = plot.histo[i].GetBinCenter(
113 plot.histo[i].FindFirstBinAbove())
115 plot.maxBinShift[i] =
abs(
116 plot.histo[i].FindLastBinAbove() - numberOfBins / 2)
118 plot.maxShift[i] = plot.histo[i].GetBinCenter(
119 plot.histo[i].FindLastBinAbove())
121 if (
abs(plot.maxBinShift[i]) == numberOfBins / 2 + 1):
122 plot.maxBinShift[i] = 0
127 if (config.rangemode ==
"stddev"):
129 if (plot.histo[i].GetEntries() != 0
and plot.histo[i].GetStdDev() != 0):
132 if (
max(plot.maxShift) / plot.histo[i].GetStdDev() > config.defpeak):
134 binShift =
int(plot.histo[i].FindBin(
135 config.widthstddev * plot.histo[i].GetStdDev()) - numberOfBins / 2)
137 binShift =
max(plot.maxBinShift)
140 plot.binShift[i] = binShift
143 if (config.rangemode ==
"all"):
145 plot.binShift[i] = plot.maxBinShift[i]
148 if (config.rangemode ==
"given"):
151 valuelist = config.rangexyzM
153 valuelist = config.rangerotM
155 valuelist = config.rangedistM
157 for value
in valuelist:
159 if (
abs(plot.maxShift[i]) < value):
163 if (
abs(plot.maxShift[i]) > valuelist[-1]):
164 binShift = valuelist[-1]
166 plot.binShift[i] =
int(
167 binShift / plot.histo[i].GetBinWidth(1))
170 if (config.samerange == 1):
172 plot.binShift[i] =
max(plot.binShift)
176 plot.usedRange[i] = plot.binShift[i]
181 for j
in range(1, numberOfBins / 2 - plot.binShift[i]):
182 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
184 for j
in range(numberOfBins / 2 + plot.binShift[i], plot.histo[i].GetNbinsX()):
185 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
189 if (plot.histo[i].GetEntries() != 0):
192 mergeNumberBins = plot.binShift[i]
194 if (mergeNumberBins != 0):
196 mergeNumberBins =
int(
197 2. * mergeNumberBins / config.numberofbins)
200 if (mergeNumberBins == 0):
202 while (numberOfBins % mergeNumberBins != 0
and mergeNumberBins != 1):
206 plot.histo[i] = plot.histo[i].
Rebin(mergeNumberBins)
207 plot.histoAxis[i] = plot.histo[i].GetXaxis()
212 plot.histoAxis[i].SetRange(
int(numberOfBins / (2 * mergeNumberBins) - plot.binShift[
213 i] / mergeNumberBins),
int(numberOfBins / (2 * mergeNumberBins) + plot.binShift[i] / mergeNumberBins))
216 limit = config.limit[mode]
219 if (plot.histo[i].GetEntries() > 0):
221 plot.text.AddText(
"max. shift {0}: {1:.2} {2}".
format(plot.xyz[i], plot.maxShift[i], plot.unit))
222 if (
abs(plot.maxShift[i]) > limit):
223 plot.text.AddText(
"! {0} shift bigger than {1} {2}".
format(plot.xyz[i], limit, plot.unit))
225 plot.text.AddText(
"max. shift {0}: {1:.2}".
format(plot.xyz[i], plot.maxShift[i]))
226 if (
abs(plot.maxShift[i]) > limit):
227 plot.text.AddText(
"! {0} shift bigger than {1}".
format(plot.xyz[i], limit))
229 if (plot.hiddenEntries[i] != 0):
230 plot.text.AddText(
"! {0}: {1} outlier !".
format(
231 plot.xyz[i],
int(plot.hiddenEntries[i])))
234 plots[modeNumber][structNumber] = plot
241 ROOT.gStyle.SetOptStat(
"emrs")
243 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
244 for structNumber, struct
in enumerate(alignables.structures):
246 plot = plots[modeNumber][structNumber]
248 canvas = ROOT.TCanvas(
"canvasModules{0}_{1}".
format(
249 struct.get_name(), mode),
"Parameter", 300, 0, 800, 600)
257 ident = mpsv_style.identification(config)
265 if(plot.histo[i].GetEntries() > 0):
268 mpsv_style.setstatsize(canvas, plot.histo[i], config)
269 plot.histo[i].DrawCopy()
271 if (plotNumber == 0):
278 "{0}/plots/pdf/modules_{1}_{2}.pdf".
format(config.outputPath, mode, struct.get_name()))
281 image = ROOT.TImage.Create()
282 image.FromPad(canvas)
284 "{0}/plots/png/modules_{1}_{2}.png".
format(config.outputPath, mode, struct.get_name()))
287 output = mpsv_classes.OutputData(plottype=
"mod", name=struct.get_name(),
288 parameter=mode, filename=
"modules_{0}_{1}".
format(mode, struct.get_name()))
289 config.outputList.append(output)
295 if config.showsubmodule:
296 alignables.create_children_list()
297 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
298 for structNumber, struct
in enumerate(alignables.structures):
300 plot = plots[modeNumber][structNumber]
302 mpsv_subModule.plot(MillePedeUser, alignables,
303 mode, struct, plot, config)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
def plot(MillePedeUser, alignables, config)