Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4SmoothTrajectory class implementation << 23 // >> 24 // $Id: G4SmoothTrajectory.cc,v 1.8 2002/11/11 13:13:02 johna Exp $ >> 25 // GEANT4 tag $Name: geant4-05-01 $ >> 26 // >> 27 // >> 28 // --------------------------------------------------------------- >> 29 // >> 30 // G4SmoothTrajectory.cc 27 // 31 // 28 // Contact: 32 // Contact: 29 // Questions and comments to this code shoul 33 // Questions and comments to this code should be sent to 30 // Katsuya Amako (e-mail: Katsuya.Amako@k 34 // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) 31 // Makoto Asai (e-mail: asai@slac.stanf << 35 // Makoto Asai (e-mail: asai@kekvax.kek.jp) 32 // Takashi Sasaki (e-mail: Takashi.Sasaki@ 36 // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) 33 // ------------------------------------------- << 37 // >> 38 // --------------------------------------------------------------- 34 39 35 #include "G4SmoothTrajectory.hh" << 36 #include "G4ClonedSmoothTrajectory.hh" << 37 40 38 #include "G4AttDef.hh" << 41 #include "G4SmoothTrajectory.hh" >> 42 #include "G4SmoothTrajectoryPoint.hh" >> 43 #include "G4ParticleTable.hh" 39 #include "G4AttDefStore.hh" 44 #include "G4AttDefStore.hh" >> 45 #include "G4AttDef.hh" 40 #include "G4AttValue.hh" 46 #include "G4AttValue.hh" 41 #include "G4ParticleTable.hh" << 42 #include "G4SmoothTrajectoryPoint.hh" << 43 #include "G4UIcommand.hh" << 44 #include "G4UnitsTable.hh" 47 #include "G4UnitsTable.hh" 45 #include "G4AutoLock.hh" << 48 #include "g4std/strstream" 46 49 47 namespace { << 50 G4Allocator<G4SmoothTrajectory> aSmoothTrajectoryAllocator; 48 G4Mutex CloneSmoothTrajectoryMutex = G4MUTEX_ << 49 } << 50 << 51 // #define G4ATTDEBUG << 52 #ifdef G4ATTDEBUG << 53 # include "G4AttCheck.hh" << 54 #endif << 55 51 56 G4Allocator<G4SmoothTrajectory>*& aSmoothTraje << 52 G4SmoothTrajectory::G4SmoothTrajectory() 57 { << 53 : positionRecord(0), fTrackID(0), fParentID(0), 58 G4ThreadLocalStatic G4Allocator<G4SmoothTraj << 54 PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""), 59 return _instance; << 55 initialMomentum( G4ThreeVector() ) 60 } << 56 {;} 61 57 62 G4SmoothTrajectory::G4SmoothTrajectory(const G 58 G4SmoothTrajectory::G4SmoothTrajectory(const G4Track* aTrack) 63 { 59 { 64 G4ParticleDefinition* fpParticleDefinition = << 60 G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition(); 65 ParticleName = fpParticleDefinition->GetPart << 61 ParticleName = fpParticleDefinition->GetParticleName(); 66 PDGCharge = fpParticleDefinition->GetPDGChar << 62 PDGCharge = fpParticleDefinition->GetPDGCharge(); 67 PDGEncoding = fpParticleDefinition->GetPDGEn << 63 PDGEncoding = fpParticleDefinition->GetPDGEncoding(); 68 fTrackID = aTrack->GetTrackID(); << 64 fTrackID = aTrack->GetTrackID(); 69 fParentID = aTrack->GetParentID(); << 65 fParentID = aTrack->GetParentID(); 70 initialKineticEnergy = aTrack->GetKineticEne << 66 initialMomentum = aTrack->GetMomentum(); 71 initialMomentum = aTrack->GetMomentum(); << 67 positionRecord = new TrajectoryPointContainer(); 72 positionRecord = new G4TrajectoryPointContai << 68 // Following is for the first trajectory point 73 << 69 positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition())); 74 // Following is for the first trajectory poi << 70 75 // << 71 // The first point has no auxiliary points, so set the auxiliary 76 positionRecord->push_back(new G4SmoothTrajec << 72 // points vector to NULL (jacek 31/10/2002) 77 << 73 positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition(), NULL)); 78 // The first point has no auxiliary points, << 79 // points vector to NULL << 80 // << 81 positionRecord->push_back(new G4SmoothTrajec << 82 } 74 } 83 75 84 G4SmoothTrajectory::G4SmoothTrajectory(G4Smoot << 76 G4SmoothTrajectory::G4SmoothTrajectory(G4SmoothTrajectory & right) 85 { 77 { 86 ParticleName = right.ParticleName; 78 ParticleName = right.ParticleName; 87 PDGCharge = right.PDGCharge; 79 PDGCharge = right.PDGCharge; 88 PDGEncoding = right.PDGEncoding; 80 PDGEncoding = right.PDGEncoding; 89 fTrackID = right.fTrackID; 81 fTrackID = right.fTrackID; 90 fParentID = right.fParentID; 82 fParentID = right.fParentID; 91 initialKineticEnergy = right.initialKineticE << 92 initialMomentum = right.initialMomentum; 83 initialMomentum = right.initialMomentum; 93 positionRecord = new G4TrajectoryPointContai << 84 positionRecord = new TrajectoryPointContainer(); 94 85 95 for (auto& i : *right.positionRecord) { << 86 for(size_t i=0;i<right.positionRecord->size();i++) 96 auto rightPoint = (G4SmoothTrajectoryPoint << 87 { >> 88 G4SmoothTrajectoryPoint* rightPoint = (G4SmoothTrajectoryPoint*)((*(right.positionRecord))[i]); 97 positionRecord->push_back(new G4SmoothTraj 89 positionRecord->push_back(new G4SmoothTrajectoryPoint(*rightPoint)); 98 } 90 } 99 } 91 } 100 92 101 G4VTrajectory* G4SmoothTrajectory::CloneForMas << 102 { << 103 G4AutoLock lock(&CloneSmoothTrajectoryMutex) << 104 auto* cloned = new G4ClonedSmoothTrajectory( << 105 return cloned; << 106 } << 107 << 108 G4SmoothTrajectory::~G4SmoothTrajectory() 93 G4SmoothTrajectory::~G4SmoothTrajectory() 109 { 94 { 110 if (positionRecord != nullptr) { << 95 // positionRecord->clearAndDestroy(); 111 for (auto& i : *positionRecord) { << 96 size_t i; 112 delete i; << 97 for(i=0;i<positionRecord->size();i++){ 113 } << 98 delete (*positionRecord)[i]; 114 positionRecord->clear(); << 115 delete positionRecord; << 116 } 99 } >> 100 positionRecord->clear(); >> 101 >> 102 delete positionRecord; 117 } 103 } 118 104 119 void G4SmoothTrajectory::ShowTrajectory(std::o << 105 void G4SmoothTrajectory::ShowTrajectory(G4std::ostream& os) const 120 { 106 { 121 // Invoke the default implementation in G4VT 107 // Invoke the default implementation in G4VTrajectory... 122 // << 123 G4VTrajectory::ShowTrajectory(os); 108 G4VTrajectory::ShowTrajectory(os); 124 << 125 // ... or override with your own code here. 109 // ... or override with your own code here. 126 } 110 } 127 111 128 void G4SmoothTrajectory::DrawTrajectory() cons << 112 void G4SmoothTrajectory::DrawTrajectory(G4int i_mode) const 129 { 113 { 130 // Invoke the default implementation in G4VT 114 // Invoke the default implementation in G4VTrajectory... 131 // << 115 G4VTrajectory::DrawTrajectory(i_mode); 132 G4VTrajectory::DrawTrajectory(); << 133 << 134 // ... or override with your own code here. 116 // ... or override with your own code here. 135 } 117 } 136 118 137 const std::map<G4String, G4AttDef>* G4SmoothTr << 119 const G4std::map<G4String,G4AttDef>* G4SmoothTrajectory::GetAttDefs() const 138 { 120 { 139 G4bool isNew; 121 G4bool isNew; 140 std::map<G4String, G4AttDef>* store = G4AttD << 122 G4std::map<G4String,G4AttDef>* store >> 123 = G4AttDefStore::GetInstance("G4SmoothTrajectory",isNew); 141 if (isNew) { 124 if (isNew) { >> 125 142 G4String ID("ID"); 126 G4String ID("ID"); 143 (*store)[ID] = G4AttDef(ID, "Track ID", "P << 127 (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int"); 144 128 145 G4String PID("PID"); 129 G4String PID("PID"); 146 (*store)[PID] = G4AttDef(PID, "Parent ID", << 130 (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int"); 147 131 148 G4String PN("PN"); 132 G4String PN("PN"); 149 (*store)[PN] = G4AttDef(PN, "Particle Name << 133 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String"); 150 134 151 G4String Ch("Ch"); 135 G4String Ch("Ch"); 152 (*store)[Ch] = G4AttDef(Ch, "Charge", "Phy << 136 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","","G4double"); 153 137 154 G4String PDG("PDG"); 138 G4String PDG("PDG"); 155 (*store)[PDG] = G4AttDef(PDG, "PDG Encodin << 139 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int"); 156 << 157 G4String IKE("IKE"); << 158 (*store)[IKE] = G4AttDef(IKE, "Initial kin << 159 140 160 G4String IMom("IMom"); 141 G4String IMom("IMom"); 161 (*store)[IMom] = G4AttDef(IMom, "Initial m << 142 (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", 162 << 143 "Physics","","G4ThreeVector"); 163 G4String IMag("IMag"); << 164 (*store)[IMag] = << 165 G4AttDef(IMag, "Initial momentum magnitu << 166 144 167 G4String NTP("NTP"); 145 G4String NTP("NTP"); 168 (*store)[NTP] = G4AttDef(NTP, "No. of poin << 146 (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int"); >> 147 169 } 148 } 170 return store; 149 return store; 171 } 150 } 172 151 173 std::vector<G4AttValue>* G4SmoothTrajectory::C << 174 { << 175 auto values = new std::vector<G4AttValue>; << 176 << 177 values->push_back(G4AttValue("ID", G4UIcomma << 178 152 179 values->push_back(G4AttValue("PID", G4UIcomm << 153 G4std::vector<G4AttValue>* G4SmoothTrajectory::CreateAttValues() const >> 154 { >> 155 char c[100]; >> 156 G4std::ostrstream s(c,100); 180 157 181 values->push_back(G4AttValue("PN", ParticleN << 158 G4std::vector<G4AttValue>* values = new G4std::vector<G4AttValue>; 182 159 183 values->push_back(G4AttValue("Ch", G4UIcomma << 160 s.seekp(G4std::ios::beg); >> 161 s << fTrackID << G4std::ends; >> 162 values->push_back(G4AttValue("ID",c,"")); 184 163 185 values->push_back(G4AttValue("PDG", G4UIcomm << 164 s.seekp(G4std::ios::beg); >> 165 s << fParentID << G4std::ends; >> 166 values->push_back(G4AttValue("PID",c,"")); 186 167 187 values->push_back(G4AttValue("IKE", G4BestUn << 168 values->push_back(G4AttValue("PN",ParticleName,"")); 188 169 189 values->push_back(G4AttValue("IMom", G4BestU << 170 s.seekp(G4std::ios::beg); >> 171 s << PDGCharge << G4std::ends; >> 172 values->push_back(G4AttValue("Ch",c,"")); 190 173 191 values->push_back(G4AttValue("IMag", G4BestU << 174 s.seekp(G4std::ios::beg); >> 175 s << PDGEncoding << G4std::ends; >> 176 values->push_back(G4AttValue("PDG",c,"")); 192 177 193 values->push_back(G4AttValue("NTP", G4UIcomm << 178 s.seekp(G4std::ios::beg); >> 179 s << G4BestUnit(initialMomentum,"Energy") << G4std::ends; >> 180 values->push_back(G4AttValue("IMom",c,"")); 194 181 195 #ifdef G4ATTDEBUG << 182 s.seekp(G4std::ios::beg); 196 G4cout << G4AttCheck(values, GetAttDefs()); << 183 s << GetPointEntries() << G4std::ends; 197 #endif << 184 values->push_back(G4AttValue("NTP",c,"")); 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 // (jacek 30/10/2002) 205 aStep->GetPostStepPoint()->GetPosition(), << 192 positionRecord->push_back( >> 193 new G4SmoothTrajectoryPoint(aStep->GetPostStepPoint()->GetPosition(), >> 194 aStep->GetPointerToVectorOfAuxiliaryPoints())); 206 } 195 } 207 << 196 208 G4ParticleDefinition* G4SmoothTrajectory::GetP 197 G4ParticleDefinition* G4SmoothTrajectory::GetParticleDefinition() 209 { 198 { 210 return (G4ParticleTable::GetParticleTable()- << 199 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName)); 211 } 200 } 212 201 213 void G4SmoothTrajectory::MergeTrajectory(G4VTr 202 void G4SmoothTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) 214 { 203 { 215 if (secondTrajectory == nullptr) return; << 204 if(!secondTrajectory) return; 216 205 217 auto seco = (G4SmoothTrajectory*)secondTraje << 206 G4SmoothTrajectory* seco = (G4SmoothTrajectory*)secondTrajectory; 218 G4int ent = seco->GetPointEntries(); 207 G4int ent = seco->GetPointEntries(); 219 << 208 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 << 209 { 221 // << 222 for (G4int i = 1; i < ent; ++i) { << 223 positionRecord->push_back((*(seco->positio 210 positionRecord->push_back((*(seco->positionRecord))[i]); >> 211 // positionRecord->push_back(seco->positionRecord->removeAt(1)); 224 } 212 } 225 delete (*seco->positionRecord)[0]; 213 delete (*seco->positionRecord)[0]; 226 seco->positionRecord->clear(); 214 seco->positionRecord->clear(); 227 } 215 } >> 216 >> 217 228 218