Skip to content

Commit

Permalink
feat: report truth efficiency (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Jan 7, 2025
1 parent 9242015 commit ce86143
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
63 changes: 51 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,10 @@ jobs:
id: files
run: |
echo evgenFile=evgen.${{ matrix.evgen }}.dat >> $GITHUB_OUTPUT
echo simFile=sim.${{ matrix.evgen }}.${{ matrix.config }}.hipo >> $GITHUB_OUTPUT
echo recFile=rec.${{ matrix.evgen }}.${{ matrix.config }}.hipo >> $GITHUB_OUTPUT
echo anaFile=ana.${{ matrix.evgen }}.${{ matrix.config }}.txt >> $GITHUB_OUTPUT
suffix=${{ matrix.evgen }}.${{ matrix.config }}
echo suffix=$suffix >> $GITHUB_OUTPUT
echo simFile=sim.$suffix.hipo >> $GITHUB_OUTPUT
echo recFile=rec.$suffix.hipo >> $GITHUB_OUTPUT
echo coatjavaConfigFile=clas12-config/$(grep -w ${{ matrix.config }} clas12-config/coatjava.ver | awk '{print $1}') >> $GITHUB_OUTPUT
echo gemcConfigFile=clas12-config/$(grep -w ${{ matrix.config }} clas12-config/gemc.ver | awk '{print $1}') >> $GITHUB_OUTPUT
- name: config files exist
Expand Down Expand Up @@ -528,15 +529,26 @@ jobs:
-y ${{ steps.files.outputs.coatjavaConfigFile }} \
-i ${{ steps.files.outputs.simFile }} \
-o ${{ steps.files.outputs.recFile }}
### handle outputs
- name: check if output exists
run: ls ${{ steps.files.outputs.recFile }}
- name: analysis
### run analysis
- name: analyze efficiency
run: |
coatjava/coatjava/bin/trutheff ${{ steps.files.outputs.recFile }} | tee ana.tmp
cat ana.tmp |\
grep -v 'reader::' |\
grep -v '{' \
> ana.efficiency.${{ steps.files.outputs.suffix }}.txt
- name: analyze multiplicity
run: |
bankName="REC::Particle"
[[ "${{ matrix.evgen }}" =~ FT ]] && bankName="RECFT::Particle"
echo "bankName = $bankName"
coatjava/coatjava/bin/run-groovy bin/multiplicity.groovy ${{ steps.files.outputs.recFile }} ${{ steps.files.outputs.anaFile }} $bankName
echo "bank: $bankName" | tee ana.bankName.${{ steps.files.outputs.suffix }}.txt
coatjava/coatjava/bin/run-groovy bin/multiplicity.groovy \
${{ steps.files.outputs.recFile }} \
$bankName |\
tee ana.tmp
tail -n1 ana.tmp > ana.multiplicity.${{ steps.files.outputs.suffix }}.txt
- uses: actions/upload-artifact@v4
with:
name: sim.${{ matrix.evgen }}.${{ matrix.config }}
Expand All @@ -551,12 +563,38 @@ jobs:
with:
name: ana.${{ matrix.evgen }}.${{ matrix.config }}
retention-days: 3
path: ana.${{ matrix.evgen }}.${{ matrix.config }}.txt
path: ana.*

# finalize
#############################################################################
final:
name: Final
report_efficiency:
name: Report efficiency
needs:
- fulltest
- config_files
runs-on: ubuntu-latest
steps:
- name: download ana
uses: actions/download-artifact@v4
with:
pattern: ana.*
merge-multiple: true
- run: tree
- name: report efficiency
run: |
echo "# Efficiency Report" >> $GITHUB_STEP_SUMMARY
for config in $(echo '${{ needs.config_files.outputs.matrix_full }}' | jq -r '.config[]') ; do
echo "## config: \`$config\`" >> $GITHUB_STEP_SUMMARY
for evgen in $(echo '${{ needs.config_files.outputs.matrix_full }}' | jq -r '.evgen[]') ; do
echo "### evgen: \`$evgen\`" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat ana.efficiency.${evgen}.${config}.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
done
done
report_multiplicity:
name: Report multiplicity
needs:
- fulltest
- config_files
Expand All @@ -567,6 +605,7 @@ jobs:
with:
pattern: ana.*
merge-multiple: true
- run: tree
- name: read multiplicity
run: |
echo "# Multiplicity Report" >> $GITHUB_STEP_SUMMARY
Expand All @@ -576,12 +615,12 @@ jobs:
first=true
for config in $(echo '${{ needs.config_files.outputs.matrix_full }}' | jq -r '.config[]') ; do
if $first ; then
grep -E '^bank: ' ana.${evgen}.${config}.txt >> $GITHUB_STEP_SUMMARY
cat ana.bankName.${evgen}.${config}.txt >> $GITHUB_STEP_SUMMARY
echo "multiplicity: |" >> $GITHUB_STEP_SUMMARY
printf " %25s: PID (multiplicity) ... # sorted multiplicity for each PID\n" "config" >> $GITHUB_STEP_SUMMARY
first=false
fi
printf " %25s: %s" $config "$(tail -n1 ana.${evgen}.${config}.txt)" | xargs -0 -I{} echo {} >> $GITHUB_STEP_SUMMARY
printf " %25s: %s" $config "$(cat ana.multiplicity.${evgen}.${config}.txt)" | xargs -0 -I{} echo {} >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
done
Expand Down
9 changes: 7 additions & 2 deletions bin/ci_gemc_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ case $gemcVer in
;;
esac

### run a simulation
### run a simulation, with truth-matching enabled
$gemcExe \
$gemcConfigFile \
-INPUT_GEN_FILE="LUND, $evgenFile" \
-USE_GUI=0 \
-OUTPUT="hipo, $simFile"
-OUTPUT="hipo, $simFile" \
-RUNNO=11 \
-SAVE_ALL_MOTHERS=1 \
-SKIPREJECTEDHITS=1 \
-INTEGRATEDRAW="*" \
-NGENP=50
18 changes: 5 additions & 13 deletions bin/multiplicity.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
// - run with `run-groovy`

import org.jlab.io.hipo.HipoDataSource
import groovy.json.JsonOutput

if(args.length<3) {
if(args.length<2) {
System.err.println """
USAGE: run-groovy ${this.class.getSimpleName()}.groovy [HIPO file from reconstruction] [output file name] [bank]
USAGE: run-groovy ${this.class.getSimpleName()}.groovy [HIPO file from reconstruction] [bank]
"""
System.exit(101)
}

def inFile = args[0]
def outFile = args[1]
def particleBankName = args[2]
def outFileH = new File(outFile)
def outFileW = outFileH.newWriter(false)
def particleBankName = args[1]

def reader = new HipoDataSource()
reader.open(inFile)
Expand All @@ -34,9 +30,5 @@ while(reader.hasEvent()) {
}
mult = mult.sort{ -it.value }

outFileW << "bank: $particleBankName\n" << JsonOutput.prettyPrint(JsonOutput.toJson(mult)) << '\n'
mult.each{ outFileW << sprintf("%14s ", sprintf("%d (%d)", it.key, it.value)) }
outFileW << '\n'
outFileW.close()

println "wrote $outFile"
mult.each{ printf("%14s ", sprintf("%d (%d)", it.key, it.value)) }
printf("\n")

0 comments on commit ce86143

Please sign in to comment.