Belle II Software light-2607-kasei
Particle Class Reference

Public Member Functions

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

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)
 
 extraPathSpec = extraPathSpec
 specifications for running extra modules
 

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 165 of file config.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
str identifier,
MVAConfiguration mvaConfig,
PreCutConfiguration preCutConfig = PreCutConfiguration(),
PostCutConfiguration postCutConfig = PostCutConfiguration(),
dict | None extraPathSpec = None )
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
    @param extraPathSpec extra module specifications

Definition at line 173 of file config.py.

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

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 205 of file config.py.

205 def __eq__(self, a):
206 """
207 Compares to Particle objects.
208 They are equal if their identifier, name, label, all channels, preCutConfig and postCutConfig is equal
209 @param a another Particle object
210 """
211 return (self.identifier == a.identifier and self.name == a.name and self.label == a.label and
212 self.channels == a.channels and self.preCutConfig == a.preCutConfig and self.postCutConfig == a.postCutConfig)
213

◆ __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 220 of file config.py.

220 def __hash__(self):
221 """
222 Creates a hash of a Particle object.
223 This is necessary to use this as a key in a dictionary
224 """
225 return hash((self.identifier, self.channels, self.preCutConfig, self.postCutConfig, self.mvaConfig))
226

◆ __str__()

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

Definition at line 214 of file config.py.

214 def __str__(self):
215 """
216 Creates a string representation of a Particle object.
217 """
218 return str((self.identifier, self.channels, self.preCutConfig, self.postCutConfig, self.mvaConfig))
219

◆ addChannel()

addChannel ( self,
typing.Sequence[str] daughters,
MVAConfiguration mvaConfig = None,
PreCutConfiguration preCutConfig = None,
bool pi0veto = False,
dict | None extraPathSpec = None )
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
    @param extraPathSpec extra module specifications

Definition at line 232 of file config.py.

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

◆ daughters()

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

Definition at line 228 of file config.py.

228 def daughters(self):
229 """ Property returning list of unique daughter particles of all channels """
230 return list(frozenset([daughter for channel in self.channels for daughter in channel.daughters]))
231

Member Data Documentation

◆ channels

channels = []

DecayChannel objects added by addChannel() method.

Definition at line 197 of file config.py.

◆ extraPathSpec

extraPathSpec = extraPathSpec

specifications for running extra modules

Definition at line 203 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 188 of file config.py.

◆ label

label = v[1]

Additional label like hasMissing or has2Daughters.

Definition at line 193 of file config.py.

◆ mvaConfig

mvaConfig = mvaConfig

multivariate analysis configuration (see MVAConfiguration)

Definition at line 195 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 191 of file config.py.

◆ postCutConfig

postCutConfig = postCutConfig

post cut configuration (see PostCutConfiguration)

Definition at line 201 of file config.py.

◆ preCutConfig

preCutConfig = preCutConfig

intermediate cut configuration (see PreCutConfiguration)

Definition at line 199 of file config.py.


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