ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleHPAngularP.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleHPAngularP.hh
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 //
27 //
28 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
29 //
30 #ifndef G4ParticleHPAngularP_h
31 #define G4ParticleHPAngularP_h 1
32 
34 
35 #include "globals.hh"
38 
40 {
41  public:
42 
44  {
45  theCosTh = NULL;
46  theProb = NULL;
47  theEnergy = 0.;
48  nCoeff = 0;
49  }
51  {
52  if(theCosTh!=0) delete [] theCosTh;
53  if(theProb!=0) delete [] theProb;
54  }
55 
56  inline void Init(std::istream & aDataFile)
57  {
58  G4double eNeu, cosTheta, probDist;
59  G4int nProb;
60  aDataFile >> eNeu >> nProb;
61  theManager.Init(aDataFile);
62  eNeu *= CLHEP::eV;
63  Init(eNeu, nProb);
64  for (G4int iii=0; iii<nProb; iii++)
65  {
66  aDataFile >> cosTheta >> probDist;
67  SetCosTh(iii, cosTheta);
68  SetProb(iii,probDist);
69  }
70  }
71 
72  inline void Init(G4double e, G4int n)
73  {
74  theCosTh = new G4double[n];
75  theProb = new G4double[n];
76  theEnergy = e;
77  nCoeff = n;
78  }
79 
81  inline void SetCosTh(G4int l, G4double coeff) {theCosTh[l]=coeff;}
82  inline void SetProb(G4int l, G4double coeff) {theProb[l]=coeff;}
83 
84  inline G4double GetCosTh(G4int l) {return theCosTh[l];}
85  inline G4double GetProb(G4int l) {return theProb[l];}
86  inline G4double GetEnergy(){return theEnergy;}
87  inline G4int GetNumberOfPoints(){ return nCoeff; }
88  inline G4double GetCosTh()
89  {
90  G4int i;
91  G4double rand = G4UniformRand();
92  G4double run=0, runo=0;
93  for (i=0; i<GetNumberOfPoints(); i++)
94  {
95  runo=run;
96  run += GetProb(i);
97  if(run>rand) break;
98  }
99  if(i == GetNumberOfPoints()) i--;
100  G4double costh = theInt.Interpolate(theManager.GetScheme(i), rand,
101  runo, run, GetCosTh(i-1), GetCosTh(i));
102  return costh;
103  }
104 
105  private:
106 
107  G4double theEnergy; // neutron energy
108  G4ParticleHPInterpolator theInt; // knows tointerpolate
110  G4InterpolationManager theManager; // knows the interpolation between stores
112  G4double * theProb; // probability distribution as fcn of theta
113  // integral normalised to 1.
114 };
115 #endif