Belle II Software  release-06-02-00
029_roe.py
1 #!/usr/bin/env python3
2 
3 import sys
4 import basf2 as b2
5 import modularAnalysis as ma
6 import stdV0s
7 import variables.collections as vc
8 import variables.utils as vu
9 
10 # get input file number from the command line
11 filenumber = sys.argv[1]
12 
13 # create path
14 main = b2.Path()
15 
16 # load input data from mdst/udst file
17 ma.inputMdstList(
18  environmentType="default",
19  filelist=[b2.find_file(f"starterkit/2021/1111540100_eph3_BGx0_{filenumber}.root", "examples")],
20  path=main,
21 )
22 
23 # fill final state particle lists
24 ma.fillParticleList(
25  "e+:uncorrected",
26  "electronID > 0.1 and dr < 0.5 and abs(dz) < 2 and thetaInCDCAcceptance",
27  path=main,
28 )
29 stdV0s.stdKshorts(path=main)
30 
31 # combine final state particles to form composite particles
32 ma.reconstructDecay(
33  "J/psi:ee -> e+:uncorrected e-:uncorrected", cut="dM < 0.11", path=main
34 )
35 
36 # combine J/psi and KS candidates to form B0 candidates
37 ma.reconstructDecay(
38  "B0 -> J/psi:ee K_S0:merged",
39  cut="Mbc > 5.2 and abs(deltaE) < 0.15",
40  path=main,
41 )
42 
43 # match reconstructed with MC particles
44 ma.matchMCTruth("B0", path=main)
45 
46 # build the rest of the event
47 ma.buildRestOfEvent("B0", fillWithMostLikely=True, path=main)
48 track_based_cuts = "thetaInCDCAcceptance and pt > 0.075 and dr < 5 and abs(dz) < 10"
49 ecl_based_cuts = "thetaInCDCAcceptance and E > 0.05"
50 roe_mask = ("my_mask", track_based_cuts, ecl_based_cuts)
51 ma.appendROEMasks("B0", [roe_mask], path=main)
52 
53 # Create list of variables to save into the output file
54 b_vars = []
55 
56 standard_vars = vc.kinematics + vc.mc_kinematics + vc.mc_truth
57 b_vars += vc.deltae_mbc
58 b_vars += standard_vars
59 
60 # ROE variables
61 roe_kinematics = ["roeE()", "roeM()", "roeP()", "roeMbc()", "roeDeltae()"]
62 roe_multiplicities = [
63  "nROE_Charged()",
64  "nROE_Photons()",
65  "nROE_NeutralHadrons()",
66 ]
67 b_vars += roe_kinematics + roe_multiplicities
68 # Let's also add a version of the ROE variables that includes the mask:
69 for roe_variable in roe_kinematics + roe_multiplicities:
70  # e.g. instead of 'roeE()' (no mask) we want 'roeE(my_mask)'
71  roe_variable_with_mask = roe_variable.replace("()", "(my_mask)")
72  b_vars.append(roe_variable_with_mask)
73 
74 # Variables for final states (electrons, positrons, pions)
75 fs_vars = vc.pid + vc.track + vc.track_hits + standard_vars
76 b_vars += vu.create_aliases_for_selected(
77  fs_vars,
78  "B0 -> [J/psi -> ^e+ ^e-] [K_S0 -> ^pi+ ^pi-]",
79  prefix=["ep", "em", "pip", "pim"],
80 )
81 # Variables for J/Psi, KS
82 jpsi_ks_vars = vc.inv_mass + standard_vars
83 b_vars += vu.create_aliases_for_selected(jpsi_ks_vars, "B0 -> ^J/psi ^K_S0")
84 # Also add kinematic variables boosted to the center of mass frame (CMS)
85 # for all particles
86 cmskinematics = vu.create_aliases(
87  vc.kinematics, "useCMSFrame({variable})", "CMS"
88 )
89 b_vars += vu.create_aliases_for_selected(
90  cmskinematics, "^B0 -> [^J/psi -> ^e+ ^e-] [^K_S0 -> ^pi+ ^pi-]"
91 )
92 
93 # Save variables to an output file (ntuple)
94 ma.variablesToNtuple(
95  "B0",
96  variables=b_vars,
97  filename="Bd2JpsiKS.root",
98  treename="tree",
99  path=main,
100 )
101 
102 # Start the event loop (actually start processing things)
103 b2.process(main)
104 
105 # print out the summary
106 print(b2.statistics)
def stdKshorts(prioritiseV0=True, fitter='TreeFit', path=None)
Definition: stdV0s.py:17