Belle II Software  release-05-01-25
B2A202-LoadReconstructedParticles.py
1 #!/usr/bin/env python3
2 
3 
22 
23 import basf2 as b2
24 import modularAnalysis as ma
25 import variables.collections as vc
26 import variables.utils as vu
27 from stdV0s import stdKshorts
28 from stdPi0s import stdPi0s
29 from stdKlongs import stdKlongs
30 
31 # create path
32 my_path = b2.create_path()
33 
34 # load input ROOT file
35 ma.inputMdst(environmentType='default',
36  filename=b2.find_file('B2pi0D_D2hh_D2hhh_B2munu.root', 'examples', False),
37  path=my_path)
38 
39 # print contents of the DataStore before loading Particles
40 ma.printDataStore(path=my_path)
41 
42 # create and fill gamma/e/mu/pi/K/p/n ParticleLists
43 # second argument are the selection criteria: '' means no cut, take all
44 #
45 # note that you can give any name to your lists e.g. 'gamma:mycandidates',
46 # except for the name 'all' which is the only name that is reserved for lists
47 # with no cuts
48 ma.fillParticleList(decayString='gamma:all', cut='', path=my_path)
49 ma.fillParticleList(decayString='e-:all', cut='', path=my_path)
50 ma.fillParticleList(decayString='mu-:all', cut='', path=my_path)
51 ma.fillParticleList(decayString='pi-:all', cut='', path=my_path)
52 ma.fillParticleList(decayString='K-:all', cut='', path=my_path)
53 ma.fillParticleList(decayString='anti-p-:all', cut='', path=my_path)
54 ma.fillParticleList(decayString='anti-n0:all', cut='', path=my_path)
55 
56 # alternatively, we can create and fill final state Particle lists only
57 # with candidates that pass certain PID requirements
58 ma.fillParticleList(decayString='gamma:highE', cut='E > 1.0', path=my_path)
59 ma.fillParticleList(decayString='e+:good', cut='electronID > 0.1', path=my_path)
60 ma.fillParticleList(decayString='mu+:good', cut='muonID > 0.1', path=my_path)
61 ma.fillParticleList(decayString='pi+:good', cut='protonID > 0.1', path=my_path)
62 ma.fillParticleList(decayString='K+:good', cut='kaonID > 0.1', path=my_path)
63 ma.fillParticleList(decayString='p+:good', cut='protonID > 0.1', path=my_path)
64 
65 # another possibility is to use default functions
66 # for example stdKshorts() from stdV0s.py that:
67 # - takes all V0 candidates, performs vertex fit, and fills 'K_S0:merged' ParticleList
68 # (-> for more details about V0s have a look at B2A203-LoadV0s.py)
69 # or for example stdPi0s() from stdPi0s.py:
70 stdKshorts(prioritiseV0=True, path=my_path)
71 stdPi0s(listtype='eff10_Jan2020Fit', path=my_path)
72 stdPi0s(listtype='eff20_Jan2020Fit', path=my_path)
73 stdPi0s(listtype='eff30_Jan2020Fit', path=my_path)
74 stdPi0s(listtype='eff40_Jan2020Fit', path=my_path)
75 stdPi0s(listtype='eff50_Jan2020Fit', path=my_path)
76 stdPi0s(listtype='eff60_Jan2020Fit', path=my_path)
77 stdKlongs(listtype='allklm', path=my_path) # only 'allklm' is recommended at the moment
78 
79 # print contents of the DataStore after loading Particles
80 ma.printDataStore(path=my_path)
81 
82 # print out the contents of each ParticleList
83 ma.printList('gamma:all', False, path=my_path)
84 ma.printList('gamma:highE', False, path=my_path)
85 ma.printList('e-:all', False, path=my_path)
86 ma.printList('e-:good', False, path=my_path)
87 ma.printList('mu-:all', False, path=my_path)
88 ma.printList('mu-:good', False, path=my_path)
89 ma.printList('pi-:all', False, path=my_path)
90 ma.printList('pi-:good', False, path=my_path)
91 ma.printList('K-:all', False, path=my_path)
92 ma.printList('K-:good', False, path=my_path)
93 ma.printList('anti-p-:all', False, path=my_path)
94 ma.printList('anti-p-:good', False, path=my_path)
95 ma.printList('K_S0:merged', False, path=my_path)
96 ma.printList('pi0:eff40_Jan2020Fit', False, path=my_path)
97 ma.printList('K_L0:allklm', False, path=my_path)
98 ma.printList('n0:all', False, path=my_path)
99 
100 
101 # Select variables that we want to store to ntuple
102 # You can either use preselected variable groups from variableCollections
103 # or use your own lists. Both options are shown here.
104 # For more information on the VariableManager, VariableCollections, etc.,
105 # please refer to the dedicated VariableManager examples.
106 
107 # Note: vc.<collection> is a list (of variables); multiple lists are
108 # concatenated with the + operator.
109 
110 charged_particle_variables = vc.reco_stats + \
111  vc.kinematics + \
112  vc.track + \
113  vc.track_hits + \
114  vc.pid + \
115  vc.mc_truth + \
116  vc.mc_kinematics
117 
118 gamma_variables = vc.kinematics + \
119  vc.mc_kinematics + \
120  vc.cluster
121 
122 K0s_variables = vc.kinematics + \
123  vc.inv_mass + \
124  vc.vertex + \
125  vc.mc_vertex + \
126  vc.pid + \
127  vc.mc_truth + \
128  ['dr', 'dz', 'isSignal', 'chiProb']
129 
130 pi0_variables = vc.mc_truth + \
131  vc.kinematics + \
132  ['extraInfo(BDT)', 'decayAngle(0)']
133 
134 K0l_variables = vc.kinematics + \
135  vc.mc_kinematics + \
136  vc.klm_cluster
137 
138 n0_variables = K0l_variables + \
139  ['isFromECL', 'isFromKLM']
140 
141 # Saving variables to ntuple
142 output_file = 'B2A202-LoadReconstructedParticles.root'
143 ma.variablesToNtuple(decayString='pi+:all',
144  variables=charged_particle_variables,
145  treename='pion',
146  filename=output_file,
147  path=my_path)
148 ma.variablesToNtuple(decayString='K+:all',
149  variables=charged_particle_variables,
150  treename='kaon',
151  filename=output_file,
152  path=my_path)
153 ma.variablesToNtuple(decayString='e+:all',
154  variables=charged_particle_variables,
155  treename='elec',
156  filename=output_file,
157  path=my_path)
158 ma.variablesToNtuple(decayString='mu+:all',
159  variables=charged_particle_variables,
160  treename='muon',
161  filename=output_file,
162  path=my_path)
163 ma.variablesToNtuple(decayString='gamma:all',
164  variables=gamma_variables,
165  treename='phot',
166  filename=output_file,
167  path=my_path)
168 ma.variablesToNtuple(decayString='K_L0:allklm',
169  variables=K0l_variables,
170  treename='klong',
171  filename=output_file,
172  path=my_path)
173 ma.variablesToNtuple(decayString='n0:all',
174  variables=n0_variables,
175  treename='neutron',
176  filename=output_file,
177  path=my_path)
178 
179 # Note here, that since we want to get info about gammas from pi0,
180 # we convert names of the variables from the gamma list in the way that they will
181 # correspond to given gammas.
182 ma.variablesToNtuple(decayString='pi0:eff40_Jan2020Fit',
183  variables=pi0_variables + vu.create_aliases_for_selected(gamma_variables, 'pi0 -> ^gamma ^gamma'),
184  filename=output_file,
185  treename='pi0',
186  path=my_path)
187 
188 # Here for pions from K0s we do the same thing, but here we add custom aliases
189 # (see ntuples to see the difference)
190 ma.variablesToNtuple(decayString='K_S0:merged',
191  variables=K0s_variables +
192  vu.create_aliases_for_selected(charged_particle_variables, 'K_S0 -> ^pi+ pi-', 'pip') +
193  vu.create_aliases_for_selected(charged_particle_variables, 'K_S0 -> pi+ ^pi-', 'pim'),
194  filename=output_file,
195  treename='kshort',
196  path=my_path)
197 
198 # Process the events
199 b2.process(my_path)
200 
201 # print out the summary
202 print(b2.statistics)
stdPi0s
Definition: stdPi0s.py:1
variables.utils
Definition: utils.py:1
stdKlongs
Definition: stdKlongs.py:1
variables.collections
Definition: collections.py:1