00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "G4SDParticleFilter.hh"
00031 #include "G4Step.hh"
00032 #include "G4ParticleTable.hh"
00033 #include "G4ParticleDefinition.hh"
00034
00036
00037
00038
00039
00040
00041
00042
00043
00045
00046 G4SDParticleFilter::G4SDParticleFilter(G4String name)
00047 :G4VSDFilter(name)
00048 {
00049 thePdef.clear();
00050 theIonZ.clear();
00051 theIonA.clear();
00052 }
00053
00054 G4SDParticleFilter::G4SDParticleFilter(G4String name,
00055 const G4String& particleName)
00056 :G4VSDFilter(name)
00057 {
00058 thePdef.clear();
00059 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
00060 if(!pd)
00061 {
00062 G4String msg = "Particle <";
00063 msg += particleName;
00064 msg += "> not found.";
00065 G4Exception("G4SDParticleFilter::G4SDParticleFilter",
00066 "DetPS0101",FatalException,msg);
00067 }
00068 thePdef.push_back(pd);
00069 theIonZ.clear();
00070 theIonA.clear();
00071 }
00072
00073 G4SDParticleFilter::G4SDParticleFilter(G4String name,
00074 const std::vector<G4String>& particleNames)
00075 :G4VSDFilter(name)
00076 {
00077 thePdef.clear();
00078 for ( size_t i = 0; i < particleNames.size(); i++){
00079 G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleNames[i]);
00080 if(!pd)
00081 {
00082 G4String msg = "Particle <";
00083 msg += particleNames[i];
00084 msg += "> not found.";
00085 G4Exception("G4SDParticleFilter::G4SDParticleFilter",
00086 "DetPS0102",FatalException,msg);
00087 }
00088 thePdef.push_back(pd);
00089 theIonZ.clear();
00090 theIonA.clear();
00091 }
00092 }
00093
00094 G4SDParticleFilter::G4SDParticleFilter(G4String name,
00095 const std::vector<G4ParticleDefinition*>& particleDef)
00096 :G4VSDFilter(name), thePdef(particleDef)
00097 {
00098 for ( size_t i = 0; i < particleDef.size(); i++){
00099 if(!particleDef[i]) G4Exception("G4SDParticleFilter::G4SDParticleFilter",
00100 "DetPS0103",FatalException,
00101 "NULL pointer is found in the given particleDef vector.");
00102 }
00103 theIonZ.clear();
00104 theIonA.clear();
00105 }
00106
00107 G4SDParticleFilter::~G4SDParticleFilter()
00108 {
00109 thePdef.clear();
00110 theIonZ.clear();
00111 theIonA.clear();
00112 }
00113
00114 G4bool G4SDParticleFilter::Accept(const G4Step* aStep) const
00115 {
00116
00117 for ( size_t i = 0; i < thePdef.size(); i++){
00118 if ( thePdef[i] == aStep->GetTrack()->GetDefinition() ) return TRUE;
00119 }
00120
00121
00122 for ( size_t i = 0; i < theIonZ.size(); i++){
00123 if ( theIonZ[i] == aStep->GetTrack()->GetDefinition()->GetAtomicNumber()
00124 && theIonA[i] == aStep->GetTrack()->GetDefinition()->GetAtomicMass() ){
00125 return TRUE;
00126 }
00127 }
00128
00129 return FALSE;
00130 }
00131
00132 void G4SDParticleFilter::add(const G4String& particleName)
00133 {
00134 G4ParticleDefinition* pd =
00135 G4ParticleTable::GetParticleTable()->FindParticle(particleName);
00136 if(!pd)
00137 {
00138 G4String msg = "Particle <";
00139 msg += particleName;
00140 msg += "> not found.";
00141 G4Exception("G4SDParticleFilter::add()",
00142 "DetPS0104",FatalException,msg);
00143 }
00144 for ( size_t i = 0; i < thePdef.size(); i++){
00145 if ( thePdef[i] == pd ) return;
00146 }
00147 thePdef.push_back(pd);
00148 }
00149
00150 void G4SDParticleFilter::addIon(G4int Z, G4int A){
00151 for ( size_t i = 0; i < theIonZ.size(); i++){
00152 if ( theIonZ[i] == Z && theIonA[i] == A ){
00153 G4cout << "G4SDParticleFilter:: Ion has been already registered."<<G4endl;
00154 return;
00155 }
00156 }
00157 theIonZ.push_back(Z);
00158 theIonA.push_back(A);
00159 }
00160
00161 void G4SDParticleFilter::show(){
00162 G4cout << "----G4SDParticleFileter particle list------"<<G4endl;
00163 for ( size_t i = 0; i < thePdef.size(); i++){
00164 G4cout << thePdef[i]->GetParticleName() << G4endl;
00165 }
00166 for ( size_t i = 0; i < theIonZ.size(); i++){
00167 G4cout << " Ion PrtclDef (" << theIonZ[i]<<","<<theIonA[i]<<")"
00168 << G4endl;
00169 }
00170 G4cout << "-------------------------------------------"<<G4endl;
00171 }
00172
00173
00174