Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id: G4IT.cc 71125 2013-06-11 15:39:09Z gcosmo $ 26 // 27 // 27 // Author: Mathieu Karamitros (kara (AT) cenbg 28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 28 // 29 // 29 // History: 30 // History: 30 // ----------- 31 // ----------- 31 // 10 Oct 2011 M.Karamitros created 32 // 10 Oct 2011 M.Karamitros created 32 // 33 // 33 // ------------------------------------------- 34 // ------------------------------------------------------------------- 34 35 35 #include "G4IT.hh" 36 #include "G4IT.hh" 36 #include "G4KDTree.hh" 37 #include "G4KDTree.hh" 37 #include "G4ITBox.hh" 38 #include "G4ITBox.hh" 38 #include "G4Track.hh" 39 #include "G4Track.hh" 39 #include "G4TrackList.hh" << 40 #include "G4TrackingInformation.hh" << 41 40 42 using namespace std; 41 using namespace std; 43 42 44 //-------------------------------------------- << 43 G4ThreadLocal G4Allocator<G4IT> *aITAllocator = 0; 45 // << 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 45 /// 46 // Static functions 46 // Static functions 47 // << 47 /// 48 G4IT* GetIT(const G4Track* track) 48 G4IT* GetIT(const G4Track* track) 49 { 49 { 50 return (dynamic_cast<G4IT*>(track->GetUserIn << 50 return (dynamic_cast<G4IT*>(track->GetUserInformation())); 51 } 51 } 52 52 53 G4IT* GetIT(const G4Track& track) 53 G4IT* GetIT(const G4Track& track) 54 { 54 { 55 return (dynamic_cast<G4IT*>(track.GetUserInf << 55 return (dynamic_cast<G4IT*>(track.GetUserInformation())); 56 } << 57 << 58 template<> << 59 G4KDNode<G4IT>::~G4KDNode(){ << 60 fPoint->SetNode(nullptr); << 61 } 56 } 62 << 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 63 //-------------------------------------------- << 58 /// 64 // << 65 // Constructors / Destructors 59 // Constructors / Destructors 66 // << 60 /// 67 G4IT::G4IT() : << 61 G4IT::G4IT() : G4VUserTrackInformation("G4IT"), 68 G4VUserTrackInformation("G4IT"), << 62 fpTrack (0), 69 fpTrack(nullptr), << 63 fpPreviousIT(0), fpNextIT(0), 70 fpPreviousIT(nullptr), << 64 fTrackingInformation() 71 fpNextIT(nullptr), << 65 // fpTrackingInformation(new G4TrackingInformation()) 72 fpTrackingInformation(new G4TrackingInform << 66 { 73 { << 67 if (!aITAllocator) aITAllocator = new G4Allocator<G4IT>; 74 fpITBox = nullptr; << 68 fpITBox=0; 75 fpKDNode = nullptr; << 69 fpKDNode = 0 ; 76 fpTrackNode = nullptr; << 70 fpTrackNode = 0; 77 fParentID_A = 0; << 71 fParentID_A = 0; 78 fParentID_B = 0; << 72 fParentID_B = 0; 79 } 73 } 80 74 81 // Use only by inheriting classes 75 // Use only by inheriting classes 82 G4IT::G4IT(const G4IT& /*right*/) : << 76 G4IT::G4IT(const G4IT& /*right*/) : G4VUserTrackInformation("G4IT"), 83 G4VUserTrackInformation("G4IT"), << 77 fpTrack (0), 84 fpTrack(nullptr), << 78 fpPreviousIT(0), fpNextIT(0), 85 fpPreviousIT(nullptr), << 79 fTrackingInformation() 86 fpNextIT(nullptr), << 80 // fpTrackingInformation(new G4TrackingInformation()) 87 fpTrackingInformation(new G4TrackingInform << 81 { 88 { << 82 fpITBox=0; 89 fpITBox = nullptr; << 83 fpKDNode = 0 ; 90 fpKDNode = nullptr; << 84 fpTrackNode = 0; 91 fpTrackNode = nullptr; << 85 fParentID_A = 0; 92 fParentID_A = 0; << 86 fParentID_B = 0; 93 fParentID_B = 0; << 94 } 87 } 95 88 96 // Should not be used 89 // Should not be used 97 G4IT& G4IT::operator=(const G4IT& right) 90 G4IT& G4IT::operator=(const G4IT& right) 98 { 91 { 99 G4ExceptionDescription exceptionDescription; << 92 G4ExceptionDescription exceptionDescription; 100 exceptionDescription << 93 exceptionDescription << "The assignment operator of G4IT should not be used, this feature is not supported." 101 << "The assignment operator of G4IT shou << 94 << "If really needed, please contact the developers."; 102 "this feature is not supported." << 95 G4Exception("G4IT::operator=(const G4IT& right)","G4IT001",FatalException,exceptionDescription); 103 << "If really needed, please contact the << 96 104 G4Exception("G4IT::operator=(const G4IT& rig << 97 if(this == &right) return *this; 105 "G4IT001", << 98 106 FatalException, << 99 fpTrack = 0; 107 exceptionDescription); << 100 fpITBox = 0; 108 << 101 fpPreviousIT = 0; 109 if (this == &right) return *this; << 102 fpNextIT = 0; 110 << 103 fpKDNode = 0 ; 111 fpTrack = nullptr; << 104 fParentID_A = 0; 112 fpITBox = nullptr; << 105 fParentID_B = 0; 113 fpPreviousIT = nullptr; << 106 // fpTrackingInformation = 0; 114 fpNextIT = nullptr; << 107 fpTrackNode = 0; 115 fpKDNode = nullptr; << 108 116 fParentID_A = 0; << 109 return *this; 117 fParentID_B = 0; << 110 } 118 fpTrackingInformation = nullptr; << 111 119 fpTrackNode = nullptr; << 112 G4IT::G4IT(G4Track * aTrack) : G4VUserTrackInformation("G4IT"), 120 << 113 fpPreviousIT(0), fpNextIT(0), 121 return *this; << 114 fTrackingInformation() 122 } << 115 // fpTrackingInformation(new G4TrackingInformation()) 123 << 116 { 124 G4IT::G4IT(G4Track * aTrack) : << 117 if (!aITAllocator) aITAllocator = new G4Allocator<G4IT>; 125 G4VUserTrackInformation("G4IT"), << 118 fpITBox = 0; 126 fpPreviousIT(nullptr), << 119 fpTrack = aTrack; 127 fpNextIT(nullptr), << 120 fpKDNode = 0 ; 128 fpTrackingInformation(new G4TrackingInform << 121 fpTrackNode = 0; 129 { << 122 fParentID_A = 0; 130 fpITBox = nullptr; << 123 fParentID_B = 0; 131 fpTrack = aTrack; << 124 RecordCurrentPositionNTime(); 132 fpKDNode = nullptr; << 133 fpTrackNode = nullptr; << 134 fParentID_A = 0; << 135 fParentID_B = 0; << 136 RecordCurrentPositionNTime(); << 137 } 125 } 138 126 139 void G4IT::TakeOutBox() 127 void G4IT::TakeOutBox() 140 { 128 { 141 if(fpITBox != nullptr) << 129 if(fpITBox) 142 { << 130 { 143 fpITBox->Extract(this); << 131 fpITBox->Extract(this); 144 fpITBox = nullptr; << 132 } 145 } << 133 146 << 134 if(fpKDNode) 147 if(fpTrackNode != nullptr) << 135 { 148 { << 136 InactiveNode(fpKDNode); 149 delete fpTrackNode; << 137 fpKDNode = 0; 150 fpTrackNode = nullptr; << 138 } 151 } << 152 << 153 if(fpKDNode != nullptr) << 154 { << 155 InactiveNode(fpKDNode); << 156 fpKDNode = nullptr; << 157 } << 158 } 139 } 159 140 160 G4IT::~G4IT() 141 G4IT::~G4IT() 161 { 142 { 162 TakeOutBox(); << 143 TakeOutBox(); 163 << 164 if(fpTrackingInformation != nullptr) << 165 { << 166 delete fpTrackingInformation; << 167 fpTrackingInformation = nullptr; << 168 } << 169 144 170 // Note : << 145 // if(fpTrackingInformation) 171 // G4ITTrackingManager will delete fTrackNode. << 146 // { 172 // fKDNode will be deleted when the KDTree is << 147 // delete fpTrackingInformation; >> 148 // fpTrackingInformation = 0; >> 149 // } >> 150 >> 151 // Note : >> 152 // G4ITTrackingManager will delete fTrackNode. >> 153 // fKDNode will be deleted when the KDTree is rebuilt 173 } 154 } 174 << 155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 175 //-------------------------------------------- << 176 /// 156 /// 177 // Methods 157 // Methods 178 /// 158 /// 179 << 180 G4bool G4IT::operator<(const G4IT& right) cons << 181 { << 182 if (GetITType() == right.GetITType()) << 183 { << 184 return (this->diff(right)); << 185 } << 186 << 187 return (GetITType() < right.GetITType()); << 188 << 189 } << 190 << 191 G4bool G4IT::operator==(const G4IT& right) con << 192 { << 193 if (GetITType() == right.GetITType()) << 194 { << 195 return this->equal(right); << 196 } << 197 return false; << 198 } << 199 << 200 G4bool G4IT::operator!=(const G4IT& right) con << 201 { << 202 return !(this->operator==(right)); << 203 } << 204 << 205 double G4IT::operator[](int i) const << 206 { << 207 return fpTrack->GetPosition()[i]; << 208 } << 209 << 210 //-------------------------------------------- << 211 << 212 const G4ThreeVector& G4IT::GetPosition() const << 213 { << 214 if (fpTrack != nullptr) return GetTrack()->G << 215 return *(new G4ThreeVector()); << 216 } << 217 << 218 void G4IT::RecordCurrentPositionNTime() 159 void G4IT::RecordCurrentPositionNTime() 219 { 160 { 220 if (fpTrack != nullptr) << 161 if(fpTrack) 221 { << 162 { 222 fpTrackingInformation->RecordCurrentPositi << 163 fTrackingInformation.RecordCurrentPositionNTime(fpTrack); 223 } << 164 } 224 } 165 } 225 166 226 G4double G4IT::GetPreStepGlobalTime() const << 167 G4bool G4IT::operator<(const G4IT& right) const 227 { 168 { 228 return fpTrackingInformation->GetPreStepGlob << 169 if(GetITType() == right.GetITType() ) >> 170 { >> 171 return (this->diff(right)) ; >> 172 } >> 173 else >> 174 { >> 175 return (GetITType() < right.GetITType()); >> 176 } >> 177 return false; 229 } 178 } 230 179 231 G4double G4IT::GetPreStepLocalTime() const << 180 G4bool G4IT::operator==(const G4IT& right) const 232 { 181 { 233 return fpTrackingInformation->GetPreStepLoca << 182 if(GetITType() == right.GetITType() ) >> 183 { >> 184 return this->equal(right); >> 185 } >> 186 return false; 234 } 187 } 235 188 236 const G4ThreeVector& G4IT::GetPreStepPosition( << 189 G4bool G4IT::operator!=(const G4IT& right) const 237 { 190 { 238 return fpTrackingInformation->GetPreStepPosi << 191 return !(this->operator==(right)); 239 } 192 } 240 << 241 193