Project
Loading...
Searching...
No Matches
VecGeomG4Map.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_SIMSETUP_VECGEOMG4MAP_H_
13#define O2_SIMSETUP_VECGEOMG4MAP_H_
14
15#include <VecGeom/volumes/PlacedVolume.h>
16
17#include <cstddef>
18#include <cstdint>
19#include <unordered_map>
20#include <vector>
21
22class G4VPhysicalVolume;
23class TG4RootDetectorConstruction;
24class TGeoNode;
25
26namespace o2::simsetup
27{
28
39{
40 public:
44 void build(TG4RootDetectorConstruction const& dc, bool flattenAssemblies);
45
48 G4VPhysicalVolume* const* chain(int vgId, unsigned& size) const
49 {
50 if (static_cast<std::size_t>(vgId) >= mChainSize.size()) {
51 size = 0;
52 return nullptr;
53 }
54 size = mChainSize[vgId];
55 return mChain.data() + mChainBegin[vgId];
56 }
57
62 vecgeom::VPlacedVolume const* toVecGeom(int g4Id) const { return mG4ToVG[g4Id]; }
63
65 static vecgeom::VPlacedVolume const* ambiguous()
66 {
67 return reinterpret_cast<vecgeom::VPlacedVolume const*>(std::uintptr_t{1});
68 }
69
71 std::vector<vecgeom::VPlacedVolume const*> const& candidates(int g4Id) const
72 {
73 static const std::vector<vecgeom::VPlacedVolume const*> empty;
74 const auto it = mAmbiguous.find(g4Id);
75 return it == mAmbiguous.end() ? empty : it->second;
76 }
77
79 bool chainMatches(vecgeom::VPlacedVolume const* pv, G4VPhysicalVolume* const* first, std::size_t n) const
80 {
81 unsigned size = 0;
82 auto* const* own = chain(pv->id(), size);
83 if (size != n) {
84 return false;
85 }
86 for (std::size_t i = 0; i < n; ++i) {
87 if (own[i] != first[i]) {
88 return false;
89 }
90 }
91 return true;
92 }
93
95 unsigned chainSize(int vgId) const
96 {
97 return static_cast<std::size_t>(vgId) < mChainSize.size() ? mChainSize[vgId] : 0;
98 }
99
101 vecgeom::VPlacedVolume const* world() const { return mWorld; }
102
104 std::size_t ambiguousCount() const { return mAmbiguous.size(); }
105
106 std::size_t size() const { return mPairs; }
107
108 private:
109 void registerPair(vecgeom::VPlacedVolume const* parent, vecgeom::VPlacedVolume const* pv,
110 std::vector<TGeoNode*> const& nodes, TG4RootDetectorConstruction const& dc);
111
112 std::vector<unsigned> mChainBegin;
113 std::vector<unsigned> mChainSize;
114 std::vector<G4VPhysicalVolume*> mChain;
115 std::vector<vecgeom::VPlacedVolume const*> mG4ToVG;
116 std::unordered_map<int, std::vector<vecgeom::VPlacedVolume const*>> mAmbiguous;
117 vecgeom::VPlacedVolume const* mWorld = nullptr;
118 std::size_t mPairs = 0;
119 std::size_t mMispaired = 0;
120};
121
122} // namespace o2::simsetup
123
124#endif
int32_t i
GPUChain * chain
G4VPhysicalVolume *const * chain(int vgId, unsigned &size) const
static vecgeom::VPlacedVolume const * ambiguous()
Marks a Geant4 volume that several VecGeom placements reach.
std::vector< vecgeom::VPlacedVolume const * > const & candidates(int g4Id) const
The placements that share an ambiguous Geant4 volume, to be told apart by their chains.
void build(TG4RootDetectorConstruction const &dc, bool flattenAssemblies)
unsigned chainSize(int vgId) const
How many Geant4 levels a VecGeom placement accounts for.
vecgeom::VPlacedVolume const * toVecGeom(int g4Id) const
bool chainMatches(vecgeom::VPlacedVolume const *pv, G4VPhysicalVolume *const *first, std::size_t n) const
Whether a placement's chain is exactly the given run of Geant4 volumes.
std::size_t size() const
std::size_t ambiguousCount() const
How many Geant4 volumes share more than one VecGeom placement.
vecgeom::VPlacedVolume const * world() const
The outermost placement, standing for the Geant4 world volume.
GLdouble n
Definition glcorearb.h:1982
GLsizeiptr size
Definition glcorearb.h:659
GLint first
Definition glcorearb.h:399
void empty(int)