Tutorial for normalized sum of two functions Here: a background exponential and a crystalball function Parameters can be set: 
- with the TF1 object before adding the function (for 3) and 4))
 
- with the TF1NormSum object (first two are the coefficients, then the non constant parameters)
 
- with the TF1 object after adding the function
 
Sum can be constructed by:
- by a string containing the names of the functions and/or the coefficient in front
 
- by a string containg formulas like expo, gaus...
 
- by the list of functions and coefficients (which are 1 by default)
 
- by a std::vector for functions and coefficients
 
 Time to generate 1050000 events:  
Real time 0:00:00, CP time 0.160
****************************************
Minimizer is Minuit2 / Migrad
Chi2                      =      1018.73
NDf                       =          993
Edm                       =  9.65559e-06
NCalls                    =          233
NSignal                   =        50082   +/-   1231.21     
NBackground               =       998899   +/-   1569.86     
Mean                      =      2.99896   +/-   0.0022426   
Sigma                     =     0.297871   +/-   0.00230279  
Alpha                     =      2.12493   +/-   0.1368      
N                         =       1.1562   +/-   0.468136    
Slope                     =    -0.300341   +/-   0.000644187 
Time to fit using ROOT TF1Normsum: 
Real time 0:00:00, CP time 0.160
   
import ROOT
 
nsig = 50000
nbkg = 1000000
nEvents = nsig + nbkg
nBins = 1000
 
signal_mean = 3.0
f_cb = 
ROOT.TF1(
"MyCrystalBall", 
"crystalball", -5.0, 5.0)
 
f_exp = 
ROOT.TF1(
"MyExponential", 
"expo", -5.0, 5.0)
 
 
 
 
 
 
 
h_sum = 
ROOT.TH1D(
"h_ExpCB", 
"Exponential Bkg + CrystalBall function", nBins, -5.0, 5.0)
 
print(
"Time to generate {0} events:  ".
format(nEvents))
 
 
 
print("Time to fit using ROOT TF1Normsum: ")
 
for i, pref 
in enumerate([nsig, nbkg, signal_mean]):
 
            "testFitNormSum",
            "Difference found in fitted {0} - difference is {1:.2f} sigma".
format(
 
            ),
        )
 
 
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
 
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
 
- Author
 - Jonas Rembser, Lorenzo Moneta (C++ version) 
 
Definition in file fitNormSum.py.