Skip to content

Commit 47a11e6

Browse files
Lauren WillsLauren Wills
authored andcommitted
feat: add elemental fractions to the material recording step. add a toggle to enable / disable
1 parent aa31700 commit 47a11e6

9 files changed

Lines changed: 45 additions & 1 deletion

File tree

Core/include/Acts/Material/MaterialInteraction.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ struct MaterialInteraction {
8181
double pathCorrection = 1.;
8282
/// The effective, passed material properties including the path correction.
8383
MaterialSlab materialSlab = MaterialSlab::Nothing();
84+
/// Vectors of the individual elements present
85+
std::vector<unsigned int> elementZ = {};
86+
/// How much of each element are present
87+
std::vector<float> elementFrac = {};
8488
};
8589

8690
/// Simple result struct to be returned

Examples/Algorithms/Geant4/include/ActsExamples/Geant4/Geant4Simulation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class Geant4MaterialRecording final : public Geant4SimulationBase {
191191

192192
/// Materials to exclude from the recording.
193193
std::vector<std::string> excludeMaterials = {"Air", "Vacuum"};
194+
bool recordElementFractions = false;
194195
};
195196

196197
/// Material recording constructor

Examples/Algorithms/Geant4/include/ActsExamples/Geant4/MaterialSteppingAction.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MaterialSteppingAction final : public G4UserSteppingAction {
3535
std::shared_ptr<EventStore> eventStore;
3636

3737
std::vector<std::string> excludeMaterials = {};
38+
bool recordElementFractions = false;
3839
};
3940

4041
/// Construct the action

