CMS 3D CMS Logo

Functions | Variables
compare Namespace Reference

Functions

def ensureDir (directory)
 
def hoverlay (hists, xtitle, ytitle, name)
 
def LegendSettings (leg, ncolumn)
 
def makeCompareVars (tree, var, sel, leglist, nbin, xmin, xmax, xtitle, ytitle, scale, name)
 
def makeEffPlotsVars (tree, varx, vary, sel, nbinx, xmin, xmax, nbiny, ymin, ymax, xtitle, ytitle, leglabel=None, header='', addon='', option='pt', marker=20)
 
def overlay (hists, ytitle, header, addon)
 
def save (canvas, name)
 

Variables

 argc
 
 argvs
 
 den_sel
 
 hist
 
 hists
 
 hvardict
 
 loose_id
 
 num_sel
 
 reco_cut
 
 runtype
 
 sampledict
 
 tfile
 
 tlabel
 
 tree
 
 vardict
 
 xlabel
 

Function Documentation

def compare.ensureDir (   directory)

Definition at line 40 of file compare.py.

Referenced by save().

40 def ensureDir(directory):
41  if not os.path.exists(directory):
42  os.makedirs(directory)
43 
def ensureDir(directory)
Definition: compare.py:40
def compare.hoverlay (   hists,
  xtitle,
  ytitle,
  name 
)

Definition at line 192 of file compare.py.

References LegendSettings(), and save().

192 def hoverlay(hists, xtitle, ytitle, name):
193 
194  c = TCanvas()
195 
196  ymax = 0
197  for hist in hists:
198  if ymax < hist.GetMaximum():
199  ymax = hist.GetMaximum()
200 
201 
202  leg = TLegend(0.6,0.65,0.91,0.9)
203  LegendSettings(leg,1)
204 
205  for ii, ihist in enumerate(hists):
206  ihist.SetMaximum(ymax*1.2)
207  ihist.SetMinimum(0.)
208  ihist.SetMarkerSize(0.)
209  ihist.GetXaxis().SetTitle(xtitle)
210  ihist.GetYaxis().SetTitle(ytitle)
211 
212  if ii ==0:
213  ihist.Draw('h')
214  else:
215  ihist.Draw('hsame')
216 
217  leg.AddEntry(ihist, ihist.GetName(), "l")
218 
219 
220  leg.Draw()
221 
222 
223  save(c, 'compare_' + runtype + '/hist_' + name)
224 
225 
226 
227 
def save(canvas, name)
Definition: compare.py:44
def LegendSettings(leg, ncolumn)
Definition: compare.py:50
def hoverlay(hists, xtitle, ytitle, name)
Definition: compare.py:192
def compare.LegendSettings (   leg,
  ncolumn 
)

Definition at line 50 of file compare.py.

Referenced by hoverlay(), makeCompareVars(), and overlay().

50 def LegendSettings(leg, ncolumn):
51  leg.SetNColumns(ncolumn)
52  leg.SetBorderSize(0)
53  leg.SetFillColor(10)
54  leg.SetLineColor(0)
55  leg.SetFillStyle(0)
56  leg.SetTextSize(0.03)
57  leg.SetTextFont(42)
58 
59 
60 
def LegendSettings(leg, ncolumn)
Definition: compare.py:50
def compare.makeCompareVars (   tree,
  var,
  sel,
  leglist,
  nbin,
  xmin,
  xmax,
  xtitle,
  ytitle,
  scale,
  name 
)

Definition at line 61 of file compare.py.

References LegendSettings(), and harvestTrackValidationPlots.str.

