CMS 3D CMS Logo

TrackerCleaner.h
Go to the documentation of this file.
1 
13 #ifndef TauAnalysis_MCEmbeddingTools_TrackerCleaner_H
14 #define TauAnalysis_MCEmbeddingTools_TrackerCleaner_H
15 
23 
27 
32 
33 
34 #include <string>
35 #include <iostream>
36 #include <map>
37 
38 
39 template <typename T>
41 {
42  public:
43  explicit TrackerCleaner(const edm::ParameterSet&);
44  ~TrackerCleaner() override;
45 
46  private:
47  void produce(edm::Event&, const edm::EventSetup&) override;
48 
51 
52  std::map<std::string, edm::EDGetTokenT<TrackClusterCollection > > inputs_;
53 
54  bool match_rechit_type(const TrackingRecHit &murechit);
55 
56 
57 };
58 
59 template <typename T>
61  mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection")))
62 
63 {
64  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
65  for (auto inCollection : inCollections){
66  inputs_[inCollection.instance()] = consumes<TrackClusterCollection >(inCollection);
67  produces<TrackClusterCollection>(inCollection.instance());
68  }
69 
70 
71 }
72 
73 
74 template <typename T>
76 {
77 // nothing to be done yet...
78 }
79 
80 
81 template <typename T>
83 {
84 
85  using namespace edm;
86 
88  iEvent.getByToken(mu_input_, muonHandle);
89  edm::View<pat::Muon> muons = *muonHandle;
90 
91  for (auto input_ : inputs_){
92 
94  iEvent.getByToken(input_.second, inputClusters);
95 
96  std::vector<bool> vetodClusters;
97 
98  vetodClusters.resize(inputClusters->dataSize(), false);
99 
100  for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
101  if(!iMuon->isGlobalMuon() ) continue;
102  const reco::Track* mutrack = iMuon->globalTrack().get();
103  // reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() ));
104  for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) {
105  const TrackingRecHit &murechit = **hitIt;
106  if(!(murechit).isValid()) continue;
107 
108  if (match_rechit_type(murechit)){
109  auto & thit = reinterpret_cast<BaseTrackerRecHit const&>(murechit);
110  auto const & cluster = thit.firstClusterRef();
111  vetodClusters[cluster.key()]=true;
112  }
113 
114 
115  }
116  }
117  std::unique_ptr<TrackClusterCollection > output(new TrackClusterCollection());
118 
119  int idx = 0;
120  for ( typename TrackClusterCollection::const_iterator clustSet = inputClusters->begin(); clustSet != inputClusters->end(); ++clustSet ) {
121  DetId detIdObject( clustSet->detId() );
122  typename TrackClusterCollection::FastFiller spc(*output, detIdObject);
123  for (typename edmNew::DetSet<T>::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end(); ++clustIt ) {
124  idx++;
125  if (vetodClusters[idx-1]) continue;
126  //if (!vetodClusters[idx-1]) continue; for inverted selction
127  spc.push_back(*clustIt);
128  }
129  }
130  iEvent.put(std::move(output),input_.first);
131  }
132 
133 }
134 #endif
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
const edm::EDGetTokenT< edm::View< pat::Muon > > mu_input_
data_type const * const_iterator
Definition: DetSetNew.h:30
TrackerCleaner(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
~TrackerCleaner() override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
const_iterator begin() const
Definition: Muon.py:1
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
Definition: DetId.h:18
std::map< std::string, edm::EDGetTokenT< TrackClusterCollection > > inputs_
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
virtual OmniClusterRef const & firstClusterRef() const =0
const_iterator end() const
bool match_rechit_type(const TrackingRecHit &murechit)
def move(src, dest)
Definition: eostools.py:510
edmNew::DetSetVector< T > TrackClusterCollection
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109