Project

General

Profile

generate_icarus_events.sh

script to generate event similar to those seen to cause issues - Robert Hatcher, 11/22/2017 04:17 PM

 
1
#! /usr/bin/env bash
2

    
3
# generate events similar to those reported by icarus
4
# first guess at naming of flux files (can't see /pnfs space,
5
# but know the general pattern ...) use ifdh cp to fetch them
6
#
7
# then setup for independent GENIE running ala:
8
## https://cdcvs.fnal.gov/redmine/projects/genie/wiki/Running_gevgen_fnal
9

    
10
# HERE ARE WHAT MOST USERS MIGHT WANT TO CHANGE
11

    
12
export run=4242                 # arbitrary run number, also used as seed
13
# export EXPOSURE="-e 7.5e13"   # POT exposure
14
export EXPOSURE="-n 10000"      # number of events
15
# one can either run for
16
#   a fixed # of protons-on-target (for a sensible flux file)
17
#   a fixed # of generated events
18
# but not both (so either _one_ of -n or -e flag)
19

    
20

    
21
#######################################################################
22

    
23
# setup dune just to get GENIE
24
source /grid/fermiapp/products/dune/setup_dune.sh
25
setup dunetpc v06_56_01 -q debug:e14
26

    
27
# make GENIE quieter about ROOT6 header finding (ugh)
28
export ROOT_INCLUDE_PATH=${ROOT_INCLUDE_PATH}:${GENIE_INC}/GENIE
29

    
30
# again on "dune" because I can access those GPVMs, but not icarus
31
WORKDIR=/dune/app/users/${USER}/fix_nuance_codes
32
if [ ! -d ${WORKDIR} ]; then mkdir -p ${WORKDIR} ; fi
33

    
34
cd ${WORKDIR}
35

    
36
set -x
37

    
38
# grab a copy of icarus.gdml from their build
39
export GEOMETRY="icarus.gdml"         # or whatever (.root is okay too)
40

    
41
if [ ! -f ${GEOMETRY} ]; then
42
   export PRODUCTS=${PRODUCTS}:/cvmfs/icarus.opensciencegrid.org/products/icarus
43
   setup -j icaruscode v06_54_00 -q e14:prof
44
   cp $ICARUSCODE_DIR/gdml/${GEOMETRY} .
45
fi
46

    
47
export TOPVOL="volTPCActive"          # top volume in which to generate
48
export GPREFIX="icarus"               # file naming prefix
49

    
50
# GENIEXSECFILE is defined by UPS  setup genie_xsec ...
51

    
52
# include MEC because that's part of the problem
53
export GENLIST="Default+CCMEC+NCMEC"
54

    
55
# quiet GENIE down ... by default it is _quite_ verbose
56
# this file should either be in a genie_xsec or genie_phyopt added path
57
# as part of $GXMLPATH cascade of locations
58
export MSGLVL=Messenger_production.xml
59

    
60
if [ ! -d flux ]; then
61
  mkdir flux
62
fi
63

    
64
# make sure we have some flux files (at least two)
65
nf=`ls -1 flux/*.root 2>/dev/null | wc -l`
66
if [ ${nf} -lt 2 ]; then
67
  cd flux
68
  # grab some flux files ...
69
  # rename them so gsimple is in the name and GENIE can figure out
70
  # the format in gevgen_fnal by guessing
71
  PNFSPATH=/pnfs/icarus/persistent/bnb_gsimple/fluxes_Oct2017
72
  for i in `seq 1 2` ; do
73
    FILETOGET=${PNFSPATH}/converted_beammc_icarus_000${i}.root
74
    if [ -f ${FILETOGET} ]; then
75
       # yeah, the disk is mounted, #^%$ ifdh just use plain cp
76
       cp ${FILETOGET} ./icarus_bnb_000${i}.gsimple.root
77
    else
78
       # if ifdh cp doesn't work then you need to get a proxy first
79
       #   to me that's black magic, I'll let each individual figure it out
80
       ifdh cp ${FILETOGET} ./icarus_bnb_000${i}.gsimple.root
81
    fi
82
  done
83
  cd  ..
84
fi
85
export FLUXFILE="flux/*icarus*.gsimple.root"
86
export DETLOC="NOTHINGSPECIAL"      # not relevant for gsimple flux files
87
                                    #   but needs to be non-blank
88

    
89
# scanning the geometry for maxpathlength involves sending flux rays
90
# through the geomtry ...
91
NRAYS="+25000"
92

    
93
export GMSGLAYOUT="SIMPLE"
94
# BASIC=default SIMPLE is without timestamps (easier comparisons)
95

    
96
# we're going to create this file once so we don't have to rescan
97
export MAXPLFILE=mysetup.maxpl.xml
98
FORCEPL=0  # set this non-zero to force regeneration
99

    
100
# okay generate a maxpathlength file (once)
101
if [ ! -f ${MAXPLFILE} -o ${FORCEPL} -ne 0 ]; then
102
   echo -e "${OUTRED}generate maxpath${OUTNOCOL}"
103
   ## generate maxpath
104
   rm -f xyzzy.9999.ghep.root gevgen_gen_maxpath.* genie-mcjob-9999.status
105
   if [ -f ${MAXPLFILE} ]; then
106
      mv ${MAXPLFILE} ${MAXPLFILE}-previous
107
   fi
108

    
109
   gevgen_fnal \
110
      -f ${FLUXFILE},${DETLOC} \
111
      -g ${GEOMETRY} \
112
      -t ${TOPVOL} \
113
      -m "+${MAXPLFILE}" \
114
      -S "${NRAYS}" \
115
      -L "cm" -D "g_cm3" \
116
      -n 1 \
117
      --seed ${run} \
118
      -r 9999 \
119
      -o xyzzy \
120
      --cross-sections ${GENIEXSECFILE} \
121
      --event-generator-list ${GENLIST} \
122
      --message-thresholds ${MSGLVL} \
123
      > gevgen_gen_maxpath.out 2> gevgen_gen_maxpath.err
124
fi
125

    
126

    
127
rm -f gevgen_${run}.* icarus.${run}.ghep.root
128
echo -e "${OUTRED}generate events run=${run} ${EXPOSURE}${OUTNOCOL}"
129
## run events
130
#     -m "./${MAXPLFILE}" \
131
gevgen_fnal \
132
   -f ${FLUXFILE},${DETLOC} \
133
   -g ${GEOMETRY} \
134
   -t ${TOPVOL} \
135
   -m "./${MAXPLFILE}" \
136
   -L "cm" -D "g_cm3" \
137
   ${EXPOSURE} \
138
   --seed ${run} \
139
   -r ${run} \
140
   -o ${GPREFIX} \
141
   --cross-sections ${GENIEXSECFILE} \
142
   --event-generator-list ${GENLIST} \
143
   --message-thresholds ${MSGLVL} \
144
   --event-record-print-level 0 \
145
   > gevgen_${run}.out 2> gevgen_${run}.err < /dev/null
146

    
147
# --event-record-print-level 0 = don't print each generate event
148
# log files fill quickly otherwise
149

    
150
# this "status" file gets updated periodically (every 50 events)
151
# with a printout of the current event just for a quick peek
152
# but at the end also tells you something about the processing time
153
# though might be 49 entries before the last event ...
154
cat genie-mcjob-${run}.status
155

    
156
set +x
157

    
158
echo "you can inspect the output file (when done) via:"
159
echo "   gevdump --event-record-print-level 13 -f ${GPREFIX}.${run}.ghep.root"
160

    
161
# end-of-script