Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:18

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/Plugins/Detray/DetrayConversionUtils.hpp"
0010 
0011 detray::axis::label Acts::DetrayConversionUtils::convertAxisDirection(
0012     AxisDirection bValue) {
0013   switch (bValue) {
0014     case AxisDirection::AxisX:
0015       return detray::axis::label::e_x;
0016     case AxisDirection::AxisY:
0017       return detray::axis::label::e_y;
0018     case AxisDirection::AxisZ:
0019       return detray::axis::label::e_z;
0020     case AxisDirection::AxisR:
0021       return detray::axis::label::e_r;
0022     case AxisDirection::AxisPhi:
0023       return detray::axis::label::e_phi;
0024     case AxisDirection::AxisRPhi:
0025       return detray::axis::label::e_rphi;
0026     default:
0027       throw std::invalid_argument(
0028           "DetrayMaterialConverter: unknown binning value detected.");
0029   }
0030 }
0031 
0032 detray::axis::bounds Acts::DetrayConversionUtils::convertBinningOption(
0033     BinningOption bOption) {
0034   // That's a bit of a mind bender, but the conversion is correct
0035   // closed -> axis are closed, i.e. circular
0036   // open -> axis are not closed, but the range is closed (no overflow bin) ->
0037   // closed
0038   switch (bOption) {
0039     case BinningOption::closed:
0040       return detray::axis::bounds::e_circular;
0041     case BinningOption::open:
0042       return detray::axis::bounds::e_closed;
0043     default:
0044       throw std::invalid_argument(
0045           "DetrayMaterialConverter: unknown binning option detected.");
0046   }
0047 }
0048 
0049 detray::axis::binning Acts::DetrayConversionUtils::convertBinningType(
0050     BinningType bType) {
0051   switch (bType) {
0052     case BinningType::equidistant:
0053       return detray::axis::binning::e_regular;
0054     case BinningType::arbitrary:
0055       return detray::axis::binning::e_irregular;
0056     default:
0057       throw std::invalid_argument(
0058           "DetrayMaterialConverter: unknown binning type detected.");
0059   }
0060 }
0061 
0062 detray::io::axis_payload Acts::DetrayConversionUtils::convertBinningData(
0063     const BinningData& bData) {
0064   detray::io::axis_payload axis;
0065 
0066   axis.bins = bData.bins();
0067   // Set the binning type
0068   axis.binning = convertBinningType(bData.type);
0069   // Set the binning option
0070   axis.bounds = convertBinningOption(bData.option);
0071   // Set the binning value
0072   axis.label = convertAxisDirection(bData.binvalue);
0073   // Set the binning range
0074   axis.edges = {};
0075   if (bData.type == BinningType::equidistant) {
0076     axis.edges = {bData.min, bData.max};
0077   } else {
0078     axis.edges.insert(axis.edges.end(), bData.boundaries().begin(),
0079                       bData.boundaries().end());
0080   }
0081   return axis;
0082 }