source: trunk/source/digits_hits/scorer/src/G4SDParticleFilter.cc @ 814

Last change on this file since 814 was 814, checked in by garnier, 16 years ago

import all except CVS

File size: 4.7 KB
Line 
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.1 2007/07/11 01:31:03 asaim 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
47G4SDParticleFilter::G4SDParticleFilter(G4String name)
48  :G4VSDFilter(name)
49{
50  thePdef.clear();
51}
52
53G4SDParticleFilter::G4SDParticleFilter(G4String name,
54                                       const G4String& particleName)
55  :G4VSDFilter(name)
56{
57  thePdef.clear();
58  G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
59  if(!pd)
60  {
61    G4String msg = "Particle <";
62    msg += particleName;
63    msg += "> not found.";
64    G4Exception("G4SDParticleFilter::G4SDParticleFilter()",
65                "DetUtil0000",FatalException,msg);
66  }
67  thePdef.push_back(pd);
68}
69
70G4SDParticleFilter::G4SDParticleFilter(G4String name, 
71                               const std::vector<G4String>& particleNames)
72  :G4VSDFilter(name)
73{
74  thePdef.clear();
75  for ( size_t i = 0; i < particleNames.size(); i++){
76   G4ParticleDefinition* pd = G4ParticleTable::GetParticleTable()->FindParticle(particleNames[i]);
77   if(!pd)
78   {
79     G4String msg = "Particle <";
80     msg += particleNames[i];
81     msg += "> not found.";
82     G4Exception("G4SDParticleFilter::G4SDParticleFilter()",
83                "DetUtil0000",FatalException,msg);
84   }
85   thePdef.push_back(pd);
86  }
87}
88
89G4SDParticleFilter::G4SDParticleFilter(G4String name, 
90                       const std::vector<G4ParticleDefinition*>& particleDef)
91  :G4VSDFilter(name), thePdef(particleDef)
92{
93  for ( size_t i = 0; i < particleDef.size(); i++){
94    if(!particleDef[i]) G4Exception("G4SDParticleFilter::G4SDParticleFilter()","DetUtil0001",FatalException,
95       "NULL pointer is found in the given particleDef vector.");
96  }
97}
98
99G4SDParticleFilter::~G4SDParticleFilter()
100{ 
101  thePdef.clear();
102}
103
104G4bool G4SDParticleFilter::Accept(const G4Step* aStep) const
105{
106  for ( size_t i = 0; i < thePdef.size(); i++){
107    if ( thePdef[i] == aStep->GetTrack()->GetDefinition() ) return TRUE;
108  }
109  return FALSE;
110}
111
112void G4SDParticleFilter::add(const G4String& particleName)
113{
114  G4ParticleDefinition* pd = 
115    G4ParticleTable::GetParticleTable()->FindParticle(particleName);
116  if(!pd)
117  {
118     G4String msg = "Particle <";
119     msg += particleName;
120     msg += "> not found.";
121     G4Exception("G4SDParticleFilter::add()",
122                "DetUtil0002",FatalException,msg);
123  }
124  for ( size_t i = 0; i < thePdef.size(); i++){
125    if ( thePdef[i] == pd ) return;
126  }
127  thePdef.push_back(pd);
128}
129
130void G4SDParticleFilter::show(){
131  G4cout << "----G4SDParticleFileter particle list------"<<G4endl;
132  for ( size_t i = 0; i < thePdef.size(); i++){
133    G4cout << thePdef[i]->GetParticleName() << G4endl;
134  }
135  G4cout << "-------------------------------------------"<<G4endl;
136}
137
138
139
Note: See TracBrowser for help on using the repository browser.