Geant4  10.01
G4ParticleHPHash.hh
Go to the documentation of this file.
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 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
28 //
29 #ifndef G4ParticleHPHash_h
30 #define G4ParticleHPHash_h
31 
32 #include "globals.hh"
33 #include <vector>
34 
36 {
37 public:
39  {
40  theUpper = 0;
41  prepared = false;
42  }
43 
45  {
46  if(theUpper) delete theUpper;
47  }
48 
50  {
51  theIndex = aHash.theIndex;
52  theData = aHash.theData;
53  if(aHash.theUpper != 0)
54  {
55  theUpper = new G4ParticleHPHash(*(aHash.theUpper));
56  }
57  else
58  {
59  theUpper = 0;
60  }
61  }
62 
64  {
65  if(&aHash != this)
66  {
67  theIndex = aHash.theIndex;
68  theData = aHash.theData;
69  if(aHash.theUpper != 0)
70  {
71  theUpper = new G4ParticleHPHash(*(aHash.theUpper));
72  }
73  else
74  {
75  theUpper = 0;
76  }
77  }
78  return *this;
79  }
80 
81  void Clear()
82  {
83  if(theUpper)
84  {
85  theUpper->Clear();
86  delete theUpper;
87  theUpper = 0;
88  }
89  theIndex.clear();
90  theData.clear();
91  prepared = false;
92  }
93 
94  G4bool Prepared() const {return prepared;}
95  inline void SetData(G4int index, G4double x, G4double y)
96  {
97  prepared = true;
98  G4ParticleHPDataPoint aPoint;
99  aPoint.SetData(x, y);
100  theData.push_back(aPoint);
101  theIndex.push_back(index);
102  if(0 == theData.size()%10 && 0!=theData.size())
103  {
104  if(0 == theUpper) theUpper = new G4ParticleHPHash();
105  theUpper->SetData(theData.size()-1, x, y);
106  }
107  }
108 
110  {
111  G4int result=-1;
112  if(theData.size() == 0) return 0;
113  if(theData[0].GetX()>e) return 0;
114 
115  G4int lower=0;
116  if(theUpper != 0)
117  {
118  lower = theUpper->GetMinIndex(e);
119  }
120  unsigned int i;
121  for(i=lower; i<theData.size(); i++)
122  {
123  if(theData[i].GetX()>e)
124  {
125  result = theIndex[i-1];
126  break;
127  }
128  }
129  if(result == -1) result = theIndex[theIndex.size()-1];
130  return result;
131  }
132 
133 private:
134 
137  std::vector<int> theIndex;
138  std::vector<G4ParticleHPDataPoint> theData; // the data
139 };
140 #endif
void SetData(G4double e, G4double x)
G4ParticleHPHash * theUpper
G4bool Prepared() const
std::vector< G4ParticleHPDataPoint > theData
int G4int
Definition: G4Types.hh:78
void SetData(G4int index, G4double x, G4double y)
bool G4bool
Definition: G4Types.hh:79
G4ParticleHPHash & operator=(const G4ParticleHPHash &aHash)
double G4double
Definition: G4Types.hh:76
G4int GetMinIndex(G4double e) const
G4ParticleHPHash(const G4ParticleHPHash &aHash)
std::vector< int > theIndex