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