Project
Loading...
Searching...
No Matches
VecGeomG4NavigatorBase.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_VECGEOMG4NAVIGATORBASE_H_
13#define O2_SIMSETUP_VECGEOMG4NAVIGATORBASE_H_
14
15#include "VecGeomG4Map.h"
16
17#include "G4Navigator.hh"
18#include "G4SystemOfUnits.hh"
19#include "G4ThreeVector.hh"
20
21#include <VecGeom/base/Transformation3D.h>
22#include <VecGeom/base/Vector3D.h>
23#include <VecGeom/navigation/NavigationState.h>
24#include <VecGeom/volumes/PlacedVolume.h>
25
26namespace o2::simsetup
27{
28
34{
35 protected:
36 using V3 = vecgeom::Vector3D<double>;
37 static constexpr double kG4ToVG = 1. / CLHEP::cm;
38 static constexpr double kVGToG4 = CLHEP::cm;
39
40 explicit VecGeomG4NavigatorBase(VecGeomG4Map const& map) : mMap(map) {}
41
42 static V3 toVG(const G4ThreeVector& p) { return {p.x() * kG4ToVG, p.y() * kG4ToVG, p.z() * kG4ToVG}; }
43 static V3 toDir(const G4ThreeVector& d) { return {d.x(), d.y(), d.z()}; }
44
47 G4VPhysicalVolume* historyFromState(vecgeom::NavigationState const& state);
48
51 bool stateFromHistory(vecgeom::NavigationState& state) const;
52
55 [[gnu::always_inline]] static bool directionLeaves(const V3& n, const V3& dir)
56 {
57 constexpr double kMinExitingNormalCosine = 1e-3; // as in G4NormalNavigation
58 return n.Dot(dir) >= kMinExitingNormalCosine;
59 }
60
62 [[gnu::always_inline]] static bool directionLeaves(vecgeom::NavigationState const& exited, const V3& point,
63 const V3& dir)
64 {
65 if (exited.IsOutside() || exited.Top() == nullptr) {
66 return false;
67 }
68 vecgeom::Transformation3D m;
69 exited.TopMatrix(m);
70 V3 n;
71 exited.Top()->GetUnplacedVolume()->Normal(m.Transform(point), n);
72 if (!(n.Mag2() > 0.5)) {
73 return false; // no valid exit normal: Geant4 does not block either
74 }
75 return directionLeaves(m.InverseTransformDirection(n), dir);
76 }
77
79};
80
81} // namespace o2::simsetup
82
83#endif
SurfaceTrackState state
static bool directionLeaves(const V3 &n, const V3 &dir)
static V3 toDir(const G4ThreeVector &d)
G4VPhysicalVolume * historyFromState(vecgeom::NavigationState const &state)
static V3 toVG(const G4ThreeVector &p)
bool stateFromHistory(vecgeom::NavigationState &state) const
static bool directionLeaves(vecgeom::NavigationState const &exited, const V3 &point, const V3 &dir)
The same, with the normal taken from exited, which has the volume left on top.
VecGeomG4NavigatorBase(VecGeomG4Map const &map)
GLdouble n
Definition glcorearb.h:1982
const GLfloat * m
Definition glcorearb.h:4066