Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:54:33

0001 /** \class TrackerCleaner
0002  *
0003  * 
0004  * \author Stefan Wayand;
0005  *         Christian Veelken, LLR
0006  *
0007  * 
0008  *
0009  * 
0010  *
0011  */
0012 
0013 #ifndef TauAnalysis_MCEmbeddingTools_TrackerCleaner_H
0014 #define TauAnalysis_MCEmbeddingTools_TrackerCleaner_H
0015 
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "DataFormats/Common/interface/Handle.h"
0020 #include "DataFormats/PatCandidates/interface/Muon.h"
0021 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 
0024 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
0025 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
0026 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0027 
0028 #include "DataFormats/Common/interface/SortedCollection.h"
0029 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0030 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0031 #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h"
0032 
0033 #include <string>
0034 #include <iostream>
0035 #include <map>
0036 
0037 template <typename T>
0038 class TrackerCleaner : public edm::stream::EDProducer<> {
0039 public:
0040   explicit TrackerCleaner(const edm::ParameterSet&);
0041   ~TrackerCleaner() override;
0042 
0043 private:
0044   void produce(edm::Event&, const edm::EventSetup&) override;
0045 
0046   const edm::EDGetTokenT<edm::View<pat::Muon> > mu_input_;
0047   typedef edmNew::DetSetVector<T> TrackClusterCollection;
0048 
0049   std::map<std::string, edm::EDGetTokenT<TrackClusterCollection> > inputs_;
0050 
0051   bool match_rechit_type(const TrackingRecHit& murechit);
0052 };
0053 
0054 template <typename T>
0055 TrackerCleaner<T>::TrackerCleaner(const edm::ParameterSet& iConfig)
0056     : mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection")))
0057 
0058 {
0059   std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
0060   for (const auto& inCollection : inCollections) {
0061     inputs_[inCollection.instance()] = consumes<TrackClusterCollection>(inCollection);
0062     produces<TrackClusterCollection>(inCollection.instance());
0063   }
0064 }
0065 
0066 template <typename T>
0067 TrackerCleaner<T>::~TrackerCleaner() {
0068   // nothing to be done yet...
0069 }
0070 
0071 template <typename T>
0072 void TrackerCleaner<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0073   using namespace edm;
0074 
0075   edm::Handle<edm::View<pat::Muon> > muonHandle;
0076   iEvent.getByToken(mu_input_, muonHandle);
0077   edm::View<pat::Muon> muons = *muonHandle;
0078 
0079   for (auto input_ : inputs_) {
0080     edm::Handle<TrackClusterCollection> inputClusters;
0081     iEvent.getByToken(input_.second, inputClusters);
0082 
0083     std::vector<bool> vetodClusters;
0084 
0085     vetodClusters.resize(inputClusters->dataSize(), false);
0086 
0087     for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
0088       if (!iMuon->isGlobalMuon())
0089         continue;
0090       const reco::Track* mutrack = iMuon->globalTrack().get();
0091       //  reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() ));
0092       for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) {
0093         const TrackingRecHit& murechit = **hitIt;
0094         if (!(murechit).isValid())
0095           continue;
0096 
0097         if (match_rechit_type(murechit)) {
0098           auto& thit = reinterpret_cast<BaseTrackerRecHit const&>(murechit);
0099           auto const& cluster = thit.firstClusterRef();
0100           vetodClusters[cluster.key()] = true;
0101         }
0102       }
0103     }
0104     std::unique_ptr<TrackClusterCollection> output(new TrackClusterCollection());
0105 
0106     int idx = 0;
0107     for (typename TrackClusterCollection::const_iterator clustSet = inputClusters->begin();
0108          clustSet != inputClusters->end();
0109          ++clustSet) {
0110       DetId detIdObject(clustSet->detId());
0111       typename TrackClusterCollection::FastFiller spc(*output, detIdObject);
0112       for (typename edmNew::DetSet<T>::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end();
0113            ++clustIt) {
0114         idx++;
0115         if (vetodClusters[idx - 1])
0116           continue;
0117         //if (!vetodClusters[idx-1]) continue; for inverted selction
0118         spc.push_back(*clustIt);
0119       }
0120     }
0121     iEvent.put(std::move(output), input_.first);
0122   }
0123 }
0124 #endif