ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SDParticleFilter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SDParticleFilter.cc
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"
32 #include "G4ParticleDefinition.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 
46  :G4VSDFilter(name)
47 {
48  thePdef.clear();
49  theIonZ.clear();
50  theIonA.clear();
51 }
52 
54  const G4String& particleName)
55  :G4VSDFilter(name)
56 {
57  thePdef.clear();
59  if(!pd)
60  {
61  G4String msg = "Particle <";
62  msg += particleName;
63  msg += "> not found.";
64  G4Exception("G4SDParticleFilter::G4SDParticleFilter",
65  "DetPS0101",FatalException,msg);
66  }
67  thePdef.push_back(pd);
68  theIonZ.clear();
69  theIonA.clear();
70 }
71 
73  const std::vector<G4String>& particleNames)
74  :G4VSDFilter(name)
75 {
76  thePdef.clear();
77  for ( size_t i = 0; i < particleNames.size(); i++){
79  if(!pd)
80  {
81  G4String msg = "Particle <";
82  msg += particleNames[i];
83  msg += "> not found.";
84  G4Exception("G4SDParticleFilter::G4SDParticleFilter",
85  "DetPS0102",FatalException,msg);
86  }
87  thePdef.push_back(pd);
88  theIonZ.clear();
89  theIonA.clear();
90  }
91 }
92 
94  const std::vector<G4ParticleDefinition*>& particleDef)
95  :G4VSDFilter(name), thePdef(particleDef)
96 {
97  for ( size_t i = 0; i < particleDef.size(); i++){
98  if(!particleDef[i]) G4Exception("G4SDParticleFilter::G4SDParticleFilter",
99  "DetPS0103",FatalException,
100  "NULL pointer is found in the given particleDef vector.");
101  }
102  theIonZ.clear();
103  theIonA.clear();
104 }
105 
107 {
108  thePdef.clear();
109  theIonZ.clear();
110  theIonA.clear();
111  }
112 
114 {
115 
116  for ( size_t i = 0; i < thePdef.size(); i++){
117  if ( thePdef[i] == aStep->GetTrack()->GetDefinition() ) return TRUE;
118  }
119 
120  // Ions by Z,A
121  for ( size_t i = 0; i < theIonZ.size(); i++){
122  if ( theIonZ[i] == aStep->GetTrack()->GetDefinition()->GetAtomicNumber()
123  && theIonA[i] == aStep->GetTrack()->GetDefinition()->GetAtomicMass() ){
124  return TRUE;
125  }
126  }
127 
128  return FALSE;
129 }
130 
131 void G4SDParticleFilter::add(const G4String& particleName)
132 {
133  G4ParticleDefinition* pd =
135  if(!pd)
136  {
137  G4String msg = "Particle <";
138  msg += particleName;
139  msg += "> not found.";
140  G4Exception("G4SDParticleFilter::add()",
141  "DetPS0104",FatalException,msg);
142  }
143  for ( size_t i = 0; i < thePdef.size(); i++){
144  if ( thePdef[i] == pd ) return;
145  }
146  thePdef.push_back(pd);
147 }
148 
150  for ( size_t i = 0; i < theIonZ.size(); i++){
151  if ( theIonZ[i] == Z && theIonA[i] == A ){
152  G4cout << "G4SDParticleFilter:: Ion has been already registered."<<G4endl;
153  return;
154  }
155  }
156  theIonZ.push_back(Z);
157  theIonA.push_back(A);
158 }
159 
161  G4cout << "----G4SDParticleFileter particle list------"<<G4endl;
162  for ( size_t i = 0; i < thePdef.size(); i++){
163  G4cout << thePdef[i]->GetParticleName() << G4endl;
164  }
165  for ( size_t i = 0; i < theIonZ.size(); i++){
166  G4cout << " Ion PrtclDef (" << theIonZ[i]<<","<<theIonA[i]<<")"
167  << G4endl;
168  }
169  G4cout << "-------------------------------------------"<<G4endl;
170 }
171 
172 
173