File indexing completed on 2024-04-06 11:56:35
0001
0002
0003
0004
0005
0006
0007 from builtins import range
0008 import logging
0009
0010 import ROOT
0011 ROOT.PyConfig.IgnoreCommandLineOptions = True
0012 ROOT.gROOT.SetBatch()
0013
0014 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
0015 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
0016
0017
0018 def plot(MillePedeUser, alignables, mode, struct, parentPlot, config):
0019 logger = logging.getLogger("mpsvalidate")
0020
0021
0022 number = 0
0023 for i in range(3):
0024 if(parentPlot.histo[i].GetEntries() == 0):
0025 number += 1
0026 if (number == 3):
0027 return
0028
0029
0030 numberOfBins = 10000
0031
0032
0033
0034
0035
0036
0037 plots = []
0038
0039
0040 for subStructNumber, subStruct in enumerate(struct.get_children()):
0041 plots.append(mpsv_classes.PlotData(mode))
0042
0043
0044 plot = plots[subStructNumber]
0045
0046 for i in range(3):
0047 if (mode == "xyz"):
0048 plot.histo.append(ROOT.TH1F("{0} {1} {2}".format(struct.get_name() + " " + subStruct.get_name(), plot.xyz[
0049 i], mode), "Parameter {0}".format(plot.xyz[i]), numberOfBins, -1000, 1000))
0050 else:
0051 plot.histo.append(ROOT.TH1F("{0} {1} {2}".format(struct.get_name() + " " + subStruct.get_name(), plot.xyz[
0052 i], mode), "Parameter {0}".format(plot.xyz[i]), numberOfBins, -0.1, 0.1))
0053
0054 plot.histo[i].SetLineColor(6)
0055 plot.histo[i].SetStats(0)
0056
0057
0058 plot.title = ROOT.TPaveLabel(
0059 0.1, 0.8, 0.9, 0.9, "Module: {0} {1}".format(struct.get_name(), mode))
0060 plot.text = ROOT.TPaveText(0.05, 0.1, 0.95, 0.75)
0061 plot.text.SetTextAlign(12)
0062 plot.text.SetTextSizePixels(20)
0063
0064
0065 plots[subStructNumber] = plot
0066
0067
0068
0069
0070
0071 for line in MillePedeUser:
0072
0073 if (line.ObjId == 1):
0074 for subStructNumber, subStruct in enumerate(struct.get_children()):
0075
0076 plot = plots[subStructNumber]
0077
0078
0079 if (subStruct.contains_detid(line.Id)):
0080 for i in range(3):
0081 if (abs(line.Par[plot.data[i]]) != 999999):
0082
0083 if (mode == "xyz"):
0084 plot.histo[i].Fill(
0085 10000 * line.Par[plot.data[i]])
0086 else:
0087 plot.histo[i].Fill(line.Par[plot.data[i]])
0088
0089
0090 plots[subStructNumber] = plot
0091
0092
0093
0094
0095 for subStructNumber, subStruct in enumerate(struct.get_children()):
0096
0097 plot = plots[subStructNumber]
0098 for i in range(3):
0099 if (plot.histo[i].GetEntries() != 0 and plot.histo[i].GetStdDev() != 0):
0100
0101 binShift = parentPlot.usedRange[i]
0102
0103
0104
0105 for j in range(1, numberOfBins // 2 - binShift):
0106 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
0107
0108 for j in range(numberOfBins // 2 + binShift, plot.histo[i].GetNbinsX()):
0109 plot.hiddenEntries[i] += plot.histo[i].GetBinContent(j)
0110
0111
0112 mergeNumberBins = binShift
0113
0114 if (mergeNumberBins != 0):
0115
0116 mergeNumberBins = int(
0117 2. * mergeNumberBins / config.numberofbins)
0118
0119
0120 if (mergeNumberBins == 0):
0121 mergeNumberBins = 1
0122 while (numberOfBins % mergeNumberBins != 0 and mergeNumberBins != 1):
0123 mergeNumberBins -= 1
0124
0125
0126 plot.histo[i] = plot.histo[i].Rebin(mergeNumberBins)
0127
0128
0129
0130
0131 plot.histo[i].GetXaxis().SetRange(int(numberOfBins // (2 * mergeNumberBins) - binShift /
0132 mergeNumberBins), int(numberOfBins // (2 * mergeNumberBins) + binShift / mergeNumberBins))
0133
0134
0135 plots[subStructNumber] = plot
0136
0137
0138
0139
0140
0141 canvas = ROOT.TCanvas("SubStruct_{0}_{1}".format(
0142 struct.get_name(), mode), "Parameter", 300, 0, 800, 600)
0143 canvas.Divide(2, 2)
0144
0145 canvas.cd(1)
0146 parentPlot.title.Draw()
0147
0148 legend = ROOT.TLegend(0.05, 0.1, 0.95, 0.75)
0149
0150 for i in range(3):
0151 canvas.cd(i + 2)
0152
0153
0154 maximum = []
0155
0156 if (parentPlot.histo[i].GetEntries() == 0):
0157 continue
0158
0159
0160 parentPlot.histo[i].Scale(1. / parentPlot.histo[i].Integral())
0161 maximum.append(parentPlot.histo[i].GetMaximum())
0162
0163 for subStructNumber, subStruct in enumerate(struct.get_children()):
0164
0165 plot = plots[subStructNumber]
0166
0167 if (plot.histo[i].GetEntries() > 0):
0168 plot.histo[i].Scale(1. / plot.histo[i].Integral())
0169 maximum.append(plot.histo[i].GetMaximum())
0170
0171
0172 plots[subStructNumber] = plot
0173
0174
0175 parentPlot.histo[i].GetYaxis().SetRangeUser(0., 1.1 * max(maximum))
0176 parentPlot.histo[i].SetYTitle("normalized")
0177 parentPlot.histo[i].Draw()
0178
0179 for subStructNumber, subStruct in enumerate(struct.get_children()):
0180
0181 plot = plots[subStructNumber].histo[i]
0182
0183 plot.SetLineColorAlpha(subStructNumber + 2, 0.5)
0184 plot.Draw("same")
0185 if (i == 0):
0186 legend.AddEntry(plot, subStruct.get_name(), "l")
0187
0188 canvas.cd(1)
0189
0190 legend.Draw()
0191
0192 ident = mpsv_style.identification(config)
0193 ident.Draw()
0194
0195 canvas.Update()
0196
0197
0198 canvas.Print(
0199 "{0}/plots/pdf/subModules_{1}_{2}.pdf".format(config.outputPath, mode, struct.get_name()))
0200
0201
0202 image = ROOT.TImage.Create()
0203 image.FromPad(canvas)
0204 image.WriteImage(
0205 "{0}/plots/png/subModules_{1}_{2}.png".format(config.outputPath, mode, struct.get_name()))
0206
0207
0208 output = mpsv_classes.OutputData(plottype="subMod", name=struct.get_name(), number=subStructNumber + 1,
0209 parameter=mode, filename="subModules_{0}_{1}".format(mode, struct.get_name()))
0210 config.outputList.append(output)