Belle II Software light-2607-kasei
TrainingDataInformation Class Reference

Public Member Functions

 __init__ (self, typing.Sequence[config.Particle] particles, str outputPath='')
 
bool available (self)
 
pybasf2.Path reconstruct (self)
 
 get_mc_counts (self)
 

Public Attributes

 particles = particles
 list of config.Particle objects
 
 filename = os.path.join(outputPath, 'mcParticlesCount.root')
 filename
 

Detailed Description

Contains the relevant information about the used training data.
Basically we write out the number of MC particles in the whole dataset.
This numbers we can use to calculate what fraction of candidates we have to write
out as TrainingData to get a reasonable amount of candidates to train on
(too few candidates will lead to heavy overtraining, too many won't fit into memory).
Secondly we can use this information for the generation of the monitoring pdfs,
where we calculate reconstruction efficiencies.

Definition at line 74 of file core.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
typing.Sequence[config.Particle] particles,
str outputPath = '' )
Create a new TrainingData object
@param particles list of config.Particle objects
@param outputPath path to the output directory

Definition at line 85 of file core.py.

85 def __init__(self, particles: typing.Sequence[config.Particle], outputPath: str = ''):
86 """
87 Create a new TrainingData object
88 @param particles list of config.Particle objects
89 @param outputPath path to the output directory
90 """
91
92 self.particles = particles
93
94 self.filename = os.path.join(outputPath, 'mcParticlesCount.root')
95

Member Function Documentation

◆ available()

bool available ( self)
Check if the relevant information is already available

Definition at line 96 of file core.py.

96 def available(self) -> bool:
97 """
98 Check if the relevant information is already available
99 """
100 return os.path.isfile(self.filename)
101

◆ get_mc_counts()

get_mc_counts ( self)
Read out the number of MC particles from the file created by reconstruct

Definition at line 119 of file core.py.

119 def get_mc_counts(self):
120 """
121 Read out the number of MC particles from the file created by reconstruct
122 """
123 # Unique absolute pdg-codes of all particles
124 # Always avoid the top-level 'import ROOT'.
125 import ROOT # noqa
126 root_file = ROOT.TFile.Open(self.filename, 'read')
127 mc_counts = {}
128
129 for key in root_file.GetListOfKeys():
130 variable = ROOT.Belle2.MakeROOTCompatible.invertMakeROOTCompatible(key.GetName())
131 pdg = abs(int(variable[len('NumberOfMCParticlesInEvent('):-len(")")]))
132 hist = key.ReadObj()
133 mc_counts[pdg] = {}
134 mc_counts[pdg]['sum'] = sum(hist.GetXaxis().GetBinCenter(bin + 1) * hist.GetBinContent(bin + 1)
135 for bin in range(hist.GetNbinsX()))
136 mc_counts[pdg]['std'] = hist.GetStdDev()
137 mc_counts[pdg]['avg'] = hist.GetMean()
138 mc_counts[pdg]['max'] = hist.GetXaxis().GetBinCenter(hist.FindLastBinAbove(0.0))
139 mc_counts[pdg]['min'] = hist.GetXaxis().GetBinCenter(hist.FindFirstBinAbove(0.0))
140
141 mc_counts[0] = {}
142 mc_counts[0]['sum'] = hist.GetEntries() # this is the total number of ALL events, does not matter which hist we take
143 root_file.Close()
144 return mc_counts
145
146

◆ reconstruct()

pybasf2.Path reconstruct ( self)
Returns pybasf2.Path which counts the number of MCParticles in each event.
@param particles list of config.Particle objects

Definition at line 102 of file core.py.

102 def reconstruct(self) -> pybasf2.Path:
103 """
104 Returns pybasf2.Path which counts the number of MCParticles in each event.
105 @param particles list of config.Particle objects
106 """
107 # Unique absolute pdg-codes of all particles
108 pdgs = {abs(pdg.from_name(particle.name)) for particle in self.particles}
109
110 path = basf2.create_path()
111 module = basf2.register_module('VariablesToHistogram')
112 module.set_name("VariablesToHistogram_MCCount")
113 module.param('variables', [(f'NumberOfMCParticlesInEvent({pdg})', 100, -0.5, 99.5) for pdg in pdgs])
114 module.param('fileName', self.filename)
115 module.param('ignoreCommandLineOverride', True)
116 path.add_module(module)
117 return path
118
from_name(name)
Definition pdg.py:63

Member Data Documentation

◆ filename

filename = os.path.join(outputPath, 'mcParticlesCount.root')

filename

Definition at line 94 of file core.py.

◆ particles

particles = particles

list of config.Particle objects

Definition at line 92 of file core.py.


The documentation for this class was generated from the following file: