Geant4-11
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
G4TrajectoryChargeFilter Class Reference

#include <G4TrajectoryChargeFilter.hh>

Inheritance diagram for G4TrajectoryChargeFilter:
G4SmartFilter< G4VTrajectory > G4VFilter< G4VTrajectory >

Public Types

typedef G4VTrajectory Type
 

Public Member Functions

G4bool Accept (const G4VTrajectory &) const
 
void Add (const G4String &particle)
 
virtual void Clear ()
 
virtual bool Evaluate (const G4VTrajectory &) const
 
 G4TrajectoryChargeFilter (const G4String &name="Unspecified")
 
G4bool GetActive () const
 
G4bool GetInvert () const
 
G4String GetName () const
 
G4bool GetVerbose () const
 
G4String Name () const
 
virtual void Print (std::ostream &ostr) const
 
virtual void PrintAll (std::ostream &ostr) const
 
virtual void Reset ()
 
void SetActive (const G4bool &)
 
void SetInvert (const G4bool &)
 
void SetVerbose (const G4bool &)
 
virtual ~G4TrajectoryChargeFilter ()
 

Private Types

enum  MyCharge { Negative =-1 , Neutral =0 , Positive =1 }
 

Private Member Functions

void Add (const MyCharge &chgear)
 
G4bool ConvertToCharge (const G4String &, MyCharge &)
 

Private Attributes

G4bool fActive
 
std::vector< MyChargefCharges
 
G4bool fInvert
 
G4String fName
 
size_t fNPassed
 
size_t fNProcessed
 
G4bool fVerbose
 

Detailed Description

Definition at line 39 of file G4TrajectoryChargeFilter.hh.

Member Typedef Documentation

◆ Type

Definition at line 43 of file G4VFilter.hh.

Member Enumeration Documentation

◆ MyCharge

Constructor & Destructor Documentation

◆ G4TrajectoryChargeFilter()

G4TrajectoryChargeFilter::G4TrajectoryChargeFilter ( const G4String name = "Unspecified")

◆ ~G4TrajectoryChargeFilter()

G4TrajectoryChargeFilter::~G4TrajectoryChargeFilter ( )
virtual

Definition at line 39 of file G4TrajectoryChargeFilter.cc.

39{}

Member Function Documentation

◆ Accept()

G4bool G4SmartFilter< G4VTrajectory >::Accept ( const G4VTrajectory object) const
virtualinherited

Implements G4VFilter< G4VTrajectory >.

Definition at line 57 of file G4SmartFilter.hh.

105{
106 if (fVerbose) {
107 G4cout<<"Begin verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
108 G4cout<<"Active ? : "<<fActive<<G4endl;
109 }
110
111 fNProcessed++;
112
113 // Pass everything if filter is not active
114 if (!fActive) {
115 fNPassed++;
116 return true;
117 }
118
119 // Do filtering
120 G4bool passed = Evaluate(object);
121
122 // Apply inversion if applicable
123 if (fInvert) passed = !passed;
124
125 if (passed) fNPassed++;
126
127 if (fVerbose) {
128 G4cout<<"Inverted ? : "<<fInvert<<G4endl;
129 G4cout<<"Passed ? : "<<passed<<G4endl;
130 G4cout<<"End verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
131 }
132
133 return passed;
134}
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual G4bool Evaluate(const G4VTrajectory &) const=0
G4String Name() const
Definition: G4VFilter.hh:80

◆ Add() [1/2]

void G4TrajectoryChargeFilter::Add ( const G4String particle)

Definition at line 63 of file G4TrajectoryChargeFilter.cc.

64{
65 MyCharge myCharge;
66
67 if (!ConvertToCharge(charge, myCharge)) {
69 ed << "Invalid charge "<<charge;
71 ("G4TrajectoryChargeFilter::Add(const G4String& charge)",
72 "modeling0115", JustWarning, ed);
73 return;
74 }
75
76 return Add(myCharge);
77}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4bool ConvertToCharge(const G4String &, MyCharge &)
void Add(const G4String &particle)

References Add(), ConvertToCharge(), G4Exception(), and JustWarning.

Referenced by Add().

◆ Add() [2/2]

void G4TrajectoryChargeFilter::Add ( const MyCharge chgear)
private

Definition at line 80 of file G4TrajectoryChargeFilter.cc.

81{
82 fCharges.push_back(charge);
83}
std::vector< MyCharge > fCharges

References fCharges.

◆ Clear()

void G4TrajectoryChargeFilter::Clear ( )
virtual

Implements G4SmartFilter< G4VTrajectory >.

Definition at line 98 of file G4TrajectoryChargeFilter.cc.

99{
100 // Clear registered charge vector
101 fCharges.clear();
102}

References fCharges.

◆ ConvertToCharge()

G4bool G4TrajectoryChargeFilter::ConvertToCharge ( const G4String string,
MyCharge myCharge 
)
private

Definition at line 105 of file G4TrajectoryChargeFilter.cc.

106{
107 bool result(true);
108
109 G4int charge;
110 std::istringstream is(string.c_str());
111 is >> charge;
112
113 switch (charge) {
114 case 1:
116 break;
117 case 0:
119 break;
120 case -1:
122 break;
123 default:
124 result = false;
125 }
126
127 return result;
128}
int G4int
Definition: G4Types.hh:85

References Negative, Neutral, and Positive.

Referenced by Add().

◆ Evaluate()

bool G4TrajectoryChargeFilter::Evaluate ( const G4VTrajectory traj) const
virtual

Implements G4SmartFilter< G4VTrajectory >.

