Geant4-11
G4SDParticleFilter.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//
27//
28// G4VSensitiveDetector
29#include "G4SDParticleFilter.hh"
30#include "G4Step.hh"
31#include "G4ParticleTable.hh"
33
35// class description:
36//
37// This is the class of a filter to be associated with a
38// sensitive detector.
39// This class filters steps by partilce definition.
40//
41// Created: 2005-11-14 Tsukasa ASO.
42//
44
47{
48 thePdef.clear();
49 theIonZ.clear();
50 theIonA.clear();
51}
52
54 const G4String& particleName)
56{
57 thePdef.clear();
60 if(!pd)
61 {
62 G4String msg = "Particle <";
63 msg += particleName;
64 msg += "> not found.";
65 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0101",
66 FatalException, msg);
67 }
68 thePdef.push_back(pd);
69 theIonZ.clear();
70 theIonA.clear();
71}
72
74 G4String name, const std::vector<G4String>& particleNames)
76{
77 thePdef.clear();
78 for(size_t i = 0; i < particleNames.size(); i++)
79 {
82 if(!pd)
83 {
84 G4String msg = "Particle <";
85 msg += particleNames[i];
86 msg += "> not found.";
87 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0102",
88 FatalException, msg);
89 }
90 thePdef.push_back(pd);
91 theIonZ.clear();
92 theIonA.clear();
93 }
94}
95
97 G4String name, const std::vector<G4ParticleDefinition*>& particleDef)
99 , thePdef(particleDef)
100{
101 for(size_t i = 0; i < particleDef.size(); i++)
102 {
103 if(!particleDef[i])
104 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0103",
106 "NULL pointer is found in the given particleDef vector.");
107 }
108 theIonZ.clear();
109 theIonA.clear();
110}
111
113{
114 thePdef.clear();
115 theIonZ.clear();
116 theIonA.clear();
117}
118
120{
121 for(size_t i = 0; i < thePdef.size(); i++)
122 {
123 if(thePdef[i] == aStep->GetTrack()->GetDefinition())
124 return TRUE;
125 }
126
127 // Ions by Z,A
128 for(size_t i = 0; i < theIonZ.size(); i++)
129 {
130 if(theIonZ[i] == aStep->GetTrack()->GetDefinition()->GetAtomicNumber() &&
131 theIonA[i] == aStep->GetTrack()->GetDefinition()->GetAtomicMass())
132 {
133 return TRUE;
134 }
135 }
136
137 return FALSE;
138}
139
140void G4SDParticleFilter::add(const G4String& particleName)
141{
144 if(!pd)
145 {
146 G4String msg = "Particle <";
147 msg += particleName;
148 msg += "> not found.";
149 G4Exception("G4SDParticleFilter::add()", "DetPS0104", FatalException, msg);
150 }
151 for(size_t i = 0; i < thePdef.size(); i++)
152 {
153 if(thePdef[i] == pd)
154 return;
155 }
156 thePdef.push_back(pd);
157}
158
160{
161 for(size_t i = 0; i < theIonZ.size(); i++)
162 {
163 if(theIonZ[i] == Z && theIonA[i] == A)
164 {
165 G4cout << "G4SDParticleFilter:: Ion has been already registered."
166 << G4endl;
167 return;
168 }
169 }
170 theIonZ.push_back(Z);
171 theIonA.push_back(A);
172}
173
175{
176 G4cout << "----G4SDParticleFileter particle list------" << G4endl;
177 for(size_t i = 0; i < thePdef.size(); i++)
178 {
179 G4cout << thePdef[i]->GetParticleName() << G4endl;
180 }
181 for(size_t i = 0; i < theIonZ.size(); i++)
182 {
183 G4cout << " Ion PrtclDef (" << theIonZ[i] << "," << theIonA[i] << ")"
184 << G4endl;
185 }
186 G4cout << "-------------------------------------------" << G4endl;
187}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
const G4int Z[17]
const G4double A[17]
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
G4int GetAtomicNumber() const
G4int GetAtomicMass() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
std::vector< G4int > theIonZ
G4SDParticleFilter(G4String name)
void addIon(G4int Z, G4int A)
std::vector< G4int > theIonA
void add(const G4String &particleName)
virtual G4bool Accept(const G4Step *) const
std::vector< G4ParticleDefinition * > thePdef
Definition: G4Step.hh:62
G4Track * GetTrack() const
G4ParticleDefinition * GetDefinition() const
const char * name(G4int ptype)