3The
TF1 class has several additions
for its use from Python, which are also
4available in its subclasses
TF2 and
TF3.
6First,
TF1 instance can be initialized with user-defined Python functions. Given
a generic Python callable,
7the following can performed:
10def func(
x: numpy.ndarray, pars: numpy.ndarray) -> float:
11 return pars[0] *
x[0] *
x[0] +
x[1] * pars[0]
13my_func =
ROOT.
TF1(
"my_func", func, -10, 10, npar=2, ndim=2)
16Second, after performing the initialisation with
a Python functor, the
TF1 instance can be evaluated using the Pythonized
26def pyf_tf1_coulomb(
x,
p):
27 return
p[1] *
x[0] *
x[1] / (
p[0]**2) * math.exp(-
p[2] /
p[0])
29rtf1_coulomb =
ROOT.
TF1(
"my_func", pyf_tf1_coulomb, -10, 10, ndims = 2, npars = 3)
31#
x dataset: 5 pairs of particle charges
42 [8.99e9], # Coulomb constant k (in N·m²/C²)
43 [0.1] # Additional factor
for modulation
46#
Slice to avoid the dummy column of 10's
47res = rtf1_coulomb.EvalPar(
x[:, ::2], params)
54#
for illustration,
a sinusoidal
function with six parameters
55myFunction =
ROOT.
TF1(
"myExampleFunction",
"[0] + [1] * x + [2]*sin([3] * x) + [4]*cos([5] * x)", -5, 5)
57# declare the parameters
as a numpy.array or array.array
58myParams =
np.array([0.04, 0.4, 3.0, 3.14, 1.5, 3.14])
60# note: the following
line would also work by setting all six parameters equal to 3.0
61# myParams =
np.array([3.0] * 6)
static Roo_reg_AGKInteg1D instance
void SetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Restore the parameters from pars into the function.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
A 2-Dim function with parameters.
A 3-Dim function with parameters.
pythonization(class_name, ns="::", is_prefix=False)
Decorator that allows to pythonize C++ classes.
T Slice(const T &histo, std::vector< Int_t > &args)
Creates a sliced copy of the given histogram.
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Namespace for new ROOT classes and functions.
void evaluate(typename Architecture_t::Tensor_t &A, EActivationFunction f)
Apply the given activation function to each value in the given tensor A.
void variables(TString dataset, TString fin="TMVA.root", TString dirName="InputVariables_Id", TString title="TMVA Input Variables", Bool_t isRegression=kFALSE, Bool_t useTMVAStyle=kTRUE)