Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:39

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2024 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
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   // Return container: Assume a high assignment rate
0019   std::vector<MaterialInteraction> assignedMaterialInteractions;
0020   assignedMaterialInteractions.reserve(materialInteractions.size());
0021   // Return container: The unassigned materials
0022   std::vector<MaterialInteraction> unassignedMaterialInteractions;
0023 
0024   /// Simple matching of material interactions to surfaces - no pre/post
0025   /// matching
0026   // -----------------------------------------------------------------------------
0027   // Double-Loop over the sorted material interactions
0028   std::size_t is = 0u;
0029   for (const auto& materialInteraction : materialInteractions) {
0030     // First check if there is a global veto
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     // Now veto this assignment
0040     if (veto) {
0041       continue;
0042     }
0043 
0044     // Walk along the sorted intersections
0045     auto [cSurface, cPosition, cDirection] = intersectedSurfaces[is];
0046     ActsScalar cDistance = (cPosition - materialInteraction.position).norm();
0047 
0048     // Peak forward to check if you have a closer intersection
0049     while (
0050         is + 1u < intersectedSurfaces.size() &&
0051         (((intersectedSurfaces[is + 1]).position - materialInteraction.position)
0052              .norm() < cDistance)) {
0053       // Recalculate the new distance
0054       ActsScalar nDistance = ((intersectedSurfaces[is + 1]).position -
0055                               materialInteraction.position)
0056                                  .norm();
0057       ++is;
0058       cDistance = nDistance;
0059     }
0060 
0061     // Settled on the right intersection
0062     auto [surface, position, direction] = intersectedSurfaces[is];
0063 
0064     // Calculate the path correction
0065     ActsScalar pathCorrection =
0066         surface->pathCorrection(gctx, position, direction);
0067 
0068     // A local veta veto kicked in
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     // Assign the material interaction
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     // Check for possible reassignment
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   // Check which candidate surfaces had an assignment
0097   std::set<const Surface*> assignedSurfaces;
0098   for (const auto& assignedMaterialInteraction : assignedMaterialInteractions) {
0099     assignedSurfaces.insert(assignedMaterialInteraction.surface);
0100   }
0101 
0102   // Return container: Surfaces without assignments
0103   // (empty bin correction can use this information)
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   // return the pair of assigned and unassigned material interactions
0113   return {assignedMaterialInteractions, unassignedMaterialInteractions,
0114           surfacesWithoutAssignments};
0115 }