1 |
gpetrucc |
1.1 |
//
|
2 |
|
|
// $Id: CompositeCandidateCleaner.cc,v 1.1 2009/04/14 13:58:52 gpetrucc Exp $
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
/**
|
6 |
|
|
\class pat::CompositeCandidateCleaner CompositeCandidateCleaner.h "PhysicsTools/PatAlgos/interface/CompositeCandidateCleaner.h"
|
7 |
|
|
\brief Matcher of reconstructed objects to L1 Muons
|
8 |
|
|
|
9 |
|
|
\author Giovanni Petrucciani
|
10 |
|
|
\version $Id: CompositeCandidateCleaner.cc,v 1.1 2009/04/14 13:58:52 gpetrucc Exp $
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
15 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
16 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
17 |
|
|
#include "FWCore/ParameterSet/interface/InputTag.h"
|
18 |
|
|
|
19 |
|
|
#include <DataFormats/Candidate/interface/CompositeCandidate.h>
|
20 |
|
|
#include <functional>
|
21 |
|
|
|
22 |
|
|
namespace pat {
|
23 |
|
|
namespace helper {
|
24 |
|
|
struct ShallowClonePtrOverlap {
|
25 |
|
|
typedef reco::CandidatePtr value_type;
|
26 |
|
|
value_type operator()(const reco::Candidate &c) const { return c.masterClonePtr(); }
|
27 |
|
|
bool operator()(const value_type &v1, const value_type &v2) const { return v1 == v2; }
|
28 |
|
|
};
|
29 |
|
|
struct ShallowCloneOverlap {
|
30 |
|
|
typedef reco::CandidateBaseRef value_type;
|
31 |
|
|
value_type operator()(const reco::Candidate &c) const { return c.masterClone(); }
|
32 |
|
|
bool operator()(const value_type &v1, const value_type &v2) const { return v1 == v2; }
|
33 |
|
|
};
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
template<typename CompositeCandidateT, typename OverlapT>
|
37 |
|
|
class CompositeCandidateCleanerT : public edm::EDProducer {
|
38 |
|
|
public:
|
39 |
|
|
explicit CompositeCandidateCleanerT(const edm::ParameterSet & iConfig);
|
40 |
|
|
virtual ~CompositeCandidateCleanerT() { }
|
41 |
|
|
|
42 |
|
|
virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
|
43 |
|
|
|
44 |
|
|
private:
|
45 |
|
|
edm::InputTag src_;
|
46 |
|
|
|
47 |
|
|
enum Mode { NoCleaning, OneProbe, BestMass };
|
48 |
|
|
Mode mode_;
|
49 |
|
|
double mass_;
|
50 |
|
|
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
typedef CompositeCandidateCleanerT<reco::CompositeCandidate,helper::ShallowClonePtrOverlap> CompositeShallowClonePtrCandidateCleaner;
|
54 |
|
|
typedef CompositeCandidateCleanerT<reco::CompositeCandidate,helper::ShallowCloneOverlap> CompositeShallowCloneCandidateCleaner;
|
55 |
|
|
} // namespace
|
56 |
|
|
|
57 |
|
|
template<typename CompositeCandidateT, typename OverlapT>
|
58 |
|
|
pat::CompositeCandidateCleanerT<CompositeCandidateT,OverlapT>::CompositeCandidateCleanerT(const edm::ParameterSet & iConfig) :
|
59 |
|
|
src_(iConfig.getParameter<edm::InputTag>("src")), mass_(0)
|
60 |
|
|
{
|
61 |
|
|
std::string mode = iConfig.getParameter<std::string>("mode");
|
62 |
|
|
if (mode == "NoCleaning") { // Pass all
|
63 |
|
|
mode_ = NoCleaning;
|
64 |
|
|
} else if (mode == "OneProbe") { // One probe only
|
65 |
|
|
mode_ = OneProbe;
|
66 |
|
|
} else if (mode == "BestMass") {
|
67 |
|
|
mode_ = BestMass;
|
68 |
|
|
mass_ = iConfig.getParameter<double>("mass");
|
69 |
|
|
}
|
70 |
|
|
produces<typename std::vector<CompositeCandidateT> >();
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
template<typename CompositeCandidateT, typename OverlapT>
|
74 |
|
|
void
|
75 |
|
|
pat::CompositeCandidateCleanerT<CompositeCandidateT,OverlapT>::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
|
76 |
|
|
using namespace edm;
|
77 |
|
|
using namespace std;
|
78 |
|
|
|
79 |
|
|
Handle<View<CompositeCandidateT> > src;
|
80 |
|
|
iEvent.getByLabel(src_, src);
|
81 |
|
|
|
82 |
|
|
// boolean work area. use ints
|
83 |
|
|
vector<int> good(src->size(), 1);
|
84 |
|
|
|
85 |
|
|
// Overlap
|
86 |
|
|
OverlapT overlap;
|
87 |
|
|
|
88 |
|
|
// loop variables
|
89 |
|
|
typename View<CompositeCandidateT>::const_iterator it, jt, be = src->begin(), ed = src->end(), ed1 = ed - 1;
|
90 |
|
|
size_t i, j;
|
91 |
|
|
if (src->size() > 1) {
|
92 |
|
|
for (it = be, i = 0; it != ed1; ++it, ++i) {
|
93 |
|
|
const CompositeCandidateT & ci = *it;
|
94 |
|
|
assert(ci.daughter(0) != 0);
|
95 |
|
|
typename OverlapT::value_type vt1 = overlap(*ci.daughter(0)); // tag
|
96 |
|
|
for (jt = it+1, j = i+1; jt != ed; ++jt, ++j) {
|
97 |
|
|
const CompositeCandidateT & cj = *jt;
|
98 |
|
|
assert(cj.daughter(0) != 0);
|
99 |
|
|
typename OverlapT::value_type vt2 = overlap(*cj.daughter(0));
|
100 |
|
|
if (overlap(vt1, vt2)) { // same tag
|
101 |
|
|
if (mode_ == OneProbe) {
|
102 |
|
|
good[i] = 0; good[j] = 0;
|
103 |
|
|
} else if (mode_ == BestMass) {
|
104 |
|
|
int worse = fabs(ci.mass() - mass_) > fabs(cj.mass() - mass_) ? i : j;
|
105 |
|
|
good[worse] = 0;
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
// room for output
|
113 |
|
|
auto_ptr<vector<CompositeCandidateT> > out(new vector<CompositeCandidateT>());
|
114 |
|
|
out->reserve(src->size());
|
115 |
|
|
for (it = be, i = 0; it != ed; ++it, ++i) {
|
116 |
|
|
if (good[i]) out->push_back(*it);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
iEvent.put(out);
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
#include "FWCore/Framework/interface/MakerMacros.h"
|
123 |
|
|
using namespace pat;
|
124 |
|
|
DEFINE_FWK_MODULE(CompositeShallowClonePtrCandidateCleaner);
|
125 |
|
|
DEFINE_FWK_MODULE(CompositeShallowCloneCandidateCleaner);
|