Jpp 20.0.0-72-g597b30bc9
the software that should make you happy
Loading...
Searching...
No Matches
JRandomEventRunByRun.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author zaly
4#
5version=1.0
6script=${0##*/}
7
8# ------------------------------------------------------------------------------------------
9#
10# Script to jointly run JRandomTimesliceWriter and JTriggerProcessor in run-by-run mode.
11#
12# ------------------------------------------------------------------------------------------
13
14if [ -z $JPP_DIR ]; then
15 echo "Variable JPP_DIR undefined."
16 exit
17fi
18
19source $JPP_DIR/setenv.sh $JPP_DIR
20
21set_variable: DEBUG RANDOMEVENT_DEBUG 1
22set_variable: WORKDIR RANDOMEVENT_WORKDIR ./
23set_variable: BACKGROUND_HZ RANDOMEVENT_BACKGROUND_HZ `getK40Rates`
24set_variable: MIXED_BACKGROUND_HZ RANDOMEVENT_MIXED_BACKGROUND_HZ 8.0 6.0
25set_variable: SEED RANDOMEVENT_SEED 0
26set_variable: NUMBER_OF_SLICES RANDOMEVENT_SLICES 10
27set_variable: RECYCLING RANDOMEVENT_RECYCLING "0 0"
28set_variable: FACTOR RANDOMEVENT_FACTOR 1.0
29set_variable: SAMPLER RANDOMEVENT_SAMPLER "1 1000"
30
31set_variable DAQ_TIMESLICE JDAQTimesliceL0
32
33if do_usage $*; then
34 usage "$script <detector file> <detector file> <output file> <DAQ file> <PMT parameters file>"\
35 "\nAuxiliary script to produce random event data."
36fi
37
38if (( $# == 5 )); then
39 set_variable DETECTORA $1
40 set_variable DETECTORB $2
41 set_variable OUTPUT_FILE $3
42 set_variable DAQ_FILE $4
43 set_variable PMT_FILE $5
44else
45 fatal "Wrong number of arguments."
46fi
47
48JPrintTree -f $DAQ_FILE -@ "type = JDAQSummaryslice" -k number_of_entries | read N
49
50set_variable RUNBYRUN "file=$DAQ_FILE; sampler=${SAMPLER%% *} $(($N / 2))"
51
52#################################################################################################
53#
54# The sampler values correspond to N_on N_off, respectively (note that sampler calls JSampler),
55# where:
56# N_on = number of time slices to read;
57# N_off = number of time slices to skip.
58#
59# The sampler option works as follows.
60# It will
61# read -on average- N_on consecutive time slices and
62# skip -on average- N_off time slices
63# modulo the number of time slices in the file.
64#
65# The larger N_on, the faster the reading, because this reduces the random accesses
66# of the data taking file to pick up a next time slice.
67# The smaller N_off, the less time slices are skipped.
68# So, N_on = 0 guarantees that all time slices are sampled.
69# Note that if the number of time slices to be produced is small, then too small a value of N_off
70# could create a bias because only the first time slices of the data taking file are then sampled.
71#################################################################################################
72
73set_variable DIR `mktemp -d $WORKDIR/XXXXXX`
74set_variable PIPE $DIR/pipe.dat
75set_variable PARAMETERS $DIR/trigger_parameters.txt
76set_variable TRIGGER $DIR/trigger_processor.root
77set_variable HEADER $DIR/header.root
78
79eval `JPrintDetector -a $DETECTORA -O GEOMETRY`
80
81if (( $MINIMAL_DISTANCE_M > 15.0 )); then
82 MIXED_BACKGROUND_HZ="0.0 0.0"
83fi
84
85mkfifo $PIPE
86
87if [[ ! -p $PIPE ]]; then
88 fatal "Error opening $PIPE."
89fi
90
91timer_start
92
93JRandomTimesliceWriter \
94 -a ${DETECTORA} \
95 -o ${HEADER} \
96 -o ${PIPE} \
97 -n ${NUMBER_OF_SLICES} \
98 -P ${PMT_FILE} \
99 -P "QE=${FACTOR}" \
100 -S ${SEED} \
101 -B "$BACKGROUND_HZ" \
102 -X "$MIXED_BACKGROUND_HZ" \
103 -N "$RECYCLING" \
104 -r "${RUNBYRUN}" \
105 -d ${DEBUG} \
106 --! &
107
108BG=$!
109
110JPrintTriggerParameters \
111 -f ${DAQ_FILE} > $PARAMETERS
112
113JTriggerProcessor \
114 -a ${DETECTORB} \
115 -f ${PIPE} \
116 -@ ${PARAMETERS} \
117 -C ${DAQ_TIMESLICE} \
118 -o ${TRIGGER} \
119 -d ${DEBUG} \
120 --!
121
122CHECK_EXIT_CODE
123
124JConvert \
125 -f ${HEADER} \
126 -f ${TRIGGER} \
127 -o ${OUTPUT_FILE} \
128 -m
129
130CHECK_EXIT_CODE
131
132# check exit code background process
133
134wait $BG
135
136STATUS=$?
137
138if (( $STATUS != 0 )); then
139 error "JRandomTimesliceWriter exit status $STATUS"
140 exit $STATUS
141fi
142
143rm -rf ${DIR}
144
145timer_stop
146timer_print
147
148JPrintTree \
149 -f ${OUTPUT_FILE}
150
151JTriggerMonitor \
152 -f ${OUTPUT_FILE} \
153 -o /dev/null