Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:59

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 #pragma once
0010 
0011 #include "Acts/Geometry/TrackingVolume.hpp"
0012 
0013 #include <sstream>
0014 
0015 namespace Acts {
0016 
0017 /// Simple struct to select volumes
0018 struct VolumeSelector {
0019   bool selectMaterial = true;
0020   bool selectLayer = false;
0021   bool selectPassive = false;
0022 
0023   /// VolumeSelector with options
0024   ///
0025   /// @param sMaterial is the directive to select material volumes
0026   /// @param sLayer is the directive to select volumes with layers
0027   /// @param sPassive is the directive to select passive volumes
0028   VolumeSelector(bool sMaterial = true, bool sLayer = false,
0029                  bool sPassive = false)
0030       : selectMaterial(sMaterial),
0031         selectLayer(sLayer),
0032         selectPassive(sPassive) {}
0033 
0034   /// Call operator to check if a volume should be selected
0035   ///
0036   /// @param volume is the test volume
0037   bool operator()(const Acts::TrackingVolume& volume) const {
0038     if (selectMaterial && volume.volumeMaterial() != nullptr) {
0039       return true;
0040     }
0041     if (selectLayer && volume.confinedLayers() != nullptr) {
0042       return true;
0043     }
0044     if (selectPassive) {
0045       return true;
0046     }
0047     return false;
0048   }
0049 };
0050 
0051 /// The information to be writtern out per hit volume
0052 struct VolumeHit {
0053   const TrackingVolume* volume = nullptr;
0054   Vector3 position;
0055   Vector3 direction;
0056 };
0057 
0058 /// A Volume Collector struct
0059 /// templated with a Selector type
0060 ///
0061 /// Whenever a volume is passed in the propagation
0062 /// that satisfies the selector, it is recorded
0063 /// for further usage in the flow.
0064 template <typename Selector = VolumeSelector>
0065 struct VolumeCollector {
0066   /// The selector used for this volume
0067   Selector selector;
0068 
0069   /// Simple result struct to be returned
0070   /// It has all the VolumeHit objects that
0071   /// are collected (and thus have been selected)
0072   struct this_result {
0073     std::vector<VolumeHit> collected;
0074   };
0075 
0076   using result_type = this_result;
0077 
0078   /// Collector action for the ActionList of the Propagator
0079   /// It checks if the propagator state has a current volume,
0080   /// in which case the action is performed:
0081   /// - it records the volume given the configuration
0082   ///
0083   /// @tparam propagator_state_t is the type of Propagator state
0084   /// @tparam stepper_t Type of the stepper used for the propagation
0085   /// @tparam navigator_t Type of the navigator used for the propagation
0086   ///
0087   /// @param [in,out] state is the mutable stepper state object
0088   /// @param [in] stepper The stepper in use
0089   /// @param [in] navigator The navigator in use
0090   /// @param [in,out] result is the mutable result object
0091   /// @param logger the logger object
0092   template <typename propagator_state_t, typename stepper_t,
0093             typename navigator_t>
0094   void act(propagator_state_t& state, const stepper_t& stepper,
0095            const navigator_t& navigator, result_type& result,
0096            const Logger& logger) const {
0097     auto currentVolume = navigator.currentVolume(state.navigation);
0098 
0099     // The current volume has been assigned by the navigator
0100     if (currentVolume && selector(*currentVolume)) {
0101       // Create for recording
0102       VolumeHit volume_hit;
0103       volume_hit.volume = currentVolume;
0104       volume_hit.position = stepper.position(state.stepping);
0105       volume_hit.direction = stepper.direction(state.stepping);
0106       bool save = true;
0107       // Check if the Volume ws already encountered
0108       for (auto const& res : result.collected) {
0109         if (res.volume == volume_hit.volume) {
0110           save = false;
0111           break;
0112         }
0113       }
0114       // Save if in the result if it does not already exist
0115       if (save) {
0116         result.collected.push_back(volume_hit);
0117         // Screen output
0118         ACTS_VERBOSE("Collect volume  " << currentVolume->geometryId());
0119       }
0120     }
0121   }
0122 };
0123 
0124 }  // namespace Acts