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);
39 
40  private:
41  typedef std::vector<edm::InputTag> VInputTag;
42  // configurables
43  std::vector<edm::InputTag> particles_;
45 
46  };
47 
48 }
49 
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 
63 }
64 
65 
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
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 
99 
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
pat::helper::VertexingHelper vertexing_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
tuple result
Definition: query.py:137
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
PATVertexAssociationProducer(const edm::ParameterSet &iConfig)
#define end
Definition: vmac.h:38
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::vector< edm::InputTag > VInputTag
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.