Skip to content

feat: add per-process and per-photon G4 timing instrumentation#280

Open
ggalgoczi wants to merge 2 commits intomainfrom
photontiming_geant4
Open

feat: add per-process and per-photon G4 timing instrumentation#280
ggalgoczi wants to merge 2 commits intomainfrom
photontiming_geant4

Conversation

@ggalgoczi
Copy link
Copy Markdown
Contributor

Add optical photon performance profiling to a new example based GPURaytrace:

  • Per-process step timing (Transportation, OpWLS, OpRayleigh, OpAbsorption) using std::chrono::steady_clock between consecutive SteppingAction calls
  • Per-photon lifetime timing with median, percentiles, and histogram
  • Per-photon step count statistics (avg, median, p10/p50/p90/p99)
  • --skip-gpu flag to measure G4-only photon propagation without GPU

Add benchmark script (examples/photontiming_geant4/photontimingandsteps.sh) that correctly measures GPU vs G4 speedup using three runs:

  1. G4 with photons, no GPU (--skip-gpu)
  2. G4 baseline with setStackPhotons false
  3. Normal GPU run

Measured on apex.gdml (10 MeV electron, ~250k photons, RTX 4090):

  • Transportation: 0.77 us/step, 114M steps, 99.8% of total time
  • OpWLS: 0.85 us/invocation, 42k invocations, 0.07% of total
  • Median photon: 2.1 us (UV, exits world quickly)
  • Average photon: 306 us (skewed by 4% WLS-converted tail at 1-10ms)
  • Speedup: ~1,400x (single-threaded G4 vs GPU)

Shall be merged after wavelength shifting is

Add optical photon performance profiling to GPURaytrace:

- Per-process step timing (Transportation, OpWLS, OpRayleigh, OpAbsorption)
  using std::chrono::steady_clock between consecutive SteppingAction calls
- Per-photon lifetime timing with median, percentiles, and histogram
- Per-photon step count statistics (avg, median, p10/p50/p90/p99)
- --skip-gpu flag to measure G4-only photon propagation without GPU

Add benchmark script (examples/photontiming_geant4/photontimingandsteps.sh)
that correctly measures GPU vs G4 speedup using three runs:
1. G4 with photons, no GPU (--skip-gpu)
2. G4 baseline with setStackPhotons false
3. Normal GPU run

Measured on apex.gdml (10 MeV electron, ~250k photons, RTX 4090):
- Transportation: 0.77 us/step, 114M steps, 99.8% of total time
- OpWLS: 0.85 us/invocation, 42k invocations, 0.07% of total
- Median photon: 2.1 us (UV, exits world quickly)
- Average photon: 306 us (skewed by 4% WLS-converted tail at 1-10ms)
- Speedup: ~1,400x (single-threaded G4 vs GPU)
@ggalgoczi ggalgoczi requested a review from plexoos April 8, 2026 00:55
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-linter Review

Used clang-format v20.1.2

