Skip to content

Commit

Permalink
fix: get rid of DRY-violating hard-coded energies (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Jan 29, 2025
1 parent a142bc1 commit 6ba9d6c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defaults:

env:
dataset: ci_test
rcdb_connection: mysql://[email protected]/rcdb # RCDB server available to runners
# NOTE: if any of these versions are changed, update the POM files too
java_version: 21
java_distribution: zulu
Expand Down Expand Up @@ -143,6 +144,8 @@ jobs:
run: ls *.tar.zst | xargs -I{} tar xavf {}
- name: tree
run: tree
- name: set RCDB connection # to one that's available to the runner
run: echo RCDB_CONNECTION=${{env.rcdb_connection}} | tee -a $GITHUB_ENV
- name: run monitoring
run: bin/run-monitoring.sh -d ${{env.dataset}} --findhipo --series --focus-${{matrix.type}} validation_files
- name: tree slurm
Expand Down Expand Up @@ -195,6 +198,8 @@ jobs:
run: ls *.tar.zst | xargs -I{} tar xavf {}
- name: tree
run: tree
- name: set RCDB connection # to one that's available to the runner
run: echo RCDB_CONNECTION=${{env.rcdb_connection}} | tee -a $GITHUB_ENV
- name: test monitoring swifjob
run: |
single_rundir=$(find validation_files -mindepth 1 -maxdepth 1 -type d | head -n1)
Expand Down
10 changes: 10 additions & 0 deletions bin/get-beam-energy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e
set -u
source $(dirname $0)/environ.sh

# set class path to include groovy's classpath, for `java` calls
export CLASSPATH="$JYPATH${CLASSPATH:+:${CLASSPATH}}"

java org.jlab.clas.timeline.get_beam_energy $*
64 changes: 27 additions & 37 deletions bin/run-monitoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,49 +346,38 @@ for rdir in ${rdirs[@]}; do
fi
mkdir -p $outputSubDir

# make job scripts for each $key
jobscript=$slurmDir/scripts/$key.$dataset.$runnum.sh
case $key in

detectors)

# hard-coded beam energy values, which may be "more correct" than those in RCDB; if a run
# is not found here, RCDB will be used instead
# FIXME: use a config file; this violates DRY with qa-physics/monitorRead.groovy
beam_energy=`python -c """
# get beam energy from RCDB
echo "Retrieving beam energy from RCDB..."
beam_energy=$($TIMELINESRC/bin/get-beam-energy.sh $runnum | tail -n1)
# override beam energy, for cases where RCDB is incorrect
# - currently only needed for RG-F
beam_energy_override=`python -c """
beamlist = [
(3861, 5673, 10.6),
(5674, 5870, 7.546),
(5871, 6000, 6.535),
(6608, 6783, 10.199),
(11093, 11283, 10.4096),
(11284, 11300, 4.17179),
(11323, 11571, 10.3894),
(11620, 11657, 2.182),
(11658, 12283, 10.389),
(12389, 12444, 2.182),
(12445, 12951, 10.389),
(15013, 15490, 5.98636),
(15533, 15727, 2.07052),
(15728, 15784, 4.02962),
(15787, 15884, 5.98636),
(16010, 16078, 2.21),
(16079, 19130, 10.55),
(12389, 12443, 2.182),
(12444, 12951, 10.389),
]
for r0,r1,eb in beamlist:
if $runnum>=r0 and $runnum<=r1:
print(eb)
"""`
if [ -z "$beam_energy" ]; then
echo "Retrieving beam energy from RCDB..."
beam_energy=$(run-groovy $TIMELINE_GROOVY_OPTS $TIMELINESRC/bin/get-beam-energy.groovy $runnum | tail -n1)
fi
if [ -z "$beam_energy" ]; then
printError "Unknown beam energy for run $runnum"
exit 100
fi
echo "Beam energy = $beam_energy"
"""`
if [ -n "$beam_energy_override" ]; then
if [ -n "$beam_energy" ]; then
printWarning "overriding RCDB beam energy $beam_energy to be $beam_energy_override, for run $runnum"
fi
beam_energy=$beam_energy_override
fi
if [ -z "$beam_energy" ]; then
printError "Unknown beam energy for run $runnum, since RCDB query failed and no overriding beam energy was provided"
exit 100
fi
echo "Beam energy = $beam_energy"

