Belle II Software  release-08-01-10
background_bhabha_generation.py
1 
8 
9 import sys
10 import basf2
11 
12 if len(sys.argv) != 2:
13  print("Usage: {} [bbbrem|bhwide|bhwide_largeangle]".format(sys.argv[0]), file=sys.stderr)
14  sys.exit(1)
15 
16 generator = sys.argv[1].lower()
17 
18 kill = basf2.create_path()
19 main = basf2.create_path()
20 main.add_module("EventInfoSetter", expList=0, runList=1, evtNumList=1000000)
21 main.add_module("EventInfoPrinter")
22 
23 basf2.set_log_level(basf2.LogLevel.DEBUG)
24 basf2.set_debug_level(250)
25 basf2.logging.package("framework").log_level = basf2.LogLevel.WARNING
26 
27 
28 def add_cut(name, minParticles, maxParticles, minTheta, maxTheta=None):
29  """Add a generator level cut and kill the event if the cut is not passed. In
30  this case the cut is on the min/max charged particles which have a
31  center-of-mass theta angle between minTheta and maxTheta. If maxTheta is not
32  given assume it to be 180-minTheta for a symmetric window"""
33 
34  # if only one angle make it symmetric
35  if maxTheta is None:
36  maxTheta = 180 - minTheta
37  selection = main.add_module("GeneratorPreselection", applyInCMS=True, nChargedMin=minParticles, nChargedMax=maxParticles,
38  MinChargedTheta=minTheta, MaxChargedTheta=maxTheta, MinChargedP=0., MinChargedPt=0.)
39  selection.if_value("!=11", kill)
40  selection.set_name("generator cut: " + name)
41 
42 
43 if generator == "bbbrem":
44  main.add_module("BBBremInput", MinPhotonEnergyFraction=0.000001, Unweighted=True, MaxWeight=1.57001e+07)
45  # at least one track below 0.5 degree means maximum one particle in 0.5-179.5
46  add_cut("at least one track below 0.5 degree", 0, 1, 0.5)
47 elif generator == "bhwide":
48  main.add_module("BHWideInput", ScatteringAngleRangeElectron=[0.5, 179.5], ScatteringAngleRangePositron=[0.5, 179.5])
49  add_cut("both tracks at least 0.5 degree", 2, 2, 0.5)
50  # but if one is above 1 and the other above 10 degree so we in 1-170 and
51  # 10-179
52  add_cut("max one track in 1-170", 0, 1, 1, 170)
53  add_cut("max one track in 10-179", 0, 1, 10, 179)
54 elif generator == "bhwide_largeangle":
55  main.add_module("BHWideInput", ScatteringAngleRangeElectron=[0.5, 179.5], ScatteringAngleRangePositron=[0.5, 179.5])
56  add_cut("both tracks at least 1 degree", 2, 2, 1)
57  add_cut("at least one 10 degree", 1, 2, 10)
58 else:
59  print("unknown generation setting: {}".format(generator))
60 
61 main.add_module("Progress")
62 main.add_module("RootOutput", outputFileName="%s.root" % generator)
63 basf2.process(main)
64 print(basf2.statistics)