Belle II Software  release-06-02-00
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(environmentType='default',
30  filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples', False),
31  path=my_path)
32 
33 # use standard final state particle lists
34 # creates "pi+:all" ParticleList (and c.c.)
35 ma.fillParticleListFromMC(decayString='pi+:gen', cut='', path=my_path)
36 
37 # ID of weight table is taken from B2A904
38 weight_table_id = "ParticleReweighting:TestMomentum"
39 
40 if not os.getenv('BELLE2_EXAMPLES_DATA_DIR'):
41  b2.B2FATAL("You need the example data installed. Run `b2install-data example` in terminal for it.")
42 
43 db_location = os.getenv('BELLE2_EXAMPLES_DATA_DIR') + '/database/'
44 b2.conditions.prepend_testing_payloads(db_location + 'database.txt')
45 
46 # We know what weight info will be added (see B2A904),
47 # so we add aliases and add it to the tools
48 va.variables.addAlias('Weight', 'extraInfo(' + weight_table_id + '_Weight)')
49 va.variables.addAlias('StatErr', 'extraInfo(' + weight_table_id + '_StatErr)')
50 va.variables.addAlias('SystErr', 'extraInfo(' + weight_table_id + '_SystErr)')
51 va.variables.addAlias('binID', 'extraInfo(' + weight_table_id + '_binID)')
52 
53 
54 # We configure weighing module
55 reweighter = b2.register_module('ParticleWeighting')
56 reweighter.param('tableName', weight_table_id)
57 reweighter.param('particleList', 'pi+:gen')
58 my_path.add_module(reweighter)
59 
60 
61 pivars = ['p', 'pz', 'Weight', 'StatErr', 'SystErr', 'binID']
62 
63 # Saving variables to ntuple
64 output_file = 'B2A905-ApplyWeightsToTracks.root'
65 ma.variablesToNtuple(decayString='pi+:gen',
66  variables=pivars,
67  treename='pion',
68  filename=output_file,
69  path=my_path)
70 
71 # Process the events
72 b2.process(my_path)
73 
74 # print out the summary
75 print(b2.statistics)