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
|
//
// template for implementation of jet associations
// F Ratnikov, UMd, Sep. 5, 2007
//
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/JetReco/interface/JetCollection.h"
namespace JetAssociationTemplate {
template <typename Container>
inline unsigned findJet(const Container& fContainer, const reco::Jet& fJet) {
for (unsigned i = 0; i < fContainer.size(); ++i) {
if (&*(fContainer[i].first) == &fJet)
return i;
}
throw cms::Exception("Invalid jet") << "JetAssociationTemplate-> inquire association with jet which is not "
"available in the original jet collection";
}
template <typename Container, typename Value>
inline bool setValue(Container* fContainer, const reco::JetBaseRef& fJet, const Value& fValue) {
if (!fContainer)
return false;
fContainer->setValue(fJet.key(), fValue);
return true;
}
template <typename Container, typename Value>
inline bool setValue(Container& fContainer, const reco::JetBaseRef& fJet, const Value& fValue) {
return setValue(&fContainer, fJet, fValue);
}
template <typename Container, typename Value>
inline const Value& getValue(const Container& fContainer, const reco::JetBaseRef& fJet) {
return fContainer[fJet];
}
template <typename Container, typename Value>
inline const Value& getValue(const Container& fContainer, const reco::Jet& fJet) {
unsigned i = findJet(fContainer, fJet);
return fContainer[i].second;
}
template <typename Container>
inline std::vector<reco::JetBaseRef> allJets(const Container& fContainer) {
std::vector<reco::JetBaseRef> result;
for (unsigned i = 0; i < fContainer.size(); ++i) {
result.push_back(fContainer[i].first);
}
return result;
}
template <typename Container>
inline bool hasJet(const Container& fContainer, const reco::JetBaseRef& fJet) {
for (unsigned i = 0; i < fContainer.size(); ++i) {
if (fContainer[i].first == fJet)
return true;
}
return false;
}
template <typename Container>
inline bool hasJet(const Container& fContainer, const reco::Jet& fJet) {
for (unsigned i = 0; i < fContainer.size(); ++i) {
if (&*(fContainer[i].first) == &fJet)
return true;
}
return false;
}
} // namespace JetAssociationTemplate
|