BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSRegion.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 "BDSGlobalConstants.hh"
20#include "BDSRegion.hh"
21#include "BDSUtilities.hh"
22
23#include "parser/region.h"
24
25#include "globals.hh"
26#include "G4ProductionCuts.hh"
27#include "G4Region.hh"
28
29#include <ostream>
30
31BDSRegion::BDSRegion(G4String nameIn):
32 name(nameIn),
33 g4cuts(nullptr),
34 g4region(nullptr)
35{
36 // these are the defaults according to BDSIM, but no necessarily the defaults
37 // according to the physics list used - ie if a Geant4 reference physics list
38 // is used with default
40 defaultRangeCut = g->DefaultRangeCut();
41 if (g->DefaultRangeCutsSet())
42 {
43 rangeCutElectrons = g->ProdCutElectronsSet() ? g->ProdCutElectrons() : defaultRangeCut;
44 rangeCutPositrons = g->ProdCutPositronsSet() ? g->ProdCutPositrons() : defaultRangeCut;
45 rangeCutProtons = g->ProdCutProtonsSet() ? g->ProdCutProtons() : defaultRangeCut;
46 rangeCutPhotons = g->ProdCutPhotonsSet() ? g->ProdCutPhotons() : defaultRangeCut;
47 }
48 else
49 {
50 rangeCutElectrons = g->ProdCutElectrons();
51 rangeCutPositrons = g->ProdCutPositrons();
52 rangeCutProtons = g->ProdCutProtons();
53 rangeCutPhotons = g->ProdCutPhotons();
54 }
55 ProduceG4Region();
56}
57
58BDSRegion::BDSRegion(G4String nameIn,
59 const BDSRegion* defaultValue,
60 G4double defaultRangeCutIn,
61 G4double rangeCutElectronsIn,
62 G4double rangeCutPositronsIn,
63 G4double rangeCutProtonsIn,
64 G4double rangeCutPhotonsIn):
65 name(nameIn),
66 g4cuts(nullptr),
67 g4region(nullptr)
68{
69 // if the G4dobule defaultRangeCutIn is supplied, then this takes precedence over
70 // using any values from const BDSRegion* defaultValue
71 G4bool useSuppliedDefaultNumber = BDS::IsFinite(defaultRangeCutIn);
72 defaultRangeCut = BDS::IsFinite(defaultRangeCutIn) ? defaultRangeCutIn : defaultValue->defaultRangeCut;
73 rangeCutElectrons = BDS::IsFinite(rangeCutElectronsIn) ? rangeCutElectronsIn : (useSuppliedDefaultNumber ? defaultRangeCutIn : defaultValue->rangeCutElectrons);
74 rangeCutPositrons = BDS::IsFinite(rangeCutPositronsIn) ? rangeCutPositronsIn : (useSuppliedDefaultNumber ? defaultRangeCutIn : defaultValue->rangeCutPositrons);
75 rangeCutProtons = BDS::IsFinite(rangeCutProtonsIn) ? rangeCutProtonsIn : (useSuppliedDefaultNumber ? defaultRangeCutIn : defaultValue->rangeCutProtons);
76 rangeCutPhotons = BDS::IsFinite(rangeCutPhotonsIn) ? rangeCutPhotonsIn : (useSuppliedDefaultNumber ? defaultRangeCutIn : defaultValue->rangeCutPhotons);
77 ProduceG4Region();
78}
79
80BDSRegion::BDSRegion(const GMAD::Region& parserRegion,
81 const BDSRegion* defaultRegion):
82 BDSRegion(G4String(parserRegion.name),
83 defaultRegion,
84 parserRegion.defaultRangeCut * CLHEP::m,
85 parserRegion.prodCutElectrons * CLHEP::m,
86 parserRegion.prodCutPositrons * CLHEP::m,
87 parserRegion.prodCutProtons * CLHEP::m,
88 parserRegion.prodCutPhotons * CLHEP::m)
89{;}
90
91BDSRegion::~BDSRegion()
92{
93 delete g4cuts;
94 delete g4region;
95}
96
97std::ostream& operator<< (std::ostream& out, BDSRegion const &r)
98{
99 out << "Region \"" << r.name << "\"" << G4endl;
100 out << "default range cut " << r.defaultRangeCut << " mm" << G4endl;
101 out << "e- range cut " << r.rangeCutElectrons << " mm" << G4endl;
102 out << "e+ range cut " << r.rangeCutPositrons << " mm" << G4endl;
103 out << "proton range cut " << r.rangeCutProtons << " mm" << G4endl;
104 out << "photon range cut " << r.rangeCutPhotons << " mm" << G4endl;
105 return out;
106}
107
109{
110 g4cuts = new G4ProductionCuts();
111 g4cuts->SetProductionCut(rangeCutElectrons, "e-");
112 g4cuts->SetProductionCut(rangeCutPositrons, "e+");
113 g4cuts->SetProductionCut(rangeCutProtons, "proton");
114 g4cuts->SetProductionCut(rangeCutPhotons, "gamma");
115
116 g4region = new G4Region(name);
117 g4region->SetProductionCuts(g4cuts);
118}
119
A class that holds global options and constants.
static BDSGlobalConstants * Instance()
Access method.
Range cuts for a region. Help with defaults.
Definition: BDSRegion.hh:41
G4Region * g4region
Public members for simplicity.
Definition: BDSRegion.hh:64
G4double rangeCutElectrons
Public members for simplicity.
Definition: BDSRegion.hh:59
G4double defaultRangeCut
Public members for simplicity.
Definition: BDSRegion.hh:58
G4ProductionCuts * g4cuts
Public members for simplicity.
Definition: BDSRegion.hh:63
G4String name
Public members for simplicity.
Definition: BDSRegion.hh:57
G4double rangeCutPhotons
Public members for simplicity.
Definition: BDSRegion.hh:62
G4double rangeCutProtons
Public members for simplicity.
Definition: BDSRegion.hh:61
G4double rangeCutPositrons
Public members for simplicity.
Definition: BDSRegion.hh:60
void ProduceG4Region()
Function to create cuts and region.
Definition: BDSRegion.cc:108
Region class for parser.
Definition: region.h:36
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())