11 from ROOT
import (TH1F, TCanvas, TGraph, TImage, TLegend, TPaveLabel,
12 TPaveText, TTree, gROOT, gStyle)
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
19 def plot(treeFile, alignables, config):
20 logger = logging.getLogger(
"mpsvalidate")
22 for mode
in [
"xyz",
"rot"]:
27 listMillePedeUser = []
29 for i
in range(config.firsttree, 101):
30 if (treeFile.GetListOfKeys().Contains(
"MillePedeUser_{0}".
format(i))):
31 listMillePedeUser.append(i)
34 for i
in listMillePedeUser:
35 MillePedeUser.append(treeFile.Get(
"MillePedeUser_{0}".
format(i)))
44 newlistMillePedeUser = []
46 for line
in MillePedeUser[0]:
47 if (line.ObjId != 1
and any(
abs(line.Par[time.data[i]]) != 999999
for i
in [0, 1, 2])):
49 newlistMillePedeUser.append(config.firsttree)
53 for ttreeNumber, ttree
in enumerate(MillePedeUser[1:]):
55 if (line.Id == first):
56 if (
any(
abs(line.Par[time.data[i]]) != 999999
for i
in [0, 1, 2])):
58 newlistMillePedeUser.append(
59 ttreeNumber + config.firsttree + 1)
62 listMillePedeUser = newlistMillePedeUser
66 for i
in listMillePedeUser:
67 MillePedeUser.append(treeFile.Get(
"MillePedeUser_{0}".
format(i)))
69 if not listMillePedeUser:
70 logger.error(
"Timeplots: no TTrees found")
74 logger.error(
"Timeplots: no TTree could be opened")
86 for line
in MillePedeUser[0]:
87 if (line.ObjId != 1
and any(
abs(line.Par[time.data[i]]) != 999999
for i
in [0, 1, 2])):
88 plots.append(PlotData(mode))
91 if (line.ObjId
not in objids):
92 objids.append(line.ObjId)
96 plots[-1].histo.append(TH1F(
"Time Structure {0} {1} {2} {3}".
format(mode, alignables.get_name_by_objid(
97 line.ObjId), len(plots), i),
"", len(listMillePedeUser), 0, len(listMillePedeUser)))
98 plots[-1].label = line.Id
99 plots[-1].objid = line.ObjId
102 plots[-1].histo[i].SetYTitle(
"#Delta"+time.xyz[i]+
" ["+time.unit+
"]")
104 plots[-1].histo[i].SetYTitle(
"#Delta"+time.xyz[i])
105 plots[-1].histo[i].SetXTitle(
"IOV")
106 plots[-1].histo[i].SetStats(0)
107 plots[-1].histo[i].SetMarkerStyle(21)
109 plots[-1].histo[i].GetXaxis().SetLabelSize(0.08)
110 plots[-1].histo[i].GetYaxis().SetTitleOffset(1.6)
117 for treeNumber, tree
in enumerate(MillePedeUser):
119 if (line.ObjId != 1
and any(
abs(line.Par[time.data[i]]) != 999999
for i
in [0, 1, 2])):
122 if (plot.label == line.Id):
125 plot.histo[i].GetXaxis().SetBinLabel(
126 treeNumber + 1, str(listMillePedeUser[treeNumber]))
129 plot.histo[i].SetBinContent(
130 treeNumber + 1, 10000 * line.Par[plot.data[i]])
132 plot.histo[i].SetBinContent(
133 treeNumber + 1, line.Par[plot.data[i]])
139 maximum = [[0, 0, 0]
for x
in range(len(objids))]
140 minimum = [[0, 0, 0]
for x
in range(len(objids))]
142 for index, objid
in enumerate(objids):
144 if (plot.objid == objid):
147 if (plot.histo[i].GetMaximum() > maximum[index][i]):
148 maximum[index][i] = plot.histo[i].GetMaximum()
150 if (plot.histo[i].GetMinimum() < minimum[index][i]):
151 minimum[index][i] = plot.histo[i].GetMinimum()
158 for index, objid
in enumerate(objids):
160 canvas = TCanvas(
"canvasTimeBigStrucutres_{0}_{1}".
format(
161 mode, alignables.get_name_by_objid(objid)),
"Parameter", 300, 0, 800, 600)
165 title = TPaveLabel(0.1, 0.8, 0.9, 0.9,
"{0} over time {1}".
format(
166 alignables.get_name_by_objid(objid), mode))
168 legend = TLegend(0.05, 0.1, 0.95, 0.75)
185 if (plot.objid == objid):
187 if (config.rangemodeHL ==
"all"):
188 plot.usedRange[i] =
max(
189 abs(maximum[index][i]),
abs(minimum[index][i]))
192 if (config.rangemodeHL ==
"given"):
195 valuelist = config.rangexyzHL
197 valuelist = config.rangerotHL
200 for value
in valuelist:
202 if (
max(
abs(maximum[index][i]),
abs(minimum[index][i])) < value):
203 plot.usedRange[i] = value
206 if (
max(
abs(maximum[index][i]),
abs(minimum[index][i])) > valuelist[-1]):
207 plot.usedRange[i] = valuelist[-1]
216 if (plot.objid == objid):
218 if (config.samerangeHL == 1):
219 plot.usedRange[i] =
max(map(abs, plot.usedRange))
222 plot.histo[i].GetYaxis(
223 ).SetRangeUser(-1.2 *
abs(plot.usedRange[i]), 1.2 *
abs(plot.usedRange[i]))
225 plot.histo[i].SetLineColorAlpha(number + 2, 0.5)
226 plot.histo[i].SetMarkerColorAlpha(number + 2, 1)
229 plot.histo[i].SetLineColor(0)
230 plot.histo[i].Draw(
"PSAME")
233 copy.append(TGraph(plot.histo[i]))
235 copy[-1].SetMaximum(1.2 *
abs(plot.usedRange[i]))
236 copy[-1].SetMinimum(-1.2 *
abs(plot.usedRange[i]))
238 copy[-1].SetLineColorAlpha(number + 2, 0.5)
239 copy[-1].Draw(
"LPSAME")
243 plot.histo[i],
"{0}".
format(number))
252 canvas.Print(
"{0}/plots/pdf/timeStructures_{1}_{2}.pdf".
format(
253 config.outputPath, mode, alignables.get_name_by_objid(objid)))
256 image = TImage.Create()
257 image.FromPad(canvas)
258 image.WriteImage(
"{0}/plots/png/timeStructures_{1}_{2}.png".
format(
259 config.outputPath, mode, alignables.get_name_by_objid(objid)))
262 output = OutputData(plottype=
"time", name=alignables.get_name_by_objid(
263 objid), parameter=mode, filename=
"timeStructures_{0}_{1}".
format(mode, alignables.get_name_by_objid(objid)))
264 config.outputList.append(output)
def identification
creates the identification text in the top left corner
bool any(const std::vector< T > &v, const T &what)
Abs< T >::type abs(const T &t)