Click here for the full clang-format patch
diff --git a/src/GPURaytrace.cpp b/src/GPURaytrace.cpp
index 64386ca..be1dd60 100644
--- a/src/GPURaytrace.cpp
+++ b/src/GPURaytrace.cpp
@@ -78,3 +78 @@ int main(int argc, char **argv)
-    program.add_argument("--skip-gpu")
-        .help("skip GPU photon propagation (for measuring G4-only photon time)")
-        .flag();
+    program.add_argument("--skip-gpu").help("skip GPU photon propagation (for measuring G4-only photon time)").flag();
diff --git a/src/GPURaytrace.h b/src/GPURaytrace.h
index b61f0d6..ccad899 100644
--- a/src/GPURaytrace.h
+++ b/src/GPURaytrace.h
@@ -483,4 +483,20 @@ struct SteppingAction : G4UserSteppingAction
-                if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
-                else if (pname == "OpWLS")     { fTimeOpWLS += dt; fCountOpWLS++; }
-                else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
-                else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
+                if (pname == "Transportation")
+                {
+                    fTimeTransport += dt;
+                    fCountTransport++;
+                }
+                else if (pname == "OpWLS")
+                {
+                    fTimeOpWLS += dt;
+                    fCountOpWLS++;
+                }
+                else if (pname == "OpRayleigh")
+                {
+                    fTimeOpRayleigh += dt;
+                    fCountOpRayleigh++;
+                }
+                else if (pname == "OpAbsorption")
+                {
+                    fTimeOpAbsorption += dt;
+                    fCountOpAbsorption++;
+                }
@@ -507 +523,2 @@ struct SteppingAction : G4UserSteppingAction
-        if (fSkipGenstep) return; // skip genstep collection for timing-only runs
+        if (fSkipGenstep)
+            return; // skip genstep collection for timing-only runs
@@ -637 +654,3 @@ struct TrackingAction : G4UserTrackingAction
-            while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
+            while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt))
+            {
+            }
@@ -639 +658,3 @@ struct TrackingAction : G4UserTrackingAction
-            while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
+            while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt))
+            {
+            }
@@ -641,6 +662,12 @@ struct TrackingAction : G4UserTrackingAction
-            if (dt < 1000)           fTimeBucket0++;
-            else if (dt < 10000)     fTimeBucket1++;
-            else if (dt < 100000)    fTimeBucket2++;
-            else if (dt < 1000000)   fTimeBucket3++;
-            else if (dt < 10000000)  fTimeBucket4++;
-            else                     fTimeBucket5++;
+            if (dt < 1000)
+                fTimeBucket0++;
+            else if (dt < 10000)
+                fTimeBucket1++;
+            else if (dt < 100000)
+                fTimeBucket2++;
+            else if (dt < 1000000)
+                fTimeBucket3++;
+            else if (dt < 10000000)
+                fTimeBucket4++;
+            else
+                fTimeBucket5++;
@@ -649 +676,5 @@ struct TrackingAction : G4UserTrackingAction
-            { std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
+            {
+                std::lock_guard<std::mutex> lock(fTimesMutex);
+                fAllTimes.push_back(dt);
+                fAllSteps.push_back(nsteps);
+            }
@@ -656 +687,2 @@ struct TrackingAction : G4UserTrackingAction
-        if (n == 0) return;
+        if (n == 0)
+            return;
@@ -691 +723,2 @@ struct TrackingAction : G4UserTrackingAction
-            for (int s : fAllSteps) step_sum += s;
+            for (int s : fAllSteps)
+                step_sum += s;
@@ -699,4 +732,2 @@ struct TrackingAction : G4UserTrackingAction
-                      << "p10=" << fAllSteps[ssz / 10]
-                      << ", p50=" << fAllSteps[ssz / 2]
-                      << ", p90=" << fAllSteps[ssz * 9 / 10]
-                      << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
+                      << "p10=" << fAllSteps[ssz / 10] << ", p50=" << fAllSteps[ssz / 2]
+                      << ", p90=" << fAllSteps[ssz * 9 / 10] << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
@@ -718,6 +749,4 @@ inline void RunAction::PrintTimingReport()
-                std::cout << "Geant4: StepTime " << std::setw(15) << name
-                          << ":  count=" << std::setw(10) << count
-                          << "  avg=" << std::fixed << std::setprecision(2) << std::setw(8)
-                          << total_ns / 1000.0 / count << " us"
-                          << "  total=" << std::setprecision(3) << std::setw(8)
-                          << total_ns / 1e9 << " s" << std::endl;
+                std::cout << "Geant4: StepTime " << std::setw(15) << name << ":  count=" << std::setw(10) << count
+                          << "  avg=" << std::fixed << std::setprecision(2) << std::setw(8) << total_ns / 1000.0 / count
+                          << " us"
+                          << "  total=" << std::setprecision(3) << std::setw(8) << total_ns / 1e9 << " s" << std::endl;

Have any feedback or feature suggestions? Share it here.

Comment on lines +78 to +80
program.add_argument("--skip-gpu")
.help("skip GPU photon propagation (for measuring G4-only photon time)")
.flag();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
program.add_argument("--skip-gpu")
.help("skip GPU photon propagation (for measuring G4-only photon time)")
.flag();
program.add_argument("--skip-gpu").help("skip GPU photon propagation (for measuring G4-only photon time)").flag();

Comment on lines +483 to +486
if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
else if (pname == "OpWLS") { fTimeOpWLS += dt; fCountOpWLS++; }
else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
else if (pname == "OpWLS") { fTimeOpWLS += dt; fCountOpWLS++; }
else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
if (pname == "Transportation")
{
fTimeTransport += dt;
fCountTransport++;
}
else if (pname == "OpWLS")
{
fTimeOpWLS += dt;
fCountOpWLS++;
}
else if (pname == "OpRayleigh")
{
fTimeOpRayleigh += dt;
fCountOpRayleigh++;
}
else if (pname == "OpAbsorption")
{
fTimeOpAbsorption += dt;
fCountOpAbsorption++;
}

}
}

