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