File indexing completed on 2025-08-05 08:09:39
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Material/MaterialInteractionAssignment.hpp"
0010
0011 Acts::MaterialInteractionAssignment::Result
0012 Acts::MaterialInteractionAssignment::assign(
0013 const GeometryContext& gctx,
0014 const std::vector<MaterialInteraction>& materialInteractions,
0015 const std::vector<IAssignmentFinder::SurfaceAssignment>&
0016 intersectedSurfaces,
0017 const Options& options) {
0018
0019 std::vector<MaterialInteraction> assignedMaterialInteractions;
0020 assignedMaterialInteractions.reserve(materialInteractions.size());
0021
0022 std::vector<MaterialInteraction> unassignedMaterialInteractions;
0023
0024
0025
0026
0027
0028 std::size_t is = 0u;
0029 for (const auto& materialInteraction : materialInteractions) {
0030
0031 bool veto = false;
0032 for (const auto& gVeto : options.globalVetos) {
0033 if (gVeto(materialInteraction)) {
0034 unassignedMaterialInteractions.push_back(materialInteraction);
0035 veto = true;
0036 break;
0037 }
0038 }
0039
0040 if (veto) {
0041 continue;
0042 }
0043
0044
0045 auto [cSurface, cPosition, cDirection] = intersectedSurfaces[is];
0046 ActsScalar cDistance = (cPosition - materialInteraction.position).norm();
0047
0048
0049 while (
0050 is + 1u < intersectedSurfaces.size() &&
0051 (((intersectedSurfaces[is + 1]).position - materialInteraction.position)
0052 .norm() < cDistance)) {
0053
0054 ActsScalar nDistance = ((intersectedSurfaces[is + 1]).position -
0055 materialInteraction.position)
0056 .norm();
0057 ++is;
0058 cDistance = nDistance;
0059 }
0060
0061
0062 auto [surface, position, direction] = intersectedSurfaces[is];
0063
0064
0065 ActsScalar pathCorrection =
0066 surface->pathCorrection(gctx, position, direction);
0067
0068
0069 GeometryIdentifier intersectionID = surface->geometryId();
0070 if (options.localVetos.find(intersectionID) != options.localVetos.end()) {
0071 const auto& localVeto = *options.localVetos.find(intersectionID);
0072 if (localVeto(materialInteraction, intersectedSurfaces[is])) {
0073 unassignedMaterialInteractions.push_back(materialInteraction);
0074 continue;
0075 }
0076 }
0077
0078
0079 MaterialInteraction assignedMaterialInteraction = materialInteraction;
0080 assignedMaterialInteraction.pathCorrection = pathCorrection;
0081 assignedMaterialInteraction.surface = surface;
0082 assignedMaterialInteraction.position = position;
0083 assignedMaterialInteraction.direction = direction;
0084 assignedMaterialInteraction.intersectionID = intersectionID;
0085
0086 if (is + 1u < intersectedSurfaces.size() &&
0087 options.reAssignments.find(intersectionID) !=
0088 options.reAssignments.end()) {
0089 auto reAssignment = (*options.reAssignments.find(intersectionID));
0090 reAssignment(assignedMaterialInteraction, intersectedSurfaces[is],
0091 intersectedSurfaces[is + 1]);
0092 }
0093 assignedMaterialInteractions.push_back(assignedMaterialInteraction);
0094 }
0095
0096
0097 std::set<const Surface*> assignedSurfaces;
0098 for (const auto& assignedMaterialInteraction : assignedMaterialInteractions) {
0099 assignedSurfaces.insert(assignedMaterialInteraction.surface);
0100 }
0101
0102
0103
0104 std::vector<IAssignmentFinder::SurfaceAssignment> surfacesWithoutAssignments;
0105 for (const auto& intersectedSurface : intersectedSurfaces) {
0106 if (assignedSurfaces.find(intersectedSurface.surface) ==
0107 assignedSurfaces.end()) {
0108 surfacesWithoutAssignments.push_back(intersectedSurface);
0109 }
0110 }
0111
0112
0113 return {assignedMaterialInteractions, unassignedMaterialInteractions,
0114 surfacesWithoutAssignments};
0115 }