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
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
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
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
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
00200 if (!qrevorder) {
00201 SimParticleList::const_iterator itr;
00202 for(itr= associatedParticleList.begin();
00203 itr!= associatedParticleList.end(); ++itr) {
00204 (*itr)-> Print(ostr);
00205 }
00206 } else {
00207 if(parentParticle) parentParticle-> Print(ostr, true);
00208 }
00209 }