Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:26

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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   // Check for empty intersection
0025   if (intersectedSurfaces.empty()) {
0026     unassignedMaterialInteractions = materialInteractions;
0027     return {assignedMaterialInteractions, unassignedMaterialInteractions, {}};
0028   }
0029 
0030   /// Simple matching of material interactions to surfaces - no pre/post
0031   /// matching
0032   // -----------------------------------------------------------------------------
0033   // Double-Loop over the sorted material interactions
0034   std::size_t is = 0u;
0035   for (const auto& materialInteraction : materialInteractions) {
0036     // First check if there is a global veto
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     // Now veto this assignment
0046     if (veto) {
0047       continue;
0048     }
0049 
0050     // Walk along the sorted intersections
0051     auto [cSurface, cPosition, cDirection] = intersectedSurfaces[is];
0052     double cDistance = (cPosition - materialInteraction.position).norm();
0053 
0054     // Peak forward to check if you have a closer intersection
0055     while (
0056         is + 1u < intersectedSurfaces.size() &&
0057         (((intersectedSurfaces[is + 1]).position - materialInteraction.position)
0058              .norm() < cDistance)) {
0059       // Recalculate the new distance
0060       double nDistance = ((intersectedSurfaces[is + 1]).position -
0061                           materialInteraction.position)
0062                              .norm();
0063       ++is;
0064       cDistance = nDistance;
0065     }
0066 
0067     // Settled on the right intersection
0068     auto [surface, position, direction] = intersectedSurfaces[is];
0069 
0070     // Calculate the path correction
0071     double pathCorrection = surface->pathCorrection(gctx, position, direction);
0072 
0073     // A local veta veto kicked in
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     // Assign the material interaction - position stays, but intersection is
0084     // updated
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     // Check for possible reassignment
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   // Check which candidate surfaces had an assignment
0102   std::set<const Surface*> assignedSurfaces;
0103   for (const auto& assignedMaterialInteraction : assignedMaterialInteractions) {
0104     assignedSurfaces.insert(assignedMaterialInteraction.surface);
0105   }
0106 
0107   // Return container: Surfaces without assignments
0108   // (empty bin correction can use this information)
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   // return the pair of assigned and unassigned material interactions
0117   return {assignedMaterialInteractions, unassignedMaterialInteractions,
0118           surfacesWithoutAssignments};
0119 }