diff --git a/tools/plotting/fastnnlo_kfactor.py b/tools/plotting/fastnnlo_kfactor.py index f14ff13a8159b552c29086e6130c0dde5f733995..6125862eedbc41d944e8dccc46bf369e863564e1 100755 --- a/tools/plotting/fastnnlo_kfactor.py +++ b/tools/plotting/fastnnlo_kfactor.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 #-*- coding:utf-8 -*- ################################################### @@ -66,12 +66,12 @@ def main(): # PDF set name pdfset = os.path.basename(args['pdfset']) pdfname = os.path.splitext(pdfset)[0] - print 'PDF Set: ', pdfname, '\n' + print('PDF Set: ', pdfname, '\n') # chosen higher order and lower order for kfactor # was earlier called args['order'] - print 'Higher order: ', args['numerator'] - print 'Lower order: ', args['denominator'] # used to be args['normoder'] + print('Higher order: ', args['numerator']) + print('Lower order: ', args['denominator']) # used to be args['normoder'] # will be set to True in case all three plots are required (use this again when plotting) allplots = False @@ -81,14 +81,14 @@ def main(): elif (args['numerator'] in [2, 'nnlo', 'NNLO']): high = 'NNLO' else: - print 'ERROR: Invalid choice of order. Aborted.' + print('ERROR: Invalid choice of order. Aborted.') sys.exit('Higher order can be NLO (=1) or NNLO (=2).') - print 'Chosen highest order: %s.' % high + print('Chosen highest order: %s.' % high) elif (args['numerator'] is None) and (args['denominator'] is not None): sys.exit( 'Either both orders have to be specified, or none. Missing higher order.') else: - print 'No specific order chosen.' + print('No specific order chosen.') if args['denominator'] is not None: if (args['denominator'] in [0, 'lo', 'LO']): @@ -96,17 +96,17 @@ def main(): elif (args['denominator'] in [1, 'nlo', 'NLO']): low = 'NLO' else: - print 'ERROR: Invalid choice of lower order. Aborted.' + print('ERROR: Invalid choice of lower order. Aborted.') sys.exit('Lower (=denominator) order can be LO (=0) or NLO (=1).') - print 'Chosen lower (=denominator) order: %s.' % low + print('Chosen lower (=denominator) order: %s.' % low) elif (args['denominator'] is None) and (args['numerator'] is not None): sys.exit( 'ERROR: Either both orders have to be specified, or none. Missing lower order.') else: - print 'No specific lower order chosen.' + print('No specific lower order chosen.') if (args['numerator'] is None) and (args['denominator'] is None): - print 'No specific orders chosen: Look at NLO/LO, NNLO/NLO and NNLO/LO.' + print('No specific orders chosen: Look at NLO/LO, NNLO/NLO and NNLO/LO.') all_orders = ['LO', 'NLO', 'NNLO'] allplots = True @@ -120,39 +120,39 @@ def main(): # Get labeling for the x-axis # dimensionality of table: ndim = fnlo.GetNumDiffBin() - print '\n', 'Dimensions: ', ndim + print('\n', 'Dimensions: ', ndim) # labels of all the dimensions: labels = fnlo.GetDimLabels() - print 'Labels: ', labels + print('Labels: ', labels) # label of first dimension: xlabel = fnlo.GetDimLabel(0) - print 'x-label: ', xlabel + print('x-label: ', xlabel) # Now evaluate fastNLO table for creating 3 plots # if we allow options -o and -n, we will need an if-condition here! - print 'Start table evaluation for creating three plots. \n' + print('Start table evaluation for creating three plots. \n') # true or false depending on whether nnlo exists nnlo_existence = fnlo.SetContributionON(fastnlo.kFixedOrder, 2, True) if (nnlo_existence == False): - print "No NNLO entry in given table. Plotting only NLO/LO." + print("No NNLO entry in given table. Plotting only NLO/LO.") elif (nnlo_existence == True): - print "Table contains NNLO entry." + print("Table contains NNLO entry.") # cross section for all 3 orders xs_list = [] for n in orders: for j in range(0, 3): fnlo.SetContributionON(fastnlo.kFixedOrder, j, orders[n][j]) - print '\n' - print 'Calc XS for order: %s' % n, '\n' + print('\n') + print('Calc XS for order: %s' % n, '\n') fnlo.CalcCrossSection() xs_list.append(fnlo.GetCrossSection()) xs_all = np.array(xs_list) - print 'Cross section with all subprocesses xs_all: \n' - print xs_all, '\n \n' + print('Cross section with all subprocesses xs_all: \n') + print(xs_all, '\n \n') # calculate k-facators fractions_three_plots = [] @@ -163,7 +163,7 @@ def main(): # kfactors: NLO/LO, NNLO/NLO, NNLO/LO fractions_three = np.array(fractions_three_plots) - print 'k-factors (line by line): NLO/LO, NNLO/NLO, NNLO/LO: \n', fractions_three + print('k-factors (line by line): NLO/LO, NNLO/NLO, NNLO/LO: \n', fractions_three) if (allplots == False): if high == 'NLO': @@ -207,7 +207,7 @@ def main(): # axis settings? color settings? bin_bounds = np.array(fnlo.GetObsBinsBounds(0)) - print 'bin bounds: ', bin_bounds.flatten() + print('bin bounds: ', bin_bounds.flatten()) xstart = bin_bounds.flatten()[0] xstop = bin_bounds.flatten()[-1] xaxis_ticks = np.linspace(xstart, xstop, num=5) @@ -219,30 +219,28 @@ def main(): # plot all the kfactors into one plot. can be changed to 3 plots by introducing some for-loop # if (args['numerator'] is None): #no specific order chosen if single_plot == False: - print 'Start plotting. \n' + print('Start plotting. \n') for k in range(0, 3): - print 'Current index in fractions array: ', k + print('Current index in fractions array: ', k) #c = next(color) c = colors_orders[labels[k]] - ax0.plot(bin_bounds.flatten(), steppify_bin(fractions_three[k]), - label=labels[k], color=c, alpha=1.0) +# ax0.plot(list(bin_bounds.flatten()), list(steppify_bin(fractions_three[k])), label=labels[k], color=c, alpha=1.0) # elif (args['numerator']) is not None: else: # plot specific chosen order (or NLO/LO in case there is no NNLO) - print 'Start plotting of chosen kfactor. \n' - ax0.plot(bin_bounds.flatten(), steppify_bin(fraction_single), - label=label_single, color='g', alpha=1.0) + print('Start plotting of chosen kfactor. \n') +# ax0.plot(list(bin_bounds.flatten()), list(steppify_bin(fraction_single)), label=label_single, color='g', alpha=1.0) # get limits for axes: xlim = ax0.get_xlim() ylim = ax0.get_ylim() - print 'xlim: ', xlim - print 'ylim: ', ylim, '\n' + print('xlim: ', xlim) + print('ylim: ', ylim, '\n') # settings for the whole plot - ax0.set_xscale('log', nonposx='clip') + ax0.set_xscale('log') ax0.axis([xlim[0], xlim[1], ylim[0]-0.05, ylim[1]+0.05]) # flexible axis ax0.set_xlim(xlim[0], xlim[1]) # adjust x-axis # plt.xticks(xaxis_ticks, xaxis_ticks @@ -277,7 +275,7 @@ def main(): plotname = '%s.kfactor.png' % tablename fig0.savefig(plotname, bbox_inches='tight') - print 'k-factor plot saved as: %s' % plotname, '\n \n' + print('k-factor plot saved as: %s' % plotname, '\n \n') ########################################################