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
// -*- C++ -*-
//
// Package:    PF_PU_AssoMap
// Class:      PF_PU_AssoMap
//
/**\class PF_PU_AssoMap PF_PU_AssoMap.cc CommonTools/RecoUtils/plugins/PF_PU_AssoMap.cc

 Description: Produces a map with association between tracks and their particular most probable vertex with a quality of this association

*/
//
// Original Author:  Matthias Geisler,32 4-B20,+41227676487,
// $Id$
//
//

#include "CommonTools/RecoUtils/interface/PF_PU_AssoMap.h"

//
// static data member definitions
//

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

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

  token_TrackCollection_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("TrackCollection"));

  //register your products

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

PF_PU_AssoMap::~PF_PU_AssoMap() {
  // do anything here that needs to be done at destruction time
  // (e.g. close files, deallocate resources etc.)
}

//
// member functions
//

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

  //get the input track collection
  Handle<TrackCollection> trkcollH;
  iEvent.getByToken(token_TrackCollection_, trkcollH);

  string asstype = input_AssociationType_.label();

  PF_PU_AssoMapAlgos::GetInputCollections(iEvent, iSetup);

  if (asstype == "TracksToVertex" || asstype == "VertexToTracks" || asstype == "Both") {
    auto mappings = createMappings(trkcollH);
    if (asstype == "TracksToVertex" || asstype == "Both") {
      iEvent.put(SortAssociationMap(&(*mappings.first), trkcollH));
    }
    if (asstype == "VertexToTracks" || asstype == "Both") {
      iEvent.put(std::move(mappings.second));
    }
  }
}

// ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
void PF_PU_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(PF_PU_AssoMap);