Functions | Variables
make_reco_miniprod5_plots Namespace Reference

Functions

def SetHistStyle (hist, fill_color, isData)
 
def GetFillColor (sample)
 
def GetLegendTitle (sample, opts)
 
def GetPlotTag (opts)
 
def MakePlots (opts)
 

Variables

string default_indir = "/pnfs/nova/persistent/users/mislivec/xsec_tuning_miniprod5/"
 Parse Options. More...
 
string default_outdir = './plots/reco/'
 
string help_indir = 'Input histogram files directory. Default:\n%s'
 
string help_outdir = 'Output histogram files directory. Default:\n%s'
 
 parser = OptionParser()
 
 dest
 
 type
 
 default
 
 None
 
 help
 
 action
 
 False
 
 opts
 
 args
 

Function Documentation

def make_reco_miniprod5_plots.GetFillColor (   sample)

Definition at line 25 of file make_reco_miniprod5_plots.py.

Referenced by MakePlots().

25 def GetFillColor( sample ) :
26 
27  fill_color = 0
28  if sample == "Data" : fill_color = 0
29  elif 'TotMC' in sample : fill_color = kRed
30  elif 'QEL' in sample : fill_color = kAzure+7
31  elif 'MEC' in sample : fill_color = kOrange-1
32  elif 'RES' in sample : fill_color = kGreen+2
33  elif 'DIS' in sample : fill_color = kGray
34  elif 'Other' in sample : fill_color = kBlack
35 
36  return fill_color
37 
38 
def make_reco_miniprod5_plots.GetLegendTitle (   sample,
  opts 
)

Definition at line 39 of file make_reco_miniprod5_plots.py.

Referenced by MakePlots().

39 def GetLegendTitle( sample, opts ) :
40 
41  title = 'Undefined'
42  if 'QEL' in sample : title = 'QE'
43  elif 'MEC' in sample : title = 'MEC'
44  elif 'RES' in sample : title = 'RES'
45  elif 'DIS' in sample : title = 'DIS'
46  elif 'Other' in sample : title = 'Other'
47 
48  if sample == 'Data' : title = 'ND Data'
49 
50  return title
51 
52 
def make_reco_miniprod5_plots.GetPlotTag (   opts)

Definition at line 53 of file make_reco_miniprod5_plots.py.

Referenced by MakePlots().

53 def GetPlotTag( opts ) :
54 
55  tag = ''
56 
57  if opts.mec_minerva : tag += '_MinervaMEC'
58  elif opts.mec_gauss : tag += '_GaussMEC'
59  elif opts.no_mec : tag += '_NoMEC'
60 
61  if opts.res_minos : tag += "_MinosRES"
62  elif opts.res_rpa : tag += "_RPARES"
63  elif opts.res_pauli_block : tag += "_RESPauliBlock"
64  elif opts.res_minerva : tag += "_MinervaRES"
65  elif opts.no_res_supp_tag : tag += "_NoRESSupp"
66 
67  #if opts.default_genie : tag = '_DefaultGENIE'
68 
69  return tag
70 
def make_reco_miniprod5_plots.MakePlots (   opts)

Definition at line 71 of file make_reco_miniprod5_plots.py.

References plot_validation_datamc.Clone(), GetFillColor(), GetLegendTitle(), GetPlotTag(), makeTrainCVSamples.int, cet.pow(), PandAna.Demos.demo1.range, Scale(), SetHistStyle(), and SetTitle().

