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