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),
"", numberOfBins, -1000, 1000))
51 plot.histo.append(TH1F(
"{0} {1} {2}".
format(struct.get_name(), plot.xyz[
52 i], mode),
"", numberOfBins, -0.1, 0.1))
55 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i]+
" ["+plot.unit+
"]")
57 plot.histo[i].SetXTitle(
"#Delta"+plot.xyz[i])
58 plot.histo[i].SetYTitle(
"number of alignables")
59 plot.histo[i].GetXaxis().SetTitleOffset(0.8)
60 plot.histoAxis.append(plot.histo[i].GetXaxis())
63 plot.title = TPaveLabel(
64 0.1, 0.8, 0.9, 0.9,
"Module: {0} {1}".
format(struct.get_name(), mode))
65 plot.text = TPaveText(0.05, 0.1, 0.95, 0.75)
66 plot.text.SetTextAlign(12)
67 plot.text.SetTextSizePixels(20)
70 plots[modeNumber][structNumber] = plot
76 for line
in MillePedeUser:
79 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
80 for structNumber, struct
in enumerate(alignables.structures):
82 plot = plots[modeNumber][structNumber]
85 if (struct.contains_detid(line.Id)):
87 if (
abs(line.Par[plot.data[i]]) != 999999):
91 10000 * line.Par[plot.data[i]])
93 plot.histo[i].
Fill(line.Par[plot.data[i]])
96 plots[modeNumber][structNumber] = plot
102 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
103 for structNumber, struct
in enumerate(alignables.structures):
105 plot = plots[modeNumber][structNumber]
110 if (
abs(numberOfBins / 2 - plot.histo[i].FindFirstBinAbove()) >
abs(plot.histo[i].FindLastBinAbove() - numberOfBins / 2)):
111 plot.maxBinShift[i] =
abs(
112 numberOfBins / 2 - plot.histo[i].FindFirstBinAbove())
114 plot.maxShift[i] = plot.histo[i].GetBinCenter(
115 plot.histo[i].FindFirstBinAbove())
117 plot.maxBinShift[i] =
abs(
118 plot.histo[i].FindLastBinAbove() - numberOfBins / 2)
120 plot.maxShift[i] = plot.histo[i].GetBinCenter(
121 plot.histo[i].FindLastBinAbove())
123 if (
abs(plot.maxBinShift[i]) == numberOfBins / 2 + 1):
124 plot.maxBinShift[i] = 0
129 if (config.rangemode ==
"stddev"):
131 if (plot.histo[i].GetEntries() != 0
and plot.histo[i].GetStdDev() != 0):
134 if (
max(plot.maxShift) / plot.histo[i].GetStdDev() > config.defpeak):
136 binShift = int(plot.histo[i].FindBin(
137 config.widthstddev * plot.histo[i].GetStdDev()) - numberOfBins / 2)
139 binShift =
max(plot.maxBinShift)
142 plot.binShift[i] = binShift
145 if (config.rangemode ==
"all"):
147 plot.binShift[i] = plot.maxBinShift[i]
150 if (config.rangemode ==
"given"):
153 valuelist = config.rangexyzM
155 valuelist = config.rangerotM
157 valuelist = config.rangedistM
159 for value
in valuelist:
161 if (
abs(plot.maxShift[i]) < value):
165 if (
abs(plot.maxShift[i]) > valuelist[-1]):
166 binShift = valuelist[-1]
168 plot.binShift[i] = int(
169 binShift / plot.histo[i].GetBinWidth(1))
172 if (config.samerange == 1):
174 plot.binShift[i] =
max(plot.binShift)
178 plot.usedRange[i] = plot.binShift[i]
183 for j
in range(1, numberOfBins / 2 - plot.binShift[i]):
184 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
186 for j
in range(numberOfBins / 2 + plot.binShift[i], plot.histo[i].GetNbinsX()):
187 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
191 if (plot.histo[i].GetEntries() != 0):
194 mergeNumberBins = plot.binShift[i]
196 if (mergeNumberBins != 0):
198 mergeNumberBins = int(
199 2. * mergeNumberBins / config.numberofbins)
202 if (mergeNumberBins == 0):
204 while (numberOfBins % mergeNumberBins != 0
and mergeNumberBins != 1):
208 plot.histo[i] = plot.histo[i].
Rebin(mergeNumberBins)
209 plot.histoAxis[i] = plot.histo[i].GetXaxis()
214 plot.histoAxis[i].SetRange(int(numberOfBins / (2 * mergeNumberBins) - plot.binShift[
215 i] / mergeNumberBins), int(numberOfBins / (2 * mergeNumberBins) + plot.binShift[i] / mergeNumberBins))
218 limit = config.limit[mode]
221 if (plot.histo[i].GetEntries() > 0):
223 plot.text.AddText(
"max. shift {0}: {1:.2} {2}".
format(plot.xyz[i], plot.maxShift[i], plot.unit))
224 if (
abs(plot.maxShift[i]) > limit):
225 plot.text.AddText(
"! {0} shift bigger than {1} {2}".
format(plot.xyz[i], limit, plot.unit))
227 plot.text.AddText(
"max. shift {0}: {1:.2}".
format(plot.xyz[i], plot.maxShift[i]))
228 if (
abs(plot.maxShift[i]) > limit):
229 plot.text.AddText(
"! {0} shift bigger than {1}".
format(plot.xyz[i], limit))
231 if (plot.hiddenEntries[i] != 0):
232 plot.text.AddText(
"! {0}: {1} outlier !".
format(
233 plot.xyz[i], int(plot.hiddenEntries[i])))
236 plots[modeNumber][structNumber] = plot
243 gStyle.SetOptStat(
"emrs")
245 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
246 for structNumber, struct
in enumerate(alignables.structures):
248 plot = plots[modeNumber][structNumber]
250 canvas = TCanvas(
"canvasModules{0}_{1}".
format(
251 struct.get_name(), mode),
"Parameter", 300, 0, 800, 600)
267 if(plot.histo[i].GetEntries() > 0):
271 plot.histo[i].DrawCopy()
273 if (plotNumber == 0):
280 "{0}/plots/pdf/modules_{1}_{2}.pdf".
format(config.outputPath, mode, struct.get_name()))
283 image = TImage.Create()
284 image.FromPad(canvas)
286 "{0}/plots/png/modules_{1}_{2}.png".
format(config.outputPath, mode, struct.get_name()))
289 output = OutputData(plottype=
"mod", name=struct.get_name(),
290 parameter=mode, filename=
"modules_{0}_{1}".
format(mode, struct.get_name()))
291 config.outputList.append(output)
297 if (config.showsubmodule == 1):
298 alignables.create_children_list()
299 for modeNumber, mode
in enumerate([
"xyz",
"rot",
"dist"]):
300 for structNumber, struct
in enumerate(alignables.structures):
302 plot = plots[modeNumber][structNumber]
305 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