test
CMS 3D CMS Logo

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

Functions

def plot
 

Function Documentation

def bigStructure.plot (   MillePedeUser,
  alignables,
  config 
)

Definition at line 18 of file bigStructure.py.

References funct.abs(), style.identification(), and bookConverter.max.

Referenced by mps_validate.main().

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