Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:52

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
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;  // the data
0128 };
0129 #endif