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