Belle II Software  release-06-02-00
B2A906-EnergyBiasCorrection.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 import modularAnalysis as ma
13 import variables as va
14 import os
15 
16 # define scale tests
17 sys_tests = ['def', 'scale']
18 
19 # Select the variation from the list
20 test = 'scale'
21 
22 if test not in sys_tests:
23  print(f"Unknown systematic test {test}")
24  exit(1)
25 
26 # create path
27 my_path = b2.create_path()
28 
29 # load input ROOT file
30 ma.inputMdst(environmentType='default',
31  filename=b2.find_file('B02D0pi0_D02pi0pi0.root', 'examples', False),
32  path=my_path)
33 
34 # ID of weight table
35 weight_table_id = "PhotonEnergyBiasCorrection_Feb2021"
36 
37 b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
38 
39 # We know what weight info will be added,
40 # so we add aliases and add it to the tools
41 va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)')
42 va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)')
43 va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)')
44 
45 # fill particleLists
46 GammaSelection = 'theta > 0.296706 and theta < 2.6179'
47 ma.fillParticleList(decayString='gamma:sel',
48  cut=GammaSelection,
49  path=my_path)
50 
51 if test == 'def':
52  pass
53 elif test == 'scale':
54  # The scaling must only be applied to collision data, but not to MC.
55  # In principle, it can be run for MC as well because internally MC events are skipped anyway.
56  # However, it's better (faster, no error message) to skip the energy scaling in the steering file when running over MC.
57  # weight_table_id+"_Weight" is used to scale photon energy
58  ma.correctEnergyBias(inputListNames=['gamma:sel'], tableName=weight_table_id, path=my_path)
59 
60 var1 = ['M',
61  'p',
62  'E', 'Weight', 'StatErr', 'binID'
63  ]
64 
65 
66 ma.variablesToNtuple(decayString='gamma:sel',
67  variables=var1,
68  filename=f'gamma_{test}.root',
69  path=my_path)
70 
71 # process the events
72 b2.process(my_path)
73 
74 # print out the summary
75 print(b2.statistics)