ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinAdjustment.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinAdjustment.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 // BinAdjustment.hpp, Acts project
12 
13 #pragma once
14 
15 #include <stdexcept>
16 
21 
22 namespace Acts {
23 
30 BinUtility adjustBinUtility(const BinUtility& bu, const RadialBounds& rBounds) {
31  // Default constructor
32  BinUtility uBinUtil;
33  // The parameters from the cylinder bounds
34  double minR = rBounds.get(RadialBounds::eMinR);
35  double maxR = rBounds.get(RadialBounds::eMaxR);
36  double minPhi = rBounds.get(RadialBounds::eAveragePhi) -
38  double maxPhi = rBounds.get(RadialBounds::eAveragePhi) +
40  // Retrieve the binning data
41  const std::vector<BinningData>& bData = bu.binningData();
42  // Loop over the binning data and adjust the dimensions
43  for (auto& bd : bData) {
44  // The binning value
45  BinningValue bval = bd.binvalue;
46  // Throw exceptions is stuff doesn't make sense:
47  // - not the right binning value
48  // - not equidistant
49  if (bd.type == arbitrary) {
50  throw std::invalid_argument("Arbirary binning can not be adjusted.");
51  } else if (bval != binR and bval != binPhi) {
52  throw std::invalid_argument("Disc binning must be: phi, r");
53  }
54  float min, max = 0.;
55  // Perform the value adjustment
56  if (bval == binPhi) {
57  min = minPhi;
58  max = maxPhi;
59  } else {
60  min = minR;
61  max = maxR;
62  }
63  // Create the updated BinningData
64  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
65  uBinUtil += BinUtility(uBinData);
66  }
67  return uBinUtil;
68 }
69 
77  const CylinderBounds& cBounds) {
78  // Default constructor
79  BinUtility uBinUtil;
80  // The parameters from the cylinder bounds
81  double cR = cBounds.get(CylinderBounds::eR);
82  double cHz = cBounds.get(CylinderBounds::eHalfLengthZ);
83  double avgPhi = cBounds.get(CylinderBounds::eAveragePhi);
84  double halfPhi = cBounds.get(CylinderBounds::eHalfPhiSector);
85  double minPhi = avgPhi - halfPhi;
86  double maxPhi = avgPhi + halfPhi;
87  ;
88  // Retrieve the binning data
89  const std::vector<BinningData>& bData = bu.binningData();
90  // Loop over the binning data and adjust the dimensions
91  for (auto& bd : bData) {
92  // The binning value
93  BinningValue bval = bd.binvalue;
94  // Throw exceptions if stuff doesn't make sense:
95  // - not the right binning value
96  // - not equidistant
97  if (bd.type == arbitrary) {
98  throw std::invalid_argument("Arbitrary binning can not be adjusted.");
99  } else if (bval != binRPhi and bval != binPhi and bval != binZ) {
100  throw std::invalid_argument("Cylinder binning must be: rphi, phi, z");
101  }
102  float min, max = 0.;
103  // Perform the value adjustment
104  if (bval == binPhi) {
105  min = minPhi;
106  max = maxPhi;
107  } else if (bval == binRPhi) {
108  min = cR * minPhi;
109  max = cR * maxPhi;
110  } else {
111  min = -cHz;
112  max = cHz;
113  }
114  // Create the updated BinningData
115  BinningData uBinData(bd.option, bval, bd.bins(), min, max);
116  uBinUtil += BinUtility(uBinData);
117  }
118  return uBinUtil;
119 }
120 
128  // The surface type is a cylinder
129  if (surface.type() == Surface::Cylinder) {
130  // Cast to Cylinder bounds and return
131  auto cBounds = dynamic_cast<const CylinderBounds*>(&(surface.bounds()));
132  // Return specific adjustment
133  return adjustBinUtility(bu, *cBounds);
134 
135  } else if (surface.type() == Surface::Disc) {
136  // Cast to Cylinder bounds and return
137  auto rBounds = dynamic_cast<const RadialBounds*>(&(surface.bounds()));
138  // Return specific adjustment
139  return adjustBinUtility(bu, *rBounds);
140  }
141 
142  throw std::invalid_argument(
143  "Bin adjustment not implemented for this surface yet!");
144 
145  return BinUtility();
146 }
147 
148 } // namespace Acts