Belle II Software  release-08-01-10
variablesToEventBasedTree.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # The VariablesToEventBasedTree module saves variables from the VariableManager
12 # to an event-based TTree
13 #
14 # For full documentation please refer to https://software.belle2.org
15 # Anything unclear? Ask questions at https://questions.belle2.org
16 
17 import basf2
18 import modularAnalysis as ma # a shorthand for the analysis tools namespace
19 
20 mypath = basf2.Path() # create a new path
21 
22 # add input data and ParticleLoader modules to the path
23 ma.inputMdstList([basf2.find_file('analysis/tests/mdst.root')], path=mypath)
24 ma.fillParticleLists([('K-', 'kaonID > 0.2'), ('pi+', 'pionID > 0.2')], path=mypath)
25 ma.reconstructDecay('D0 -> K- pi+', '1.750 < M < 1.95', path=mypath)
26 ma.matchMCTruth('D0', path=mypath)
27 
28 # This will write out one row per event in the TTree
29 # The branches of the TTree are arrays containing the variables for each D0 candidate in the event
30 # The event_variables are handled differently, the branches of these event_variables are just floats,
31 # you can use this to write out candidate independent information (aka event-based variables)
32 mypath.add_module('VariablesToEventBasedTree',
33  particleList='D0',
34  variables=['dM', 'isSignal', 'mcErrors', 'p', 'E',
35  'daughter(0, kaonID)', 'daughter(1, pionID)'],
36  event_variables=['nTracks', 'isMC'])
37 # It's possible to have multiple event-based trees in the same output file.
38 # Of course their names have to be different.
39 mypath.add_module('VariablesToEventBasedTree',
40  particleList='K-',
41  treeName='kaon',
42  variables=['isSignal', 'mcErrors', 'p', 'E', 'kaonID'],
43  event_variables=['nTracks', 'isMC'])
44 
45 # process the data
46 basf2.process(mypath)
47 print(basf2.statistics)