Trees | Indices | Help |
---|
|
1 #! /usr/bin/env python 2 ################################################################################ 3 # 4 # Copyright (c) 2010 The MadGraph5_aMC@NLO Development team and Contributors 5 # 6 # This file is a part of the MadGraph5_aMC@NLO project, an application which 7 # automatically generates Feynman diagrams and matrix elements for arbitrary 8 # high-energy processes in the Standard Model and beyond. 9 # 10 # It is subject to the MadGraph5_aMC@NLO license which should accompany this 11 # distribution. 12 # 13 # For more information, visit madgraph.phys.ucl.ac.be and amcatnlo.web.cern.ch 14 # 15 ################################################################################ 16 """Example code to plot custom curves based on djrs.dat with matplotlib""" 17 import os 18 import sys 19 import matplotlib.pyplot as plt 20 import matplotlib.gridspec as gridspec 21 import matplotlib.pylab as pylab 22 23 24 ################################################################################ 25 # TRY TO LINK TO HISTOGRAMS.PY 26 ################################################################################ 27 # We need to link to histograms.dat. 28 # You can put the path to MG5_aMC main directory here to link from any directory 29 #sys.path.append('PATH/TO/MADGRAPH') 30 #try to find relatively to this file 31 sys.path.append(os.path.basename(os.path.basename(__file__))) #../ 32 sys.path.append(os.path.basename(os.path.basename(os.path.basename(__file__)))) #../../ 33 # lets try the import. 34 try: 35 import madgraph 36 except ImportError: 37 try: 38 import internal 39 except ImportError: 40 print "You need to specify the path to the MG5_aMC directory" 41 sys.exit(1) 42 else: 43 from internal.histograms import * 44 else: 45 from madgraph.various.histograms import * 46 47 ################################################################################ 48 # CHOICE OF INPUT FILE 49 ################################################################################ 50 # check if an argument is passed as inputfiles: 51 if len(sys.argv) >1: 52 input_file = sys.argv[1] 53 else: 54 #take the default path 55 input_file = './Events/run_01/tag_1_djrs.dat' 56 print "Reading information from: ", input_file 57 58 59 ################################################################################ 60 # PARSING THE FILE AND ACCESS TO BASIC PROPERTY OF THE OBJECT 61 ################################################################################ 62 #parsing the data and create the object instance 63 hwu_list = HwUList(input_file, raw_labels=True) 64 # raw label prevent modification of the weight label. They will stay at their inputfile value 65 66 # get the list of the plot names 67 names = hwu_list.get_hist_names() 68 #print names 69 # get the list of the weight label 70 weights_name = hwu_list.get_wgt_names() 71 #print weights_name 72 # In this example, I want to plot the DJR1 -> select the histograms with d01 in their name: 73 selected_hist = [hwu_list.get(n) for n in names if 'd01' in n] 74 75 ################################################################################ 76 # CREATE THE PLOT AND THE ASSOCIATE RATIO PLOT 77 ################################################################################ 78 # define a multi-plot frame for the plot 79 gs1 = gridspec.GridSpec(2, 1, height_ratios=[5,1]) 80 gs1.update(wspace=0, hspace=0) # set the spacing between axes. 81 main_frame = plt.subplot(gs1[0]) # main frame/plot 82 ratio_frame = plt.subplot(gs1[1]) # ratio frame/plot 83 84 main_frame.set_yscale('log') 85 #main_frame.yaxis.set_label_coords(-0.07, 0.90) 86 main_frame.set_ylabel(r'$\frac{d\sigma_{LO}}{dDJR1} [pb]$') 87 main_frame.set_title('Differential Jet Rate') 88 main_frame.set_xticklabels([]) #remove x-axis in the main frame (due to the ratio frame) 89 90 #ratio_frame.xaxis.set_label_coords(0.90, -0.20) 91 ratio_frame.set_xlabel(r'$log(DJR1/1[GeV])$') 92 ratio_frame.set_ylabel(r'$ME/PS$') 93 94 95 ################################################################################ 96 # SETTING THE CURVE 97 ################################################################################ 98 # Adding the curves. Here I want to plot two curves: 99 # the curve with the maximum value of QCUT from the 0 jet sample 100 # the curve with the minimal value of QCUT from the highest multiplicity sample 101 qcut= [l for l in weights_name if l.startswith('MUF=1_MUR=1_PDF=247000_MERGING=')] 102 min_qcut,max_qcut = qcut[0],qcut[-1] 103 104 #get the histo 105 h_0j = [h for h in selected_hist if 'Jet sample 0' in h.get_HwU_histogram_name()][0] 106 h_1j = [h for h in selected_hist if 'Jet sample 1' in h.get_HwU_histogram_name()][0] 107 108 y_0j = h_0j.get(min_qcut) 109 y_1j = h_1j.get(max_qcut) 110 l_0j, = main_frame.plot(h_0j.get('bins'), y_0j, label='0j', linestyle='steps') 111 l_1j, = main_frame.plot(h_1j.get('bins'), y_1j, label='1j', linestyle='steps') 112 113 114 ################################################################################ 115 # ADDING UNCERTAINTY BAND 116 ################################################################################ 117 # Add the PDF uncertainty on the 0j sample 118 # the attribute of get_uncertainty_band can be a regular expression, a list of weight name, or a function returning 0/1 119 # Special attributes exists: PDF, QCUT, ALPSFACT, SCALE # this assumes standard name formatting 120 # For PDF you can force the type of uncertainty band by specifying mode='gaussian' or mode='hessian' 121 # if using 'PDF' attributes the correct type should be found automatically 122 pdfmin, pdfmax = h_0j.get_uncertainty_band('PDF') 123 fill_between_steps(h_0j.get('bins'), pdfmin, pdfmax, ax=main_frame, facecolor=l_0j.get_color(), alpha=0.5, 124 edgecolor=l_0j.get_color() 125 ) 126 # use a second method for h_1j 127 pdfmin, pdfmax = h_1j.get_uncertainty_band(['MUF=1_MUR=1_PDF=%i_MERGING=30' % i for i in range(247000,247100)], mode='hessian') 128 fill_between_steps(h_1j.get('bins'), pdfmin, pdfmax, ax=main_frame, facecolor=l_1j.get_color(), alpha=0.5, 129 edgecolor=l_1j.get_color() 130 ) 131 132 133 ################################################################################ 134 # ADDING RATIO PLOT 135 ################################################################################ 136 ratio = [y_0j[i]/y_1j[i] if y_1j[i] else 0 for i in xrange(len(y_0j))] 137 ratio_frame.plot(h_0j.get('bins'), ratio, linestyle='steps') 138 139 140 ################################################################################ 141 # SETTING SOME STYLE IMPROVMENT FOR THE PLOT 142 ################################################################################ 143 # Some final style processing of matplotlib 144 main_frame.legend(ncol=2, prop={'size':12}, loc=4) 145 ratio_frame.set_yticks(ratio_frame.get_yticks()[:-1]) # remove upper tick of the ratio plot 146 # Adding the MadGraph5_aMC@NLO flag on the plot (likely overcomplicated plot.text() should be better) 147 ax_c = main_frame.twinx() 148 ax_c.set_ylabel('MadGraph5_aMC@NLO') 149 ax_c.yaxis.set_label_coords(1.01, 0.25) 150 ax_c.set_yticks(main_frame.get_yticks()) 151 ax_c.set_yticklabels([]) 152 153 154 ################################################################################ 155 # WRITE THE OUTPUT FILE 156 ################################################################################ 157 plt.savefig("DJR1.pdf") # many extension possible (jpg/png/...) 158
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Dec 20 09:18:05 2018 | http://epydoc.sourceforge.net |