e15190.neutron_wall.spectra.LabPtransverseRapidity

class e15190.neutron_wall.spectra.LabPtransverseRapidity(runs: list[int])

Functions

__init__(runs)

build_rdataframe([tree_name, implicit_mt])

Build the RDataFrame and store it as self.rdf.

coverage_curve(rapidity_range)

Returns a function that calculates the phase space coverage for a given transverse momentum.

define_energy([name, rdf, inplace])

Define the total relativistic energy of the neutron.

define_neutron_cut([name, light_bias, ...])

Define the neutron cut, cut.

filter_charged_particles([rdf, inplace])

Veto charged particles.

filter_microball_multiplicity([bhat_range, ...])

Filter the RDataFrame by microball multiplicity.

filter_tdc(tdc_range[, tdc_branch_name, ...])

Filter the RDataFrame by TDC.

get_average_coverages(rapidity_range, ...)

Get average phase space coverages at various transverse momentum ranges.

get_coincidence_peak([branch_name, rdf, ...])

Get the coincidence peak of the TDC.

get_spectrum_1d(norm_rapidity_range, ...[, ...])

Get the lab transverse momentum spectrum at a given rapidity range.

get_spectrum_2d([norm_rapidity_range, ...])

Get the 2D histogram of transverse momentum vs.

is_inside(rapidity, transverse_momentum)

Check if the given points are inside the phase space.

kinergy_curve(kinergy[, mass])

Return a function that calculates the transverse momentum for a given rapidity.

kinergy_curves()

A 2-tuple of kinergy curves that sets the boundaries of the phase space.

theta_curve(theta[, mass])

Return a function that calculates the transverse momentum for a given rapidity.

theta_curves()

A 2-tuple of theta curves that sets the boundaries of the phase space.

Properties

ROOT_FILE_DIR

bhat_range

kinergy_range

theta_range

__init__(runs: list[int])
build_rdataframe(tree_name: str | None = None, implicit_mt=True) → ROOT.RDataFrame

Build the RDataFrame and store it as self.rdf.

Different from Spectrum.build_rdataframe(), this function will always build the RDataFrame in place.

This function will apply filters and define new quantities ready for the construction of transverse momentum spectra. It will also populate the lazy container with total_count and tdc_count.

This function is written for quick construction of spectra. Many cuts and definitions are written with the most common decisions. If you want to customize the cuts and definitions, you shall use functions in Spectrum or directly interact with self.rdf.

static theta_curve(theta: float, mass=939.5654205203889) → Callable[[float | np.ndarray], float | np.ndarray]

Return a function that calculates the transverse momentum for a given rapidity.

The theta and mass (particle) are fixed.

Parameters
  • theta (float) – Polar angle in lab frame in radian.

  • mass (float, default MASS_NEUTRON) – Mass of the particle in MeV/c^2.

Returns

transverse_momentum – Function that calculates the transverse momentum for a given (unnormalized) rapidity in MeV/c.

Return type

