CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
bigStructure Namespace Reference

Functions

def plot
 

Function Documentation

def bigStructure.plot (   MillePedeUser,
  alignables,
  config 
)

Definition at line 17 of file bigStructure.py.

References funct.abs(), SiStripPI.max, sistrip::SpyUtilities.range(), and str.

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