CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventHypothesis.cc
Go to the documentation of this file.
3 
4 void pat::EventHypothesis::add(const CandRefType &ref, const std::string &role) {
5  particles_.push_back(value_type(role,ref));
6 }
7 
9 pat::EventHypothesis::get(const std::string &role, int index) const
10 {
11  if (index >= 0) {
12  const_iterator it = realGet(begin(), end(), ByRole(role), index);
13  if (it == end()) { throw cms::Exception("Index not found") << "Can't find a particle with role " << role << " and index " << index << "\n"; }
14  return it->second;
15  } else {
16  const_reverse_iterator it = realGet(rbegin(), rend(), ByRole(role), -index);
17  if (it == rend()) { throw cms::Exception("Index not found") << "Can't find a particle with role " << role << " and index " << index << "\n"; }
18  return it->second;
19  }
20 }
21 
24 {
25  if (index >= 0) {
26  const_iterator it = realGet(begin(), end(), filter, index);
27  if (it == end()) { throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n"; }
28  return it->second;
29  } else {
30  const_reverse_iterator it = realGet(rbegin(), rend(), filter, -index);
31  if (it == rend()) { throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n"; }
32  return it->second;
33  }
34 }
35 
36 
37 std::vector<pat::EventHypothesis::CandRefType>
38 pat::EventHypothesis::all(const std::string &roleRegexp) const
39 {
40  return all(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
41 }
42 
43 std::vector<pat::EventHypothesis::CandRefType>
45 {
46  std::vector<pat::EventHypothesis::CandRefType> ret;
47  for (const_iterator it = begin(); it != end(); ++it) {
48  if (filter(*it)) ret.push_back(it->second);
49  }
50  return ret;
51 }
52 
53 size_t
54 pat::EventHypothesis::count(const std::string &roleRegexp) const
55 {
57 }
58 
59 size_t
61 {
62  size_t n = 0;
63  for (const_iterator it = begin(); it != end(); ++it) {
64  if (role(*it)) ++n;
65  }
66  return n;
67 }
68 
71 {
73 }
74 
76 pat::EventHypothesis::loop(const std::string &roleRegexp) const
77 {
78  return loop(new pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
79 }
80 
83 {
84  return CandLooper(*this, role);
85 }
86 
89 {
90  return CandLooper(*this, role);
91 }
92 
95 {
96  return CandLooper(*this, role);
97 }
98 
99 
CandLooper loop() const
Loops over all particles.
std::vector< value_type > particles_
std::pair< std::string, CandRefType > value_type
size_t count() const
static const AcceptAllFilter & get()
void add(const CandRefType &ref, const std::string &role)
std::vector< CandRefType > all(const std::string &roleRegexp) const
Return EDM references to all particles which have certaint roles.
#define end
Definition: vmac.h:38
eventhypothesis::ParticleFilterPtr ParticleFilterPtr
vector_type::const_iterator const_iterator
#define begin
Definition: vmac.h:31
Looper< reco::Candidate > CandLooper
vector_type::const_reverse_iterator const_reverse_iterator
const CandRefType & get(const std::string &role, int index=0) const