1 |
/**
|
2 |
\class pat::PATVertexAssociationProducer PATVertexAssociationProducer.h "PhysicsTools/PatAlgos/interface/PATVertexAssociationProducer.h"
|
3 |
\brief Produces VertexAssociation and a ValueMap to the originating
|
4 |
reco jets
|
5 |
|
6 |
The PATVertexAssociationProducer produces a set of vertex associations for one or more
|
7 |
collection of Candidates, and saves them in a ValueMap in the event.
|
8 |
|
9 |
These can be retrieved in PAT Layer 1 to be embedded in PAT Objects
|
10 |
|
11 |
\author Giovanni Petrucciani
|
12 |
\version $Id: VertexAssociationProducer.cc,v 1.1 2008/07/22 12:47:02 gpetrucc Exp $
|
13 |
*/
|
14 |
|
15 |
|
16 |
#include "FWCore/Framework/interface/EDProducer.h"
|
17 |
#include "FWCore/Framework/interface/Event.h"
|
18 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
19 |
#include "FWCore/ParameterSet/interface/InputTag.h"
|
20 |
|
21 |
#include "DataFormats/Common/interface/ValueMap.h"
|
22 |
#include "DataFormats/Common/interface/View.h"
|
23 |
#include "DataFormats/PatCandidates/interface/Vertexing.h"
|
24 |
#include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
|
25 |
|
26 |
|
27 |
namespace pat {
|
28 |
|
29 |
class PATVertexAssociationProducer : public edm::EDProducer {
|
30 |
|
31 |
typedef edm::ValueMap<pat::VertexAssociation> VertexAssociationMap;
|
32 |
|
33 |
public:
|
34 |
|
35 |
explicit PATVertexAssociationProducer(const edm::ParameterSet & iConfig);
|
36 |
~PATVertexAssociationProducer();
|
37 |
|
38 |
virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
|
39 |
|
40 |
private:
|
41 |
typedef std::vector<edm::InputTag> VInputTag;
|
42 |
// configurables
|
43 |
std::vector<edm::InputTag> particles_;
|
44 |
pat::helper::VertexingHelper vertexing_;
|
45 |
|
46 |
};
|
47 |
|
48 |
}
|
49 |
|
50 |
using pat::PATVertexAssociationProducer;
|
51 |
|
52 |
PATVertexAssociationProducer::PATVertexAssociationProducer(const edm::ParameterSet& iConfig) :
|
53 |
particles_( iConfig.existsAs<VInputTag>("candidates") ? // if it's a VInputTag
|
54 |
iConfig.getParameter<VInputTag>("candidates") :
|
55 |
VInputTag(1, iConfig.getParameter<edm::InputTag>("candidates")) ),
|
56 |
vertexing_(iConfig)
|
57 |
{
|
58 |
produces<VertexAssociationMap>();
|
59 |
}
|
60 |
|
61 |
|
62 |
PATVertexAssociationProducer::~PATVertexAssociationProducer() {
|
63 |
}
|
64 |
|
65 |
|
66 |
void PATVertexAssociationProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
|
67 |
using namespace edm; using namespace std;
|
68 |
// read in vertices and EventSetup
|
69 |
vertexing_.newEvent(iEvent, iSetup);
|
70 |
|
71 |
// prepare room and tools for output
|
72 |
auto_ptr<VertexAssociationMap> result(new VertexAssociationMap());
|
73 |
VertexAssociationMap::Filler filler(*result);
|
74 |
vector<pat::VertexAssociation> assos;
|
75 |
|
76 |
// loop on input tags
|
77 |
for (VInputTag::const_iterator it = particles_.begin(), end = particles_.end(); it != end; ++it) {
|
78 |
// read candidates
|
79 |
Handle<View<reco::Candidate> > cands;
|
80 |
iEvent.getByLabel(*it, cands);
|
81 |
assos.clear(); assos.reserve(cands->size());
|
82 |
// loop on candidates
|
83 |
for (size_t i = 0, n = cands->size(); i < n; ++i) {
|
84 |
assos.push_back( vertexing_(cands->refAt(i)) );
|
85 |
}
|
86 |
// insert into ValueMap
|
87 |
filler.insert(cands, assos.begin(), assos.end());
|
88 |
}
|
89 |
|
90 |
// do the real filling
|
91 |
filler.fill();
|
92 |
|
93 |
// put our produced stuff in the event
|
94 |
iEvent.put(result);
|
95 |
}
|
96 |
|
97 |
|
98 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
99 |
|
100 |
DEFINE_FWK_MODULE(PATVertexAssociationProducer);
|