Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
// -*- C++ -*-
//
// Package:    PFCand_AssoMap
// Class:      PFCand_AssoMap
//
/**\class PFCand_AssoMap PFCand_AssoMap.cc CommonTools/RecoUtils/plugins/PFCand_AssoMap.cc

  Description: Produces a map with association between pf candidates and their particular most probable vertex with a quality of this association
*/
//
// Original Author:  Matthias Geisler
//         Created:  Wed Apr 18 14:48:37 CEST 2012
// $Id: PFCand_AssoMap.cc,v 1.5 2012/11/21 09:52:27 mgeisler Exp $
//
//
#include "CommonTools/RecoUtils/interface/PFCand_AssoMap.h"

// system include files
#include <memory>
#include <vector>
#include <string>

// user include files

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"

//
// constructors and destructor
//
PFCand_AssoMap::PFCand_AssoMap(const edm::ParameterSet& iConfig) : PFCand_AssoMapAlgos(iConfig, consumesCollector()) {
  //now do what ever other initialization is needed

  input_AssociationType_ = iConfig.getParameter<edm::InputTag>("AssociationType");

  token_PFCandidates_ =
      consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidateCollection"));

  //register your products

  if (input_AssociationType_.label() == "PFCandsToVertex") {
    produces<PFCandToVertexAssMap>();
  } else {
    if (input_AssociationType_.label() == "VertexToPFCands") {
      produces<VertexToPFCandAssMap>();
    } else {
      if (input_AssociationType_.label() == "Both") {
        produces<PFCandToVertexAssMap>();
        produces<VertexToPFCandAssMap>();
      } else {
        std::cout << "No correct InputTag for AssociationType!" << std::endl;
        std::cout << "Won't produce any AssociationMap!" << std::endl;
      }
    }
  }
}

PFCand_AssoMap::~PFCand_AssoMap() {}

//
// member functions
//

// ------------ method called to produce the data  ------------
void PFCand_AssoMap::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
  using namespace edm;
  using namespace std;
  using namespace reco;

  //get the input pfCandidateCollection
  Handle<PFCandidateCollection> pfCandH;
  iEvent.getByToken(token_PFCandidates_, pfCandH);

  string asstype = input_AssociationType_.label();

  PFCand_AssoMapAlgos::GetInputCollections(iEvent, iSetup);

  if (asstype == "PFCandsToVertex" || asstype == "VertexToPFCands" || asstype == "Both") {
    auto mappings = createMappings(pfCandH);
    if (asstype == "PFCandsToVertex" || asstype == "Both") {
      iEvent.put(SortPFCandAssociationMap(&(*mappings.first), &iEvent.productGetter()));
    }
    if (asstype == "VertexToPFCands" || asstype == "Both") {
      iEvent.put(std::move(mappings.second));
    }
  }
}

// ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
void PFCand_AssoMap::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
  //The following says we do not know what parameters are allowed so do no validation
  // Please change this to state exactly what you do use, even if it is no parameters
  edm::ParameterSetDescription desc;
  desc.setUnknown();
  descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(PFCand_AssoMap);