Belle II Software  release-08-01-10
AafhGenerationWithPreselection.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
18 
19 from basf2 import set_log_level, LogLevel, create_path, process, register_module, statistics
20 
21 # suppress messages and during processing:
22 set_log_level(LogLevel.INFO)
23 
24 main = create_path()
25 
26 # event info setter
27 main.add_module("EventInfoSetter", expList=0, runList=1, evtNumList=100)
28 
29 # generator
30 aafh = register_module('AafhInput')
31 aafh.param({
32  # decay mode to generate.
33  # 1: e+e- -> mu+mu-L+L- where L is a user defined particle (default: tau)
34  # 2: e+e- -> mu+mu-mu+mu-
35  # 3: e+e- -> e+e-mu+mu-
36  # 4: e+e- -> e+e-L+L- where L is a user defined particle (default: tau)
37  # 5: e+e- -> e+e-e+e-
38  'mode': 5,
39  # to set the particle for modes 1 and 4 use set parameter "particle"
40  # rejection scheme to generate unweighted events
41  # 1: use rejection once for the final event weight
42  # 2: use rejection per sub generator and then for the final event
43  'rejection': 2,
44  # max subgenerator event weight, only used if rejection is set to 2
45  # (default). If this value is to low the generation will produce errors. If
46  # it is to high generation runs slower.
47  'maxSubgeneratorWeight': 1.0,
48  # max final event weight which is always used. If this value is to low the
49  # generation will produce errors. If it is to high generation runs slower.
50  # ==> should be around 2-4
51  'maxFinalWeight': 3.0,
52  # adjust subgenerator weights so that each sub generator has same
53  # probability to be called and the maximum weight is equal as well. These
54  # values are printed at the end of generation when output level is set to
55  # INFO. These weights strongly depend on the mode
56  'subgeneratorWeights': [
57  1.0,
58  7.986e+01,
59  5.798e+04,
60  3.898e+05,
61  1.0,
62  1.664e+00,
63  2.812e+00,
64  7.321e-01,
65  ],
66  # set to awfully precise
67  'suppressionLimits': [1e100] * 4,
68  # minimum invariant mass of the secondary pair
69  'minMass': 0.50,
70 })
71 aafh.logging.log_level = LogLevel.INFO
72 
73 # preselection to reject no tag events
74 generatorpreselection = register_module('GeneratorPreselection')
75 generatorpreselection.param('nChargedMin', 1)
76 # generatorpreselection.param('nChargedMax', 999)
77 generatorpreselection.param('MinChargedP', 0.25)
78 generatorpreselection.param('MinChargedPt', 0.1)
79 generatorpreselection.param('MinChargedTheta', 17.)
80 generatorpreselection.param('MaxChargedTheta', 150.)
81 generatorpreselection.param('nPhotonMin', 1)
82 # generatorpreselection.param('nPhotonMax', 999)
83 generatorpreselection.param('MinPhotonEnergy', 0.50)
84 generatorpreselection.param('MinPhotonTheta', 15.)
85 generatorpreselection.param('MaxPhotonTheta', 170.)
86 
87 # print generated particles
88 mcparticleprinter = register_module('PrintMCParticles')
89 mcparticleprinter.logging.log_level = LogLevel.INFO
90 
91 output = register_module('RootOutput')
92 output.param('outputFileName', './aafh_out.root')
93 
94 # creating the path for the processing
95 main.add_module(aafh)
96 main.add_module(generatorpreselection)
97 # create an empty path and check the return value of the the preselection
98 emptypath = create_path()
99 generatorpreselection.if_value('<1', emptypath)
100 # continue the main path otherwise (e.g. call detector simulation)
101 main.add_module(mcparticleprinter)
102 main.add_module(output)
103 
104 # process the events
105 process(main)
106 
107 # show call statistics
108 print(statistics)