Skip to content

Commit 70a9679

Browse files
committed
Address review: let a model override DoIt, and fix the example's config
- DoIt is Geant4's own entry point and is no longer final, so a model that does not fit the common shape can replace it rather than work around it. - Its comment now says what it is: it wraps the logic common to every model and delegates the physics to sample(). - The example passed G4.fastSimRegions=ABSO_AIR_ENVELOPE, which overrides the envelope walk with a region containing only AFaM and reproduces exactly the behaviour this branch fixes. It now passes G4.fastSimEnvelope=AFaM. - Drops an unreachable guard in the toy model: ModelTrigger only calls it above its threshold and an exponential of a finite path cannot reach zero. - Comment wording throughout: say what a class is rather than what O2 used to lack, and "encloses" rather than "measures against".
1 parent 8be434d commit 70a9679

6 files changed

Lines changed: 27 additions & 25 deletions

File tree

Detectors/FastSim/include/FastSim/FastSimModel.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
///
1717
/// A fast simulation model replaces the detailed transport through a region of
1818
/// the geometry by a function from the particle that enters it to the particles
19-
/// that leave it. `DoIt()` below is the plumbing and is the same for every
20-
/// model; a model implements `sample()` and nothing else.
19+
/// that leave it. `DoIt()` is Geant4's own entry point
20+
/// (`G4VFastSimulationModel::DoIt`); the implementation here wraps the logic
21+
/// common to every model and delegates the physics to `sample()`. A model that
22+
/// needs a different shape can still override `DoIt()`.
2123

2224
#include "G4VFastSimulationModel.hh"
2325

@@ -58,8 +60,8 @@ constexpr double kSurfaceEpsilonCm = 1e-5;
5860
/// Base class for fast simulation models.
5961
///
6062
/// The model is attached to regions (see G4FastSimulation.h) purely so that
61-
/// Geant4 consults it; what it measures against is the ENVELOPE VOLUME named
62-
/// below, which is normally the mother volume of a whole module. The two are
63+
/// Geant4 consults it; what it encloses is the ENVELOPE VOLUME named below,
64+
/// which is normally the mother volume of a whole module. The two are
6365
/// deliberately separate, because a Geant4 region in O2 can only ever be "every
6466
/// volume of a given material" -- the VMC special cuts make every logical volume
6567
/// a root of its own material's region, and Geant4 stops propagating a region at
@@ -76,10 +78,12 @@ class FastSimModel : public G4VFastSimulationModel
7678
G4bool IsApplicable(const G4ParticleDefinition& particle) override;
7779
G4bool ModelTrigger(const G4FastTrack& fastTrack) override;
7880

79-
/// Measures the distance to the envelope surface, asks `sample()` what comes
80-
/// out, kills the incident particle, stacks the result and books the energy
81-
/// difference as a deposit.
82-
void DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep) final;
81+
/// Wraps the common logic of a fast simulation action and delegates the
82+
/// physics to `sample()`: it measures the distance to the envelope surface,
83+
/// kills the incident particle, stacks what `sample()` returned and books the
84+
/// energy difference as a deposit. Override it for a model that does not fit
85+
/// that shape.
86+
void DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep) override;
8387

8488
protected:
8589
/// Given the particle that entered, return everything that leaves. This is
@@ -91,7 +95,7 @@ class FastSimModel : public G4VFastSimulationModel
9195
/// the track is not inside it at all.
9296
int envelopeDepth(const G4Track* track) const;
9397

94-
G4String mEnvelope; ///< logical volume the model measures against
98+
G4String mEnvelope; ///< logical volume the model encloses
9599
double mMinEnergy = 0.; ///< internal Geant4 units; below this the detailed transport runs
96100
mutable bool mWarned = false;
97101
};

Detectors/FastSim/include/FastSim/G4FastSimulation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class G4FastSimulation : public TG4VUserFastSimulation
5353
double mMinEnergy = 1.;
5454
};
5555

