Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
tmpdir
4 changes: 4 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: eventdisplay-release-tests
channels:
- conda-forge
dependencies:
- python>=3.8
- numpy
- matplotlib
- pandoc
- pre-commit
- towncrier
Expand All @@ -11,3 +14,4 @@ dependencies:
# activate: conda activate eventdisplay-release-tests
# update (conda/mamba): conda env update -f environment.yml --prune
# update (micromamba): micromamba update -f environment.yml
# update (micromamba): micromamba update -n eventdisplay-release-tests -f environment.yml
1 change: 1 addition & 0 deletions release_tests/montecarlo/irf_plotting/irf_plotting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CUT="NTel3-PointSource-Hard-TMVA-BDT"
CUT="NTel2-PointSource-Soft-TMVA-BDT"
CUT="NTel2-PointSource-Moderate-TMVA-BDT"
CUT="NTel2-PointSource-Moderate"
echo "WARNING: CUT is hardwired to $CUT (for now)"
# Comparison plots - version and simtype hardwired
COMPAREVERSION="v492"
COMPARESIMTYPE="CARE_202404"
Expand Down
1 change: 0 additions & 1 deletion release_tests/montecarlo/mc_data_comparison/.gitignore

This file was deleted.

99 changes: 88 additions & 11 deletions release_tests/montecarlo/mc_data_comparison/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,97 @@
# MC / data comparison
# MC / Data Comparison

Scripts and tools to compare MC distributions with results from the Crab Nebula.
**No apptainer usage!**

Fill and plot distributions with
Scripts and tools to compare Monte Carlo (MC) distributions with observational results from the Crab Nebula.

## Quick Start

```console
./compareDatawithMC.sh <runparameter file> <SZE/MZE/LZE/WOBBLE>
./compareDatawithMC.sh <runparameter file> <SZE|MZE|LZE|WOBBLE>
```

Requires as input:
Where `<SZE|MZE|LZE|WOBBLE>` specifies the observation conditions:

- `SZE`: Small zenith angles (0-25°, 0.5° wobble)
- `MZE`: Medium zenith angles (40-50°, 0.5° wobble)
- `LZE`: Large zenith angles (50-70°, 0.5° wobble)
- `WOBBLE`: Large wobble offsets (MC at 1° wobble, summer atmosphere only)

NOTE! The zenith angle bins are different compared to those used in the Crab Nebula analysis.

## Prerequisites

### Input Data Requirements

- MC simulation files for each minor epoch (organized by atmosphere type)
- Crab Nebula mscw results for each minor epoch
- Run lists for Crab observations (generated separately)

## Preparation Steps

Before running the comparison, you must generate the Crab run lists:

```console
# From release_tests/sources/Crab/
./runlist_generator_from_anasum_log.sh <run parameter file> <anasum-results-directory>
```

This generates run lists for minor epochs, zenith angle ranges, and atmosphere types.
The run lists are saved in `EventDisplay_Release_<version>/Crab/runlists/`.

## Running the Comparison

### Step 1: Prepare Run Parameter File

The `<run parameter file>` must contain the following fields (one per line):

- MC files for each minor epoch
- Crab mscw results for each minor epoch
```text
* VERSION <eventdisplay_version> # e.g., V6
* SIMTYPE <simulation_type> # e.g., CARE, CARE_RedHV
* ATMOSPHERE <atmosphere_id> # e.g., 61, 62 (repeat line for multiple values)
* EPOCH <epoch_id> [nsb] # e.g., V6_2019_2020s 0
* CRAB_NSB <nsb_level> # e.g., 0, 1, or NOTSET
```

The leading `*` is part of the parameter-file syntax. To provide multiple atmospheres or epochs, repeat the corresponding line. If `CRAB_NSB` is `NOTSET`, the script reads the per-epoch NSB value from the optional 4th field of each `* EPOCH ...` line.

### Step 2: Execute Comparison

```console
cd release_tests/montecarlo/mc_data_comparison/
./compareDatawithMC.sh <path/to/run\ parameter\ file> SZE
```

This will:

1. Parse the run parameter file
2. Locate MC simulation files based on epoch and atmosphere
3. Find corresponding Crab observational data
4. Submit Condor jobs for each combination
5. Generate comparison plots as PDF files

### Step 3: Monitor Progress

- Condor jobs are submitted with resource requests: 4000MB RAM, 10GB disk
- Temporary symbolic links are created in: `{output_dir}/tmp/{uuid}/`
- **Note**: Temporary directories must be cleaned up manually after completion

## Output Structure

Results are written to:

