Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
33#include "globals.hh"
34
35#include <vector>
36
38{
39 public:
41 {
42 theUpper = nullptr;
43 prepared = false;
44 }
45
46 ~G4ParticleHPHash() { delete theUpper; }
47
49 {
50 theIndex = aHash.theIndex;
51 theData = aHash.theData;
52 prepared = aHash.prepared;
53 if (aHash.theUpper != nullptr) {
54 theUpper = new G4ParticleHPHash(*(aHash.theUpper));
55 }
56 else {
57 theUpper = nullptr;
58 }
59 }
60
62 {
63 if (&aHash != this) {
64 theIndex = aHash.theIndex;
65 theData = aHash.theData;
66 if (aHash.theUpper != nullptr) {
67 theUpper = new G4ParticleHPHash(*(aHash.theUpper));
68 }
69 else {
70 theUpper = nullptr;
71 }
72 }
73 return *this;
74 }
75
76 void Clear()
77 {
78 if (theUpper != nullptr) {
79 theUpper->Clear();
80 delete theUpper;
81 theUpper = nullptr;
82 }
83 theIndex.clear();
84 theData.clear();
85 prepared = false;
86 }
87
88 G4bool Prepared() const { return prepared; }
89 inline void SetData(G4int index, G4double x, G4double y)
90 {
91 prepared = true;
93 aPoint.SetData(x, y);
94 theData.push_back(aPoint);
95 theIndex.push_back(index);
96 if (0 == theData.size() % 10 && !theData.empty()) {
97 if (nullptr == theUpper) theUpper = new G4ParticleHPHash();
98 theUpper->SetData(static_cast<G4int>(theData.size()) - 1, x, y);
99 }
100 }
101
103 {
104 G4int result = -1;
105 if (theData.empty()) return 0;
106 if (theData[0].GetX() > e) return 0;
107
108 G4int lower = 0;
109 if (theUpper != nullptr) {
110 lower = theUpper->GetMinIndex(e);
111 }
112 unsigned int i;
113 for (i = lower; i < theData.size(); i++) {
114 if (theData[i].GetX() > e) {
115 result = theIndex[i - 1];
116 break;
117 }
118 }
119 if (result == -1) result = theIndex[theIndex.size() - 1];
120 return result;
121 }
122
123 private:
124 G4bool prepared;
125 G4ParticleHPHash* theUpper;
126 std::vector<int> theIndex;
127 std::vector<G4ParticleHPDataPoint> theData; // the data
128};
129#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void SetData(G4double e, G4double x)
void SetData(G4int index, G4double x, G4double y)
G4ParticleHPHash(const G4ParticleHPHash &aHash)
G4ParticleHPHash & operator=(const G4ParticleHPHash &aHash)
G4bool Prepared() const
G4int GetMinIndex(G4double e) const