fit module

Defines the basic components of the reaction plane fit.

class reaction_plane_fit.fit.BackgroundFitComponent(rp_orientation: str, *args, **kwargs)[source]

Bases: reaction_plane_fit.fit.FitComponent

Fit component in the background region.

Parameters:
  • rp_orientation (str) – Reaction plane orientation for the component.
  • *args (list) – Only use named args.
  • **kwargs (dict) – Named arguments to be passed on to the base component.
determine_fit_function(resolution_parameters: Dict[str, float], reaction_plane_parameter: reaction_plane_fit.base.ReactionPlaneParameter) → None[source]

Use the class parameters to determine the fit and background functions and store them.

set_data_limits(hist: pachyderm.histogram.Histogram1D) → pachyderm.histogram.Histogram1D[source]

Set the limits of the fit to only use near-side data (ie dPhi < pi/2)

Only the near-side will be used for the fit to avoid the signal at large dPhi on the away-side.

Parameters:hist (histogram.Histogram1D) – The input data.
Returns:The data limited to the near-side.
Return type:histogram.Histogram1D
class reaction_plane_fit.fit.FitComponent(fit_type: reaction_plane_fit.base.FitType, resolution_parameters: Dict[str, float], use_log_likelihood: bool = False)[source]

Bases: abc.ABC

A component of the fit.

Parameters:
  • fit_type (FitType) – Type (region and orientation) of the fit component.
  • resolution_parameters (dict) – Maps resolution parameters of the form “R22” (for the R_{2,2} parameter) to the value. Expects “R22” - “R82”
  • use_log_likelihood (bool) – If true, use log likelihood cost function. Often used when statistics are limited. Default: False
fit_type

Overall type of the fit.

Type:FitType
use_log_likelihood

True if the fit should be performed using log likelihood.

Type:bool
fit_function

Function of the component.

Type:function
cost_func

Cost function associated with the fit component.

Type:pachyderm.fit.CostFunctionBase
calculate_background_function_errors(x: numpy.ndarray) → numpy.ndarray[source]

Calculate the background function errors based on values from the fit.

Parameters:x – x values where the errors will be evaluated.
Returns:The calculated error values.
calculate_fit_errors(x: numpy.ndarray) → numpy.ndarray[source]

Calculate the fit function errors based on values from the fit.

Parameters:x – x values where the errors will be evaluated.
Returns:The calculated error values.
determine_fit_function(resolution_parameters: Dict[str, float], reaction_plane_parameter: reaction_plane_fit.base.ReactionPlaneParameter) → None[source]

Use the class parameters to determine the fit and background functions and store them.

determine_parameters_limits() → Dict[str, Union[bool, float, Tuple[float, float], Tuple[int, int]]][source]

Determine the parameter seed values, limits, step sizes for the component.

Note

These values should be specified with the proper names so that they will be recognized by Minuit. This is the user’s responsibility.

Parameters:None.
Returns:Dictionary of the function arguments which specifies their
evaluate_background(x: numpy.ndarray) → numpy.ndarray[source]

Evaluates the background components of the fit function.

In the case of a background component, this is identical to evaluate_fit(...). However, in the case of a signal component, this describes the background contribution to the signal.

Parameters:x – x values where the fit component will be evaluated.
Returns:Background function values at the given x values.
evaluate_fit(x: numpy.ndarray) → numpy.ndarray[source]

Evaluate the fit component.

Parameters:x – x values where the fit component will be evaluated.
Returns:Function values at the given x values.
region
rp_orientation
set_data_limits(hist: pachyderm.histogram.Histogram1D) → pachyderm.histogram.Histogram1D[source]

Extract the data from the histogram.

set_fit_type(region: Optional[str] = None, orientation: Optional[str] = None) → None[source]

Update the fit type.

Will use the any of the existing parameters if they are not specified.

Parameters:
  • region (str) – Region of the fit type.
  • orientation (str) – Orientation of the fit type.
Returns:

The fit type is set in the component.

Return type:

None

class reaction_plane_fit.fit.ReactionPlaneFit(resolution_parameters: Dict[str, float], use_log_likelihood: bool, signal_region: Optional[Tuple[float, float]] = None, background_region: Optional[Tuple[float, float]] = None, use_minos: bool = False, verbosity: int = 3)[source]

Bases: abc.ABC

Contains the reaction plane fit for one particular set of data and fit components.

Parameters:
  • resolution_parameters (dict) – Maps resolution parameters of the form “R22” (for the R_{2,2} parameter) to the value. Expects “R22” - “R82” (even RP only).
  • use_log_likelihood (bool) – If true, use log likelihood cost function. Often used when statistics are limited. Default: False
  • signal_region – Min and max extraction range for the signal dominated region. Should be provided as the absolute value (ex: (0., 0.6)).
  • background_region – Min and max extraction range for the background dominated region. Should be provided as the absolute value (ex: (0.8, 1.2)).
  • use_minos – Calculate the errors using Minos in addition to Hesse.
  • verbosity – Minuit verbosity level. Default: 3. This is extremely verbose, but it’s quite useful. 1 is commonly when you would like less verbose output.
resolution_parameters

Maps resolution parameters of the form “R22” (for the R_{2,2} parameter) to the value. Expects “R22” - “R82” (even RP only).

Type:dict
use_log_likelihood

If true, use log likelihood cost function. Often used when statistics are limited. Default: False

Type:bool
signal_region

