Belle II Software  release-08-01-10
chi2MCTrackMatcher.py
1 # Path building
2 from basf2 import create_path, register_module, LogLevel, process, statistics
3 
4 # analysis
5 from stdCharged import stdK, stdPi
6 import modularAnalysis as ma
7 import variables.collections as vc
8 import variables.utils as vu
9 
10 
11 NtupleFilePath = "/nfs/dust/belle2/user/floschw/Data/example_Ntuple_1000.root"
12 ROOTFilePath = "/nfs/dust/belle2/user/floschw/Data/simulation/sim_1000.root"
13 
14 path = create_path()
15 # Load a MDST Root file where relations from hit matching
16 # are excluded.
17 path.add_module("RootInput",
18  inputFileName=ROOTFilePath,
19  excludeBranchNames=["TracksToMCParticles"])
20 
21 # Add the Chi2-matcher to path
22 chi2Matcher = register_module("Chi2MCTrackMatcher")
23 
24 # Define input parameters
25 
26 # Chi2 Cut Off values.
27 # These are the reasonable default Cut Off values:
28 CutOffs = [128024, 95, 173, 424, 90, 424]
29 chi2Matcher.param("CutOffs", CutOffs)
30 # Package used for inversion of the covariance matrix:
31 # ROOT is default since in general it is faster and scales better
32 # False: ROOT [default]; True: eigen
33 chi2Matcher.param("linalg", False)
34 
35 # Shows some additional Debug messages
36 chi2Matcher.logging.log_level = LogLevel.DEBUG
37 chi2Matcher.logging.debug_level = 30
38 
39 # Add the Chi2-matcher module to the execution path
40 path.add_module(chi2Matcher)
41 
42 # Now you can do your reconstruction
43 # Here for example a reconstruction of a D*+ decay, for slow pion analysis
44 
45 stdPi("all", path=path)
46 stdK("good", path=path)
47 decaystring = "anti-B0 -> [D*+ -> [[D0 -> K-:good pi+:good] pi+:good] e-:good anit-nu_e"
48 # reconstruct the D0. Introduced a mass cut to clean mass distribution.
49 ma.reconstructDecay("D0 -> K-:good pi+:all", "1.85466<M<1.875", path=path)
50 ma.matchMCTruth("D0", path=path)
51 
52 # reconstruct the D*+
53 ma.reconstructDecay("D*+ -> D0 pi+:all", "", path=path)
54 ma.matchMCTruth("D*+", path=path)
55 
56 # collect variables nessesary for slow pion analysis
57 listofvariables = [
58  "E",
59  "M",
60  "PDG",
61  "isSignalAcceptMissing",
62  "d0",
63  "d0Err",
64  "omega",
65  "omegaErr",
66  "phi0",
67  "phi0Err",
68  "phi",
69  "phiErr",
70  "tanLambda",
71  "tanLambdaErr",
72  "z0",
73  "z0Err",
74  "theta",
75  "thetaErr",
76  "p",
77  "pErr",
78  "pt",
79  "ptErr",
80  "px",
81  "pxErr",
82  "py",
83  "pyErr",
84  "pz",
85  "pzErr",
86  "d0Pull",
87  "omegaPull",
88  "phi0Pull",
89  "tanLambdaPull",
90  "z0Pull",
91  "mcP",
92  "mcPT",
93  "mcPX",
94  "mcPY",
95  "mcPZ",
96  "mcDecayVertexX",
97  "mcDecayVertexY",
98  "mcDecayVertexZ",
99  "isSignal",
100  "mcErrors",
101  "mcPDG",
102  "charge"] + vc.mc_vertex
103 
104 # assign the variables to dacay particles
105 variables = vu.create_aliases(listofvariables, "{variable}", "Dstar")
106 variables += vu.create_aliases(listofvariables, "daughter(0,{variable})", "D0")
107 variables += vu.create_aliases(listofvariables, "daughter(1,{variable})", "Dstarpi")
108 
109 # save everything to an Ntuple
110 ma.variablesToNtuple("D*+",
111  variables=variables,
112  filename=NtupleFilePath,
113  treename="tree",
114  path=path)
115 
116 # process the path
117 process(path)
118 # show some module statistics
119 print(statistics)