Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4IT.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 // $Id: G4IT.cc 102637 2017-02-10 11:08:17Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4IT.hh"
37 #include "G4KDTree.hh"
38 #include "G4ITBox.hh"
39 #include "G4Track.hh"
40 #include "G4TrackList.hh"
41 #include "G4TrackingInformation.hh"
42 
43 using namespace std;
44 
45 //------------------------------------------------------------------------------
46 //
47 // Static functions
48 //
49 G4IT* GetIT(const G4Track* track)
50 {
51  return (dynamic_cast<G4IT*>(track->GetUserInformation()));
52 }
53 
54 G4IT* GetIT(const G4Track& track)
55 {
56  return (dynamic_cast<G4IT*>(track.GetUserInformation()));
57 }
58 
59 template<>
61  fPoint->SetNode(nullptr);
62 }
63 
64 //------------------------------------------------------------------------------
65 //
66 // Constructors / Destructors
67 //
70  fpTrack(nullptr),
71  fpPreviousIT(nullptr),
72  fpNextIT(nullptr),
73  fpTrackingInformation(new G4TrackingInformation())
74 {
75  fpITBox = nullptr;
76  fpKDNode = nullptr;
77  fpTrackNode = nullptr;
78  fParentID_A = 0;
79  fParentID_B = 0;
80 }
81 
82 // Use only by inheriting classes
83 G4IT::G4IT(const G4IT& /*right*/) :
85  fpTrack(nullptr),
86  fpPreviousIT(nullptr),
87  fpNextIT(nullptr),
88  fpTrackingInformation(new G4TrackingInformation())
89 {
90  fpITBox = nullptr;
91  fpKDNode = nullptr;
92  fpTrackNode = nullptr;
93  fParentID_A = 0;
94  fParentID_B = 0;
95 }
96 
97 // Should not be used
98 G4IT& G4IT::operator=(const G4IT& right)
99 {
100  G4ExceptionDescription exceptionDescription;
101  exceptionDescription
102  << "The assignment operator of G4IT should not be used, "
103  "this feature is not supported."
104  << "If really needed, please contact the developers.";
105  G4Exception("G4IT::operator=(const G4IT& right)",
106  "G4IT001",
108  exceptionDescription);
109 
110  if (this == &right) return *this;
111 
112  fpTrack = nullptr;
113  fpITBox = nullptr;
114  fpPreviousIT = nullptr;
115  fpNextIT = nullptr;
116  fpKDNode = nullptr;
117  fParentID_A = 0;
118  fParentID_B = 0;
119  fpTrackingInformation = nullptr;
120  fpTrackNode = nullptr;
121 
122  return *this;
123 }
124 
125 G4IT::G4IT(G4Track * aTrack) :
126  G4VUserTrackInformation("G4IT"),
127  fpPreviousIT(0),
128  fpNextIT(0),
129  fpTrackingInformation(new G4TrackingInformation())
130 {
131  fpITBox = 0;
132  fpTrack = aTrack;
133  fpKDNode = nullptr;
134  fpTrackNode = nullptr;
135  fParentID_A = 0;
136  fParentID_B = 0;
138 }
139 
141 {
142  if(fpITBox)
143  {
144  fpITBox->Extract(this);
145  fpITBox = nullptr;
146  }
147 
148  if(fpTrackNode)
149  {
150  delete fpTrackNode;
151  fpTrackNode = nullptr;
152  }
153 
154  if(fpKDNode)
155  {
156  InactiveNode(fpKDNode);
157  fpKDNode = nullptr;
158  }
159 }
160 
162 {
163  TakeOutBox();
164 
165  if(fpTrackingInformation)
166  {
167  delete fpTrackingInformation;
168  fpTrackingInformation = nullptr;
169  }
170 
171 // Note :
172 // G4ITTrackingManager will delete fTrackNode.
173 // fKDNode will be deleted when the KDTree is rebuilt
174 }
175 
176 //------------------------------------------------------------------------------
178 // Methods
180 
181 G4bool G4IT::operator<(const G4IT& right) const
182 {
183  if (GetITType() == right.GetITType())
184  {
185  return (this->diff(right));
186  }
187  else
188  {
189  return (GetITType() < right.GetITType());
190  }
191  return false;
192 }
193 
194 G4bool G4IT::operator==(const G4IT& right) const
195 {
196  if (GetITType() == right.GetITType())
197  {
198  return this->equal(right);
199  }
200  return false;
201 }
202 
203 G4bool G4IT::operator!=(const G4IT& right) const
204 {
205  return !(this->operator==(right));
206 }
207 
208 double G4IT::operator[](int i) const
209 {
210  return fpTrack->GetPosition()[i];
211 }
212 
213 //------------------------------------------------------------------------------
214 
216 {
217  if (fpTrack) return GetTrack()->GetPosition();
218  return *(new G4ThreeVector());
219 }
220 
222 {
223  if (fpTrack)
224  {
225  fpTrackingInformation->RecordCurrentPositionNTime(fpTrack);
226  }
227 }
228 
230 {
231  return fpTrackingInformation->GetPreStepGlobalTime();
232 }
233 
235 {
236  return fpTrackingInformation->GetPreStepLocalTime();
237 }
238 
240 {
241  return fpTrackingInformation->GetPreStepPosition();
242 }
243 
Definition: G4IT.hh:88
virtual G4bool equal(const G4IT &right) const =0
void TakeOutBox()
Definition: G4IT.cc:140
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetPreStepGlobalTime() const
CLHEP::Hep3Vector G4ThreeVector
G4IT()
Definition: G4IT.cc:68
const G4ThreeVector & GetPreStepPosition() const
Definition: G4IT.cc:239
const G4ThreeVector & GetPosition() const
void RecordCurrentPositionNTime()
Definition: G4IT.cc:221
void RecordCurrentPositionNTime(G4Track *)
G4bool operator<(const G4IT &right) const
Definition: G4IT.cc:181
virtual ~G4KDNode()
G4VUserTrackInformation * GetUserInformation() const
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:49
bool G4bool
Definition: G4Types.hh:79
G4Track * fpTrack
Definition: G4IT.hh:168
G4bool operator==(const G4IT &right) const
Definition: G4IT.cc:194
void InactiveNode(G4KDNode_Base *)
Definition: G4KDNode.cc:58
G4IT & operator=(const G4IT &)
Definition: G4IT.cc:98
G4double GetPreStepLocalTime() const
G4double GetPreStepLocalTime() const
Definition: G4IT.cc:234
const G4ThreeVector & GetPreStepPosition() const
virtual G4bool diff(const G4IT &right) const =0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double operator[](int i) const
Definition: G4IT.cc:208
virtual const G4ITType GetITType() const =0
G4Track * GetTrack()
Definition: G4IT.hh:219
double G4double
Definition: G4Types.hh:76
virtual ~G4IT()
Definition: G4IT.cc:161
G4double GetPreStepGlobalTime() const
Definition: G4IT.cc:229
const G4ThreeVector & GetPosition() const
Definition: G4IT.cc:215
G4bool operator!=(const G4IT &right) const
Definition: G4IT.cc:203
void Extract(G4IT *)
Definition: G4ITBox.cc:87