How to add a new detector to GBRAHMS

F.Videbaek
Physics Department, BNL
October 12, 1998

Introduction

It is assumed that you have a reasonable knowledge of the conventions used in Geant3.21. The present note only relates to BRAHMS specific setup. Adding a new detector essentially involves the following steps described in more details in the following sections.

In order to follow the description below it will be useful to refer to the extracts of the sample files included at the end for the detector T6 and the code extracts in the text. This includes source codes eg_t6.F bd_T6.F, geo_t6.inc and the general files umedia.F, umate.F , umate.inc and umedia.inc.

File naming conventions

The standard makefile makes the assumption that file names ending in .F will be preprocessed by gcc before being compiled. This allows us to have standard c-like pre-processor statements like

#ifdef, #endif, etc

in the fortran code, thus given a easy way of dealing with machine dependent features if necessary. All new code should be in .F files. Some legacy routines are plain .f files.

Materials and Tracking Media

The materials definitions are in the subroutine umate and the tracking media definitions in the subroutine umedia. The source code are in umate.F and umedia.F, respectively. Materials and media are references by Geant using an unique integer number. To manage this as safely as possible, all materials and media are to be references by a symbolic parameter, that is defined in the include files umate.inc and umedia.inc. Whenever a new material is added it must given a name and assigned a number using a previous defined material.

The files umate.F and umedia.F are found in the directory geant/src/user and the include files in geant/inc.

Example:

Step1.

In umate.inc. Pick a number just above those already used. Geant allocates table space up to te highest number used so do not pick a too high number.

 

