Belle II Software  release-05-01-25
MadGraph_darkphoton_isr.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Usage: basf2 MadGraph_darkphoton_isr.py 0 (or 1) for ISR Off (or On)
4 
16 
17 # NOTICE!
18 # Please be careful to set the MG parameters listed below, including "mg_el"... "mg_bwcutoff" etc.
19 # Especially all these rapidity cuts and minium energy requirements change the cross sections.
20 
21 
22 from basf2 import *
23 from beamparameters import add_beamparameters
24 import os
25 import subprocess
26 
27 if len(sys.argv) < 2:
28  print('Please provide ISR parameter')
29  sys.exit()
30 if sys.argv[1] == "1":
31  print('ISR is on')
32 if sys.argv[1] == "0":
33  print('ISR is off')
34 
35 # parameters that can be modified
36 isr = int(sys.argv[1])
37 
38 if isr == 1:
39  mg_lpp1 = '3'
40  mg_lpp2 = '-3'
41 else:
42  mg_lpp1 = '0'
43  mg_lpp2 = '0'
44 
45 mg_nevents = '100'
46 mg_beamenergy = '10.58/2.'
47 mg_generate = 'e+ e- > a ap, ap > mu+ mu-'
48 mg_parameter_wap = '0.03102254'
49 mg_parameter_map = '1.0e0'
50 mg_seed = '1'
51 mg_ge = '0.3028177'
52 mg_gchi = '0.0'
53 mg_el = '0.2'
54 mg_ea = '0.2'
55 mg_etaa = '3.13'
56 mg_etal = '3.13'
57 mg_mll = '0.2'
58 mg_bwcutoff = '200.'
59 
60 mg_model = \
61  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/models/darkphoton'
62  )
63 
64 # full path to steering template file (full path to model must be inside the template steering file)
65 if isr == 1:
66  mg_steeringtemplate = \
67  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/examples/run_darkphoton_isr.steeringtemplate'
68  )
69 else:
70  mg_steeringtemplate = \
71  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/examples/run_darkphoton.steeringtemplate'
72  )
73 
74 # full path to output directory
75 mg_outputdir = \
76  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/output/darkphoton_mumu'
77  )
78 
79 # -------------------------------------------------------
80 # no user input needed below this line
81 
82 # full path to MadGraph externals
83 mg_externals = 'mg5_aMC'
84 
85 # full path to steering file (generated automatically, will be overwritten (if existing) or created)
86 mg_steeringfile = \
87  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/examples/run_darkphoton.steering'
88  )
89 
90 # full path to run card (param_card is generated automatically, defaults are overwritten in the steering file)
91 mg_runcard = \
92  os.path.expandvars('$BELLE2_LOCAL_DIR/generators/madgraph/cards/run_card.dat'
93  )
94 
95 # Replace the output directory and the run card
96 mydict = {}
97 mydict['MGMODEL'] = mg_model
98 mydict['MGOUTPUT'] = mg_outputdir
99 mydict['MGRUNDCARD'] = mg_runcard
100 mydict['MGNEVENTS'] = mg_nevents
101 mydict['MGBEAMENERGY'] = mg_beamenergy
102 mydict['MGGENERATE'] = mg_generate
103 mydict['MGPARAMETERWAP'] = mg_parameter_wap
104 mydict['MGPARAMETERMAP'] = mg_parameter_map
105 mydict['MGSEED'] = mg_seed
106 mydict['MGlpp1'] = mg_lpp1
107 mydict['MGlpp2'] = mg_lpp2
108 mydict['MGge'] = mg_ge
109 mydict['MGgchi'] = mg_gchi
110 mydict['MGel'] = mg_el
111 mydict['MGea'] = mg_ea
112 mydict['MGetaa'] = mg_etaa
113 mydict['MGetal'] = mg_etal
114 mydict['MGmll'] = mg_mll
115 mydict['MGbwcutoff'] = mg_bwcutoff
116 
117 fp1 = open(mg_steeringfile, 'w')
118 fp2 = open(mg_steeringtemplate, 'r')
119 data = fp2.read()
120 fp2.close()
121 for (key, value) in mydict.items():
122  data = data.replace(key, value)
123 fp1.write(data)
124 fp1.close()
125 
126 # run MadGraph
127 subprocess.check_call([mg_externals, mg_steeringfile])
128 
129 # gunzip the unweighted output file
130 subprocess.check_call(['gunzip', mg_outputdir + '/Events/run_01/unweighted_events.lhe.gz'])
131 
132 
133 # creating the path for the processing
134 set_log_level(LogLevel.ERROR)
135 
136 # creating the path for the processing
137 main = create_path()
138 
139 # beam parameters
140 beamparameters = add_beamparameters(main, "Y4S")
141 
142 lhereader = register_module('LHEInput')
143 lhereader.param('makeMaster', True)
144 lhereader.param('inputFileList', [mg_outputdir + '/Events/run_01/unweighted_events.lhe'])
145 lhereader.param('useWeights', False)
146 lhereader.param('nInitialParticles', 2)
147 lhereader.param('nVirtualParticles', 0)
148 lhereader.param('boost2Lab', True)
149 lhereader.param('wrongSignPz', True)
150 
151 
152 # Add lhereader module
153 main.add_module(lhereader)
154 print_params(lhereader)
155 
156 # Add progress module
157 progress = register_module('Progress')
158 progress.set_log_level(LogLevel.INFO)
159 main.add_module(progress)
160 
161 # Add rootoutput module
162 rootoutput = register_module('RootOutput')
163 rootoutput.param('outputFileName', 'LHEReaderMasterOutputDarkMuMu.root')
164 main.add_module(rootoutput)
165 
166 # Add mcparticleprinter module
167 main.add_module('PrintMCParticles', logLevel=LogLevel.DEBUG,
168  onlyPrimaries=False)
169 
170 # Process
171 process(main)