Belle II Software  release-05-02-19
variablesToExtraInfo.py
1 #!/usr/bin/env python3
2 
3 # The VariablesToExtraInfo module saves variables at some stage in the
4 # processing chain for recovery later. In this example it saves the invariant
5 # mass of D0 candidates, before- and after- running a vertex fit. You could
6 # also use this to save electron energy (or dielectron q2) before- and after-
7 # running Bremsstrahlung correction or similar.
8 #
9 # Thomas Keck and Sam Cunliffe
10 #
11 # For full documentation please refer to https://software.belle2.org
12 # Anything unclear? Ask questions at https://questions.belle2.org
13 
14 import basf2
15 import modularAnalysis as ma # a shorthand for the analysis tools namespace
16 from vertex import kFit
17 
18 mypath = basf2.Path() # create a new path
19 
20 # add input data and ParticleLoader modules to the path
21 ma.inputMdstList('default', [basf2.find_file('analysis/tests/mdst.root')], path=mypath)
22 ma.fillParticleLists([('K-', 'kaonID > 0.2'), ('pi+', 'pionID > 0.2')], path=mypath)
23 ma.reconstructDecay('D0 -> K- pi+', '1.750 < M < 1.95', path=mypath)
24 ma.matchMCTruth('D0', path=mypath)
25 
26 # this saves the "pre-vertex fit" mass in the extraInfo() of the D0 particle
27 mypath.add_module('VariablesToExtraInfo',
28  particleList='D0',
29  variables={'M': 'M_before_vertex_fit'})
30 
31 # Now we do a vertex fit (this can change the mass).
32 # All candidates are kept.
33 kFit('D0', -1.0, path=mypath)
34 
35 # now save the pre- and post- fit mass using VariablesToNtuple
36 mypath.add_module('VariablesToNtuple',
37  particleList='D0',
38  variables=['M', 'extraInfo(M_before_vertex_fit)'])
39 
40 # It is important to understand that modules are loaded onto a basf2.Path by
41 # the modularAnalysis convenience functions (or by hand by you) and the order
42 # matters so you need to put VariablesToExtraInfo in the path *before* your
43 # processing which may alter variables.
44 #
45 # Here is an example of how to check this:
46 basf2.B2RESULT("Printing modules on the path")
47 for i, module in enumerate(mypath.modules()):
48  basf2.B2RESULT(i, " ", module.name())
49 # We use B2RESULT because it stands out in amongst the basf2 information.
50 # I could use python's native print()
51 
52 # process the data
53 basf2.process(mypath)
54 print(basf2.statistics)
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25