Definition at line 42 of file G4TrajectoryChargeFilter.cc.

43{
44 G4double charge = traj.GetCharge();
45
46 if (GetVerbose()) G4cout<<"G4TrajectoryChargeFilter processing trajectory with charge: "<<charge<<G4endl;
47
48 MyCharge myCharge;
49
50 if(charge>0.) myCharge = Positive;
51 else if(charge<0.) myCharge = Negative;
52 else myCharge = Neutral;
53
54 std::vector<MyCharge>::const_iterator iter = std::find(fCharges.begin(), fCharges.end(), myCharge);
55
56 // Fail if charge not registered
57 if (iter == fCharges.end()) return false;
58
59 return true;
60}
double G4double
Definition: G4Types.hh:83
virtual G4double GetCharge() const =0

References fCharges, G4cout, G4endl, G4VTrajectory::GetCharge(), G4SmartFilter< G4VTrajectory >::GetVerbose(), Negative, Neutral, and Positive.

◆ GetActive()

G4bool G4SmartFilter< G4VTrajectory >::GetActive
inherited

Definition at line 67 of file G4SmartFilter.hh.

173{
174 return fActive;
175}

◆ GetInvert()

G4bool G4SmartFilter< G4VTrajectory >::GetInvert
inherited

Definition at line 71 of file G4SmartFilter.hh.

187{
188 return fInvert;
189}

◆ GetName()

G4String G4VFilter< G4VTrajectory >::GetName
inherited

Definition at line 61 of file G4VFilter.hh.

88{
89 return Name();
90}

◆ GetVerbose()

G4bool G4SmartFilter< G4VTrajectory >::GetVerbose
inherited

Definition at line 75 of file G4SmartFilter.hh.

201{
202 return fVerbose;
203}

◆ Name()

G4String G4VFilter< G4VTrajectory >::Name
inherited

Definition at line 60 of file G4VFilter.hh.

81{
82 return fName;
83}

◆ Print()

void G4TrajectoryChargeFilter::Print ( std::ostream &  ostr) const
virtual

Implements G4SmartFilter< G4VTrajectory >.

Definition at line 86 of file G4TrajectoryChargeFilter.cc.

87{
88 ostr<<"Charges registered: "<<G4endl;
89 std::vector<MyCharge>::const_iterator iter = fCharges.begin();
90
91 while (iter != fCharges.end()) {
92 ostr<<*iter<<G4endl;
93 iter++;
94 }
95}

References fCharges, and G4endl.

◆ PrintAll()

void G4SmartFilter< G4VTrajectory >::PrintAll ( std::ostream &  ostr) const
virtualinherited

Implements G4VFilter< G4VTrajectory >.

Definition at line 60 of file G4SmartFilter.hh.

139{
140 ostr<<"Printing data for filter: "<<G4VFilter<T>::Name()<<G4endl;
141
142 Print(ostr);
143
144 ostr<<"Active ? : " <<fActive<<G4endl;
145 ostr<<"Inverted ? : " <<fInvert<<G4endl;
146 ostr<<"#Processed : " <<fNProcessed<<G4endl;
147 ostr<<"#Passed : " <<fNPassed<<G4endl;
148}
virtual void Print(std::ostream &ostr) const=0

◆ Reset()

void G4SmartFilter< G4VTrajectory >::Reset
virtualinherited

Implements G4VFilter< G4VTrajectory >.

Definition at line 63 of file G4SmartFilter.hh.

153{
154 fActive = true;
155 fInvert = false;
156 fNProcessed = 0;
157 fNPassed = 0;
158
159 // Clear subclass data
160 Clear();
161}

◆ SetActive()

void G4SmartFilter< G4VTrajectory >::SetActive ( const G4bool active)
inherited

Definition at line 66 of file G4SmartFilter.hh.

166{
167 fActive = active;
168}

◆ SetInvert()

void G4SmartFilter< G4VTrajectory >::SetInvert ( const G4bool invert)
inherited

Definition at line 70 of file G4SmartFilter.hh.

180{
181 fInvert = invert;
182}

◆ SetVerbose()

void G4SmartFilter< G4VTrajectory >::SetVerbose ( const G4bool verbose)
inherited

Definition at line 74 of file G4SmartFilter.hh.

194{
195 fVerbose = verbose;
196}

Field Documentation

◆ fActive

G4bool G4SmartFilter< G4VTrajectory >::fActive
privateinherited

Definition at line 81 of file G4SmartFilter.hh.

◆ fCharges

std::vector<MyCharge> G4TrajectoryChargeFilter::fCharges
private

Definition at line 69 of file G4TrajectoryChargeFilter.hh.

Referenced by Add(), Clear(), Evaluate(), and Print().

◆ fInvert

G4bool G4SmartFilter< G4VTrajectory >::fInvert
privateinherited

Definition at line 82 of file G4SmartFilter.hh.

◆ fName

G4String G4VFilter< G4VTrajectory >::fName
privateinherited

Definition at line 66 of file G4VFilter.hh.

◆ fNPassed

size_t G4SmartFilter< G4VTrajectory >::fNPassed
mutableprivateinherited

Definition at line 84 of file G4SmartFilter.hh.

◆ fNProcessed

size_t G4SmartFilter< G4VTrajectory >::fNProcessed
mutableprivateinherited

Definition at line 85 of file G4SmartFilter.hh.

◆ fVerbose

G4bool G4SmartFilter< G4VTrajectory >::fVerbose
privateinherited

Definition at line 83 of file G4SmartFilter.hh.


The documentation for this class was generated from the following files: