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