File indexing completed on 2025-01-18 09:58:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef G4ParticleHPHash_h
0030 #define G4ParticleHPHash_h
0031
0032 #include "G4ParticleHPDataPoint.hh"
0033 #include "globals.hh"
0034
0035 #include <vector>
0036
0037 class G4ParticleHPHash
0038 {
0039 public:
0040 G4ParticleHPHash()
0041 {
0042 theUpper = nullptr;
0043 prepared = false;
0044 }
0045
0046 ~G4ParticleHPHash() { delete theUpper; }
0047
0048 G4ParticleHPHash(const G4ParticleHPHash& aHash)
0049 {
0050 theIndex = aHash.theIndex;
0051 theData = aHash.theData;
0052 prepared = aHash.prepared;
0053 if (aHash.theUpper != nullptr) {
0054 theUpper = new G4ParticleHPHash(*(aHash.theUpper));
0055 }
0056 else {
0057 theUpper = nullptr;
0058 }
0059 }
0060
0061 G4ParticleHPHash& operator=(const G4ParticleHPHash& aHash)
0062 {
0063 if (&aHash != this) {
0064 theIndex = aHash.theIndex;
0065 theData = aHash.theData;
0066 if (aHash.theUpper != nullptr) {
0067 theUpper = new G4ParticleHPHash(*(aHash.theUpper));
0068 }
0069 else {
0070 theUpper = nullptr;
0071 }
0072 }
0073 return *this;
0074 }
0075
0076 void Clear()
0077 {
0078 if (theUpper != nullptr) {
0079 theUpper->Clear();
0080 delete theUpper;
0081 theUpper = nullptr;
0082 }
0083 theIndex.clear();
0084 theData.clear();
0085 prepared = false;
0086 }
0087
0088 G4bool Prepared() const { return prepared; }
0089 inline void SetData(G4int index, G4double x, G4double y)
0090 {
0091 prepared = true;
0092 G4ParticleHPDataPoint aPoint;
0093 aPoint.SetData(x, y);
0094 theData.push_back(aPoint);
0095 theIndex.push_back(index);
0096 if (0 == theData.size() % 10 && !theData.empty()) {
0097 if (nullptr == theUpper) theUpper = new G4ParticleHPHash();
0098 theUpper->SetData(static_cast<G4int>(theData.size()) - 1, x, y);
0099 }
0100 }
0101
0102 G4int GetMinIndex(G4double e) const
0103 {
0104 G4int result = -1;
0105 if (theData.empty()) return 0;
0106 if (theData[0].GetX() > e) return 0;
0107
0108 G4int lower = 0;
0109 if (theUpper != nullptr) {
0110 lower = theUpper->GetMinIndex(e);
0111 }
0112 unsigned int i;
0113 for (i = lower; i < theData.size(); i++) {
0114 if (theData[i].GetX() > e) {
0115 result = theIndex[i - 1];
0116 break;
0117 }
0118 }
0119 if (result == -1) result = theIndex[theIndex.size() - 1];
0120 return result;
0121 }
0122
0123 private:
0124 G4bool prepared;
0125 G4ParticleHPHash* theUpper;
0126 std::vector<int> theIndex;
0127 std::vector<G4ParticleHPDataPoint> theData;
0128 };
0129 #endif