Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0028 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
0029 //
0030 #ifndef G4ParticleHPAngularP_h
0031 #define G4ParticleHPAngularP_h 1
0032 
0033 #include "G4InterpolationManager.hh"
0034 #include "G4ParticleHPInterpolator.hh"
0035 #include "globals.hh"
0036 
0037 #include <CLHEP/Units/SystemOfUnits.h>
0038 
0039 class G4ParticleHPAngularP
0040 {
0041   public:
0042     G4ParticleHPAngularP()
0043     {
0044       theCosTh = nullptr;
0045       theProb = nullptr;
0046       theEnergy = 0.;
0047       nCoeff = 0;
0048     }
0049     ~G4ParticleHPAngularP()
0050     {
0051       delete[] theCosTh;
0052       delete[] theProb;
0053     }
0054 
0055     inline void Init(std::istream& aDataFile)
0056     {
0057       G4double eNeu, cosTheta, probDist;
0058       G4int nProb;
0059       aDataFile >> eNeu >> nProb;
0060       theManager.Init(aDataFile);
0061       eNeu *= CLHEP::eV;
0062       Init(eNeu, nProb);
0063       for (G4int iii = 0; iii < nProb; iii++) {
0064         aDataFile >> cosTheta >> probDist;
0065         SetCosTh(iii, cosTheta);
0066         SetProb(iii, probDist);
0067       }
0068     }
0069 
0070     inline void Init(G4double e, G4int n)
0071     {
0072       theCosTh = new G4double[n];
0073       theProb = new G4double[n];
0074       theEnergy = e;
0075       nCoeff = n;
0076     }
0077 
0078     inline void SetEnergy(G4double energy) { theEnergy = energy; }
0079     inline void SetCosTh(G4int l, G4double coeff) { theCosTh[l] = coeff; }
0080     inline void SetProb(G4int l, G4double coeff) { theProb[l] = coeff; }
0081 
0082     inline G4double GetCosTh(G4int l) { return theCosTh[l]; }
0083     inline G4double GetProb(G4int l) { return theProb[l]; }
0084     inline G4double GetEnergy() { return theEnergy; }
0085     inline G4int GetNumberOfPoints() { return nCoeff; }
0086     inline G4double GetCosTh()
0087     {
0088       G4int i;
0089       G4double rand = G4UniformRand();
0090       G4double run = 0, runo = 0;
0091       for (i = 0; i < GetNumberOfPoints(); i++) {
0092         runo = run;
0093         run += GetProb(i);
0094         if (run > rand) break;
0095       }
0096       if (i == GetNumberOfPoints()) i--;
0097       G4double costh =
0098         theInt.Interpolate(theManager.GetScheme(i), rand, runo, run, GetCosTh(i - 1), GetCosTh(i));
0099       return costh;
0100     }
0101 
0102   private:
0103     G4double theEnergy;  // neutron energy
0104     G4ParticleHPInterpolator theInt;  // knows tointerpolate
0105     G4int nCoeff;
0106     G4InterpolationManager theManager;  // knows the interpolation between stores
0107     G4double* theCosTh;
0108     G4double* theProb;  // probability distribution as fcn of theta
0109                         // integral normalised to 1.
0110 };
0111 #endif