Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
34////////////////////////////////////////////////////////////////////////////////
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//
43///////////////////////////////////////////////////////////////////////////////
44
48
50 const G4String& particleName)
51 : G4VSDFilter(name)
52{
55 if(pd == nullptr)
56 {
57 G4String msg = "Particle <";
58 msg += particleName;
59 msg += "> not found.";
60 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0101",
61 FatalException, msg);
62 }
63 thePdef.push_back(pd);
64}
65
67 G4String name, const std::vector<G4String>& particleNames)
68 : G4VSDFilter(name)
69{
70 for(const auto & particleName : particleNames)
71 {
74 if(pd == nullptr)
75 {
76 G4String msg = "Particle <";
77 msg += particleName;
78 msg += "> not found.";
79 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0102",
80 FatalException, msg);
81 }
82 thePdef.push_back(pd);
83 }
84}
85
87 G4String name, const std::vector<G4ParticleDefinition*>& particleDef)
88 : G4VSDFilter(name)
89 , thePdef(particleDef)
90{
91 for(auto i : particleDef)
92 {
93 if(i == nullptr)
94 G4Exception("G4SDParticleFilter::G4SDParticleFilter", "DetPS0103",
96 "NULL pointer is found in the given particleDef vector.");
97 }
98}
99
101{
102 for(auto i : thePdef)
103 {
104 if(i == aStep->GetTrack()->GetDefinition())
105 return true;
106 }
107
108 // Ions by Z,A
109 for(size_t i = 0; i < theIonZ.size(); i++)
110 {
111 if(theIonZ[i] == aStep->GetTrack()->GetDefinition()->GetAtomicNumber() &&
112 theIonA[i] == aStep->GetTrack()->GetDefinition()->GetAtomicMass())
113 {
114 return true;
115 }
116 }
117
118 return false;
119}
120
121void G4SDParticleFilter::add(const G4String& particleName)
122{
125 if(pd == nullptr)
126 {
127 G4String msg = "Particle <";
128 msg += particleName;
129 msg += "> not found.";
130 G4Exception("G4SDParticleFilter::add()", "DetPS0104", FatalException, msg);
131 }
132 for(auto & i : thePdef)
133 {
134 if(i == pd)
135 return;
136 }
137 thePdef.push_back(pd);
138}
139
141{
142 for(size_t i = 0; i < theIonZ.size(); i++)
143 {
144 if(theIonZ[i] == Z && theIonA[i] == A)
145 {
146 G4cout << "G4SDParticleFilter:: Ion has been already registered."
147 << G4endl;
148 return;
149 }
150 }
151 theIonZ.push_back(Z);
152 theIonA.push_back(A);
153}
154
156{
157 G4cout << "----G4SDParticleFileter particle list------" << G4endl;
158 for(auto & i : thePdef)
159 {
160 G4cout << i->GetParticleName() << G4endl;
161 }
162 for(size_t i = 0; i < theIonZ.size(); i++)
163 {
164 G4cout << " Ion PrtclDef (" << theIonZ[i] << "," << theIonA[i] << ")"
165 << G4endl;
166 }
167 G4cout << "-------------------------------------------" << G4endl;
168}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4double A[17]
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4int GetAtomicNumber() const
G4int GetAtomicMass() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
G4bool Accept(const G4Step *) const override
G4SDParticleFilter(G4String name)
void addIon(G4int Z, G4int A)
void add(const G4String &particleName)
G4Track * GetTrack() const
G4ParticleDefinition * GetDefinition() const