CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PFCand_AssoMap.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFCand_AssoMap
4 // Class: PFCand_AssoMap
5 //
10 //
11 // Original Author: Matthias Geisler
12 // Created: Wed Apr 18 14:48:37 CEST 2012
13 // $Id: PFCand_AssoMap.cc,v 1.5 2012/11/21 09:52:27 mgeisler Exp $
14 //
15 //
17 
18 // system include files
19 #include <memory>
20 #include <vector>
21 #include <string>
22 
23 // user include files
24 
26 
29 
30 //
31 // constructors and destructor
32 //
34  //now do what ever other initialization is needed
35 
36  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");
37 
39  consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidateCollection"));
40 
41  //register your products
42 
43  if (input_AssociationType_.label() == "PFCandsToVertex") {
44  produces<PFCandToVertexAssMap>();
45  } else {
46  if (input_AssociationType_.label() == "VertexToPFCands") {
47  produces<VertexToPFCandAssMap>();
48  } else {
49  if (input_AssociationType_.label() == "Both") {
50  produces<PFCandToVertexAssMap>();
51  produces<VertexToPFCandAssMap>();
52  } else {
53  std::cout << "No correct InputTag for AssociationType!" << std::endl;
54  std::cout << "Won't produce any AssociationMap!" << std::endl;
55  }
56  }
57  }
58 }
59 
61 
62 //
63 // member functions
64 //
65 
66 // ------------ method called to produce the data ------------
68  using namespace edm;
69  using namespace std;
70  using namespace reco;
71 
72  //get the input pfCandidateCollection
74  iEvent.getByToken(token_PFCandidates_, pfCandH);
75 
76  string asstype = input_AssociationType_.label();
77 
79 
80  if (asstype == "PFCandsToVertex" || asstype == "VertexToPFCands" || asstype == "Both") {
81  auto mappings = createMappings(pfCandH);
82  if (asstype == "PFCandsToVertex" || asstype == "Both") {
83  iEvent.put(SortPFCandAssociationMap(&(*mappings.first), &iEvent.productGetter()));
84  }
85  if (asstype == "VertexToPFCands" || asstype == "Both") {
86  iEvent.put(std::move(mappings.second));
87  }
88  }
89 }
90 
91 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
93  //The following says we do not know what parameters are allowed so do no validation
94  // Please change this to state exactly what you do use, even if it is no parameters
96  desc.setUnknown();
97  descriptions.addDefault(desc);
98 }
99 
100 //define this as a plug-in
void GetInputCollections(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EDProductGetter const & productGetter() const
Definition: Event.cc:106
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
edm::InputTag input_AssociationType_
def move
Definition: eostools.py:511
~PFCand_AssoMap() override
edm::EDGetTokenT< reco::PFCandidateCollection > token_PFCandidates_
void produce(edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const & label() const
Definition: InputTag.h:36
PFCand_AssoMap(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:144
std::unique_ptr< PFCandToVertexAssMap > SortPFCandAssociationMap(PFCandToVertexAssMap *, edm::EDProductGetter const *getter)
std::pair< std::unique_ptr< PFCandToVertexAssMap >, std::unique_ptr< VertexToPFCandAssMap > > createMappings(edm::Handle< reco::PFCandidateCollection > pfCandH)