DUNE / larnd-sim

Simulation framework for a pixelated Liquid Argon TPC
Apache License 2.0
10 stars 29 forks source link

Reproducibility #125

Open krwood opened 1 year ago

krwood commented 1 year ago

It seems that larnd-sim is not creating a reproducible simulation - at least when running our 2x2 spill edep-sim files through. When running the same file through simulate_pixels.py with the random seed fixed to the same value, I get a different number of packets generated for each. This is true even when disabling the light simulation. (tests run on feature_config_seed branch)

Produce the two simulation files:

#!/bin/bash

EDEPH5="/global/cfs/cdirs/dune/www/data/2x2/simulation/mkramer_dev/MiniRun2_1E19_RHC_convert2h5/EDEPSIM_H5/g4numiv6_minervame_me000z-200i_0_0001.000.EDEPSIM.h5"
LARNDH5="g4numiv6_minervame_me000z-200i_0_0001.000.EDEPSIM.LARNDSIM-TEST"
ROOT_LARNDSIM="/global/cfs/cdirs/dune/users/kwood/larnd-sim_reprod/larnd-sim"

if test -f "$LARNDH5"; then
    rm $LARNDH5
fi 

python simulate_pixels.py --input_filename=${EDEPH5} \
  --output_filename=${LARNDH5}"_1.h5" \
  --detector_properties=${ROOT_LARNDSIM}/larndsim/detector_properties/2x2.yaml \
  --simulation_properties=${ROOT_LARNDSIM}/larndsim/simulation_properties/2x2_NuMI_sim.yaml \
  --pixel_layout=${ROOT_LARNDSIM}/larndsim/pixel_layouts/multi_tile_layout-2.3.16.yaml \
  --response_file=${ROOT_LARNDSIM}/larndsim/bin/response_44.npy \
  --light_det_noise_filename=${ROOT_LARNDSIM}/larndsim/bin/light_noise-2x2-example.npy \
  --rand_seed=12345

python simulate_pixels.py --input_filename=${EDEPH5} \
  --output_filename=${LARNDH5}"_2.h5" \
  --detector_properties=${ROOT_LARNDSIM}/larndsim/detector_properties/2x2.yaml \
  --simulation_properties=${ROOT_LARNDSIM}/larndsim/simulation_properties/2x2_NuMI_sim.yaml \
  --pixel_layout=${ROOT_LARNDSIM}/larndsim/pixel_layouts/multi_tile_layout-2.3.16.yaml \
  --response_file=${ROOT_LARNDSIM}/larndsim/bin/response_44.npy \
  --light_det_noise_filename=${ROOT_LARNDSIM}/larndsim/bin/light_noise-2x2-example.npy \
  --rand_seed=12345

Compare simulations:

import matplotlib.pyplot as plt 
import h5py

f1 = h5py.File('g4numiv6_minervame_me000z-200i_0_0001.000.EDEPSIM.LARNDSIM-TEST_1.h5','r')
f2 = h5py.File('g4numiv6_minervame_me000z-200i_0_0001.000.EDEPSIM.LARNDSIM-TEST_2.h5','r')

data_packets_1 = f1['packets'][f1['packets']['packet_type'] == 0]
data_packets_2 = f2['packets'][f2['packets']['packet_type'] == 0]

print("data packets in file 1 =",len(data_packets_1))
print("data packets in file 2 =",len(data_packets_2))

n_max = max(len(data_packets_1),len(data_packets_2))

plt.hist(data_packets_1['dataword'],label='file 1',bins=range(0,256,1),alpha=0.5)
plt.hist(data_packets_2['dataword'],label='file 2',bins=range(0,256,1),alpha=0.5)
plt.legend()
plt.savefig("check_reprod.pdf")

Results:

data packets in file 1 = 4765
data packets in file 2 = 4757

check_reprod.pdf