Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0027 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
0028 //
0029 #ifndef G4ParticleHPEnergyDistribution_h
0030 #define G4ParticleHPEnergyDistribution_h 1
0031 
0032 #include "G4ParticleHPArbitaryTab.hh"
0033 #include "G4ParticleHPEvapSpectrum.hh"
0034 #include "G4ParticleHPFissionSpectrum.hh"
0035 #include "G4ParticleHPMadlandNixSpectrum.hh"
0036 #include "G4ParticleHPSimpleEvapSpectrum.hh"
0037 #include "G4ParticleHPWattSpectrum.hh"
0038 #include "G4VParticleHPEDis.hh"
0039 #include "G4ios.hh"
0040 #include "Randomize.hh"
0041 #include "globals.hh"
0042 
0043 #include <fstream>
0044 
0045 // we will need a List of these .... one per term.
0046 
0047 class G4ParticleHPEnergyDistribution
0048 {
0049   public:
0050     G4ParticleHPEnergyDistribution()
0051     {
0052       theEnergyDistribution = nullptr;
0053       theNumberOfPartials = 0;
0054       theRepresentationType = 0;
0055     }
0056     ~G4ParticleHPEnergyDistribution()
0057     {
0058       if (theEnergyDistribution != nullptr) {
0059         for (G4int i = 0; i < theNumberOfPartials; i++) {
0060           delete theEnergyDistribution[i];
0061         }
0062         delete[] theEnergyDistribution;
0063       }
0064     }
0065 
0066     inline void Init(std::istream& theData)
0067     {
0068       G4double dummy;
0069       theData >> dummy >> theNumberOfPartials;
0070       theEnergyDistribution = new G4VParticleHPEDis*[theNumberOfPartials];
0071       for (G4int i = 0; i < theNumberOfPartials; i++) {
0072         theData >> theRepresentationType;
0073         switch (theRepresentationType) {
0074           case 1:
0075             theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
0076             break;
0077           case 5:
0078             theEnergyDistribution[i] = new G4ParticleHPEvapSpectrum;
0079             break;
0080           case 7:
0081             theEnergyDistribution[i] = new G4ParticleHPFissionSpectrum;
0082             break;
0083           case 9:
0084             theEnergyDistribution[i] = new G4ParticleHPSimpleEvapSpectrum;
0085             break;
0086           case 11:
0087             theEnergyDistribution[i] = new G4ParticleHPWattSpectrum;
0088             break;
0089           case 12:
0090             theEnergyDistribution[i] = new G4ParticleHPMadlandNixSpectrum;
0091             break;
0092     default:
0093             theEnergyDistribution[i] = new G4ParticleHPArbitaryTab;
0094         }
0095         theEnergyDistribution[i]->Init(theData);
0096       }
0097     }
0098 
0099     inline G4double Sample(G4double anEnergy, G4int& it)
0100     {
0101       G4double result = 0;
0102       it = 0;
0103       if (theNumberOfPartials != 0) {
0104         G4double sum = 0;
0105         auto running = new G4double[theNumberOfPartials];
0106         running[0] = 0;
0107         G4int i;
0108         for (i = 0; i < theNumberOfPartials; i++) {
0109           if (i != 0) running[i] = running[i - 1];
0110           running[i] += theEnergyDistribution[i]->GetFractionalProbability(anEnergy);
0111         }
0112         sum = running[theNumberOfPartials - 1];
0113         G4double random = G4UniformRand();
0114         for (i = 0; i < theNumberOfPartials; i++) {
0115           it = i;
0116           if (running[i] / sum > random) break;
0117         }
0118         delete[] running;
0119         if (it == theNumberOfPartials) it--;
0120         result = theEnergyDistribution[it]->Sample(anEnergy);
0121       }
0122       return result;
0123     }
0124 
0125   private:
0126     G4int theNumberOfPartials;
0127     G4int theRepresentationType;
0128     G4VParticleHPEDis** theEnergyDistribution;
0129 };
0130 
0131 #endif