Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MoleculeLocator.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Author: Christian Velten (2025)
27
28#include "G4MoleculeLocator.hh"
29
30#include "G4IT.hh"
32#include "G4Track.hh"
34
35G4ThreadLocal G4MoleculeLocator* G4MoleculeLocator::fpInstance = nullptr;
36
37G4MoleculeLocator::G4MoleculeLocator()
38{
39 fNavigator = std::make_unique<G4ITNavigator>();
40}
41
42G4MoleculeLocator* G4MoleculeLocator::Instance()
43{
44 if (fpInstance == nullptr) {
46 fpInstance = instance.Instance();
47 }
48 if (!fpInstance->fIsInitialized) {
49 fpInstance->Initialize();
50 }
51 return fpInstance;
52}
53
54void G4MoleculeLocator::Initialize()
55{
57 ->GetNavigatorForTracking()
58 ->GetWorldVolume());
59 fIsInitialized = true;
60}
61
63{
64 G4IT* pITrack = GetIT(pTrack);
65
66 if (pITrack == nullptr) {
67 G4Exception("G4MoleculeLocator::LocateMoleculeSetStateAndTouchable", "NOT_AN_IT", FatalErrorInArgument,
68 "The track passed to this method appears to not hold an IT (molecule) object!");
69 }
70
71 std::unique_ptr<G4ITNavigatorState_Lock> tmpStateHolder;
72 if (pITrack->GetTrackingInfo()->GetNavigatorState() != nullptr)
73 fNavigator->SetNavigatorState(pITrack->GetTrackingInfo()->GetNavigatorState());
74 else {
75 fNavigator->NewNavigatorState();
76 tmpStateHolder = std::unique_ptr<G4ITNavigatorState_Lock>(fNavigator->GetNavigatorState());
77 // will be deleted once method goes out of scope
78 }
79
80 G4ThreeVector direction = pTrack->GetMomentumDirection();
81
82 fNavigator->LocateGlobalPointAndSetup(pTrack->GetPosition(), &direction, false, false);
83
84 G4TouchableHandle touchable = fNavigator->CreateTouchableHistory();
85 return touchable;
86}
87
89{
90 G4IT* pITrack = GetIT(pTrack);
91
92 if (pITrack == nullptr) {
93 G4Exception("G4MoleculeLocator::LocateMoleculeSetStateAndTouchable", "NOT_AN_IT", FatalErrorInArgument,
94 "The track passed to this method appears to not hold an IT (molecule) object!");
95 }
96
97 fNavigator->NewNavigatorState();
98 GetIT(pTrack)->GetTrackingInfo()->SetNavigatorState(fNavigator->GetNavigatorState());
99
100 G4ThreeVector direction = pTrack->GetMomentumDirection();
101
102 fNavigator->LocateGlobalPointAndSetup(pTrack->GetPosition(), &direction, false, false);
103
104 G4TouchableHandle touchable = fNavigator->CreateTouchableHistory();
105 pTrack->SetTouchableHandle(touchable);
106 pTrack->SetNextTouchableHandle(touchable);
107}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4IT * GetIT(const G4Track *track)
Definition G4IT.cc:48
G4TemplateRNGHelper< G4long > * G4TemplateRNGHelper< G4long >::instance
CLHEP::Hep3Vector G4ThreeVector
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
G4TouchableHandle is a type providing reference counting mechanism for any kind of touchable objects....
static G4ITTransportationManager * GetTransportationManager()
Definition G4IT.hh:88
G4TrackingInformation * GetTrackingInfo()
Definition G4IT.hh:143
void LocateMoleculeSetStateAndTouchable(G4Track *)
G4TouchableHandle LocateMoleculeTrack(const G4Track *)
static G4MoleculeLocator * Instance()
void SetNextTouchableHandle(const G4TouchableHandle &apValue)
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
const G4ThreeVector & GetMomentumDirection() const
void SetNavigatorState(G4ITNavigatorState_Lock *)
G4ITNavigatorState_Lock * GetNavigatorState() const
#define G4ThreadLocal
Definition tls.hh:77