1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#ifndef Candidate_CompositeRefCandidateT_h
#define Candidate_CompositeRefCandidateT_h
/** \class reco::CompositeRefCandidateT<D>
*
* a reco::Candidate composed of daughters.
* The daughters has persistent references (edm::Ref <...>)
* to reco::Candidate stored in a separate collection.
*
* \author Luca Lista, INFN
*
*
*/
#include "DataFormats/Candidate/interface/LeafCandidate.h"
#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
namespace reco {
template <typename D>
class CompositeRefCandidateT : public LeafCandidate {
public:
/// collection of references to daughters
typedef D daughters;
/// collection of references to daughters
typedef D mothers;
/// default constructor
CompositeRefCandidateT() : LeafCandidate() {}
/// constructor from values
CompositeRefCandidateT(Charge q,
const LorentzVector& p4,
const Point& vtx = Point(0, 0, 0),
int pdgId = 0,
int status = 0,
bool integerCharge = true)
: LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
/// constructor from values
CompositeRefCandidateT(Charge q,
const PolarLorentzVector& p4,
const Point& vtx = Point(0, 0, 0),
int pdgId = 0,
int status = 0,
bool integerCharge = true)
: LeafCandidate(q, p4, vtx, pdgId, status, integerCharge) {}
/// constructor from a particle
explicit CompositeRefCandidateT(const LeafCandidate& c) : LeafCandidate(c) {}
/// destructor
~CompositeRefCandidateT() override;
/// returns a clone of the candidate
CompositeRefCandidateT<D>* clone() const override;
/// number of daughters
size_t numberOfDaughters() const override;
/// number of mothers
size_t numberOfMothers() const override;
/// return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
const Candidate* daughter(size_type) const override;
using ::reco::LeafCandidate::daughter; // avoid hiding the base
/// return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode)
const Candidate* mother(size_type = 0) const override;
/// return daughter at a given position, i = 0, ... numberOfDaughters() - 1
Candidate* daughter(size_type) override;
/// add a daughter via a reference
void addDaughter(const typename daughters::value_type&);
/// add a daughter via a reference
void addMother(const typename mothers::value_type&);
/// clear daughter references
void clearDaughters() { dau.clear(); }
/// clear mother references
void clearMothers() { mom.clear(); }
/// reference to daughter at given position
typename daughters::value_type daughterRef(size_type i) const { return dau[i]; }
/// references to daughtes
const daughters& daughterRefVector() const { return dau; }
/// reference to mother at given position
typename daughters::value_type motherRef(size_type i = 0) const { return mom[i]; }
/// references to mothers
const mothers& motherRefVector() const { return mom; }
/// set daughters product ID
void resetDaughters(const edm::ProductID& id) { dau = daughters(id); }
/// set mother product ID
void resetMothers(const edm::ProductID& id) { mom = mothers(id); }
CMS_CLASS_VERSION(13)
private:
/// collection of references to daughters
daughters dau;
/// collection of references to mothers
daughters mom;
/// check overlap with another candidate
bool overlap(const Candidate&) const override;
};
template <typename D>
inline void CompositeRefCandidateT<D>::addDaughter(const typename daughters::value_type& cand) {
dau.push_back(cand);
}
template <typename D>
inline void CompositeRefCandidateT<D>::addMother(const typename daughters::value_type& cand) {
mom.push_back(cand);
}
template <typename D>
CompositeRefCandidateT<D>::~CompositeRefCandidateT() {}
template <typename D>
CompositeRefCandidateT<D>* CompositeRefCandidateT<D>::clone() const {
return new CompositeRefCandidateT(*this);
}
template <typename D>
const Candidate* CompositeRefCandidateT<D>::daughter(size_type i) const {
return (i < numberOfDaughters()) ? &*dau[i] : nullptr;
}
template <typename D>
const Candidate* CompositeRefCandidateT<D>::mother(size_type i) const {
return (i < numberOfMothers()) ? &*mom[i] : nullptr;
}
template <typename D>
Candidate* CompositeRefCandidateT<D>::daughter(size_type i) {
return nullptr;
}
template <typename D>
size_t CompositeRefCandidateT<D>::numberOfDaughters() const {
return dau.size();
}
template <typename D>
size_t CompositeRefCandidateT<D>::numberOfMothers() const {
return mom.size();
}
template <typename D>
bool CompositeRefCandidateT<D>::overlap(const Candidate& c2) const {
throw cms::Exception("Error") << "can't check overlap internally for CompositeRefCanddate";
}
} // namespace reco
#endif
|