*
* $Id$
*
* $Log$
*
*CMZ :  3.00/00 25/01/2002  19.00.30  by  Marialuigia Ambriola
*CMZ :  2.01/00 08/03/2000  18.32.08  by  Unknown
*CMZ :  2.00/00 29/02/2000  14.18.34  by  Francesco Cafagna
*CMZ :  1.02/00 07/11/99  17.40.38  by  Francesco Cafagna
*CMZ :  1.01/00 22/05/96  12.52.18  by  Francesco Cafagna
*CMZ :  1.00/03 19/04/96  14.07.01  by  Francesco Cafagna
*CMZ :  1.00/02 05/04/96  15.19.07  by  Francesco Cafagna
*-- Author :    Francesco Cafagna   30/11/95
      SUBROUTINE GPHBK
************************************************************************
*                                                                      *
*                                                                      *
*             To book the user's histograms                            *
*                                                                      *
* Called by: UGINIT                                                    *
* Author: Francesco Cafagna, 30/11/95 16.20.45                         *
*                                                                      *
************************************************************************
#include "gppntp.inc"
#include "gpgene.inc"
#include "gpphit.inc"
#include "gppdigi.inc"
#include "gptof.inc"
#include "gptrd.inc"
#include "gpcat.inc"
#include "gpcas.inc"
#include "gpspe.inc"
#include "gpcal.inc"
#include "gptotr.inc"
*
#include "gpkey.inc"
      INTEGER ISTAT,IERR
*ML:
      CHARACTER*50 CHFORM
