HepMC event record
Filter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014 The HepMC collaboration (see AUTHORS for details)
5 //
6 /**
7  * @file Filter.cc
8  * @brief Implementation of \b class Filter
9  *
10  */
11 #include "HepMC/Search/Filter.h"
12 
13 #include "HepMC/GenEvent.h"
14 #include "HepMC/GenVertex.h"
15 #include "HepMC/GenParticle.h"
16 
17 namespace HepMC {
18 
19 
20 bool Filter::passed_filter(const GenParticlePtr &p) const {
21 
22  switch( m_value_type) {
23  case INTEGER_PARAM: return passed_int_filter (p);
24  case BOOL_PARAM: return passed_bool_filter(p);
25  case ATTRIBUTE_PARAM: return passed_attribute_filter(p);
26  }
27 
28  return false;
29 }
30 
32 
33  int value = 0;
34 
35  switch(m_int) {
36  case STATUS: value = p->status(); break;
37  case PDG_ID: value = p->pid(); break;
38  case ABS_PDG_ID: value = abs( p->pid() ); break;
39  default:
40  // This should never happen
41  ERROR( "Unsupported filter ("<<m_int<<")" )
42  return false;
43  };
44 
45  DEBUG( 10, "Filter: checking id="<<p->id()<<" param="<<m_int<<" operator="<<m_operator<<" value="<<value<<" compare to="<<m_int_value )
46 
47  switch(m_operator) {
48  case EQUAL: return (value==m_int_value);
49  case GREATER: return (value> m_int_value);
50  case LESS: return (value< m_int_value);
51  case GREATER_OR_EQUAL: return (value>=m_int_value);
52  case LESS_OR_EQUAL: return (value<=m_int_value);
53  case NOT_EQUAL: return (value!=m_int_value);
54  };
55 
56  return false;
57 }
58 
60 
61  bool result = false;
62  GenVertexPtr buf;
63 
64  DEBUG( 10, "Filter: checking id="<<p->id()<<" param="<<m_bool<<" value="<<m_bool_value<<" (bool)" )
65 
66  switch( m_bool ) {
67  case HAS_END_VERTEX: result = (bool) p->end_vertex(); break;
68  case HAS_PRODUCTION_VERTEX: result = (bool) p->production_vertex(); break;
69  case HAS_SAME_PDG_ID_DAUGHTER:
70  buf = p->end_vertex();
71  if( !buf ) {
72  result = false;
73  break;
74  }
75 
76  if( buf->particles_out().size() == 0 ) {
77  result = false;
78  break;
79  }
80 
81  FOREACH( const GenParticlePtr &p_out, buf->particles_out() ) {
82 
83  if( p_out->pid() == p->pid() ) {
84  result = true;
85  break;
86  }
87  }
88 
89  break;
90  case IS_STABLE: result = (bool) (p->status() == 1); break;
91  case IS_BEAM: result = (bool) (p->status() == 4); break;
92  };
93 
94  if( m_bool_value == false ) result = !result;
95 
96  return result;
97 }
98 
100 
101  bool ret = false;
102 
103  string attribute = p->attribute_as_string(m_attribute_name);
104 
105  DEBUG( 10, "Filter: checking id="<<p->id()<<" m_attribute="<<m_attribute<<" m_bool_val="<<m_bool_value<<" att name='"<<m_attribute_name<<"' att str='"<<m_attribute_str<<"' compare to='"<<attribute<<"'" )
106 
107  switch( m_attribute ) {
108  case ATTRIBUTE_EXISTS: ret = (attribute.length() > 0); break;
109  case ATTRIBUTE_IS_EQUAL: ret = (m_attribute_str.compare(attribute) == 0); break;
110  }
111 
112  if( !m_bool_value ) ret = !ret;
113 
114  return ret;
115 }
116 
117 } // namespace HepMC
bool m_bool_value
Filter parameter for boolean-type filter.
FilterParamType m_value_type
Parameter type.
FilterBoolParam m_bool
Boolean value (if boolean parameter type)
bool passed_attribute_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for attribute-type filters.
Definition: Filter.cc:99
FilterOperator m_operator
Operator used by filter.
bool passed_bool_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for pointer-type filters.
Definition: Filter.cc:59
bool passed_int_filter(const GenParticlePtr &p) const
Filter::passed_filter helper for integer-type filters.
Definition: Filter.cc:31
FilterAttributeParam m_attribute
Attribute value (if attribute parameter type)
FilterIntegerParam m_int
Integer value (if integer parameter type)
string m_attribute_str
Filter parameter for attribute-type filters.
bool passed_filter(const GenParticlePtr &p) const
Check if HepMC::GenParticle passed this filter.
Definition: Filter.cc:20
string m_attribute_name
Filter parameter for attribute-type filters.
int m_int_value
Filter parameter for integer-type filter.
Definition of template class SmartPointer.