#include "WCSimTrajectory.hh" #include "G4TrajectoryPoint.hh" #include "G4ParticleTable.hh" #include "G4AttDefStore.hh" #include "G4AttDef.hh" #include "G4AttValue.hh" #include "G4UnitsTable.hh" #include "G4VProcess.hh" #include "G4PhysicalConstants.hh" #include "G4SystemOfUnits.hh" #include //G4Allocator aTrajectoryAllocator; G4Allocator myTrajectoryAllocator; WCSimTrajectory::WCSimTrajectory() : positionRecord(0), fTrackID(0), fParentID(0), PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""), initialMomentum( G4ThreeVector() ),SaveIt(false),creatorProcess(""), globalTime(0.0) {;} WCSimTrajectory::WCSimTrajectory(const G4Track* aTrack) { G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition(); ParticleName = fpParticleDefinition->GetParticleName(); PDGCharge = fpParticleDefinition->GetPDGCharge(); PDGEncoding = fpParticleDefinition->GetPDGEncoding(); fTrackID = aTrack->GetTrackID(); fParentID = aTrack->GetParentID(); initialMomentum = aTrack->GetMomentum(); positionRecord = new TrajectoryPointContainer(); // Following is for the first trajectory point positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition())); stoppingPoint = aTrack->GetPosition(); stoppingVolume = aTrack->GetVolume(); if ( aTrack->GetUserInformation() != 0 ) SaveIt = true; else SaveIt = false; globalTime = aTrack->GetGlobalTime(); if (aTrack->GetCreatorProcess() != 0 ) { const G4VProcess* tempproc = aTrack->GetCreatorProcess(); creatorProcess = tempproc->GetProcessName(); } else creatorProcess = ""; } WCSimTrajectory::WCSimTrajectory(WCSimTrajectory & right):G4VTrajectory() { ParticleName = right.ParticleName; PDGCharge = right.PDGCharge; PDGEncoding = right.PDGEncoding; fTrackID = right.fTrackID; fParentID = right.fParentID; initialMomentum = right.initialMomentum; positionRecord = new TrajectoryPointContainer(); stoppingPoint = right.stoppingPoint; stoppingVolume = right.stoppingVolume; SaveIt = right.SaveIt; creatorProcess = right.creatorProcess; for(size_t i=0;isize();i++) { G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]); positionRecord->push_back(new G4TrajectoryPoint(*rightPoint)); } globalTime = right.globalTime; } WCSimTrajectory::~WCSimTrajectory() { // positionRecord->clearAndDestroy(); size_t i; for(i=0;isize();i++){ delete (*positionRecord)[i]; } positionRecord->clear(); delete positionRecord; } void WCSimTrajectory::ShowTrajectory(std::ostream& os) const { // Invoke the default implementation in G4VTrajectory... G4VTrajectory::ShowTrajectory(os); // ... or override with your own code here. } void WCSimTrajectory::DrawTrajectory(G4int i_mode) const { // Invoke the default implementation in G4VTrajectory... G4VTrajectory::DrawTrajectory(); // ... or override with your own code here. } const std::map* WCSimTrajectory::GetAttDefs() const { G4bool isNew; std::map* store = G4AttDefStore::GetInstance("WCSimTrajectory",isNew); if (isNew) { G4String ID("ID"); (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int"); G4String PID("PID"); (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int"); G4String PN("PN"); (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String"); G4String Ch("Ch"); (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","","G4double"); G4String PDG("PDG"); (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int"); G4String IMom("IMom"); (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics","","G4ThreeVector"); G4String NTP("NTP"); (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int"); } return store; } std::vector* WCSimTrajectory::CreateAttValues() const { char c[100]; //std::ostrstream s(c,100); std::ostringstream s(c); std::vector* values = new std::vector; s.seekp(std::ios::beg); s << fTrackID << std::ends; values->push_back(G4AttValue("ID",c,"")); s.seekp(std::ios::beg); s << fParentID << std::ends; values->push_back(G4AttValue("PID",c,"")); values->push_back(G4AttValue("PN",ParticleName,"")); s.seekp(std::ios::beg); s << PDGCharge << std::ends; values->push_back(G4AttValue("Ch",c,"")); s.seekp(std::ios::beg); s << PDGEncoding << std::ends; values->push_back(G4AttValue("PDG",c,"")); s.seekp(std::ios::beg); s << G4BestUnit(initialMomentum,"Energy") << std::ends; values->push_back(G4AttValue("IMom",c,"")); s.seekp(std::ios::beg); s << GetPointEntries() << std::ends; values->push_back(G4AttValue("NTP",c,"")); return values; } void WCSimTrajectory::AppendStep(const G4Step* aStep) { positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()-> GetPosition() )); } G4ParticleDefinition* WCSimTrajectory::GetParticleDefinition() { return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName)); } void WCSimTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) { if(!secondTrajectory) return; WCSimTrajectory* seco = (WCSimTrajectory*)secondTrajectory; stoppingPoint = seco->stoppingPoint; stoppingVolume = seco->stoppingVolume; G4int ent = seco->GetPointEntries(); for(G4int i=1;ipush_back((*(seco->positionRecord))[i]); // positionRecord->push_back(seco->positionRecord->removeAt(1)); } delete (*seco->positionRecord)[0]; seco->positionRecord->clear(); }