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 87061 2014-11-24 11:43:34Z 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 "G4TrackList.hh" 40 #include "G4TrackingInformation.hh" << 41 41 42 using namespace std; 42 using namespace std; 43 43 44 //-------------------------------------------- << 44 G4ThreadLocal G4Allocator<G4IT> *aITAllocator = 0; 45 // << 45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 46 /// 46 // Static functions 47 // Static functions 47 // << 48 /// 48 G4IT* GetIT(const G4Track* track) 49 G4IT* GetIT(const G4Track* track) 49 { 50 { 50 return (dynamic_cast<G4IT*>(track->GetUserIn 51 return (dynamic_cast<G4IT*>(track->GetUserInformation())); 51 } 52 } 52 53 53 G4IT* GetIT(const G4Track& track) 54 G4IT* GetIT(const G4Track& track) 54 { 55 { 55 return (dynamic_cast<G4IT*>(track.GetUserInf 56 return (dynamic_cast<G4IT*>(track.GetUserInformation())); 56 } 57 } 57 << 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 58 template<> << 59 /// 59 G4KDNode<G4IT>::~G4KDNode(){ << 60 fPoint->SetNode(nullptr); << 61 } << 62 << 63 //-------------------------------------------- << 64 // << 65 // Constructors / Destructors 60 // Constructors / Destructors 66 // << 61 /// 67 G4IT::G4IT() : 62 G4IT::G4IT() : 68 G4VUserTrackInformation("G4IT"), 63 G4VUserTrackInformation("G4IT"), 69 fpTrack(nullptr), << 64 fpTrack(0), 70 fpPreviousIT(nullptr), << 65 fpPreviousIT(0), 71 fpNextIT(nullptr), << 66 fpNextIT(0), 72 fpTrackingInformation(new G4TrackingInform << 67 fTrackingInformation() 73 { << 68 // fpTrackingInformation(new G4TrackingInformation()) 74 fpITBox = nullptr; << 69 { 75 fpKDNode = nullptr; << 70 if (!aITAllocator) aITAllocator = new G4Allocator<G4IT>; 76 fpTrackNode = nullptr; << 71 fpITBox = 0; >> 72 fpKDNode = 0; >> 73 fpTrackNode = 0; 77 fParentID_A = 0; 74 fParentID_A = 0; 78 fParentID_B = 0; 75 fParentID_B = 0; 79 } 76 } 80 77 81 // Use only by inheriting classes 78 // Use only by inheriting classes 82 G4IT::G4IT(const G4IT& /*right*/) : 79 G4IT::G4IT(const G4IT& /*right*/) : 83 G4VUserTrackInformation("G4IT"), 80 G4VUserTrackInformation("G4IT"), 84 fpTrack(nullptr), << 81 fpTrack(0), 85 fpPreviousIT(nullptr), << 82 fpPreviousIT(0), 86 fpNextIT(nullptr), << 83 fpNextIT(0), 87 fpTrackingInformation(new G4TrackingInform << 84 fTrackingInformation() 88 { << 85 // fpTrackingInformation(new G4TrackingInformation()) 89 fpITBox = nullptr; << 86 { 90 fpKDNode = nullptr; << 87 fpITBox = 0; 91 fpTrackNode = nullptr; << 88 fpKDNode = 0; >> 89 fpTrackNode = 0; 92 fParentID_A = 0; 90 fParentID_A = 0; 93 fParentID_B = 0; 91 fParentID_B = 0; 94 } 92 } 95 93 96 // Should not be used 94 // Should not be used 97 G4IT& G4IT::operator=(const G4IT& right) 95 G4IT& G4IT::operator=(const G4IT& right) 98 { 96 { 99 G4ExceptionDescription exceptionDescription; 97 G4ExceptionDescription exceptionDescription; 100 exceptionDescription 98 exceptionDescription 101 << "The assignment operator of G4IT shou << 99 << "The assignment operator of G4IT should not be used, this feature is not supported." 102 "this feature is not supported." << 103 << "If really needed, please contact the 100 << "If really needed, please contact the developers."; 104 G4Exception("G4IT::operator=(const G4IT& rig << 101 G4Exception("G4IT::operator=(const G4IT& right)", "G4IT001", FatalException, 105 "G4IT001", << 106 FatalException, << 107 exceptionDescription); 102 exceptionDescription); 108 103 109 if (this == &right) return *this; 104 if (this == &right) return *this; 110 105 111 fpTrack = nullptr; << 106 fpTrack = 0; 112 fpITBox = nullptr; << 107 fpITBox = 0; 113 fpPreviousIT = nullptr; << 108 fpPreviousIT = 0; 114 fpNextIT = nullptr; << 109 fpNextIT = 0; 115 fpKDNode = nullptr; << 110 fpKDNode = 0; 116 fParentID_A = 0; 111 fParentID_A = 0; 117 fParentID_B = 0; 112 fParentID_B = 0; 118 fpTrackingInformation = nullptr; << 113 // fpTrackingInformation = 0; 119 fpTrackNode = nullptr; << 114 fpTrackNode = 0; 120 115 121 return *this; 116 return *this; 122 } 117 } 123 118 124 G4IT::G4IT(G4Track * aTrack) : 119 G4IT::G4IT(G4Track * aTrack) : 125 G4VUserTrackInformation("G4IT"), 120 G4VUserTrackInformation("G4IT"), 126 fpPreviousIT(nullptr), << 121 fpPreviousIT(0), 127 fpNextIT(nullptr), << 122 fpNextIT(0), 128 fpTrackingInformation(new G4TrackingInform << 123 fTrackingInformation() >> 124 // fpTrackingInformation(new G4TrackingInformation()) 129 { 125 { 130 fpITBox = nullptr; << 126 if (!aITAllocator) aITAllocator = new G4Allocator<G4IT>; >> 127 fpITBox = 0; 131 fpTrack = aTrack; 128 fpTrack = aTrack; 132 fpKDNode = nullptr; << 129 fpKDNode = 0; 133 fpTrackNode = nullptr; << 130 fpTrackNode = 0; 134 fParentID_A = 0; 131 fParentID_A = 0; 135 fParentID_B = 0; 132 fParentID_B = 0; 136 RecordCurrentPositionNTime(); 133 RecordCurrentPositionNTime(); 137 } 134 } 138 135 139 void G4IT::TakeOutBox() 136 void G4IT::TakeOutBox() 140 { 137 { 141 if(fpITBox != nullptr) << 138 if(fpITBox) 142 { 139 { 143 fpITBox->Extract(this); 140 fpITBox->Extract(this); 144 fpITBox = nullptr; << 145 } 141 } 146 142 147 if(fpTrackNode != nullptr) << 143 if(fpTrackNode) 148 { 144 { 149 delete fpTrackNode; 145 delete fpTrackNode; 150 fpTrackNode = nullptr; << 146 fpTrackNode = 0; 151 } 147 } 152 148 153 if(fpKDNode != nullptr) << 149 if(fpKDNode) 154 { 150 { 155 InactiveNode(fpKDNode); 151 InactiveNode(fpKDNode); 156 fpKDNode = nullptr; << 152 fpKDNode = 0; 157 } 153 } 158 } 154 } 159 155 160 G4IT::~G4IT() 156 G4IT::~G4IT() 161 { 157 { 162 TakeOutBox(); 158 TakeOutBox(); 163 159 164 if(fpTrackingInformation != nullptr) << 160 // if(fpTrackingInformation) 165 { << 161 // { 166 delete fpTrackingInformation; << 162 // delete fpTrackingInformation; 167 fpTrackingInformation = nullptr; << 163 // fpTrackingInformation = 0; 168 } << 164 // } 169 165 170 // Note : 166 // Note : 171 // G4ITTrackingManager will delete fTrackNode. 167 // G4ITTrackingManager will delete fTrackNode. 172 // fKDNode will be deleted when the KDTree is 168 // fKDNode will be deleted when the KDTree is rebuilt 173 } 169 } 174 << 170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 175 //-------------------------------------------- << 176 /// 171 /// 177 // Methods 172 // Methods 178 /// 173 /// >> 174 void G4IT::RecordCurrentPositionNTime() >> 175 { >> 176 if (fpTrack) >> 177 { >> 178 fTrackingInformation.RecordCurrentPositionNTime(fpTrack); >> 179 } >> 180 } 179 181 180 G4bool G4IT::operator<(const G4IT& right) cons 182 G4bool G4IT::operator<(const G4IT& right) const 181 { 183 { 182 if (GetITType() == right.GetITType()) 184 if (GetITType() == right.GetITType()) 183 { 185 { 184 return (this->diff(right)); 186 return (this->diff(right)); 185 } 187 } 186 << 188 else 187 return (GetITType() < right.GetITType()); << 189 { 188 << 190 return (GetITType() < right.GetITType()); >> 191 } >> 192 return false; 189 } 193 } 190 194 191 G4bool G4IT::operator==(const G4IT& right) con 195 G4bool G4IT::operator==(const G4IT& right) const 192 { 196 { 193 if (GetITType() == right.GetITType()) 197 if (GetITType() == right.GetITType()) 194 { 198 { 195 return this->equal(right); 199 return this->equal(right); 196 } 200 } 197 return false; 201 return false; 198 } 202 } 199 203 200 G4bool G4IT::operator!=(const G4IT& right) con 204 G4bool G4IT::operator!=(const G4IT& right) const 201 { 205 { 202 return !(this->operator==(right)); 206 return !(this->operator==(right)); 203 } 207 } 204 208 205 double G4IT::operator[](int i) const << 206 { << 207 return fpTrack->GetPosition()[i]; << 208 } << 209 << 210 //-------------------------------------------- << 211 << 212 const G4ThreeVector& G4IT::GetPosition() const 209 const G4ThreeVector& G4IT::GetPosition() const 213 { 210 { 214 if (fpTrack != nullptr) return GetTrack()->G << 211 if (fpTrack) return GetTrack()->GetPosition(); 215 return *(new G4ThreeVector()); 212 return *(new G4ThreeVector()); 216 } 213 } 217 214 218 void G4IT::RecordCurrentPositionNTime() << 215 const double& G4IT::operator[](int i) const 219 { 216 { 220 if (fpTrack != nullptr) << 217 return const_cast<G4ThreeVector&>(GetTrack()->GetPosition())[i]; 221 { << 222 fpTrackingInformation->RecordCurrentPositi << 223 } << 224 } 218 } 225 << 226 G4double G4IT::GetPreStepGlobalTime() const << 227 { << 228 return fpTrackingInformation->GetPreStepGlob << 229 } << 230 << 231 G4double G4IT::GetPreStepLocalTime() const << 232 { << 233 return fpTrackingInformation->GetPreStepLoca << 234 } << 235 << 236 const G4ThreeVector& G4IT::GetPreStepPosition( << 237 { << 238 return fpTrackingInformation->GetPreStepPosi << 239 } << 240 << 241 219