Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:33:59

0001 #include "DataFormats/Math/interface/deltaR.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 
0010 #include <memory>
0011 #include <vector>
0012 
0013 ////////////////////////////////////////////////////////////////////////////////
0014 // class definition
0015 ////////////////////////////////////////////////////////////////////////////////
0016 class IsoTracks : public edm::global::EDProducer<> {
0017 public:
0018   explicit IsoTracks(edm::ParameterSet const&);
0019   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0020 
0021 private:
0022   double coneRadius_;
0023   double threshold_;
0024   edm::EDGetTokenT<std::vector<reco::Track>> v_recoTrackToken_;
0025 };
0026 
0027 ////////////////////////////////////////////////////////////////////////////////
0028 // construction
0029 ////////////////////////////////////////////////////////////////////////////////
0030 
0031 IsoTracks::IsoTracks(edm::ParameterSet const& iConfig)
0032     : coneRadius_{iConfig.getParameter<double>("radius")},
0033       threshold_{iConfig.getParameter<double>("SumPtFraction")},
0034       v_recoTrackToken_{consumes<std::vector<reco::Track>>(iConfig.getParameter<edm::InputTag>("src"))} {
0035   produces<std::vector<reco::Track>>();
0036 }
0037 
0038 ////////////////////////////////////////////////////////////////////////////////
0039 // implementation of member functions
0040 ////////////////////////////////////////////////////////////////////////////////
0041 
0042 //______________________________________________________________________________
0043 void IsoTracks::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0044   auto isoTracks = std::make_unique<std::vector<reco::Track>>();
0045 
0046   edm::Handle<std::vector<reco::Track>> dirtyTracks;
0047   iEvent.getByToken(v_recoTrackToken_, dirtyTracks);
0048 
0049   if (dirtyTracks->empty()) {
0050     iEvent.put(std::move(isoTracks));
0051     return;
0052   }
0053 
0054   double sumPtInCone{};
0055   for (auto it1 = dirtyTracks->begin(); it1 != dirtyTracks->end(); ++it1) {
0056     for (auto it2 = dirtyTracks->begin(); it2 != dirtyTracks->end(); ++it2) {
0057       if (it1 == it2)
0058         continue;
0059       if (deltaR(it1->eta(), it1->phi(), it2->eta(), it2->phi()) < coneRadius_) {
0060         sumPtInCone += it2->pt();
0061       }
0062     }
0063     if (sumPtInCone <= threshold_ * it1->pt()) {
0064       isoTracks->push_back(*it1);
0065     }
0066   }
0067 
0068   iEvent.put(std::move(isoTracks));
0069 }
0070 
0071 DEFINE_FWK_MODULE(IsoTracks);