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