56-
/// The one hook O2 was missing. Returns nullptr when no model is configured,
57-
/// which is exactly the behaviour before this file existed.
56+
/// Supplies Geant4-VMC with the fast simulation models and their regions.
57+
/// Returns nullptr when no model is configured, so nothing is set up.
5858
class G4RunConfiguration : public TG4RunConfiguration
5959
{
6060
public:

Detectors/FastSim/include/FastSim/ToyAbsorberFastSim.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
namespace o2::fastsim
1818
{
1919

20-
/// A toy model: one particle out, continuing along the incident direction with
21-
/// the energy exponentially attenuated over the path through the envelope.
22-
/// It exists to exercise the machinery, not to describe an absorber.
20+
/// A toy fast simulation model for the absorber: one particle out, continuing
21+
/// along the incident direction with the energy exponentially attenuated over
22+
/// the path through the envelope.
2323
class ToyAbsorberFastSim : public FastSimModel
2424
{
2525
public:

Detectors/FastSim/src/FastSimModel.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ void FastSimModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
120120
input.mass = track->GetDefinition()->GetPDGMass() / CLHEP::GeV;
121121
input.time = track->GetGlobalTime() / CLHEP::ns;
122122
// Deliberately NOT GetEnvelopeSolid(): that is the region's root volume, i.e.
123-
// one absorber piece. Measure against the envelope volume instead, using the
124-
// transform the touchable already holds for that level.
123+
// one absorber piece. Use the envelope volume instead, with the transform the
124+
// touchable already holds for that level.
125125
const G4int level = envelopeDepth(track);
126126
const G4VTouchable* touchable = track->GetTouchable();
127127
const G4AffineTransform& toLocal =

Detectors/FastSim/src/ToyAbsorberFastSim.cxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ std::vector<FastSimOutput> ToyAbsorberFastSim::sample(const FastSimInput& input)
2828
// A toy transformation, not a physics model: the incident particle carries on
2929
// in its direction with the energy attenuated over the path through the
3030
// envelope. A trained model returns a shower here instead.
31+
// Always positive: ModelTrigger only calls a model above its threshold, and
32+
// an exponential of a finite path cannot reach zero.
3133
const double kinetic = input.kineticEnergy * std::exp(-input.exitDistance / kAbsorptionLengthCm);
32-
if (kinetic <= 0.) {
33-
return {};
34-
}
3534
const double momentum = std::sqrt(kinetic * (kinetic + 2. * input.mass));
3635

3736
FastSimOutput out;

run/SimExamples/FastSim_Absorber/run.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
# exponentially attenuated energy. What the example demonstrates is the
1010
# machinery, not the physics.
1111
#
12-
# The region is named by TRACKING MEDIUM. `ABSO_AIR_ENVELOPE` is the medium of
13-
# AFaM, the mother volume of the whole absorber, and it exists for exactly this
14-
# purpose: Geant4-VMC builds a region per MATERIAL and adds every volume of that
15-
# material to it, so a volume can only be addressed on its own if its material
16-
# is its own.
12+
# `G4.fastSimEnvelope` names the volume the model stands in for: AFaM, the
13+
# mother of the whole absorber. The regions Geant4 needs in order to consult the
14+
# model are derived from it by walking its subtree and collecting the media,
15+
# because a region can only ever be "every volume of a given material".
1716
#
1817
# The setup is PIPE and ABSO only, which keeps the run short and puts the
1918
# absorber in the path of everything.
@@ -41,7 +40,7 @@ mkdir -p fast && cd fast
4140
o2-sim-serial -n ${EVENTS} ${GEN} -e TGeant4 ${MODULES} -o fast \
4241
--configKeyValues "${COMMON};\
4342
G4.fastSimModels=toyAbsorber;\
44-
G4.fastSimRegions=ABSO_AIR_ENVELOPE;\
43+
G4.fastSimEnvelope=AFaM;\
4544
G4.fastSimMinEnergy=1.0" > logfast 2>&1
4645
cd ..
4746

0 commit comments

Comments
 (0)