10 from ROOT
import (TH1F, TCanvas, TImage, TPaveLabel, TPaveText, TTree, gROOT,
13 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate
import subModule
14 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes
import PedeDumpData, OutputData, PlotData
15 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry
import Alignables, Structure
16 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style
import identification, setstatsize
19 def plot(MillePedeUser, alignables, config):
20 logger = logging.getLogger(
"mpsvalidate")
22 alignables.create_list(MillePedeUser)
34 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
37 for structNumber, struct
in enumerate(alignables.structures):
38 plots[modeNumber].
append(PlotData(mode))
41 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
42 for structNumber, struct
in enumerate(alignables.structures):
44 plot = plots[modeNumber][structNumber]
48 plot.histo.append(TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
49 i], mode),
"Parameter {0}".
format(plot.xyz[i]), numberOfBins, -1000, 1000))
51 plot.histo.append(TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
52 i], mode),
"Parameter {0}".
format(plot.xyz[i]), numberOfBins, -0.1, 0.1))
54 plot.histo[i].SetXTitle(plot.unit)
55 plot.histo[i].GetXaxis().SetTitleOffset(0.85)
56 plot.histoAxis.append(plot.histo[i].GetXaxis())
59 plot.title = TPaveLabel(
60 0.1, 0.8, 0.9, 0.9,
"Module: {0} {1}".
format(struct.get_name(), mode))
61 plot.text = TPaveText(0.05, 0.1, 0.95, 0.75)
62 plot.text.SetTextAlign(12)
63 plot.text.SetTextSizePixels(20)
66 plots[modeNumber][structNumber] = plot
72 for line
in MillePedeUser:
75 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
76 for structNumber, struct
in enumerate(alignables.structures):
78 plot = plots[modeNumber][structNumber]
81 if (struct.contains_detid(line.Id)):
83 if (
abs(line.Par[plot.data[i]]) != 999999):
87 10000 * line.Par[plot.data[i]])
89 plot.histo[i].
Fill(line.Par[plot.data[i]])
92 plots[modeNumber][structNumber] = plot
98 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
99 for structNumber, struct
in enumerate(alignables.structures):
101 plot = plots[modeNumber][structNumber]
106 if (
abs(numberOfBins / 2 - plot.histo[i].FindFirstBinAbove()) >
abs(plot.histo[i].FindLastBinAbove() - numberOfBins / 2)):
107 plot.maxBinShift[i] =
abs(
108 numberOfBins / 2 - plot.histo[i].FindFirstBinAbove())
110 plot.maxShift[i] = plot.histo[i].GetBinCenter(
111 plot.histo[i].FindFirstBinAbove())
113 plot.maxBinShift[i] =
abs(
114 plot.histo[i].FindLastBinAbove() - numberOfBins / 2)
116 plot.maxShift[i] = plot.histo[i].GetBinCenter(
117 plot.histo[i].FindLastBinAbove())
119 if (
abs(plot.maxBinShift[i]) == numberOfBins / 2 + 1):
120 plot.maxBinShift[i] = 0
125 if (config.rangemode ==
"stddev"):
127 if (plot.histo[i].GetEntries() != 0
and plot.histo[i].GetStdDev() != 0):
130 if (
max(plot.maxShift) / plot.histo[i].GetStdDev() > config.defpeak):
132 binShift = int(plot.histo[i].FindBin(
133 config.widthstddev * plot.histo[i].GetStdDev()) - numberOfBins / 2)
135 binShift =
max(plot.maxBinShift)
138 plot.binShift[i] = binShift
141 if (config.rangemode ==
"all"):
143 plot.binShift[i] = plot.maxBinShift[i]
146 if (config.rangemode ==
"given"):
149 valuelist = config.rangexyzM
151 valuelist = config.rangerotM
153 valuelist = config.rangedistM
155 for value
in valuelist:
157 if (
abs(plot.maxShift[i]) < value):
161 if (
abs(plot.maxShift[i]) > valuelist[-1]):
162 binShift = valuelist[-1]
164 plot.binShift[i] = int(
165 binShift / plot.histo[i].GetBinWidth(1))
168 if (config.samerange == 1):
170 plot.binShift[i] =
max(plot.binShift)
174 plot.usedRange[i] = plot.binShift[i]
179 for j
in range(1, numberOfBins / 2 - plot.binShift[i]):
180 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
182 for j
in range(numberOfBins / 2 + plot.binShift[i], plot.histo[i].GetNbinsX()):
183 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
187 if (plot.histo[i].GetEntries() != 0):
190 mergeNumberBins = plot.binShift[i]
192 if (mergeNumberBins != 0):
194 mergeNumberBins = int(
195 2. * mergeNumberBins / config.numberofbins)
198 if (mergeNumberBins == 0):
200 while (numberOfBins % mergeNumberBins != 0
and mergeNumberBins != 1):
204 plot.histo[i] = plot.histo[i].
Rebin(mergeNumberBins)
205 plot.histoAxis[i] = plot.histo[i].GetXaxis()
210 plot.histoAxis[i].SetRange(int(numberOfBins / (2 * mergeNumberBins) - plot.binShift[
211 i] / mergeNumberBins), int(numberOfBins / (2 * mergeNumberBins) + plot.binShift[i] / mergeNumberBins))
214 limit = config.limit[mode]
217 if (plot.histo[i].GetEntries() > 0):
218 plot.text.AddText(
"max. shift {0}: {1:.2}".
format(
219 plot.xyz[i], plot.maxShift[i]))
220 if (
abs(plot.maxShift[i]) > limit):
222 "! {0} shift bigger than {1} !".
format(plot.xyz[i], limit))
223 if (plot.hiddenEntries[i] != 0):
224 plot.text.AddText(
"! {0} {1} outlier !".
format(
225 plot.xyz[i], int(plot.hiddenEntries[i])))
228 plots[modeNumber][structNumber] = plot
235 gStyle.SetOptStat(
"emrs")
237 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
238 for structNumber, struct
in enumerate(alignables.structures):
240 plot = plots[modeNumber][structNumber]
242 canvas = TCanvas(
"canvasModules{0}_{1}".
format(
243 struct.get_name(), mode),
"Parameter", 300, 0, 800, 600)
259 if(plot.histo[i].GetEntries() > 0):
263 plot.histo[i].DrawCopy()
265 if (plotNumber == 0):
272 "{0}/plots/pdf/modules_{1}_{2}.pdf".
format(config.outputPath, mode, struct.get_name()))
275 image = TImage.Create()
276 image.FromPad(canvas)
278 "{0}/plots/png/modules_{1}_{2}.png".
format(config.outputPath, mode, struct.get_name()))
281 output = OutputData(plottype=
"mod", name=struct.get_name(),
282 parameter=mode, filename=
"modules_{0}_{1}".
format(mode, struct.get_name()))
283 config.outputList.append(output)
289 if (config.showsubmodule == 1):
290 alignables.create_children_list()
291 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
292 for structNumber, struct
in enumerate(alignables.structures):
294 plot = plots[modeNumber][structNumber]
297 mode, struct, plot, config)
def identification
creates the identification text in the top left corner
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 ...
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Abs< T >::type abs(const T &t)
def setstatsize
statistics size