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