Skip to content

Commit 2c91e1c

Browse files
committed
added new gPhotonDetector routine, similar to flux but only records optical photons. it does not require recordZeroEdep to be set. cherenkov detector modified to use it
1 parent 2addd73 commit 2c91e1c

14 files changed

Lines changed: 99 additions & 10 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The project goal is to make Geant4-based simulation accessible to users who want
2121
- Geometry and material storage in SQLite or GEMC ASCII databases
2222
- Geometry imports from native GEMC databases, GDML, and CAD meshes
2323
- Run-number and variation support for reusable detector configurations
24-
- Built-in sensitive detector digitizations: `flux`, `dosimeter`, and `particle_counter`
24+
- Built-in sensitive detector digitizations: `flux`, `gPhotonDetector`, `dosimeter`, and `particle_counter`
2525
- Dynamic C++ plugin infrastructure for custom digitization, fields, particle readers, and output streamers
2626
- Event generation from command-line/YAML particle definitions and Lund files
2727
- Output streamers for ASCII, CSV, JSON, JLAB SRO, and optional ROOT output

ci/install_examples_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"b3": {"runs": ["1", "11"], "variations": ["default", "alt"]},
1818
},
1919
"optical": {
20-
"cherenkov": {"runs": ["1"], "variations": ["default", "CO2", "C4F10"]},
20+
"cherenkov": {"runs": ["1"], "variations": ["default", "mediumIndexRadiator", "highIndexRadiator"]},
2121
},
2222
}
2323

examples/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ examples_map = {
1414
'b3' : { 'runs' : ['1', '11'], 'variations' : ['default', 'alt'] }
1515
},
1616
'optical' : {
17-
'cherenkov' : { 'runs' : ['1'], 'variations' : ['default', 'CO2', 'C4F10'] },
17+
'cherenkov' : { 'runs' : ['1'], 'variations' : ['default', 'mediumIndexRadiator', 'highIndexRadiator'] },
1818
}
1919
}
2020

examples/optical/cherenkov/cherenkov.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,6 @@
112112
backplate.material = material
113113

114114
backplate.color = "lightgray"
115-
backplate.digitization = "flux"
115+
backplate.digitization = "gPhotonDetector"
116116
backplate.set_identifier("detector", panel_id)
117117
backplate.publish(cfg)

examples/optical/cherenkov/cherenkov.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,3 @@ gparticle:
2626
- name: e-
2727
p: 1000
2828
vz: -50
29-
30-
# Required for optical-photon flux hits because optical photons deposit zero energy.
31-
recordZeroEdep: true

gdetector/gdetectorConstruction.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "gsystemConventions.h"
99
#include "gDosimeterDigitization.h"
1010
#include "gFluxDigitization.h"
11+
#include "gPhotonDetectorDigitization.h"
1112
#include "gParticleCounterDigitization.h"
1213

1314
// geant4
@@ -262,6 +263,9 @@ void GDetectorConstruction::loadDigitizationPlugins() {
262263
if (sdname == FLUXNAME) {
263264
log->info(1, "Loading flux digitization plugin for routine <" + sdname + ">");
264265
digitization_routines_map->emplace(sdname, std::make_shared<GFluxDigitization>(gopt));
266+
} else if (sdname == GPHOTON_DETECTORNAME) {
267+
log->info(1, "Loading gPhotonDetector digitization plugin for routine <" + sdname + ">");
268+
digitization_routines_map->emplace(sdname, std::make_shared<GPhotonDetectorDigitization>(gopt));
265269
} else if (sdname == COUNTERNAME) {
266270
log->info(1, "Loading particle counter digitization plugin for routine <" + sdname + ">");
267271
digitization_routines_map->emplace(sdname, std::make_shared<GParticleCounterDigitization>(gopt));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "gPhotonDetectorDigitization.h"
2+
3+
// geant4
4+
#include "G4OpticalPhoton.hh"
5+
#include "G4Step.hh"
6+
7+
bool GPhotonDetectorDigitization::decisionToSkipHit(double energy, const G4Step* thisStep) {
8+
if (thisStep == nullptr || thisStep->GetTrack() == nullptr) {
9+
return true;
10+
}
11+
12+
const auto* particle = thisStep->GetTrack()->GetDefinition();
13+
if (particle != G4OpticalPhoton::OpticalPhotonDefinition()) {
14+
return true;
15+
}
16+
17+
if (energy == 0) {
18+
return false;
19+
}
20+
21+
return GDynamicDigitization::decisionToSkipHit(energy);
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "gFluxDigitization.h"
4+
5+
/**
6+
* \class GPhotonDetectorDigitization
7+
* \brief Built-in digitization routine for optical-photon flux detectors.
8+
*
9+
* This routine records the same output fields as \c flux, but accepts only Geant4
10+
* optical-photon steps. Optical photons are recorded even when they deposit zero
11+
* energy, independent of the global \c recordZeroEdep switch.
12+
*/
13+
class GPhotonDetectorDigitization : public GFluxDigitization
14+
{
15+
public:
16+
/// Inherit the base constructor (const std::shared_ptr<GOptions>&).
17+
using GFluxDigitization::GFluxDigitization;
18+
19+
/**
20+
* \brief Keeps only optical-photon steps.
21+
*
22+
* \param energy Total deposited energy for the step.
23+
* \param thisStep Geant4 step being processed.
24+
* \return true when the step should be skipped.
25+
*/
26+
bool decisionToSkipHit(double energy, const G4Step* thisStep) override;
27+
};

gdynamicDigitization/gdynamicdigitization.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,20 @@ class GDynamicDigitization : public GBase<GDynamicDigitization> {
472472
return false;
473473
}
474474

475+
/**
476+
* \brief Decides whether a step should be skipped before hit creation.
477+
*
478+
* This overload gives digitization routines access to the full Geant4 step while
479+
* preserving the legacy energy-only hook for existing plugins.
480+
*
481+
* \param energy Total deposited energy for the step.
482+
* \param thisStep Geant4 step being processed.
483+
* \return true if the step should be skipped.
484+
*/
485+
virtual bool decisionToSkipHit(double energy, [[maybe_unused]] const G4Step* thisStep) {
486+
return decisionToSkipHit(energy);
487+
}
488+
475489
/**
476490
* \brief Sets the options pointer required by the digitization base.
477491
*

gdynamicDigitization/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ LD += {
1515
'sources' : files(
1616
'gdynamicdigitization.cc',
1717
'gFluxDigitization.cc',
18+
'gPhotonDetectorDigitization.cc',
1819
'gParticleCounterDigitization.cc',
1920
'gDosimeterDigitization.cc',
2021
'gdynamicdigitization_options.cc'
2122
),
2223
'headers' : files(
2324
'gdynamicdigitization_options.h',
2425
'gFluxDigitization.h',
26+
'gPhotonDetectorDigitization.h',
2527
'gParticleCounterDigitization.h',
2628
'gDosimeterDigitization.h',
2729
'greadoutSpecs.h'

0 commit comments

Comments
 (0)