G4SDParticleFilter.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // G4VSensitiveDetector
00030 #include "G4SDParticleFilter.hh"
00031 #include "G4Step.hh"
00032 #include "G4ParticleTable.hh"
00033 #include "G4ParticleDefinition.hh"
00034 
00036 // class description:
00037 //
00038 //  This is the class of a filter to be associated with a
00039 // sensitive detector. 
00040 //  This class filters steps by partilce definition.
00041 //
00042 // Created: 2005-11-14  Tsukasa ASO.
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   // Ions by Z,A
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 

Generated on Mon May 27 17:49:49 2013 for Geant4 by  doxygen 1.4.7