Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:41

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         lt_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("lostTracks")))  // lost tracks
0046   {
0047     produces<edm::ValueMap<bool>>("isFromLostTrack");  // name of the value map that I want to actually produce
0048   }
0049   ~IsFromLostTrackMapProducer() override{};
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0055 
0056   // ----------member data ---------------------------
0057   edm::EDGetTokenT<edm::View<pat::IsolatedTrack>> srcIsoTracks_;
0058   edm::EDGetTokenT<pat::PackedCandidateCollection> lt_;
0059 };
0060 
0061 //
0062 // constants, enums and typedefs
0063 //
0064 
0065 //
0066 // static data member definitions
0067 //
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 // ------------ method called to produce the data  ------------
0074 void IsFromLostTrackMapProducer::produce(edm::StreamID streamID,
0075                                          edm::Event& iEvent,
0076                                          const edm::EventSetup& iSetup) const {
0077   // isolated tracks
0078   auto srcIsoTracks = iEvent.getHandle(srcIsoTracks_);
0079 
0080   // lostTracks collection
0081   auto ltHandle = iEvent.getHandle(lt_);
0082 
0083   // the map cannot be filled straight away, so create an intermediate vector
0084   unsigned int Nit = srcIsoTracks->size();
0085   std::vector<bool> v_isFromLostTrack(Nit, false);
0086 
0087   for (unsigned int iit = 0; iit < Nit; iit++) {
0088     auto isotrack = srcIsoTracks->ptrAt(iit);
0089     pat::PackedCandidateRef pcref =
0090         isotrack->packedCandRef();  // this is either the reference to the pf candidate or to the lost track
0091     bool isFromLostTrack = (pcref.isNonnull() && pcref.id() == ltHandle.id());
0092     v_isFromLostTrack[iit] = isFromLostTrack;
0093   }
0094 
0095   auto vm_isFromLostTrack = std::make_unique<edm::ValueMap<bool>>();
0096   edm::ValueMap<bool>::Filler filler(*vm_isFromLostTrack);
0097   filler.insert(srcIsoTracks, v_isFromLostTrack.begin(), v_isFromLostTrack.end());
0098   filler.fill();
0099   iEvent.put(std::move(vm_isFromLostTrack), "isFromLostTrack");
0100 }
0101 
0102 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0103 void IsFromLostTrackMapProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0104   edm::ParameterSetDescription desc;
0105   desc.add<edm::InputTag>("srcIsoTracks")->setComment("isolated track input collection");
0106   desc.add<edm::InputTag>("lostTracks")->setComment("lost tracks collection");
0107 
0108   descriptions.addWithDefaultLabel(desc);
0109 }
0110 
0111 //define this as a plug-in
0112 DEFINE_FWK_MODULE(IsFromLostTrackMapProducer);