Belle II Software  release-05-01-25
070_fei.py
1 #!/usr/bin/env python3
2 
3 import sys
4 import basf2 as b2
5 import fei
6 import modularAnalysis as ma
7 from variables import variables as vm
8 
9 # get input file number from the command line
10 filenumber = sys.argv[1]
11 
12 # create path
13 main = b2.Path()
14 
15 # load input data from mdst/udst file
16 ma.inputMdst(
17  environmentType="default",
18  filename=b2.find_file(f"starterkit/2021/1111540100_eph3_BGx0_{filenumber}.root", "examples"),
19  path=main,
20 )
21 
22 # Add the database with the classifier weight files for the FEI
23 # You can use the command b2conditionsdb-recommend
24 b2.conditions.prepend_globaltag("analysis_tools_release-04-02")
25 
26 # Get FEI default channels.
27 # Utilise the arguments to toggle on and off certain channels
28 particles = fei.get_default_channels(
29  chargedB=True,
30  neutralB=False,
31  hadronic=True,
32  semileptonic=False,
33  baryonic=True,
34 )
35 
36 # Set up FEI configuration specifying the FEI prefix
37 configuration = fei.FeiConfiguration(
38  prefix="FEIv4_2020_MC13_release_04_01_01", monitor=False
39 )
40 
41 # Get FEI path
42 feistate = fei.get_path(particles, configuration)
43 
44 # Add FEI path to the path to be processed
45 main.add_path(feistate.path)
46 
47 # Add MC matching when applying to MC.
48 # This is required for variables like isSignal and mcErrors below
49 ma.matchMCTruth(list_name="B+:generic", path=main)
50 
51 # Rank B+ candidates by signal classifier output
52 ma.rankByHighest(
53  particleList="B+:generic",
54  variable="extraInfo(SignalProbability)",
55  outputVariable="FEIProbabilityRank",
56  path=main,
57 )
58 vm.addAlias("FEIProbRank", "extraInfo(FEIProbabilityRank)")
59 
60 vm.addAlias("SigProb", "extraInfo(SignalProbability)")
61 vm.addAlias("decayModeID", "extraInfo(decayModeID)")
62 
63 # Store tag-side variables of interest.
64 ma.variablesToNtuple(
65  "B+:generic",
66  [
67  "Mbc",
68  "deltaE",
69  "mcErrors",
70  "SigProb",
71  "decayModeID",
72  "FEIProbRank",
73  "isSignal",
74  ],
75  filename="B_charged_hadronic.root",
76  path=main,
77 )
78 
79 # Process events
80 b2.process(main)
81 print(b2.statistics)