Jpp 21.0.0-rc.3
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."\
36 "\nThe first detector file is used to convert the true data to DAQ data and the second to covert DAQ data to calibrated data."\
37 "\nNormally, these correspond to the 'perfect' calibration and the 'online' calibration, respectively."
38
39fi
40
41if (( $# == 5 )); then
42 set_variable DETECTORA $1
43 set_variable DETECTORB $2
44 set_variable OUTPUT_FILE $3
45 set_variable DAQ_FILE $4
46 set_variable PMT_FILE $5
47else
48 fatal "Wrong number of arguments."
49fi
50
51JPrintTree -f $DAQ_FILE -@ "type = JDAQSummaryslice" -k number_of_entries | read N
52
53set_variable RUNBYRUN "file=$DAQ_FILE; sampler=${SAMPLER%% *} $(($N / 2))"
54
55#################################################################################################
56#
57# The sampler values correspond to N_on N_off, respectively (note that sampler calls JSampler),
58# where:
59# N_on = number of time slices to read;
60# N_off = number of time slices to skip.
61#
62# The sampler option works as follows.
63# It will
64# read -on average- N_on consecutive time slices and
65# skip -on average- N_off time slices
66# modulo the number of time slices in the file.
67#
68# The larger N_on, the faster the reading, because this reduces the random accesses
69# of the data taking file to pick up a next time slice.
70# The smaller N_off, the less time slices are skipped.
71# So, N_on = 0 guarantees that all time slices are sampled.
72# Note that if the number of time slices to be produced is small, then too small a value of N_off
73# could create a bias because only the first time slices of the data taking file are then sampled.
74#################################################################################################
75
76set_variable DIR `mktemp -d $WORKDIR/XXXXXX`
77set_variable PIPE $DIR/pipe.dat
78set_variable PARAMETERS $DIR/trigger_parameters.txt
79set_variable TRIGGER $DIR/trigger_processor.root
80set_variable HEADER $DIR/header.root
81
82eval `JPrintDetector -a $DETECTORA -O GEOMETRY`
83
84if (( $MINIMAL_DISTANCE_M > 15.0 )); then
85 MIXED_BACKGROUND_HZ="0.0 0.0"
86fi
87
88mkfifo $PIPE
89
90if [[ ! -p $PIPE ]]; then
91 fatal "Error opening $PIPE."
92fi
93
94timer_start
95
96JRandomTimesliceWriter \
97 -a ${DETECTORA} \
98 -o ${HEADER} \
99 -o ${PIPE} \
100 -n ${NUMBER_OF_SLICES} \
101 -P ${PMT_FILE} \
102 -P "QE=${FACTOR}" \
103 -S ${SEED} \
104 -B "$BACKGROUND_HZ" \
105 -X "$MIXED_BACKGROUND_HZ" \
106 -N "$RECYCLING" \
107 -r "${RUNBYRUN}" \
108 -d ${DEBUG} \
109 --! &
110
111BG=$!
112
113JPrintTriggerParameters \
114 -f ${DAQ_FILE} > $PARAMETERS
115
116JTriggerProcessor \
117 -a ${DETECTORB} \
118 -f ${PIPE} \
119 -@ ${PARAMETERS} \
120 -C ${DAQ_TIMESLICE} \
121 -o ${TRIGGER} \
122 -d ${DEBUG} \
123 --!
124
125CHECK_EXIT_CODE
126
127JConvert \
128 -f ${HEADER} \
129 -f ${TRIGGER} \
130 -o ${OUTPUT_FILE} \
131 -m
132
133CHECK_EXIT_CODE
134
135# check exit code background process
136
137wait $BG
138
139STATUS=$?
140
141if (( $STATUS != 0 )); then
142 error "JRandomTimesliceWriter exit status $STATUS"
143 exit $STATUS
144fi
145
146rm -rf ${DIR}
147
148timer_stop
149timer_print
150
151JPrintTree \
152 -f ${OUTPUT_FILE}
153
154JTriggerMonitor \
155 -f ${OUTPUT_FILE} \
156 -o /dev/null