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