Callable[[float | np.ndarray], float | np.ndarray

static kinergy_curve(kinergy: float, mass=939.5654205203889) → Callable[[float | np.ndarray], float | np.ndarray]

Return a function that calculates the transverse momentum for a given rapidity.

The kinetic energy and mass (particle) are fixed.

Parameters
  • kinergy (float) – Kinetic energy in MeV. This should be the total kinetic energy of the whole isotope (particle). So if you are given the kinetic energy per nucleon, you should multiply it by the mass number.

  • mass (float, default MASS_NEUTRON) – Mass of the particle in MeV/c^2.

Returns

transverse_momentum – Function that calculates the transverse momentum for a given rapidity in MeV/c.

Return type

Callable[[float | np.ndarray], float | np.ndarray

static theta_curves() → tuple[typing.Callable, typing.Callable]

A 2-tuple of theta curves that sets the boundaries of the phase space.

Returns

theta_curves – First element is the curve for the lower boundary, second element is the curve for the upper boundary.

Return type

tuple[Callable, Callable]

static kinergy_curves() → tuple[typing.Callable, typing.Callable]

A 2-tuple of kinergy curves that sets the boundaries of the phase space.

Returns

kinergy_curves – First element is the curve for the lower boundary, second element is the curve for the upper boundary.

Return type

tuple[Callable, Callable]

static is_inside(rapidity: float | np.ndarray, transverse_momentum: float | np.ndarray) → bool | np.ndarray

Check if the given points are inside the phase space.

Under the hood, this method converts back both rapidity and transverse momentum into lab (kinetic) energy and lab theta angle. Then it checks if the given points are inside the energy cuts and theta cuts.

Parameters
  • rapidity (float or np.ndarray) – The (unnormalized) rapidity in lab frame.

  • transverse_momentum (float or np.ndarray) – The transverse momentum in MeV/c.

Returns

is_inside – True if the given points are inside the phase space, False otherwise. Points on the boundary are considered inside.

Return type

bool or np.ndarray

static coverage_curve(rapidity_range: tuple[float, float]) → Callable[[float | np.ndarray], float | np.ndarray]

Returns a function that calculates the phase space coverage for a given transverse momentum.

Parameters

rapidity_range (tuple[float, float]) – The range of unnormalized rapidity in lab frame.

Returns

coverage – A function that calculates the coverage of the phase space for a given transverse momentum in MeV/c.

Return type

Callable[[float | np.ndarray], float | np.ndarray]

static get_average_coverages(rapidity_range: tuple[float, float], transverse_momentum_ranges: numpy.ndarray) → numpy.ndarray

Get average phase space coverages at various transverse momentum ranges.

Parameters
  • rapidity_range (tuple[float, float]) – The range of unnormalized rapidity in lab frame.

  • transverse_momentum_ranges (arary of shape (n, 2)) – The transverse momentum ranges in MeV/c.

get_spectrum_2d(norm_rapidity_range=(0.0, 1.0), norm_rapidity_bins=200, ptransverse_range=(0.0, 800.0), ptransverse_bins=4000, inplace=True) → Optional[cppyy.gbl.TH2]

Get the 2D histogram of transverse momentum vs. beam-normalized rapidity.

Parameters
  • norm_rapidity_range (2-tuple of float, default (0.0, 1.0)) – Range of beam-normalized rapidity in lab frame.

  • norm_rapidity_bins (int, default 200) – Number of bins for the beam-normalized rapidity.

  • ptransverse_range (2-tuple of float, default (0.0, 800.0)) – Range of transverse momentum in MeV/c.

  • ptransverse_bins (int, default 800 * 5) – Number of bins for the transverse momentum.

  • inplace (bool, default True) – When True, the histogram will be stored in self.lazy and evaluated lazily. When False, the histogram will be evaluated immediately and returned.

Returns

hist_2d – The 2D histogram. If inplace=True, returns None.

Return type

ROOT.TH2 or None

get_spectrum_1d(norm_rapidity_range: tuple[float, float], ptransverse_range: tuple[float, float], ptransverse_bins: int, geometric_efficiency=True, intrinsic_efficiency=True, background_subtraction=True, coverage_correction=True) → Optional[pandas.core.frame.DataFrame]

Get the lab transverse momentum spectrum at a given rapidity range.

Parameters
  • norm_rapidity_range (2-tuple of float) – Range of beam-normalized rapidity in lab frame.

  • ptransverse_range (2-tuple) – Histogram range of \(p_T/A\) in MeV/c.

  • ptransverse_bins (int) – Number of bins for the histogram.

Returns

spectrum – DataFrame with columns ‘x’, ‘y’, ‘yerr’ and ‘yferr’. If append_to_lazy=True, returns None.

Return type

pandas.DataFrame or None

Examples

>>> from e15190.neutron_wall import spectra
>>> spec = spectra.LabPtransverseRapidity(list(range(4224, 4245 + 1)))
>>> spec.build_rdataframe()
>>> spec.get_spectrum_2d(inplace=True) # this is needed before you can get 1D spectrum
>>> df = spec.get_spectrum_1d(
...     norm_rapidity_range=(0.4, 0.6),
...     ptransverse_range=(100, 600),
...     ptransverse_bins=500 // 20,
...     geometric_efficiency=True,
...     intrinsic_efficiency=True,
...     background_subtraction=True,
...     coverage_correction=True,
... )
static _drop_spectrum_outliers(df: pandas.core.frame.DataFrame, drop_outliers: float, yname='y') → pandas.core.frame.DataFrame

Drop outliers in the dataframe.

This function assumes outliers only occur at the ends of the spectrum. In other words, if a point in the middle is an outlier, it will not be dropped. This decision is made to keep the resulting spectrum continuous. Empirically, for this purpose, if an outlier happens in the middle, it is likely that there is some problem with the data anyway.

Parameters
  • df (pandas.DataFrame) – The dataframe to drop outliers from. Must have a column named defined by yname.

  • drop_outliers (float) – Outliers are defined as points whose ratio to the neighboring point is larger than drop_outliers.

  • yname (str, default 'y') – The name of the column in df that contains the values to check for outliers.

Returns

df – The dataframe with outliers dropped.

Return type

pandas.DataFrame

static _infer_reaction(runs: list[int]) → dict[Literal['target', 'beam', 'beam_energy'], str | float]

Infer the reaction from the runs.

Parameters

runs (list[int]) – A list of runs.

Returns

reaction – A dictionary containing the reaction information.

Return type

dict[Literal[‘target’, ‘beam’, ‘beam_energy’], str | float]

Raises

ValueError – If the runs are not from the same reaction.

static _infer_shadow_bar_present(runs: list[int]) → bool

Infer whether the shadow bar is present.

Parameters

runs (list[int]) – A list of runs.

Returns

presence – True if the shadow bar is present for all runs, False otherwise.

Return type

bool

Raises

ValueError – If the runs have different shadow bar presence.

define_energy(name='energy', rdf: Optional[cppyy.gbl.ROOT.RDataFrame] = None, inplace=False) → Optional[cppyy.gbl.ROOT.RDataFrame]

Define the total relativistic energy of the neutron.

This function will define a new column energy in the RDataFrame. It first computes the relativistic beta using time-of-flight and distance between the target and the hit position on NWB. Then it calculates the total energy assuming a mass of neutron. If charged particles and gamma rays have not been excluded, the energies for those hits will be off because they are not neutrons.

Parameters
  • name (str, default 'energy') – Name of the new column. The values will be in MeV.

  • rdf (ROOT.RDataFrame, optional) – The RDataFrame to be filtered. If None, the RDataFrame stored in self.rdf will be used.

  • inplace (bool, default False) – Whether to apply the definition in place.

Returns

rdf – The RDataFrame with the new column. If inplace=True, returns None.

Return type

ROOT.RDataFrame or None

define_neutron_cut(name='cut', light_bias=3.0, position_cut=True, positive_adc_cut=True, extra_cuts: Optional[list[str]] = None, rdf: Optional[cppyy.gbl.ROOT.RDataFrame] = None, inplace=False) → Optional[cppyy.gbl.ROOT.RDataFrame]

Define the neutron cut, cut.

Parameters
  • name (str, default 'cut') – Name of the new column.

  • light_bias (float, default 3.0) – The light output bias in MeVee.

  • position_cut (bool, default True) – Whether to apply the position cut. Shadow bar cuts are applied automatically if shadow bars are present in those runs. See self.shadow_bar_present.

  • positive_adc_cut (bool, default True) – Whether to apply the positive ADC cut. If True, all the fast and total ADCs must be positive.

  • extra_cuts (list[str], optional) – Extra cuts to be applied. Each cut should be a string that can be parsed by PyROOT. Any columns that are defined in the RDF can be used in the cut. The cuts will be joined by &&.

  • rdf (ROOT.RDataFrame, optional) – The RDataFrame to be filtered. If None, the RDataFrame stored in

  • inplace (bool, default False) – Whether to apply the cut in place.

filter_charged_particles(rdf: Optional[cppyy.gbl.ROOT.RDataFrame] = None, inplace=False) → Optional[cppyy.gbl.ROOT.RDataFrame]

Veto charged particles.

This function will filter out charged particles by requiring the multiplicity of veto wall to be 0.

Parameters
  • rdf (ROOT.RDataFrame, optional) – The RDataFrame to be filtered. If None, the RDataFrame stored in self.rdf will be used.

  • inplace (bool, default False) – Whether to apply the filter in place.

Returns

rdf – The filtered RDataFrame. If inplace=True, returns None.

Return type

ROOT.RDataFrame or None

filter_microball_multiplicity(bhat_range: Optional[tuple[float, float]] = None, multi_range: Optional[tuple[int, int]] = None, inplace=False) → Optional[cppyy.gbl.ROOT.RDataFrame]

Filter the RDataFrame by microball multiplicity.

Parameters
  • bhat_range (tuple[float, float], optional) – The range of normalized impact parameter, e.g. (0.0, 0.4). If this is not provided, multi_range must be provided.

  • multi_range (tuple[int, int], optional) – The inclusive range of microball multiplicity, e.g. (14, 30). If bhat_range is provided, this will be ignored.

  • inplace (bool, default False) – Whether to apply the filter in place.

Returns

rdf – The filtered RDataFrame. If inplace=True, returns None.

Return type

ROOT.RDataFrame or None

filter_tdc(tdc_range: tuple[float, float], tdc_branch_name='TDC_mb_nw', rdf: Optional[cppyy.gbl.ROOT.RDataFrame] = None, inplace=False) → Optional[cppyy.gbl.ROOT.RDataFrame]

Filter the RDataFrame by TDC.

Parameters
  • tdc_range (tuple[float, float]) – The range of TDC.

  • rdf (ROOT.RDataFrame, optional) – The RDataFrame to be filtered. If None, the RDataFrame stored in self.rdf will be used.

  • inplace (bool, default False) – Whether to apply the filter in place.

Returns

rdf – The filtered RDataFrame. If inplace=True, returns None.

Return type

ROOT.RDataFrame or None

get_coincidence_peak(branch_name='TDC_mb_nw', rdf: Optional[ROOT.RDataFrame] = None, return_histogram=False) → dict[Literal['mean', 'stdev'], float] | ROOT.TH1

Get the coincidence peak of the TDC.

You may want to apply the microball multiplicity filter before calling this function.