CMS 3D CMS Logo

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  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 
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) {
60  particlesTokens_.push_back( consumes<edm::View<reco::Candidate> >( *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 result = std::make_unique<VertexAssociationMap>();
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(std::move(result));
99 }
100 
101 
103 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
pat::helper::VertexingHelper vertexing_
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
PATVertexAssociationProducer(const edm::ParameterSet &iConfig)
#define end
Definition: vmac.h:39
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.
HLT enums.
Produces VertexAssociation and a ValueMap to the originating reco jets.
std::vector< edm::InputTag > particles_
def move(src, dest)
Definition: eostools.py:510
Produces and/or checks pat::VertexAssociation&#39;s.