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 // G4SmoothTrajectory class implementation 26 // G4SmoothTrajectory class implementation 27 // 27 // 28 // Contact: 28 // Contact: 29 // Questions and comments to this code shoul 29 // Questions and comments to this code should be sent to 30 // Katsuya Amako (e-mail: Katsuya.Amako@k 30 // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) 31 // Makoto Asai (e-mail: asai@slac.stanf 31 // Makoto Asai (e-mail: asai@slac.stanford.edu) 32 // Takashi Sasaki (e-mail: Takashi.Sasaki@ 32 // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) 33 // ------------------------------------------- 33 // -------------------------------------------------------------------- 34 34 35 #include "G4SmoothTrajectory.hh" 35 #include "G4SmoothTrajectory.hh" 36 #include "G4ClonedSmoothTrajectory.hh" << 37 36 38 #include "G4AttDef.hh" 37 #include "G4AttDef.hh" 39 #include "G4AttDefStore.hh" 38 #include "G4AttDefStore.hh" 40 #include "G4AttValue.hh" 39 #include "G4AttValue.hh" 41 #include "G4ParticleTable.hh" 40 #include "G4ParticleTable.hh" 42 #include "G4SmoothTrajectoryPoint.hh" 41 #include "G4SmoothTrajectoryPoint.hh" 43 #include "G4UIcommand.hh" 42 #include "G4UIcommand.hh" 44 #include "G4UnitsTable.hh" 43 #include "G4UnitsTable.hh" 45 #include "G4AutoLock.hh" << 46 << 47 namespace { << 48 G4Mutex CloneSmoothTrajectoryMutex = G4MUTEX_ << 49 } << 50 44 51 // #define G4ATTDEBUG 45 // #define G4ATTDEBUG 52 #ifdef G4ATTDEBUG 46 #ifdef G4ATTDEBUG 53 # include "G4AttCheck.hh" 47 # include "G4AttCheck.hh" 54 #endif 48 #endif 55 49 56 G4Allocator<G4SmoothTrajectory>*& aSmoothTraje 50 G4Allocator<G4SmoothTrajectory>*& aSmoothTrajectoryAllocator() 57 { 51 { 58 G4ThreadLocalStatic G4Allocator<G4SmoothTraj 52 G4ThreadLocalStatic G4Allocator<G4SmoothTrajectory>* _instance = nullptr; 59 return _instance; 53 return _instance; 60 } 54 } 61 55 62 G4SmoothTrajectory::G4SmoothTrajectory(const G 56 G4SmoothTrajectory::G4SmoothTrajectory(const G4Track* aTrack) 63 { 57 { 64 G4ParticleDefinition* fpParticleDefinition = 58 G4ParticleDefinition* fpParticleDefinition = aTrack->GetDefinition(); 65 ParticleName = fpParticleDefinition->GetPart 59 ParticleName = fpParticleDefinition->GetParticleName(); 66 PDGCharge = fpParticleDefinition->GetPDGChar 60 PDGCharge = fpParticleDefinition->GetPDGCharge(); 67 PDGEncoding = fpParticleDefinition->GetPDGEn 61 PDGEncoding = fpParticleDefinition->GetPDGEncoding(); 68 fTrackID = aTrack->GetTrackID(); 62 fTrackID = aTrack->GetTrackID(); 69 fParentID = aTrack->GetParentID(); 63 fParentID = aTrack->GetParentID(); 70 initialKineticEnergy = aTrack->GetKineticEne 64 initialKineticEnergy = aTrack->GetKineticEnergy(); 71 initialMomentum = aTrack->GetMomentum(); 65 initialMomentum = aTrack->GetMomentum(); 72 positionRecord = new G4TrajectoryPointContai 66 positionRecord = new G4TrajectoryPointContainer(); 73 67 74 // Following is for the first trajectory poi 68 // Following is for the first trajectory point 75 // 69 // 76 positionRecord->push_back(new G4SmoothTrajec 70 positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition())); 77 71 78 // The first point has no auxiliary points, 72 // The first point has no auxiliary points, so set the auxiliary 79 // points vector to NULL 73 // points vector to NULL 80 // 74 // 81 positionRecord->push_back(new G4SmoothTrajec 75 positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition(), nullptr)); 82 } 76 } 83 77 84 G4SmoothTrajectory::G4SmoothTrajectory(G4Smoot 78 G4SmoothTrajectory::G4SmoothTrajectory(G4SmoothTrajectory& right) 85 { 79 { 86 ParticleName = right.ParticleName; 80 ParticleName = right.ParticleName; 87 PDGCharge = right.PDGCharge; 81 PDGCharge = right.PDGCharge; 88 PDGEncoding = right.PDGEncoding; 82 PDGEncoding = right.PDGEncoding; 89 fTrackID = right.fTrackID; 83 fTrackID = right.fTrackID; 90 fParentID = right.fParentID; 84 fParentID = right.fParentID; 91 initialKineticEnergy = right.initialKineticE 85 initialKineticEnergy = right.initialKineticEnergy; 92 initialMomentum = right.initialMomentum; 86 initialMomentum = right.initialMomentum; 93 positionRecord = new G4TrajectoryPointContai 87 positionRecord = new G4TrajectoryPointContainer(); 94 88 95 for (auto& i : *right.positionRecord) { 89 for (auto& i : *right.positionRecord) { 96 auto rightPoint = (G4SmoothTrajectoryPoint 90 auto rightPoint = (G4SmoothTrajectoryPoint*)i; 97 positionRecord->push_back(new G4SmoothTraj 91 positionRecord->push_back(new G4SmoothTrajectoryPoint(*rightPoint)); 98 } 92 } 99 } << 100 << 101 G4VTrajectory* G4SmoothTrajectory::CloneForMas << 102 { << 103 G4AutoLock lock(&CloneSmoothTrajectoryMutex) << 104 auto* cloned = new G4ClonedSmoothTrajectory( << 105 return cloned; << 106 } 93 } 107 94 108 G4SmoothTrajectory::~G4SmoothTrajectory() 95 G4SmoothTrajectory::~G4SmoothTrajectory() 109 { 96 { 110 if (positionRecord != nullptr) { 97 if (positionRecord != nullptr) { 111 for (auto& i : *positionRecord) { 98 for (auto& i : *positionRecord) { 112 delete i; 99 delete i; 113 } 100 } 114 positionRecord->clear(); 101 positionRecord->clear(); 115 delete positionRecord; 102 delete positionRecord; 116 } 103 } 117 } 104 } 118 105 119 void G4SmoothTrajectory::ShowTrajectory(std::o 106 void G4SmoothTrajectory::ShowTrajectory(std::ostream& os) const 120 { 107 { 121 // Invoke the default implementation in G4VT 108 // Invoke the default implementation in G4VTrajectory... 122 // 109 // 123 G4VTrajectory::ShowTrajectory(os); 110 G4VTrajectory::ShowTrajectory(os); 124 111 125 // ... or override with your own code here. 112 // ... or override with your own code here. 126 } 113 } 127 114 128 void G4SmoothTrajectory::DrawTrajectory() cons 115 void G4SmoothTrajectory::DrawTrajectory() const 129 { 116 { 130 // Invoke the default implementation in G4VT 117 // Invoke the default implementation in G4VTrajectory... 131 // 118 // 132 G4VTrajectory::DrawTrajectory(); 119 G4VTrajectory::DrawTrajectory(); 133 120 134 // ... or override with your own code here. 121 // ... or override with your own code here. 135 } 122 } 136 123 137 const std::map<G4String, G4AttDef>* G4SmoothTr 124 const std::map<G4String, G4AttDef>* G4SmoothTrajectory::GetAttDefs() const 138 { 125 { 139 G4bool isNew; 126 G4bool isNew; 140 std::map<G4String, G4AttDef>* store = G4AttD 127 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("G4SmoothTrajectory", isNew); 141 if (isNew) { 128 if (isNew) { 142 G4String ID("ID"); 129 G4String ID("ID"); 143 (*store)[ID] = G4AttDef(ID, "Track ID", "P 130 (*store)[ID] = G4AttDef(ID, "Track ID", "Physics", "", "G4int"); 144 131 145 G4String PID("PID"); 132 G4String PID("PID"); 146 (*store)[PID] = G4AttDef(PID, "Parent ID", 133 (*store)[PID] = G4AttDef(PID, "Parent ID", "Physics", "", "G4int"); 147 134 148 G4String PN("PN"); 135 G4String PN("PN"); 149 (*store)[PN] = G4AttDef(PN, "Particle Name 136 (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String"); 150 137 151 G4String Ch("Ch"); 138 G4String Ch("Ch"); 152 (*store)[Ch] = G4AttDef(Ch, "Charge", "Phy 139 (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double"); 153 140 154 G4String PDG("PDG"); 141 G4String PDG("PDG"); 155 (*store)[PDG] = G4AttDef(PDG, "PDG Encodin 142 (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int"); 156 143 157 G4String IKE("IKE"); 144 G4String IKE("IKE"); 158 (*store)[IKE] = G4AttDef(IKE, "Initial kin 145 (*store)[IKE] = G4AttDef(IKE, "Initial kinetic energy", "Physics", "G4BestUnit", "G4double"); 159 146 160 G4String IMom("IMom"); 147 G4String IMom("IMom"); 161 (*store)[IMom] = G4AttDef(IMom, "Initial m 148 (*store)[IMom] = G4AttDef(IMom, "Initial momentum", "Physics", "G4BestUnit", "G4ThreeVector"); 162 149 163 G4String IMag("IMag"); 150 G4String IMag("IMag"); 164 (*store)[IMag] = 151 (*store)[IMag] = 165 G4AttDef(IMag, "Initial momentum magnitu 152 G4AttDef(IMag, "Initial momentum magnitude", "Physics", "G4BestUnit", "G4double"); 166 153 167 G4String NTP("NTP"); 154 G4String NTP("NTP"); 168 (*store)[NTP] = G4AttDef(NTP, "No. of poin 155 (*store)[NTP] = G4AttDef(NTP, "No. of points", "Physics", "", "G4int"); 169 } 156 } 170 return store; 157 return store; 171 } 158 } 172 159 173 std::vector<G4AttValue>* G4SmoothTrajectory::C 160 std::vector<G4AttValue>* G4SmoothTrajectory::CreateAttValues() const 174 { 161 { 175 auto values = new std::vector<G4AttValue>; 162 auto values = new std::vector<G4AttValue>; 176 163 177 values->push_back(G4AttValue("ID", G4UIcomma 164 values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), "")); 178 165 179 values->push_back(G4AttValue("PID", G4UIcomm 166 values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), "")); 180 167 181 values->push_back(G4AttValue("PN", ParticleN 168 values->push_back(G4AttValue("PN", ParticleName, "")); 182 169 183 values->push_back(G4AttValue("Ch", G4UIcomma 170 values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(PDGCharge), "")); 184 171 185 values->push_back(G4AttValue("PDG", G4UIcomm 172 values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(PDGEncoding), "")); 186 173 187 values->push_back(G4AttValue("IKE", G4BestUn 174 values->push_back(G4AttValue("IKE", G4BestUnit(initialKineticEnergy, "Energy"), "")); 188 175 189 values->push_back(G4AttValue("IMom", G4BestU 176 values->push_back(G4AttValue("IMom", G4BestUnit(initialMomentum, "Energy"), "")); 190 177 191 values->push_back(G4AttValue("IMag", G4BestU 178 values->push_back(G4AttValue("IMag", G4BestUnit(initialMomentum.mag(), "Energy"), "")); 192 179 193 values->push_back(G4AttValue("NTP", G4UIcomm 180 values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), "")); 194 181 195 #ifdef G4ATTDEBUG 182 #ifdef G4ATTDEBUG 196 G4cout << G4AttCheck(values, GetAttDefs()); 183 G4cout << G4AttCheck(values, GetAttDefs()); 197 #endif 184 #endif 198 185 199 return values; 186 return values; 200 } 187 } 201 188 202 void G4SmoothTrajectory::AppendStep(const G4St 189 void G4SmoothTrajectory::AppendStep(const G4Step* aStep) 203 { 190 { 204 positionRecord->push_back(new G4SmoothTrajec 191 positionRecord->push_back(new G4SmoothTrajectoryPoint( 205 aStep->GetPostStepPoint()->GetPosition(), 192 aStep->GetPostStepPoint()->GetPosition(), aStep->GetPointerToVectorOfAuxiliaryPoints())); 206 } 193 } 207 194 208 G4ParticleDefinition* G4SmoothTrajectory::GetP 195 G4ParticleDefinition* G4SmoothTrajectory::GetParticleDefinition() 209 { 196 { 210 return (G4ParticleTable::GetParticleTable()- 197 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName)); 211 } 198 } 212 199 213 void G4SmoothTrajectory::MergeTrajectory(G4VTr 200 void G4SmoothTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) 214 { 201 { 215 if (secondTrajectory == nullptr) return; 202 if (secondTrajectory == nullptr) return; 216 203 217 auto seco = (G4SmoothTrajectory*)secondTraje 204 auto seco = (G4SmoothTrajectory*)secondTrajectory; 218 G4int ent = seco->GetPointEntries(); 205 G4int ent = seco->GetPointEntries(); 219 206 220 // initial point of the second trajectory sh 207 // initial point of the second trajectory should not be merged 221 // 208 // 222 for (G4int i = 1; i < ent; ++i) { 209 for (G4int i = 1; i < ent; ++i) { 223 positionRecord->push_back((*(seco->positio 210 positionRecord->push_back((*(seco->positionRecord))[i]); 224 } 211 } 225 delete (*seco->positionRecord)[0]; 212 delete (*seco->positionRecord)[0]; 226 seco->positionRecord->clear(); 213 seco->positionRecord->clear(); 227 } 214 } 228 215