Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  prepared = aHash.prepared;
54  if(aHash.theUpper != 0)
55  {
56  theUpper = new G4ParticleHPHash(*(aHash.theUpper));
57  }
58  else
59  {
60  theUpper = 0;
61  }
62  }
63 
65  {
66  if(&aHash != this)
67  {
68  theIndex = aHash.theIndex;
69  theData = aHash.theData;
70  if(aHash.theUpper != 0)
71  {
72  theUpper = new G4ParticleHPHash(*(aHash.theUpper));
73  }
74  else
75  {
76  theUpper = 0;
77  }
78  }
79  return *this;
80  }
81 
82  void Clear()
83  {
84  if(theUpper)
85  {
86  theUpper->Clear();
87  delete theUpper;
88  theUpper = 0;
89  }
90  theIndex.clear();
91  theData.clear();
92  prepared = false;
93  }
94 
95  G4bool Prepared() const {return prepared;}
96  inline void SetData(G4int index, G4double x, G4double y)
97  {
98  prepared = true;
99  G4ParticleHPDataPoint aPoint;
100  aPoint.SetData(x, y);
101  theData.push_back(aPoint);
102  theIndex.push_back(index);
103  if(0 == theData.size()%10 && 0!=theData.size())
104  {
105  if(0 == theUpper) theUpper = new G4ParticleHPHash();
106  theUpper->SetData(theData.size()-1, x, y);
107  }
108  }
109 
111  {
112  G4int result=-1;
113  if(theData.size() == 0) return 0;
114  if(theData[0].GetX()>e) return 0;
115 
116  G4int lower=0;
117  if(theUpper != 0)
118  {
119  lower = theUpper->GetMinIndex(e);
120  }
121  unsigned int i;
122  for(i=lower; i<theData.size(); i++)
123  {
124  if(theData[i].GetX()>e)
125  {
126  result = theIndex[i-1];
127  break;
128  }
129  }
130  if(result == -1) result = theIndex[theIndex.size()-1];
131  return result;
132  }
133 
134 private:
135 
136  G4bool prepared;
137  G4ParticleHPHash * theUpper;
138  std::vector<int> theIndex;
139  std::vector<G4ParticleHPDataPoint> theData; // the data
140 };
141 #endif
G4double G4ParticleHPJENDLHEData::G4double result
void SetData(G4double e, G4double x)
G4bool Prepared() const
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)