Belle II Software development
B2A424-OrcaKinFit_vertexfit_4Cfit.py
1#!/usr/bin/env python3
2
3
10
11
25
26#
27# Import and mdst loading
28#
29import basf2 as b2
30from modularAnalysis import inputMdst
31from modularAnalysis import fillParticleList
32from modularAnalysis import reconstructDecay
33from modularAnalysis import matchMCTruth
34from vertex import raveFit
35from kinfit import fitKinematic4C
36from modularAnalysis import variablesToNtuple
37import pdg
38import variables.collections as vc
39import variables.utils as vu
40
41# create path
42my_path = b2.create_path()
43
44# load input ROOT file
45inputMdst(filename=b2.find_file('darkphotonmumu_mdst.root', 'examples', False),
46 path=my_path)
47
48# Creates a list of good photon and muons
49fillParticleList("gamma:sel", 'E > 0.1 and abs(formula(clusterTiming/clusterErrorTiming)) < 1.0', path=my_path)
50fillParticleList("mu-:sel", 'electronID < 0.01 and chiProb > 0.001 and abs(dz) < 3 and dr < 0.1', path=my_path)
51pdg.add_particle('A', 9000008, 999., 999., 0, 0) # name, PDG, mass, width, charge, spin
52reconstructDecay("A:sel -> mu-:sel mu+:sel", "", path=my_path)
53reconstructDecay("A:selvertex -> mu-:sel mu+:sel", "", path=my_path)
54
55# Perform four momentum constraint fit using Rave and update the Daughters
56raveFit("A:selvertex", -1.0, constraint="iptube", daughtersUpdate=True, path=my_path)
57
58pdg.add_particle('beam', 9000009, 999., 999., 0, 0) # name, PDG, mass, width, charge, spin
59reconstructDecay("beam:sel -> A:sel gamma:sel", "", path=my_path)
60reconstructDecay("beam:selv -> A:selvertex gamma:sel", "", path=my_path)
61reconstructDecay("beam:selv4c -> A:selvertex gamma:sel", "", path=my_path)
62
63# Associates the MC truth
64matchMCTruth('beam:sel', path=my_path)
65matchMCTruth('beam:selv', path=my_path)
66matchMCTruth('beam:selv4c', path=my_path)
67
68# Perform four momentum constraint fit using OrcaKinFit and update the Daughters
69fitKinematic4C("beam:selv4c", path=my_path)
70
71# Select variables that we want to store to ntuple
72muvars = vc.kinematics + vc.mc_truth + vc.mc_kinematics + vc.pid + vc.momentum_uncertainty
73gammavars = vc.inv_mass + vc.kinematics + vc.mc_kinematics + vc.mc_truth + vc.momentum_uncertainty
74avars = vc.inv_mass + vc.kinematics + vc.mc_kinematics + vc.mc_truth + vc.momentum_uncertainty
75uvars = vc.inv_mass + vc.kinematics + vc.mc_kinematics + vc.mc_truth + \
76 vu.create_aliases_for_selected(muvars, 'beam -> [A -> ^mu+ ^mu-] gamma') + \
77 vu.create_aliases_for_selected(gammavars, 'beam -> A ^gamma') + \
78 vu.create_aliases_for_selected(avars, 'beam -> ^A gamma')
79
80uvarsv = uvars + ['chiProb']
81
82uvars4c = uvars + ['OrcaKinFitProb', 'OrcaKinFitProb', 'OrcaKinFitChi2', 'OrcaKinFitErrorCode'] + \
83 vu.create_aliases(['VertexFitChi2',
84 'VertexFitProb'], 'daughter(1, extraInfo({variable}))', "A")
85
86# Saving variables to ntuple
87output_file = 'B2A424-OrcaKinFit_vertexfit_4Cfit.root'
88variablesToNtuple('beam:selv4c', uvars4c,
89 filename=output_file, treename='beamselv4c', path=my_path)
90variablesToNtuple('beam:selv', uvarsv,
91 filename=output_file, treename='beamselv', path=my_path)
92variablesToNtuple('beam:sel', uvarsv,
93 filename=output_file, treename='beamsel', path=my_path)
94
95#
96# Process and print statistics
97#
98
99# Process the events
100b2.process(my_path)
101# print out the summary
102print(b2.statistics)
def add_particle(name, pdgCode, mass, width, charge, spin, max_width=None, lifetime=0, pythiaID=0, define_anti_particle=False)
Definition: pdg.py:135