71 def MakePlots( opts ) :
72 
73  beam = opts.beam
74 
75  filename_data = os.path.join( opts.indir, "hists_xec_tuning_mp5_%s_data.root" % beam )
76  filename_mc = os.path.join( opts.indir, "hists_xec_tuning_mp5_%s_mc.root" % beam )
77 
78  if not os.path.exists( filename_data ) : sys.exit( 'Data file does not exist:\n%s' % filename_data )
79  if not os.path.exists( filename_mc ) : sys.exit( 'MC file does not exist:\n%s' % filename_mc )
80 
81  file_data = TFile( filename_data )
82  file_mc = TFile( filename_mc )
83 
84  print 'Hist file data:\n', file_data.GetName()
85  print 'Hist file MC:\n', file_mc.GetName()
86 
87  tree_pot_data = file_data.Get( 'pot' )
88  pot_data = 0.0
89  for i in range( tree_pot_data.GetEntries() ) :
90  tree_pot_data.GetEntry( i )
91  pot_data += tree_pot_data.pot_data
92 
93  tree_pot_mc = file_mc.Get( 'pot' )
94  pot_mc = 0.0
95  for i in range( tree_pot_mc.GetEntries() ) :
96  tree_pot_mc.GetEntry( i )
97  pot_mc += tree_pot_mc.pot_mc
98 
99  mc_pot_scale = pot_data / pot_mc
100 
101  print 'pot_data = %.2e' % pot_data
102  print 'pot_mc = %.2e' % pot_mc
103  print 'mc_pot_scale = %.3f' % mc_pot_scale
104 
105  distributions = []
106  distributions.append( "PrimTrkLen" )
107  distributions.append( "RecoCosThetaMu" )
108  distributions.append( "RecoEhad" )
109  distributions.append( "RecoEhadFrac" )
110  distributions.append( "RecoEhadVis" )
111  distributions.append( "RecoEmu" )
112  distributions.append( "RecoEnu" )
113  distributions.append( "RecoQ2" )
114  distributions.append( "RecoQ3" )
115  distributions.append( "RecoW" )
116 
117  distributions.append( "PrimTrkLen_WSelected" )
118  distributions.append( "RecoCosThetaMu_WSelected" )
119  distributions.append( "RecoEhad_WSelected" )
120  distributions.append( "RecoEhadFrac_WSelected" )
121  distributions.append( "RecoEhadVis_WSelected" )
122  distributions.append( "RecoEmu_WSelected" )
123  distributions.append( "RecoEnu_WSelected" )
124  distributions.append( "RecoQ2_WSelected" )
125  distributions.append( "RecoQ3_WSelected" )
126  distributions.append( "RecoW_WSelected" )
127 
128  for i in range( 4 ) :
129  quant_str = "_EhadQuantile%d" % ( i+1 )
130  distributions.append( "PrimTrkLen" + quant_str )
131  distributions.append( "RecoCosThetaMu" + quant_str )
132  distributions.append( "RecoEhad" + quant_str )
133  distributions.append( "RecoEhadVis" + quant_str )
134  distributions.append( "RecoEmu" + quant_str )
135  distributions.append( "RecoEnu" + quant_str )
136  distributions.append( "RecoQ2" + quant_str )
137  distributions.append( "RecoQ3" + quant_str )
138  distributions.append( "RecoW" + quant_str )
139 
140 
141  mc_comps = []
142  mc_comps.append( "MEC" )
143  mc_comps.append( "QEL" )
144  mc_comps.append( "RES" )
145  mc_comps.append( "DIS" )
146  mc_comps.append( "Other" )
147 
148  if opts.res_minos :
149  mc_comps[ mc_comps.index( "RES" ) ] = "RES_MINOS"
150  elif opts.res_rpa :
151  mc_comps[ mc_comps.index( "RES" ) ] = "RES_RPA"
152  elif opts.res_pauli_block :
153  mc_comps[ mc_comps.index( "RES" ) ] = "RES_PauliBlock"
154  elif opts.res_minerva :
155  mc_comps[ mc_comps.index( "RES" ) ] = "RES_MINERvA"
156 
157  if opts.mec_minerva :
158  mc_comps[ mc_comps.index( "MEC" ) ] = "MEC_MINERvA"
159  if opts.mec_gauss :
160  mc_comps[ mc_comps.index( "MEC" ) ] = "MEC_DoubleGauss"
161  elif opts.no_mec :
162  mc_comps.remove( "MEC" )
163 
164  print 'mc_comps =', mc_comps
165 
166  canvas_dist = TCanvas()
167  canvas_ratio = TCanvas()
168 
169  #text_size = 0.05
170  text_size = 0.045
171  text_size_wsel = 0.044
172  text_font = 42
173  text_angle = 0.0
174  setNDC = True
175  line_spacing = text_size + 0.01
176 
177  xpos_right = 0.6
178  xpos_left = gStyle.GetPadLeftMargin() + text_size
179  ypos_top = 1.0 - gStyle.GetPadTopMargin() - 0.02
180 
181  isRHC = beam.upper() == 'RHC'
182 
183  text_beam = "Neutrino Beam"
184  if isRHC : text_beam = "Antineutrino Beam"
185  label_beam = root_style.GetLabel( text_beam, xpos_right, ypos_top, text_size, kBlack, text_font, 13, text_angle, setNDC )
186 
187  text_select = '#nu_{#mu} + #bar{#nu}_{#mu} CC Selection'
188  ypos_select = ypos_top - text_size #line_spacing
189  label_select = root_style.GetLabel( text_select, xpos_right, ypos_select, text_size, kBlack, text_font, 13, text_angle, setNDC )
190 
191  label_prelim = root_style.GetLabelPreliminary()
192  label_prelim.SetTextFont( text_font )
193  label_prelim.SetTextSize(2/30.)
194 
195  text_list_weights = []
196 
197  if opts.mec_minerva :
198  text_list_weights.append( 'MINERvA MEC' )
199  elif opts.mec_gauss :
200  text_list_weights.append( 'MEC Gauss Enh.' )
201 
202  if opts.res_minos :
203  text_list_weights.append( 'MINOS RES Supp.' )
204  elif opts.res_rpa :
205  text_list_weights.append( 'RPA RES Supp.' )
206  elif opts.res_pauli_block :
207  text_list_weights.append( 'RES Pauli Blocking' )
208  if opts.res_minerva :
209  text_list_weights.append( 'MINERvA RES Supp.' )
210  elif opts.no_res_supp_tag :
211  text_list_weights.append( 'No RES Supp.' )
212 
213  #elif opts.default_genie :
214  # text_list_weights.append( 'Default GENIE' )
215 
216  event_scale_power = 4
217  event_scale = 1.0 / pow( 10.0, event_scale_power )
218 
219  for d in distributions :
220 
221  hist_name_data = '%s_Data' % d
222  if not file_data.FindKey( hist_name_data ) :
223  print "Histogram \"%s\" not found. Skipping..." % hist_name_data
224  continue
225  hist_data = file_data.Get( hist_name_data )
226  hist_data.Scale( event_scale )
227  hist_data.GetYaxis().SetTitle( '10^{%d} Events' % event_scale_power )
228  SetHistStyle( hist_data, GetFillColor( 'Data' ), True )
229 
230  hists_mc = {}
231  hist_tot_mc_sum = None
232 
233  legend = root_style.GetLegend()
234  legend.SetTextSize( text_size )
235  legend.SetTextFont( text_font )
236  #legend.SetHeader( text_select )
237  legend.AddEntry( hist_data, GetLegendTitle( 'Data', opts ), 'LPE' )
238 
239  for c in mc_comps :
240  hist_name = '%s_%s' % ( d, c )
241  #print 'hist_name =', hist_name
242  if not file_mc.FindKey( hist_name ) :
243  print "Histogram \"%s\" not found. Skipping..." % hist_name
244  break
245  hists_mc[ c ] = file_mc.Get( hist_name )
246  hists_mc[ c ].Scale( mc_pot_scale * event_scale )
247  SetHistStyle( hists_mc[ c ], GetFillColor( c ), False )
248 
249  if hist_tot_mc_sum == None :
250  hist_tot_mc_sum = hists_mc[ c ].Clone( 'TotMC' )
251  SetHistStyle( hist_tot_mc_sum, GetFillColor( 'TotMC' ), False )
252  else :
253  hist_tot_mc_sum.Add( hists_mc[ c ] )
254 
255  #print "len( mc_comps ) =", len( mc_comps )
256  #print "len( hists_mc ) =", len( hists_mc )
257  if len( hists_mc ) != len( mc_comps ) : continue
258 
259  for c in mc_comps :
260  legend_name = GetLegendTitle( c, opts )
261  legend.AddEntry( hists_mc[ c ], legend_name, 'F' )
262 
263  stackMC = THStack()
264  for c in reversed( mc_comps ) : stackMC.Add( hists_mc[ c ] )
265 
266  maxData = hist_data.GetBinContent( hist_data.GetMaximumBin() )
267  ymax_scale = 1.5
268  if d == 'RecoQ2_EhadQuantile3' :
269  #if isRHC : ymax_scale = 2.5
270  #else : ymax_scale = 2.0
271  ymax_scale = 2.0
272  elif d == 'RecoQ2_EhadQuantile4' :
273  if isRHC : ymax_scale = 2.5
274  else : ymax_scale = 3.0
275  elif d == "RecoEhadVis_EhadQuantile4" :
276  if isRHC : ymax_scale = 2.5
277  else : ymax_scale = 3.0
278  elif d == "RecoQ3_EhadQuantile4" :
279  #if isRHC : ymax_scale = 3.5
280  #else : ymax_scale = 2.5
281  ymax_scale = 2.0
282  elif d == "RecoQ2_WSelected" :
283  if isRHC : ymax_scale = 1.9
284  else : ymax_scale = 1.7
285  elif d == "RecoEhadVis" :
286  ymax_scale = 1.3
287  elif d == "RecoEhadFrac" :
288  ymax_scale = 1.3
289  elif d == 'RecoCosThetaMu_EhadQuantile3' :
290  ymax_scale = 1.5
291  elif d == 'RecoCosThetaMu_EhadQuantile4' :
292  ymax_scale = 2.0
293  #if 'RecoCosThetaMu' in d :
294  # ymax_scale = 1.5
295 
296  ymax = ymax_scale * maxData
297  stackMC.SetMaximum( ymax )
298  stackMC.SetMinimum( 0.0 )
299  hist_data.SetMaximum( ymax )
300  hist_data.SetMinimum( 0.0 )
301 
302  xmin = hist_data.GetXaxis().GetXmin()
303  xmax = hist_data.GetXaxis().GetXmax()
304  xndiv = hist_data.GetXaxis().GetNdivisions()
305  if 'RecoW' in d:
306  xmin = 0.5
307  xmax = 2.5
308  xndiv = 504
309  if 'RecoEnu' in d:
310  xmin = 0.0
311  xmax = 4.0
312  xndiv = 508
313  elif 'PrimTrkLen' in d :
314  xmax = 15.0
315  #xndiv = 407
316  elif 'RecoCosThetaMu' in d :
317  xmin = 0.7
318  xndiv = 506
319  elif 'RecoQ2' in d :
320  xmax = 1.0
321  elif 'RecoEhadVis' in d :
322  if isRHC :
323  #xmax = 0.4
324  #xndiv = 504
325  xmax = 0.6
326  xndiv = 506
327  else :
328  xmax = 0.6
329  xndiv = 506
330 
331  if 'EhadQuantile' in d :
332  text_qntl = 'Quantile %d' % int( d[-1] )
333  label_qntl = root_style.GetLabel( 'Quantile X', xpos_left, ypos_top, text_size, kBlack, text_font, 13, text_angle, setNDC )
334 
335  # Set X and Y positions of labels and legend
336 
337  xpos_legend = 0.55
338  width_legend = 1.0 - gStyle.GetPadRightMargin() - 0.005 - xpos_legend
339  xpos_other = gStyle.GetPadLeftMargin() + 0.04
340  dists_flip_legend_xpos = []
341  dists_flip_legend_xpos.append( "PrimTrkLen_EhadQuantile1" )
342  dists_flip_legend_xpos.append( "PrimTrkLen_EhadQuantile2" )
343  dists_flip_legend_xpos.append( "RecoQ3_EhadQuantile4" )
344  dists_flip_legend_xpos.append( "RecoW_EhadQuantile4" )
345  dists_flip_legend_xpos.append( "RecoEhad_EhadQuantile4" )
346  dists_flip_legend_xpos.append( "RecoEhadVis_EhadQuantile4" )
347 
348  if d in dists_flip_legend_xpos or "RecoEnu" in d or 'RecoCosThetaMu' in d :
349  xpos_legend = gStyle.GetPadLeftMargin() + 0.03 # text_size
350  xpos_other = 0.5
351 
352  label_beam .SetX( xpos_legend + 0.01 )
353  label_select.SetX( xpos_legend + 0.01 )
354  legend.SetX1( xpos_legend )
355  legend.SetX2( xpos_legend + width_legend )
356  legend.SetY2( ypos_select - text_size - 0.02 )
357  legend.SetY1( legend.GetY2() - ( legend.GetTextSize() + 0.01 ) * legend.GetNRows() )
358  legend.SetFillColorAlpha( 0, 0 )
359 
360  text_list_others = []
361  text_list_others.append( "Miniprod5" )
362 
363  if 'EhadQuantile' in d :
364  text_list_others.append( 'Quantile %d' % int( d[-1] ) )
365 
366  if 'WSelected' in d :
367  text_list_others.append( '1.2 < W_{reco} < 1.5 GeV/c^{2}' )
368 
369  text_list_others += text_list_weights
370 
371  labels_others = []
372  ypos_other = ypos_top
373  for text in text_list_others :
374  '''
375  if 'RecoW' in text :
376  labels_others.append( root_style.GetLabel( text, xpos_other, ypos_other, text_size_wsel, kBlack, text_font, 13, text_angle, setNDC ) )
377  elif 'RPA' in text :
378  labels_others.append( root_style.GetLabel( text, xpos_other+.03, ypos_other, text_size_wsel, kBlack, text_font, 13, text_angle, setNDC ) )
379  else :
380  labels_others.append( root_style.GetLabel( text, xpos_other, ypos_other, text_size, kBlack, text_font, 13, text_angle, setNDC ) )
381  '''
382 
383  ypos_temp = ypos_other
384  if "W_{reco}" in text : ypos_temp += 0.01
385  labels_others.append( root_style.GetLabel( text, xpos_other, ypos_temp, text_size, kBlack, text_font, 13, text_angle, setNDC ) )
386  ypos_other -= line_spacing
387 
388  if 'RecoQ2' in d :
389  hist_data.GetXaxis().SetTitle( "Reco Q^{2} (GeV^{2}/c^{2})" )
390  elif 'RecoQ3' in d :
391  hist_data.GetXaxis().SetTitle( "Reco #left|#vec{q}#right| (GeV/c)" )
392  elif 'PrimTrkLen' in d :
393  hist_data.GetXaxis().SetTitle( "Muon Track Length (m)" )
394  elif "RecoW" in d :
395  hist_data.GetXaxis().SetTitle( "Reco W (GeV/c^{2})" )
396 
397  canvas_dist.cd()
398  canvas_dist.Clear()
399 
400  hist_data.GetXaxis().SetRangeUser( xmin, xmax )
401  if 'PrimTrkLen' not in d : hist_data.GetXaxis().SetNdivisions( xndiv, False )
402 
403  hist_data.Draw( 'E' )
404  stackMC.Draw( 'hist same' )
405  stackMC.GetXaxis().SetRangeUser( xmin, xmax )
406  '''
407  if opts.draw_tot_mc :
408  hist_tot_mc = file_mc.Get( '%s_TotMC' % d )
409  hist_tot_mc.Scale( mc_pot_scale )
410  hist_tot_mc.SetLineColor( kRed )
411  legend.AddEntry( hist_tot_mc, 'Total MC', 'L' )
412  hist_tot_mc.Draw( 'same hist' )
413  '''
414 
415  hist_data.Draw( 'same E' )
416  if 'PrimTrkLen' in d or 'RecoEnu' in d :
417  legend.Draw()
418  else :
419  legend.Draw()
420  #label_prelim.Draw()
421  label_beam.Draw()
422  label_select.Draw()
423  for label in labels_others : label.Draw()
424 
425  hist_ratio = hist_data.Clone( '%s_Ratio' % d )
426  hist_ratio.Divide( hist_tot_mc_sum )
427  hist_ratio.GetYaxis().SetTitle( 'Data / MC' )
428  hist_ratio.GetYaxis().SetRangeUser( 0.5, 1.5 )
429  hist_ratio.GetYaxis().SetNdivisions( 504 )
430 
431  canvas_ratio.cd()
432  canvas_ratio.Clear()
433  canvas_ratio.SetGridy(1)
434  hist_ratio.Draw( 'E' )
435 
436  plot_tag = GetPlotTag( opts )
437  if opts.add_out_tag != None : plot_tag += '_%s' % opts.add_out_tag
438 
439  plots_dir = os.path.join( opts.outdir, 'MP5_%s_Reco%s' % ( beam.upper(), plot_tag ) )
440  if not os.path.isdir( plots_dir ) : os.makedirs( plots_dir )
441 
442  out_dist_name = 'MP5_%s_%s' % ( beam.upper(), d )
443  out_dist_name += plot_tag
444 
445  #canvas_dist.SaveAs( 'plots/%s.pdf' % out_dist_name )
446  canvas_dist.SaveAs( os.path.join( plots_dir, '%s.pdf' % out_dist_name ) )
447  #root_style.SavePlots( canvas_dist, os.path.join( plots_dir, out_dist_name ) )
448 
449  out_name_ratio = '%s_%s_Ratio' % ( beam.upper(), d )
450  out_name_ratio += plot_tag
451 
452  #canvas_ratio.SaveAs( 'plots/%s.pdf' % out_name_ratio )
453  #canvas_ratio.SaveAs( os.path.join( plots_dir, '%s.pdf' % out_name_ratio ) )
454 
455 
def SetHistStyle(hist, fill_color, isData)
constexpr T pow(T x)
Definition: pow.h:75
gargamelle SetTitle("Gargamelle #nu_{e} CC data")
simulatedPeak Scale(1/simulationNormalisationFactor)
def make_reco_miniprod5_plots.SetHistStyle (   hist,
  fill_color,
  isData 
)

