CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VertexAssociationProducer.cc
Go to the documentation of this file.
1 
20 
25 
26 
27 namespace pat {
28 
30 
32 
33  public:
34 
35  explicit PATVertexAssociationProducer(const edm::ParameterSet & iConfig);
37 
38  virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
39 
40  private:
41  typedef std::vector<edm::InputTag> VInputTag;
42  // configurables
43  std::vector<edm::InputTag> particles_;
44  std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > > particlesTokens_;
46 
47  };
48 
49 }
50 
52 
53 PATVertexAssociationProducer::PATVertexAssociationProducer(const edm::ParameterSet& iConfig) :
54  particles_( iConfig.existsAs<VInputTag>("candidates") ? // if it's a VInputTag
55  iConfig.getParameter<VInputTag>("candidates") :
56  VInputTag(1, iConfig.getParameter<edm::InputTag>("candidates")) ),
57  vertexing_(iConfig, consumesCollector())
58 {
59  for (VInputTag::const_iterator it = particles_.begin(), end = particles_.end(); it != end; ++it) {
61  }
62  produces<VertexAssociationMap>();
63 }
64 
65 
67 }
68 
69 
71  using namespace edm; using namespace std;
72  // read in vertices and EventSetup
73  vertexing_.newEvent(iEvent, iSetup);
74 
75  // prepare room and tools for output
76  auto_ptr<VertexAssociationMap> result(new VertexAssociationMap());
77  VertexAssociationMap::Filler filler(*result);
78  vector<pat::VertexAssociation> assos;
79 
80  // loop on input tags
81  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator it = particlesTokens_.begin(), end = particlesTokens_.end(); it != end; ++it) {
82  // read candidates
84  iEvent.getByToken(*it, cands);
85  assos.clear(); assos.reserve(cands->size());
86  // loop on candidates
87  for (size_t i = 0, n = cands->size(); i < n; ++i) {
88  assos.push_back( vertexing_(cands->refAt(i)) );
89  }
90  // insert into ValueMap
91  filler.insert(cands, assos.begin(), assos.end());
92  }
93 
94  // do the real filling
95  filler.fill();
96 
97  // put our produced stuff in the event
98  iEvent.put(result);
99 }
100 
101 
103 
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
pat::helper::VertexingHelper vertexing_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
tuple result
Definition: query.py:137
PATVertexAssociationProducer(const edm::ParameterSet &iConfig)
#define end
Definition: vmac.h:37
std::vector< edm::InputTag > VInputTag
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > particlesTokens_
edm::ValueMap< pat::VertexAssociation > VertexAssociationMap
void newEvent(const edm::Event &event)
To be called for each new event, reads in the vertex collection.
Produces VertexAssociation and a ValueMap to the originating reco jets.
std::vector< edm::InputTag > particles_
Produces and/or checks pat::VertexAssociation&#39;s.