Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // INCL++ intra-nuclear cascade model 26 // INCL++ intra-nuclear cascade model 27 // Alain Boudard, CEA-Saclay, France << 27 // Pekka Kaitaniemi, CEA and Helsinki Institute of Physics 28 // Joseph Cugnon, University of Liege, Belgium << 28 // Davide Mancusi, CEA 29 // Jean-Christophe David, CEA-Saclay, France << 29 // Alain Boudard, CEA 30 // Pekka Kaitaniemi, CEA-Saclay, France, and H << 30 // Sylvie Leray, CEA 31 // Sylvie Leray, CEA-Saclay, France << 31 // Joseph Cugnon, University of Liege 32 // Davide Mancusi, CEA-Saclay, France << 32 // >> 33 // INCL++ revision: v5.1.8 33 // 34 // 34 #define INCLXX_IN_GEANT4_MODE 1 35 #define INCLXX_IN_GEANT4_MODE 1 35 36 36 #include "globals.hh" 37 #include "globals.hh" 37 38 38 #ifndef G4INCLClusteringModelIntercomparison_h 39 #ifndef G4INCLClusteringModelIntercomparison_hh 39 #define G4INCLClusteringModelIntercomparison_h 40 #define G4INCLClusteringModelIntercomparison_hh 1 40 41 41 #ifdef INCLXX_IN_GEANT4_MODE 42 #ifdef INCLXX_IN_GEANT4_MODE 42 #define INCL_CACHING_CLUSTERING_MODEL_INTERCOM 43 #define INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set 1 43 #endif // INCLXX_IN_GEANT4_MODE 44 #endif // INCLXX_IN_GEANT4_MODE 44 45 45 #include "G4INCLIClusteringModel.hh" 46 #include "G4INCLIClusteringModel.hh" 46 #include "G4INCLParticle.hh" 47 #include "G4INCLParticle.hh" 47 #include "G4INCLParticleTable.hh" 48 #include "G4INCLParticleTable.hh" 48 #include "G4INCLCluster.hh" 49 #include "G4INCLCluster.hh" 49 #include "G4INCLNucleus.hh" 50 #include "G4INCLNucleus.hh" 50 #include "G4INCLKinematicsUtils.hh" 51 #include "G4INCLKinematicsUtils.hh" 51 #include "G4INCLHashing.hh" 52 #include "G4INCLHashing.hh" 52 53 53 #include <set> 54 #include <set> 54 #include <algorithm> 55 #include <algorithm> 55 56 56 namespace G4INCL { 57 namespace G4INCL { 57 58 58 /** \brief Container for the relevant inform << 59 * << 60 * This struct contains all the information << 61 * clustering algorithm. It is probably more << 62 * feeds on, hopefully improving cache perfo << 63 */ << 64 struct ConsideredPartner { << 65 Particle *particle; << 66 G4bool isTargetSpectator; << 67 G4int Z; << 68 G4int S; << 69 ThreeVector position; << 70 ThreeVector momentum; << 71 G4double energy; << 72 G4double potentialEnergy; << 73 << 74 ConsideredPartner() : << 75 particle(NULL), << 76 isTargetSpectator(false), << 77 Z(0), << 78 S(0), << 79 energy(0.), << 80 potentialEnergy(0.) << 81 {} << 82 << 83 ConsideredPartner(Particle * const p) : << 84 particle(p), << 85 isTargetSpectator(particle->isTargetSpec << 86 Z(particle->getZ()), << 87 S(particle->getS()), << 88 position(particle->getPosition()), << 89 momentum(particle->getMomentum()), << 90 energy(particle->getEnergy()), << 91 potentialEnergy(particle->getPotentialEn << 92 {} << 93 }; << 94 << 95 /// \brief Cluster coalescence algorithm use 59 /// \brief Cluster coalescence algorithm used in the IAEA intercomparison 96 class ClusteringModelIntercomparison : publi 60 class ClusteringModelIntercomparison : public IClusteringModel { 97 public: 61 public: 98 ClusteringModelIntercomparison(Config cons 62 ClusteringModelIntercomparison(Config const * const theConfig) : 99 theNucleus(NULL), 63 theNucleus(NULL), 100 selectedA(0), 64 selectedA(0), 101 selectedZ(0), 65 selectedZ(0), 102 selectedS(0), << 103 sqtot(0.), 66 sqtot(0.), 104 cascadingEnergyPool(0.), 67 cascadingEnergyPool(0.), 105 protonMass(ParticleTable::getRealMass(Pr 68 protonMass(ParticleTable::getRealMass(Proton)), 106 neutronMass(ParticleTable::getRealMass(N 69 neutronMass(ParticleTable::getRealMass(Neutron)), 107 lambdaMass(ParticleTable::getRealMass(La << 108 runningMaxClusterAlgorithmMass(theConfig 70 runningMaxClusterAlgorithmMass(theConfig->getClusterMaxMass()), 109 nConsideredMax(0), 71 nConsideredMax(0), 110 nConsidered(0), 72 nConsidered(0), 111 consideredPartners(NULL), 73 consideredPartners(NULL), 112 isInRunningConfiguration(NULL), 74 isInRunningConfiguration(NULL), 113 maxMassConfigurationSkipping(ParticleTab 75 maxMassConfigurationSkipping(ParticleTable::maxClusterMass) 114 { 76 { 115 // Set up the maximum charge and neutron 77 // Set up the maximum charge and neutron number for clusters 116 clusterZMaxAll = 0; 78 clusterZMaxAll = 0; 117 clusterNMaxAll = 0; 79 clusterNMaxAll = 0; 118 for(G4int A=0; A<=runningMaxClusterAlgor 80 for(G4int A=0; A<=runningMaxClusterAlgorithmMass; ++A) { 119 if(clusterZMax[A]>clusterZMaxAll) << 81 if(ParticleTable::clusterZMax[A]>clusterZMaxAll) 120 clusterZMaxAll = clusterZMax[A]; << 82 clusterZMaxAll = ParticleTable::clusterZMax[A]; 121 if(A-clusterZMin[A]>clusterNMaxAll) << 83 if(A-ParticleTable::clusterZMin[A]>clusterNMaxAll) 122 clusterNMaxAll = A-clusterZMin[A]; << 84 clusterNMaxAll = A-ParticleTable::clusterZMin[A]; 123 } 85 } 124 std::fill(candidateConfiguration, 86 std::fill(candidateConfiguration, 125 candidateConfiguration + Parti 87 candidateConfiguration + ParticleTable::maxClusterMass, 126 static_cast<Particle*>(NULL)); 88 static_cast<Particle*>(NULL)); 127 89 128 std::fill(runningEnergies, 90 std::fill(runningEnergies, 129 runningEnergies + ParticleTabl 91 runningEnergies + ParticleTable::maxClusterMass, 130 0.0); 92 0.0); 131 93 132 std::fill(runningPotentials, 94 std::fill(runningPotentials, 133 runningPotentials + ParticleTa 95 runningPotentials + ParticleTable::maxClusterMass, 134 0.0); 96 0.0); 135 97 136 std::fill(runningConfiguration, 98 std::fill(runningConfiguration, 137 runningConfiguration + Particl 99 runningConfiguration + ParticleTable::maxClusterMass, 138 -1); 100 -1); 139 101 140 } 102 } 141 103 142 virtual ~ClusteringModelIntercomparison() 104 virtual ~ClusteringModelIntercomparison() { 143 delete [] consideredPartners; 105 delete [] consideredPartners; 144 delete [] isInRunningConfiguration; 106 delete [] isInRunningConfiguration; 145 } 107 } 146 108 147 virtual Cluster* getCluster(Nucleus*, Part 109 virtual Cluster* getCluster(Nucleus*, Particle*); 148 virtual G4bool clusterCanEscape(Nucleus co 110 virtual G4bool clusterCanEscape(Nucleus const * const, Cluster const * const); 149 111 150 private: 112 private: 151 void findClusterStartingFrom(const G4int o << 113 void findClusterStartingFrom(const G4int oldA, const G4int oldZ); 152 G4double getPhaseSpace(const G4int oldA, C << 114 G4double getPhaseSpace(const G4int oldA, Particle const * const p); 153 115 154 Nucleus *theNucleus; 116 Nucleus *theNucleus; 155 117 156 G4double runningEnergies[ParticleTable::ma 118 G4double runningEnergies[ParticleTable::maxClusterMass+1]; 157 ThreeVector runningMomenta[ParticleTable:: 119 ThreeVector runningMomenta[ParticleTable::maxClusterMass+1]; 158 ThreeVector runningPositions[ParticleTable 120 ThreeVector runningPositions[ParticleTable::maxClusterMass+1]; 159 G4double runningPotentials[ParticleTable:: 121 G4double runningPotentials[ParticleTable::maxClusterMass+1]; 160 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTE 122 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask) 161 Hashing::NucleonItem runningConfiguration[ 123 Hashing::NucleonItem runningConfiguration[ParticleTable::maxClusterMass]; 162 #elif defined(INCL_CACHING_CLUSTERING_MODEL_IN << 124 #elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set) 163 G4int runningConfiguration[ParticleTable:: 125 G4int runningConfiguration[ParticleTable::maxClusterMass]; 164 #else 126 #else 165 #error Unrecognized INCL_CACHING_CLUSTERING_MO << 127 #error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask. 166 #endif 128 #endif 167 129 168 G4int selectedA, selectedZ, selectedS; << 130 G4int selectedA, selectedZ; 169 G4double sqtot; 131 G4double sqtot; 170 132 171 G4int clusterZMaxAll, clusterNMaxAll; 133 G4int clusterZMaxAll, clusterNMaxAll; 172 134 173 G4double cascadingEnergyPool; 135 G4double cascadingEnergyPool; 174 136 175 /// \brief Lower limit of Z for cluster of << 176 static const G4int clusterZMin[ParticleTab << 177 /// \brief Upper limit of Z for cluster of << 178 static const G4int clusterZMax[ParticleTab << 179 << 180 /// \brief Precomputed factor 1.0/A << 181 static const G4double clusterPosFact[Parti << 182 << 183 /// \brief Precomputed factor (1.0/A)^2 << 184 static const G4double clusterPosFact2[Part << 185 << 186 /// \brief Phase-space parameters for clus << 187 static const G4double clusterPhaseSpaceCut << 188 << 189 static const G4double limitCosEscapeAngle; 137 static const G4double limitCosEscapeAngle; 190 138 191 const G4double protonMass; 139 const G4double protonMass; 192 const G4double neutronMass; 140 const G4double neutronMass; 193 const G4double lambdaMass; << 194 141 195 G4int runningMaxClusterAlgorithmMass; 142 G4int runningMaxClusterAlgorithmMass; 196 143 197 G4int nConsideredMax; 144 G4int nConsideredMax; 198 G4int nConsidered; 145 G4int nConsidered; 199 146 200 /** \brief Array of considered cluster par 147 /** \brief Array of considered cluster partners 201 * 148 * 202 * A dynamical array of ConsideredPartner << 149 * A dynamical array of Particle* is allocated on this variable and filled 203 * variable and filled with pointers to nu << 150 * with pointers to nucleons which are eligible for clustering. We used to 204 * clustering. We used to use a ParticleLi << 151 * use a ParticleList for this purpose, but this made it very cumbersome to 205 * made it very cumbersome to check whethe << 152 * check whether nucleons had already been included in the running 206 * included in the running configuration. << 153 * configuration. Using an array of Particle* coupled with a boolean mask 207 * coupled with a boolean mask (\see{isInR << 154 * (\see{isInRunningConfiguration}) reduces the overhead by a large amount. 208 * overhead by a large amount. Running ti << 155 * Running times for 1-GeV p+Pb208 went down by almost 30% (!). 209 * by almost 30% (!). << 210 * 156 * 211 * Lesson learnt: when you need speed, not 157 * Lesson learnt: when you need speed, nothing beats a good ol' array. 212 */ 158 */ 213 ConsideredPartner *consideredPartners; << 159 Particle **consideredPartners; 214 160 215 /** \brief Array of flags for nucleons in 161 /** \brief Array of flags for nucleons in the running configuration 216 * 162 * 217 * Clustering partners that are already us 163 * Clustering partners that are already used in the running cluster 218 * configuration are flagged as "true" in 164 * configuration are flagged as "true" in this array. 219 */ 165 */ 220 G4bool *isInRunningConfiguration; 166 G4bool *isInRunningConfiguration; 221 167 222 /** \brief Best cluster configuration 168 /** \brief Best cluster configuration 223 * 169 * 224 * This array contains pointers to the nuc 170 * This array contains pointers to the nucleons which make up the best 225 * cluster configuration that has been fou 171 * cluster configuration that has been found so far. 226 */ 172 */ 227 Particle *candidateConfiguration[ParticleT 173 Particle *candidateConfiguration[ParticleTable::maxClusterMass]; 228 174 229 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTE 175 #if defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_HashMask) 230 typedef std::set<Hashing::HashType> HashCo 176 typedef std::set<Hashing::HashType> HashContainer; 231 typedef HashContainer::iterator HashIterat 177 typedef HashContainer::iterator HashIterator; 232 178 233 /// \brief Array of containers for configu 179 /// \brief Array of containers for configurations that have already been checked 234 HashContainer checkedConfigurations[Partic 180 HashContainer checkedConfigurations[ParticleTable::maxClusterMass-2]; 235 #elif defined(INCL_CACHING_CLUSTERING_MODEL_IN 181 #elif defined(INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON_Set) 236 /** \brief Class for storing and comparing 182 /** \brief Class for storing and comparing sorted nucleon configurations 237 * 183 * 238 * This class is actually just a wrapper a 184 * This class is actually just a wrapper around an array of Particle* 239 * pointers. It provides a lexicographical 185 * pointers. It provides a lexicographical comparison operator 240 * (SortedNucleonConfiguration::operator<) 186 * (SortedNucleonConfiguration::operator<) for inclusion in std::set 241 * containers. 187 * containers. 242 */ 188 */ 243 class SortedNucleonConfiguration { 189 class SortedNucleonConfiguration { 244 public: 190 public: 245 // Use Particle* as nucleon identifier 191 // Use Particle* as nucleon identifiers 246 typedef G4int NucleonItem; 192 typedef G4int NucleonItem; 247 193 248 /// \brief Constructor 194 /// \brief Constructor 249 SortedNucleonConfiguration() : theSize 195 SortedNucleonConfiguration() : theSize(0), nucleons(NULL) {} 250 196 251 /// \brief Copy constructor 197 /// \brief Copy constructor 252 SortedNucleonConfiguration(const Sorte 198 SortedNucleonConfiguration(const SortedNucleonConfiguration &rhs) : 253 theSize(rhs.theSize), 199 theSize(rhs.theSize), 254 nucleons(new NucleonItem[theSize]) 200 nucleons(new NucleonItem[theSize]) 255 { 201 { 256 std::copy(rhs.nucleons, rhs.nucleons+t 202 std::copy(rhs.nucleons, rhs.nucleons+theSize, nucleons); 257 } 203 } 258 204 259 /// \brief Destructor 205 /// \brief Destructor 260 ~SortedNucleonConfiguration() { 206 ~SortedNucleonConfiguration() { 261 delete [] nucleons; 207 delete [] nucleons; 262 } 208 } 263 209 264 /// \brief Helper method for the assig 210 /// \brief Helper method for the assignment operator 265 void swap(SortedNucleonConfiguration & 211 void swap(SortedNucleonConfiguration &rhs) { 266 std::swap(theSize, rhs.theSize); 212 std::swap(theSize, rhs.theSize); 267 std::swap(nucleons, rhs.nucleons); 213 std::swap(nucleons, rhs.nucleons); 268 } 214 } 269 215 270 /// \brief Assignment operator 216 /// \brief Assignment operator 271 SortedNucleonConfiguration &operator=( 217 SortedNucleonConfiguration &operator=(const SortedNucleonConfiguration &rhs) { 272 SortedNucleonConfiguration tempConfi 218 SortedNucleonConfiguration tempConfig(rhs); 273 swap(tempConfig); 219 swap(tempConfig); 274 return *this; 220 return *this; 275 } 221 } 276 222 277 /** \brief Order operator for SortedNu 223 /** \brief Order operator for SortedNucleonConfiguration 278 * 224 * 279 * The comparison is done lexicographi 225 * The comparison is done lexicographically (i.e. from the first 280 * element to the last). 226 * element to the last). 281 */ 227 */ 282 G4bool operator<(const SortedNucleonCo 228 G4bool operator<(const SortedNucleonConfiguration &rhs) const { 283 // assert(theSize==rhs.theSize); 229 // assert(theSize==rhs.theSize); 284 return std::lexicographical_compare( 230 return std::lexicographical_compare(nucleons, nucleons+theSize, rhs.nucleons, rhs.nucleons+theSize); 285 } 231 } 286 232 287 /// \brief Fill configuration with arr 233 /// \brief Fill configuration with array of NucleonItem 288 void fill(NucleonItem *config, size_t 234 void fill(NucleonItem *config, size_t n) { 289 theSize = n; 235 theSize = n; 290 nucleons = new NucleonItem[theSize]; 236 nucleons = new NucleonItem[theSize]; 291 std::copy(config, config+theSize, nu 237 std::copy(config, config+theSize, nucleons); 292 std::sort(nucleons, nucleons+theSize 238 std::sort(nucleons, nucleons+theSize); 293 } 239 } 294 240 295 private: 241 private: 296 /// \brief Size of the array 242 /// \brief Size of the array 297 size_t theSize; 243 size_t theSize; 298 244 299 /// \brief The real array 245 /// \brief The real array 300 NucleonItem *nucleons; 246 NucleonItem *nucleons; 301 }; 247 }; 302 248 303 typedef std::set<SortedNucleonConfiguratio 249 typedef std::set<SortedNucleonConfiguration> SortedNucleonConfigurationContainer; 304 typedef SortedNucleonConfigurationContaine 250 typedef SortedNucleonConfigurationContainer::iterator SortedNucleonConfigurationIterator; 305 251 306 /// \brief Array of containers for configu 252 /// \brief Array of containers for configurations that have already been checked 307 SortedNucleonConfigurationContainer checke 253 SortedNucleonConfigurationContainer checkedConfigurations[ParticleTable::maxClusterMass-2]; 308 #elif !defined(INCL_CACHING_CLUSTERING_MODEL_I << 254 #else 309 #error Unrecognized INCL_CACHING_CLUSTERING_MO << 255 #error Unrecognized INCL_CACHING_CLUSTERING_MODEL_INTERCOMPARISON. Allowed values are: Set, HashMask. 310 #endif 256 #endif 311 257 312 /** \brief Maximum mass for configuration 258 /** \brief Maximum mass for configuration storage 313 * 259 * 314 * Skipping configurations becomes ineffic 260 * Skipping configurations becomes inefficient above this mass. 315 */ 261 */ 316 G4int maxMassConfigurationSkipping; 262 G4int maxMassConfigurationSkipping; 317 }; 263 }; 318 264 319 } 265 } 320 266 321 #endif 267 #endif 322 268