Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #define INCLXX_IN_GEANT4_MODE 1
34 
35 #include "globals.hh"
36 
37 #ifndef G4INCLClusteringModelIntercomparison_hh
38 #define G4INCLClusteringModelIntercomparison_hh 1
39 
40 #ifdef INCLXX_IN_GEANT4_MODE
41 #define INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set 1
42 #endif // INCLXX_IN_GEANT4_MODE
43 
45 #include "G4INCLParticle.hh"
46 #include "G4INCLParticleTable.hh"
47 #include "G4INCLCluster.hh"
48 #include "G4INCLNucleus.hh"
49 #include "G4INCLKinematicsUtils.hh"
50 #include "G4INCLHashing.hh"
51 
52 #include <set>
53 #include <algorithm>
54 
55 namespace G4INCL {
56 
57  /** \brief Container for the relevant information
58  *
59  * This struct contains all the information that is relevant for the
60  * clustering algorithm. It is probably more compact than the Particles it
61  * feeds on, hopefully improving cache performance.
62  */
71 
73  particle(NULL),
74  isTargetSpectator(false),
75  Z(0),
76  energy(0.),
77  potentialEnergy(0.)
78  {}
79 
81  particle(p),
83  Z(particle->getZ()),
84  position(particle->getPosition()),
85  momentum(particle->getMomentum()),
86  energy(particle->getEnergy()),
87  potentialEnergy(particle->getPotentialEnergy())
88  {}
89  };
90 
91  /// \brief Cluster coalescence algorithm used in the IAEA intercomparison
93  public:
94  ClusteringModelIntercomparison(Config const * const theConfig) :
95  theNucleus(NULL),
96  selectedA(0),
97  selectedZ(0),
98  sqtot(0.),
99  cascadingEnergyPool(0.),
100  protonMass(ParticleTable::getRealMass(Proton)),
101  neutronMass(ParticleTable::getRealMass(Neutron)),
102  runningMaxClusterAlgorithmMass(theConfig->getClusterMaxMass()),
103  nConsideredMax(0),
104  nConsidered(0),
105  consideredPartners(NULL),
106  isInRunningConfiguration(NULL),
107  maxMassConfigurationSkipping(ParticleTable::maxClusterMass)
108  {
109  // Set up the maximum charge and neutron number for clusters
110  clusterZMaxAll = 0;
111  clusterNMaxAll = 0;
112  for(G4int A=0; A<=runningMaxClusterAlgorithmMass; ++A) {
113  if(clusterZMax[A]>clusterZMaxAll)
114  clusterZMaxAll = clusterZMax[A];
115  if(A-clusterZMin[A]>clusterNMaxAll)
116  clusterNMaxAll = A-clusterZMin[A];
117  }
118  std::fill(candidateConfiguration,
119  candidateConfiguration + ParticleTable::maxClusterMass,
120  static_cast<Particle*>(NULL));
121 
122  std::fill(runningEnergies,
123  runningEnergies + ParticleTable::maxClusterMass,
124  0.0);
125 
126  std::fill(runningPotentials,
127  runningPotentials + ParticleTable::maxClusterMass,
128  0.0);
129 
130  std::fill(runningConfiguration,
131  runningConfiguration + ParticleTable::maxClusterMass,
132  -1);
133 
134  }
135 
137  delete [] consideredPartners;
138  delete [] isInRunningConfiguration;
139  }
140 
141  virtual Cluster* getCluster(Nucleus*, Particle*);
142  virtual G4bool clusterCanEscape(Nucleus const * const, Cluster const * const);
143 
144  private:
145  void findClusterStartingFrom(const G4int oldA, const G4int oldZ);
146  G4double getPhaseSpace(const G4int oldA, ConsideredPartner const &p);
147 
148  Nucleus *theNucleus;
149 
150  G4double runningEnergies[ParticleTable::maxClusterMass+1];
151  ThreeVector runningMomenta[ParticleTable::maxClusterMass+1];
152  ThreeVector runningPositions[ParticleTable::maxClusterMass+1];
153  G4double runningPotentials[ParticleTable::maxClusterMass+1];
154 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask)
155  Hashing::NucleonItem runningConfiguration[ParticleTable::maxClusterMass];
156 #elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set)
157  G4int runningConfiguration[ParticleTable::maxClusterMass];
158 #else
159 #error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask.
160 #endif
161 
162  G4int selectedA, selectedZ;
163  G4double sqtot;
164 
165  G4int clusterZMaxAll, clusterNMaxAll;
166 
167  G4double cascadingEnergyPool;
168 
169  /// \brief Lower limit of Z for cluster of mass A
170  static const G4int clusterZMin[ParticleTable::maxClusterMass+1];
171  /// \brief Upper limit of Z for cluster of mass A
172  static const G4int clusterZMax[ParticleTable::maxClusterMass+1];
173 
174  /// \brief Precomputed factor 1.0/A
175  static const G4double clusterPosFact[ParticleTable::maxClusterMass+1];
176 
177  /// \brief Precomputed factor (1.0/A)^2
178  static const G4double clusterPosFact2[ParticleTable::maxClusterMass+1];
179 
180  /// \brief Phase-space parameters for cluster formation
181  static const G4double clusterPhaseSpaceCut[ParticleTable::maxClusterMass+1];
182 
183  static const G4double limitCosEscapeAngle;
184 
185  const G4double protonMass;
186  const G4double neutronMass;
187 
188  G4int runningMaxClusterAlgorithmMass;
189 
190  G4int nConsideredMax;
191  G4int nConsidered;
192 
193  /** \brief Array of considered cluster partners
194  *
195  * A dynamical array of ConsideredPartner objects is allocated on this
196  * variable and filled with pointers to nucleons which are eligible for
197  * clustering. We used to use a ParticleList for this purpose, but this
198  * made it very cumbersome to check whether nucleons had already been
199  * included in the running configuration. Using an array of Particle*
200  * coupled with a boolean mask (\see{isInRunningConfiguration}) reduces the
201  * overhead by a large amount. Running times for 1-GeV p+Pb208 went down
202  * by almost 30% (!).
203  *
204  * Lesson learnt: when you need speed, nothing beats a good ol' array.
205  */
206  ConsideredPartner *consideredPartners;
207 
208  /** \brief Array of flags for nucleons in the running configuration
209  *
210  * Clustering partners that are already used in the running cluster
211  * configuration are flagged as "true" in this array.
212  */
213  G4bool *isInRunningConfiguration;
214 
215  /** \brief Best cluster configuration
216  *
217  * This array contains pointers to the nucleons which make up the best
218  * cluster configuration that has been found so far.
219  */
220  Particle *candidateConfiguration[ParticleTable::maxClusterMass];
221 
222 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask)
223  typedef std::set<Hashing::HashType> HashContainer;
224  typedef HashContainer::iterator HashIterator;
225 
226  /// \brief Array of containers for configurations that have already been checked
227  HashContainer checkedConfigurations[ParticleTable::maxClusterMass-2];
228 #elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set)
229  /** \brief Class for storing and comparing sorted nucleon configurations
230  *
231  * This class is actually just a wrapper around an array of Particle*
232  * pointers. It provides a lexicographical comparison operator
233  * (SortedNucleonConfiguration::operator<) for inclusion in std::set
234  * containers.
235  */
236  class SortedNucleonConfiguration {
237  public:
238  // Use Particle* as nucleon identifiers
239  typedef G4int NucleonItem;
240 
241  /// \brief Constructor
242  SortedNucleonConfiguration() : theSize(0), nucleons(NULL) {}
243 
244  /// \brief Copy constructor
245  SortedNucleonConfiguration(const SortedNucleonConfiguration &rhs) :
246  theSize(rhs.theSize),
247  nucleons(new NucleonItem[theSize])
248  {
249  std::copy(rhs.nucleons, rhs.nucleons+theSize, nucleons);
250  }
251 
252  /// \brief Destructor
253  ~SortedNucleonConfiguration() {
254  delete [] nucleons;
255  }
256 
257  /// \brief Helper method for the assignment operator
258  void swap(SortedNucleonConfiguration &rhs) {
259  std::swap(theSize, rhs.theSize);
260  std::swap(nucleons, rhs.nucleons);
261  }
262 
263  /// \brief Assignment operator
264  SortedNucleonConfiguration &operator=(const SortedNucleonConfiguration &rhs) {
265  SortedNucleonConfiguration tempConfig(rhs);
266  swap(tempConfig);
267  return *this;
268  }
269 
270  /** \brief Order operator for SortedNucleonConfiguration
271  *
272  * The comparison is done lexicographically (i.e. from the first
273  * element to the last).
274  */
275  G4bool operator<(const SortedNucleonConfiguration &rhs) const {
276 // assert(theSize==rhs.theSize);
277  return std::lexicographical_compare(nucleons, nucleons+theSize, rhs.nucleons, rhs.nucleons+theSize);
278  }
279 
280  /// \brief Fill configuration with array of NucleonItem
281  void fill(NucleonItem *config, size_t n) {
282  theSize = n;
283  nucleons = new NucleonItem[theSize];
284  std::copy(config, config+theSize, nucleons);
285  std::sort(nucleons, nucleons+theSize);
286  }
287 
288  private:
289  /// \brief Size of the array
290  size_t theSize;
291 
292  /// \brief The real array
293  NucleonItem *nucleons;
294  };
295 
296  typedef std::set<SortedNucleonConfiguration> SortedNucleonConfigurationContainer;
297  typedef SortedNucleonConfigurationContainer::iterator SortedNucleonConfigurationIterator;
298 
299  /// \brief Array of containers for configurations that have already been checked
300  SortedNucleonConfigurationContainer checkedConfigurations[ParticleTable::maxClusterMass-2];
301 #else
302 #error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask.
303 #endif
304 
305  /** \brief Maximum mass for configuration storage
306  *
307  * Skipping configurations becomes inefficient above this mass.
308  */
309  G4int maxMassConfigurationSkipping;
310  };
311 
312 }
313 
314 #endif
virtual G4bool clusterCanEscape(Nucleus const *const, Cluster const *const)
const char * p
Definition: xmltok.h:285
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
int G4int
Definition: G4Types.hh:78
void copy(std::vector< T > &main, const std::vector< T > &data)
Definition: DicomRun.hh:91
G4double getRealMass(const G4INCL::ParticleType t)
Get particle mass (in MeV/c^2)
bool G4bool
Definition: G4Types.hh:79
void swap(shared_ptr< P > &, shared_ptr< P > &)
Definition: memory.h:1247
const G4int n
Container for the relevant information.
virtual Cluster * getCluster(Nucleus *, Particle *)
bool operator<(const CexmcAngularRange &left, const CexmcAngularRange &right)
Functions for hashing a collection of NucleonItems.
Cluster coalescence algorithm used in the IAEA intercomparison.
double G4double
Definition: G4Types.hh:76