ATLAS Offline Software
Public Member Functions | Protected Attributes | List of all members
ChargeFilter< T > Class Template Reference

ChargeFilter can filter objects upon their charge. More...

#include <ChargeFilter.h>

Inheritance diagram for ChargeFilter< T >:
Collaboration diagram for ChargeFilter< T >:

Public Member Functions

 ChargeFilter ()
 Default constructor: More...
 
 ChargeFilter (const ChargeFilter< T > &rhs)
 Copy constructor: More...
 
virtual ~ChargeFilter ()
 Destructor: More...
 
ChargeFilter< T > & operator= (const ChargeFilter< T > &rhs)
 Assignment operator: More...
 
virtual bool isAccepted (const T *element) const
 Main filter method. More...
 
double charge () const
 Returns the charge the filter is looking for. More...
 
void setFilter (const IFilterCuts *filter)
 Copies the IFilterCuts properties of the given object to the current IFilterCuts object (ie: it copies the required charge() to the current object) More...
 
void setCharge (const ChargeType &charge)
 Set the filter to look for the given charge. More...
 
bool operator() (const T *element) const
 

Protected Attributes

std::optional< ChargeTypem_charge
 The charge the filter is looking for. More...
 

Detailed Description

template<typename T>
class ChargeFilter< T >

ChargeFilter can filter objects upon their charge.

One can only require a charge (not a range in charges). But it could be extended to a range.

Definition at line 31 of file ChargeFilter.h.

Constructor & Destructor Documentation

◆ ChargeFilter() [1/2]

template<typename T >
ChargeFilter< T >::ChargeFilter

Default constructor:

Implementation.

Definition at line 103 of file ChargeFilter.h.

103  :
104  IFilterCuts(),
105  IFilter<T>(),
106  m_charge()
107 {}

◆ ChargeFilter() [2/2]

template<typename T >
ChargeFilter< T >::ChargeFilter ( const ChargeFilter< T > &  rhs)

Copy constructor:

Definition at line 110 of file ChargeFilter.h.

110  :
111  IFilterCuts(rhs),
112  IFilter<T>(rhs),
113  m_charge(rhs.m_charge)
114 {}

◆ ~ChargeFilter()

template<typename T >
ChargeFilter< T >::~ChargeFilter
virtual

Destructor:

Definition at line 130 of file ChargeFilter.h.

130 {}

Member Function Documentation

◆ charge()

template<typename T >
double ChargeFilter< T >::charge

Returns the charge the filter is looking for.

Definition at line 154 of file ChargeFilter.h.

155 {
156  if (m_charge) {
157  return *m_charge;
158  }
159  throw std::domain_error( "No charge selection defined" );
160 }

◆ isAccepted()

template<typename T >
bool ChargeFilter< T >::isAccepted ( const T *  element) const
virtual

Main filter method.

This method takes the decision whether or not the filter has to accept the element. It returns true or false accordingly if the charge of the particle matchs the one of the filter, it is accepted. If no cut has been defined, it returns true by default.

Check if a charge cut has been set-up

The charge cut is un-initialized so by convention we return true;

Otherwise return true by convention

Implements IFilter< T >.

Definition at line 133 of file ChargeFilter.h.

134 {
136  if ( !m_charge ) {
139  return true;
140  } else {
141  const ChargeType charge = element->charge();
142  if ( *m_charge == charge ) {
143  return true;
144  } else {
145  return false;
146  }
147  }
148 
150  return true;
151 }

◆ operator()()

template<typename T >
bool IFilter< T >::operator() ( const T *  element) const
inlineinherited

Definition at line 101 of file IFilter.h.

102 {
103  return isAccepted(element);
104 }

◆ operator=()

template<typename T >
ChargeFilter< T > & ChargeFilter< T >::operator= ( const ChargeFilter< T > &  rhs)
inline

Assignment operator:

Definition at line 118 of file ChargeFilter.h.

119 {
120  if ( this != &rhs ) {
123  m_charge = rhs.m_charge;
124  }
125  return *this;
126 }

◆ setCharge()

template<typename T >
void ChargeFilter< T >::setCharge ( const ChargeType charge)

Set the filter to look for the given charge.

Parameters
charge: the charge the filter will be looking for.

Definition at line 181 of file ChargeFilter.h.

182 {
183  m_charge = charge;
184 }

◆ setFilter()

template<typename T >
void ChargeFilter< T >::setFilter ( const IFilterCuts filter)
virtual

Copies the IFilterCuts properties of the given object to the current IFilterCuts object (ie: it copies the required charge() to the current object)

Implements IFilterCuts.

Definition at line 163 of file ChargeFilter.h.

164 {
165  if ( filter ) {
166  const ChargeFilter<T> * chFilter =
167  dynamic_cast<const ChargeFilter<T> *>(filter);
168  if ( chFilter ) {
169  operator=(*chFilter);
170  } else {
171  MsgStream log( Athena::getMessageSvc(), "ChargeFilter" );
172  log << MSG::ERROR
173  << "Can't dynamic_cast " << typeid(filter).name()
174  << " to a ChargeFilter"
175  << endmsg;
176  }
177  }
178 }

Member Data Documentation

◆ m_charge

template<typename T >
std::optional<ChargeType> ChargeFilter< T >::m_charge
protected

The charge the filter is looking for.

It is unitialized by default (in the std::optional sense)

Definition at line 95 of file ChargeFilter.h.


The documentation for this class was generated from the following file:
IFilter
IFilter is the main interface to the filters.
Definition: IFilter.h:31
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
IFilter::operator=
IFilter< T > & operator=(const IFilter< T > &rhs)
Assignment operator:
Definition: IFilter.h:91
covarianceTool.filter
filter
Definition: covarianceTool.py:514
ChargeFilter::charge
double charge() const
Returns the charge the filter is looking for.
Definition: ChargeFilter.h:154
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
IFilter::isAccepted
virtual bool isAccepted(const T *element) const =0
Main filter method.
ChargeFilter::m_charge
std::optional< ChargeType > m_charge
The charge the filter is looking for.
Definition: ChargeFilter.h:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
IFilterCuts::IFilterCuts
IFilterCuts()
Default constructor:
Definition: IFilterCuts.h:69
ChargeType
double ChargeType
typedef ChargeType used to anticipate changes here
Definition: Event/EventKernel/EventKernel/IParticle.h:40
ChargeFilter
ChargeFilter can filter objects upon their charge.
Definition: ChargeFilter.h:32
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
IFilterCuts::operator=
IFilterCuts & operator=(const IFilterCuts &rhs)
Assignment operator:
Definition: IFilterCuts.h:78
ChargeFilter::operator=
ChargeFilter< T > & operator=(const ChargeFilter< T > &rhs)
Assignment operator:
Definition: ChargeFilter.h:118