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