diff --git a/run-sampling-batch.sh b/run-sampling-batch.sh new file mode 100755 index 0000000..12def56 --- /dev/null +++ b/run-sampling-batch.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +CONFIGS=(pb_scint fe_scint w_scint_ecal pb_lar) +RUNS_PER_CONFIG=4 +NEVENTS=10000 +MAX_PARALLEL=16 + +EXE="$(pwd)/build/run_sampling" +OUTDIR="$(pwd)/sampling_batch_output" +WORKROOT="$OUTDIR/.work" + +mkdir -p "$WORKROOT" + +run_one() { + local config="$1" idx="$2" + local workdir="$WORKROOT/${config}_${idx}" + mkdir -p "$workdir" + ( + cd "$workdir" + "$EXE" "$config" "$NEVENTS" + mv "sampling_${config}_${NEVENTS}events_hits.root" "$OUTDIR/sampling_${config}_10k_${idx}.root" + ) + rmdir "$workdir" +} +export -f run_one +export EXE NEVENTS OUTDIR WORKROOT + +jobs=() +for config in "${CONFIGS[@]}"; do + for idx in $(seq 0 $((RUNS_PER_CONFIG - 1))); do + jobs+=("$config $idx") + done +done + +printf '%s\n' "${jobs[@]}" | xargs -P "$MAX_PARALLEL" -L 1 bash -c 'run_one "$1" "$2"' _ + +rmdir "$WORKROOT" diff --git a/src/RunAction.cc b/src/RunAction.cc index 4e00ef5..ac7eb5f 100644 --- a/src/RunAction.cc +++ b/src/RunAction.cc @@ -114,6 +114,8 @@ RunAction::RunAction() analysisManager->CreateNtupleDColumn("post_dx"); // col 27 analysisManager->CreateNtupleDColumn("post_dy"); // col 28 analysisManager->CreateNtupleDColumn("post_dz"); // col 29 + analysisManager->CreateNtupleSColumn("next_volume"); // col 30 (volume entered if step ended at a boundary, else "") + analysisManager->CreateNtupleSColumn("next_material"); // col 31 (material entered if step ended at a boundary, else "") analysisManager->FinishNtuple(); // Spawning ntuple (one row per secondary born, ntuple id=2) diff --git a/src/SteppingAction.cc b/src/SteppingAction.cc index a40b6c4..c395a7f 100644 --- a/src/SteppingAction.cc +++ b/src/SteppingAction.cc @@ -149,6 +149,22 @@ void SteppingAction::UserSteppingAction(const G4Step* step) analysisManager->FillNtupleDColumn(1, 28, postDir.y()); analysisManager->FillNtupleDColumn(1, 29, postDir.z()); + // H: volume/material the track is about to enter, if this step ended at a + // geometric boundary. post->GetPhysicalVolume() still refers to the volume + // the step occurred in, not the one being entered, so use track->GetNextVolume(). + G4String nextVolumeName = ""; + G4String nextMaterialName = ""; + if (post->GetStepStatus() == fGeomBoundary) { + auto nextVolume = track->GetNextVolume(); + if (nextVolume) { + nextVolumeName = nextVolume->GetName(); + auto nextMaterial = nextVolume->GetLogicalVolume()->GetMaterial(); + if (nextMaterial) nextMaterialName = nextMaterial->GetName(); + } + } + analysisManager->FillNtupleSColumn(1, 30, nextVolumeName); + analysisManager->FillNtupleSColumn(1, 31, nextMaterialName); + // Field: B [T] and E [V/m] at pre-step position; zero if no field is registered G4double Bx=0, By=0, Bz=0, Ex=0, Ey=0, Ez=0; const auto* fm = G4TransportationManager::GetTransportationManager()->GetFieldManager();