Geant4-11
G4MCTSimParticle.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
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// --------------------------------------------------------------------
43{
44}
45
46// --------------------------------------------------------------------
48 G4int apcode, G4int atid, G4int ptid,
49 const G4LorentzVector& p)
50 : name(aname)
51 , momentumAtVertex(p)
52 , pdgID(apcode)
53 , trackID(atid)
54 , parentTrackID(ptid)
55{
56}
57
58// --------------------------------------------------------------------
60 G4int apcode, G4int atid, G4int ptid,
61 const G4LorentzVector& p,
62 const G4MCTSimVertex* v)
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// --------------------------------------------------------------------
74{
76}
77
78// --------------------------------------------------------------------
80{
81 associatedParticleList.push_back(p);
82 p->SetParentParticle(this);
83 return associatedParticleList.size();
84}
85
86// --------------------------------------------------------------------
88{
89 return associatedParticleList.size();
90}
91
92// --------------------------------------------------------------------
94{
95 G4int size = associatedParticleList.size();
96 if(i >= 0 && i < size)
97 return associatedParticleList[i];
98 else
99 return nullptr;
100}
101
102// --------------------------------------------------------------------
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// --------------------------------------------------------------------
117{
118 storeFlag = q;
119 if(vertex)
121 if(primaryFlag)
122 return;
125}
126
127// --------------------------------------------------------------------
128void G4MCTSimParticle::PrintSingle(std::ostream& ostr) const
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::setprecision(3)
146 << momentumAtVertex.x() / GeV << "," << std::setw(7)
147 << std::setprecision(3) << momentumAtVertex.y() / GeV << ","
148 << std::setw(7) << std::setprecision(3) << momentumAtVertex.z() / GeV
149 << "," << std::setw(7) << std::setprecision(3)
150 << momentumAtVertex.e() / GeV << ") @";
151 ostr << name << "(" << pdgID << ")";
152
153 if(vertex != nullptr)
154 {
155 ostr << " %" << vertex->GetCreatorProcessName() << G4endl;
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) << vertex-> GetID();
165 ostr.unsetf(std::ios::fixed);
166 ostr.setf(std::ios::scientific | std::ios::right | std::ios::showpoint);
167 ostr << "- X(" << std::setw(9) << std::setprecision(2)
168 << vertex->GetPosition().x() / mm << "," << std::setw(9)
169 << std::setprecision(2) << vertex->GetPosition().y() / mm << ","
170 << std::setw(9) << std::setprecision(2)
171 << vertex->GetPosition().z() / mm << "," << std::setw(9)
172 << std::setprecision(2) << vertex->GetTime() / ns << ")";
173 ostr.unsetf(std::ios::scientific);
174
175 ostr << " @" << vertex->GetVolumeName() << "-" << vertex->GetVolumeNumber();
176 }
177 ostr << G4endl;
178}
179
180// --------------------------------------------------------------------
181void G4MCTSimParticle::Print(std::ostream& ostr, G4bool qrevorder) const
182{
183 PrintSingle(ostr);
184
185 // recursively print associated particles
186 if(!qrevorder)
187 { // parent -> child
188 for(auto itr = associatedParticleList.cbegin();
189 itr != associatedParticleList.cend(); ++itr)
190 {
191 (*itr)->Print(ostr);
192 }
193 }
194 else
195 { // child -> parent
197 parentParticle->Print(ostr, true);
198 }
199}
static constexpr double mm
Definition: G4SIunits.hh:95
static constexpr double GeV
Definition: G4SIunits.hh:203
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
double z() const
double x() const
double y() const
G4MCTSimParticle * GetParentParticle() const
void Print(std::ostream &ostr=std::cout, G4bool qrevorder=false) const
void SetStoreFlagToParentTree(G4bool q=true)
virtual ~G4MCTSimParticle()
G4MCTSimParticle * parentParticle
G4MCTSimParticle * GetAssociatedParticle(G4int i) const
G4LorentzVector momentumAtVertex
G4int GetTreeLevel() const
void SetParentParticle(const G4MCTSimParticle *p)
G4MCTSimVertex * vertex
void PrintSingle(std::ostream &ostr=std::cout) const
G4int AssociateParticle(G4MCTSimParticle *p)
G4int GetNofAssociatedParticles() const
std::vector< G4MCTSimParticle * > associatedParticleList
void SetStoreFlag(G4bool q)
G4int GetVolumeNumber() const
const G4ThreeVector & GetPosition() const
G4double GetTime() const
const G4String & GetCreatorProcessName() const
G4int GetID() const
const G4String & GetVolumeName() const
G4bool GetStoreFlag() const
const char * name(G4int ptype)
#define ns
Definition: xmlparse.cc:614