How to fit 2D histograms? Is there a way to fit a line to a scatter plot ?


When you have simple distributions where the Y value is nearly a function of the X variable, it is more convenient to use a profile histogram (see HBOOK routine HBPROF or PAW command PROFILE)

You can use the Histo/fit command with the predefined fitting functions on a profile histogram. See the macro below.

 macro fit2l
 h/del 0
 application comis quit
       subroutine make2d
       call hbook2(2,'test',40,0.,10.,40,0.,10.,0.)
       call hbprof(1,'test',40,0.,10.,0.,10.,'S')
       do 10 i=1,10000
          dev=0.5-rndm(i)
          x=10.*rndm(i)
          call hfill(1,x,x+dev,1.)
          call hfill(2,x,x+dev,1.)
   10  continue
       end
 quit
 call make2d
 zone 1 2
 h/pl 2
 hi/fit 1 p1
 return
 
 PAW > exe fit2l
      **********************************************
      *                                            *
      * Function minimization by SUBROUTINE HFITPO *
      * Variable-metric method                     *
      * ID =          1  CHOPT = TU                *
      *                                            *
      **********************************************
  Convergence when estimated distance to minimum (EDM) .LT.  0.10E+01

  FCN=   1.792382     FROM MIGRAD    STATUS=CONVERGED     31 CALLS       32 TOTAL
                      EDM=  0.21E-24    STRATEGY= 1      ERROR MATRIX ACCURATE

   EXT PARAMETER                                   STEP         FIRST
   NO.   NAME        VALUE          ERROR          SIZE      DERIVATIVE
    1      A0       0.55398E-01   0.85177E-01   0.26538E-02  -0.96222E-11
    2      A1       0.98826       0.14371E-01   0.25001E-02  -0.82064E-10

  CHISQUARE = 0.4717E-01  NPFIT =    40

 PAW >
 


Release NotesKnown bugsFAQsContributionsTutorialReference manualDown loadMiscellaneous

Paw.Support@cern.ch