Re: Format of the output EVENTBIN card

From: Giuseppe Battistoni <Giuseppe.Battistoni@mi.infn.it>
Date: Wed Apr 02 2008 - 09:45:03 CEST

I can give you an example to readout an unformatted output from eventbin.
I had a case in which I succeded in reading out such output to produce
directly a ROOT output. See the following and the attachments.
        
        Giuseppe

1) Input file
==============

there is an Eventbin card to write onto unformatted output the energy
deposition in 3 regions (from n.5 to n.7)

EVENTBIN 2.0 ENERGY -49.0 7.0 E_DepTot
EVENTBIN 5.0 &

The output is written on unit 49

2) Readout
==========
The code to read out unformatted output is the following.
It is a fortran code calling also C++ routines to produce a ROOT output.
There are 2 files (fortran source, c++ source) and one Makefile
Notice the use of
a) ARRNDX routine (ARRay iNDeX): is a FLUKA routine which
translates the address index of an element of a n_th dimensional
array into the n individual indeces, assuming 1 as starting index
b) the fortran code calls the following C++ routines:
treeinit(),
histini()
treefill()
fileclose()

The code can read more than one file (one after the other)

fortran code: (readbin.f)
-------------
      PROGRAM READBIN

      PARAMETER ( MXUSBN = 100 )
      PARAMETER ( MXDUMM = 4500000 )
      PARAMETER ( PI = 3.141592653589793D0 )
      LOGICAL LUSBIN, LEVTBN, LNTZER, LUSEVT, LUSTKB, LTRKBN, LSNGBN
      CHARACTER*80 FILE1,RUNTIT
      CHARACTER*32 RUNTIM
      CHARACTER*10 TITUSB(MXUSBN)
      COMMON /UUSRBN/ XLOW (MXUSBN), XHIGH (MXUSBN), YLOW (MXUSBN),
     & YHIGH (MXUSBN), ZLOW (MXUSBN), ZHIGH (MXUSBN),
     & DXUSBN(MXUSBN), DYUSBN(MXUSBN), DZUSBN(MXUSBN),
     & TCUSBN(MXUSBN), BKUSBN(MXUSBN), B2USBN(MXUSBN),
     & XAXUSB(MXUSBN), YAXUSB(MXUSBN),
     & NXBIN (MXUSBN), NYBIN (MXUSBN), NZBIN (MXUSBN),
     & ITUSBN(MXUSBN), IDUSBN(MXUSBN), KBUSBN(MXUSBN),
     & IPUSBN(MXUSBN), KRTNBN(MXUSBN), LEVTBN(MXUSBN),
     & LNTZER(MXUSBN), LSNGBN(MXUSBN), LTRKBN(MXUSBN),
     & NUSRBN, LUSBIN, LUSEVT, LUSTKB
      INTEGER*4 NHITS, IHELP(MXDUMM),IREG(MXDUMM),ICELL(MXDUMM)
     $ ,IETA(MXDUMM)
      REAL*4 GMHELP(MXDUMM)
      REAL*8 XFF,YFF,EDEP1,EDEP2,EDEP3
**
      INTEGER*4 NDIM (3), IDIM (3)
**
      CALL treeinit();
