G4MCTSimEvent.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //   G4MCTSimEvent.cc
00027 //
00028 // ====================================================================
00029 #include "G4ios.hh"
00030 #include "G4MCTSimEvent.hh"
00031 #include "G4MCTSimParticle.hh"
00032 #include "G4MCTSimVertex.hh"
00033 
00034 // ====================================================================
00035 //
00036 // class description
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) { // ID not yet assigned
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 }

Generated on Mon May 27 17:48:51 2013 for Geant4 by  doxygen 1.4.7