BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSHistBinMapper.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "BDSHistBinMapper.hh"
21
22BDSHistBinMapper::BDSHistBinMapper(G4int nBinsIIn, G4int nBinsJIn, G4int nBinsKIn, G4int nBinsLIn) :
23 nBinsI(nBinsIIn),
24 nBinsJ(nBinsJIn),
25 nBinsK(nBinsKIn),
26 nBinsL(nBinsLIn){
27}
28
29#ifdef USE_BOOST
30BDSHistBinMapper::BDSHistBinMapper(G4int nBinsIIn, G4int nBinsJIn, G4int nBinsKIn, G4int nBinsLIn,
31 boost_histogram_axes_variant energyAxisIn) : nBinsI(nBinsIIn),
32 nBinsJ(nBinsJIn),
33 nBinsK(nBinsKIn),
34 nBinsL(nBinsLIn),
35 energyAxis(energyAxisIn) {
36 if (nBinsL != 1) // it means we are in the 4D case
37 {
38 nBinsL += 2; // + 2 to take into account in the mapping the two under and overflow bins
39 }
40}
41#endif
42
43G4int BDSHistBinMapper::GlobalFromIJKLIndex(G4int iIndex,
44 G4int jIndex,
45 G4int kIndex,
46 G4int lIndex) const
47{
48 return iIndex * nBinsJ * nBinsK * nBinsL + jIndex * nBinsK * nBinsL + kIndex * nBinsL + lIndex;
49}
50
51void BDSHistBinMapper::IJKLFromGlobal(G4int globalBin,
52 G4int &iIndex,
53 G4int &jIndex,
54 G4int &kIndex,
55 G4int &lIndex) const
56{
57 iIndex = globalBin / (nBinsL * nBinsK * nBinsJ);
58 jIndex = (globalBin - iIndex*nBinsL * nBinsK * nBinsJ) / (nBinsL * nBinsK);
59 kIndex = (globalBin - jIndex*nBinsL * nBinsK - iIndex * nBinsL * nBinsK * nBinsJ) / nBinsL;
60 lIndex = globalBin - kIndex*nBinsL - jIndex * nBinsL * nBinsK - iIndex*nBinsL * nBinsK * nBinsJ;
61}