Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:45

0001 // -*- C++ -*-
0002 //
0003 // Package:    PhysicsTools/NanoAOD
0004 // Class:      IsFromLostTrackMapProducer
0005 //
0006 /**\class IsFromLostTrackMapProducer IsFromLostTrackMapProducer.cc PhysicsTools/NanoAOD/plugins/IsFromLostTrackMapProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Maria Giulia Ratti (ETHZ) [mratti]
0015 //         Created:  Thu, 22 Nov 2018 12:34:48 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031 
0032 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0033 #include "DataFormats/PatCandidates/interface/IsolatedTrack.h"
0034 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0035 
0036 //
0037 // class declaration
0038 //
0039 
0040 class IsFromLostTrackMapProducer : public edm::global::EDProducer<> {
0041 public:
0042   explicit IsFromLostTrackMapProducer(const edm::ParameterSet& iConfig)
0043       : srcIsoTracks_(consumes<edm::View<pat::IsolatedTrack>>(
0044             iConfig.getParameter<edm::InputTag>("srcIsoTracks"))),  // final isolated tracks
0045         pc_(consumes<pat::PackedCandidateCollection>(
0046             iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),  // pf candidates
0047         lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks")))  // lost tracks
0048   {
0049     produces<edm::ValueMap<bool>>("isFromLostTrack");  // name of the value map that I want to actually produce
0050   }
0051   ~IsFromLostTrackMapProducer() override{};
0052 
0053   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054 
0055 private:
0056   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0057 
0058   // ----------member data ---------------------------
0059   edm::EDGetTokenT<edm::View<pat::IsolatedTrack>> srcIsoTracks_;
0060   edm::EDGetTokenT<pat::PackedCandidateCollection> pc_;
0061   edm::EDGetTokenT<pat::PackedCandidateCollection> lt_;
0062 };
0063 
0064 //
0065 // constants, enums and typedefs
0066 //
0067 
0068 //
0069 // static data member definitions
0070 //
0071 
0072 //
0073 // member functions
0074 //
0075 
0076 // ------------ method called to produce the data  ------------
0077 void IsFromLostTrackMapProducer::produce(edm::StreamID streamID,
0078                                          edm::Event& iEvent,
0079                                          const edm::EventSetup& iSetup) const {
0080   // isolated tracks
0081   edm::Handle<edm::View<pat::IsolatedTrack>> srcIsoTracks;
0082   iEvent.getByToken(srcIsoTracks_, srcIsoTracks);
0083 
0084   // packedPFCandidate collection
0085   edm::Handle<pat::PackedCandidateCollection> pc_handle;
0086   iEvent.getByToken(pc_, pc_handle);
0087 
0088   // lostTracks collection
0089   edm::Handle<pat::PackedCandidateCollection> lt_handle;
0090   iEvent.getByToken(lt_, lt_handle);
0091 
0092   // the map cannot be filled straight away, so create an intermediate vector
0093   unsigned int Nit = srcIsoTracks->size();
0094   std::vector<bool> v_isFromLostTrack(Nit, false);
0095 
0096   for (unsigned int iit = 0; iit < Nit; iit++) {
0097     auto isotrack = srcIsoTracks->ptrAt(iit);
0098     pat::PackedCandidateRef pcref =
0099         isotrack->packedCandRef();  // this is either the reference to the pf candidate or to the lost track
0100     bool isFromLostTrack = (pcref.isNonnull() && pcref.id() == lt_handle.id());
0101     v_isFromLostTrack[iit] = isFromLostTrack;
0102   }
0103 
0104   std::unique_ptr<edm::ValueMap<bool>> vm_isFromLostTrack(new edm::ValueMap<bool>());
0105   edm::ValueMap<bool>::Filler filler(*vm_isFromLostTrack);
0106   filler.insert(srcIsoTracks, v_isFromLostTrack.begin(), v_isFromLostTrack.end());
0107   filler.fill();
0108   iEvent.put(std::move(vm_isFromLostTrack), "isFromLostTrack");
0109 }
0110 
0111 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0112 void IsFromLostTrackMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0113   edm::ParameterSetDescription desc;
0114   desc.add<edm::InputTag>("srcIsoTracks")->setComment("isolated track input collection");
0115   desc.add<edm::InputTag>("packedPFCandidates")->setComment("packed PF Candidates collection ");
0116   desc.add<edm::InputTag>("lostTracks")->setComment("lost tracks collection");
0117 
0118   descriptions.addWithDefaultLabel(desc);
0119 }
0120 
0121 //define this as a plug-in
0122 DEFINE_FWK_MODULE(IsFromLostTrackMapProducer);