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