Skip to content

Commit

Permalink
ci: Physmon for event simulation (#2232)
Browse files Browse the repository at this point in the history
All our physics monitors depend on the simulation which is not directly monitored at the moment. In this PR I add a first monitoring version for Fatras and Geant4.

The monitoring is not optimal yet but should be sufficient if something changes or breaks for simulation.

Possible improvements:
- record deltas for momenta / eta / phi and so on instead of initial and final

Blocked by
- #2241
- #2260
- #2262
- #2263
- #2264
- #2265
- #2266
  • Loading branch information
andiwand committed Jul 6, 2023
1 parent 0eebf3b commit b513232
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 35 deletions.
4 changes: 1 addition & 3 deletions CI/physmon/ckf_truth_smeared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ checks:
IntegralCheck:
threshold: 3




nHoles_vs_eta:
KolmogorovTest:
threshold: 0.25

nOutliers_vs_pT:
KolmogorovTest:
threshold: 0.59
Expand Down
1 change: 0 additions & 1 deletion CI/physmon/gsf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ checks:
threshold: 3
IntegralCheck:
threshold: 3

56 changes: 56 additions & 0 deletions CI/physmon/particles_final_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
histograms:
"vx|vy":
nbins: 100
min: -2000.0
max: 2000.0

vz:
nbins: 100
min: -5000.0
max: 5000.0

vt:
nbins: 100
min: -30.0
max: 30.0

"p|pt":
nbins: 100
min: 0
max: 200.0

"px|py|pz":
nbins: 100
min: -200.0
max: 200.0

eta:
nbins: 100
min: -3.0
max: 3.0

phi:
nbins: 100
min: -4.0
max: 4.0

q:
nbins: 100
min: -2.0
max: 2.0

m:
nbins: 100
min: 0.0
max: 0.15

exclude:
- event_id
- particle_id
- particle_type
- process
- vertex_primary
- vertex_secondary
- particle
- generation
- sub_particle
56 changes: 56 additions & 0 deletions CI/physmon/particles_initial_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
histograms:
"vx|vy|vz":
nbins: 100
min: -0.1
max: 0.1

vz:
nbins: 100
min: -200.0
max: 200.0

vt:
nbins: 100
min: -4.0
max: 4.0

"p|pt":
nbins: 100
min: 0
max: 200.0

"px|py|pz":
nbins: 100
min: -200.0
max: 200.0

eta:
nbins: 100
min: -3.0
max: 3.0

phi:
nbins: 100
min: -4.0
max: 4.0

q:
nbins: 100
min: -2.0
max: 2.0

m:
nbins: 100
min: 0.0
max: 0.15

exclude:
- event_id
- particle_id
- particle_type
- process
- vertex_primary
- vertex_secondary
- particle
- generation
- sub_particle
68 changes: 62 additions & 6 deletions CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e


mode=${1:all}
if ! [[ $mode = @(all|kalman|gsf|fullchains|vertexing) ]]; then
echo "Usage: $0 <all|kalman|gsf|fullchains|vertexing> (outdir)"
if ! [[ $mode = @(all|kalman|gsf|fullchains|vertexing|simulation) ]]; then
echo "Usage: $0 <all|kalman|gsf|fullchains|vertexing|simulation> (outdir)"
exit 1
fi

Expand All @@ -20,10 +20,21 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd

source $SCRIPT_DIR/setup.sh
echo "::group::Generate validation dataset"
CI/physmon/workflows/physmon_truth_tracking_kalman.py $outdir 2>&1 > $outdir/run_truth_tracking_kalman.log
CI/physmon/workflows/physmon_truth_tracking_gsf.py $outdir 2>&1 > $outdir/run_truth_tracking_gsf.log
CI/physmon/workflows/physmon_ckf_tracking.py $outdir 2>&1 > $outdir/run_ckf_tracking.log
CI/physmon/workflows/physmon_vertexing.py $outdir 2>&1 > $outdir/run_vertexing.log
if [[ "$mode" == "all" || "$mode" == "kalman" ]]; then
CI/physmon/workflows/physmon_truth_tracking_kalman.py $outdir 2>&1 > $outdir/run_truth_tracking_kalman.log
fi
if [[ "$mode" == "all" || "$mode" == "gsf" ]]; then
CI/physmon/workflows/physmon_truth_tracking_gsf.py $outdir 2>&1 > $outdir/run_truth_tracking_gsf.log
fi
if [[ "$mode" == "all" || "$mode" == "fullchains" ]]; then
CI/physmon/workflows/physmon_ckf_tracking.py $outdir 2>&1 > $outdir/run_ckf_tracking.log
fi
if [[ "$mode" == "all" || "$mode" == "vertexing" ]]; then
CI/physmon/workflows/physmon_vertexing.py $outdir 2>&1 > $outdir/run_vertexing.log
fi
if [[ "$mode" == "all" || "$mode" == "simulation" ]]; then
CI/physmon/workflows/physmon_simulation.py $outdir 2>&1 > $outdir/run_simulation.log
fi
echo "::endgroup::"

set +e
Expand Down Expand Up @@ -127,8 +138,48 @@ function full_chain() {
--title "Track Summary CKF ${suffix}" \
-o $outdir/tracksummary_ckf_${suffix}.html \
-p $outdir/tracksummary_ckf_${suffix}_plots
}

function simulation() {
suffix=$1

config="CI/physmon/simulation_config.yml"

Examples/Scripts/generic_plotter.py \
$outdir/particles_initial_${suffix}.root \
particles \
$outdir/particles_initial_${suffix}_hist.root \
--silent \
--config CI/physmon/particles_initial_config.yml
ec=$(($ec | $?))

# remove ntuple file because it's large
rm $outdir/particles_initial_${suffix}.root

run \
$outdir/particles_initial_${suffix}_hist.root \
$refdir/particles_initial_${suffix}_hist.root \
--title "Particles inital ${suffix}" \
-o $outdir/particles_initial_${suffix}.html \
-p $outdir/particles_initial_${suffix}_plots

Examples/Scripts/generic_plotter.py \
$outdir/particles_final_${suffix}.root \
particles \
$outdir/particles_final_${suffix}_hist.root \
--silent \
--config CI/physmon/particles_final_config.yml
ec=$(($ec | $?))

# remove ntuple file because it's large
rm $outdir/particles_final_${suffix}.root

run \
$outdir/particles_final_${suffix}_hist.root \
$refdir/particles_final_${suffix}_hist.root \
--title "Particles final ${suffix}" \
-o $outdir/particles_final_${suffix}.html \
-p $outdir/particles_final_${suffix}_plots
}

if [[ "$mode" == "all" || "$mode" == "fullchains" ]]; then
Expand Down Expand Up @@ -180,6 +231,11 @@ if [[ "$mode" == "all" || "$mode" == "vertexing" ]]; then
rm $outdir/performance_vertexing_*mu*
fi

if [[ "$mode" == "all" || "$mode" == "simulation" ]]; then
simulation fatras
simulation geant4
fi

CI/physmon/summary.py $outdir/*.html $outdir/summary.html
ec=$(($ec | $?))

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions CI/physmon/tracksummary_ckf_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,3 @@ exclude:
- majorityParticleId
- multiTraj_nr
- subTraj_nr



3 changes: 0 additions & 3 deletions CI/physmon/truth_tracking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ checks:
IntegralCheck:
threshold: 3




"nStates_*":
KolmogorovTest: null
"nMeasurements_*":
Expand Down
111 changes: 111 additions & 0 deletions CI/physmon/workflows/physmon_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python3

import tempfile
from pathlib import Path
import shutil

import acts
from acts.examples.simulation import (
addFatras,
addGeant4,
ParticleSelectorConfig,
)

from physmon_common import makeSetup

u = acts.UnitConstants

setup = makeSetup()


with tempfile.TemporaryDirectory() as temp:
tp = Path(temp)

rnd = acts.examples.RandomNumbers(seed=42)

s = acts.examples.Sequencer(
events=1000,
numThreads=1,
logLevel=acts.logging.INFO,
fpeMasks=acts.examples.Sequencer.FpeMask.fromFile(
Path(__file__).parent.parent / "fpe_masks.yml"
),
)

for d in setup.decorators:
s.addContextDecorator(d)

s.addReader(
acts.examples.EventGenerator(
level=acts.logging.INFO,
generators=[
acts.examples.EventGenerator.Generator(
multiplicity=acts.examples.FixedMultiplicityGenerator(n=1),
vertex=acts.examples.GaussianVertexGenerator(
mean=acts.Vector4(0, 0, 0, 0),
stddev=acts.Vector4(10 * u.um, 10 * u.um, 50 * u.mm, 1 * u.ns),
),
particles=acts.examples.ParametricParticleGenerator(
p=(1 * u.GeV, 100 * u.GeV),
pTransverse=True,
eta=(-3.0, 3.0),
phi=(0.0 * u.degree, 360.0 * u.degree),
pdg=pdg,
randomizeCharge=True,
),
)
for pdg in [
acts.PdgParticle.eMuon,
acts.PdgParticle.ePionPlus,
acts.PdgParticle.eElectron,
]
],
outputParticles="particles_input",
randomNumbers=rnd,
)
)

addFatras(
s,
setup.trackingGeometry,
setup.field,
rnd,
enableInteractions=True,
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
inputParticles="particles_input",
outputParticlesInitial="particles_initial_fatras",
outputParticlesFinal="particles_final_fatras",
outputSimHits="simhits_fatras",
outputDirRoot=tp / "fatras",
)

addGeant4(
s,
setup.detector,
setup.trackingGeometry,
setup.field,
rnd,
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
killVolume=setup.trackingGeometry.worldVolume,
killAfterTime=25 * u.ns,
killSecondaries=True,
inputParticles="particles_input",
outputParticlesInitial="particles_initial_geant4",
outputParticlesFinal="particles_final_geant4",
outputSimHits="simhits_geant4",
outputDirRoot=tp / "geant4",
)

s.run()
del s

for file, name in [
(tp / "fatras" / "particles_initial.root", "particles_initial_fatras.root"),
(tp / "fatras" / "particles_final.root", "particles_final_fatras.root"),
(tp / "geant4" / "particles_initial.root", "particles_initial_geant4.root"),
(tp / "geant4" / "particles_final.root", "particles_final_geant4.root"),
]:
assert file.exists(), "file not found"
shutil.copy(file, setup.outdir / name)
11 changes: 6 additions & 5 deletions Examples/Algorithms/Geant4/src/Geant4Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ ActsExamples::ProcessCode ActsExamples::Geant4SimulationBase::execute(
}

if (eventStore().hits.empty()) {
ACTS_INFO("Step merging: No steps recorded");
ACTS_DEBUG("Step merging: No steps recorded");
} else {
ACTS_INFO("Step merging: mean hits per hit: "
<< static_cast<double>(eventStore().numberGeantSteps) /
eventStore().hits.size());
ACTS_INFO(
ACTS_DEBUG("Step merging: mean hits per hit: "
<< static_cast<double>(eventStore().numberGeantSteps) /
eventStore().hits.size());
ACTS_DEBUG(
"Step merging: max hits per hit: " << eventStore().maxStepsForHit);
}

Expand Down Expand Up @@ -228,6 +228,7 @@ ActsExamples::Geant4Simulation::Geant4Simulation(const Config& cfg,
ParticleKillAction::Config particleKillCfg;
particleKillCfg.volume = cfg.killVolume;
particleKillCfg.maxTime = cfg.killAfterTime;
particleKillCfg.secondaries = cfg.killSecondaries;

SensitiveSteppingAction::Config stepCfg;
stepCfg.eventStore = m_eventStore;
Expand Down

0 comments on commit b513232

Please sign in to comment.