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