Integer new_material
Parameter (mate_next =  "an unused parameter value"

Step2

In umedia.inc add the code

Integer med_next
Parameter (med_next = <an unused parameter value>)

Step3

In umate.F insert the materials definitions like

CALL GSMATE(mate_next,……)

Step4

In umedia.F insert the media definitions

CALL GTMED(med_next, mate_next,….)

Geometry

The GBRAHMS code has introduced the concepts of logical volume trees. In terms of geant a volume is placed in the tree of volumes. The GBRAHMS introduces the concept of logical tree's where an entry is complete detector, or an ensemble of detectors. These entries are named e.g. fms1, fms2, t6. Each entry has a state associated with it describing if it is opened i.e. included or closed in a given run (execution of GBRAHMS), if the detectors it contains are active etc. It will also have a set of parameters associated with it.

Geometry definitions

The geometry definitions are to be done in two subroutines named for consistency as eg_detector and bd_detector. detector is taken as the name in this example for the added detector. A real example could be bd_t6 and eg_t6 for the definitions of the back counter t6. These two subroutines can be assembled within a single source code named eg_detector.F or in two then named eg_detector.F and bd_detector.F. Detector constants and parameters that should be available for viewing and possible change should be defined in an include file named geo_detector.inc. In general the position and overall size of a detector should be accessible this way. The purpose of the two files are

Create the parameter include and common block file in geo_detector.inc The common block should be named /detector/ and the parameters in the common block detector_<name>.

Step2:

Create the bd_detector.F subroutine. It should include the geo_detector.inc file. It has two sections. The first sets the default parameter values
Example

T6_width = 55.
T6_height= 55.

Secondly it declares itself to the logical tree structure of GBRAHMS and tells what parameters are accessible though the command line.
Example

        Call exddes('T6')
        Call set_tree_opt('T6','ON')  ! on by default
        Call exdpar('T6',t6_width, 'WIDTH','VAR')

This implies that the parameter t6_width can be changed on the KUIP command line by a call >set_param t6 width 60.0 and the parameters can be insected by list_param t6 all.

Step2:

Write the code for the geometry definition eg_detector. For this is important where the place the added detector in terms of coordinate system or mother volume.

Step3

Hit structures are defined also in eg_detector. For thin detectors like gas detectors and scintillator slats the default description is likely ok. Take what is in eg_t6.F as an example. If this structure is chosen there is no need to make any modification to gustep. In this case you only have to add code to the standard comis analysis routines anantp.f and gbr2c.f such that the hits can be written to ntuples or stream files for processing outside of GBRAHMS.

In case of massive detector like calorimeters gustep will also have to be modified in order not to create excessive amount of hits.

Initialization

The Initialization and definitions are done in only two places

Sample code from zigeom.F

call bd_wf1
call bd_wf2
call bd_t6

Ugeom: This entry calls the entries that are opened for a given configuration. This may call the geometry routines for different logical units like eg_fms1 which in turns call eg_t6 etc. So depending of where the added detector logically belongs the call of the eg_detector should be placed in either ugeom.f

Sample code extract from ugeom.f. This shows how a global detector(here beam-beam counter) is included into the logic tree.

     stat = get_detstat('BB')
     call eg_beambeam(stat)

or in one of the upper level geometry routines like eg_fms2.f

Sample code extract from eg_fms2.f. This shows how a t6 detector is included into the logic tree and the geometry definition called..

c
c     define detector elements
c
      call eg_t4
      call eg_t5
      call eg_tof2
      call eg_rich

      stat = get_detstat('t6')
      if(btest(stat,onstat)) then
        call eg_t6
      endif

Checkout of setup

Once the code compiles and links it is time to perform a carefully checkout of the newly added detector. Code changes should not be put back into the CVS depository before this is done. GBRAHMS is shared and used by multiple people. Also notify me and Kris Hagel when this commit action is done. It is envisioned that we take advantage at some point in time of automatic features of CVS to make the notification. This is though not implemented.

How the ZDCs was added

Adding the ZDC could not be done using the standard recipes. This is because this is a calorimeter, and one will not want to add all the individual hits to the detector. A first attempt which might work is to do the following.

The ZDCs code has been proto-typed but not yet run and tested.

Appendix 1. Sample Code

This appendix contains complete code examples for bd_t6.F, eg_t6.F.

bd_t6.F
c     $Log: bd_t6.F,v $
c     Revision 1.3  1997/11/05 22:00:04  videbaek
c     FS updates (fairly) complete
c
c     =============================================
      subroutine  bd_t6
c     =============================================
      implicit none
c
c     Init routine routine for detector T6
c     Back counter for RICH detector
 
 
      include 'geo_t6.inc'
c
c     initialize var parameters
c
      t6_width =  55.0
      t6_height = 55.0
      t6_length = 10.0
      t6_ref_distance = 380. 
      t6_ref_angle    = -3.9
c
c     define the tree name  table
c
      call exddes('T6')
      call set_tree_opt('T6','OFF')
      call exdpar('T6', t6_height, 'HEIGHT', 'VAR')
      call exdpar('T6', t6_width,  'WIDTH',  'VAR')
      call exdpar('T6', t6_length, 'LENGTH', 'VAR')
      call exdpar('T6', t6_xc    , 'XC'    , 'CALC')
      call exdpar('T6', t6_zc    , 'ZC'    , 'CALC')
      call exdpar('T6', t6_angle , 'ANGLE' , 'CALC')
      call exdpar('T6', t6_ref_distance, 'REFDIST','VAR')
      call exdpar('T6', t6_ref_angle,    'REF_ANG','VAR')
      call exdpar('T6', t6_xref  , 'XREF'    , 'CALC')
      call exdpar('T6', t6_zref  , 'ZREF'    , 'CALC')
 
      end
eg_t6.F defines the detector geometry and the hit structures.
c     $Id: eg_t6.F,v 1.3 1998/05/06 20:41:26 videbaek Exp $
c     $Log: eg_t6.F,v $
c     Revision 1.3  1998/05/06 20:41:26  videbaek
c     tpc code updates (again)
c
c     Revision 1.2  1997/11/05 22:00:09  videbaek
c     FS updates (fairly) complete
c
c     ===================================================================
      subroutine eg_t6
c     ===================================================================
      implicit none
c
c     Include files:-
c     ================
      include 'umedia.inc'
      include 'ugeom.inc'
      include 'geo_t6.inc'
      include 'geo_rich.inc'
      include 'hits.inc'
#include "geo_fms.inc"
#include "udefs.inc"
c
c
c
c     local variables
c     ===============
c
c
      real distance
      real par(3), zl, xl, cs, si
      real deltax
 
      integer ivolu
      integer nwsa, nwpa, iset, idet
      data nwsa /200/
      data nwpa /200/
c
      integer nbitsh(9)
      data nbitsh /32,32,32,32,32,32,32,32,32/
      real orig(9), fact(9)
      character*4 namesh(9)
c
c
c     detector t6
c
 
      par(1) = t6_width/2.
      par(2) = t6_height/2.
      par(3) = t6_length/2.
 
      call gsvolu('T6  ', 'BOX ', med_ne_he_ch4_sens,
     $            par, 3, ivolu)
      t6_angle = rich_angle + t6_ref_angle
      distance =  t6_ref_distance
      deltax   = t6_width/2.+1
c
      t6_angle = fms2_angle + t6_ref_angle
      cs = cos(t6_ref_angle*degrad)
      si = sin(t6_ref_angle*degrad)
      t6_xref    = fms2_det_xref + distance * si + deltax * cs
      t6_zref    = fms2_det_zref + distance * cs + deltax * si
      call gsrotm(85, t6_ref_angle+90., 0.,
     $     90.,  90., t6_ref_angle, 0.)
      call fms2_to_gfms2(t6_xref, t6_zref, xl, zl)
      call fms2_to_global(t6_xref, t6_zref, t6_xc, t6_zc)
 
      call gspos('T6  ',1,'FMS2',xl, 0., zl, 85, 'ONLY')
 
c
c     define the hit structures for t6
c
      call gsdetv('T6  ', 'T6  ', h_t6, nwpa, nwsa, iset, idet)
c
      namesh(1) = 'X'
      namesh(2) = 'Y'
      namesh(3) = 'Z'
      namesh(4) = 'XO'
      namesh(5) = 'YO'
      namesh(6) = 'ZO'
      namesh(7) = 'TOF'
      namesh(8) = 'DEDX'
      namesh(9) = 'ETOT'
c
      orig(1) = 600.
      orig(2) = t6_height/2.+0.01
      orig(3) = 0.
      orig(4) = 600.
      orig(5) = t6_height/2.+0.01
      orig(6) = 0.
      orig(7) = 0.
      orig(8) = 0.
      orig(9) = 0.
c
      fact(1) = 1000.
      fact(2) = 1000.
      fact(3) = 1000.
      fact(4) = 1000.
      fact(5) = 1000.
      fact(6) = 1000.
      fact(7) = 1.0e11
      fact(8) = 1.0e07
      fact(9) = 1.0e06
c
      call gsdeth('T6  ', 'T6  ', 9, namesh, nbitsh, orig, fact)
      call gsatt('T5  ','COLO',active_volume_color)
 
      return
      end
c

geo_t6.inc
 
c     $Id: geo_t6.inc,v 1.3 1998/05/08 20:57:35 videbaek Exp $
c
c     $Log: geo_t6.inc,v $
c     Revision 1.3  1998/05/08 20:57:35  videbaek
c     Added log and Id cvs headers
c
c
c     geometry file for T6 magnet. 
c
c     basic geometry parameters
c     some are input others are calculated at the time of
c     setting up the geometry.
c
      real T6_height, T6_width, T6_length
      real T6_xc, T6_zc
      real T6_xref, T6_zref
      real T6_ref_distance
      real T6_ref_angle
      real T6_angle
c
      common /T6/       T6_height, T6_width, T6_length
     &                 ,T6_ref_angle, T6_ref_distance
     &                 ,T6_angle
     &                 ,T6_xc, T6_zc
     &                 ,T6_xref, T6_zref
 

umate.inc   contains the symbolic definitions for materials.

c     $Id: umate.inc,v 1.2 1998/05/08 20:57:41 videbaek Exp $
c
c     $Log: umate.inc,v $
c     Revision 1.2  1998/05/08 20:57:41  videbaek
c     Added log and Id cvs headers
c
c
c       File:- user_mate.inc
c       ====================
c
c       description:-
c       =============
c       This file contains the symbolic names for the materials
c       defined for the BRAHMS geant setup
c
c       The actual materials are filled in the userdeef routine
c       This is common for the forward and midrap spectrometer.
c
 
      integer mat_he, mat_carbon, mat_al, mat_Fe, mat_air, mat_vacuum
      integer mat_methan, mat_scin, mat_be, mat_pb, mat_si
      parameter (mat_he = 1)
      parameter (mat_carbon  = 2)
      parameter (mat_al = 3)
      parameter (mat_fe = 4)
      parameter (mat_air = 5)
      parameter (mat_vacuum = 6)
      parameter (mat_be = 7)
      parameter (mat_pb = 8)
      parameter (mat_si = 9)
      parameter (mat_methan = 10)
      parameter (mat_scin = 11)
      integer mat_ne_he_ch4
      parameter (mat_ne_he_ch4=12)
      integer mat_sio2
      parameter (mat_sio2 = 14)
      integer mat_arch4_90_10
      parameter (mat_arch4_90_10 = 15)  
      integer mat_freon12
      parameter (mat_freon12 = 16)
      integer  mat_c4f10
      parameter (mat_c4f10 = 17)
      Integer mat_cu
      parameter (mat_cu = 18)
      Integer mat_liquid_n2
      parameter (mat_liquid_n2 = 19)
      Integer mat_w
      parameter (mat_w = 20)
      Integer mat_uvt
      parameter (mat_uvt = 21)
      Integer mat_pmt
      parameter (mat_pmt = 22)
      Integer mat_g10
      parameter (mat_g10 = 23)
      Integer mat_si02
      parameter (mat_si02 = 24)
      Integer mat_ar_isobutane
      parameter (mat_ar_isobutane = 25)
      integer mat_ar_co2_90_10
      parameter (mat_ar_co2_90_10 = 26) 
      Integer mat_plexiglas
      parameter (mat_plexiglas = 27)