Belle II Software development
test_continuum_gen_and_fragmentation.py
1
8
9'''Test for checking if the continuum generation and fragmentation works.'''
10
11import basf2 as b2
12import b2test_utils as b2tu
13from generators import add_continuum_generator, get_default_decayfile
14import pdg
15
16
17def run_continuum_generation(finalstate):
18 with b2tu.clean_working_directory():
19 n_events = 100
20 b2.set_random_seed(57)
21 main = b2.Path()
22 main.add_module('EventInfoSetter')
23 add_continuum_generator(
24 finalstate=finalstate,
25 path=main,
26 )
27 b2.process(main, n_events)
28
29
30def run_fragmentation_with_add_particles():
31 with b2tu.clean_working_directory():
32 n_events = 100
33 b2.set_random_seed(57)
34 pdg.add_particle("ALP", 9000005, 0, 0, 0, 0)
35
36 main = b2.Path()
37 main.add_module('EventInfoSetter')
38
39 kkmc_inputfile = b2.find_file('data/generators/kkmc/ccbar_nohadronization.input.dat')
40 kkmc_logfile = 'kkmc_ccbar.txt'
41 kkmc_config = b2.find_file('data/generators/kkmc/KK2f_defaults.dat')
42 # use KKMC to generate ccbar events (no fragmentation at this stage)
43 main.add_module(
44 'KKGenInput',
45 tauinputFile=kkmc_inputfile,
46 KKdefaultFile=kkmc_config,
47 taudecaytableFile='',
48 kkmcoutputfilename=kkmc_logfile,
49 eventType="ccbar",
50 )
51
52 pythia_config = b2.find_file('data/generators/modules/fragmentation/pythia_belle2_charm.dat')
53 decay_user = b2.find_file('data/generators/modules/fragmentation/dec_belle2_qqbar.dec')
54 decay_file = get_default_decayfile()
55 # add the fragmentation module to fragment the generated quarks into hadrons
56 # using PYTHIA8
57 main.add_module(
58 'Fragmentation',
59 ParameterFile=pythia_config,
60 ListPYTHIAEvent=0,
61 UseEvtGen=1,
62 DecFile=decay_file,
63 UserDecFile=decay_user,
64 # Would be better to use the ALP here as well, but this makes the generation more complex
65 QuarkPairMotherParticle=23,
66 AdditionalPDGCodes=[9000005],
67 )
68 b2.process(main, n_events)
69
70
71for final_state in ["uubar", "ddbar", "ssbar", "ccbar"]:
72 b2.B2INFO(f'Running the test for continuum generation and final state {final_state}')
73 return_code = b2tu.run_in_subprocess(target=run_continuum_generation, finalstate=final_state)
74 if return_code != 0:
75 b2.B2FATAL(
76 f'Continuum generation fails when generating events for final state {final_state}')
77
78b2.B2INFO('Running the test for fragmentation with additional particles')
79return_code = b2tu.run_in_subprocess(target=run_fragmentation_with_add_particles)
80if return_code != 0:
81 b2.B2FATAL('Fragmentation fails when adding additional particles to Pythia')
add_particle(name, pdgCode, mass, width, charge, spin, max_width=None, lifetime=0, pythiaID=0, define_anti_particle=False)
Definition pdg.py:135