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