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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// -*- C++ -*-
//
// Package: PFCand_NoPU_WithAM
// Class: PFCand_NoPU_WithAM
//
/**\class PF_PU_AssoMap PFCand_NoPU_WithAM.cc CommonTools/RecoUtils/plugins/PFCand_NoPU_WithAM.cc
Description: Produces a collection of PFCandidates associated to the first vertex based on the association map
*/
//
// Original Author: Matthias Geisler,32 4-B20,+41227676487,
// Created: Thu Dec 1 16:07:41 CET 2011
// $Id: PFCand_NoPU_WithAM.cc,v 1.5 2012/12/06 14:03:15 mgeisler Exp $
//
//
#include "CommonTools/RecoUtils/interface/PFCand_NoPU_WithAM.h"
// system include files
#include <memory>
#include <vector>
// user include files
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackReco/interface/TrackBase.h"
using namespace edm;
using namespace std;
using namespace reco;
//
// constructors and destructor
//
PFCand_NoPU_WithAM::PFCand_NoPU_WithAM(const edm::ParameterSet& iConfig) {
//now do what ever other initialization is needed
input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
token_PFCandToVertexAssMap_ =
mayConsume<PFCandToVertexAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
token_VertexToPFCandAssMap_ =
mayConsume<VertexToPFCandAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
//register your products
if (input_AssociationType_.label() == "PFCandsToVertex") {
produces<PFCandidateCollection>("P2V");
} else {
if (input_AssociationType_.label() == "VertexToPFCands") {
produces<PFCandidateCollection>("V2P");
} else {
if (input_AssociationType_.label() == "Both") {
produces<PFCandidateCollection>("P2V");
produces<PFCandidateCollection>("V2P");
} else {
cout << "No correct InputTag for AssociationType!" << endl;
cout << "Won't produce any PFCandiateCollection!" << endl;
}
}
}
}
//
// member functions
//
// ------------ method called to produce the data ------------
void PFCand_NoPU_WithAM::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
unique_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection());
unique_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection());
bool p2vassmap = false;
bool v2passmap = false;
//get the input vertex<->pf-candidate association map
Handle<PFCandToVertexAssMap> p2vAM;
Handle<VertexToPFCandAssMap> v2pAM;
string asstype = input_AssociationType_.label();
if ((asstype == "PFCandsToVertex") || (asstype == "Both")) {
if (iEvent.getByToken(token_PFCandToVertexAssMap_, p2vAM)) {
p2vassmap = true;
}
}
if ((asstype == "VertexToPFCands") || (asstype == "Both")) {
if (iEvent.getByToken(token_VertexToPFCandAssMap_, v2pAM)) {
v2passmap = true;
}
}
if (!p2vassmap && !v2passmap) {
cout << "No input collection could be found" << endl;
return;
}
int negativeQuality = 0;
if (input_MinQuality_ >= 2) {
negativeQuality = -1;
} else {
if (input_MinQuality_ == 1) {
negativeQuality = -2;
} else {
negativeQuality = -3;
}
}
if (p2vassmap) {
const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
//get the candidates associated to the first vertex and store them in a pf-candidate collection
for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++) {
PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
int quality = pfccoll[pfccoll_ite].second;
if ((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality))) {
p2v_firstvertex->push_back(*pfcand);
}
}
iEvent.put(std::move(p2v_firstvertex), "P2V");
}
if (v2passmap) {
//get the input vertex collection
Handle<VertexCollection> input_vtxcollH;
iEvent.getByToken(token_VertexCollection_, input_vtxcollH);
VertexRef firstVertexRef(input_vtxcollH, 0);
VertexToPFCandAssMap::const_iterator v2p_ite;
for (v2p_ite = v2pAM->begin(); v2p_ite != v2pAM->end(); v2p_ite++) {
PFCandidateRef pfcand = v2p_ite->key;
for (unsigned v_ite = 0; v_ite < (v2p_ite->val).size(); v_ite++) {
VertexRef vtxref = (v2p_ite->val)[v_ite].first;
int quality = (v2p_ite->val)[v_ite].second;
if ((vtxref == firstVertexRef) &&
((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality)))) {
v2p_firstvertex->push_back(*pfcand);
}
}
}
iEvent.put(std::move(v2p_firstvertex), "V2P");
}
}
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void PFCand_NoPU_WithAM::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.add<InputTag>("AssociationType");
desc.add<InputTag>("VertexPFCandAssociationMap");
desc.add<InputTag>("VertexCollection");
desc.add<int>("MinQuality");
descriptions.addDefault(desc);
}
//define this as a plug-in
DEFINE_FWK_MODULE(PFCand_NoPU_WithAM);
|