test
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  std::auto_ptr<TrackToTrackMap> trackToTrackMap_cleaned(new TrackToTrackMap());
97 
98  edm::Handle<TrackToTrackMap> trackToTrackMap;
99  evt.getByLabel(todoItem->srcTracks_, trackToTrackMap);
100  if ( verbosity_ ) {
101  for ( typename TrackToTrackMap::const_iterator entry = trackToTrackMap->begin();
102  entry != trackToTrackMap->end(); ++entry ) {
103  std::cout << "trackToTrackMap[" << entry->key.id() << ":" << entry->key.key() << "] = " << entry->val.id() << ":" << entry->val.key() << std::endl;
104  }
105  }
106 
107  size_t numGlobalMuons_cleaned = globalMuons_cleaned->size();
108  for ( size_t iGlobalMuons_cleaned = 0; iGlobalMuons_cleaned < numGlobalMuons_cleaned; ++iGlobalMuons_cleaned ) {
109  reco::TrackRef globalMuonTrack_cleaned(globalMuons_cleaned, iGlobalMuons_cleaned);
110  if ( verbosity_ ) {
111  std::cout << " globalMuon(cleaned = " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "):"
112  << " Pt = " << globalMuonTrack_cleaned->pt() << ", eta = " << globalMuonTrack_cleaned->eta() << ", phi = " << globalMuonTrack_cleaned->phi() << std::endl;
113  }
114  bool isMatched = false;
115  reco::TrackRef tevMuonTrack_matched;
116  double dRmatch = 1.e+3;
117  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
118  if ( isMatched ) {
119  if ( verbosity_ ) {
120  std::cout << "--> adding trackToTrackMap[" << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "]"
121  << " = " << tevMuonTrack_matched.id() << ":" << tevMuonTrack_matched.key() << std::endl;
122  }
123  trackToTrackMap_cleaned->insert(globalMuonTrack_cleaned, tevMuonTrack_matched);
124  } else {
125  throw cms::Exception("TeVMuonTrackCleaner::produceTrackExtras")
126  << "Failed to find Track association for " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "!!\n";
127  }
128  }
129 
130  evt.put(trackToTrackMap_cleaned, todoItem->srcTracks_.instance());
131  }
132 }
133 
135 
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
edm::InputTag srcGlobalMuons_cleaned_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void produceTrackExtras(edm::Event &, const edm::EventSetup &)
bool isMatched(TrackingRecHit const &hit)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
TeVMuonTrackCleaner(const edm::ParameterSet &)
edm::AssociationMap< edm::OneToOne< reco::TrackCollection, reco::TrackCollection > > TrackToTrackMap
key_type key() const
Accessor for product key.
Definition: Ref.h:266
std::string const & label() const
Definition: InputTag.h:42
std::string const & process() const
Definition: InputTag.h:46
tuple cout
Definition: gather_cfg.py:121
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
std::vector< todoListEntryType > todoList_
std::string const & instance() const
Definition: InputTag.h:43