if (fSkipGenstep) return; // skip genstep collection for timing-only runs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (fSkipGenstep) return; // skip genstep collection for timing-only runs
if (fSkipGenstep)
return; // skip genstep collection for timing-only runs

fPhotonCount++;

long long cur = fMinPhotonTime.load();
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt))
{
}

long long cur = fMinPhotonTime.load();
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
cur = fMaxPhotonTime.load();
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt))
{
}

else fTimeBucket5++;

int nsteps = track->GetCurrentStepNumber();
{ std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
{ std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
{
std::lock_guard<std::mutex> lock(fTimesMutex);
fAllTimes.push_back(dt);
fAllSteps.push_back(nsteps);
}

void PrintPhotonTiming()
{
int n = fPhotonCount.load();
if (n == 0) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (n == 0) return;
if (n == 0)
return;

if (ssz > 0)
{
long long step_sum = 0;
for (int s : fAllSteps) step_sum += s;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
for (int s : fAllSteps) step_sum += s;
for (int s : fAllSteps)
step_sum += s;

Comment on lines +699 to +702
<< "p10=" << fAllSteps[ssz / 10]
<< ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10]
<< ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
<< "p10=" << fAllSteps[ssz / 10]
<< ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10]
<< ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
<< "p10=" << fAllSteps[ssz / 10] << ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10] << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;

Comment on lines +718 to +723
std::cout << "Geant4: StepTime " << std::setw(15) << name
<< ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8)
<< total_ns / 1000.0 / count << " us"
<< " total=" << std::setprecision(3) << std::setw(8)
<< total_ns / 1e9 << " s" << std::endl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
std::cout << "Geant4: StepTime " << std::setw(15) << name
<< ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8)
<< total_ns / 1000.0 / count << " us"
<< " total=" << std::setprecision(3) << std::setw(8)
<< total_ns / 1e9 << " s" << std::endl;
std::cout << "Geant4: StepTime " << std::setw(15) << name << ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8) << total_ns / 1000.0 / count
<< " us"
<< " total=" << std::setprecision(3) << std::setw(8) << total_ns / 1e9 << " s" << std::endl;

The genstep collection (Cerenkov/Scintillation CollectGenstep calls and
associated mutex locks) adds overhead to the G4-only timing run. Guard
it with fSkipGenstep flag so Run 1 measures pure G4 photon propagation
without GPU-related bookkeeping.
@ggalgoczi ggalgoczi force-pushed the photontiming_geant4 branch from b799d72 to 9bfd6fa Compare April 8, 2026 01:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v20.1.2) reports: 2 file(s) not formatted
  • src/GPURaytrace.cpp
  • src/GPURaytrace.h

Have any feedback or feature suggestions? Share it here.

@github-actions github-actions bot dismissed their stale review April 8, 2026 01:34

outdated suggestion

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cpp-linter Review

Used clang-format v20.1.2

