***
*     hxuser.f
***
*
      SUBROUTINE UHINIT
*
************************************************************************
*                                                                      *
*             To initialise HBOOK                                      *
*                                                                      *
************************************************************************
*
cn..          Define of HBOOK word
      integer istat
      character chtags(3)*5
      data chtags/'Pt','ToF','N'/
C
***   -----------------------------------------------------------------
*
*             Open HBOOK
*
      CALL HROPEN(1,'PHENIX','phenix.nt','n',1024,istat)
**
*
*             Booking Histogram & Ntuple file
*
      CALL HBOOKN(10,'Ntuple',3,'PHENIX',5000,chtags)
C
      CALL HBOOK1(100,'Pt-distribution(MeV/c)',100,0.,2000.,0.)
c      CALL HBOOK1(110,'dN/(Pt*dPt)(MeV/c)',100,0.,2000.,0.)
c      CALL HBOOK1(120,'rapidity-distribution',100,-0.1,0.1,0.)
C
      CALL HBOOK1(200,'(ToF) Energy loss(MeV)',100,0.,20.,0.)
C
      CALL HBOOK1(300,'(EMcal) Cherenkov(Pt=100MeV)',100,0.,0.5E+4,0.)
      CALL HBOOK1(310,'(EMcal) Cherenkov(Pt=200MeV)',100,0.,1.E+4,0.)
      CALL HBOOK1(320,'(EMcal) Cherenkov(Pt=300MeV)',100,0.,2.E+4,0.)
      CALL HBOOK1(330,'(EMcal) Cherenkov(Pt=500MeV)',100,0.,2.E+4,0.)
      CALL HBOOK1(340,'(EMcal) Cherenkov(Pt=800MeV)',100,0.,3.E+4,0.)
      CALL HBOOK1(350,'(EMcal) Cherenkov(Pt=1000MeV)',100,0.,3.E+4,0.)
      CALL HBOOK1(360,'(EMcal) Cherenkov(Pt=1500MeV)',100,0.,5.E+4,0.)
      CALL HBOOK1(370,'(EMcal) Cherenkov(Pt=2000MeV)',100,0.,5.E+4,0.)
      CALL HBOOK1(380,'(EMcal) Cherenkov(Pt=3000MeV)',100,0.,10.E+4,0.)
      CALL HBOOK1(390,'(EMcal) Cherenkov(Pt=5000MeV)',100,0.,10.E+4,0.)
*
      END
*
***
*
      SUBROUTINE HUOUT
*
************************************************************************
*                                                                      *
*             User routine called at the end of HBOOK.                 *
*                                                                      *
************************************************************************
*
*KEEP,user common block
      common/uELOSS/IDtof,IDcal,pt,ELOSStof,ELOSScal,Nckov
C
*KEND.
C
      real event(3)
      real pt,ELOSStof,ELOSScal,Nckov
      integer icycle,IDtof,IDcal
*     ------------------------------------------------------------------
**
*
*             Filling Histogram file
*
      write(6,*) IEVENT,pt*1.0+E3,'(MeV)  ToF ',ELOSStof,'EMcal',Nckov
C
      event(1) = pt*1.0+E3
      event(2) = ELOSStof
      event(3) = Nckov
C
c      ELOSStof = HSUM(IDtof)
      if(ELOSStof .ge. 0.1)then
         CALL HFILL(200,ELOSStof,0.,1.)
      endif
C
      if((pt .ge. 0.05) .and. (pt .lt.0.15 ))then
         CALL HFILL(300,Nckov,0.,1.)
      endif
      if((pt .ge. 0.15) .and. (pt .lt.0.25 ))then
         CALL HFILL(310,Nckov,0.,1.)
      endif
      if((pt .ge. 0.25) .and. (pt .lt.0.35 ))then
         CALL HFILL(320,Nckov,0.,1.)
      endif
      if((pt .ge. 0.45) .and. (pt .lt.0.55 ))then
         CALL HFILL(330,Nckov,0.,1.)
      endif
      if((pt .ge. 0.75) .and. (pt .lt.0.85 ))then
         CALL HFILL(340,Nckov,0.,1.)
      endif
      if((pt .ge. 0.95) .and. (pt .lt.1.05 ))then
         CALL HFILL(350,Nckov,0.,1.)
      endif
      if((pt .ge. 1.45) .and. (pt .lt.1.55 ))then
         CALL HFILL(360,Nckov,0.,1.)
      endif
      if((pt .ge. 1.90) .and. (pt .lt.2.10 ))then
         CALL HFILL(370,Nckov,0.,1.)
      endif
      if((pt .ge. 2.90) .and. (pt .lt.3.10 ))then
         CALL HFILL(380,Nckov,0.,1.)
      endif
      if((pt .ge. 4.90) .and. (pt .lt.5.10 ))then
      if((pt .ge. 4.90) .and. (pt .lt.5.10 ))then
         CALL HFILL(390,Nckov,0.,1.)
      endif
C
      CALL HFN(10,event)
      ELOSStof = 0.
      Nckov = 0.
      Nckov = 0
C
      NAMES(3)='    '
**
*             Write a histogram onto file
*
c      CALL HROUT(IDtof,icycle,' ')
c      CALL HROUT(IDcal,icycle,' ')
C
c      CALL HDELET(IDtof)
c      CALL HDELET(IDcal)
*
      END
*
*