# make job scripts for each $key
jobscript=$slurmDir/scripts/$key.$dataset.$runnum.sh
case $key in

detectors)
cat > $jobscript << EOF
#!/usr/bin/env bash
set -e
Expand Down Expand Up @@ -440,7 +429,8 @@ run-groovy \\
$(realpath $rdir) \\
$outputSubDir \\
$monitorReadType \\
$runnum
$runnum \\
$beam_energy
# check output HIPO files
$TIMELINESRC/bin/hipo-check.sh \$(find $outputSubDir -name "*.hipo")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package org.jlab.clas.timeline

// get beam energy from RCDB
import org.rcdb.*

Expand Down
90 changes: 21 additions & 69 deletions qa-physics/monitorRead.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ def AUXFILE = false // enable auxfile production, an event-by-event table (a la
def printDebug = { msg -> if(VERBOSE) println "[DEBUG]: $msg" }

// ARGUMENTS
def inHipoType = "dst" // options: "dst", "skim"
def runnum = 0
if(args.length<2) {
if(args.length<5) {
System.err.println """
USAGE: run-groovy ${this.class.getSimpleName()}.groovy [HIPO directory or file] [output directory] [type(OPTIONAL)] [runnum(OPTIONAL)]
USAGE: run-groovy ${this.class.getSimpleName()}.groovy [HIPO directory or file] [output directory] [type] [runnum] [beam energy]
REQUIRED parameters:
- [HIPO directory or file] should be a directory of HIPO files
or a single hipo file (depends on [type]: use 'dst' for directory
or 'skim' for file)
- [output directory] output directory for the produced files
OPTIONAL parameters:
- [type] can be 'dst' or 'skim' (default is '$inHipoType')
- [runnum] the run number; if not specified, it will be obtained from RUN::config
- [type] can be 'dst' or 'skim'
- [runnum] the run number
- [beam energy] the beam energy in GeV
"""
System.exit(101)
}
def inHipo = args[0]
def outDir = args[1]
if(args.length>=3) inHipoType = args[2]
if(args.length>=4) runnum = args[3].toInteger()
def inHipo = args[0]
def outDir = args[1]
def inHipoType = args[2]
def runnum = args[3].toInteger()
def beamEnergy = args[4].toDouble()
System.println """
inHipo = $inHipo
outDir = $outDir
inHipoType = $inHipoType"""
inHipoType = $inHipoType
runnum = $runnum
beamEnergy = $beamEnergy"""

// get hipo file names
def inHipoList = []
Expand Down Expand Up @@ -110,60 +110,11 @@ else if(runnum>=12210 && runnum<=12951) RG="RGF" // spring+summer 20
else if(runnum>=15019 && runnum<=15884) RG="RGM"
else if(runnum>=16042 && runnum<=16786) RG="RGC" // summer 22
else if(runnum>=16843 && runnum<=17408) RG="RGC" // fall 22
else if(runnum>=17477 && runnum<=17811) RG="RGC" // spring 23
else if(runnum>=18305 && runnum<=19131) RG="RGD" // fall 23
else System.err.println "WARNING: unknown run group; using default run-group-dependent settings (see monitorRead.groovy)"
println "rungroup = $RG"

// beam energy
// - hard-coded; could instead get from RCDB, but sometimes it is incorrect
def EBEAM = 10.6041 // RGA default
if(RG=="RGA") {
if(runnum>=3031 && runnum<=3120) EBEAM = 6.42313 // spring 18
else if(runnum>=3129 && runnum<=3818) EBEAM = 10.594 // spring 18
else if(runnum>=3819 && runnum<=3861) EBEAM = 6.42313 // spring 18
else if(runnum>=3862 && runnum<=4325) EBEAM = 10.594 // spring 18
else if(runnum>=5032 && runnum<=5666) EBEAM = 10.6041 // fall 18
else if(runnum>=6616 && runnum<=6783) EBEAM = 10.1998 // spring 19
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGB") {
if(runnum>=6120 && runnum<=6399) EBEAM = 10.5986 // spring
else if(runnum>=6409 && runnum<=6604) EBEAM = 10.1998 // spring
else if(runnum>=11093 && runnum<=11283) EBEAM = 10.4096 // fall
else if(runnum>=11284 && runnum<=11300) EBEAM = 4.17179 // fall BAND_FT
else if(runnum>=11323 && runnum<=11571) EBEAM = 10.3894 // winter (RCDB may still be incorrect)
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGC") {
if(runnum>=16042 && runnum<=16078) EBEAM = 2.21
else if(runnum>=16079 && runnum<=16786) EBEAM = 10.55
else if(runnum>=16843 && runnum<=17408) EBEAM = 10.55
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGD") {
if(runnum>=18305 && runnum<=18439) EBEAM = 10.5473
else if(runnum>=18440 && runnum<=19131) EBEAM = 10.5322
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGK") {
if(runnum>=5674 && runnum<=5870) EBEAM = 7.546
else if(runnum>=5875 && runnum<=6000) EBEAM = 6.535
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGF") {
if (runnum>=12210 && runnum<=12388) EBEAM = 10.389 // RCDB may still be incorrect
else if(runnum>=12389 && runnum<=12443) EBEAM = 2.186 // RCDB may still be incorrect
else if(runnum>=12444 && runnum<=12951) EBEAM = 10.389 // RCDB may still be incorrect
else System.err.println "ERROR: unknown beam energy"
}
else if(RG=="RGM") {
if (runnum>=15013 && runnum<=15490) EBEAM = 5.98636
else if(runnum>=15533 && runnum<=15727) EBEAM = 2.07052
else if(runnum>=15728 && runnum<=15784) EBEAM = 4.02962
else if(runnum>=15787 && runnum<=15884) EBEAM = 5.98636
else System.err.println "ERROR: unknown beam energy"
}

/* gated FC charge determination: `FCmode`
* - 0: DAQ-gated FC charge is incorrect
* - recharge option was likely OFF during cook, and should be turned on
Expand Down Expand Up @@ -214,6 +165,11 @@ if(RG=="RGD") {
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////


// Set CSV variables for `FCmode==3`
def csvfilepath = ""
def FORMAT = DEFAULT // Set org.apache.commons.csv.CSVFormat Format
Expand Down Expand Up @@ -272,10 +228,6 @@ def getDataFromCSV = { _runnum, _key ->
return dataFromCSV[_key][_runnum]
}

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

// make outut directories and define output file
"mkdir -p $outDir".execute()
def outHipo = new TDirectory()
Expand Down Expand Up @@ -329,7 +281,7 @@ def nu
def x
def y
def z
def vecBeam = new LorentzVector(0, 0, EBEAM, EBEAM)
def vecBeam = new LorentzVector(0, 0, beamEnergy, beamEnergy)
def vecTarget = new LorentzVector(0, 0, 0, 0.938)
def vecEle = new LorentzVector()
def vecH = new LorentzVector()
Expand Down Expand Up @@ -464,7 +416,7 @@ def findParticles = { pid, binNum ->
// calculate x and y
nu = vecBeam.e() - vecEle.e()
x = Q2 / ( 2 * 0.938272 * nu )
y = nu / EBEAM
y = nu / beamEnergy

// CUT for electron: Q2 cut
//if(Q2<2.5) return
Expand Down

0 comments on commit 6ba9d6c

Please sign in to comment.