*
      iev = 0
      call histini(iev)
      IEVRE = 0
 1000 CONTINUE
      WRITE(*,*)' Type the input file:'
      FILE1=' '
      READ (*,'(A)')FILE1
      IF ( FILE1 .EQ. ' ' ) GO TO 2000
      OPEN (UNIT=1,FILE=FILE1,STATUS='OLD',FORM='UNFORMATTED',
     & ERR= 200)
      GO TO 300
 200 CONTINUE
      WRITE(*,*)' Error opening primary/secondary file!'
      GO TO 2000
 300 CONTINUE

      IREAD=0
      READ(1)RUNTIT,RUNTIM
      WRITE(*,*) RUNTIT
      WRITE(*,*) RUNTIM
      IREAD=IREAD+1
      IB0=0
      NBTOT=0
      DO 1201 IB=IB0+1,1000
         READ (1,ERR=1205,END=1500) NB, TITUSB(IB), ITUSBN(IB),
     & IDUSBN(IB),
     & XLOW(IB),XHIGH(IB),NXBIN(IB),
     & DXUSBN(IB),YLOW(IB),
     & YHIGH(IB),NYBIN(IB),DYUSBN(IB),
     & ZLOW(IB),ZHIGH(IB),NZBIN(IB),
     & DZUSBN(IB),LNTZER(IB),BKUSBN(IB),
     & B2USBN(IB),TCUSBN(IB)
         WRITE(*,*) NB, TITUSB(IB), ITUSBN(IB),
     & IDUSBN(IB),
     & XLOW(IB),XHIGH(IB),NXBIN(IB),
     & DXUSBN(IB),YLOW(IB),
     & YHIGH(IB),NYBIN(IB),DYUSBN(IB),
     & ZLOW(IB),ZHIGH(IB),NZBIN(IB),
     & DZUSBN(IB),LNTZER(IB),BKUSBN(IB),
     & B2USBN(IB),TCUSBN(IB)
         IREAD=IREAD+1
         NBOLD=NB
         NBTOT=IB
 1201 CONTINUE
 1205 CONTINUE
      REWIND 1
      DO I=1,IREAD
        READ(1)
      ENDDO
      DO IEV=1,100000000
C WRITE(*,*) "Now IEV = ",IEV
         ETOT = 0.0
         DO IB=1,NBTOT
            READ(1,END=1500)MB,IEVD,WEI
            NB = IB
            IF ( LNTZER(NB) ) THEN
               READ (1, END=1500) NHITS,(IHELP(J),GMHELP(J),J=1,NHITS)
            ELSE
               READ (1, END=1500)
     & (GMHELP(J),J=1,NXBIN(NB)*NYBIN(NB)*NZBIN(NB))
               NHITS = NXBIN(NB)*NYBIN(NB)*NZBIN(NB)
C WRITE(*,*) 'NHITS = ',NHITS
               DO J = 1, NHITS
                  IHELP(J) = J
               END DO
            END IF

C write(*,*) ( GMHELP(K), K=1,NHITS)
            DO J=1,NHITS
               NDIM (1) = NXBIN (NB)
               NDIM (2) = NYBIN (NB)
               NDIM (3) = NZBIN (NB)
               CALL ARRNDX ( IHELP(J), 3, NDIM, IDIM )
               IF (GMHELP(J).GT.0.) THEN
                  ETOT = ETOT + gmhelp(j)
               ENDIF
            END DO
            EDEP1 = gmhelp(1)
            EDEP2 = gmhelp(2)
            EDEP3 = gmhelp(3)
            CALL treefill(EDEP1,EDEP2,EDEP3)
C call histdel()
         ENDDO
         IEVRE = IEVRE + 1
C WRITE (*,*) 'EV, ETOT: ',IEVRE, ETOT
      END DO
 1500 CONTINUE
      WRITE (*,*)' IEVD:',IEVD
      CLOSE(1)
      GOTO 1000
 2000 CONTINUE
 2200 CONTINUE
      WRITE(*,*)
      WRITE(*,*)' IEVRE :',IEVRE
      CALL fileclose()
      STOP
      END

C++ source: (HistLib.cpp)
-----------

#ifndef __CFORTRAN_LOADED
#include "cfortran.h"
#endif

using namespace std;

#include <stdio.h>
#include "iostream"

#include <TROOT.h>
#include <TTree.h>
#include <TFile.h>
#include <TH1D.h>
#ifndef WIN32
#define treeinit treeinit_
#else
#define treeinit TREEINIT
#endif

static TFile *RootFile = 0;
// static TTree *RootTree = 0;
// static Results *TheResults = 0;
TH1D *RootHist1;
TH1D *RootHist2;
TH1D *RootHist3;

extern "C" {
  void treeinit ()
  {
    printf("Executing TREEINIT\n");
    RootFile = new TFile("mutel.root","recreate");
  }
}

#ifndef WIN32
#define histini histini_
#else
#define histini HISTINI
#endif

extern "C" {
  void histini (Int_t &ih)
  {
    RootHist1 = new TH1D("sc1","Scint1",100,0.,0.050);
    RootHist2 = new TH1D("sc2","Scint2",100,0.,0.050);
    RootHist3 = new TH1D("sc3","Scint3",100,0.,0.050);
  }
}

