CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TeVMuonTrackMixer.cc
Go to the documentation of this file.
1 
24 
26 
32 
34 
35 #include <vector>
36 
38 
40 {
41  public:
42  explicit TeVMuonTrackMixer(const edm::ParameterSet&);
44 
45  private:
46  virtual void produceTrackExtras(edm::Event&, const edm::EventSetup&);
47 
49 };
50 
52  : TrackMixerBase(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->srcTrackCollection1_.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 << "<TeVMuonTrackMixer::produceTrackExtras (" << moduleLabel_ << ")>:" << std::endl;
86 
87  edm::Handle<reco::TrackCollection> globalMuons_cleaned;
88  evt.getByLabel(srcGlobalMuons_cleaned_, globalMuons_cleaned);
89 
90  for ( typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
91  todoItem != todoList_.end(); ++todoItem ) {
92  edm::Handle<reco::TrackCollection> trackCollection1;
93  evt.getByLabel(todoItem->srcTrackCollection1_, trackCollection1);
94  edm::Handle<TrackToTrackMap> trackToTrackMap1;
95  evt.getByLabel(todoItem->srcTrackCollection1_, trackToTrackMap1);
96 
97  edm::Handle<reco::TrackCollection> trackCollection2;
98  evt.getByLabel(todoItem->srcTrackCollection2_, trackCollection2);
99  edm::Handle<TrackToTrackMap> trackToTrackMap2;
100  evt.getByLabel(todoItem->srcTrackCollection2_, trackToTrackMap2);
101 
102  if ( verbosity_ ) {
103  std::cout << "input1 (" << todoItem->srcTrackCollection1_.label() << ":" << todoItem->srcTrackCollection1_.instance() << ":" << todoItem->srcTrackCollection1_.process() << "):" << std::endl;
104  std::cout << " trackCollection(productId = " << trackCollection1.id() << "): #entries = " << trackCollection1->size() << std::endl;
105  std::cout << " trackToTrackMap(productId = " << trackToTrackMap1.id() << "): #entries = " << trackToTrackMap1->size() << std::endl;
106  for ( typename TrackToTrackMap::const_iterator entry = trackToTrackMap1->begin();
107  entry != trackToTrackMap1->end(); ++entry ) {
108  std::cout << " trackToTrackMap[" << entry->key.id() << ":" << entry->key.key() << "] = " << entry->val.id() << ":" << entry->val.key() << std::endl;
109  }
110  std::cout << "input2 (" << todoItem->srcTrackCollection2_.label() << ":" << todoItem->srcTrackCollection2_.instance() << ":" << todoItem->srcTrackCollection2_.process() << "):" << std::endl;
111  std::cout << " trackCollection(productId = " << trackCollection2.id() << "): #entries = " << trackCollection2->size() << std::endl;
112  std::cout << " trackToTrackMap(productId = " << trackToTrackMap2.id() << "): #entries = " << trackToTrackMap2->size() << std::endl;
113  for ( typename TrackToTrackMap::const_iterator entry = trackToTrackMap2->begin();
114  entry != trackToTrackMap2->end(); ++entry ) {
115  std::cout << " trackToTrackMap[" << entry->key.id() << ":" << entry->key.key() << "] = " << entry->val.id() << ":" << entry->val.key() << std::endl;
116  }
117  }
118 
119  std::auto_ptr<TrackToTrackMap> trackToTrackMap_output(new TrackToTrackMap());
120 
121  size_t numGlobalMuons_cleaned = globalMuons_cleaned->size();
122  for ( size_t iGlobalMuons_cleaned = 0; iGlobalMuons_cleaned < numGlobalMuons_cleaned; ++iGlobalMuons_cleaned ) {
123  reco::TrackRef globalMuonTrack_cleaned(globalMuons_cleaned, iGlobalMuons_cleaned);
124  if ( verbosity_ ) {
125  std::cout << " globalMuon(cleaned = " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "):"
126  << " Pt = " << globalMuonTrack_cleaned->pt() << ", eta = " << globalMuonTrack_cleaned->eta() << ", phi = " << globalMuonTrack_cleaned->phi() << std::endl;
127  }
128  bool isMatched = false;
129  reco::TrackRef tevMuonTrack_matched;
130  double dRmatch = 1.e+3;
131  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap1, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
132  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap2, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
133  if ( isMatched ) {
134  if ( verbosity_ ) {
135  std::cout << "--> adding trackToTrackMap[" << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "]"
136  << " = " << tevMuonTrack_matched.id() << ":" << tevMuonTrack_matched.key() << std::endl;
137  }
138  trackToTrackMap_output->insert(globalMuonTrack_cleaned, tevMuonTrack_matched);
139  } else {
140  throw cms::Exception("TeVMuonTrackMixer::produceTrackExtras")
141  << "Failed to find Track association for " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "!!\n";
142  }
143  }
144 
145  evt.put(trackToTrackMap_output, todoItem->srcTrackCollection1_.instance());
146  }
147 }
148 
150 
std::vector< todoListEntryType > todoList_
tuple cfg
Definition: looper.py:237
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag srcGlobalMuons_cleaned_
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
key_type key() const
Accessor for product key.
Definition: Ref.h:266
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
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:402
TeVMuonTrackMixer(const edm::ParameterSet &)
virtual void produceTrackExtras(edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121
std::string moduleLabel_
tuple verbosity
Definition: mvaPFMET_cff.py:80