Belle II Software development
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 73 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 84 of file core.py.

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

Member Function Documentation

◆ available()

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

Definition at line 95 of file core.py.

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

◆ get_mc_counts()

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

Definition at line 118 of file core.py.

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

◆ 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 101 of file core.py.

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

Member Data Documentation

◆ filename

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

filename

Definition at line 93 of file core.py.

◆ particles

particles = particles

list of config.Particle objects

Definition at line 91 of file core.py.


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