Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // ********************************************************************
0002 // * License and Disclaimer                                           *
0003 // *                                                                  *
0004 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0005 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0006 // * conditions of the Geant4 Software License,  included in the file *
0007 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0008 // * include a list of copyright holders.                             *
0009 // *                                                                  *
0010 // * Neither the authors of this software system, nor their employing *
0011 // * institutes,nor the agencies providing financial support for this *
0012 // * work  make  any representation or  warranty, express or implied, *
0013 // * regarding  this  software system or assume any liability for its *
0014 // * use.  Please see the license in the file  LICENSE  and URL above *
0015 // * for the full disclaimer and the limitation of liability.         *
0016 // *                                                                  *
0017 // * This  code  implementation is the result of  the  scientific and *
0018 // * technical work of the GEANT4 collaboration.                      *
0019 // * By using,  copying,  modifying or  distributing the software (or *
0020 // * any work based  on the software)  you  agree  to acknowledge its *
0021 // * use  in  resulting  scientific  publications,  and indicate your *
0022 // * acceptance of all terms of the Geant4 Software license.          *
0023 // ********************************************************************
0024 //
0025 //
0026 //
0027 
0028 #ifndef G4OctreeFinder_hh
0029 #define G4OctreeFinder_hh 1
0030 
0031 #include "globals.hh"
0032 #include "G4Octree.hh"
0033 #include "G4Track.hh"
0034 #include "G4ITType.hh"
0035 #include "G4memory.hh"
0036 #include "G4TrackList.hh"
0037 
0038 #include <map>
0039 #include <functional>
0040 
0041 #undef DEBUG
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 class G4VFinder
0044 {
0045 public:
0046     G4VFinder() = default;
0047     virtual ~G4VFinder() = default;
0048     virtual void Clear() = 0;
0049     virtual void SetVerboseLevel(G4int level) = 0;
0050     virtual G4int GetVerboseLevel() = 0;
0051     virtual G4ITType GetITType() = 0;
0052 };
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 #ifndef _Extractor_
0056 #define _Extractor_
0057 template<typename CONTAINER>
0058 class Extractor
0059 {
0060 public:
0061     const G4ThreeVector operator () (typename CONTAINER::iterator it)
0062     {
0063       return (*it)->GetPosition();
0064     }
0065     std::function<G4bool(const std::pair<typename CONTAINER::iterator,G4double>,
0066                          const std::pair<typename CONTAINER::iterator,G4double>)>
0067     compareInterval = [](const std::pair<typename CONTAINER::iterator,G4double>& iter1,
0068                          const std::pair<typename CONTAINER::iterator,G4double>& iter2)
0069     -> G4bool
0070     {
0071         return (std::get<1>(iter1) < std::get<1>(iter2));
0072     };
0073     
0074 };
0075 #endif
0076 template<class T,typename CONTAINER>
0077 class G4OctreeFinder: public G4VFinder
0078 {
0079     using Octree = G4Octree<typename CONTAINER::iterator,
0080     Extractor<CONTAINER> >;
0081     using OctreeHandle = G4shared_ptr<Octree>;
0082     using TreeMap = std::map<int, OctreeHandle>;
0083     
0084 private:
0085     static G4ThreadLocal G4OctreeFinder* fInstance;
0086     G4OctreeFinder();
0087     int fVerbose{0};
0088     G4bool fIsOctreeUsed{false};
0089     G4bool fIsOctreeBuit{false};
0090     Extractor<CONTAINER> fExtractor;
0091     TreeMap fTreeMap;
0092     OctreeHandle fTree;
0093 public:
0094     static G4OctreeFinder * Instance();
0095     
0096     void SetOctreeUsed(G4bool used);
0097     G4bool IsOctreeUsed() const;
0098     
0099     void SetOctreeBuilt(G4bool used);
0100     G4bool IsOctreeBuilt() const;
0101     
0102     ~G4OctreeFinder() override;
0103     void Clear() override;
0104 
0105     void SetVerboseLevel(G4int level) override
0106     {
0107         fVerbose = level;
0108     }
0109 
0110     G4int GetVerboseLevel() override
0111     {
0112         return fVerbose;
0113     }
0114 
0115     G4ITType GetITType() override
0116     {
0117         return T::ITType();
0118     }
0119     void BuildTreeMap(const std::map<G4int,CONTAINER*>& listMap);
0120     void FindNearestInRange(const G4Track& track,
0121                             const int& key,
0122                             G4double R,
0123                             std::vector<std::pair<typename
0124                             CONTAINER::iterator,G4double>>& result,
0125                             G4bool isSort = false) const;
0126 
0127     void FindNearest(const G4Track& track,
0128                             const int& key,
0129                             G4double R,
0130                             std::vector<std::pair<typename
0131                             CONTAINER::iterator,G4double>>& result,
0132                             G4bool isSort = false) const;
0133     
0134     void FindNearestInRange(const G4ThreeVector& position,
0135                             const G4int& key,
0136                             G4double R,
0137                             std::vector<std::pair<typename
0138                             CONTAINER::iterator,G4double>>& result,
0139                             G4bool isSort = false) const;
0140 
0141     void FindNearestInRange(const G4ThreeVector& /*from this point*/,
0142                             G4double R,
0143                             std::vector<std::pair<
0144                             typename CONTAINER::iterator,G4double> >&
0145                             result,
0146                             G4bool isSorted) const;
0147 };
0148 
0149 #include "G4OctreeFinder.icc"
0150 #endif