Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:29

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // INCL++ intra-nuclear cascade model
0027 // Alain Boudard, CEA-Saclay, France
0028 // Joseph Cugnon, University of Liege, Belgium
0029 // Jean-Christophe David, CEA-Saclay, France
0030 // Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
0031 // Sylvie Leray, CEA-Saclay, France
0032 // Davide Mancusi, CEA-Saclay, France
0033 //
0034 #define INCLXX_IN_GEANT4_MODE 1
0035 
0036 #include "globals.hh"
0037 
0038 /*
0039  * G4INCLRandom.hh
0040  *
0041  *  \date 7 June 2009
0042  * \author Pekka Kaitaniemi
0043  */
0044 
0045 #ifndef G4INCLRANDOM_HH_
0046 #define G4INCLRANDOM_HH_
0047 
0048 #include <iostream>
0049 #include <cmath>
0050 #include <utility>
0051 #include <limits>
0052 #include "G4INCLIRandomGenerator.hh"
0053 #include "G4INCLThreeVector.hh"
0054 #include "G4INCLGlobals.hh"
0055 #include "G4INCLConfig.hh"
0056 #ifdef INCLXX_IN_GEANT4_MODE
0057   #include "Randomize.hh"
0058 #endif
0059 
0060 namespace G4INCL {
0061 
0062   namespace Random {
0063     /**
0064      * Set the random number generator implementation to be used globally by INCL.
0065      *
0066      * @see G4INCL::IRandomGenerator
0067      */
0068     void setGenerator(G4INCL::IRandomGenerator *aGenerator);
0069 
0070     /**
0071      * Set the seeds of the current generator.
0072      *
0073      */
0074     void setSeeds(const SeedVector &sv);
0075 
0076     /**
0077      * Get the seeds of the current generator.
0078      *
0079      */
0080     SeedVector getSeeds();
0081 
0082     /**
0083      * Generate flat distribution of random numbers.
0084      */
0085     G4double shoot();
0086 
0087     /**
0088      * Return a random number in the ]0,1] interval
0089      */
0090     G4double shoot0();
0091 
0092     /**
0093      * Return a random number in the [0,1[ interval
0094      */
0095     G4double shoot1();
0096 
0097     /**
0098      * Return a random integer in the [0,n[ interval
0099      */
0100     template<typename T> T shootInteger(T n){
0101       return static_cast<T>(shoot1() * n);
0102     }
0103 
0104     /**
0105      * Generate random numbers using gaussian distribution.
0106      */
0107     G4double gauss(G4double sigma=1.);
0108 
0109 #ifdef INCLXX_IN_GEANT4_MODE
0110     /**
0111      * Generate random numbers using gaussian distribution to be used only
0112      * for correlated pairs
0113      */
0114       G4double gaussWithMemory(G4double sigma=1.);
0115 #endif
0116 
0117     /**
0118      * Generate isotropically-distributed ThreeVectors of given norm.
0119      */
0120     ThreeVector normVector(G4double norm=1.);
0121 
0122     /**
0123      * Generate ThreeVectors that are uniformly distributed in a sphere of
0124      * radius rmax.
0125      */
0126     ThreeVector sphereVector(G4double rmax=1.);
0127 
0128     /** \brief Generate Gaussianly-distributed ThreeVectors
0129      *
0130      * Generate ThreeVectors that are distributed as a three-dimensional
0131      * Gaussian of the given sigma.
0132      */
0133     ThreeVector gaussVector(G4double sigma=1.);
0134 
0135     /// \brief Generate pairs of correlated Gaussian random numbers
0136     std::pair<G4double,G4double> correlatedGaussian(const G4double corrCoeff, const G4double x0=0., const G4double sigma=1.);
0137 
0138     /// \brief Generate pairs of correlated uniform random numbers
0139     std::pair<G4double,G4double> correlatedUniform(const G4double corrCoeff);
0140 
0141     /**
0142      * Delete the generator
0143      */
0144     void deleteGenerator();
0145 
0146     /**
0147      * Check if the generator is initialized.
0148      */
0149     G4bool isInitialized();
0150 
0151 #ifdef INCL_COUNT_RND_CALLS
0152     /// \brief Return the number of calls to the RNG
0153     unsigned long long getNumberOfCalls();
0154 #endif
0155 
0156     /// \brief Save the status of the random-number generator
0157     void saveSeeds();
0158 
0159     /// \brief Get the saved status of the random-number generator
0160     SeedVector getSavedSeeds();
0161 
0162     /// \brief Initialize generator according to a Config object
0163 #ifdef INCLXX_IN_GEANT4_MODE
0164     void initialize(Config const * const);
0165 #else
0166     void initialize(Config const * const theConfig);
0167 #endif
0168 
0169     class Adapter {
0170       public:
0171         using result_type = unsigned long long;
0172 
0173         static constexpr result_type min() {
0174           return std::numeric_limits<Adapter::result_type>::min();
0175         }
0176 
0177         static constexpr result_type max() {
0178           return std::numeric_limits<Adapter::result_type>::max();
0179         }
0180 
0181         result_type operator()() const {
0182 
0183           #ifdef INCLXX_IN_GEANT4_MODE
0184              return G4RandFlat::shootInt(INT_MAX);
0185           #else
0186              return shootInteger(max());
0187           #endif
0188 
0189         }
0190 
0191     };
0192 
0193     Adapter const &getAdapter();
0194   }
0195 
0196 }
0197 
0198 #endif /* G4INCLRANDOM_HH_ */