FLUKA in ROOT Alberto Fass Endre Fut Introduction

FLUKA in ROOT Alberto Fassò Endre Futó

Introduction FLUKA is written in FORTRAN 77 (~900 routines) It is excluded to rewrite it in C++ Present use of FLUKA: - FORTRAN user routines having access to the information in the COMMONs Solution: - Rewrite COMMONs to C++ header files - Rewrite only user routines to C++ (better: call from FORTRAN user routines corresponding C++ procedures)

Main differences between FORTRAN and C++ (1) ● ● Arrays: – FORTRAN: columnwise (leftmost subscripts vary fastest) – C++: rowwise (rightmost subscipts vary fastest) Subroutine arguments: – FORTRAN: to be passed by reference – C++: non-array arguments passed by value, therefore declare them to be passed by ref or const ref – C++: array args are declared arrays, but actually passed by ref, because C++ converts use of array name to a pointer to the array's first element – C++: args not modified by FORTRAN to be declared const

Main differences between FORTRAN and C++ (2) ● Be aware of storing vars in memory ● LOGICAL variables ● exponent should be e (not d) ● If in C++ number starts with 0 -> octal number ● Character variables (no string in FORTRAN) ● No blanks in C++ variable names ● Problem of EQUIVALENCE -> union ● Input/Ouput: avoid doing input or output from both languages with the same file or device – There may be implementation-specific behaviours, but generally the output of the two will be intermingled

Rewrite COMMONs to C++ header files Perl script c 2 h. pl far from being perfect, question of time and effort to write a better one, therefore always check: – Multidimensional arrays (swap dimensions) – Arrays dimensioned X(n: m) -> X[n-m+1] – CHARACTER* vars -> swap dim and char size – LOGICAL vars -> all should be integers – All comment lines – All continuation lines – All unions created from EQUIVALENCEs – All double constants -> exponent should be e – All exp constants -> exp cannot start with 0

Rewrite COMMONs to C++ header files extern “C” { * /EPISOR/ LOGICAL LUSSRC CHARACTER SDUSOU*8 COMMON /EPISOR/ WHASOU(12), TKESUM, LUSSRC COMMON /CHEPSR/ SDUSOU typedef struct { Double_t whasou[12]; Double_t tkesum; Int_t lussrc; } episor. Common; #define EPISOR COMMON_BLOCK(EPISOR, episor) COMMON_BLOCK_DEF(episor. Common, EPISOR); typedef struct { Char_t sdsou[8]; } chepsr. Common; #define CHEPSR COMMON_BLOCK(CHEPSR, chepsr) COMMON_BLOCK_DEF(chepsr. Common, CHEPSR); }

Mixing FORTRAN and C++ header. h #ifndef __CFORTRAN_LOADED #include “. . . /root/include/cfortran. h” #endif #ifndef WIN 32 #define flukam_ #else #define flukam FLUKAM #endif extern “C” { void flukam (const int& iflgeo); // COMMON /AAAAAA/ AA, BB, II, JJ typedef {double aa; double bb; int ii; int jj; } aaaaaa. Common; #define AAAAAA COMMON_BLOCK(AAAAAA, aaaaaa) COMMON_BLOCK_DEF(aaaaaa. Common, AAAAAA); }

Mixing FORTRAN and C++ main. cxx + flukam. f #include “header. h” int main () { flukam (0); return (0); } SUBROUTINE FLUKAM (IFLGEO) REAL *8 AA, BB COMMON /AAAAAA/ AA, BB, II, JJ AA = 1. BB = 2. II = 10 JJ = 20 ICODE = 100 MREG = 17 CALL MGDRAW (ICODE, MREG) RETURN END

Mixing FORTRAN and C++ mgdraw. cxx #include <iostream. h> #include <iomanip. h> #include “header. h” #ifndef WIN 32 #define flukam_ #else #define flukam FLUKAM #endif extern “C” { void mgdraw (int& icode, int& mreg) { cout << “ ICODE=” << icode << “ MREG=” << mreg << endl; cout << “ AA=” << AAAAAA. aa << “ BB=” << AAAAAA. bb << endl; cout << “ II=” << AAAAAA. ii << “ JJ=” << AAAAAA. jj << endl; } }

Mixing FORTRAN and C++ compiling and linking g++ -c main. cxx g++ -c mgdraw. cxx g 77 -c flukam. f g++ -o mixedprog main. o mgdraw. o flukam. o mixedprog ============= Results ============ ICODE=100 MREG=17 AA=1. BB=2. II=10 JJ=20

Mixing FLUKA and ROOT compiling and linking ● In the C++ user routine include – – ● all necessary header files of ROOT, e. g. #include “. . . /root/include/TObject. h” all header files containing variables of COMMONs to be used, e. g. #include “. . . . /flukacppheaders/Ftrackr. h” Modify the lfluka linker file – – replace g 77 by g++ Add library g 2 c $F 77 $FFLAGS. . . . -l${LIBF} ${LIBA} -lg 2 c
- Slides: 11