*END ML.
*
*     ------------------------------------------------------------------
C
C You need all the previous commons to declare the CWN-tpla blocks to HBOOK
C
      CALL HCDIR('//GPAMELA',' ')
      CALL HBNT(NCWN,'GPAMELA','D')
      CALL HBNAME(NCWN,'GENERAL',IRUN,'IRUN:I,IEVNT:I,IPA:I,X0,Y0,'
     +//'Z0,THETA,PHI,P0')
C
C TOF
C
      IF(HTOF) THEN
         IF(HLONG) THEN
            CALL HBNAME(NCWN,'TOF',NTHTOF,'NTHTOF:I::[0,100],'
     +           //'IPLTOF(NTHTOF):I::[0,7],IPADDLE(NTHTOF):I::[0,16],'
     +           //'IPARTOF(NTHTOF):I::[0,100],XINTOF(NTHTOF),'
     +           //'YINTOF(NTHTOF),'
     +           //'ZINTOF(NTHTOF),XOUTTOF(NTHTOF),YOUTTOF(NTHTOF),'
     +           //'ZOUTTOF(NTHTOF),'
     +           //'ERELTOF(NTHTOF),TIMETOF(NTHTOF),PATHTOF(NTHTOF),'
     +           //'P0TOF(NTHTOF)')
         ELSE
            CALL HBNAME(NCWN,'TOF',NTHTOF,'NTHTOF:I::[0,100],'
     +           //'IPLTOF(NTHTOF):I::[0,7],IPADDLE(NTHTOF):I::[0,16],'
     +           //'IPARTOF(NTHTOF):I::[0,100]')
            CALL HBNAME(NCWN,'TOF',XAVTOF,'XAVTOF(NTHTOF),'
     +           //'YAVTOF(NTHTOF),ZAVTOF(NTHTOF)')
            CALL HBNAME(NCWN,'TOF',ERELTOF,'ERELTOF(NTHTOF),'
     +           //'TIMETOF(NTHTOF)')
            CALL HBNAME(NCWN,'TOF',P0TOF,'P0TOF(NTHTOF)')
         ENDIF
      ENDIF
C
C TRD
C
      IF(HTRD) THEN
*ML:
         WRITE(CHFORM,10000)NHMTRD+1
10000    FORMAT('NTHTRD:I::[0,',I4,']')
*END ML.
         IF(HLONG) THEN
*ML:
            CALL HBNAME(NCWN,'TRD',NTHTRD,CHFORM)
*END ML.
*            CALL HBNAME(NCWN,'TRD',NTHTRD,'NTHTRD:I::[0,100]')
            CALL HBNAME(NCWN,'TRD',IPARTRD,'IPARTRD(NTHTRD):I::[0,120]')
            CALL HBNAME(NCWN,'TRD',ITRBS,'ITRBS(NTHTRD):I::[0,100]')
*ML:
*            CALL HBNAME(NCWN,'TRD',ITRSO,'ITRSO(NTHTRD):I::[0,32]')
            CALL HBNAME(NCWN,'TRD',ITRSI,'ITRSI(NTHTRD):I::[0,32]')
*END ML.
            CALL HBNAME(NCWN,'TRD',XINTRD,'XINTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',YINTRD,'YINTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ZINTRD,'ZINTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',XOUTTRD,'XOUTTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',YOUTTRD,'YOUTTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ZOUTTRD,'ZOUTTRD(NTHTRD)')
c            CALL HBNAME(NCWN,'TRD',ERELTRD,'ERELTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ELOSTRD,'ELOSTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',PATHTRD,'PATHTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',P0TRD,'P0TRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ETRTRD,'ETRTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',NTRTRD,'NTRTRD(NTHTRD):I')
C ML:
#if defined(GPAMELA_GARFIELD)
            CALL HBNAME(NCWN,'TRD',EGARTRD,'EGARTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',NGARTRD,'NGARTRD(NTHTRD):I')
            CALL HBNAME(NCWN,'TRD',ERELTRD,'ERELTRD(NTHTRD)')
#endif
C END ML.
C #
C # This is just for the Transition radiation production
C #
c            CALL HBNAME(NCWN,'TR',ENTRTOT,'ENTRTOT,ENLAY(18):R')
c            CALL HBNAME(NCWN,'TR',NPHTOTR,'NPHTOTR:I,NPHLAY(18):I')
c            CALL HBNAME(NCWN,'TR',ENTRSTRAW,'ENTRSTRAW(32,32):R')
c            CALL HBNAME(NCWN,'TR',NTRSTRAW,'NTRSTRAW(32,32):I')
         ELSE
*ML:
            CALL HBNAME(NCWN,'TRD',NTHTRD,CHFORM)
*END ML.
*            CALL HBNAME(NCWN,'TRD',NTHTRD,'NTHTRD:I::[0,100]')
            CALL HBNAME(NCWN,'TRD',IPARTRD,'IPARTRD(NTHTRD):I::[0,120]')
            CALL HBNAME(NCWN,'TRD',ITRBS,'ITRBS(NTHTRD):I::[0,100]')
*ML:
*            CALL HBNAME(NCWN,'TRD',ITRSO,'ITRSO(NTHTRD):I::[0,32]')
            CALL HBNAME(NCWN,'TRD',ITRSI,'ITRSI(NTHTRD):I::[0,32]')
*END ML.
            CALL HBNAME(NCWN,'TRD',XAVTRD,'XAVTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',YAVTRD,'YAVTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ZAVTRD,'ZAVTRD(NTHTRD)')
C            CALL HBNAME(NCWN,'TRD',ERELTRD,'ERELTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',P0TRD,'P0TRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ETRTRD,'ETRTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',NTRTRD,'NTRTRD(NTHTRD):I')
C ML:
#if defined(GPAMELA_GARFIELD)
            CALL HBNAME(NCWN,'TRD',EGARTRD,'EGARTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',NGARTRD,'NGARTRD(NTHTRD)')
            CALL HBNAME(NCWN,'TRD',ERELTRD,'ERELTRD(NTHTRD)')
#endif
C END ML.
C #
C # This is just for the Transition radiation production
C #
c            CALL HBNAME(NCWN,'TR',ENTRTOT,'ENTRTOT,ENLAY(18):R')
c            CALL HBNAME(NCWN,'TR',NPHTOTR,'NPHTOTR:I,NPHLAY(18):I')
c            CALL HBNAME(NCWN,'TR',ENTRSTRAW,'ENTRSTRAW(32,32):R')
c            CALL HBNAME(NCWN,'TR',NTRSTRAW,'NTRSTRAW(32,32):I')
         ENDIF
      ENDIF
C
C CAT
C
      IF(HCAT) THEN
         IF(HLONG) THEN
            CALL HBNAME(NCWN,'CAT',NTHCAT,'NTHCAT:I::[0,50]')
            CALL HBNAME(NCWN,'CAT',IPARCAT,'IPARCAT(NTHCAT):I::[0,120]')
            CALL HBNAME(NCWN,'CAT',ICAT,'ICAT(NTHCAT):I::[0,4]')
            CALL HBNAME(NCWN,'CAT',XINCAT,'XINCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',YINCAT,'YINCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',ZINCAT,'ZINCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',XOUTCAT,'XOUTCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',YOUTCAT,'YOUTCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',ZOUTCAT,'ZOUTCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',ERELCAT,'ERELCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',TIMECAT,'TIMECAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',PATHCAT,'PATHCAT(NTHCAT)')
            CALL HBNAME(NCWN,'CAT',P0CAT,'P0CAT(NTHCAT)')
         ELSE
            CALL HBNAME(NCWN,'CAT',NTHCAT,'NTHCAT:I::[0,50]')
            CALL HBNAME(NCWN,'CAT',IPARCAT,'IPARCAT(NTHCAT):I::[0,120]')
            CALL HBNAME(NCWN,'CAT',ICAT,'ICAT(NTHCAT):I::[0,4]')
            CALL HBNAME(NCWN,'CAT',P0CAT,'P0CAT(NTHCAT)')
         ENDIF
      ENDIF
C
C CAS
C
      IF(HCAS) THEN
         IF(HLONG) THEN
            CALL HBNAME(NCWN,'CAS',NTHCAS,'NTHCAS:I::[0,50]')
            CALL HBNAME(NCWN,'CAS',IPARCAS,'IPARCAS(NTHCAS):I::[0,120]')
            CALL HBNAME(NCWN,'CAS',ICAS,'ICAS(NTHCAS):I::[0,4]')
            CALL HBNAME(NCWN,'CAS',XINCAS,'XINCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',YINCAS,'YINCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',ZINCAS,'ZINCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',XOUTCAS,'XOUTCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',YOUTCAS,'YOUTCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',ZOUTCAS,'ZOUTCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',ERELCAS,'ERELCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',TIMECAS,'TIMECAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',PATHCAS,'PATHCAS(NTHCAS)')
            CALL HBNAME(NCWN,'CAS',P0CAS,'P0CAS(NTHCAS)')
         ELSE
            CALL HBNAME(NCWN,'CAS',NTHCAS,'NTHCAS:I::[0,50]')
            CALL HBNAME(NCWN,'CAS',IPARCAS,'IPARCAS(NTHCAS):I::[0,120]')
            CALL HBNAME(NCWN,'CAS',ICAS,'ICAS(NTHCAS):I::[0,4]')
            CALL HBNAME(NCWN,'CAS',P0CAS,'P0CAS(NTHCAS)')
         ENDIF
      ENDIF
C
C SPE
C
      IF(HSPE) THEN
         IF(HLONG) THEN
            CALL HBNAME(NCWN,'SPE',NTHSPE,'NTHSPE:I::[0,100]')
            CALL HBNAME(NCWN,'SPE',IPARSPE,'IPARSPE(NTHSPE):I::[0,120]')
            CALL HBNAME(NCWN,'SPE',ITRPB,'ITRPB(NTHSPE):I::[0,6]')
            CALL HBNAME(NCWN,'SPE',ITRSL,'ITRSL(NTHSPE):I::[0,6]')
            CALL HBNAME(NCWN,'SPE',ITSPA,'ITSPA(NTHSPE):I::[0,2]')
            CALL HBNAME(NCWN,'SPE',XINSPE,'XINSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',YINSPE,'YINSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',ZINSPE,'ZINSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',XOUTSPE,'XOUTSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',YOUTSPE,'YOUTSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',ZOUTSPE,'ZOUTSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',ERELSPE,'ERELSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',PATHSPE,'PATHSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',P0SPE,'P0SPE(NTHSPE)')
         ELSE
            CALL HBNAME(NCWN,'SPE',NTHSPE,'NTHSPE:I::[0,100]')
            CALL HBNAME(NCWN,'SPE',IPARSPE,'IPARSPE(NTHSPE):I::[0,120]')
            CALL HBNAME(NCWN,'SPE',ITRPB,'ITRPB(NTHSPE):I::[0,6]')
            CALL HBNAME(NCWN,'SPE',ITRSL,'ITRSL(NTHSPE):I::[0,6]')
            CALL HBNAME(NCWN,'SPE',ITSPA,'ITSPA(NTHSPE):I::[0,2]')
            CALL HBNAME(NCWN,'SPE',XAVSPE,'XAVSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',YAVSPE,'YAVSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',ZAVSPE,'ZAVSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',ERELSPE,'ERELSPE(NTHSPE)')
            CALL HBNAME(NCWN,'SPE',P0SPE,'P0SPE(NTHSPE)')
         ENDIF
      ENDIF
C
C CAL
C
      IF(HCAL) THEN
*ML:
         WRITE(CHFORM,10100)NHMCAL
10100    FORMAT('NTHCAL:I::[0,',I4,']')
*END ML.
         IF(HLONG) THEN
*ML:
            CALL HBNAME(NCWN,'CAL',NTHCAL,CHFORM)
*END ML.
*            CALL HBNAME(NCWN,'CAL',NTHCAL,'NTHCAL:I::[0,1000]')
            CALL HBNAME(NCWN,'CAL',ICAPL,'ICAPL(NTHCAL):I::[0,48]')
            CALL HBNAME(NCWN,'CAL',ICASI,'ICASI(NTHCAL):I::[0,40]')
            CALL HBNAME(NCWN,'CAL',ICAST,'ICAST(NTHCAL):I::[0,32]')
            CALL HBNAME(NCWN,'CAL',XINCAL,'XINCAL(NTHCAL)')
            CALL HBNAME(NCWN,'CAL',YINCAL,'YINCAL(NTHCAL)')
            CALL HBNAME(NCWN,'CAL',ZINCAL,'ZINCAL(NTHCAL)')
            CALL HBNAME(NCWN,'CAL',ERELCAL,'ERELCAL(NTHCAL)')
         ELSE
*ML:
            CALL HBNAME(NCWN,'CAL',NTHCAL,CHFORM)
*END ML.
*            CALL HBNAME(NCWN,'CAL',NTHCAL,'NTHCAL:I::[0,1000]')
            CALL HBNAME(NCWN,'CAL',ICAPL,'ICAPL(NTHCAL):I::[0,48]')
            CALL HBNAME(NCWN,'CAL',ICASI,'ICASI(NTHCAL):I::[0,40]')
            CALL HBNAME(NCWN,'CAL',ICAST,'ICAST(NTHCAL):I::[0,32]')
            CALL HBNAME(NCWN,'CAL',ERELCAL,'ERELCAL(NTHCAL)')
         ENDIF
      ENDIF
C
C User action
C
      CALL GPUHBK
C
      CALL HBSET('BSIZE',NBSIZE,IERR)
      IF(IERR.NE.0) PRINT*,' Error changing N-tple buffer size'
      CALL HPRNT(NCWN)
      RETURN
      END
