Belle II Software  release-08-01-10
B2A905-ApplyWeightsToTracks.py
1 #!/usr/bin/env python3
2 
3 
10 
11 
19 
20 import basf2 as b2
21 import modularAnalysis as ma
22 import variables as va
23 import os
24 
25 # create path
26 my_path = b2.create_path()
27 
28 # load input ROOT file
29 ma.inputMdst(filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples', False),
30  path=my_path)
31 
32 # use standard final state particle lists
33 # creates "pi+:all" ParticleList (and c.c.)
34 ma.fillParticleListFromMC(decayString='pi+:gen', cut='', path=my_path)
35 
36 # ID of weight table is taken from B2A904
37 weight_table_id = "ParticleReweighting:TestMomentum"
38 
39 if not os.getenv('BELLE2_EXAMPLES_DATA_DIR'):
40  b2.B2FATAL("You need the example data installed. Run `b2install-data example` in terminal for it.")
41 
42 db_location = os.getenv('BELLE2_EXAMPLES_DATA_DIR') + '/database/'
43 b2.conditions.prepend_testing_payloads(db_location + 'database.txt')
44 
45 # We know what weight info will be added (see B2A904),
46 # so we add aliases and add it to the tools
47 va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)')
48 va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)')
49 va.variables.addAlias('SystErr', 'extraInfo(' + weight_table_id + '_SystErr)')
50 va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)')
51 
52 
53 # We configure weighing module
54 reweighter = b2.register_module('ParticleWeighting')
55 reweighter.param('tableName', weight_table_id)
56 reweighter.param('particleList', 'pi+:gen')
57 my_path.add_module(reweighter)
58 
59 
60 pivars = ['p', 'pz', 'Weight', 'StatErr', 'SystErr', 'binID']
61 
62 # Saving variables to ntuple
63 output_file = 'B2A905-ApplyWeightsToTracks.root'
64 ma.variablesToNtuple(decayString='pi+:gen',
65  variables=pivars,
66  treename='pion',
67  filename=output_file,
68  path=my_path)
69 
70 # Process the events
71 b2.process(my_path)
72 
73 # print out the summary
74 print(b2.statistics)