Belle II Software  release-08-00-10
MadGraph_darkphoton.py
1 
8 
9 import hashlib
10 import os
11 import subprocess
12 
13 import basf2 as b2
14 import pdg
15 
16 
17 # Check the basf2 location
18 basf2_dir = os.environ.get('BELLE2_LOCAL_DIR', os.environ.get('BELLE2_RELEASE_DIR'))
19 
20 # Generation parameters
21 mg_steeringtemplate = f'{basf2_dir}/generators/madgraph/examples/run_darkphoton.steeringtemplate'
22 mg_nevents = '1000'
23 mg_beamenergy = '10.579558/2.'
24 b2_seed = b2.get_random_seed().encode('utf-8')
25 mg_seed = f'{int(hashlib.sha256(b2_seed).hexdigest(), 16) % 10**8}'
26 
27 # Models parameters
28 mg_model = f'{basf2_dir}/generators/madgraph/models/Dark_photon_UFO'
29 mg_generate = 'e+ e- > a ap, ap > DM DM~'
30 mAp = 1.0
31 mg_parameter_mAp = str(mAp)
32 mg_parameter_mDM = str(mAp / 3.0)
33 mg_parameter_gDM = '0.1'
34 mg_parameter_kappa = '0.001'
35 # this sets the width to 1 keV: switch to 'auto' for allowing MadGraph to compute the width using mAp, mDM and gDM
36 mg_parameter_wAp = '0.000001'
37 
38 # Path to output directory
39 mg_output = f'Dark_photon_mass_{int(mAp)}'
40 if not os.path.exists(mg_output):
41  os.mkdir(mg_output)
42 else:
43  import shutil # nowa
44  shutil.rmtree(mg_output, ignore_errors=True)
45  os.mkdir(mg_output)
46 
47 # Other stuffs
48 mg_externals = 'mg5_aMC' # MadGraph executable (from the externals)
49 mg_steeringfile = f'{mg_output}/run_darkphoton.steering' # MadGraph steering file (will be created on-the-fly later)
50 # MadGraph run_card to be used (param_card is generated automatically)
51 mg_runcard = f'{basf2_dir}/generators/madgraph/cards/run_card.dat'
52 
53 # Write the MadGraph steering file
54 mydict = {
55  'MGMODEL': mg_model,
56  'MGGENERATE': mg_generate,
57  'MGOUTPUT': mg_output,
58  'MGRUNDCARD': mg_runcard,
59  'MGBEAMENERGY': mg_beamenergy,
60  'MGNEVENTS': mg_nevents,
61  'MGSEED': mg_seed,
62  'MGPARAMETER_mAp': mg_parameter_mAp,
63  'MGPARAMETER_wAp': mg_parameter_wAp,
64  'MGPARAMETER_mDM': mg_parameter_mDM,
65  'MGPARAMETER_gDM': mg_parameter_gDM,
66  'MGPARAMETER_kappa': mg_parameter_kappa,
67 }
68 with open(mg_steeringtemplate, 'r') as template:
69  data = template.read()
70  for (key, value) in mydict.items():
71  data = data.replace(key, value)
72 steering = open(mg_steeringfile, 'w')
73 steering.write(data)
74 steering.close()
75 
76 # Run MadGraph and "gunzip" output file
77 subprocess.check_call([mg_externals, mg_steeringfile])
78 subprocess.check_call(['gunzip', f'{mg_output}/Events/run_01/unweighted_events.lhe.gz'])
79 
80 # Run basf2
81 pdg.add_particle('Ap', 4900023, mAp, 0.000001, 0, 2)
82 pdg.add_particle('DM', 4900101, mAp / 3.0, 0.000001, 0, 1)
83 pdg.add_particle('anti-DM', -4900101, mAp / 3.0, 0.000001, 0, 1)
84 
85 main = b2.Path()
86 
87 main.add_module('LHEInput',
88  expNum=0,
89  runNum=0,
90  inputFileList=b2.find_file(f'{mg_output}/Events/run_01/unweighted_events.lhe'),
91  makeMaster=True,
92  useWeights=False,
93  nInitialParticles=2,
94  nVirtualParticles=1,
95  wrongSignPz=True)
96 
97 main.add_module('BoostMCParticles')
98 
99 main.add_module('SmearPrimaryVertex')
100 
101 main.add_module('Progress')
102 
103 main.add_module('RootOutput',
104  outputFileName=f'Dark_photon_mass_{int(mAp)}.root')
105 
106 b2.process(main)
def add_particle(name, pdgCode, mass, width, charge, spin, max_width=None, lifetime=0, pythiaID=0, define_anti_particle=False)
Definition: pdg.py:134