File indexing completed on 2025-01-18 09:11:26
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 if (intersectedSurfaces.empty()) {
0026 unassignedMaterialInteractions = materialInteractions;
0027 return {assignedMaterialInteractions, unassignedMaterialInteractions, {}};
0028 }
0029
0030
0031
0032
0033
0034 std::size_t is = 0u;
0035 for (const auto& materialInteraction : materialInteractions) {
0036
0037 bool veto = false;
0038 for (const auto& gVeto : options.globalVetos) {
0039 if (gVeto(materialInteraction)) {
0040 unassignedMaterialInteractions.push_back(materialInteraction);
0041 veto = true;
0042 break;
0043 }
0044 }
0045
0046 if (veto) {
0047 continue;
0048 }
0049
0050
0051 auto [cSurface, cPosition, cDirection] = intersectedSurfaces[is];
0052 double cDistance = (cPosition - materialInteraction.position).norm();
0053
0054
0055 while (
0056 is + 1u < intersectedSurfaces.size() &&
0057 (((intersectedSurfaces[is + 1]).position - materialInteraction.position)
0058 .norm() < cDistance)) {
0059
0060 double nDistance = ((intersectedSurfaces[is + 1]).position -
0061 materialInteraction.position)
0062 .norm();
0063 ++is;
0064 cDistance = nDistance;
0065 }
0066
0067
0068 auto [surface, position, direction] = intersectedSurfaces[is];
0069
0070
0071 double pathCorrection = surface->pathCorrection(gctx, position, direction);
0072
0073
0074 GeometryIdentifier intersectionID = surface->geometryId();
0075 if (options.localVetos.contains(intersectionID)) {
0076 const auto& localVeto = *options.localVetos.find(intersectionID);
0077 if (localVeto(materialInteraction, intersectedSurfaces[is])) {
0078 unassignedMaterialInteractions.push_back(materialInteraction);
0079 continue;
0080 }
0081 }
0082
0083
0084
0085 MaterialInteraction assignedMaterialInteraction = materialInteraction;
0086 assignedMaterialInteraction.pathCorrection = pathCorrection;
0087 assignedMaterialInteraction.surface = surface;
0088 assignedMaterialInteraction.direction = direction;
0089 assignedMaterialInteraction.intersection = position;
0090 assignedMaterialInteraction.intersectionID = intersectionID;
0091
0092 if (is + 1u < intersectedSurfaces.size() &&
0093 options.reAssignments.contains(intersectionID)) {
0094 auto reAssignment = (*options.reAssignments.find(intersectionID));
0095 reAssignment(assignedMaterialInteraction, intersectedSurfaces[is],
0096 intersectedSurfaces[is + 1]);
0097 }
0098 assignedMaterialInteractions.push_back(assignedMaterialInteraction);
0099 }
0100
0101
0102 std::set<const Surface*> assignedSurfaces;
0103 for (const auto& assignedMaterialInteraction : assignedMaterialInteractions) {
0104 assignedSurfaces.insert(assignedMaterialInteraction.surface);
0105 }
0106
0107
0108
0109 std::vector<IAssignmentFinder::SurfaceAssignment> surfacesWithoutAssignments;
0110 for (const auto& intersectedSurface : intersectedSurfaces) {
0111 if (!assignedSurfaces.contains(intersectedSurface.surface)) {
0112 surfacesWithoutAssignments.push_back(intersectedSurface);
0113 }
0114 }
0115
0116
0117 return {assignedMaterialInteractions, unassignedMaterialInteractions,
0118 surfacesWithoutAssignments};
0119 }