source: trunk/source/persistency/mctruth/src/G4MCTSimEvent.cc @ 1098

Last change on this file since 1098 was 818, checked in by garnier, 16 years ago

import all except CVS

File size: 5.8 KB
Line 
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
40//////////////////////////
41G4MCTSimEvent::G4MCTSimEvent()
42//////////////////////////
43{
44}
45
46///////////////////////////
47G4MCTSimEvent::~G4MCTSimEvent()
48///////////////////////////
49{
50  ClearEvent();
51}
52
53//////////////////////////////////////////////////////////////
54G4bool G4MCTSimEvent::AddParticle(const G4MCTSimParticle* aparticle)
55//////////////////////////////////////////////////////////////
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
69////////////////////////////////////////////////////////
70G4MCTSimParticle* G4MCTSimEvent::FindParticle(int tid) const
71////////////////////////////////////////////////////////
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
81///////////////////////////////////////////////////
82G4MCTSimVertex* G4MCTSimEvent::GetVertex(int vid) const
83///////////////////////////////////////////////////
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
93////////////////////////////////////////
94void G4MCTSimEvent::BuildVertexContainer()
95////////////////////////////////////////
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
111//////////////////////////////
112void G4MCTSimEvent::ClearEvent() 
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
129//////////////////////////////////////////////
130int G4MCTSimEvent::GetNofStoredParticles() const
131//////////////////////////////////////////////
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
141/////////////////////////////////////////////
142int G4MCTSimEvent::GetNofStoredVertices() const
143/////////////////////////////////////////////
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
154/////////////////////////////////////////////////
155void G4MCTSimEvent::Print(std::ostream& ostr) const
156/////////////////////////////////////////////////
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}
Note: See TracBrowser for help on using the repository browser.