BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSPSCellFlux4D.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#include "BDSPSCellFlux4D.hh"
19#include "BDSHistBinMapper.hh"
20
21#ifdef USE_BOOST
22#include <boost/variant.hpp>
23#endif
24
25#include <iostream>
26
27#include "G4String.hh"
28#include "G4Types.hh"
29
30BDSPSCellFlux4D::BDSPSCellFlux4D(const G4String& name,
31 const BDSHistBinMapper* mapperIn,
32 G4int ni, G4int nj, G4int nk,
33 G4int depi, G4int depj, G4int depk):
34 G4PSCellFlux3D(name,ni,nj,nk,depi,depj,depk),
35 fDepthi(depi),
36 fDepthj(depj),
37 fDepthk(depk),
38 mapper(mapperIn)
39{;}
40
41BDSPSCellFlux4D::BDSPSCellFlux4D(const G4String& name,
42 const BDSHistBinMapper* mapperIn,
43 const G4String& unit,
44 G4int ni, G4int nj, G4int nk,
45 G4int depi, G4int depj, G4int depk):
46 G4PSCellFlux3D(name, unit, ni, nj, nk, depi, depj, depk),
47 fDepthi(depi),
48 fDepthj(depj),
49 fDepthk(depk),
50 mapper(mapperIn)
51{;}
52
53G4int BDSPSCellFlux4D::GetIndex(G4Step* aStep)
54{
55 const G4VTouchable* touchable = aStep->GetPreStepPoint()->GetTouchable();
56
57 G4int i = touchable->GetReplicaNumber(fDepthi);
58 G4int j = touchable->GetReplicaNumber(fDepthj);
59 G4int k = touchable->GetReplicaNumber(fDepthk);
60
61#ifdef USE_BOOST
62 double energy = aStep->GetPostStepPoint()->GetKineticEnergy();
63 G4int l = boost::apply_visitor([&energy](auto&& one){return (decltype(one)(one))->index(energy);}, mapper->GetEnergyAxis()) + 1; // + 1 to get the index starting from 0 (the underflow bin has -1 as index)
64#else
65 G4int l = 0;
66#endif
67
68 if (i<0 || j<0 || k<0)
69 {
70 G4ExceptionDescription ED;
71 ED << "GetReplicaNumber is negative" << G4endl
72 << "touchable->GetReplicaNumber(fDepthi) returns i,j,k = "
73 << i << "," << j << "," << k << "," << l << " for volume "
74 << touchable->GetVolume(fDepthi)->GetName() << ","
75 << touchable->GetVolume(fDepthj)->GetName() << ","
76 << touchable->GetVolume(fDepthk)->GetName() << "," << G4endl;
77 G4Exception("PSRadiationQuantity3D::GetIndex","DetPS0006",JustWarning,ED);
78 }
79
80 G4int globalIndex = mapper->GlobalFromIJKLIndex(i, j, k, l); // x,y,z,e
81 return globalIndex;
82}
Mapping from axis indices to 1D index.