Add next_volume/next_material columns and sampling batch script
Records the volume and material a track is about to enter when a step ends at a geometric boundary, since post-step's physical volume still refers to the volume the step occurred in. Also adds run-sampling-batch.sh to run all run_sampling configs in parallel from isolated directories, avoiding output filename collisions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Executable
+40
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user