G4MCTSimParticle.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 //   G4MCTSimParticle.cc
00027 //
00028 // ====================================================================
00029 
00030 #include <sstream>
00031 #include <iomanip>
00032 
00033 #include "G4MCTSimParticle.hh"
00034 
00035 #include "globals.hh"
00036 #include "G4SystemOfUnits.hh"
00037 #include "G4ios.hh"
00038 #include "G4MCTSimVertex.hh"
00039 
00040 // ====================================================================
00041 //
00042 // class description
00043 //
00044 // ====================================================================
00045 
00047 G4MCTSimParticle::G4MCTSimParticle()
00048   : parentParticle(0), pdgID(0),
00049     trackID(0), parentTrackID(0),
00050     primaryFlag(false), 
00051     vertex(0), storeFlag(false)
00053 {
00054 }
00055 
00057 G4MCTSimParticle::G4MCTSimParticle(std::string aname, int apcode, 
00058                                int atid, int ptid,
00059                                const G4LorentzVector& p)
00060   : parentParticle(0), 
00061     name(aname), pdgID(apcode), 
00062     trackID(atid), parentTrackID(ptid),
00063     primaryFlag(false),momentumAtVertex(p),
00064     vertex(0), storeFlag(false)
00066 {
00067 }
00068 
00070 G4MCTSimParticle::G4MCTSimParticle(std::string aname, int apcode, 
00071                                int atid, int ptid,
00072                                const G4LorentzVector& p,
00073                                const G4MCTSimVertex* v )
00074   : parentParticle(0), 
00075     name(aname), pdgID(apcode), 
00076     trackID(atid), parentTrackID(ptid),
00077     primaryFlag(false),momentumAtVertex(p), 
00078     vertex(const_cast<G4MCTSimVertex*>(v)), storeFlag(false)
00080 {
00081 }
00082 
00084 G4MCTSimParticle::~G4MCTSimParticle()
00086 {
00087   associatedParticleList.clear();
00088 }
00089 
00091 int G4MCTSimParticle::AssociateParticle(G4MCTSimParticle* p)
00093 {
00094   associatedParticleList.push_back(p);
00095   p-> SetParentParticle(this);
00096   return associatedParticleList.size();
00097 }
00098 
00100 int G4MCTSimParticle::GetNofAssociatedParticles() const
00102 {
00103   return associatedParticleList.size();
00104 }
00105 
00107 G4MCTSimParticle* G4MCTSimParticle::GetAssociatedParticle(int i) const
00109 {
00110   int size= associatedParticleList.size();
00111   if(i>=0 && i< size) return associatedParticleList[i];
00112   else return 0;
00113 }
00114 
00116 int G4MCTSimParticle::GetTreeLevel() const
00118 {
00119   const G4MCTSimParticle* p= this;
00120   int nlevel;
00121   for(nlevel=1;;nlevel++) {
00122     p= p-> GetParentParticle();
00123     if(p==0) return nlevel;
00124   }
00125 }
00126 
00128 void G4MCTSimParticle::SetStoreFlagToParentTree(G4bool q)
00130 {
00131   storeFlag=q;
00132   if(vertex) vertex-> SetStoreFlag(q);
00133   if(primaryFlag) return;
00134   if(parentParticle) parentParticle-> SetStoreFlagToParentTree(q);
00135 }
00136 
00137 
00139 void G4MCTSimParticle::PrintSingle(std::ostream& ostr) const
00141 {
00142   std::ostringstream os;
00143   char cqp=' ';
00144   if(storeFlag) cqp='+';
00145   os << cqp << trackID << '\0';
00146   std::string stid(os.str());
00147   ostr << std::setw(6) << stid;
00148   //ostr << std::setw(4) << trackID;
00149 
00150   if(primaryFlag) ostr << "*";
00151   else ostr << " ";
00152   ostr << "<" << std::setw(5) << parentTrackID;
00153   ostr.setf(std::ios::fixed);
00154   ostr << ": P(" 
00155       << std::setw(7) << std::setprecision(3) << momentumAtVertex.x()/GeV 
00156       << "," << std::setw(7) << std::setprecision(3) 
00157       << momentumAtVertex.y()/GeV  
00158       << "," << std::setw(7) << std::setprecision(3) 
00159       << momentumAtVertex.z()/GeV 
00160       << "," << std::setw(7) << std::setprecision(3) 
00161       << momentumAtVertex.e()/GeV << ") @";
00162   ostr << name << "(" << pdgID << ")";
00163 
00164   if(vertex) {
00165     ostr << " %" << vertex-> GetCreatorProcessName() << G4endl;
00166 
00167     std::ostringstream osv;
00168     char cqv=' ';
00169     if(vertex->GetStoreFlag()) cqv='+';
00170     osv << cqv << vertex-> GetID() << '\0';
00171     std::string svid(osv.str());
00172     ostr << "       " << std::setw(6) << svid;
00173     //ostr << "      " << std::setw(4) << vertex-> GetID();
00174     ostr.unsetf(std::ios::fixed);
00175     ostr.setf(std::ios::scientific|std::ios::right|std::ios::showpoint);
00176     ostr << "- X(" << std::setw(9) << std::setprecision(2) 
00177         << vertex-> GetPosition().x()/mm 
00178         << "," << std::setw(9) << std::setprecision(2) 
00179         << vertex-> GetPosition().y()/mm
00180         << "," << std::setw(9) << std::setprecision(2) 
00181         << vertex-> GetPosition().z()/mm 
00182         << "," << std::setw(9) << std::setprecision(2) 
00183         << vertex-> GetTime()/ns << ")";
00184     ostr.unsetf(std::ios::scientific);
00185     
00186     ostr << " @" << vertex-> GetVolumeName()
00187         << "-" << vertex-> GetVolumeNumber();
00188   } 
00189   ostr << G4endl;
00190   
00191 }
00192 
00194 void G4MCTSimParticle::Print(std::ostream& ostr, G4bool qrevorder) const
00196 {
00197   PrintSingle(ostr);
00198 
00199   // recursively print associated particles
00200   if (!qrevorder) { // parent -> child
00201     SimParticleList::const_iterator itr;
00202     for(itr= associatedParticleList.begin(); 
00203         itr!= associatedParticleList.end(); ++itr) {
00204       (*itr)-> Print(ostr);
00205     }
00206   } else { // child -> parent
00207     if(parentParticle) parentParticle-> Print(ostr, true);
00208   }
00209 }

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