Belle II Software  release-06-02-00
MadGraph_sm_uubar.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
18 
19 from basf2 import *
20 from beamparameters import add_beamparameters
21 import os
22 import subprocess
23 
24 # parameters that can be modified
25 mg_nevents = '100'
26 mg_beamenergy = '10.355/2.'
27 mg_generate = 'e+ e- > u u~'
28 mg_seed = '1'
29 
30 # full path to steering template file (full path to model must be inside the template steering file)
31 mg_steeringtemplate = \
32  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/examples/run_sm.steeringtemplate'
33  )
34 
35 # full path to output directory
36 mg_outputdir = \
37  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/output/sm_qqbar')
38 
39 # -------------------------------------------------------
40 # no user input needed below this line
41 
42 # full path to MadGraph externals
43 mg_externals = 'mg5_aMC'
44 
45 # full path to steering file (generated automatically, will be overwritten (if existing) or created)
46 mg_steeringfile = \
47  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/examples/run_sm_uubar.steering'
48  )
49 
50 # full path to run card (param_card is generated automatically, defaults are overwritten in the steering file)
51 mg_runcard = \
52  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/cards/run_card.dat'
53  )
54 
55 # Replace the output directory and the run card
56 mydict = {}
57 mydict['MGOUTPUT'] = mg_outputdir
58 mydict['MGRUNDCARD'] = mg_runcard
59 mydict['MGNEVENTS'] = mg_nevents
60 mydict['MGBEAMENERGY'] = mg_beamenergy
61 mydict['MGGENERATE'] = mg_generate
62 mydict['MGSEED'] = mg_seed
63 
64 fp1 = open(mg_steeringfile, 'w')
65 fp2 = open(mg_steeringtemplate, 'r')
66 data = fp2.read()
67 fp2.close()
68 for (key, value) in mydict.items():
69  data = data.replace(key, value)
70 fp1.write(data)
71 fp1.close()
72 
73 # run MadGraph
74 subprocess.check_call([mg_externals, mg_steeringfile])
75 
76 # gunzip the unweighted output file
77 subprocess.check_call(['gunzip', mg_outputdir + '/Events/run_01/unweighted_events.lhe.gz'])
78 
79 # creating the path for the processing
80 set_log_level(LogLevel.ERROR)
81 
82 # creating the path for the processing
83 main = create_path()
84 
85 # beam parameters
86 beamparameters = add_beamparameters(main, "Y3S")
87 
88 lhereader = register_module('LHEInput')
89 lhereader.param('makeMaster', True)
90 lhereader.param('runNum', 1)
91 lhereader.param('expNum', 1)
92 lhereader.param('inputFileList', [mg_outputdir + '/Events/run_01/unweighted_events.lhe'])
93 lhereader.param('useWeights', False)
94 lhereader.param('nInitialParticles', 2)
95 lhereader.param('nVirtualParticles', 0)
96 lhereader.param('boost2Lab', False)
97 lhereader.param('wrongSignPz', True)
98 
99 # Add lhereader module
100 main.add_module(lhereader)
101 print_params(lhereader)
102 
103 # Add progress module
104 progress = register_module('Progress')
105 progress.set_log_level(LogLevel.INFO)
106 main.add_module(progress)
107 
108 # Add rootoutput module
109 rootoutput = register_module('RootOutput')
110 rootoutput.param('outputFileName', 'LHEReaderMasterOutputSM.root')
111 main.add_module(rootoutput)
112 
113 # Add mcparticleprinter module
114 # main.add_module('PrintMCParticles', logLevel=LogLevel.DEBUG, onlyPrimaries=False)
115 
116 # Process
117 process(main)