Click here for the full clang-format patch
diff --git a/src/GPURaytrace.cpp b/src/GPURaytrace.cpp
index 64386ca..be1dd60 100644
--- a/src/GPURaytrace.cpp
+++ b/src/GPURaytrace.cpp
@@ -78,3 +78 @@ int main(int argc, char **argv)
-    program.add_argument("--skip-gpu")
-        .help("skip GPU photon propagation (for measuring G4-only photon time)")
-        .flag();
+    program.add_argument("--skip-gpu").help("skip GPU photon propagation (for measuring G4-only photon time)").flag();
diff --git a/src/GPURaytrace.h b/src/GPURaytrace.h
index b61f0d6..ccad899 100644
--- a/src/GPURaytrace.h
+++ b/src/GPURaytrace.h
@@ -483,4 +483,20 @@ struct SteppingAction : G4UserSteppingAction
-                if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
-                else if (pname == "OpWLS")     { fTimeOpWLS += dt; fCountOpWLS++; }
-                else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
-                else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
+                if (pname == "Transportation")
+                {
+                    fTimeTransport += dt;
+                    fCountTransport++;
+                }
+                else if (pname == "OpWLS")
+                {
+                    fTimeOpWLS += dt;
+                    fCountOpWLS++;
+                }
+                else if (pname == "OpRayleigh")
+                {
+                    fTimeOpRayleigh += dt;
+                    fCountOpRayleigh++;
+                }
+                else if (pname == "OpAbsorption")
+                {
+                    fTimeOpAbsorption += dt;
+                    fCountOpAbsorption++;
+                }
@@ -507 +523,2 @@ struct SteppingAction : G4UserSteppingAction
-        if (fSkipGenstep) return; // skip genstep collection for timing-only runs
+        if (fSkipGenstep)
+            return; // skip genstep collection for timing-only runs
@@ -637 +654,3 @@ struct TrackingAction : G4UserTrackingAction
-            while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
+            while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt))
+            {
+            }
@@ -639 +658,3 @@ struct TrackingAction : G4UserTrackingAction
-            while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
+            while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt))
+            {
+            }
@@ -641,6 +662,12 @@ struct TrackingAction : G4UserTrackingAction
-            if (dt < 1000)           fTimeBucket0++;
-            else if (dt < 10000)     fTimeBucket1++;
-            else if (dt < 100000)    fTimeBucket2++;
-            else if (dt < 1000000)   fTimeBucket3++;
-            else if (dt < 10000000)  fTimeBucket4++;
-            else                     fTimeBucket5++;
+            if (dt < 1000)
+                fTimeBucket0++;
+            else if (dt < 10000)
+                fTimeBucket1++;
+            else if (dt < 100000)
+                fTimeBucket2++;
+            else if (dt < 1000000)
+                fTimeBucket3++;
+            else if (dt < 10000000)
+                fTimeBucket4++;
+            else
+                fTimeBucket5++;
@@ -649 +676,5 @@ struct TrackingAction : G4UserTrackingAction
-            { std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
+            {
+                std::lock_guard<std::mutex> lock(fTimesMutex);
+                fAllTimes.push_back(dt);
+                fAllSteps.push_back(nsteps);
+            }
@@ -656 +687,2 @@ struct TrackingAction : G4UserTrackingAction
-        if (n == 0) return;
+        if (n == 0)
+            return;
@@ -691 +723,2 @@ struct TrackingAction : G4UserTrackingAction
-            for (int s : fAllSteps) step_sum += s;
+            for (int s : fAllSteps)
+                step_sum += s;
@@ -699,4 +732,2 @@ struct TrackingAction : G4UserTrackingAction
-                      << "p10=" << fAllSteps[ssz / 10]
-                      << ", p50=" << fAllSteps[ssz / 2]
-                      << ", p90=" << fAllSteps[ssz * 9 / 10]
-                      << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
+                      << "p10=" << fAllSteps[ssz / 10] << ", p50=" << fAllSteps[ssz / 2]
+                      << ", p90=" << fAllSteps[ssz * 9 / 10] << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
@@ -718,6 +749,4 @@ inline void RunAction::PrintTimingReport()
-                std::cout << "Geant4: StepTime " << std::setw(15) << name
-                          << ":  count=" << std::setw(10) << count
-                          << "  avg=" << std::fixed << std::setprecision(2) << std::setw(8)
-                          << total_ns / 1000.0 / count << " us"
-                          << "  total=" << std::setprecision(3) << std::setw(8)
-                          << total_ns / 1e9 << " s" << std::endl;
+                std::cout << "Geant4: StepTime " << std::setw(15) << name << ":  count=" << std::setw(10) << count
+                          << "  avg=" << std::fixed << std::setprecision(2) << std::setw(8) << total_ns / 1000.0 / count
+                          << " us"
+                          << "  total=" << std::setprecision(3) << std::setw(8) << total_ns / 1e9 << " s" << std::endl;

Have any feedback or feature suggestions? Share it here.

Comment on lines +78 to +80
program.add_argument("--skip-gpu")
.help("skip GPU photon propagation (for measuring G4-only photon time)")
.flag();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
program.add_argument("--skip-gpu")
.help("skip GPU photon propagation (for measuring G4-only photon time)")
.flag();
program.add_argument("--skip-gpu").help("skip GPU photon propagation (for measuring G4-only photon time)").flag();

Comment on lines +483 to +486
if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
else if (pname == "OpWLS") { fTimeOpWLS += dt; fCountOpWLS++; }
else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (pname == "Transportation") { fTimeTransport += dt; fCountTransport++; }
else if (pname == "OpWLS") { fTimeOpWLS += dt; fCountOpWLS++; }
else if (pname == "OpRayleigh"){ fTimeOpRayleigh += dt; fCountOpRayleigh++; }
else if (pname == "OpAbsorption"){ fTimeOpAbsorption += dt; fCountOpAbsorption++; }
if (pname == "Transportation")
{
fTimeTransport += dt;
fCountTransport++;
}
else if (pname == "OpWLS")
{
fTimeOpWLS += dt;
fCountOpWLS++;
}
else if (pname == "OpRayleigh")
{
fTimeOpRayleigh += dt;
fCountOpRayleigh++;
}
else if (pname == "OpAbsorption")
{
fTimeOpAbsorption += dt;
fCountOpAbsorption++;
}

}
}

