Belle II Software development
Particle Class Reference

Public Member Functions

 __init__ (self, str identifier, MVAConfiguration mvaConfig, PreCutConfiguration preCutConfig=PreCutConfiguration(), PostCutConfiguration postCutConfig=PostCutConfiguration())
 
 __eq__ (self, a)
 
 __str__ (self)
 
 __hash__ (self)
 
 daughters (self)
 
 addChannel (self, typing.Sequence[str] daughters, MVAConfiguration mvaConfig=None, PreCutConfiguration preCutConfig=None, bool pi0veto=False)
 

Public Attributes

str identifier = identifier + ':generic' if len(identifier.split(':')) < 2 else identifier
 pdg name of the particle with an optional additional user label separated by :
 
 name = v[0]
 The name of the particle as correct pdg name e.g.
 
 label = v[1]
 Additional label like hasMissing or has2Daughters.
 
 mvaConfig = mvaConfig
 multivariate analysis configuration (see MVAConfiguration)
 
list channels = []
 DecayChannel objects added by addChannel() method.
 
 preCutConfig = preCutConfig
 intermediate cut configuration (see PreCutConfiguration)
 
 postCutConfig = postCutConfig
 post cut configuration (see PostCutConfiguration)
 

Detailed Description

The Particle class is the only class the end-user gets into contact with.
The user creates an instance of this class for every particle he wants to reconstruct with the FEI algorithm,
and provides MVAConfiguration, PreCutConfiguration and PostCutConfiguration. These can be overwritten per channel.

Definition at line 164 of file config.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
str identifier,
MVAConfiguration mvaConfig,
PreCutConfiguration preCutConfig = PreCutConfiguration(),
PostCutConfiguration postCutConfig = PostCutConfiguration() )
Creates a Particle without any decay channels. To add decay channels use addChannel method.
    @param identifier is the pdg name of the particle as a string
           with an optional additional user label separated by ':'
    @param mvaConfig multivariate analysis configuration
    @param preCutConfig intermediate pre cut configuration
    @param postCutConfig post cut configuration

Definition at line 172 of file config.py.

175 postCutConfig: PostCutConfiguration = PostCutConfiguration()):
176 """
177 Creates a Particle without any decay channels. To add decay channels use addChannel method.
178 @param identifier is the pdg name of the particle as a string
179 with an optional additional user label separated by ':'
180 @param mvaConfig multivariate analysis configuration
181 @param preCutConfig intermediate pre cut configuration
182 @param postCutConfig post cut configuration
183 """
184
185 self.identifier = identifier + ':generic' if len(identifier.split(':')) < 2 else identifier
186 v = self.identifier.split(':')
187
188 self.name = v[0]
189
190 self.label = v[1]
191
192 self.mvaConfig = mvaConfig
193
194 self.channels = []
195
196 self.preCutConfig = preCutConfig
197
198 self.postCutConfig = postCutConfig
199

Member Function Documentation

◆ __eq__()

__eq__ ( self,
a )
Compares to Particle objects.
They are equal if their identifier, name, label, all channels, preCutConfig and postCutConfig is equal
@param a another Particle object

Definition at line 200 of file config.py.

200 def __eq__(self, a):
201 """
202 Compares to Particle objects.
203 They are equal if their identifier, name, label, all channels, preCutConfig and postCutConfig is equal
204 @param a another Particle object
205 """
206 return (self.identifier == a.identifier and self.name == a.name and self.label == a.label and
207 self.channels == a.channels and self.preCutConfig == a.preCutConfig and self.postCutConfig == a.postCutConfig)
208

◆ __hash__()

__hash__ ( self)
Creates a hash of a Particle object.
This is necessary to use this as a key in a dictionary

Definition at line 215 of file config.py.

215 def __hash__(self):
216 """
217 Creates a hash of a Particle object.
218 This is necessary to use this as a key in a dictionary
219 """
220 return hash((self.identifier, self.channels, self.preCutConfig, self.postCutConfig, self.mvaConfig))
221

◆ __str__()

__str__ ( self)
Creates a string representation of a Particle object.

Definition at line 209 of file config.py.

209 def __str__(self):
210 """
211 Creates a string representation of a Particle object.
212 """
213 return str((self.identifier, self.channels, self.preCutConfig, self.postCutConfig, self.mvaConfig))
214

◆ addChannel()

addChannel ( self,
typing.Sequence[str] daughters,
MVAConfiguration mvaConfig = None,
PreCutConfiguration preCutConfig = None,
bool pi0veto = False )
Appends a new decay channel to the Particle object.
    @param daughters is a list of pdg particle names e.g. ['pi+','K-']
    @param mvaConfig multivariate analysis configuration
    @param preCutConfig pre cut configuration object
    @param pi0veto if true, additional pi0veto variables are added to the MVA configuration

Definition at line 227 of file config.py.

231 pi0veto: bool = False):
232 """
233 Appends a new decay channel to the Particle object.
234 @param daughters is a list of pdg particle names e.g. ['pi+','K-']
235 @param mvaConfig multivariate analysis configuration
236 @param preCutConfig pre cut configuration object
237 @param pi0veto if true, additional pi0veto variables are added to the MVA configuration
238 """
239 # Append generic label to all defined daughters if no label was set yet
240 daughters = [d + ':generic' if ':' not in d else d for d in daughters]
241 # Use default mvaConfig of this particle if no channel-specific config is given
242 mvaConfig = copy.deepcopy(self.mvaConfig if mvaConfig is None else mvaConfig)
243 # Use default preCutConfig of this particle if no channel-specific config is given
244 preCutConfig = copy.deepcopy(self.preCutConfig if preCutConfig is None else preCutConfig)
245 # At the moment all channels must have the same target variable. Why?
246 if mvaConfig is not None and mvaConfig.target != self.mvaConfig.target:
247 basf2.B2FATAL(
248 f'Particle {self.identifier} has common target {self.mvaConfig.target}, while channel '
249 f'{" ".join(daughters)} has {mvaConfig.target}. Each particle must have exactly one target!')
250 # Replace generic-variables with ordinary variables.
251 # All instances of {} are replaced with all combinations of daughter indices
252 mvaVars = []
253 for v in mvaConfig.variables:
254 if v.count('{') == 0:
255 mvaVars.append(v)
256 continue
257 matches = re.findall(r'\{\s*\d*\s*\.\.\s*\d*\s*\}', v)
258 if len(matches) == 0 and v.count('{}') == 0:
259 mvaVars.append(v)
260 elif v.count('{}') > 0 and len(matches) > 0:
261 basf2.B2FATAL(f'Variable {v} contains both '+'{}'+f' and {matches}. Only one is allowed!')
262 elif len(matches) > 0:
263 ranges = []
264 skip = False
265 for match in matches:
266 tempRange = match[1:-1].split('..')
267 if tempRange[0] == '':
268 tempRange[0] = 0
269 else:
270 tempRange[0] = int(tempRange[0])
271 if tempRange[0] >= len(daughters):
272 basf2.B2DEBUG(11, f'Variable {v} contains index {tempRange[0]} which is more than daughters, skipping!')
273 skip = True
274 break
275 if tempRange[1] == '':
276 tempRange[1] = len(daughters)
277 else:
278 tempRange[1] = int(tempRange[1])
279 if tempRange[1] > len(daughters):
280 basf2.B2DEBUG(11, f'Variable {v} contains index {tempRange[1]} which is more than daughters, skipping!')
281 skip = True
282 break
283 ranges.append(tempRange)
284 if skip:
285 continue
286 if len(ranges) == 1:
287 mvaVars += [v.replace(matches[0], str(c)) for c in range(ranges[0][0], ranges[0][1])]
288 else:
289 for match in matches:
290 v = v.replace(match, '{}')
291 mvaVars += [v.format(*c) for c in itertools.product(*[range(r[0], r[1]) for r in ranges])]
292 elif v.count('{}') <= len(daughters):
293 mvaVars += [v.format(*c) for c in itertools.combinations(list(range(0, len(daughters))), v.count('{}'))]
294 elif v.count('{}') > len(daughters):
295 basf2.B2DEBUG(11, f'Variable {v} contains more brackets than daughters, which is why it will be ignored!')
296 continue
297 else:
298 basf2.B2FATAL(f'Something went wrong with variable {v}!')
299 mvaConfig = mvaConfig._replace(variables=mvaVars)
300 # Add new channel
301 decayModeID = len(self.channels)
302 self.channels.append(DecayChannel(name=self.identifier + '_' + str(decayModeID),
303 label=removeJPsiSlash(self.identifier + ' ==> ' + ' '.join(daughters)),
304 decayString=self.identifier + '_' + str(decayModeID) + ' -> ' + ' '.join(daughters),
305 daughters=daughters,
306 mvaConfig=mvaConfig,
307 preCutConfig=preCutConfig,
308 decayModeID=decayModeID,
309 pi0veto=pi0veto))
310 return self

◆ daughters()

daughters ( self)
 Property returning list of unique daughter particles of all channels 

Definition at line 223 of file config.py.

223 def daughters(self):
224 """ Property returning list of unique daughter particles of all channels """
225 return list(frozenset([daughter for channel in self.channels for daughter in channel.daughters]))
226

Member Data Documentation

◆ channels

channels = []

DecayChannel objects added by addChannel() method.

Definition at line 194 of file config.py.

◆ identifier

identifier = identifier + ':generic' if len(identifier.split(':')) < 2 else identifier

pdg name of the particle with an optional additional user label separated by :

Definition at line 185 of file config.py.

◆ label

label = v[1]

Additional label like hasMissing or has2Daughters.

Definition at line 190 of file config.py.

◆ mvaConfig

mvaConfig = mvaConfig

multivariate analysis configuration (see MVAConfiguration)

Definition at line 192 of file config.py.

◆ name

name = v[0]

The name of the particle as correct pdg name e.g.

K+, pi-, D*0.

Definition at line 188 of file config.py.

◆ postCutConfig

postCutConfig = postCutConfig

post cut configuration (see PostCutConfiguration)

Definition at line 198 of file config.py.

◆ preCutConfig

preCutConfig = preCutConfig

intermediate cut configuration (see PreCutConfiguration)

Definition at line 196 of file config.py.


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