Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-26 00:02:48

0001 // -*- C++ -*-
0002 //
0003 // Package:    InterestingTrackEcalDetIdProducer
0004 // Class:      InterestingTrackEcalDetIdProducer
0005 //
0006 /**\class InterestingTrackEcalDetIdProducer InterestingTrackEcalDetIdProducer.cc Producers/InterestingTrackEcalDetIdProducer/src/InterestingTrackEcalDetIdProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:
0015 //         Created:  Wed Sep 22 17:02:51 CEST 2010
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/stream/EDProducer.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 
0029 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0030 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0031 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0032 
0033 #include "DataFormats/DetId/interface/DetIdCollection.h"
0034 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0035 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0036 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0037 
0038 #include "DataFormats/TrackReco/interface/Track.h"
0039 
0040 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
0041 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
0042 
0043 //
0044 // class declaration
0045 //
0046 
0047 class InterestingTrackEcalDetIdProducer : public edm::stream::EDProducer<> {
0048 public:
0049   explicit InterestingTrackEcalDetIdProducer(const edm::ParameterSet&);
0050 
0051 private:
0052   void produce(edm::Event&, const edm::EventSetup&) override;
0053 
0054   // ----------member data ---------------------------
0055   edm::EDGetTokenT<reco::TrackCollection> trackCollectionToken_;
0056   edm::ParameterSet trackAssociatorPS_;
0057 
0058   double minTrackPt_;
0059 
0060   edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopologyToken_;
0061   TrackDetectorAssociator trackAssociator_;
0062   TrackAssociatorParameters trackAssociatorParameters_;
0063 };
0064 
0065 //
0066 // constants, enums and typedefs
0067 //
0068 
0069 //
0070 // static data member definitions
0071 //
0072 
0073 //
0074 // constructors and destructor
0075 //
0076 InterestingTrackEcalDetIdProducer::InterestingTrackEcalDetIdProducer(const edm::ParameterSet& iConfig)
0077     : minTrackPt_(iConfig.getParameter<double>("MinTrackPt")),
0078       caloTopologyToken_(esConsumes())
0079 
0080 {
0081   trackCollectionToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("TrackCollection"));
0082   trackAssociator_.useDefaultPropagator();
0083   edm::ConsumesCollector iC = consumesCollector();
0084   trackAssociatorParameters_.loadParameters(iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters"), iC);
0085 
0086   produces<DetIdCollection>();
0087 }
0088 
0089 //
0090 // member functions
0091 //
0092 
0093 // ------------ method called to produce the data  ------------
0094 void InterestingTrackEcalDetIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0095   using namespace edm;
0096 
0097   auto interestingDetIdCollection = std::make_unique<DetIdCollection>();
0098 
0099   // Get tracks from event
0100   edm::Handle<reco::TrackCollection> tracks;
0101   iEvent.getByToken(trackCollectionToken_, tracks);
0102 
0103   const auto& caloTopology = iSetup.getData(caloTopologyToken_);
0104 
0105   // Loop over tracks
0106   for (reco::TrackCollection::const_iterator tkItr = tracks->begin(); tkItr != tracks->end(); ++tkItr) {
0107     if (tkItr->pt() < minTrackPt_)
0108       continue;
0109 
0110     TrackDetMatchInfo info = trackAssociator_.associate(
0111         iEvent,
0112         iSetup,
0113         trackAssociator_.getFreeTrajectoryState(&iSetup.getData(trackAssociatorParameters_.bFieldToken), *tkItr),
0114         trackAssociatorParameters_);
0115 
0116     DetId centerId = info.findMaxDeposition(TrackDetMatchInfo::EcalRecHits);
0117 
0118     if (centerId.rawId() == 0)
0119       continue;
0120 
0121     // Find 5x5 around max
0122     const CaloSubdetectorTopology* topology = caloTopology.getSubdetectorTopology(DetId::Ecal, centerId.subdetId());
0123     const std::vector<DetId>& ids = topology->getWindow(centerId, 5, 5);
0124     for (std::vector<DetId>::const_iterator idItr = ids.begin(); idItr != ids.end(); ++idItr) {
0125       if (std::find(interestingDetIdCollection->begin(), interestingDetIdCollection->end(), *idItr) ==
0126           interestingDetIdCollection->end())
0127         interestingDetIdCollection->push_back(*idItr);
0128     }
0129   }
0130 
0131   iEvent.put(std::move(interestingDetIdCollection));
0132 }
0133 
0134 //define this as a plug-in
0135 DEFINE_FWK_MODULE(InterestingTrackEcalDetIdProducer);