Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4MCTSimParticle implementation 27 // 28 // Author: Youhei Morita, 12.09.2001 29 // ------------------------------------------- 30 31 #include <sstream> 32 #include <iomanip> 33 34 #include "G4MCTSimParticle.hh" 35 36 #include "globals.hh" 37 #include "G4SystemOfUnits.hh" 38 #include "G4ios.hh" 39 #include "G4MCTSimVertex.hh" 40 41 // ------------------------------------------- 42 G4MCTSimParticle::G4MCTSimParticle() 43 { 44 } 45 46 // ------------------------------------------- 47 G4MCTSimParticle::G4MCTSimParticle(const G4Str 48 G4int apcod 49 const G4Lor 50 : name(aname) 51 , momentumAtVertex(p) 52 , pdgID(apcode) 53 , trackID(atid) 54 , parentTrackID(ptid) 55 { 56 } 57 58 // ------------------------------------------- 59 G4MCTSimParticle::G4MCTSimParticle(const G4Str 60 G4int apcod 61 const G4Lor 62 const G4MCT 63 : name(aname) 64 , momentumAtVertex(p) 65 , vertex(const_cast<G4MCTSimVertex*>(v)) 66 , pdgID(apcode) 67 , trackID(atid) 68 , parentTrackID(ptid) 69 { 70 } 71 72 // ------------------------------------------- 73 G4MCTSimParticle::~G4MCTSimParticle() 74 { 75 associatedParticleList.clear(); 76 } 77 78 // ------------------------------------------- 79 G4int G4MCTSimParticle::AssociateParticle(G4MC 80 { 81 associatedParticleList.push_back(p); 82 p->SetParentParticle(this); 83 return (G4int)associatedParticleList.size(); 84 } 85 86 // ------------------------------------------- 87 G4int G4MCTSimParticle::GetNofAssociatedPartic 88 { 89 return (G4int)associatedParticleList.size(); 90 } 91 92 // ------------------------------------------- 93 G4MCTSimParticle* G4MCTSimParticle::GetAssocia 94 { 95 G4int size = (G4int)associatedParticleList.s 96 if(i >= 0 && i < size) 97 return associatedParticleList[i]; 98 else 99 return nullptr; 100 } 101 102 // ------------------------------------------- 103 G4int G4MCTSimParticle::GetTreeLevel() const 104 { 105 const G4MCTSimParticle* p = this; 106 G4int nlevel; 107 for(nlevel = 1;; ++nlevel) 108 { 109 p = p->GetParentParticle(); 110 if(p == nullptr) 111 return nlevel; 112 } 113 } 114 115 // ------------------------------------------- 116 void G4MCTSimParticle::SetStoreFlagToParentTre 117 { 118 storeFlag = q; 119 if(vertex) 120 vertex->SetStoreFlag(q); 121 if(primaryFlag) 122 return; 123 if(parentParticle) 124 parentParticle->SetStoreFlagToParentTree(q 125 } 126 127 // ------------------------------------------- 128 void G4MCTSimParticle::PrintSingle(std::ostrea 129 { 130 std::ostringstream os; 131 char cqp = ' '; 132 if(storeFlag) 133 cqp = '+'; 134 os << cqp << trackID << '\0'; 135 std::string stid(os.str()); 136 ostr << std::setw(6) << stid; 137 // ostr << std::setw(4) << trackID; 138 139 if(primaryFlag) 140 ostr << "*"; 141 else 142 ostr << " "; 143 ostr << "<" << std::setw(5) << parentTrackID 144 ostr.setf(std::ios::fixed); 145 ostr << ": P(" << std::setw(7) << std::setpr 146 << momentumAtVertex.x() / GeV << "," << 147 << std::setprecision(3) << momentumAtVe 148 << std::setw(7) << std::setprecision(3) 149 << "," << std::setw(7) << std::setpreci 150 << momentumAtVertex.e() / GeV << ") @"; 151 ostr << name << "(" << pdgID << ")"; 152 153 if(vertex != nullptr) 154 { 155 ostr << " %" << vertex->GetCreatorProcessN 156 157 std::ostringstream osv; 158 char cqv = ' '; 159 if(vertex->GetStoreFlag()) 160 cqv = '+'; 161 osv << cqv << vertex->GetID() << '\0'; 162 std::string svid(osv.str()); 163 ostr << " " << std::setw(6) << svid; 164 // ostr << " " << std::setw(4) << ver 165 ostr.unsetf(std::ios::fixed); 166 ostr.setf(std::ios::scientific | std::ios: 167 ostr << "- X(" << std::setw(9) << std::set 168 << vertex->GetPosition().x() / mm << 169 << std::setprecision(2) << vertex->Ge 170 << std::setw(9) << std::setprecision( 171 << vertex->GetPosition().z() / mm << 172 << std::setprecision(2) << vertex->Ge 173 ostr.unsetf(std::ios::scientific); 174 175 ostr << " @" << vertex->GetVolumeName() << 176 } 177 ostr << G4endl; 178 } 179 180 // ------------------------------------------- 181 void G4MCTSimParticle::Print(std::ostream& ost 182 { 183 PrintSingle(ostr); 184 185 // recursively print associated particles 186 if(!qrevorder) 187 { // parent -> child 188 for(auto itr = associatedParticleList.cbeg 189 itr != associatedParticleList.cend(); 190 { 191 (*itr)->Print(ostr); 192 } 193 } 194 else 195 { // child -> parent 196 if(parentParticle) 197 parentParticle->Print(ostr, true); 198 } 199 } 200