Belle II Software  release-05-01-25
B_generic_apply.py
1 #!/usr/bin/env python3
2 
3 # William Sutcliffe 2019
4 
5 import fei
6 import basf2 as b2
7 import modularAnalysis as ma
8 
9 # Create path
10 path = b2.create_path()
11 
12 # Load input ROOT file
13 ma.inputMdst(environmentType='default',
14  filename=b2.find_file('mdst12.root', 'validation', False),
15  path=path)
16 
17 # Add the necessary database
18 # You can use the command b2conditionsdb-recommend
19 # b2.conditions.globaltags = ['name of analysis global tag']
20 b2.conditions.prepend_globaltag(ma.getAnalysisGlobaltag())
21 
22 # Get FEI default channels.
23 # Utilise the arguments to toggle on and off certain channels
24 particles = fei.get_default_channels()
25 
26 # Set up FEI configuration specifying the FEI prefix
27 configuration = fei.config.FeiConfiguration(prefix='FEIv4_2020_MC13_release_04_01_01', training=False, monitor=False, cache=0)
28 
29 # Get FEI path
30 feistate = fei.get_path(particles, configuration)
31 
32 # Add FEI path to the path to be processed
33 path.add_path(feistate.path)
34 
35 # Add MC matching when applying to MC. This is required for variables like isSignal and mcErrors below
36 path.add_module('MCMatcherParticles', listName='B+:generic', looseMCMatching=True)
37 path.add_module('MCMatcherParticles', listName='B+:semileptonic', looseMCMatching=True)
38 path.add_module('MCMatcherParticles', listName='B0:generic', looseMCMatching=True)
39 path.add_module('MCMatcherParticles', listName='B0:semileptonic', looseMCMatching=True)
40 
41 # Store tag-side variables of interest.
42 ma.variablesToNtuple('B+:generic',
43  ['Mbc',
44  'deltaE',
45  'mcErrors',
46  'extraInfo(decayModeID)',
47  'extraInfo(uniqueSignal)',
48  'extraInfo(SignalProbability)',
49  'isSignal'],
50  filename='B_charged_hadronic.root',
51  path=path)
52 ma.variablesToNtuple('B+:semileptonic',
53  ['cosThetaBetweenParticleAndNominalB',
54  'mcErrors',
55  'extraInfo(decayModeID)',
56  'extraInfo(uniqueSignal)',
57  'extraInfo(SignalProbability)',
58  'isSignalAcceptMissingNeutrino'],
59  filename='B_charged_semileptonic.root',
60  path=path)
61 
62 ma.variablesToNtuple('B0:generic',
63  ['Mbc',
64  'deltaE',
65  'mcErrors',
66  'extraInfo(decayModeID)',
67  'extraInfo(uniqueSignal)',
68  'extraInfo(SignalProbability)',
69  'isSignal'],
70  filename='B_mixed_hadronic.root',
71  path=path)
72 ma.variablesToNtuple('B0:semileptonic',
73  ['cosThetaBetweenParticleAndNominalB',
74  'mcErrors',
75  'extraInfo(decayModeID)',
76  'extraInfo(uniqueSignal)',
77  'extraInfo(SignalProbability)',
78  'isSignalAcceptMissingNeutrino'],
79  filename='B_mixed_semileptonic.root',
80  path=path)
81 
82 # Process 100 events
83 b2.process(path, max_event=100)
84 print(b2.statistics)