Min and max extraction range for the signal dominated region. Should be provided as the absolute value (ex: (0., 0.6)).

background_region

Min and max extraction range for the background dominated region. Should be provided as the absolute value (ex: (0.8, 1.2)).

use_minos

Calculate the errors using Minos in addition to Hesse. It will give a better error estimate, but it will be much slower. Errors will be printed but not stored because we don’t store the errors directly (rather, we store the covariance matrix, which one cannot extract from Minos). By printing out the values, the use can check that the Hesse and Minos errors are similar, which will indicate that the function is well approximated by a hyperparabola at the minima (and thus Hesse errors are okay to be used).

fit_result

Result of the RP fit.

cost_func

Cost function for the RP fit.

Type:Callable
create_full_set_of_components(input_data: Dict[FitType, pachyderm.histogram.Histogram1D]) → Dict[str, reaction_plane_fit.fit.FitComponent][source]

Create the full set of fit components.

fit(data: Union[Dict[str, Dict[str, Union[Any, pachyderm.histogram.Histogram1D]]], Dict[FitType, pachyderm.histogram.Histogram1D]], user_arguments: Optional[Dict[str, Union[bool, float, Tuple[float, float], Tuple[int, int]]]] = None, skip_hesse: bool = False) → Tuple[bool, Dict[reaction_plane_fit.base.FitType, pachyderm.histogram.Histogram1D], iminuit._libiminuit.Minuit][source]

Perform the actual fit.

Parameters:
  • data – Input data to be used for the fit. The keys should either be of the form [region][orientation] or [FitType]. The values can be uproot or ROOT 1D histograms.
  • user_arguments – User arguments to override the arguments to the fit. Default: None.
  • skip_hesse – This should be used rarely and only with care! True if the hesse should _not_ be explicitly run. This is useful because sometimes it fails without a clear reason. If skipped, Minos will automatically be run, and it’s up to the user to ensure that the symmetric error estimates from Hesse run during the minimization are close to the Minos errors. If they’re not, it indicates that something went wrong in the error calculation and Hesse was failing for good reason. Default: False.
Returns:

(fit_success, formatted_data, minuit) where fit_success (bool) is True if the fitting

procedure was successful, formatted_data (dict) is the data reformatted in the preferred format for the fit, and minuit (iminuit.Minuit) is the minuit object, which is provided it is provided for specialized use cases. Note that the fit results (which contains most of the information in the minuit object) are stored in the class.

Return type:

tuple

reaction_plane_parameters = {}
read_fit_object(filename: str, data: Union[Dict[str, Dict[str, Union[Any, pachyderm.histogram.Histogram1D]]], Dict[FitType, pachyderm.histogram.Histogram1D]], user_arguments: Optional[Dict[str, Union[bool, float, Tuple[float, float], Tuple[int, int]]]] = None, y: ruamel.yaml.main.YAML = None) → Tuple[bool, Dict[reaction_plane_fit.base.FitType, pachyderm.histogram.Histogram1D]][source]

Read the fit results and setup the entire RPF object.

Using this method, the RPF object should be fully setup. The only step that isn’t performed is actually running the fit using Minuit. To read just the fit results into the object, use read_fit_results(...).

Parameters:
  • filename – Name of the file under which the fit results are saved.
  • data – Input data that was used for the fit. The keys should either be of the form [region][orientation] or [FitType]. The values can be uproot or ROOT 1D histograms.
  • user_arguments – User arguments to override the arguments to the fit. Default: None.
  • y – YAML object to be used for reading the result. If none is specified, one will be created automatically.
Returns:

(read_success, formatted_data) where read_success is True if the reading was successful, and formatted_data

is the input data reformatted according to the fit object format (ie. same as formatted_data returned when performing the fit). The results will be read into the fit object.

read_fit_results(filename: str, y: ruamel.yaml.main.YAML = None) → bool[source]

Read all fit results from the specified filename using YAML.

We don’t read the entire object from YAML because they we would have to deal with serializing many classes. Instead, we read the fit results, with the expectation that the fit object will be created independently, and then the results will be loaded.

To reconstruct the entire fit object, use read_fit_object(...).

Parameters:
  • filename – Name of the file under which the fit results are saved.
  • y – YAML object to be used for reading the result. If none is specified, one will be created automatically.
Returns:

True if the reading was successful. The results will be read into the fit object.

rp_orientations

Get the RP orientations (excluding the inclusive, which is the last entry).

write_fit_results(filename: str, y: ruamel.yaml.main.YAML = None) → bool[source]

Write all fit results to the specified filename using YAML.

We don’t write the entire object to YAML because they we would have to deal with serializing many classes. Instead, we write the results, with the expectation that the fit object will be created independently, and then the results will be loaded.

Parameters:
  • filename – Name of the file under which the fit results will be saved.
  • y – YAML object to be used for writing the result. If none is specified, one will be created automatically.
Returns:

True if the writing was successful.

class reaction_plane_fit.fit.SignalFitComponent(rp_orientation: str, *args, **kwargs)[source]

Bases: reaction_plane_fit.fit.FitComponent

Fit component in the signal region.

Parameters:
  • rp_orientation (str) – Reaction plane orientation for the component.
  • *args (list) – Only use named args.
  • **kwargs (dict) – Named arguments to be passed on to the base component.
determine_fit_function(resolution_parameters: Dict[str, float], reaction_plane_parameter: reaction_plane_fit.base.ReactionPlaneParameter) → None[source]

Use the class parameters to determine the fit and background functions and store them.