Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4INCLClusteringModelIntercomparison.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// INCL++ intra-nuclear cascade model
27// Pekka Kaitaniemi, CEA and Helsinki Institute of Physics
28// Davide Mancusi, CEA
29// Alain Boudard, CEA
30// Sylvie Leray, CEA
31// Joseph Cugnon, University of Liege
32//
33// INCL++ revision: v5.1.8
34//
35#define INCLXX_IN_GEANT4_MODE 1
36
37#include "globals.hh"
38
39#ifndef G4INCLClusteringModelIntercomparison_hh
40#define G4INCLClusteringModelIntercomparison_hh 1
41
42#ifdef INCLXX_IN_GEANT4_MODE
43#define INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set 1
44#endif // INCLXX_IN_GEANT4_MODE
45
47#include "G4INCLParticle.hh"
49#include "G4INCLCluster.hh"
50#include "G4INCLNucleus.hh"
52#include "G4INCLHashing.hh"
53
54#include <set>
55#include <algorithm>
56
57namespace G4INCL {
58
59 /// \brief Cluster coalescence algorithm used in the IAEA intercomparison
61 public:
62 ClusteringModelIntercomparison(Config const * const theConfig) :
63 theNucleus(NULL),
64 selectedA(0),
65 selectedZ(0),
66 sqtot(0.),
67 cascadingEnergyPool(0.),
68 protonMass(ParticleTable::getRealMass(Proton)),
69 neutronMass(ParticleTable::getRealMass(Neutron)),
70 runningMaxClusterAlgorithmMass(theConfig->getClusterMaxMass()),
71 nConsideredMax(0),
72 nConsidered(0),
73 consideredPartners(NULL),
74 isInRunningConfiguration(NULL),
75 maxMassConfigurationSkipping(ParticleTable::maxClusterMass)
76 {
77 // Set up the maximum charge and neutron number for clusters
78 clusterZMaxAll = 0;
79 clusterNMaxAll = 0;
80 for(G4int A=0; A<=runningMaxClusterAlgorithmMass; ++A) {
81 if(ParticleTable::clusterZMax[A]>clusterZMaxAll)
82 clusterZMaxAll = ParticleTable::clusterZMax[A];
83 if(A-ParticleTable::clusterZMin[A]>clusterNMaxAll)
84 clusterNMaxAll = A-ParticleTable::clusterZMin[A];
85 }
86 std::fill(candidateConfiguration,
87 candidateConfiguration + ParticleTable::maxClusterMass,
88 static_cast<Particle*>(NULL));
89
90 std::fill(runningEnergies,
91 runningEnergies + ParticleTable::maxClusterMass,
92 0.0);
93
94 std::fill(runningPotentials,
95 runningPotentials + ParticleTable::maxClusterMass,
96 0.0);
97
98 std::fill(runningConfiguration,
99 runningConfiguration + ParticleTable::maxClusterMass,
100 -1);
101
102 }
103
105 delete [] consideredPartners;
106 delete [] isInRunningConfiguration;
107 }
108
109 virtual Cluster* getCluster(Nucleus*, Particle*);
110 virtual G4bool clusterCanEscape(Nucleus const * const, Cluster const * const);
111
112 private:
113 void findClusterStartingFrom(const G4int oldA, const G4int oldZ);
114 G4double getPhaseSpace(const G4int oldA, Particle const * const p);
115
116 Nucleus *theNucleus;
117
118 G4double runningEnergies[ParticleTable::maxClusterMass+1];
120 ThreeVector runningPositions[ParticleTable::maxClusterMass+1];
121 G4double runningPotentials[ParticleTable::maxClusterMass+1];
122#if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask)
123 Hashing::NucleonItem runningConfiguration[ParticleTable::maxClusterMass];
124#elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set)
125 G4int runningConfiguration[ParticleTable::maxClusterMass];
126#else
127#error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask.
128#endif
129
130 G4int selectedA, selectedZ;
131 G4double sqtot;
132
133 G4int clusterZMaxAll, clusterNMaxAll;
134
135 G4double cascadingEnergyPool;
136
137 static const G4double limitCosEscapeAngle;
138
139 const G4double protonMass;
140 const G4double neutronMass;
141
142 G4int runningMaxClusterAlgorithmMass;
143
144 G4int nConsideredMax;
145 G4int nConsidered;
146
147 /** \brief Array of considered cluster partners
148 *
149 * A dynamical array of Particle* is allocated on this variable and filled
150 * with pointers to nucleons which are eligible for clustering. We used to
151 * use a ParticleList for this purpose, but this made it very cumbersome to
152 * check whether nucleons had already been included in the running
153 * configuration. Using an array of Particle* coupled with a boolean mask
154 * (\see{isInRunningConfiguration}) reduces the overhead by a large amount.
155 * Running times for 1-GeV p+Pb208 went down by almost 30% (!).
156 *
157 * Lesson learnt: when you need speed, nothing beats a good ol' array.
158 */
159 Particle **consideredPartners;
160
161 /** \brief Array of flags for nucleons in the running configuration
162 *
163 * Clustering partners that are already used in the running cluster
164 * configuration are flagged as "true" in this array.
165 */
166 G4bool *isInRunningConfiguration;
167
168 /** \brief Best cluster configuration
169 *
170 * This array contains pointers to the nucleons which make up the best
171 * cluster configuration that has been found so far.
172 */
173 Particle *candidateConfiguration[ParticleTable::maxClusterMass];
174
175#if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask)
176 typedef std::set<Hashing::HashType> HashContainer;
177 typedef HashContainer::iterator HashIterator;
178
179 /// \brief Array of containers for configurations that have already been checked
180 HashContainer checkedConfigurations[ParticleTable::maxClusterMass-2];
181#elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set)
182 /** \brief Class for storing and comparing sorted nucleon configurations
183 *
184 * This class is actually just a wrapper around an array of Particle*
185 * pointers. It provides a lexicographical comparison operator
186 * (SortedNucleonConfiguration::operator<) for inclusion in std::set
187 * containers.
188 */
189 class SortedNucleonConfiguration {
190 public:
191 // Use Particle* as nucleon identifiers
192 typedef G4int NucleonItem;
193
194 /// \brief Constructor
195 SortedNucleonConfiguration() : theSize(0), nucleons(NULL) {}
196
197 /// \brief Copy constructor
198 SortedNucleonConfiguration(const SortedNucleonConfiguration &rhs) :
199 theSize(rhs.theSize),
200 nucleons(new NucleonItem[theSize])
201 {
202 std::copy(rhs.nucleons, rhs.nucleons+theSize, nucleons);
203 }
204
205 /// \brief Destructor
206 ~SortedNucleonConfiguration() {
207 delete [] nucleons;
208 }
209
210 /// \brief Helper method for the assignment operator
211 void swap(SortedNucleonConfiguration &rhs) {
212 std::swap(theSize, rhs.theSize);
213 std::swap(nucleons, rhs.nucleons);
214 }
215
216 /// \brief Assignment operator
217 SortedNucleonConfiguration &operator=(const SortedNucleonConfiguration &rhs) {
218 SortedNucleonConfiguration tempConfig(rhs);
219 swap(tempConfig);
220 return *this;
221 }
222
223 /** \brief Order operator for SortedNucleonConfiguration
224 *
225 * The comparison is done lexicographically (i.e. from the first
226 * element to the last).
227 */
228 G4bool operator<(const SortedNucleonConfiguration &rhs) const {
229// assert(theSize==rhs.theSize);
230 return std::lexicographical_compare(nucleons, nucleons+theSize, rhs.nucleons, rhs.nucleons+theSize);
231 }
232
233 /// \brief Fill configuration with array of NucleonItem
234 void fill(NucleonItem *config, size_t n) {
235 theSize = n;
236 nucleons = new NucleonItem[theSize];
237 std::copy(config, config+theSize, nucleons);
238 std::sort(nucleons, nucleons+theSize);
239 }
240
241 private:
242 /// \brief Size of the array
243 size_t theSize;
244
245 /// \brief The real array
246 NucleonItem *nucleons;
247 };
248
249 typedef std::set<SortedNucleonConfiguration> SortedNucleonConfigurationContainer;
250 typedef SortedNucleonConfigurationContainer::iterator SortedNucleonConfigurationIterator;
251
252 /// \brief Array of containers for configurations that have already been checked
253 SortedNucleonConfigurationContainer checkedConfigurations[ParticleTable::maxClusterMass-2];
254#else
255#error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask.
256#endif
257
258 /** \brief Maximum mass for configuration storage
259 *
260 * Skipping configurations becomes inefficient above this mass.
261 */
262 G4int maxMassConfigurationSkipping;
263 };
264
265}
266
267#endif
Functions for hashing a collection of NucleonItems.
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
Cluster coalescence algorithm used in the IAEA intercomparison.
virtual G4bool clusterCanEscape(Nucleus const *const, Cluster const *const)
virtual Cluster * getCluster(Nucleus *, Particle *)
static const G4int clusterZMin[maxClusterMass+1]
static const G4int clusterZMax[maxClusterMass+1]
static const G4int maxClusterMass
bool operator<(shared_ctrl_handle const &lhs, shared_ctrl_handle const &rhs)
Definition: memory.h:588
void swap(shared_ptr< P > &, shared_ptr< P > &)
Definition: memory.h:1247