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