      REAL FUNCTION energy(Nproc)
*********************************************************
*                                                       *
* This file was generated by HUWFUN.                    *
*                                                       *
*********************************************************
*
*     Ntuple Id:      1    
*     Ntuple Title:   nTuple
*     Creation:       31/01/2007 14.50.59
*
*********************************************************
*
      LOGICAL         CHAIN
      CHARACTER*128   CFILE
      INTEGER         IDNEVT,NCHEVT,ICHEVT,I
      REAL            OBS(13)
*
      COMMON /PAWIDN/ IDNEVT,OBS
      COMMON /PAWCHN/ CHAIN, NCHEVT, ICHEVT
      COMMON /PAWCHC/ CFILE
*
*--   Ntuple Variable Declarations
*
      REAL VTX(3),PARTE(5),PARTPX(5),PARTPY(5),PARTPZ(5),PE_ESC(1000)
     + ,X_ESC(1000),Y_ESC(1000),Z_ESC(1000),PE_ENT_SCINT(1000)
     + ,X_ENT_SCINT(1000),Y_ENT_SCINT(1000),Z_ENT_SCINT(1000)
     + ,X_B_HIT(1000),Y_B_HIT(1000),Z_B_HIT(1000),E_B_HIT(1000)
     + ,X_S_HIT(1000),Y_S_HIT(1000),Z_S_HIT(1000),E_S_HIT(1000)
      INTEGER EVENT,NPART,PTYPE(5),NESCAPE,PTYP_ESC(1000),N_ENT_SCINT
     + ,PTYP_ENT_SCINT(1000),N_B_HITS,N_S_HITS
*
      COMMON /PAWCR4/ EVENT,VTX,NPART,PTYPE,PARTE,PARTPX,PARTPY,PARTPZ
     + ,NESCAPE,PTYP_ESC,PE_ESC,X_ESC,Y_ESC,Z_ESC,N_ENT_SCINT
     + ,PTYP_ENT_SCINT,PE_ENT_SCINT,X_ENT_SCINT,Y_ENT_SCINT,Z_ENT_SCINT
     + ,N_B_HITS,X_B_HIT,Y_B_HIT,Z_B_HIT,E_B_HIT,N_S_HITS,X_S_HIT
     + ,Y_S_HIT,Z_S_HIT,E_S_HIT
*
      real totalen
      integer init,Nproc,iLoop,BodyHits
      data init/1/
      save totalen,init,BodyHits
     
      if (init.eq.1) then
       totalen=0.0
       init=0
       iLoop=0
       BodyHits=0
      endif
*
*--   Enter user code here
*
      IF (N_B_HITS.gt.0) THEN
       DO I = 1,N_B_HITS
        totalen = totalen + E_B_HIT(I)
       END DO
       BodyHits = BodyHits + N_B_HITS
      END IF

      if (event.eq.NProc) then 
       print *,'Total energy for ',NProc,
     +  ' events is ',totalen
       print *,'Total number body hits for ',NProc,
     +  ' event is ',BodyHits
      endif
*



      END
