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.cc |
---|
27 | // |
---|
28 | // ==================================================================== |
---|
29 | |
---|
30 | #include "globals.hh" |
---|
31 | #include <sstream> |
---|
32 | #include <iomanip> |
---|
33 | #include "G4ios.hh" |
---|
34 | #include "G4MCTSimParticle.hh" |
---|
35 | #include "G4MCTSimVertex.hh" |
---|
36 | |
---|
37 | // ==================================================================== |
---|
38 | // |
---|
39 | // class description |
---|
40 | // |
---|
41 | // ==================================================================== |
---|
42 | |
---|
43 | ///////////////////////////////// |
---|
44 | G4MCTSimParticle::G4MCTSimParticle() |
---|
45 | : parentParticle(0), pdgID(0), |
---|
46 | trackID(0), parentTrackID(0), |
---|
47 | primaryFlag(false), |
---|
48 | vertex(0), storeFlag(false) |
---|
49 | ///////////////////////////////// |
---|
50 | { |
---|
51 | } |
---|
52 | |
---|
53 | ///////////////////////////////////////////////////////////// |
---|
54 | G4MCTSimParticle::G4MCTSimParticle(std::string aname, int apcode, |
---|
55 | int atid, int ptid, |
---|
56 | const G4LorentzVector& p) |
---|
57 | : parentParticle(0), |
---|
58 | name(aname), pdgID(apcode), |
---|
59 | trackID(atid), parentTrackID(ptid), |
---|
60 | primaryFlag(false),momentumAtVertex(p), |
---|
61 | vertex(0), storeFlag(false) |
---|
62 | /////////////////////////////////////////////////////////////// |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | ///////////////////////////////////////////////////////////// |
---|
67 | G4MCTSimParticle::G4MCTSimParticle(std::string aname, int apcode, |
---|
68 | int atid, int ptid, |
---|
69 | const G4LorentzVector& p, |
---|
70 | const G4MCTSimVertex* v ) |
---|
71 | : parentParticle(0), |
---|
72 | name(aname), pdgID(apcode), |
---|
73 | trackID(atid), parentTrackID(ptid), |
---|
74 | primaryFlag(false),momentumAtVertex(p), |
---|
75 | vertex(const_cast<G4MCTSimVertex*>(v)), storeFlag(false) |
---|
76 | /////////////////////////////////////////////////////////////// |
---|
77 | { |
---|
78 | } |
---|
79 | |
---|
80 | ///////////////////////////////// |
---|
81 | G4MCTSimParticle::~G4MCTSimParticle() |
---|
82 | ///////////////////////////////// |
---|
83 | { |
---|
84 | associatedParticleList.clear(); |
---|
85 | } |
---|
86 | |
---|
87 | //////////////////////////////////////////////////////// |
---|
88 | int G4MCTSimParticle::AssociateParticle(G4MCTSimParticle* p) |
---|
89 | //////////////////////////////////////////////////////// |
---|
90 | { |
---|
91 | associatedParticleList.push_back(p); |
---|
92 | p-> SetParentParticle(this); |
---|
93 | return associatedParticleList.size(); |
---|
94 | } |
---|
95 | |
---|
96 | ///////////////////////////////////////////////////// |
---|
97 | int G4MCTSimParticle::GetNofAssociatedParticles() const |
---|
98 | ///////////////////////////////////////////////////// |
---|
99 | { |
---|
100 | return associatedParticleList.size(); |
---|
101 | } |
---|
102 | |
---|
103 | ////////////////////////////////////////////////////////////////// |
---|
104 | G4MCTSimParticle* G4MCTSimParticle::GetAssociatedParticle(int i) const |
---|
105 | ////////////////////////////////////////////////////////////////// |
---|
106 | { |
---|
107 | int size= associatedParticleList.size(); |
---|
108 | if(i>=0 && i< size) return associatedParticleList[i]; |
---|
109 | else return 0; |
---|
110 | } |
---|
111 | |
---|
112 | //////////////////////////////////////// |
---|
113 | int G4MCTSimParticle::GetTreeLevel() const |
---|
114 | //////////////////////////////////////// |
---|
115 | { |
---|
116 | const G4MCTSimParticle* p= this; |
---|
117 | int nlevel; |
---|
118 | for(nlevel=1;;nlevel++) { |
---|
119 | p= p-> GetParentParticle(); |
---|
120 | if(p==0) return nlevel; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | ///////////////////////////////////////////////////// |
---|
125 | void G4MCTSimParticle::SetStoreFlagToParentTree(G4bool q) |
---|
126 | ///////////////////////////////////////////////////// |
---|
127 | { |
---|
128 | storeFlag=q; |
---|
129 | if(vertex) vertex-> SetStoreFlag(q); |
---|
130 | if(primaryFlag) return; |
---|
131 | if(parentParticle) parentParticle-> SetStoreFlagToParentTree(q); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | ////////////////////////////////////////////////////////// |
---|
136 | void G4MCTSimParticle::PrintSingle(std::ostream& ostr) const |
---|
137 | ////////////////////////////////////////////////////////// |
---|
138 | { |
---|
139 | std::ostringstream os; |
---|
140 | char cqp=' '; |
---|
141 | if(storeFlag) cqp='+'; |
---|
142 | os << cqp << trackID << '\0'; |
---|
143 | std::string stid(os.str()); |
---|
144 | ostr << std::setw(6) << stid; |
---|
145 | //ostr << std::setw(4) << trackID; |
---|
146 | |
---|
147 | if(primaryFlag) ostr << "*"; |
---|
148 | else ostr << " "; |
---|
149 | ostr << "<" << std::setw(5) << parentTrackID; |
---|
150 | ostr.setf(std::ios::fixed); |
---|
151 | ostr << ": P(" |
---|
152 | << std::setw(7) << std::setprecision(3) << momentumAtVertex.x()/GeV |
---|
153 | << "," << std::setw(7) << std::setprecision(3) |
---|
154 | << momentumAtVertex.y()/GeV |
---|
155 | << "," << std::setw(7) << std::setprecision(3) |
---|
156 | << momentumAtVertex.z()/GeV |
---|
157 | << "," << std::setw(7) << std::setprecision(3) |
---|
158 | << momentumAtVertex.e()/GeV << ") @"; |
---|
159 | ostr << name << "(" << pdgID << ")"; |
---|
160 | |
---|
161 | if(vertex) { |
---|
162 | ostr << " %" << vertex-> GetCreatorProcessName() << G4endl; |
---|
163 | |
---|
164 | std::ostringstream osv; |
---|
165 | char cqv=' '; |
---|
166 | if(vertex->GetStoreFlag()) cqv='+'; |
---|
167 | osv << cqv << vertex-> GetID() << '\0'; |
---|
168 | std::string svid(osv.str()); |
---|
169 | ostr << " " << std::setw(6) << svid; |
---|
170 | //ostr << " " << std::setw(4) << vertex-> GetID(); |
---|
171 | ostr.unsetf(std::ios::fixed); |
---|
172 | ostr.setf(std::ios::scientific|std::ios::right|std::ios::showpoint); |
---|
173 | ostr << "- X(" << std::setw(9) << std::setprecision(2) |
---|
174 | << vertex-> GetPosition().x()/mm |
---|
175 | << "," << std::setw(9) << std::setprecision(2) |
---|
176 | << vertex-> GetPosition().y()/mm |
---|
177 | << "," << std::setw(9) << std::setprecision(2) |
---|
178 | << vertex-> GetPosition().z()/mm |
---|
179 | << "," << std::setw(9) << std::setprecision(2) |
---|
180 | << vertex-> GetTime()/ns << ")"; |
---|
181 | ostr.unsetf(std::ios::scientific); |
---|
182 | |
---|
183 | ostr << " @" << vertex-> GetVolumeName() |
---|
184 | << "-" << vertex-> GetVolumeNumber(); |
---|
185 | } |
---|
186 | ostr << G4endl; |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | //////////////////////////////////////////////////////////////////// |
---|
191 | void G4MCTSimParticle::Print(std::ostream& ostr, G4bool qrevorder) const |
---|
192 | //////////////////////////////////////////////////////////////////// |
---|
193 | { |
---|
194 | PrintSingle(ostr); |
---|
195 | |
---|
196 | // recursively print associated particles |
---|
197 | if (!qrevorder) { // parent -> child |
---|
198 | SimParticleList::const_iterator itr; |
---|
199 | for(itr= associatedParticleList.begin(); |
---|
200 | itr!= associatedParticleList.end(); ++itr) { |
---|
201 | (*itr)-> Print(ostr); |
---|
202 | } |
---|
203 | } else { // child -> parent |
---|
204 | if(parentParticle) parentParticle-> Print(ostr, true); |
---|
205 | } |
---|
206 | } |
---|