Definition at line 12 of file make_reco_miniprod5_plots.py.

Referenced by MakePlots().

12 def SetHistStyle( hist, fill_color, isData ) :
13 
14  root_style.ApplyAxisStyleAll( hist )
15 
16  hist.SetLineColor( kBlack )
17  hist.SetMarkerColor( kBlack )
18  if isData :
19  hist.SetFillColor( 0 )
20  hist.SetFillStyle( 0 )
21  else :
22  hist.SetFillColor( fill_color )
23  hist.SetFillStyle( 1001 )
24 
def SetHistStyle(hist, fill_color, isData)

Variable Documentation

make_reco_miniprod5_plots.action

Definition at line 476 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.args

Definition at line 488 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.default

Definition at line 469 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.default_indir = "/pnfs/nova/persistent/users/mislivec/xsec_tuning_miniprod5/"

Parse Options.

default_indir = "./"

Definition at line 462 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.default_outdir = './plots/reco/'

Definition at line 463 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.dest

Definition at line 469 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.False

Definition at line 476 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.help

Definition at line 469 of file make_reco_miniprod5_plots.py.

string make_reco_miniprod5_plots.help_indir = 'Input histogram files directory. Default:\n%s'

Definition at line 465 of file make_reco_miniprod5_plots.py.

string make_reco_miniprod5_plots.help_outdir = 'Output histogram files directory. Default:\n%s'

Definition at line 466 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.None

Definition at line 469 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.opts

Definition at line 488 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.parser = OptionParser()

Definition at line 468 of file make_reco_miniprod5_plots.py.

make_reco_miniprod5_plots.type

Definition at line 469 of file make_reco_miniprod5_plots.py.