Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:45:45

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/Utilities/Histogram.hpp"
0010 
0011 #include <cassert>
0012 #include <vector>
0013 
0014 namespace Acts::Experimental {
0015 
0016 // Projection free functions
0017 Histogram1 projectionX(const Histogram2& hist2d) {
0018   auto projectedHist = boost::histogram::algorithm::project(
0019       hist2d.histogram(), std::integral_constant<unsigned, 0>{});
0020 
0021   // Extract single axis from projected histogram
0022   std::array<AxisVariant, 1> axes = {projectedHist.axis(0)};
0023 
0024   return Histogram1(hist2d.name() + "_projX", hist2d.title() + " projection X",
0025                     axes);
0026 }
0027 
0028 Histogram1 projectionY(const Histogram2& hist2d) {
0029   auto projectedHist = boost::histogram::algorithm::project(
0030       hist2d.histogram(), std::integral_constant<unsigned, 1>{});
0031 
0032   // Extract single axis from projected histogram
0033   std::array<AxisVariant, 1> axes = {projectedHist.axis(0)};
0034 
0035   return Histogram1(hist2d.name() + "_projY", hist2d.title() + " projection Y",
0036                     axes);
0037 }
0038 
0039 std::vector<double> extractBinEdges(const AxisVariant& axis) {
0040   assert(axis.size() > 0 && "Axis must have at least one bin");
0041   std::vector<double> edges(axis.size() + 1);
0042   for (int i = 0; i < axis.size(); ++i) {
0043     edges.at(i) = axis.bin(i).lower();
0044   }
0045   edges.back() = axis.bin(axis.size() - 1).upper();
0046 
0047   return edges;
0048 }
0049 
0050 }  // namespace Acts::Experimental