61 def makeCompareVars(tree, var, sel, leglist, nbin, xmin, xmax, xtitle, ytitle, scale, name):
62 
63 # print leglist
64 
65  c = TCanvas()
66 
67  hists = []
68  col = [1,2,4,8,6]
69  ymax = 0
70 
71  for ii, isel in enumerate(sel):
72  hist = TH1F('h_' + str(ii), 'h_' + str(ii), nbin, xmin, xmax)
73  hist.GetXaxis().SetTitle(xtitle)
74  hist.GetYaxis().SetTitle(ytitle)
75  hist.GetYaxis().SetNdivisions(507)
76  hist.SetLineColor(col[ii])
77  hist.SetLineWidth(len(sel)+1-ii)
78  hist.SetLineStyle(1)
79  hist.SetMarkerSize(0)
80  hist.SetMinimum(0)
81  hist.Sumw2()
82 
83 # print hist.GetName(), var, isel
84  tree.Project(hist.GetName(), var, isel)
85  hist.Scale(1./hist.GetEntries())
86 
87  if ymax < hist.GetMaximum():
88  ymax = hist.GetMaximum()
89 
90  hists.append(hist)
91 
92 
93  leg = TLegend(0.6,0.65,0.91,0.9)
94  LegendSettings(leg,1)
95 
96  for ii, ihist in enumerate(hists):
97  ihist.SetMaximum(ymax*1.2)
98  ihist.SetMinimum(0.)
99 
100  if ii ==0:
101  ihist.Draw('h')
102  else:
103  ihist.Draw('hsame')
104 
105  if leglist[ii] != 'None':
106  leg.AddEntry(ihist, leglist[ii], "l")
107 
108 
109  if leglist[0]!='None':
110  leg.Draw()
111 
112 
113 # save(c, 'compare_' + runtype + '/compare_' + name)
114 
115 
116 
117 
118 
def LegendSettings(leg, ncolumn)
Definition: compare.py:50
def makeCompareVars(tree, var, sel, leglist, nbin, xmin, xmax, xtitle, ytitle, scale, name)
Definition: compare.py:61
def compare.makeEffPlotsVars (   tree,
  varx,
  vary,
  sel,
  nbinx,
  xmin,
  xmax,
  nbiny,
  ymin,
  ymax,
  xtitle,
  ytitle,
  leglabel = None,
  header = '',
  addon = '',
  option = 'pt',
  marker = 20 
)

Definition at line 228 of file compare.py.

References mps_check.array.

228 def makeEffPlotsVars(tree, varx, vary, sel, nbinx, xmin, xmax, nbiny, ymin, ymax, xtitle, ytitle, leglabel = None, header='', addon='', option='pt', marker=20):
229 
230  binning = [20,30,40,50,60,70,80,100,150,200]
231 
232  c = TCanvas()
233 
234  if option=='pt':
235  _hist_ = TH1F('h_effp_' + addon, 'h_effp' + addon, len(binning)-1, array('d',binning))
236  _ahist_ = TH1F('ah_effp_' + addon, 'ah_effp' + addon, len(binning)-1, array('d',binning))
237  elif option=='eta':
238  _hist_ = TH1F('h_effp_' + addon, 'h_effp' + addon, nbinx, xmin, xmax)
239  _ahist_ = TH1F('ah_effp_' + addon, 'ah_effp' + addon, nbinx, xmin, xmax)
240  elif option=='nvtx':
241  _hist_ = TH1F('h_effp_' + addon, 'h_effp' + addon, len(vbinning)-1, array('d',vbinning))
242  _ahist_ = TH1F('ah_effp_' + addon, 'ah_effp' + addon, len(vbinning)-1, array('d',vbinning))
243 
244 
245  tree.Draw(varx + ' >> ' + _hist_.GetName(), sel)
246  tree.Draw(varx + ' >> ' + _ahist_.GetName(), sel + ' && ' + vary)
247 
248  g_efficiency = TGraphAsymmErrors()
249  g_efficiency.BayesDivide(_ahist_, _hist_)
250  g_efficiency.GetXaxis().SetTitle(xtitle)
251  g_efficiency.GetYaxis().SetTitle('efficiency')
252  g_efficiency.GetYaxis().SetNdivisions(507)
253  g_efficiency.SetLineWidth(3)
254  g_efficiency.SetName(header)
255  g_efficiency.SetMinimum(0.)
256  g_efficiency.GetYaxis().SetTitleOffset(1.3)
257  g_efficiency.SetMarkerStyle(marker)
258  g_efficiency.SetMarkerSize(1)
259  g_efficiency.Draw('ap')
260 
261 # save(c, 'plots/' + addon)
262 
263  return copy.deepcopy(g_efficiency)
264 
265 
266 
267 
268 
def makeEffPlotsVars(tree, varx, vary, sel, nbinx, xmin, xmax, nbiny, ymin, ymax, xtitle, ytitle, leglabel=None, header='', addon='', option='pt', marker=20)
Definition: compare.py:228
def compare.overlay (   hists,
  ytitle,
  header,
  addon 
)

Definition at line 119 of file compare.py.

References LegendSettings(), and save().

Referenced by FWCaloTowerDetailView.build(), FWMuonDetailView.build(), FWPhotonDetailView.build(), FWElectronDetailView.build(), and SiStripHitEffFromCalibTree.makeSummary().

119 def overlay(hists, ytitle, header, addon):
120 
121  print 'number of histograms = ', len(hists)
122 
123  canvas = TCanvas()
124  leg = TLegend(0.2,0.7,0.5,0.9)
125  LegendSettings(leg, 1)
126 
127  col = [1,2,4,6,8,9,12]
128 
129  ymax = -1
130  ymin = 100
131 
132  for ii, hist in enumerate(hists):
133  hist.GetYaxis().SetTitle('efficiency')
134  hist.SetLineColor(col[ii])
135  hist.SetMarkerColor(col[ii])
136  hist.SetLineWidth(2)
137  hist.SetMarkerSize(1)
138 
139 
140  for ip in range(hist.GetN()):
141  x = Double(-1)
142  y = Double(-1)
143  hist.GetPoint(ip, x, y)
144 
145  if ymin > y:
146  ymin = y
147  if ymax < y:
148  ymax = y
149 
150 #
151 # if ymax < hist.GetMaximum():
152 # ymax = hist.GetMaximum()
153 # if ymin > hist.GetMinimum():
154 # ymin = hist.GetMinimum()
155 
156  if ii==0:
157  hist.Draw("Azp")
158  else:
159 
160  hist.Draw("pzsame")
161 
162 # print hist.GetName(), hist.GetTitle()
163  legname = hist.GetName()
164 
165  leg.AddEntry(hist, legname, 'lep')
166 
167 
168  for hist in hists:
169  hist.SetMaximum(ymax*2)
170 # hist.SetMinimum(ymin*0.5)
171 
172  leg.Draw()
173 
174  tex = TLatex( hists[-1].GetXaxis().GetXmin() + 0.01*(hists[-1].GetXaxis().GetXmax() - hists[-1].GetXaxis().GetXmin()), ymax*2.1, addon.replace('tau_',''))
175 
176  tex.SetTextFont(42)
177  tex.SetTextSize(0.03)
178  tex.Draw()
179 
180  tex2 = TLatex( hists[-1].GetXaxis().GetXmin() + 0.87*(hists[-1].GetXaxis().GetXmax() - hists[-1].GetXaxis().GetXmin()), ymax*2.1, tlabel)
181 
182  tex2.SetTextFont(42)
183  tex2.SetTextSize(0.03)
184  tex2.Draw()
185 
186 
187 
188  save(canvas, 'compare_' + runtype + '/' + header)
189 
190 
191 
def save(canvas, name)
Definition: compare.py:44
def LegendSettings(leg, ncolumn)
Definition: compare.py:50
def overlay(hists, ytitle, header, addon)
Definition: compare.py:119
def compare.save (   canvas,
  name 
)

Definition at line 44 of file compare.py.

References ensureDir(), and python.rootplot.root2matplotlib.replace().

Referenced by hoverlay(), and overlay().

44 def save(canvas, name):
45  ensureDir('compare_' + runtype)
46  canvas.SaveAs(name.replace(' ','').replace('&&','')+'.pdf')
47  canvas.SaveAs(name.replace(' ','').replace('&&','')+'.gif')
48 
49 
def replace(string, replacements)
def save(canvas, name)
Definition: compare.py:44
def ensureDir(directory)
Definition: compare.py:40

Variable Documentation

compare.argc

Definition at line 14 of file compare.py.

compare.argvs

Definition at line 13 of file compare.py.

compare.den_sel

Definition at line 325 of file compare.py.

compare.hist

Definition at line 372 of file compare.py.

compare.hists
compare.hvardict

Definition at line 347 of file compare.py.

compare.loose_id

Definition at line 304 of file compare.py.

compare.num_sel

Definition at line 324 of file compare.py.

compare.reco_cut

Definition at line 303 of file compare.py.

compare.runtype

Definition at line 20 of file compare.py.

Referenced by RPCTechTriggerConfig.RPCTechTriggerConfig(), and RunTypeDef.setRunType().

compare.sampledict

Definition at line 306 of file compare.py.

compare.tfile
compare.tlabel

Definition at line 24 of file compare.py.

Referenced by cscdqm::EventProcessor.getCSCFromMap().

compare.tree
compare.vardict

Definition at line 272 of file compare.py.

compare.xlabel

Definition at line 25 of file compare.py.