Examples/Algorithms/Geant4/src/Geant4Simulation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ Geant4MaterialRecording::Geant4MaterialRecording(
392392
Geant4::MaterialSteppingAction::Config steppingCfg;
393393
steppingCfg.eventStore = m_eventStore;
394394
steppingCfg.excludeMaterials = m_cfg.excludeMaterials;
395+
steppingCfg.recordElementFractions = m_cfg.recordElementFractions;
395396
// G4RunManager will take care of deletion
396397
auto steppingAction = new Geant4::MaterialSteppingAction(
397398
steppingCfg, this->logger().cloneWithSuffix("MaterialSteppingAction"));

Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ void MaterialSteppingAction::UserSteppingAction(const G4Step* stepPtr) {
9090
mInteraction.materialSlab = slab;
9191
mInteraction.pathCorrection = step.GetStepLength() * convertLengthToActs;
9292

93+
if (m_cfg.recordElementFractions) {
94+
if (nElements == 1) {
95+
mInteraction.elementZ.push_back(
96+
static_cast<unsigned int>(material.GetZ()));
97+
mInteraction.elementFrac.push_back(1.0f);
98+
} else {
99+
for (std::size_t i = 0; i < nElements; i++){
100+
mInteraction.elementZ.push_back(
101+
static_cast<unsigned int>(elements->at(i).GetZ()));
102+
mInteraction.elementFrac.push_back(
103+
static_cast<float>(fraction[i]));
104+
}
105+
}
106+
}
107+
93108
assert(step.GetTrack() != nullptr);
94109
const G4Track& track = *step.GetTrack();
95110
const std::size_t trackId = track.GetTrackID();

Examples/Scripts/Python/material_recording.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def runMaterialRecording(
7575
randomNumbers=rnd,
7676
inputParticles=hepmc3Converter.config.outputParticles,
7777
outputMaterialTracks=materialTrackCollectionName,
78+
recordElementFractions= False,
7879
)
7980

8081
s.addAlgorithm(g4Alg)

Plugins/Root/include/ActsPlugins/Root/RootMaterialTrackIo.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class RootMaterialTrackIo {
155155
/// step material rho
156156
std::vector<float> stepMatRho;
157157
std::vector<float>* stepMatRhoPtr = &stepMatRho;
158+
/// step material element
159+
std::vector<std::vector<unsigned int>> stepElementZ;
160+
std::vector<std::vector<unsigned int>>* stepElementZPtr = &stepElementZ;
161+
/// step material fraction of elements
162+
std::vector<std::vector<float>> stepFraction;
163+
std::vector<std::vector<float>>* stepFractionPtr = &stepFraction;
158164
};
159165

160166
struct MaterialSurfacePayload {

Plugins/Root/src/RootMaterialTrackIo.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void ActsPlugins::RootMaterialTrackIo::connectForRead(TChain& materialChain) {
4343
materialChain.SetBranchAddress("mat_A", &m_stepPayload.stepMatAPtr);
4444
materialChain.SetBranchAddress("mat_Z", &m_stepPayload.stepMatZPtr);
4545
materialChain.SetBranchAddress("mat_rho", &m_stepPayload.stepMatRhoPtr);
46+
materialChain.SetBranchAddress("elements", &m_stepPayload.stepElementZPtr);
47+
materialChain.SetBranchAddress("fraction", &m_stepPayload.stepFractionPtr);
4648
if (m_cfg.surfaceInfo) {
4749
materialChain.SetBranchAddress("sur_id", &m_surfacePayload.surfaceIdPtr);
4850
materialChain.SetBranchAddress("sur_x", &m_surfacePayload.surfaceXPtr);
@@ -80,6 +82,8 @@ void ActsPlugins::RootMaterialTrackIo::connectForWrite(TTree& materialTree) {
8082
materialTree.Branch("mat_A", &m_stepPayload.stepMatA);
8183
materialTree.Branch("mat_Z", &m_stepPayload.stepMatZ);
8284
materialTree.Branch("mat_rho", &m_stepPayload.stepMatRho);
85+
materialTree.Branch("elements", &m_stepPayload.stepElementZ);
86+
materialTree.Branch("fraction", &m_stepPayload.stepFraction);
8387

8488
if (m_cfg.prePostStepInfo) {
8589
materialTree.Branch("mat_sx", &m_stepPayload.stepXs);
@@ -128,6 +132,8 @@ void ActsPlugins::RootMaterialTrackIo::write(
128132
m_stepPayload.stepMatA.clear();
129133
m_stepPayload.stepMatZ.clear();
130134
m_stepPayload.stepMatRho.clear();
135+
m_stepPayload.stepElementZ.clear();
136+
m_stepPayload.stepFraction.clear();
131137

132138
m_surfacePayload.surfaceId.clear();
133139
m_surfacePayload.surfaceX.clear();
@@ -162,6 +168,8 @@ void ActsPlugins::RootMaterialTrackIo::write(
162168
m_stepPayload.stepMatA.reserve(mints);
163169
m_stepPayload.stepMatZ.reserve(mints);
164170
m_stepPayload.stepMatRho.reserve(mints);
171+
m_stepPayload.stepElementZ.reserve(mints);
172+
m_stepPayload.stepFraction.reserve(mints);
165173

166174
m_surfacePayload.surfaceId.reserve(mints);
167175
m_surfacePayload.surfaceX.reserve(mints);
@@ -274,6 +282,8 @@ void ActsPlugins::RootMaterialTrackIo::write(
274282
m_stepPayload.stepMatA.push_back(mprops.material().Ar());
275283
m_stepPayload.stepMatZ.push_back(mprops.material().Z());
276284
m_stepPayload.stepMatRho.push_back(mprops.material().massDensity());
285+
m_stepPayload.stepElementZ.push_back(mint.elementZ);
286+
m_stepPayload.stepFraction.push_back(mint.elementFrac);
277287
// re-calculate if defined to do so
278288
if (m_cfg.recalculateTotals) {
279289
m_summaryPayload.tX0 += mprops.thicknessInX0();
@@ -320,6 +330,11 @@ RecordedMaterialTrack ActsPlugins::RootMaterialTrackIo::read() const {
320330
m_stepPayload.stepMatZ[is],
321331
m_stepPayload.stepMatRho[is]),
322332
s);
333+
/// adding the element vectors and fractions
334+
if (is < m_stepPayload.stepElementZ.size()) {
335+
mInteraction.elementZ = m_stepPayload.stepElementZ[is];
336+
mInteraction.elementFrac = m_stepPayload.stepFraction[is];
337+
}
323338
if (m_cfg.surfaceInfo) {
324339
// add the surface information to the interaction this allows the
325340
// mapping to be speed up

Python/Examples/src/plugins/Geant4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ PYBIND11_MODULE(ActsExamplesPythonBindingsGeant4, mod) {
168168
auto c = py::class_<Algorithm::Config, Geant4SimulationBase::Config,
169169
std::shared_ptr<Algorithm::Config>>(alg, "Config")
170170
.def(py::init<>());
171-
ACTS_PYTHON_STRUCT(c, outputMaterialTracks, excludeMaterials);
171+
ACTS_PYTHON_STRUCT(c, outputMaterialTracks, excludeMaterials, recordElementFractions);
172172
}
173173

174174
{

0 commit comments

Comments
 (0)