Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to set background mixing frequency variables #41

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions scripts/set_bg_mix_freq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -Euo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
IFS=$'\n\t'

# Set url for frequency tables
EGAS_URL=https://raw.githubusercontent.com/eic/simulation_campaign_datasets/${DETECTOR_VERSION}/config_data/egas_freq.csv
HGAS_URL=https://raw.githubusercontent.com/eic/simulation_campaign_datasets/${DETECTOR_VERSION}/config_data/hgas_freq.csv
MINBIAS_URL=https://raw.githubusercontent.com/eic/simulation_campaign_datasets/${DETECTOR_VERSION}/config_data/minbias_freq.csv

# Download tables
EGAS_TABLE=$( curl -L ${EGAS_URL} )
HGAS_TABLE=$( curl -L ${HGAS_URL} )
MINBIAS_TABLE=$( curl -L ${MINBIAS_URL} )

# Initialize associative arrays (maps) for each type of background
declare -A EGAS_MAP
declare -A HGAS_MAP
declare -A MINBIAS_MAP

# Function to process each line into a map
process_lines() {
local data="$1"
local -n map_ref="$2"
local index=0

while IFS=',' read -r key value; do
# Adding the line to the map with a simple index as the key
map_ref[$key]="$value"
done <<< "$data"
}

# Process the downloaded data and populate the maps
process_lines "$EGAS_TABLE" EGAS_MAP
process_lines "$HGAS_TABLE" HGAS_MAP
process_lines "$MINBIAS_TABLE" MINBIAS_MAP

export BG1_FREQ=${EGAS_MAP[${EBEAM}x${PBEAM}_${EVAC}]}
export BG2_FREQ=${HGAS_MAP[${EBEAM}x${PBEAM}_${HVAC}]}
export BG3_FREQ=${MINBIAS_MAP[${EBEAM}x${PBEAM}]}

echo "Electron Beam Gas Frequency:" $BG1_FREQ
echo "Hadron Beam Gas Frequency:" $BG2_FREQ
echo "Minbias Backgrounds Frequency:" $BG3_FREQ