Belle II Software development
pxd.background_generator Namespace Reference

basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for contributors and copyright holders. More...

Namespaces

namespace  models
 basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for contributors and copyright holders.
 

Classes

class  PXDBackgroundGenerator
 Class for the PXD background generator module. More...
 

Functions

str _verify_model (str model)
 Function to verify that model:
 
str _verify_checkpoint (Union[None, str, pathlib.Path] checkpoint)
 Function to verify that checkpoint:
 
Union[None, int] _verify_seed (Union[None, int] seed)
 Function to verify that seed:
 
int _verify_nintra (int nintra)
 Function to verify that nintra:
 
int _verify_ninter (int ninter)
 Function to verify that ninter:
 
str _verify_globaltag (str globaltag)
 Function to verify that globaltag:
 
Callable inject_simulation (Union[None, basf2.Module] module=None)
 Helper function to incorporate a module instance into add_simulation after BGOverlayInput.
 

Variables

tuple VXDID_ARGS
 Sequence of forty tuples (layer, ladder, sensor) used to instantiate VxdID specifier objects for distinct PXD modules.
 

Detailed Description

basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for contributors and copyright holders.

# This file is licensed under LGPL-3.0, see LICENSE.md. #

Generate PXD background samples for background overlay on the fly.

Function Documentation

◆ _verify_checkpoint()

str _verify_checkpoint ( Union[None, str, pathlib.Path]  checkpoint)
protected

Function to verify that checkpoint:

  • is either None, a string, or a pathlib.Path object,
  • is a valid path to an existing file - if not None.

The value of checkpoint is returned if the conditions are met. An exception is raised otherwise.

Definition at line 65 of file __init__.py.

65def _verify_checkpoint(checkpoint: Union[None, str, pathlib.Path]) -> str:
66 if not isinstance(checkpoint, (type(None), str, pathlib.Path)):
67 raise TypeError("expecting None or type str `checkpoint`")
68 if checkpoint is None:
69 return checkpoint
70 checkpoint = os.path.expandvars(str(checkpoint))
71 if not (os.path.exists(checkpoint) and os.path.isfile(checkpoint)):
72 raise ValueError(f"invalid `checkpoint`: {checkpoint!r}")
73 return checkpoint
74
75

◆ _verify_globaltag()

str _verify_globaltag ( str  globaltag)
protected

Function to verify that globaltag:

  • is a string.

The value of globaltag is returned if the condition is met. An exception is raised otherwise.

Definition at line 129 of file __init__.py.

129def _verify_globaltag(globaltag: str) -> str:
130 if not isinstance(globaltag, str):
131 raise TypeError("expecting type str `globaltag`")
132 return globaltag
133
134

◆ _verify_model()

str _verify_model ( str  model)
protected

Function to verify that model:

  • is a string,
  • is a valid name for a model that is available for selection.

The value of model is returned if the conditions are met. An exception is raised otherwise.

Definition at line 49 of file __init__.py.

49def _verify_model(model: str) -> str:
50 if not isinstance(model, str):
51 raise TypeError("expecting type str `model`")
52 elif model not in MODELS:
53 options = ", ".join(map(repr, MODELS))
54 raise ValueError(f"invalid `model`: {model!r} (options: {options}")
55 return model
56
57

◆ _verify_ninter()

int _verify_ninter ( int  ninter)
protected

Function to verify that ninter:

  • is an integer,
  • is larger than zero.

The value of ninter is returned if the conditions are met. An exception is raised otherwise.

Definition at line 115 of file __init__.py.

115def _verify_ninter(ninter: int) -> int:
116 if not isinstance(ninter, int):
117 raise TypeError("expecting type int `ninter`")
118 elif not ninter > 0:
119 raise ValueError(f"expecting `ninter` > 0 (got: {ninter}")
120 return ninter
121
122

◆ _verify_nintra()

int _verify_nintra ( int  nintra)
protected

Function to verify that nintra:

  • is an integer,
  • is larger than zero.

The value of nintra is returned if the conditions are met. An exception is raised otherwise.

Definition at line 100 of file __init__.py.

100def _verify_nintra(nintra: int) -> int:
101 if not isinstance(nintra, int):
102 raise TypeError("expecting type int `nintra`")
103 elif not nintra > 0:
104 raise ValueError(f"expecting `nintra` > 0 (got: {nintra}")
105 return nintra
106
107

◆ _verify_seed()

Union[None, int] _verify_seed ( Union[None, int]  seed)
protected

Function to verify that seed:

  • is either None or an integer,
  • is in the interval $ [-2^{63}, 2^{63} - 1] $ - if not None.

The value of seed is returned if the conditions are met. An exception is raised otherwise.

Definition at line 83 of file __init__.py.

83def _verify_seed(seed: Union[None, int]) -> Union[None, int]:
84 if not isinstance(seed, (type(None), int)):
85 raise TypeError("expecting None or type int `seed`")
86 if seed is None:
87 return seed
88 if not -(2 ** 63) <= seed < 2 ** 63:
89 raise ValueError(f"expecting -2^63 <= `seed` < 2^63 (got: {seed})")
90 return seed
91
92

◆ inject_simulation()

Callable inject_simulation ( Union[None, basf2.Module]   module = None)

Helper function to incorporate a module instance into add_simulation after BGOverlayInput.

Parameters
moduleModule instance to be incorporated, defaults to None - return unmodified function
Returns
Drop-in replacement function for add_simulation
Incorporate a module instance
into :py:func:`.add_simulation` after `!BGOverlayInput`.

:param module: Module instance to be incorporated,
    defaults to None - return unmodified function
:type module: :py:class:`basf2.Module`, optional

:returns: Drop-in replacement function for :py:func:`.add_simulation`

Definition at line 364 of file __init__.py.

364def inject_simulation(module: Union[None, basf2.Module] = None) -> Callable:
365 """Incorporate a module instance
366 into :py:func:`.add_simulation` after `!BGOverlayInput`.
367
368 :param module: Module instance to be incorporated,
369 defaults to None - return unmodified function
370 :type module: :py:class:`basf2.Module`, optional
371
372 :returns: Drop-in replacement function for :py:func:`.add_simulation`
373 """
374 from simulation import add_simulation
375
376 if module is None:
377 # no modifications necessary
378 return add_simulation
379 elif not isinstance(module, basf2.Module):
380 raise TypeError("expecting None or type basf2.Module `module`")
381
382 @functools.wraps(add_simulation)
383 def injected_simulation(path, *args, **kwargs):
384 # create a separate path with simulation modules
385 simulation_path = basf2.Path()
386 add_simulation(simulation_path, *args, **kwargs)
387
388 # manually add the simulation modules to the given path
389 for simulation_module in simulation_path.modules():
390 # append the next module from the simulation path
391 path.add_module(simulation_module)
392
393 if simulation_module.name() == "BGOverlayInput":
394 # incorporate the given module
395 path.add_module(module)
396
397 return injected_simulation

Variable Documentation

◆ VXDID_ARGS

tuple VXDID_ARGS
Initial value:
1= tuple(
2 tuple(product([1], [ladder + 1 for ladder in range(8)], [1, 2]))
3 + tuple(product([2], [ladder + 1 for ladder in range(12)], [1, 2]))
4)

Sequence of forty tuples (layer, ladder, sensor) used to instantiate VxdID specifier objects for distinct PXD modules.

It is assumed that the indices of tuples in the sequence match indices along the first axis of tensors with shape (40, 250, 768) that are produced by the generator.

Definition at line 36 of file __init__.py.