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 66 of file __init__.py.

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

◆ _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 130 of file __init__.py.

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

◆ _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 50 of file __init__.py.

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

◆ _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 116 of file __init__.py.

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

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

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

◆ _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 84 of file __init__.py.

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

◆ 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 365 of file __init__.py.

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