diff --git a/run-convert2h5/convert_edepsim_roottoh5.py b/run-convert2h5/convert_edepsim_roottoh5.py index a15bb2c..f7e0c7c 100755 --- a/run-convert2h5/convert_edepsim_roottoh5.py +++ b/run-convert2h5/convert_edepsim_roottoh5.py @@ -226,8 +226,8 @@ def initHDF5File(output_file): f.create_dataset('trajectories', (0,), dtype=trajectories_dtype, maxshape=(None,)) f.create_dataset('segments', (0,), dtype=segments_dtype, maxshape=(None,)) f.create_dataset('vertices', (0,), dtype=vertices_dtype, maxshape=(None,)) - f.create_dataset('mc_stack', (0,), dtype=genie_stack_dtype, maxshape=(None,)) - f.create_dataset('mc_hdr', (0,), dtype=genie_hdr_dtype, maxshape=(None,)) + # f.create_dataset('mc_stack', (0,), dtype=genie_stack_dtype, maxshape=(None,)) + # f.create_dataset('mc_hdr', (0,), dtype=genie_hdr_dtype, maxshape=(None,)) # Resize HDF5 file and save output arrays def updateHDF5File(output_file, trajectories, segments, vertices, genie_s, genie_h): diff --git a/run-edep-sim/macros/particle-gun.mac b/run-edep-sim/macros/particle-gun.mac new file mode 100644 index 0000000..acae2cb --- /dev/null +++ b/run-edep-sim/macros/particle-gun.mac @@ -0,0 +1,44 @@ +## Particle Gun Macro for edep-sim + +## Physics changes + +## Not everything is LAr +/edep/phys/ionizationModel 0 + +# This ensures that each hit segment in the LAr is only associated with one +# trajectory. It must be run BEFORE /edep/update. +/edep/hitSeparation volTPCActive -1 mm + +/edep/update + +/generator/kinematics/set gps + +# print commands +/gps/verbose 2 + +# generate particles +/gps/particle @ARCUBE_PARTICLE_TYPE@ + +# next, we generate a flat distribution with each muon between $ARCUBE_ENERGY_MINIMUM and $ARCUBE_ENERGY_MAXIMUM (Gradient of 0 means flat and ) +/gps/ene/type Lin +/gps/ene/min @ARCUBE_ENERGY_MINIMUM@ +/gps/ene/max @ARCUBE_ENERGY_MAXIMUM@ +/gps/ene/gradient 0 +/gps/ene/intercept 1 # + +# Specify the volume where we want the muons to be produced in. THIS MAY NEED TO BE CHANGED WHEN GDML CHANGES TOO! + +/gps/position 0.0 -0.5 7.0 m +/gps/pos/type Volume +/gps/pos/shape Para +/gps/pos/halfx 3.5 m +/gps/pos/halfy 2.0 m +/gps/pos/halfz 3.0 m + +/gps/ang/type cos # Not fully convinced this should be cosine law +/gps/ang/maxtheta 90 deg # Remember this is 0-90 deg and the rotating it by phi 0-360 deg gives a hemisphere pointing in beam direction +/gps/ang/rot1 1 0 0 +/gps/ang/rot2 0 -1 0 + +# hopefully that shows what it's using +/gps/source/show diff --git a/run-edep-sim/run_edep_sim.sh b/run-edep-sim/run_edep_sim.sh index 48f2ac3..6decb13 100755 --- a/run-edep-sim/run_edep_sim.sh +++ b/run-edep-sim/run_edep_sim.sh @@ -3,20 +3,32 @@ source ../util/reload_in_container.inc.sh source ../util/init.inc.sh -genieOutPrefix=${ARCUBE_OUTDIR_BASE}/run-genie/${ARCUBE_GENIE_NAME}/GTRAC/$subDir/${ARCUBE_GENIE_NAME}.$globalIdx -genieFile="$genieOutPrefix".GTRAC.root - -rootCode=' -auto t = (TTree*) _file0->Get("gRooTracker"); -std::cout << t->GetEntries() << std::endl;' -nEvents=$(echo "$rootCode" | root -l -b "$genieFile" | tail -1) +if [ $(echo "$ARCUBE_BEAM_TYPE") = "particle_gun" ]; + then nEvents=$(printf "%.0f" $(echo "$ARCUBE_EXPOSURE" | awk '{printf "%f", $1}')) # Convert exposure to integer + + # Make a temporary macro file to replace the energy values and particle type + tempMacroFile=$(mktemp) + rm -f "macros/particle-gun-modified.mac" + sed -e "s/@ARCUBE_PARTICLE_TYPE@/$ARCUBE_PARTICLE_TYPE/g" \ + -e "s/@ARCUBE_ENERGY_MINIMUM@/$ARCUBE_ENERGY_MINIMUM/g" \ + -e "s/@ARCUBE_ENERGY_MAXIMUM@/$ARCUBE_ENERGY_MAXIMUM/g" \ + $ARCUBE_EDEP_MAC > "$tempMacroFile" + export ARCUBE_EDEP_MAC="$tempMacroFile" +else + genieOutPrefix=${ARCUBE_OUTDIR_BASE}/run-genie/${ARCUBE_GENIE_NAME}/GTRAC/$subDir/${ARCUBE_GENIE_NAME}.$globalIdx + genieFile="$genieOutPrefix".GTRAC.root + rootCode=' + auto t = (TTree*) _file0->Get("gRooTracker"); + std::cout << t->GetEntries() << std::endl;' + nEvents=$(echo "$rootCode" | root -l -b "$genieFile" | tail -1) + + edepCode="/generator/kinematics/rooTracker/input $genieFile + /edep/runId $runNo" +fi edepRootFile=$tmpOutDir/${outName}.EDEPSIM.root rm -f "$edepRootFile" -edepCode="/generator/kinematics/rooTracker/input $genieFile -/edep/runId $runNo" - # The geometry file is given relative to the root of 2x2_sim export ARCUBE_GEOM_EDEP=$baseDir/${ARCUBE_GEOM_EDEP:-$ARCUBE_GEOM} @@ -25,3 +37,5 @@ run edep-sim -C -g "$ARCUBE_GEOM_EDEP" -o "$edepRootFile" -e "$nEvents" \ mkdir -p "$outDir/EDEPSIM/$subDir" mv "$edepRootFile" "$outDir/EDEPSIM/$subDir" + +rm -f "$tempMacroFile" diff --git a/run-edep-sim/tests/test_ParticleGun.mu.edep-sim.sh b/run-edep-sim/tests/test_ParticleGun.mu.edep-sim.sh new file mode 100755 index 0000000..674af6d --- /dev/null +++ b/run-edep-sim/tests/test_ParticleGun.mu.edep-sim.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +export ARCUBE_CONTAINER='mjkramer/sim2x2:ndlar011' +export ARCUBE_EDEP_MAC='macros/particle-gun.mac' +export ARCUBE_GEOM='geometry/nd_hall_with_lar_tms_sand_TDR_Production_geometry_v_1.0.3.gdml' +export ARCUBE_LOGDIR_BASE='/pscratch/sd/t/tta20/Particle_Gun3/test1/logs' +export ARCUBE_OUTDIR_BASE='/pscratch/sd/t/tta20/Particle_Gun3/test1/output' +export ARCUBE_RUNTIME='SHIFTER' +export ARCUBE_BEAM_TYPE='particle_gun' +export ARCUBE_EXPOSURE='5E4' +export ARCUBE_PARTICLE_TYPE='mu-' +export ARCUBE_ENERGY_MINIMUM='300 MeV' +export ARCUBE_ENERGY_MAXIMUM='3 GeV' + +for i in $(seq 10); do + ARCUBE_INDEX=$i ./run_edep_sim.sh & +done + +wait \ No newline at end of file