```text
EventDisplay_Release_<version>/mc_data_comparison/<analysis_type><disp>/<simulation_type>/
├── <epoch>_ATM<atm>_<ELE>_<wobble>_<nsb>/
│ ├── mcdatacomparison.runparameter
│ ├── mcdatacomparison.root
│ ├── mcdatacomparison.log
│ └── *.pdf # Comparison plots
└── tmp/ # Temporary symlinks (manual cleanup required)
```

**important:**
first run linking of epochs from `../../sources/Crab/`: `./runlist_generator.sh V6`
(or for any other epoch)
## Special Cases

Output and plots are written as PDFs into the `../../../../EventDisplay_Release_<version>/mc_data_comparison/` directories
- **CARE_RedHV simulations**: Handled with modified BDT cut (BDT=0 instead of 1)
- **Summer vs Winter Atmosphere**: Automatically selected based on epoch suffix ('s' or 'w')
- **Wobble Mode**: Forces atmosphere 61 and 1.0° wobble offset
114 changes: 77 additions & 37 deletions release_tests/montecarlo/mc_data_comparison/compareDatawithMC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#
# requires:
# - MC files for each minor epoch
# - Crab results for each minor epoch (read from Crab runlists; used pre-processed data)
# - Crab results for each minor epoch (read from Crab run lists; used pre-processed data)

set -e

if [[ $# < 2 ]]; then
echo "
./compareDatawithMC.sh <runparameter file> <SZE/MZE/LZE/WOBBLE>
./compareDatawithMC.sh <run parameter file> <SZE/MZE/LZE/WOBBLE>
--> choose zenith angle / wobble range
SZE: small zenith angles (0.5 deg wobble)
MZE: medium large zenith angles (0.5 deg wobble)
Expand All @@ -23,23 +23,24 @@ exit
fi

###########################
# read runparameter file
# read run parameter file
if [[ ! -e ${1} ]]; then
echo "Error, runparameter file not found: ${1}"
echo "Error, run parameter file not found: ${1}"
exit
fi
RUNPAR="${1}"
# Eventdisplay version
VERSION=$(grep VERSION ${1} | awk '{print $3}')
VERSION=$(awk '$1 == "*" && $2 == "VERSION" {print $3; exit}' "${RUNPAR}")
# Simulation type
SIMTYPE=$(grep SIMTYPE ${1} | awk '{print $3}')
SIMTYPE=$(awk '$1 == "*" && $2 == "SIMTYPE" {print $3; exit}' "${RUNPAR}")
# Atmosphere
ATMOS=($(grep ATMOSPHERE ${1} | grep "*" | awk '{print $3}'))
ATMOS=($(awk '$1 == "*" && $2 == "ATMOSPHERE" {print $3}' "${RUNPAR}"))
# Epochs
EPOCH=($(grep EPOCH ${1} | grep "*" | grep -v MAJOR | awk '{print $3}'))
EPOCH=($(awk '$1 == "*" && $2 == "EPOCH" {print $3}' "${RUNPAR}"))
# Wobble (default observing; WOBBLE mode fixed to 1 deg)
MCWOFF="0.5"
# Crab NSB level
CRABNSB=$(grep CRAB_NSB ${1} | awk '{print $3}')
CRABNSB=$(awk '$1 == "*" && $2 == "CRAB_NSB" {print $3; exit}' "${RUNPAR}")
# Analysis type
ANALYSISTYPE="AP"
DIRRECOTYPE="_DISP"
Expand All @@ -51,17 +52,30 @@ if [[ ! -z $VERITAS_ANALYSIS_TYPE ]]; then
DIRRECOTYPE=""
fi
fi
# Stereo reconstruction method
# (0: dispBDT, 2: XGB)
RECOMETHOD=0
STEREOMETHOD=""
if [[ $RECOMETHOD == 2 ]]; then
STEREOMETHOD="_XGB"
fi
###########################

# elevation range
[[ "$2" ]] && ELE=$2 || ELE="SZE"
case "$ELE" in
SZE|MZE|LZE|WOBBLE)
;;
*)
echo "Error: invalid elevation/wobble selection '${ELE}' (expected SZE, MZE, LZE, or WOBBLE)"
exit 1
;;
esac
# Directory for simulations
SIMDIR=${VERITAS_IRFPRODUCTION_DIR}/${VERSION}/${ANALYSISTYPE}/$SIMTYPE/
if [[ ! -e ${SIMDIR} ]]; then
if [[ ! -e ${SIMDIR} ]]; then
echo "Error: simulation directory not found: $SIMDIR"
exit
fi
echo "Error: simulation directory not found: $SIMDIR"
exit
fi
# Directory for mscw data files
DDIR="$VERITAS_PREPROCESSED_DATA_DIR/${ANALYSISTYPE}/mscw/"
Expand All @@ -78,8 +92,9 @@ if [[ ! -e ${CDIR} ]]; then
fi