if (fSkipGenstep) return; // skip genstep collection for timing-only runs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (fSkipGenstep) return; // skip genstep collection for timing-only runs
if (fSkipGenstep)
return; // skip genstep collection for timing-only runs

fPhotonCount++;

long long cur = fMinPhotonTime.load();
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt))
{
}

long long cur = fMinPhotonTime.load();
while (dt < cur && !fMinPhotonTime.compare_exchange_weak(cur, dt)) {}
cur = fMaxPhotonTime.load();
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt)) {}
while (dt > cur && !fMaxPhotonTime.compare_exchange_weak(cur, dt))
{
}

else fTimeBucket5++;

int nsteps = track->GetCurrentStepNumber();
{ std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
{ std::lock_guard<std::mutex> lock(fTimesMutex); fAllTimes.push_back(dt); fAllSteps.push_back(nsteps); }
{
std::lock_guard<std::mutex> lock(fTimesMutex);
fAllTimes.push_back(dt);
fAllSteps.push_back(nsteps);
}

void PrintPhotonTiming()
{
int n = fPhotonCount.load();
if (n == 0) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
if (n == 0) return;
if (n == 0)
return;

if (ssz > 0)
{
long long step_sum = 0;
for (int s : fAllSteps) step_sum += s;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
for (int s : fAllSteps) step_sum += s;
for (int s : fAllSteps)
step_sum += s;

Comment on lines +699 to +702
<< "p10=" << fAllSteps[ssz / 10]
<< ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10]
<< ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
<< "p10=" << fAllSteps[ssz / 10]
<< ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10]
<< ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;
<< "p10=" << fAllSteps[ssz / 10] << ", p50=" << fAllSteps[ssz / 2]
<< ", p90=" << fAllSteps[ssz * 9 / 10] << ", p99=" << fAllSteps[ssz * 99 / 100] << std::endl;

Comment on lines +718 to +723
std::cout << "Geant4: StepTime " << std::setw(15) << name
<< ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8)
<< total_ns / 1000.0 / count << " us"
<< " total=" << std::setprecision(3) << std::setw(8)
<< total_ns / 1e9 << " s" << std::endl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format suggestion

Suggested change
std::cout << "Geant4: StepTime " << std::setw(15) << name
<< ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8)
<< total_ns / 1000.0 / count << " us"
<< " total=" << std::setprecision(3) << std::setw(8)
<< total_ns / 1e9 << " s" << std::endl;
std::cout << "Geant4: StepTime " << std::setw(15) << name << ": count=" << std::setw(10) << count
<< " avg=" << std::fixed << std::setprecision(2) << std::setw(8) << total_ns / 1000.0 / count
<< " us"
<< " total=" << std::setprecision(3) << std::setw(8) << total_ns / 1e9 << " s" << std::endl;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant