00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "G4ios.hh"
00030 #include "G4MCTSimEvent.hh"
00031 #include "G4MCTSimParticle.hh"
00032 #include "G4MCTSimVertex.hh"
00033
00034
00035
00036
00037
00038
00039
00041 G4MCTSimEvent::G4MCTSimEvent()
00043 {
00044 }
00045
00047 G4MCTSimEvent::~G4MCTSimEvent()
00049 {
00050 ClearEvent();
00051 }
00052
00054 G4bool G4MCTSimEvent::AddParticle(const G4MCTSimParticle* aparticle)
00056 {
00057 G4MCTSimParticle* qpart= const_cast<G4MCTSimParticle*>(aparticle);
00058 int trackID= aparticle-> GetTrackID();
00059 int nc= particleMap.count(trackID);
00060 if(nc==0) {
00061 particleMap.insert(std::make_pair(trackID, qpart));
00062 return true;
00063 } else {
00064 return false;
00065 }
00066
00067 }
00068
00070 G4MCTSimParticle* G4MCTSimEvent::FindParticle(int tid) const
00072 {
00073 G4MCTSimParticleContainer::const_iterator pos= particleMap.find(tid);
00074 if(pos != particleMap.end()) {
00075 return pos-> second;
00076 } else {
00077 return 0;
00078 }
00079 }
00080
00082 G4MCTSimVertex* G4MCTSimEvent::GetVertex(int vid) const
00084 {
00085 int nv= vertexVec.size();
00086 if(vid>=1 && vid<=nv) {
00087 return vertexVec[vid-1];
00088 } else {
00089 return 0;
00090 }
00091 }
00092
00094 void G4MCTSimEvent::BuildVertexContainer()
00096 {
00097 G4MCTSimParticleContainer::iterator itr;
00098 int vid=1;
00099 for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
00100 G4MCTSimVertex* vertex= itr->second-> GetVertex();
00101 if(vertex) {
00102 if (vertex-> GetID()<0) {
00103 vertex-> SetID(vid);
00104 vid++;
00105 if (vertex) vertexVec.push_back(vertex);
00106 }
00107 }
00108 }
00109 }
00110
00112 void G4MCTSimEvent::ClearEvent()
00113
00114 {
00115 G4MCTSimParticleContainer::iterator itr;
00116 for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
00117 delete itr->second;
00118 }
00119 particleMap.clear();
00120
00121 G4MCTSimVertexContainer::iterator itrv;
00122 for(itrv= vertexVec.begin(); itrv!= vertexVec.end(); ++itrv) {
00123 delete (*itrv);
00124 }
00125 vertexVec.clear();
00126 }
00127
00128
00130 int G4MCTSimEvent::GetNofStoredParticles() const
00132 {
00133 int n=0;
00134 G4MCTSimParticleContainer::const_iterator itr;
00135 for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
00136 if(itr-> second-> GetStoreFlag()) n++;
00137 }
00138 return n;
00139 }
00140
00142 int G4MCTSimEvent::GetNofStoredVertices() const
00144 {
00145 int n=0;
00146 G4MCTSimVertexContainer::const_iterator itr;
00147 for(itr= vertexVec.begin(); itr!= vertexVec.end(); ++itr) {
00148 if((*itr)->GetStoreFlag()) n++;
00149 }
00150 return n;
00151 }
00152
00153
00155 void G4MCTSimEvent::Print(std::ostream& ostr) const
00157 {
00158 ostr << "____________________________________________________"
00159 "____________________________" << G4endl;
00160 ostr << "SimEvent:" << G4endl << G4endl;
00161 ostr << "Current Memory Usage: "
00162 << particleMap.size() << " particles, "
00163 << vertexVec.size() << " vertices."
00164 << G4endl;
00165 ostr << "trk#<ptrk#: P(Px(GeV), Py, Pz, E ) @PDG %proc\n"
00166 << " vtx#- X( X(mm), Y, Z, T(ns)) @vname-#"
00167 << G4endl;
00168 ostr << "____________________________________________________"
00169 "____________________________" << G4endl;
00170
00171 G4MCTSimParticleContainer::const_iterator itr;
00172 for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
00173 itr-> second-> PrintSingle(ostr);
00174 }
00175 ostr << "____________________________________________________"
00176 "____________________________" << G4endl;
00177 }