# output directory for MC/Data comparison
BDIR=$(readlink -f "../../../../EventDisplay_Release_${VERSION}/mc_data_comparison/${ANALYSISTYPE}${DIRRECOTYPE}/${SIMTYPE}/")
BDIR="../../../../EventDisplay_Release_${VERSION}/mc_data_comparison/${ANALYSISTYPE}${DIRRECOTYPE}${STEREOMETHOD}/${SIMTYPE}/"
mkdir -p ${BDIR}
BDIR=$(readlink -f "../../../../EventDisplay_Release_${VERSION}/mc_data_comparison/${ANALYSISTYPE}${DIRRECOTYPE}${STEREOMETHOD}/${SIMTYPE}/")
echo "Results will be written to $BDIR"

PWDIR=$(pwd)
Expand All @@ -88,14 +103,27 @@ get_mscw_file()
{
data_dir="${1}"
runn="${2}"
if [ ! -e ${data_dir}/$runn.mscw.root ]; then
if [[ ${runn} -lt 100000 ]]; then
EDIR="${data_dir}/${runn:0:1}/"
else
EDIR="${data_dir}/${runn:0:2}/"
fi
local direct_file="${data_dir}/${runn}.mscw.root"
local edir=""
local nested_file=""

if [[ -e "${direct_file}" ]]; then
echo "${direct_file}"
return 0
fi

if [[ ${runn} -lt 100000 ]]; then
edir="${data_dir}/${runn:0:1}"
else
edir="${data_dir}/${runn:0:2}"
fi
nested_file="${edir}/${runn}.mscw.root"
if [[ -e "${nested_file}" ]]; then
echo "${nested_file}"
return 0
fi
echo "$EDIR/$runn.mscw.root"

return 1
}

for I in "${EPOCH[@]}"
Expand All @@ -106,11 +134,15 @@ do
fi
# Crab NSB level (depends on epoch)
if [[ $CRABNSB == "NOTSET" ]]; then
NSB=$(grep ${I} ${1} | grep -v MAJOR | awk '{print $4}')
NSB=$(awk -v epoch="${I}" '$1 == "*" && $2 == "EPOCH" && $3 == epoch {print $4; exit}' "${RUNPAR}")
else
NSB=${CRABNSB}
fi
# Simulation file (elevation depedent)
if [[ -z "${NSB}" ]]; then
echo "Error: no NSB value found for epoch ${I} in ${RUNPAR}"
exit 1
fi
# Simulation file (elevation dependent)
if [[ $ELE = "SZE" ]]
then
simfile="20deg_${MCWOFF}wob_NOISE${NSB}.mscw.root"
Expand All @@ -123,7 +155,7 @@ do
ZEMAX="50."
elif [[ $ELE = "LZE" ]]
then
ZEMIN="50"
ZEMIN="50."
ZEMAX="70."
simfile="55deg_${MCWOFF}wob_NOISE${NSB}.mscw.root"
# wobble set (everything not 0.5 deg)
Expand Down Expand Up @@ -151,6 +183,7 @@ do
if [[ $SIMTYPE == "CARE_RedHV"* ]]; then
REDHV="_redHV"
fi
SIMATM="${atm}"
echo "Processing $I $A ${atm} $REDHV"

# Crab run list
Expand Down Expand Up @@ -178,7 +211,19 @@ do
mkdir -p "$DMSCWDIR"
DFILES=$(cat $RUNLIST)
for D in $DFILES; do
ln -s -f $(get_mscw_file $DDIR $D) "$DMSCWDIR"/"$D".mscw.root
if ! MSCWFILE=$(get_mscw_file "$DDIR" "$D"); then
echo "Error: mscw file not found for run ${D} in ${DDIR}"
exit 1
fi
ln -s -f "${MSCWFILE}" "$DMSCWDIR"/"$D".mscw.root
if [[ ${RECOMETHOD} -eq 2 ]]; then
XGBFILE="${MSCWFILE%.mscw.root}.mscw.xgb_stereo.root"
if [[ ! -e "${XGBFILE}" ]]; then
echo "Error: XGB stereo file not found for run ${D}: ${XGBFILE}"
exit 1
fi
ln -s -f "${XGBFILE}" "$DMSCWDIR"/"$D".mscw.xgb_stereo.root
fi
done
echo "TEMP DIRECTORY (to be deleted by hand): $DMSCWDIR"

Expand All @@ -191,14 +236,11 @@ do
SIMMSCW="MSCW_RECID0${DIRRECOTYPE}"