#ifndef WIN32
#define treefill treefill_
#else
#define treefill TREEFILL
#endif
extern "C" {
  void treefill(Double_t &edep1, Double_t &edep2, Double_t &edep3 )
  {
    RootHist1->Fill(edep1);
    RootHist2->Fill(edep2);
    RootHist3->Fill(edep3);
  }
}

#ifndef WIN32
#define fileclose fileclose_
#else
#define fileclose FILECLOSE
#endif

extern "C" {
  void fileclose()
  {
    RootHist1->Write();
    RootHist2->Write();
    RootHist3->Write();
    RootFile->Close();
  }
}

Makefile:
---------

# Makefile for the ROOT test programs.
# This Makefile shows nicely how to compile and link applications
# using the ROOT libraries on all supported platforms.
#

ARCH = linux
CXX =
ObjSuf = o
SrcSuf = cpp
ExeSuf =
DllSuf = so
OutPutOpt = -o
SrcFor = f

ROOTCFLAGS := $(shell root-config --cflags)
ROOTLIBS := $(shell root-config --libs)
ROOTGLIBS := $(shell root-config --glibs)
FLUKALIB = $(FLUPRO)/libflukahp.a

# Linux with egcs, gcc 2.9x, gcc 3.x (>= RedHat 5.2)
CXX = g++
CXXFLAGS = -O -Wall -fPIC
LD = g++
LDFLAGS = -O
SOFLAGS = -shared
F77 = f77
FFLAGS = -O3 -g -mcpu=pentiumpro -fexpensive-optimizations -funroll-loops -fstrength-reduce -malign-double -W -fno-automatic -fno-silent
CXXFLAGS += $(ROOTCFLAGS)
LIBS = $(ROOTLIBS) $(SYSLIBS)
GLIBS = $(ROOTGLIBS) $(SYSLIBS)

#------------------------------------------------------------------------------

readbin: readbin.o HistLib.o
            @echo "Generating Object $@..."
            f77 readbin.o HistLib.o $(FLUKALIB) $(ROOTLIBS) -o readbin

readbin.o: readbin.f
            @echo "Generating Object $@..."
            f77 -c readbin.f $(FFLAGS)
     
HistLib.o: HistLib.cpp
            @echo "Generating Library $@..."
            g++ -c HistLib.cpp $(ROOTCFLAGS)

clean:
            @rm -f readbin readbin.o HistLib.o core.*

.$(SrcSuf).$(ObjSuf):
        $(CXX) $(CXXFLAGS) -c $<

On Tue, 1 Apr 2008, Marco Calviani wrote:

> Dear Giuseppe and Stefan,
> thanks for your reply. Of course you're right that my position
> concerning the energy per nucleon has no sense, i'm sorry. I'm directly
> injecting heavy ions through a source.f file but the BEAM card the
> maximum energy is set in energy/nucleon. In any case the data given in
> the EVENTBIN card is given in GeV?
>
> Please note that my EVENTBIN card (for the formatted output) is as follows:
>
> EVENTBIN 11.0 ENERGY 70.0 4.0 0.0 0.5GA
> EVENTBIN 0.0 0.0 0.0 1.0 1.0 1.0&
>
> I've tried to use the RDBIN routine (and the unformatted output), but i
> have difficulties in compiling it. Should it be compiled against FLUKA
> libraries, like usbrea.f?
>
> Giuseppe Battistoni wrote:
> > The formatted output of EVENTBIN that you are mentioning is not
> > intended to be used for practical uses (like creating an input for
> > a graphic program).
> > If you want to use EVENTBIN, please choose the much more
> > powerful unformatted output.
> > Then you will be able to read it through a simple program
> > (not necessarily in fortran) for analysis and plotting purposes.
> > In the manual there are the main instructions to readout the unformatted
> > EVENTBIN output using fortran.
> >
> > I also believe that in case of energy deposition (i.e. WHAT(2)=208)
> > the "per nucleon" means nothing
> >
> > Giuseppe
> >
> >
>

Received on Wed Apr 2 09:47:15 2008

This archive was generated by hypermail 2.1.8 : Wed Apr 02 2008 - 09:47:16 CEST