1 FIT
  Syntax: FIT[/qual] id1 [&idb1] [-nfun1 [-nfun2 ...]] id2 [&idb2] ...
          nmode
   where: qual       are (optional) qualifiers:
                     CHI         means do a chi**2 fit
                     LIKELIHOOD  means do a likelihood fit
                     SLIKELIHOOD means do a likelihood fit including
                                 Poisson function errrors
                     NORMALIZE   means use an overall normalization factor
                     FRACTION    normalizations are fractional
                     GAUSS       means fit a Gaussian
                     FLAT        means fit a flat line
                     LINE        means fit a line with a slope
          id1,id2    are the histograms to fit
          idb1,idb2  are the (optional) secondary identifiers
          nfun       are the numbers of functions not to be used in the
                     fit to the preceding id
          nmode      =  0 chi**2 fit
                     =  1 likelihood fit
                     =  2 likelihood fit including function statistics
                     = 1n parameters are fractions + overall normalization

  Gets you into  MINUIT, so that you can  actually start fitting. You must
  have already  fetched the histogram(s)  you want  to  fit and  added the
  function(s) you want to use.  If you have  not  given the qualfier  that
  says  which sort of fit you  want to do,  you  will be asked whether you
  want to do a chi**2 or likelihood fit.  Default is chi**2. Note that the
  chi**2 or the likelihood is stored in  register 111 (access it using the
  syntax  `R111'), and the confidence level  is stored in register 112, so
  that you can use it to put in a plot for example.

  A fit including the function statistics assumes that you are fitting
  with a histogram or some other function where the error on the function
  for each bin is given by the Poisson error on the value of the
  function, e.g. the function is a Monte Carlo histogram of the
  background without any reweighting or scale factor applied. This sort
  of fit implies that the parameters are fractions and an overall
  normalization is included.

  See the section in the manual "Fitting With Mn_Fit" for more complete
  details on how to fit.  See HELP Errors for more information on MINUIT
  errors and how to interpret them.

  The normal way to fit is by using the  `FUNCTION ADD' command to add the
  function(s) that you   want to use   and then using the   `FIT' command.
  However, if  you want to do  a simple fit of a  Gaussian, flat line or a
  line with a slope you can use the  `FIT/qual' syntax. This form will add
  the correct function(s),  disable  all others and   start  fitting.  The
  default MINUIT commands  are `MINIMIZE' followed  by  `DISPLAY'. You can
  change these using `SET FIT COMMANDS'.

  It is possible to fit 1 or 2  dimensional histograms or a series of data
  points. However, it is  not possible to fit to  a true scatter plot. Use
  the `PROJECT' command to make a  binned 2-D histogram out of the scatter
  plot if you want to fit it.

  You can simultaneously fit 2 or more plots by giving both their
  identifiers with the fit command.  If you want to use different
  background functions for each plot, but the same signal, e.g. when
  you fit a mass peak from 2 different decay modes, you should give
  the function numbers NOT to be used for a plot after you give its
  identifier.  However, if you are using the option `SET RATIO ON',
  which means that the areas are parametrized as ratios, this only
  works properly for 2 plots as Mn_Fit could not constrain the sum of
  a set of parameters to be 1 in MINUIT.

  If you give the `FIT' command inside a macro I recommend that you leave
  a blank line after the fitting mode This is because you are sometimes
  asked if you want to calculate new orthogonality limits.

  Note that when you  enter MINUIT, any limits  you have set on plots will
  be reset to 0 0.  This is so that  you do not get  confused, if you do a
  `DISPLAY' and only see part of the fit. You can of course set the limits
  to whatever you like  again, if you really do  not want to see the whole
  plot.

  When inside MINUIT it is possible to include or exclude regions from the
  fit and also to  constrain parameters relative  to other parameters. For
  more details see HELP MINUIT.

  The following is a list of commands which control how you fit and what
  parameters are used:
  SET NORM ON|OFF     Turns on/off an overall normalization factor.
  SET RATIO ON|OFF    Controls how the areas are parametrized, when
                      fitting more than one plot.
  SET FIT
    DEFAULT           Sets fitting option to default
    INTEGRATE ON|OFF  Turns on/off integrating functions across each bin.
    CONVOLUTE ON|OFF  Turns on/off convoluting functions with a Gaussian.
    AREA              Calculate the AREA for dipion and
                      fragmentation functions.
    COMMANDS          Commands used in the quick fitting mode

2 Likelihood

  The formula used for the likelihood is:

  -log(L(i)) = 2 * n(i) * log(n(i) / mu(i)) - (n(i) - mu(i))
!=

  where n(i)   is the number of entries in bin i
  and   mu(i)  is the expected number of entries

  If either `n(i)' or `mu(i)' are `<= 0', the log term is set to 0.
  If the log likelihood is negative then I take `1000 * abs(-log(L(i)))'
  for that point.

  This formula can be derived as follows. The probability of observing
  `n(i)' events in bin `i', when the expected number is `mu(i)' is:

  L(i) = exp(-mu(i)) * mu(i)**n(i) / n(i)!

  In the fit one wants to determine `mu(i)'. For the total likelihood the
  product of the individual likelihoods is taken so an arbitrary
  normalization can be applied to the likelihood function that can depend
  on `n(i)', but not on `mu(i)'. I therefore define:

         exp(-mu(i)) * mu(i)**n(i)   *             n(i)!
  L(i) = -------------------------       -----------------------
                    n(i)!                exp(-n(i)) * n(i)**n(i)
!=

         exp(-mu(i)) * mu(i)**n(i)
  L(i) = -------------------------
         exp(-n(i))  * n(i)**n(i)
!=

  -log(L(i)) = -(-mu(i) - n(i)) - n(i) * log(mu(i) / n(i))
!=

             = n(i) * log(n(i) / mu(i)) - (n(i) - mu(i))

  This value is multiplied by 2 so that a log likelihood change of 1
  corresponds to a 1 sigma error.
  The likelihoods are summed and then this is the value that is minimized.


2 Examples

!\begin{enumerate}
!\item
!^
  Example 1:
    To do a chi**2 fit to plot 300:
      FIT 300
      0

!\item
!^
  Example 2:
    Do a likelihood fit to plots 400 and 501&10 simultaneously, using the
    same functions for each plot:
      FIT/like 401 501&10

!\item
!^
  Example 3:
    Do a chi**2 fit to plots 1 and 17 simultaneously. Function 1
    will be used as the signal in all plots and function 4 will be the
    background for plot 1, function 3 for plot 17:
      func use 1 2 3 4
      fit/chi 1 -2 -3 17 -2  -4

!\end{enumerate}

