Belle II Software development
topVariables.py
1#!/usr/bin/env python3
2
3
10
11# -------------------------------------------------------------------------
12# Example of using top variables on MC
13# See cdstAnalysis.py on how to use top variables on real data
14#
15# To print available top variables: basf2 top/examples/printTOPVariables.py
16# -------------------------------------------------------------------------
17
18from basf2 import create_path, process
19from simulation import add_simulation
20from reconstruction import add_reconstruction
21from background import get_background_files
22import modularAnalysis as ma
23from variables import variables
24
25# create path
26main = create_path()
27
28# generate and reconstruct 100 generic BBbar events w/ the beam background overlayed
29main.add_module('EventInfoSetter', evtNumList=[100])
30main.add_module('EvtGenInput')
31add_simulation(main, bkgfiles=get_background_files())
32add_reconstruction(main)
33
34# make a particle list of MC true pions
35ma.fillParticleList(decayString='pi+', cut='', path=main)
36ma.matchMCTruth(list_name='pi+', path=main)
37ma.applyCuts(list_name='pi+', cut='isSignal==1', path=main)
38
39# make aliases of some expert variables
40variables.addAlias('topTOF_kaon', 'topTOFExpert(321)')
41variables.addAlias('topLogLPhotonCountMCMatch', 'topDigitCountIntervalMCMatch(-20, 74.327756)')
42
43# define a list of variables to be written to ntuple
44var_list = ['p',
45 'theta',
46 'phi',
47 'charge',
48 'PDG',
49 'isSignal',
50 'topSlotID',
51 'topSlotIDMCMatch',
52 'topLocalX',
53 'topLocalY',
54 'topLocalZ',
55 'topLocalXMCMatch',
56 'topLocalYMCMatch',
57 'topLocalZMCMatch',
58 'topLocalPhi',
59 'topLocalTheta',
60 'topLocalPhiMCMatch',
61 'topLocalThetaMCMatch',
62 'topTOF',
63 'topTOFMCMatch',
64 'topTOF_kaon',
65 'extrapTrackToTOPimpactZ',
66 'extrapTrackToTOPimpactTheta',
67 'extrapTrackToTOPimpactPhi',
68 'topDigitCount',
69 'topDigitCountMCMatch',
70 'topDigitCountSignal',
71 'topDigitCountBkg',
72 'topDigitCountRaw',
73 'topLogLFlag',
74 'topLogLPhotonCount',
75 'topLogLPhotonCountMCMatch',
76 'topLogLExpectedPhotonCount',
77 'topLogLEstimatedBkgCount',
78 'topLogLElectron',
79 'topLogLMuon',
80 'topLogLPion',
81 'topLogLKaon',
82 'topLogLProton',
83 'topLogLDeuteron',
84 'topBunchIsReconstructed',
85 'topBunchNumber',
86 'topBunchMCMatch',
87 'topBunchOffset',
88 'topBunchTrackCount',
89 'topBunchUsedTrackCount',
90 'topTracksInSlot']
91
92# write variables to ntuple
93ma.variablesToNtuple(decayString='pi+', variables=var_list, treename='tree', filename='topVars_mc.root', path=main)
94
95# print progress
96main.add_module('Progress')
97
98# process events
99process(main)