CMS 3D CMS Logo

bigStructure.py
Go to the documentation of this file.
1 
5 
6 from builtins import range
7 import logging
8 
9 import ROOT
10 ROOT.PyConfig.IgnoreCommandLineOptions = True
11 ROOT.gROOT.SetBatch()
12 
13 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
14 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
15 
16 
17 def plot(MillePedeUser, alignables, config):
18  logger = logging.getLogger("mpsvalidate")
19 
20  # more space for labels
21  ROOT.gStyle.SetPadBottomMargin(0.25)
22  ROOT.gStyle.SetOptStat("emrs")
23 
24  for mode in ["xyz", "rot"]:
25  big = mpsv_classes.PlotData(mode)
26 
27  # count number of needed bins and max shift
28  for line in MillePedeUser:
29  if (line.ObjId != 1):
30  for i in range(3):
31  if (abs(line.Par[big.data[i]]) != 999999):
32  if (mode == "xyz"):
33  line.Par[big.data[i]] *= 10000
34  big.numberOfBins[i] += 1
35  if (abs(line.Par[big.data[i]]) > abs(big.maxShift[i])):
36  big.maxShift[i] = line.Par[big.data[i]]
37 
38  # initialize histograms
39  for i in range(3):
40  big.histo.append(ROOT.TH1F("Big Structure {0} {1}".format(big.xyz[i], mode), "", big.numberOfBins[i], 0, big.numberOfBins[i]))
41  if (big.unit!=""):
42  big.histo[i].SetYTitle("#Delta"+big.xyz[i]+" ["+big.unit+"]")
43  else:
44  big.histo[i].SetYTitle("#Delta"+big.xyz[i])
45  big.histo[i].SetStats(0)
46  big.histo[i].SetMarkerStyle(21)
47  big.histoAxis.append(big.histo[i].GetXaxis())
48  # bigger labels for the text
49  big.histoAxis[i].SetLabelSize(0.06)
50  big.histo[i].GetYaxis().SetTitleOffset(1.6)
51 
52  # add labels
53  big.title = ROOT.TPaveLabel(
54  0.1, 0.8, 0.9, 0.9, "High Level Structures {0}".format(mode))
55  big.text = ROOT.TPaveText(0.05, 0.1, 0.95, 0.75)
56  big.text.SetTextAlign(12)
57 
58  # error if shift is bigger than limit
59  limit = config.limit[mode]
60  for i in range(3):
61  if (big.unit!=""):
62  big.text.AddText("max. shift {0}: {1:.2} {2}".format(big.xyz[i], float(big.maxShift[i]), big.unit))
63  if (abs(big.maxShift[i]) > limit):
64  big.text.AddText("! {0} shift bigger than {1} {2}".format(big.xyz[i], limit, big.unit))
65  else:
66  big.text.AddText("max. shift {0}: {1:.2}".format(big.xyz[i], float(big.maxShift[i])))
67  if (abs(big.maxShift[i]) > limit):
68  big.text.AddText("! {0} shift bigger than {1}".format(big.xyz[i], limit))
69 
70  # fill histograms with value and name
71  for line in MillePedeUser:
72  if (line.ObjId != 1):
73  for i in range(3):
74  if (abs(line.Par[big.data[i]]) != 999999):
75  # set name of the structure
76  big.histoAxis[i].SetBinLabel(
77  big.binPosition[i],
78  str(line.Name) if len(line.Name) <= 13 else str(line.Name)[:12]+".")
79  # fill with data, big.data[i] xyz or rot data
80  # transform xyz data from cm to #mu m
81  if (mode == "xyz"):
82  big.histo[i].SetBinContent(
83  big.binPosition[i], 10000 * line.Par[big.data[i]])
84  else:
85  big.histo[i].SetBinContent(
86  big.binPosition[i], line.Par[big.data[i]])
87  big.binPosition[i] += 1
88 
89  # rotate labels
90  for i in range(3):
91  big.histoAxis[i].LabelsOption("v")
92 
93  # reset y range
94  # two types of ranges
95 
96  # 1. show all
97  if (config.rangemodeHL == "all"):
98  for i in range(3):
99  big.usedRange[i] = big.maxShift[i]
100 
101  # 2. use given values
102  if (config.rangemodeHL == "given"):
103  # loop over coordinates
104  for i in range(3):
105  if (mode == "xyz"):
106  valuelist = config.rangexyzHL
107  if (mode == "rot"):
108  valuelist = config.rangerotHL
109  # loop over given values
110  # without last value
111  for value in valuelist:
112  # maximum smaller than given value
113  if (abs(big.maxShift[i]) < value):
114  big.usedRange[i] = value
115  break
116  # if not possible, force highest
117  if (abs(big.maxShift[i]) > valuelist[-1]):
118  big.usedRange[i] = valuelist[-1]
119 
120  # all the same range
121  if (config.samerangeHL == 1):
122  # apply new range
123  for i in range(3):
124  big.usedRange[i] = max(map(abs, big.usedRange))
125 
126  # count outlieres
127  if (config.rangemodeHL == "given"):
128  for i in range(3):
129  for binNumber in range(1, big.numberOfBins[i] + 1):
130  if (abs(big.histo[i].GetBinContent(binNumber)) > big.usedRange[i]):
131  big.hiddenEntries[i] += 1
132 
133  # add number of outlieres to text
134  for i in range(3):
135  if (big.hiddenEntries[i] != 0):
136  big.text.AddText("! {0}: {1} outlier !".format(
137  big.xyz[i], int(big.hiddenEntries[i])))
138 
139  # create canvas
140  cBig = ROOT.TCanvas("canvasBigStrucutres_{0}".format(
141  mode), "Parameter", 300, 0, 800, 600)
142  cBig.Divide(2, 2)
143 
144  # draw histograms
145  cBig.cd(1)
146  big.title.Draw()
147  big.text.Draw()
148 
149  # draw identification
150  ident = mpsv_style.identification(config)
151  ident.Draw()
152 
153  # TGraph copy to hide outlier
154  copy = 3 * [None]
155 
156  # loop over coordinates
157  for i in range(3):
158  cBig.cd(i + 2)
159  # option "AXIS" to only draw the axis
160  big.histo[i].SetLineColor(0)
161  big.histo[i].Draw("AXIS")
162  # set new range
163  big.histo[i].GetYaxis().SetRangeUser(-1.1 *
164  abs(big.usedRange[i]), 1.1 * abs(big.usedRange[i]))
165 
166  # TGraph object to hide outlier
167  copy[i] = ROOT.TGraph(big.histo[i])
168  # set the new range
169  copy[i].SetMaximum(1.1 * abs(big.usedRange[i]))
170  copy[i].SetMinimum(-1.1 * abs(big.usedRange[i]))
171  # draw the data
172  copy[i].Draw("PSAME")
173 
174  cBig.Update()
175 
176  # save as pdf
177  cBig.Print(
178  "{0}/plots/pdf/structures_{1}.pdf".format(config.outputPath, mode))
179 
180  # export as png
181  image = ROOT.TImage.Create()
182  image.FromPad(cBig)
183  image.WriteImage(
184  "{0}/plots/png/structures_{1}.png".format(config.outputPath, mode))
185 
186  # add to output list
187  output = mpsv_classes.OutputData(plottype="big", parameter=mode,
188  filename="structures_{0}".format(mode))
189  config.outputList.append(output)
190 
191  # reset BottomMargin
192  ROOT.gStyle.SetPadBottomMargin(0.1)
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
str
#define str(s)
Definition: TestProcessor.cc:52
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
bigStructure.plot
def plot(MillePedeUser, alignables, config)
Definition: bigStructure.py:17
format
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
genParticles_cff.map
map
Definition: genParticles_cff.py:11