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  TrackToTrackMap::ref_type::value_type refProd = trackToTrackMap1->refProd().val;
120  if(trackToTrackMap1->empty()) refProd = trackToTrackMap2->refProd().val;
121  std::auto_ptr<TrackToTrackMap> trackToTrackMap_output(new TrackToTrackMap(globalMuons_cleaned, refProd));
122 
123  size_t numGlobalMuons_cleaned = globalMuons_cleaned->size();
124  for ( size_t iGlobalMuons_cleaned = 0; iGlobalMuons_cleaned < numGlobalMuons_cleaned; ++iGlobalMuons_cleaned ) {
125  reco::TrackRef globalMuonTrack_cleaned(globalMuons_cleaned, iGlobalMuons_cleaned);
126  if ( verbosity_ ) {
127  std::cout << " globalMuon(cleaned = " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "):"
128  << " Pt = " << globalMuonTrack_cleaned->pt() << ", eta = " << globalMuonTrack_cleaned->eta() << ", phi = " << globalMuonTrack_cleaned->phi() << std::endl;
129  }
130  bool isMatched = false;
131  reco::TrackRef tevMuonTrack_matched;
132  double dRmatch = 1.e+3;
133  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap1, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
134  matchMuonTracks(globalMuonTrack_cleaned, *trackToTrackMap2, isMatched, tevMuonTrack_matched, dRmatch, verbosity_);
135  if ( isMatched ) {
136  if ( verbosity_ ) {
137  std::cout << "--> adding trackToTrackMap[" << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "]"
138  << " = " << tevMuonTrack_matched.id() << ":" << tevMuonTrack_matched.key() << std::endl;
139  }
140  trackToTrackMap_output->insert(globalMuonTrack_cleaned, tevMuonTrack_matched);
141  } else {
142  throw cms::Exception("TeVMuonTrackMixer::produceTrackExtras")
143  << "Failed to find Track association for " << globalMuonTrack_cleaned.id() << ":" << globalMuonTrack_cleaned.key() << "!!\n";
144  }
145  }
146 
147  evt.put(trackToTrackMap_output, todoItem->srcTrackCollection1_.instance());
148  }
149 }
150 
152 
std::vector< todoListEntryType > todoList_
tuple cfg
Definition: looper.py:293
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag srcGlobalMuons_cleaned_
key_type key() const
Accessor for product key.
Definition: Ref.h:264
ProductID id() const
Accessor for product ID.
Definition: Ref.h:258
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
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:418
TeVMuonTrackMixer(const edm::ParameterSet &)
virtual void produceTrackExtras(edm::Event &, const edm::EventSetup &)
list entry
Definition: mps_splice.py:62
tuple cout
Definition: gather_cfg.py:145
std::string moduleLabel_