CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TeVMuonTrackCleaner.cc
Go to the documentation of this file.
1 
23 
29 
31 
33 
34 #include <vector>
35 #include <algorithm>
36 
38 
40 {
41  public:
42  explicit TeVMuonTrackCleaner(const edm::ParameterSet&);
44 
45  private:
46  virtual void produceTrackExtras(edm::Event&, const edm::EventSetup&);
47 
49 };
50 
52  : MuonTrackCleanerBase(cfg),
53  srcGlobalMuons_cleaned_(cfg.getParameter<edm::InputTag>("srcGlobalMuons_cleaned"))
54 {
55  for ( typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
56  todoItem != todoList_.end(); ++todoItem ) {
57  produces<TrackToTrackMap>(todoItem->srcTracks_.instance());
58  }
59 }
60 
61 namespace
62 {
63  void matchMuonTracks(const reco::TrackRef& globalMuonTrack_cleaned, const TrackToTrackMap& trackToTrackMap, bool& isMatched, reco::TrackRef& tevMuonTrack_matched, double& dRmatch, int verbosity)
64  {
65  for ( typename TrackToTrackMap::const_iterator entry = trackToTrackMap.begin();
66  entry != trackToTrackMap.end(); ++entry ) {
67  reco::TrackRef globalMuonTrack_uncleaned = entry->key;
68  double dR = reco::deltaR(globalMuonTrack_uncleaned->eta(), globalMuonTrack_uncleaned->phi(), globalMuonTrack_cleaned->eta(), globalMuonTrack_cleaned->phi());
69  if ( verbosity ) {
70  std::cout << "globalMuon(uncleaned = " << globalMuonTrack_uncleaned.id() << ":" << globalMuonTrack_uncleaned.key() << "):"
71  << " Pt = " << globalMuonTrack_uncleaned->pt() << ", eta = " << globalMuonTrack_uncleaned->eta() << ", phi = " << globalMuonTrack_uncleaned->phi() << ","
72  << " dR = " << dR << std::endl;
73  }
74  if ( dR < 1.e-2 && dR < dRmatch ) {
75  isMatched = true;
76  tevMuonTrack_matched = entry->val;
77  dRmatch = dR;
78  }
79  }
80  }
81 }
82 
84 {
85  if ( verbosity_ ) std::cout << "<TeVMuonTrackCleaner::produceTrackExtras (" << moduleLabel_ << ")>:" << std::endl;
86 
87  edm::Handle<reco::TrackCollection> globalMuons_cleaned;
88  evt.getByLabel(srcGlobalMuons_cleaned_, globalMuons_cleaned);
89  if ( verbosity_ ) {
90  std::cout << "globalMuons(cleaned = " << srcGlobalMuons_cleaned_.label() << ":" << srcGlobalMuons_cleaned_.instance() << ":" << srcGlobalMuons_cleaned_.process() << ","
91  << " productId = " << globalMuons_cleaned.id() << "): #entries = " << globalMuons_cleaned->size() << std::endl;
92  }
93 
94  for ( typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
95  todoItem != todoList_.end(); ++todoItem ) {
96 
97  edm::Handle<TrackToTrackMap> trackToTrackMap;
98  evt.getByLabel(todoItem->srcTracks_, trackToTrackMap);
99  if ( verbosity_ ) {
100  for ( typename TrackToTrackMap::const_iterator entry = trackToTrackMap->begin();
101  entry != trackToTrackMap->end(); ++entry ) {
102  std::cout << "trackToTrackMap[" << entry->key.id() << ":" << entry->key.key() << "] = " << entry->val.id() << ":" << entry->val.key() << std::endl;
103  }
104  }
105 
106  std::auto_ptr<TrackToTrackMap> trackToTrackMap_cleaned(new TrackToTrackMap(globalMuons_cleaned, trackToTrackMap->refProd().val));
107 
108  size_t numGlobalMuons_cleaned = globalMuons_cleaned->size();
109  for ( size_t iGlobalMuons_cleaned = 0; iGlobalMuons_cleaned < numGlobalMuons_cleaned; ++iGlobalMuons_cleaned ) {
110  reco::TrackRef globalMuonTrack_cleaned(globalMuons_cleaned, iGlobalMuons_cleaned);
111  if ( verbosity_ ) {
112  std::cout << " globalMuon(cleaned = " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "):"
113  << " Pt = " << globalMuonTrack_cleaned->pt() << ", eta = " << globalMuonTrack_cleaned->eta() << ", phi = " << globalMuonTrack_cleaned->phi() << std::endl;
114  }
115  bool isMatched = false;
116  reco::TrackRef tevMuonTrack_matched;
117  double dRmatch = 1.e+3;
118  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
119  if ( isMatched ) {
120  if ( verbosity_ ) {
121  std::cout << "--> adding trackToTrackMap[" << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "]"
122  << " = " << tevMuonTrack_matched.id() << ":" << tevMuonTrack_matched.key() << std::endl;
123  }
124  trackToTrackMap_cleaned->insert(globalMuonTrack_cleaned, tevMuonTrack_matched);
125  } else {
126  throw cms::Exception("TeVMuonTrackCleaner::produceTrackExtras")
127  << "Failed to find Track association for " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "!!\n";
128  }
129  }
130 
131  evt.put(trackToTrackMap_cleaned, todoItem->srcTracks_.instance());
132  }
133 }
134 
136 
tuple cfg
Definition: looper.py:259
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
key_type key() const
Accessor for product key.
Definition: Ref.h:264
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
edm::InputTag srcGlobalMuons_cleaned_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
virtual void produceTrackExtras(edm::Event &, const edm::EventSetup &)
bool isMatched(TrackingRecHit const &hit)
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, reco::TrackCollection > > TrackToTrackMap
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
TeVMuonTrackCleaner(const edm::ParameterSet &)
std::string const & label() const
Definition: InputTag.h:43
std::string const & process() const
Definition: InputTag.h:47
tuple cout
Definition: gather_cfg.py:121
std::vector< todoListEntryType > todoList_
std::string const & instance() const
Definition: InputTag.h:44