BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSScoringMeshCylinder.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 "BDSDebug.hh"
19#include "BDSException.hh"
20#include "BDSHistBinMapper.hh"
21#include "BDSScoringMeshCylinder.hh"
22#include "BDSScorerMeshInfo.hh"
23
24#include "globals.hh"
25#include "G4RotationMatrix.hh"
26#include "G4Version.hh"
27
29 const BDSScorerMeshInfo& recipe,
30 const G4Transform3D& placementTransform):
31 BDSScoringMeshCylinder(name, placementTransform.getTranslation(), placementTransform.getRotation())
32{
33 // size of the scoring mesh
34#if G4VERSION_NUMBER < 1100
35 scorerSize[0] = recipe.rOuter; // RMax
36 if (recipe.rInner > 0)
37 {
38 G4String msg = "For Geant4 < v11.0, the cylindrical scoring mesh does not support rInner\n";
39 msg += "rInner: " + std::to_string(recipe.rInner) + " mm in mesh \"" + name +"\"";
40 throw BDSException(__METHOD_NAME__, msg);
41 }
42 scorerSize[1] = recipe.ScoringMeshZ(); // full z-length
43#else
44 scorerSize[0] = recipe.rInner;
45 scorerSize[1] = recipe.rOuter;
46 scorerSize[2] = recipe.ScoringMeshZ();
47#endif
48 SetSize(scorerSize);
49
50 // divisions of the scoring mesh
51 nSegment[0] = recipe.nBinsZ;
52 nSegment[1] = recipe.nBinsPhi;
53 nSegment[2] = recipe.nBinsR;
54 nEnergySegments = recipe.nBinsE;
55 SetNumberOfSegments(nSegment);
56
57#ifdef USE_BOOST
58 mapper = new BDSHistBinMapper(fNSegment[0], fNSegment[1], fNSegment[2], nEnergySegments, recipe.energyAxis);
59#else
60 mapper = new BDSHistBinMapper(fNSegment[0], fNSegment[1], fNSegment[2], nEnergySegments);
61#endif
62}
63
64
66 const G4ThreeVector& translation,
67 const G4RotationMatrix& rotation):
68 G4ScoringCylinder(name),
69 mapper(nullptr),
70 scorerSize{0,0,0},
71 nSegment{1,1,1},
72 nEnergySegments(0)
73{
74 fRotationMatrix = new G4RotationMatrix(rotation.inverse());
75 fCenterPosition = translation;
76}
77
78const BDSHistBinMapper* BDSScoringMeshCylinder::Mapper() const
79{
80 if (!sizeIsSet)
81 {throw BDSException(__METHOD_NAME__, "mesh \"" + fWorldName + "\" size not set but queried");}
82 if (!mapper)
83 {throw BDSException(__METHOD_NAME__, "mesh \"" + fWorldName + "\" mapper has mysteriously disappeared");}
84 return mapper;
85}
86
87BDSScoringMeshCylinder::~BDSScoringMeshCylinder()
88{
89 delete mapper;
90}
General exception with possible name of object and message.
Mapping from axis indices to 1D index.
Recipe class for a scoring mesh.
Wrapper for G4ScoringCylinder to allow full access to placement.
BDSScoringMeshCylinder(const G4String &name, const BDSScorerMeshInfo &recipe, const G4Transform3D &placementTransform)