Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CompositeCandidate.cc
Go to the documentation of this file.
1 #include "../interface/CompositeCandidate.hh"
2 #include <set>
3 #include <map>
4 #include <string>
5 #include "Math/VectorUtil.h"
6 
7 namespace ic {
8 // Constructors
10 
12 
13 void CompositeCandidate::AddCandidate(std::string name, Candidate* cand) {
14  cand_map_[name] = cand;
15  cand_vec_.push_back(cand);
18 }
19 
20 Candidate* CompositeCandidate::GetCandidate(std::string name) const {
21  if (Verify(name)) {
22  return cand_map_.find(name)->second;
23  } else {
24  return 0;
25  }
26 }
27 
28 Candidate* CompositeCandidate::At(unsigned index) const {
29  return cand_vec_.at(index);
30 }
31 
32 double CompositeCandidate::PtOf(std::string name) const {
33  if (!Verify(name)) {
34  return 0.0;
35  } else {
36  return cand_map_.find(name)->second->pt();
37  }
38 }
39 
41  double pt_sum = 0.0;
42  for (unsigned i = 0; i < cand_vec_.size(); ++i) {
43  pt_sum += cand_vec_[i]->pt();
44  }
45  return pt_sum;
46 }
47 
48 double CompositeCandidate::DeltaR(std::string name1, std::string name2) const {
49  if (!Verify(name1) || !Verify(name2)) {
50  return 0.0;
51  } else {
52  return ROOT::Math::VectorUtil::DeltaR(
53  (cand_map_.find(name1)->second->vector()),
54  (cand_map_.find(name2)->second->vector()));
55  }
56 }
57 
58 double CompositeCandidate::DeltaPhi(std::string name1,
59  std::string name2) const {
60  if (!Verify(name1) || !Verify(name2)) {
61  return 0.0;
62  } else {
63  return ROOT::Math::VectorUtil::DeltaPhi(
64  (cand_map_.find(name1)->second->vector()),
65  (cand_map_.find(name2)->second->vector()));
66  }
67 }
68 
70  std::cout << "CompositeCandidate: " << vector() << std::endl;
71  std::map<std::string, Candidate*>::const_iterator iter;
72  for (iter = cand_map_.begin(); iter != cand_map_.end(); ++iter) {
73  std::cout << iter->first << "\t" << iter->second->vector() << std::endl;
74  }
75 }
76 
77 bool CompositeCandidate::Verify(std::string const& name) const {
78  static std::set<std::string> warned;
79  if (!cand_map_.count(name)) {
80  if (!warned.count(name)) {
81  warned.insert(name);
82  std::cerr << "Warning in CompositeCandidate: Candidate with label \""
83  << name << "\" not found" << std::endl;
84  }
85  return false;
86  } else {
87  return true;
88  }
89 }
90 }
Candidate * GetCandidate(std::string name) const
double DeltaR(std::string name1, std::string name2) const
virtual void Print() const
double DeltaPhi(std::string name1, std::string name2) const
int charge() const
Electric charge.
Definition: Candidate.hh:54
void set_vector(Vector const &vector)
Four-momentum.
Definition: Candidate.hh:63
Stores a four-momentum, charge and identifier, and is the base class for most other physics objects...
Definition: Candidate.hh:13
Vector const & vector() const
Four-momentum.
Definition: Candidate.hh:31
Candidate * At(unsigned index) const
void set_charge(int const &charge)
Electric charge.
Definition: Candidate.hh:81
Definition: CaloJet.hh:9
double PtOf(std::string name) const
void AddCandidate(std::string name, Candidate *cand)
Add a new Candidate.