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