ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MCTSimEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4MCTSimEvent.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // G4MCTSimEvent.cc
27 //
28 // ====================================================================
29 #include "G4ios.hh"
30 #include "G4MCTSimEvent.hh"
31 #include "G4MCTSimParticle.hh"
32 #include "G4MCTSimVertex.hh"
33 
34 // ====================================================================
35 //
36 // class description
37 //
38 // ====================================================================
39 
43 {
44 }
45 
49 {
50  ClearEvent();
51 }
52 
56 {
57  G4MCTSimParticle* qpart= const_cast<G4MCTSimParticle*>(aparticle);
58  int trackID= aparticle-> GetTrackID();
59  int nc= particleMap.count(trackID);
60  if(nc==0) {
61  particleMap.insert(std::make_pair(trackID, qpart));
62  return true;
63  } else {
64  return false;
65  }
66 
67 }
68 
72 {
73  G4MCTSimParticleContainer::const_iterator pos= particleMap.find(tid);
74  if(pos != particleMap.end()) {
75  return pos-> second;
76  } else {
77  return 0;
78  }
79 }
80 
84 {
85  int nv= vertexVec.size();
86  if(vid>=1 && vid<=nv) {
87  return vertexVec[vid-1];
88  } else {
89  return 0;
90  }
91 }
92 
96 {
97  G4MCTSimParticleContainer::iterator itr;
98  int vid=1;
99  for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
100  G4MCTSimVertex* vertex= itr->second-> GetVertex();
101  if(vertex) {
102  if (vertex-> GetID()<0) { // ID not yet assigned
103  vertex-> SetID(vid);
104  vid++;
105  if (vertex) vertexVec.push_back(vertex);
106  }
107  }
108  }
109 }
110 
113 
114 {
115  G4MCTSimParticleContainer::iterator itr;
116  for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
117  delete itr->second;
118  }
119  particleMap.clear();
120 
121  G4MCTSimVertexContainer::iterator itrv;
122  for(itrv= vertexVec.begin(); itrv!= vertexVec.end(); ++itrv) {
123  delete (*itrv);
124  }
125  vertexVec.clear();
126 }
127 
128 
132 {
133  int n=0;
134  G4MCTSimParticleContainer::const_iterator itr;
135  for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
136  if(itr-> second-> GetStoreFlag()) n++;
137  }
138  return n;
139 }
140 
144 {
145  int n=0;
146  G4MCTSimVertexContainer::const_iterator itr;
147  for(itr= vertexVec.begin(); itr!= vertexVec.end(); ++itr) {
148  if((*itr)->GetStoreFlag()) n++;
149  }
150  return n;
151 }
152 
153 
155 void G4MCTSimEvent::Print(std::ostream& ostr) const
157 {
158  ostr << "____________________________________________________"
159  "____________________________" << G4endl;
160  ostr << "SimEvent:" << G4endl << G4endl;
161  ostr << "Current Memory Usage: "
162  << particleMap.size() << " particles, "
163  << vertexVec.size() << " vertices."
164  << G4endl;
165  ostr << "trk#<ptrk#: P(Px(GeV), Py, Pz, E ) @PDG %proc\n"
166  << " vtx#- X( X(mm), Y, Z, T(ns)) @vname-#"
167  << G4endl;
168  ostr << "____________________________________________________"
169  "____________________________" << G4endl;
170 
171  G4MCTSimParticleContainer::const_iterator itr;
172  for(itr= particleMap.begin(); itr!= particleMap.end(); ++itr) {
173  itr-> second-> PrintSingle(ostr);
174  }
175  ostr << "____________________________________________________"
176  "____________________________" << G4endl;
177 }