ROOT 6.08/07 Reference Guide |
Fits MC fractions to data histogram.
A la HMCMLL, see R. Barlow and C. Beeston, Comp. Phys. Comm. 77 (1993) 219-228, and http://www.hep.man.ac.uk/~roger/hfrac.f
The virtue of this fit is that it takes into account both data and Monte Carlo statistical uncertainties. The way in which this is done is through a standard likelihood fit using Poisson statistics; however, the template (MC) predictions are also varied within statistics, leading to additional contributions to the overall likelihood. This leads to many more fit parameters (one per bin per template), but the minimisation with respect to these additional parameters is done analytically rather than introducing them as formal fit parameters. Some special care needs to be taken in the case of bins with zero content. For more details please see the original publication cited above.
An example application of this fit is given below. For a TH1* histogram ("data") fitted as the sum of three Monte Carlo sources ("mc"):
A few assumptions need to be made for the fit procedure to be carried out: 1 The total number of events in each template is not too small (so that its Poisson uncertainty can be neglected). 2 The number of events in each bin is much smaller than the total number of events in each template (so that multinomial uncertainties can be replaced with Poisson uncertainties).
Biased fit uncertainties may result if these conditions are not fulfilled (see e.g. arXiv:0803.2711).
A fit object is instantiated through TFractionFitter* fit = new TFractionFitter(data, mc); A number of basic checks (intended to ensure that the template histograms represent the same "kind" of distribution as the data one) are carried out. The TVirtualFitter object is then addressed and all fit parameters (the template fractions) declared (initially unbounded).
Fit parameters can be constrained through
fit->Constrain(parameter #, lower bound, upper bound);
Setting lower bound = upper bound = 0 removes the constraint (a la Minuit); however, a function
fit->Unconstrain(parameter #)
is also provided to simplify this.
The function
TVirtualFitter* vFit = fit->GetFitter();
is provided for direct access to the TVirtualFitter object. This allows to set and fix parameter values, and set step sizes directly.
The fit range can be restricted through
fit->SetRangeX(first bin #, last bin #);
and freed using
fit->ReleaseRangeX();
For 2D histograms the Y range can be similarly restricted using
fit->SetRangeY(first bin #, last bin #); fit->ReleaseRangeY();
and for 3D histograms also
fit->SetRangeZ(first bin #, last bin #); fit->ReleaseRangeZ();
It is also possible to exclude individual bins from the fit through
fit->ExcludeBin(bin #);
where the given bin number is assumed to follow the TH1::GetBin() numbering. Any bins excluded in this way can be included again using the corresponding
fit->IncludeBin(bin #);
Weights histograms (for a motivation see the above publication) can be specified for the individual MC sources through
fit->SetWeight(parameter #, pointer to weights histogram);
and unset by specifying a null pointer.
The fit is carried out through
Int_t status = fit->Fit();
where status is the code returned from the "MINIMIZE" command. For fits that converged, parameter values and errors can be obtained through
fit->GetResult(parameter #, value, error);
and the histogram corresponding to the total Monte Carlo prediction (which is not the same as a simple weighted sum of the input Monte Carlo distributions) can be obtained by
TH1* result = fit->GetPlot();
It is possible to change the histogram being fitted through
fit->SetData(TH1* data);
and to change the template histogram for a given parameter number through
fit->SetMC(parameter #, TH1* MC);
This can speed up code in case of multiple data or template histograms; however, it should be done with care as any settings are taken over from the previous fit. In addition, neither the dimensionality nor the numbers of bins of the histograms should change (in that case it is better to instantiate a new TFractionFitter object).
Any serious inconsistency results in an error.
Definition at line 29 of file TFractionFitter.h.
Public Member Functions | |
TFractionFitter () | |
TFractionFitter default constructor. More... | |
TFractionFitter (TH1 *data, TObjArray *MCs, Option_t *option="") | |
TFractionFitter constructor. More... | |
virtual | ~TFractionFitter () |
TFractionFitter default destructor. More... | |
void | Constrain (Int_t parm, Double_t low, Double_t high) |
Constrain the values of parameter number <parm> (the parameter numbering follows that of the input template vector). More... | |
void | ErrorAnalysis (Double_t UP) |
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation. More... | |
Double_t | EvaluateFCN (const Double_t *par) |
void | ExcludeBin (Int_t bin) |
Exclude the given bin from the fit. More... | |
TFitResultPtr | Fit () |
Perform the fit with the default UP value. More... | |
Double_t | GetChisquare () const |
Return the likelihood ratio Chi-squared (chi2) for the fit. More... | |
ROOT::Fit::Fitter * | GetFitter () const |
Give direct access to the underlying fitter class. More... | |
TH1 * | GetMCPrediction (Int_t parm) const |
Return the adjusted MC template (Aji) for template (parm). More... | |
Int_t | GetNDF () const |
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed during a fit. More... | |
TH1 * | GetPlot () |
Return the "template prediction" corresponding to the fit result (this is not the same as the weighted sum of template distributions, as template statistical uncertainties are taken into account). More... | |
Double_t | GetProb () const |
return the fit probability More... | |
void | GetResult (Int_t parm, Double_t &value, Double_t &error) const |
Obtain the fit result for parameter <parm> (the parameter numbering follows that of the input template vector). More... | |
void | IncludeBin (Int_t bin) |
Include the given bin in the fit, if it was excluded before using ExcludeBin(). More... | |
void | ReleaseRangeX () |
Release restrictions on the X range of the histogram to be used in the fit. More... | |
void | ReleaseRangeY () |
Release restrictions on the Y range of the histogram to be used in the fit. More... | |
void | ReleaseRangeZ () |
Release restrictions on the Z range of the histogram to be used in the fit. More... | |
void | SetData (TH1 *data) |
Change the histogram to be fitted to. More... | |
void | SetMC (Int_t parm, TH1 *MC) |
Change the histogram for template number <parm>. More... | |
void | SetRangeX (Int_t low, Int_t high) |
Set the X range of the histogram to be used in the fit. More... | |
void | SetRangeY (Int_t low, Int_t high) |
Set the Y range of the histogram to be used in the fit (2D or 3D histograms only). More... | |
void | SetRangeZ (Int_t low, Int_t high) |
Set the Z range of the histogram to be used in the fit (3D histograms only). More... | |
void | SetWeight (Int_t parm, TH1 *weight) |
Set bin by bin weights for template number <parm> (the parameter numbering follows that of the input template vector). More... | |
void | UnConstrain (Int_t parm) |
Remove the constraints on the possible values of parameter <parm>. More... | |
Public Member Functions inherited from TObject | |
TObject () | |
TObject constructor. More... | |
TObject (const TObject &object) | |
TObject copy ctor. More... | |
virtual | ~TObject () |
TObject destructor. More... | |
void | AbstractMethod (const char *method) const |
Use this method to implement an "abstract" method that you don't want to leave purely abstract. More... | |
virtual void | AppendPad (Option_t *option="") |
Append graphics object to current pad. More... | |
virtual void | Browse (TBrowser *b) |
Browse object. May be overridden for another default action. More... | |
virtual const char * | ClassName () const |
Returns name of class to which the object belongs. More... | |
virtual void | Clear (Option_t *="") |
virtual TObject * | Clone (const char *newname="") const |
Make a clone of an object using the Streamer facility. More... | |
virtual Int_t | Compare (const TObject *obj) const |
Compare abstract method. More... | |
virtual void | Copy (TObject &object) const |
Copy this to obj. More... | |
virtual void | Delete (Option_t *option="") |
Delete this object. More... | |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
Computes distance from point (px,py) to the object. More... | |
virtual void | Draw (Option_t *option="") |
Default Draw method for all objects. More... | |
virtual void | DrawClass () const |
Draw class inheritance tree of the class to which this object belongs. More... | |
virtual TObject * | DrawClone (Option_t *option="") const |
Draw a clone of this object in the current pad. More... | |
virtual void | Dump () const |
Dump contents of object on stdout. More... | |
virtual void | Error (const char *method, const char *msgfmt,...) const |
Issue error message. More... | |
virtual void | Execute (const char *method, const char *params, Int_t *error=0) |
Execute method on this object with the given parameter string, e.g. More... | |
virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=0) |
Execute method on this object with parameters stored in the TObjArray. More... | |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
Execute action corresponding to an event at (px,py). More... | |
virtual void | Fatal (const char *method, const char *msgfmt,...) const |
Issue fatal error message. More... | |
virtual TObject * | FindObject (const char *name) const |
Must be redefined in derived classes. More... | |
virtual TObject * | FindObject (const TObject *obj) const |
Must be redefined in derived classes. More... | |
virtual Option_t * | GetDrawOption () const |
Get option used by the graphics system to draw this object. More... | |
virtual const char * | GetIconName () const |
Returns mime type name of object. More... | |
virtual const char * | GetName () const |
Returns name of object. More... | |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
Returns string containing info about the object at position (px,py). More... | |
virtual Option_t * | GetOption () const |
virtual const char * | GetTitle () const |
Returns title of object. More... | |
virtual UInt_t | GetUniqueID () const |
Return the unique object id. More... | |
virtual Bool_t | HandleTimer (TTimer *timer) |
Execute action in response of a timer timing out. More... | |
virtual ULong_t | Hash () const |
Return hash value for this object. More... | |
virtual void | Info (const char *method, const char *msgfmt,...) const |
Issue info message. More... | |
virtual Bool_t | InheritsFrom (const char *classname) const |
Returns kTRUE if object inherits from class "classname". More... | |
virtual Bool_t | InheritsFrom (const TClass *cl) const |
Returns kTRUE if object inherits from TClass cl. More... | |
virtual void | Inspect () const |
Dump contents of this object in a graphics canvas. More... | |
void | InvertBit (UInt_t f) |
virtual Bool_t | IsEqual (const TObject *obj) const |
Default equal comparison (objects are equal if they have the same address in memory). More... | |
virtual Bool_t | IsFolder () const |
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More... | |
Bool_t | IsOnHeap () const |
virtual Bool_t | IsSortable () const |
Bool_t | IsZombie () const |
virtual void | ls (Option_t *option="") const |
The ls function lists the contents of a class on stdout. More... | |
void | MayNotUse (const char *method) const |
Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). More... | |
virtual Bool_t | Notify () |
This method must be overridden to handle object notification. More... | |
void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
Use this method to declare a method obsolete. More... | |
void | operator delete (void *ptr) |
Operator delete. More... | |
void | operator delete[] (void *ptr) |
Operator delete []. More... | |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, void *vp) |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, void *vp) |
TObject & | operator= (const TObject &rhs) |
TObject assignment operator. More... | |
virtual void | Paint (Option_t *option="") |
This method must be overridden if a class wants to paint itself. More... | |
virtual void | Pop () |
Pop on object drawn in a pad to the top of the display list. More... | |
virtual void | Print (Option_t *option="") const |
This method must be overridden when a class wants to print itself. More... | |
virtual Int_t | Read (const char *name) |
Read contents of object with specified name from the current directory. More... | |
virtual void | RecursiveRemove (TObject *obj) |
Recursively remove this object from a list. More... | |
void | ResetBit (UInt_t f) |
virtual void | SaveAs (const char *filename="", Option_t *option="") const |
Save this object in the file specified by filename. More... | |
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
Save a primitive as a C++ statement(s) on output stream "out". More... | |
void | SetBit (UInt_t f, Bool_t set) |
Set or unset the user status bits as specified in f. More... | |
void | SetBit (UInt_t f) |
virtual void | SetDrawOption (Option_t *option="") |
Set drawing option for object. More... | |
virtual void | SetUniqueID (UInt_t uid) |
Set the unique object id. More... | |
virtual void | SysError (const char *method, const char *msgfmt,...) const |
Issue system error message. More... | |
Bool_t | TestBit (UInt_t f) const |
Int_t | TestBits (UInt_t f) const |
virtual void | UseCurrentStyle () |
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. More... | |
virtual void | Warning (const char *method, const char *msgfmt,...) const |
Issue warning message. More... | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) |
Write this object to the current directory. More... | |
virtual Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const |
Write this object to the current directory. More... | |
Protected Attributes | |
TObjArray | fAji |
Double_t | fChisquare |
TH1 * | fData |
std::vector< Int_t > | fExcludedBins |
Bool_t | fFitDone |
ROOT::Fit::Fitter * | fFractionFitter |
Double_t * | fFractions |
Int_t | fHighLimitX |
Int_t | fHighLimitY |
Int_t | fHighLimitZ |
Double_t | fIntegralData |
Double_t * | fIntegralMCs |
Int_t | fLowLimitX |
Int_t | fLowLimitY |
Int_t | fLowLimitZ |
TObjArray | fMCs |
Int_t | fNDF |
Int_t | fNpar |
Int_t | fNpfits |
TH1 * | fPlot |
TObjArray | fWeights |
Private Member Functions | |
void | CheckConsistency () |
Function used internally to check the consistency between the various histograms. More... | |
void | CheckParNo (Int_t parm) const |
Function for internal use, checking parameter validity An invalid parameter results in an error. More... | |
void | ComputeChisquareLambda () |
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for details. More... | |
void | ComputeFCN (Double_t &f, const Double_t *par, Int_t flag) |
Used internally to compute the likelihood value. More... | |
void | FindPrediction (int bin, double &t_i, int &k_0, double &A_ki) const |
Function used internally to obtain the template prediction in the individual bins 'bin' <=> 'i' (paper) 'par' <=> 'j' (paper) More... | |
void | GetRanges (Int_t &minX, Int_t &maxX, Int_t &minY, Int_t &maxY, Int_t &minZ, Int_t &maxZ) const |
Used internally to obtain the bin ranges according to the dimensionality of the histogram and the limits set by hand. More... | |
bool | IsExcluded (Int_t bin) const |
Function for internal use, checking whether the given bin is excluded from the fit or not. More... | |
Additional Inherited Members | |
Public Types inherited from TObject | |
enum | { kIsOnHeap = 0x01000000, kNotDeleted = 0x02000000, kZombie = 0x04000000, kBitMask = 0x00ffffff } |
enum | { kSingleKey = BIT(0), kOverwrite = BIT(1), kWriteDelete = BIT(2) } |
enum | EStatusBits { kCanDelete = BIT(0), kMustCleanup = BIT(3), kObjInCanvas = BIT(3), kIsReferenced = BIT(4), kHasUUID = BIT(5), kCannotPick = BIT(6), kNoContextMenu = BIT(8), kInvalidObject = BIT(13) } |
Static Public Member Functions inherited from TObject | |
static Long_t | GetDtorOnly () |
Return destructor only flag. More... | |
static Bool_t | GetObjectStat () |
Get status of object stat flag. More... | |
static void | SetDtorOnly (void *obj) |
Set destructor only flag. More... | |
static void | SetObjectStat (Bool_t stat) |
Turn on/off tracking of objects in the TObjectTable. More... | |
Protected Member Functions inherited from TObject | |
virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
Interface to ErrorHandler (protected). More... | |
void | MakeZombie () |
#include <TFractionFitter.h>
TFractionFitter::TFractionFitter | ( | ) |
TFractionFitter default constructor.
Definition at line 162 of file TFractionFitter.cxx.
TFractionFitter constructor.
Does a complete initialisation (including consistency checks, default fit range as the whole histogram but without under- and overflows, and declaration of the fit parameters). Note that the histograms are not copied, only references are used.
[in] | data | histogram to be fitted |
[in] | MCs | array of TH1* corresponding template distributions |
[in] | option | can be used to control the print level of the minimization algorithm
|
Definition at line 192 of file TFractionFitter.cxx.
|
virtual |
TFractionFitter default destructor.
Definition at line 254 of file TFractionFitter.cxx.
|
private |
Function used internally to check the consistency between the various histograms.
Checks are performed on nonexistent or empty histograms, the precise histogram class, and the number of bins. In addition, integrals over the "allowed" bin ranges are computed. Any inconsistency results in a error.
Definition at line 481 of file TFractionFitter.cxx.
Function for internal use, checking parameter validity An invalid parameter results in an error.
Definition at line 324 of file TFractionFitter.cxx.
|
private |
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for details.
Definition at line 909 of file TFractionFitter.cxx.
Used internally to compute the likelihood value.
Definition at line 661 of file TFractionFitter.cxx.
Constrain the values of parameter number <parm> (the parameter numbering follows that of the input template vector).
Use UnConstrain() to remove this constraint.
Definition at line 460 of file TFractionFitter.cxx.
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation.
Definition at line 580 of file TFractionFitter.cxx.
Definition at line 68 of file TFractionFitter.h.
Exclude the given bin from the fit.
The bin numbering to be used is that of TH1::GetBin().
Definition at line 415 of file TFractionFitter.cxx.
|
private |
Function used internally to obtain the template prediction in the individual bins 'bin' <=> 'i' (paper) 'par' <=> 'j' (paper)
Definition at line 752 of file TFractionFitter.cxx.
TFitResultPtr TFractionFitter::Fit | ( | ) |
Perform the fit with the default UP value.
The value returned is the minimisation status.
Definition at line 550 of file TFractionFitter.cxx.
Double_t TFractionFitter::GetChisquare | ( | ) | const |
Return the likelihood ratio Chi-squared (chi2) for the fit.
The value is computed when the fit is executed successfully. Chi2 calculation is based on the "likelihood ratio" lambda, lambda = L(y;n) / L(m;n), where L(y;n) is the likelihood of the fit result <y> describing the data <n> and L(m;n) is the likelihood of an unknown "true" underlying distribution <m> describing the data <n>. Since <m> is unknown, the data distribution is used instead, lambda = L(y;n) / L(n;n). Note that this ratio is 1 if the fit is perfect. The chi2 value is then computed according to chi2 = -2*ln(lambda). This parameter can be shown to follow a Chi-square distribution. See for example S. Baker and R. Cousins, "Clarification of the use of chi-square and likelihood functions in fits to histograms", Nucl. Instr. Meth. A221, pp. 437-442 (1984)
Definition at line 878 of file TFractionFitter.cxx.
ROOT::Fit::Fitter * TFractionFitter::GetFitter | ( | ) | const |
Give direct access to the underlying fitter class.
This can be used e.g. to modify parameter values or step sizes.
Definition at line 316 of file TFractionFitter.cxx.
Return the adjusted MC template (Aji) for template (parm).
Note that the (Aji) times fractions only sum to the total prediction of the fit if all weights are 1. Note also that the histogram is managed by the TFractionFitter class, so the returned pointer will be invalid if the class is deleted
Definition at line 956 of file TFractionFitter.cxx.
Int_t TFractionFitter::GetNDF | ( | ) | const |
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed during a fit.
The number of degrees of freedom corresponds to the number of points used in the fit minus the number of templates.
Definition at line 889 of file TFractionFitter.cxx.
TH1 * TFractionFitter::GetPlot | ( | ) |
Return the "template prediction" corresponding to the fit result (this is not the same as the weighted sum of template distributions, as template statistical uncertainties are taken into account).
Note that the name of this histogram will simply be the same as that of the "data" histogram, prefixed with the string "Fraction fit to hist: ". Note also that the histogram is managed by the TFractionFitter class, so the returned pointer will be invalid if the class is deleted
Definition at line 618 of file TFractionFitter.cxx.
Double_t TFractionFitter::GetProb | ( | ) | const |
return the fit probability
Definition at line 898 of file TFractionFitter.cxx.
|
private |
Used internally to obtain the bin ranges according to the dimensionality of the histogram and the limits set by hand.
Definition at line 636 of file TFractionFitter.cxx.
Obtain the fit result for parameter <parm> (the parameter numbering follows that of the input template vector).
Definition at line 599 of file TFractionFitter.cxx.
Include the given bin in the fit, if it was excluded before using ExcludeBin().
The bin numbering to be used is that of TH1::GetBin().
Definition at line 432 of file TFractionFitter.cxx.
|
private |
Function for internal use, checking whether the given bin is excluded from the fit or not.
Definition at line 449 of file TFractionFitter.cxx.
void TFractionFitter::ReleaseRangeX | ( | ) |
Release restrictions on the X range of the histogram to be used in the fit.
Definition at line 347 of file TFractionFitter.cxx.
void TFractionFitter::ReleaseRangeY | ( | ) |
Release restrictions on the Y range of the histogram to be used in the fit.
Definition at line 375 of file TFractionFitter.cxx.
void TFractionFitter::ReleaseRangeZ | ( | ) |
Release restrictions on the Z range of the histogram to be used in the fit.
Definition at line 405 of file TFractionFitter.cxx.
Change the histogram to be fitted to.
Notes:
Definition at line 268 of file TFractionFitter.cxx.
Change the histogram for template number <parm>.
Notes:
Definition at line 280 of file TFractionFitter.cxx.
Set the X range of the histogram to be used in the fit.
Use ReleaseRangeX() to go back to fitting the full histogram. The consistency check ensures that no empty fit range occurs (and also recomputes the bin content integrals).
[in] | low | lower X bin number |
[in] | high | upper X bin number |
Definition at line 338 of file TFractionFitter.cxx.
Set the Y range of the histogram to be used in the fit (2D or 3D histograms only).
Use ReleaseRangeY() to go back to fitting the full histogram. The consistency check ensures that no empty fit range occurs (and also recomputes the bin content integrals).
[in] | low | lower X bin number |
[in] | high | upper X bin number |
Definition at line 361 of file TFractionFitter.cxx.
Set the Z range of the histogram to be used in the fit (3D histograms only).
Use ReleaseRangeY() to go back to fitting the full histogram. The consistency check ensures that no empty fit range occurs (and also recomputes the bin content integrals).
[in] | low | lower X bin number |
[in] | high | upper X bin number |
Definition at line 390 of file TFractionFitter.cxx.
Set bin by bin weights for template number <parm> (the parameter numbering follows that of the input template vector).
Weights can be "unset" by passing a null pointer. Consistency of the weights histogram with the data histogram is checked at this point, and an error in case of problems.
Definition at line 295 of file TFractionFitter.cxx.
Remove the constraints on the possible values of parameter <parm>.
Definition at line 469 of file TFractionFitter.cxx.
|
protected |
Definition at line 98 of file TFractionFitter.h.
|
protected |
Definition at line 96 of file TFractionFitter.h.
|
protected |
Definition at line 101 of file TFractionFitter.h.
|
protected |
Definition at line 92 of file TFractionFitter.h.
|
protected |
Definition at line 85 of file TFractionFitter.h.
|
protected |
Definition at line 108 of file TFractionFitter.h.
|
protected |
Definition at line 106 of file TFractionFitter.h.
|
protected |
Definition at line 87 of file TFractionFitter.h.
|
protected |
Definition at line 89 of file TFractionFitter.h.
|
protected |
Definition at line 91 of file TFractionFitter.h.
|
protected |
Definition at line 104 of file TFractionFitter.h.
|
protected |
Definition at line 105 of file TFractionFitter.h.
|
protected |
Definition at line 86 of file TFractionFitter.h.
|
protected |
Definition at line 88 of file TFractionFitter.h.
|
protected |
Definition at line 90 of file TFractionFitter.h.
|
protected |
Definition at line 102 of file TFractionFitter.h.
|
protected |
Definition at line 95 of file TFractionFitter.h.
|
protected |
Definition at line 110 of file TFractionFitter.h.
|
protected |
Definition at line 94 of file TFractionFitter.h.
|
protected |
Definition at line 107 of file TFractionFitter.h.
|
protected |
Definition at line 103 of file TFractionFitter.h.