diff --git a/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp b/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp index 85b9310afd3..e8564b31df3 100644 --- a/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp +++ b/Core/include/Acts/Material/AccumulatedSurfaceMaterial.hpp @@ -92,22 +92,30 @@ class AccumulatedSurfaceMaterial { /// @param lp local position for the bin assignment /// @param mp material properties to be assigned /// @param pathCorrection Correction factor for the effective path length + /// @param elementZ to list all elements' Z value present (optional) + /// @param elementFrac to list the fraction that each element makes up (optional) /// /// @return the bin triple to which the material was assigned std::array accumulate(const Vector2& lp, const MaterialSlab& mp, - double pathCorrection = 1.); + double pathCorrection = 1., + const std::vector& elementZ = {}, + const std::vector& elementFrac = {}); /// Assign a material properties object /// /// @param gp global position for the bin assignment /// @param mp material properties to be assigned /// @param pathCorrection Correction factor for the effective path length + /// @param elementZ to list all elements' Z value present (optional) + /// @param elementFrac to list the fraction that each element makes up (optional) /// /// @return the bin triple to which the material was assigned std::array accumulate(const Vector3& gp, const MaterialSlab& mp, - double pathCorrection = 1.); + double pathCorrection = 1., + const std::vector& elementZ = {}, + const std::vector& elementFrac = {}); /// Use the accumulated material to update the material variance /// @@ -162,6 +170,23 @@ class AccumulatedSurfaceMaterial { /// The stored accumulated material matrix AccumulatedMatrix m_accumulatedMaterial; + + /// The running sum of thickness per bin + /// Used to normalize the vector of fractions or element + std::vector> m_totalThickness; + + /// The list of atomic numbers of elements present during mapping, per bin + std::vector>> m_elementZ; + + /// The fraction of each element present, normalized + /// Weighted by m_totalThickness to get final fraction + std::vector>> m_weightedFrac; + + void accumulateElementData( + std::size_t bin0, std::size_t bin1, + const MaterialSlab& mp, double pathCorrection, + const std::vector& elementZ, + const std::vector& elementFrac); }; inline const BinUtility& AccumulatedSurfaceMaterial::binUtility() const { diff --git a/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp b/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp index 356a363d64a..7ce6ffa5abb 100644 --- a/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp +++ b/Core/include/Acts/Material/BinnedSurfaceMaterial.hpp @@ -27,6 +27,17 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { /// Default Constructor - deleted BinnedSurfaceMaterial() = delete; + + ///Alias for Grid Level values of elementZ vector + /// [bin0][bin1] -> Z values per bin + using ElementZMatrix = + std::vector>>; + + ///Alias for Grid Level values of ElementFrac vetcor + using ElementFracMatrix = + std::vector>>; + + /// Explicit constructor with only full MaterialSlab, /// for one-dimensional binning. /// @@ -42,7 +53,9 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { BinnedSurfaceMaterial(const BinUtility& binUtility, MaterialSlabVector fullProperties, double splitFactor = 0., - MappingType mappingType = MappingType::Default); + MappingType mappingType = MappingType::Default, + ElementZMatrix elementZ = {}, + ElementFracMatrix elementFrac = {}); /// Explicit constructor with only full MaterialSlab, /// for two-dimensional binning. @@ -59,7 +72,9 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { BinnedSurfaceMaterial(const BinUtility& binUtility, MaterialSlabMatrix fullProperties, double splitFactor = 0., - MappingType mappingType = MappingType::Default); + MappingType mappingType = MappingType::Default, + ElementZMatrix elementZ = {}, + ElementFracMatrix elementFrac = {}); /// Copy Move Constructor /// @@ -106,6 +121,25 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { using ISurfaceMaterial::materialSlab; + ///Return 3D Grid of element Z values + ///@return Reference to the ElementZMatrix + const ElementZMatrix& elementZMatrix() const; + + ///Return 3D Grid of fractions for each element Z + ///@return Reference to the ElementFracMatrix + const ElementFracMatrix& elementFracMatrix() const; + + ///Return elementZ for a specific bin + ///@return Reference to the elementZ vector for that bin + const std::vector& elementZAt(std::size_t bin0, + std::size_t bin1) const; + + ///Return elementFrac for a specific bin + ///@return Reference to the elementFrac vector for that bin + const std::vector& elementFracAt(std::size_t bin0, + std::size_t bin1) const; + + /// Output Method for std::ostream, to be overloaded by child classes /// @param sl The output stream to write to /// @return Reference to the output stream after writing @@ -117,6 +151,14 @@ class BinnedSurfaceMaterial : public ISurfaceMaterial { /// The five different MaterialSlab MaterialSlabMatrix m_fullMaterial; + + ///The Per-bin element list - indexed[bin1][bin0] + ///empty if using older material recording (element list was not recorded) + ElementZMatrix m_elementZ; + + ///The Per-bin list of fractions weighted by thickness- sum to 1 per bin + /// Empty if using older material recording (fraction was not recorded) + ElementFracMatrix m_elementFrac; }; inline const BinUtility& BinnedSurfaceMaterial::binUtility() const { @@ -127,4 +169,24 @@ inline const MaterialSlabMatrix& BinnedSurfaceMaterial::fullMaterial() const { return m_fullMaterial; } +inline const BinnedSurfaceMaterial::ElementZMatrix& +BinnedSurfaceMaterial::elementZMatrix() const { + return m_elementZ; +} + +inline const BinnedSurfaceMaterial::ElementFracMatrix& +BinnedSurfaceMaterial::elementFracMatrix() const { + return m_elementFrac; +} + +inline const std::vector& BinnedSurfaceMaterial::elementZAt( + std::size_t bin0, std::size_t bin1) const{ + return m_elementZ[bin0][bin1]; +} + +inline const std::vector& BinnedSurfaceMaterial::elementFracAt( + std::size_t bin0, std::size_t bin1) const{ + return m_elementFrac[bin0][bin1]; +} + } // namespace Acts diff --git a/Core/include/Acts/Material/MaterialInteraction.hpp b/Core/include/Acts/Material/MaterialInteraction.hpp index 12efcd5e783..4f4d38c4640 100644 --- a/Core/include/Acts/Material/MaterialInteraction.hpp +++ b/Core/include/Acts/Material/MaterialInteraction.hpp @@ -81,6 +81,10 @@ struct MaterialInteraction { double pathCorrection = 1.; /// The effective, passed material properties including the path correction. MaterialSlab materialSlab = MaterialSlab::Nothing(); + /// Vectors of the individual elements present + std::vector elementZ = {}; + /// How much of each element are present + std::vector elementFrac = {}; }; /// Simple result struct to be returned diff --git a/Core/src/Material/AccumulatedSurfaceMaterial.cpp b/Core/src/Material/AccumulatedSurfaceMaterial.cpp index 9fb08edc903..82c05f459b7 100644 --- a/Core/src/Material/AccumulatedSurfaceMaterial.cpp +++ b/Core/src/Material/AccumulatedSurfaceMaterial.cpp @@ -19,6 +19,13 @@ Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial(double splitFactor) : m_splitFactor(splitFactor) { AccumulatedVector accMat = {{AccumulatedMaterialSlab()}}; m_accumulatedMaterial = {{accMat}}; + /// initializing the three vectors needed for Detailed Material description: + m_totalThickness = std::vector>( + 1, std::vector(1, 0.0)); + m_elementZ = std::vector>>( + 1, std::vector>(1)); + m_weightedFrac = std::vector>>( + 1, std::vector>(1)); } // Binned Material constructor with split factor @@ -29,33 +36,87 @@ Acts::AccumulatedSurfaceMaterial::AccumulatedSurfaceMaterial( std::size_t bins1 = m_binUtility.bins(1); AccumulatedVector accVec(bins0, AccumulatedMaterialSlab()); m_accumulatedMaterial = AccumulatedMatrix(bins1, accVec); + m_totalThickness = std::vector>( + bins1, std::vector(bins0, 0.0)); + m_elementZ = std::vector>>( + bins1, std::vector>(bins0)); + m_weightedFrac = std::vector>>( + bins1, std::vector>(bins0)); } // Assign a material properties object std::array Acts::AccumulatedSurfaceMaterial::accumulate( - const Vector2& lp, const MaterialSlab& mp, double pathCorrection) { + const Vector2& lp, const MaterialSlab& mp, double pathCorrection, + const std::vector& elementZ, + const std::vector& elementFrac) { if (m_binUtility.dimensions() == 0) { m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection); + accumulateElementData(0, 0, mp, pathCorrection, elementZ, elementFrac); return {0, 0, 0}; } std::size_t bin0 = m_binUtility.bin(lp, 0); std::size_t bin1 = m_binUtility.bin(lp, 1); m_accumulatedMaterial[bin1][bin0].accumulate(mp, pathCorrection); + accumulateElementData(bin0, bin1, mp, pathCorrection, elementZ, elementFrac); return {bin0, bin1, 0}; } + // Assign a material properties object std::array Acts::AccumulatedSurfaceMaterial::accumulate( - const Vector3& gp, const MaterialSlab& mp, double pathCorrection) { + const Vector3& gp, const MaterialSlab& mp, double pathCorrection, + const std::vector& elementZ, + const std::vector& elementFrac) { if (m_binUtility.dimensions() == 0) { m_accumulatedMaterial[0][0].accumulate(mp, pathCorrection); + accumulateElementData(0, 0, mp, pathCorrection, elementZ, elementFrac); return {0, 0, 0}; } std::array bTriple = m_binUtility.binTriple(gp); m_accumulatedMaterial[bTriple[1]][bTriple[0]].accumulate(mp, pathCorrection); + accumulateElementData(bTriple[0],bTriple[1], mp, pathCorrection, elementZ, elementFrac); return bTriple; } +// Helper- new element list and fraction accumulation calculation +void Acts::AccumulatedSurfaceMaterial::accumulateElementData( + std::size_t bin0, size_t bin1, + const MaterialSlab& mp, double pathCorrection, + const std::vector& elementZ, + const std::vector& elementFrac) { + if (elementZ.empty() || elementZ.size() != elementFrac.size()) { + return; + } + + double stepThickness = + static_cast(mp.thickness()) / pathCorrection; + + if (stepThickness <= 0.) { + return; + } + + m_totalThickness[bin1][bin0] += stepThickness; + for (std::size_t i = 0; i (stepThickness); + } else{ + m_elementZ[bin1][bin0].push_back(z); + m_weightedFrac[bin1][bin0].push_back( + frac * static_cast(stepThickness)); + } + } +} + + + // Void average for vacuum assignment void Acts::AccumulatedSurfaceMaterial::trackVariance(const Vector3& gp, MaterialSlab slabReference, @@ -148,7 +209,31 @@ Acts::AccumulatedSurfaceMaterial::totalAverage() { mpMatrix[ib1][ib0] = m_accumulatedMaterial[ib1][ib0].totalAverage().first; } } + // Build the element composition grids + BinnedSurfaceMaterial::ElementZMatrix finalElementZ( + m_binUtility.bins(1), + std::vector>(m_binUtility.bins(0))); + BinnedSurfaceMaterial::ElementFracMatrix finalElementFrac( + m_binUtility.bins(1), + std::vector>(m_binUtility.bins(0))); + for (std::size_t ib1 = 0; ib1 < m_binUtility.bins(1); ++ib1){ + for (std::size_t ib0 = 0; ib0 < m_binUtility.bins(0); ++ib0){ + finalElementZ[ib1][ib0] = m_elementZ[ib1][ib0]; + double totalThickness = m_totalThickness[ib1][ib0]; + if (totalThickness > 0. && !m_weightedFrac[ib1][ib0].empty()) { + finalElementFrac[ib1][ib0].resize(m_weightedFrac[ib1][ib0].size()); + for (std::size_t i = 0; i < m_weightedFrac[ib1][ib0].size(); ++i){ + finalElementFrac[ib1][ib0][i] = + m_weightedFrac[ib1][ib0][i] / static_cast(totalThickness); + } + } + } + } + + // Now return the BinnedSurfaceMaterial return std::make_unique( - m_binUtility, std::move(mpMatrix), m_splitFactor); + m_binUtility, std::move(mpMatrix), m_splitFactor, + MappingType::Default, + std::move(finalElementZ), std::move(finalElementFrac)); } diff --git a/Core/src/Material/BinnedSurfaceMaterial.cpp b/Core/src/Material/BinnedSurfaceMaterial.cpp index aae46bd02d7..1ba9ec4ea47 100644 --- a/Core/src/Material/BinnedSurfaceMaterial.cpp +++ b/Core/src/Material/BinnedSurfaceMaterial.cpp @@ -16,18 +16,25 @@ Acts::BinnedSurfaceMaterial::BinnedSurfaceMaterial( const BinUtility& binUtility, MaterialSlabVector fullProperties, - double splitFactor, Acts::MappingType mappingType) - : ISurfaceMaterial(splitFactor, mappingType), m_binUtility(binUtility) { - // fill the material with deep copy + double splitFactor, Acts::MappingType mappingType, + ElementZMatrix elementZ, ElementFracMatrix elementFrac) + : ISurfaceMaterial(splitFactor, mappingType), + m_binUtility(binUtility), + m_elementZ(std::move(elementZ)), + m_elementFrac(std::move(elementFrac)) { m_fullMaterial.push_back(std::move(fullProperties)); } Acts::BinnedSurfaceMaterial::BinnedSurfaceMaterial( const BinUtility& binUtility, MaterialSlabMatrix fullProperties, - double splitFactor, Acts::MappingType mappingType) + double splitFactor, Acts::MappingType mappingType, + ElementZMatrix elementZ, ElementFracMatrix elementFrac) : ISurfaceMaterial(splitFactor, mappingType), m_binUtility(binUtility), - m_fullMaterial(std::move(fullProperties)) {} + m_fullMaterial(std::move(fullProperties)), + m_elementZ(std::move(elementZ)), + m_elementFrac(std::move(elementFrac)) { +} Acts::BinnedSurfaceMaterial& Acts::BinnedSurfaceMaterial::scale(double factor) { for (auto& materialVector : m_fullMaterial) { diff --git a/Core/src/Material/SurfaceMaterialMapper.cpp b/Core/src/Material/SurfaceMaterialMapper.cpp index 3469c4a7f29..1e5dcd17bad 100644 --- a/Core/src/Material/SurfaceMaterialMapper.cpp +++ b/Core/src/Material/SurfaceMaterialMapper.cpp @@ -390,7 +390,8 @@ Result SurfaceMaterialMapper::mapInteraction( } // Now assign the material for the accumulation process auto tBin = currentAccMaterial->second.accumulate( - currentPos, rmIter->materialSlab, currentPathCorrection); + currentPos, rmIter->materialSlab, currentPathCorrection, + rmIter->elementZ, rmIter->elementFrac); if (!touchedMapBins.contains(&(currentAccMaterial->second))) { touchedMapBins.insert(MapBin(&(currentAccMaterial->second), tBin)); } @@ -482,7 +483,8 @@ void SurfaceMaterialMapper::mapSurfaceInteraction( // Now assign the material for the accumulation process auto tBin = currentAccMaterial->second.accumulate( - currentPos, rmIter->materialSlab, rmIter->pathCorrection); + currentPos, rmIter->materialSlab, rmIter->pathCorrection, + rmIter->elementZ, rmIter->elementFrac); if (!touchedMapBins.contains(&(currentAccMaterial->second))) { touchedMapBins.insert(MapBin(&(currentAccMaterial->second), tBin)); } diff --git a/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/Geant4Simulation.hpp b/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/Geant4Simulation.hpp index 3cab540d3a6..51b4279648e 100644 --- a/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/Geant4Simulation.hpp +++ b/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/Geant4Simulation.hpp @@ -191,6 +191,7 @@ class Geant4MaterialRecording final : public Geant4SimulationBase { /// Materials to exclude from the recording. std::vector excludeMaterials = {"Air", "Vacuum"}; + bool DetailedMaterial = false; }; /// Material recording constructor diff --git a/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/MaterialSteppingAction.hpp b/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/MaterialSteppingAction.hpp index 048e843c8a3..df943366c49 100644 --- a/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/MaterialSteppingAction.hpp +++ b/Examples/Algorithms/Geant4/include/ActsExamples/Geant4/MaterialSteppingAction.hpp @@ -35,6 +35,7 @@ class MaterialSteppingAction final : public G4UserSteppingAction { std::shared_ptr eventStore; std::vector excludeMaterials = {}; + bool DetailedMaterial = false; }; /// Construct the action diff --git a/Examples/Algorithms/Geant4/src/Geant4Simulation.cpp b/Examples/Algorithms/Geant4/src/Geant4Simulation.cpp index fae9436bb3e..63fbfd37652 100644 --- a/Examples/Algorithms/Geant4/src/Geant4Simulation.cpp +++ b/Examples/Algorithms/Geant4/src/Geant4Simulation.cpp @@ -392,6 +392,7 @@ Geant4MaterialRecording::Geant4MaterialRecording( Geant4::MaterialSteppingAction::Config steppingCfg; steppingCfg.eventStore = m_eventStore; steppingCfg.excludeMaterials = m_cfg.excludeMaterials; + steppingCfg.DetailedMaterial = m_cfg.DetailedMaterial; // G4RunManager will take care of deletion auto steppingAction = new Geant4::MaterialSteppingAction( steppingCfg, this->logger().cloneWithSuffix("MaterialSteppingAction")); diff --git a/Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp b/Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp index 79ae2347169..4976649fcb7 100644 --- a/Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp +++ b/Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp @@ -93,6 +93,21 @@ void MaterialSteppingAction::UserSteppingAction(const G4Step* step) { mInteraction.materialSlab = slab; mInteraction.pathCorrection = (step->GetStepLength() / CLHEP::mm); + if (m_cfg.DetailedMaterial) { + if (nElements == 1) { + mInteraction.elementZ.push_back( + static_cast(material->GetZ())); + mInteraction.elementFrac.push_back(1.0f); + } else { + for (std::size_t i = 0; i < nElements; i++){ + mInteraction.elementZ.push_back( + static_cast(elements->at(i)->GetZ())); + mInteraction.elementFrac.push_back( + static_cast(fraction[i])); + } + } + } + G4Track* g4Track = step->GetTrack(); std::size_t trackID = g4Track->GetTrackID(); auto& materialTracks = eventStore().materialTracks; diff --git a/Plugins/Json/src/MaterialJsonConverter.cpp b/Plugins/Json/src/MaterialJsonConverter.cpp index 8988d30b6aa..aee69b0c5c3 100644 --- a/Plugins/Json/src/MaterialJsonConverter.cpp +++ b/Plugins/Json/src/MaterialJsonConverter.cpp @@ -386,6 +386,13 @@ void Acts::to_json(nlohmann::json& j, const surfaceMaterialPointer& material) { // Next option remaining: BinnedSurface material auto bsMaterial = dynamic_cast(material); if (bsMaterial != nullptr) { + std::cout << "DEBUG: entering BinnedSurfaceMaterial writer" << std::endl; + std::cout << "DEBUG: fullMaterial size: " + << bsMaterial->fullMaterial().size() << std::endl; + std::cout << "DEBUG: elementZMatrix size: " + << bsMaterial->elementZMatrix().size() << std::endl; + + // type is binned jMaterial[Acts::jsonKey().typekey] = "binned"; // Set mapping type @@ -396,16 +403,36 @@ void Acts::to_json(nlohmann::json& j, const surfaceMaterialPointer& material) { bUtility = &(bsMaterial->binUtility()); // convert the data // get the material matrix + // include the list of elements and their fractions nlohmann::json mmat = nlohmann::json::array(); + std::size_t ib1 = 0; for (const auto& mpVector : bsMaterial->fullMaterial()) { nlohmann::json mvec = nlohmann::json::array(); + std::size_t ib0 = 0; for (const auto& mp : mpVector) { nlohmann::json jmat(mp); + if (!bsMaterial->elementZMatrix().empty() && + ib1 < bsMaterial->elementZMatrix().size() && + ib0 < bsMaterial->elementZMatrix()[ib1].size()) { + const auto& zVec = bsMaterial->elementZAt(ib1, ib0); + const auto& fVec = bsMaterial->elementFracAt(ib1, ib0); + if (!zVec.empty()) { + nlohmann::json composition = nlohmann::json::array(); + for (std::size_t i = 0; i < zVec.size(); ++i) { + composition.push_back( + nlohmann::json::array({zVec[i], fVec[i]})); + } + jmat["composition"] = std::move(composition); + } + } mvec.push_back(jmat); + ++ib0; } mmat.push_back(std::move(mvec)); + ++ib1; } jMaterial[Acts::jsonKey().datakey] = std::move(mmat); + // write the bin utility nlohmann::json jBin(*bUtility); jMaterial[Acts::jsonKey().binkey] = jBin; @@ -477,12 +504,30 @@ void Acts::from_json(const nlohmann::json& j, Acts::BinUtility bUtility; Acts::MaterialSlabMatrix mpMatrix; Acts::MappingType mapType = Acts::MappingType::Default; + Acts::BinnedSurfaceMaterial::ElementZMatrix elementZMatrix; + Acts::BinnedSurfaceMaterial::ElementFracMatrix elementFracMatrix; for (auto& [key, value] : jMaterial.items()) { if (key == Acts::jsonKey().binkey && !value.empty()) { from_json(value, bUtility); } if (key == Acts::jsonKey().datakey && !value.empty()) { from_json(value, mpMatrix); + elementZMatrix.resize(value.size()); + elementFracMatrix.resize(value.size()); + for (std::size_t ib1 = 0; ib1 < value.size(); ++ib1) { + elementZMatrix[ib1].resize(value[ib1].size()); + elementFracMatrix[ib1].resize(value[ib1].size()); + for (std::size_t ib0 = 0; ib0 < value[ib1].size(); ++ib0) { + if (value[ib1][ib0].contains("composition")) { + for (const auto& pair : value[ib1][ib0]["composition"]) { + elementZMatrix[ib1][ib0].push_back( + pair[0].get()); + elementFracMatrix[ib1][ib0].push_back( + pair[1].get()); + } + } + } + } } if (key == Acts::jsonKey().maptype && !value.empty()) { from_json(value, mapType); @@ -494,7 +539,9 @@ void Acts::from_json(const nlohmann::json& j, } else if (bUtility.bins() == 1) { material = new Acts::HomogeneousSurfaceMaterial(mpMatrix[0][0], 1, mapType); } else { - material = new Acts::BinnedSurfaceMaterial(bUtility, mpMatrix, 1, mapType); + material = new Acts::BinnedSurfaceMaterial(bUtility, mpMatrix, 1, mapType, + std::move(elementZMatrix), + std::move(elementFracMatrix)); } } diff --git a/Plugins/Root/include/ActsPlugins/Root/RootMaterialTrackIo.hpp b/Plugins/Root/include/ActsPlugins/Root/RootMaterialTrackIo.hpp index f1d590c8271..17c68158d58 100644 --- a/Plugins/Root/include/ActsPlugins/Root/RootMaterialTrackIo.hpp +++ b/Plugins/Root/include/ActsPlugins/Root/RootMaterialTrackIo.hpp @@ -155,6 +155,12 @@ class RootMaterialTrackIo { /// step material rho std::vector stepMatRho; std::vector* stepMatRhoPtr = &stepMatRho; + /// step material element + std::vector> stepElementZ; + std::vector>* stepElementZPtr = &stepElementZ; + /// step material fraction of elements + std::vector> stepFraction; + std::vector>* stepFractionPtr = &stepFraction; }; struct MaterialSurfacePayload { diff --git a/Plugins/Root/src/RootMaterialTrackIo.cpp b/Plugins/Root/src/RootMaterialTrackIo.cpp index 9cd82eb91f3..ef273ef1605 100644 --- a/Plugins/Root/src/RootMaterialTrackIo.cpp +++ b/Plugins/Root/src/RootMaterialTrackIo.cpp @@ -43,6 +43,8 @@ void ActsPlugins::RootMaterialTrackIo::connectForRead(TChain& materialChain) { materialChain.SetBranchAddress("mat_A", &m_stepPayload.stepMatAPtr); materialChain.SetBranchAddress("mat_Z", &m_stepPayload.stepMatZPtr); materialChain.SetBranchAddress("mat_rho", &m_stepPayload.stepMatRhoPtr); + materialChain.SetBranchAddress("elements", &m_stepPayload.stepElementZPtr); + materialChain.SetBranchAddress("fraction", &m_stepPayload.stepFractionPtr); if (m_cfg.surfaceInfo) { materialChain.SetBranchAddress("sur_id", &m_surfacePayload.surfaceIdPtr); materialChain.SetBranchAddress("sur_x", &m_surfacePayload.surfaceXPtr); @@ -80,6 +82,8 @@ void ActsPlugins::RootMaterialTrackIo::connectForWrite(TTree& materialTree) { materialTree.Branch("mat_A", &m_stepPayload.stepMatA); materialTree.Branch("mat_Z", &m_stepPayload.stepMatZ); materialTree.Branch("mat_rho", &m_stepPayload.stepMatRho); + materialTree.Branch("elements", &m_stepPayload.stepElementZ); + materialTree.Branch("fraction", &m_stepPayload.stepFraction); if (m_cfg.prePostStepInfo) { materialTree.Branch("mat_sx", &m_stepPayload.stepXs); @@ -128,6 +132,8 @@ void ActsPlugins::RootMaterialTrackIo::write( m_stepPayload.stepMatA.clear(); m_stepPayload.stepMatZ.clear(); m_stepPayload.stepMatRho.clear(); + m_stepPayload.stepElementZ.clear(); + m_stepPayload.stepFraction.clear(); m_surfacePayload.surfaceId.clear(); m_surfacePayload.surfaceX.clear(); @@ -162,6 +168,8 @@ void ActsPlugins::RootMaterialTrackIo::write( m_stepPayload.stepMatA.reserve(mints); m_stepPayload.stepMatZ.reserve(mints); m_stepPayload.stepMatRho.reserve(mints); + m_stepPayload.stepElementZ.reserve(mints); + m_stepPayload.stepFraction.reserve(mints); m_surfacePayload.surfaceId.reserve(mints); m_surfacePayload.surfaceX.reserve(mints); @@ -274,6 +282,8 @@ void ActsPlugins::RootMaterialTrackIo::write( m_stepPayload.stepMatA.push_back(mprops.material().Ar()); m_stepPayload.stepMatZ.push_back(mprops.material().Z()); m_stepPayload.stepMatRho.push_back(mprops.material().massDensity()); + m_stepPayload.stepElementZ.push_back(mint.elementZ); + m_stepPayload.stepFraction.push_back(mint.elementFrac); // re-calculate if defined to do so if (m_cfg.recalculateTotals) { m_summaryPayload.tX0 += mprops.thicknessInX0(); @@ -320,6 +330,11 @@ RecordedMaterialTrack ActsPlugins::RootMaterialTrackIo::read() const { m_stepPayload.stepMatZ[is], m_stepPayload.stepMatRho[is]), s); + /// adding the element vectors and fractions + if (is < m_stepPayload.stepElementZ.size()) { + mInteraction.elementZ = m_stepPayload.stepElementZ[is]; + mInteraction.elementFrac = m_stepPayload.stepFraction[is]; + } if (m_cfg.surfaceInfo) { // add the surface information to the interaction this allows the // mapping to be speed up diff --git a/Python/Examples/src/plugins/Geant4.cpp b/Python/Examples/src/plugins/Geant4.cpp index bc269c124c7..28aca9c4286 100644 --- a/Python/Examples/src/plugins/Geant4.cpp +++ b/Python/Examples/src/plugins/Geant4.cpp @@ -168,7 +168,7 @@ PYBIND11_MODULE(ActsExamplesPythonBindingsGeant4, mod) { auto c = py::class_>(alg, "Config") .def(py::init<>()); - ACTS_PYTHON_STRUCT(c, outputMaterialTracks, excludeMaterials); + ACTS_PYTHON_STRUCT(c, outputMaterialTracks, excludeMaterials, DetailedMaterial); } {