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