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 | // $Id: G4SDParticleFilter.cc,v 1.2 2010/07/23 00:59:58 taso Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // G4VSensitiveDetector |
---|
31 | #include "G4SDParticleFilter.hh" |
---|
32 | #include "G4Step.hh" |
---|
33 | #include "G4ParticleTable.hh" |
---|
34 | #include "G4ParticleDefinition.hh" |
---|
35 | |
---|
36 | //////////////////////////////////////////////////////////////////////////////// |
---|
37 | // class description: |
---|
38 | // |
---|
39 | // This is the class of a filter to be associated with a |
---|
40 | // sensitive detector. |
---|
41 | // This class filters steps by partilce definition. |
---|
42 | // |
---|
43 | // Created: 2005-11-14 Tsukasa ASO. |
---|
44 | // |
---|
45 | /////////////////////////////////////////////////////////////////////////////// |
---|
46 | |
---|
47 | G4SDParticleFilter::G4SDParticleFilter(G4String name) |
---|
48 | :G4VSDFilter(name) |
---|
49 | { |
---|
50 | thePdef.clear(); |
---|
51 | theIonZ.clear(); |
---|
52 | theIonA.clear(); |
---|
53 | } |
---|
54 | |
---|
55 | G4SDParticleFilter::G4SDParticleFilter(G4String name, |
---|
56 | const G4String& particleName) |
---|
57 | :G4VSDFilter(name) |
---|
58 | { |
---|
59 | thePdef.clear(); |
---|
60 | G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleName); |
---|
61 | if(!pd) |
---|
62 | { |
---|
63 | G4String msg = "Particle <"; |
---|
64 | msg += particleName; |
---|
65 | msg += "> not found."; |
---|
66 | G4Exception("G4SDParticleFilter::G4SDParticleFilter()", |
---|
67 | "DetUtil0000",FatalException,msg); |
---|
68 | } |
---|
69 | thePdef.push_back(pd); |
---|
70 | theIonZ.clear(); |
---|
71 | theIonA.clear(); |
---|
72 | } |
---|
73 | |
---|
74 | G4SDParticleFilter::G4SDParticleFilter(G4String name, |
---|
75 | const std::vector<G4String>& particleNames) |
---|
76 | :G4VSDFilter(name) |
---|
77 | { |
---|
78 | thePdef.clear(); |
---|
79 | for ( size_t i = 0; i < particleNames.size(); i++){ |
---|
80 | G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleNames[i]); |
---|
81 | if(!pd) |
---|
82 | { |
---|
83 | G4String msg = "Particle <"; |
---|
84 | msg += particleNames[i]; |
---|
85 | msg += "> not found."; |
---|
86 | G4Exception("G4SDParticleFilter::G4SDParticleFilter()", |
---|
87 | "DetUtil0000",FatalException,msg); |
---|
88 | } |
---|
89 | thePdef.push_back(pd); |
---|
90 | theIonZ.clear(); |
---|
91 | theIonA.clear(); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | G4SDParticleFilter::G4SDParticleFilter(G4String name, |
---|
96 | const std::vector<G4ParticleDefinition*>& particleDef) |
---|
97 | :G4VSDFilter(name), thePdef(particleDef) |
---|
98 | { |
---|
99 | for ( size_t i = 0; i < particleDef.size(); i++){ |
---|
100 | if(!particleDef[i]) G4Exception("G4SDParticleFilter::G4SDParticleFilter()","DetUtil0001",FatalException, |
---|
101 | "NULL pointer is found in the given particleDef vector."); |
---|
102 | } |
---|
103 | theIonZ.clear(); |
---|
104 | theIonA.clear(); |
---|
105 | } |
---|
106 | |
---|
107 | G4SDParticleFilter::~G4SDParticleFilter() |
---|
108 | { |
---|
109 | thePdef.clear(); |
---|
110 | theIonZ.clear(); |
---|
111 | theIonA.clear(); |
---|
112 | } |
---|
113 | |
---|
114 | G4bool G4SDParticleFilter::Accept(const G4Step* aStep) const |
---|
115 | { |
---|
116 | |
---|
117 | for ( size_t i = 0; i < thePdef.size(); i++){ |
---|
118 | if ( thePdef[i] == aStep->GetTrack()->GetDefinition() ) return TRUE; |
---|
119 | } |
---|
120 | |
---|
121 | // Ions by Z,A |
---|
122 | for ( size_t i = 0; i < theIonZ.size(); i++){ |
---|
123 | if ( theIonZ[i] == aStep->GetTrack()->GetDefinition()->GetAtomicNumber() |
---|
124 | && theIonA[i] == aStep->GetTrack()->GetDefinition()->GetAtomicMass() ){ |
---|
125 | return TRUE; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | return FALSE; |
---|
130 | } |
---|
131 | |
---|
132 | void G4SDParticleFilter::add(const G4String& particleName) |
---|
133 | { |
---|
134 | G4ParticleDefinition* pd = |
---|
135 | G4ParticleTable::GetParticleTable()->FindParticle(particleName); |
---|
136 | if(!pd) |
---|
137 | { |
---|
138 | G4String msg = "Particle <"; |
---|
139 | msg += particleName; |
---|
140 | msg += "> not found."; |
---|
141 | G4Exception("G4SDParticleFilter::add()", |
---|
142 | "DetUtil0002",FatalException,msg); |
---|
143 | } |
---|
144 | for ( size_t i = 0; i < thePdef.size(); i++){ |
---|
145 | if ( thePdef[i] == pd ) return; |
---|
146 | } |
---|
147 | thePdef.push_back(pd); |
---|
148 | } |
---|
149 | |
---|
150 | void G4SDParticleFilter::addIon(G4int Z, G4int A){ |
---|
151 | for ( size_t i = 0; i < theIonZ.size(); i++){ |
---|
152 | if ( theIonZ[i] == Z && theIonA[i] == A ){ |
---|
153 | G4cout << "G4SDParticleFilter:: Ion has been already registered."<<G4endl; |
---|
154 | return; |
---|
155 | } |
---|
156 | } |
---|
157 | theIonZ.push_back(Z); |
---|
158 | theIonA.push_back(A); |
---|
159 | } |
---|
160 | |
---|
161 | void G4SDParticleFilter::show(){ |
---|
162 | G4cout << "----G4SDParticleFileter particle list------"<<G4endl; |
---|
163 | for ( size_t i = 0; i < thePdef.size(); i++){ |
---|
164 | G4cout << thePdef[i]->GetParticleName() << G4endl; |
---|
165 | } |
---|
166 | for ( size_t i = 0; i < theIonZ.size(); i++){ |
---|
167 | G4cout << " Ion PrtclDef (" << theIonZ[i]<<","<<theIonA[i]<<")" |
---|
168 | << G4endl; |
---|
169 | } |
---|
170 | G4cout << "-------------------------------------------"<<G4endl; |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | |
---|