# write run parameter file
if [[ $SIMTYPE == "CARE_RedHV" ]]; then
echo "* SIMS $SIMDIR/${I}_ATM61_gamma/${SIMMSCW}/${simfile} 4 ${MCWOFF} 0. 0. 0. ${ZEMIN} ${ZEMAX}" > $ODIR/mcdatacomparison.runparameter
if [[ $SIMTYPE == "CARE_RedHV"* ]]; then
SIMATM="61"
echo "* SIMS $SIMDIR/${I}_ATM${SIMATM}_gamma/${SIMMSCW}/${simfile} 4 ${MCWOFF} 0. 0. 0. ${ZEMIN} ${ZEMAX}" > $ODIR/mcdatacomparison.runparameter
else
if [[ $ELE == "WOBBLE" ]] && [[ ${I: -1} == "s" ]]; then
echo "* SIMS $SIMDIR/${I}_ATM62_gamma/${SIMMSCW}/${simfile} 4 ${MCWOFF} 0. 0. 0. ${ZEMIN} ${ZEMAX}" > $ODIR/mcdatacomparison.runparameter
else
echo "* SIMS $SIMDIR/${I}_ATM${atm}_gamma/${SIMMSCW}/${simfile} 4 ${MCWOFF} 0. 0. 0. ${ZEMIN} ${ZEMAX}" > $ODIR/mcdatacomparison.runparameter
fi
echo "* SIMS $SIMDIR/${I}_ATM${SIMATM}_gamma/${SIMMSCW}/${simfile} 4 ${MCWOFF} 0. 0. 0. ${ZEMIN} ${ZEMAX}" > $ODIR/mcdatacomparison.runparameter
fi
echo "* ON ${DMSCWDIR}/[0-9]*.mscw.root 4 -99. -99. 0. 360. ${ZEMIN} ${ZEMAX}" >> $ODIR/mcdatacomparison.runparameter
echo "* OFF ${DMSCWDIR}/[0-9]*.mscw.root 4 -99. -99. 0. 360. ${ZEMIN} ${ZEMAX}" >> $ODIR/mcdatacomparison.runparameter
Expand All @@ -207,17 +249,15 @@ do
FSCRIPT="$DMSCWDIR/compareDatawithMC_qsub_${SIMTYPE}_${I}${A}_${ELE}_${MCWOFF}_${NSB}"
rm -f ${FSCRIPT}.sh
sed -e "s|OUTDIR|$ODIR|" \
-e "s|EEPOCHTM|${I}_ATM${atm}|" \
-e "s|CURRENTDIR|$PWDIR|" compareDatawithMC_qsub.sh > ${FSCRIPT}.sh
-e "s|EEPOCHTM|${I}_ATM${SIMATM}|" \
-e "s|CURRENTDIR|$PWDIR|" \
-e "s|METHODRECO|$RECOMETHOD|" compareDatawithMC_qsub.sh > ${FSCRIPT}.sh

echo "Run script: $FSCRIPT"
chmod u+x $FSCRIPT.sh

$EVNDISPSCRIPTS/helper_scripts/UTILITY.condorSubmission.sh ${FSCRIPT}.sh 4000M 10G
condor_submit ${FSCRIPT}.sh.condor

continue


done
done
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ source $EVNDISPSYS/setObservatory.sh VTS
ODIR=OUTDIR
CDIR=CURRENTDIR
EPOCHATM=EEPOCHTM
RECOMETHOD=METHODRECO

BDT="1"
BDT="0"
if [[ ${ODIR} == *"CARE_RedHV"* ]]; then
BDT="0"
fi
Expand All @@ -20,7 +21,7 @@ $EVNDISPSYS/bin/compareDatawithMC \
$ODIR/mcdatacomparison.runparameter \
-3 \
$ODIR/mcdatacomparison.root \
${BDT} $EPOCHATM \
${BDT} $EPOCHATM $RECOMETHOD \
> $ODIR/mcdatacomparison.log

# prepare all plots
Expand Down
2 changes: 1 addition & 1 deletion release_tests/sources/Crab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for
Combine files using pre-processed anasum files and run list generated in step before:

```bash
./anasum_yearly.sh <runparameter file> <anasum-run-wise directory>
./anasum_from_runlists.sh <run-parameter file> <anasum-run-wise directory>
```

## Plotting
Expand Down
2 changes: 0 additions & 2 deletions release_tests/sources/Crab/plot_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ ODIR="${2}/$CUT"
echo "Output directory: $ODIR"
mkdir -p "$ODIR"

PDIR=$(pwd)

# copy anasum log files to release test directory
for F in $LFIL; do
TF=$(basename $F .combined.root)
Expand Down
Loading
Loading