CMS 3D CMS Logo

CosmicMuonLinksProducer.cc
Go to the documentation of this file.
2 
9 // system include files
10 #include <memory>
11 
12 // user include files
15 
18 
20 
24 
28 
29 using namespace edm;
30 using namespace std;
31 using namespace reco;
32 
33 //
34 // constructors and destructor
35 //
37  category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonLinksProducer";
38 
39  ParameterSet serviceParameters = iConfig.getParameter<ParameterSet>("ServiceParameters");
40 
41  theService = new MuonServiceProxy(serviceParameters, consumesCollector());
42 
43  std::vector<edm::ParameterSet> theMapPSets = iConfig.getParameter<std::vector<edm::ParameterSet> >("Maps");
44  for (std::vector<edm::ParameterSet>::const_iterator iMPS = theMapPSets.begin(); iMPS != theMapPSets.end(); iMPS++) {
45  edm::InputTag sTag = (*iMPS).getParameter<edm::InputTag>("subTrack");
46  edm::InputTag pTag = (*iMPS).getParameter<edm::InputTag>("parentTrack");
47 
48  edm::EDGetTokenT<reco::TrackCollection> subTrackTag = consumes<reco::TrackCollection>(sTag);
49  edm::EDGetTokenT<reco::TrackCollection> parentTrackTag = consumes<reco::TrackCollection>(pTag);
50  theTrackLinks.push_back(make_pair(subTrackTag, parentTrackTag));
51  theTrackLinkNames.push_back(make_pair(sTag.label(), pTag.label()));
52 
53  LogDebug(category_) << "preparing map between " << sTag << " & " << pTag;
54  std::string mapname = sTag.label() + "To" + pTag.label();
55  produces<reco::TrackToTrackMap>(mapname);
56  }
57 }
58 
60  if (theService)
61  delete theService;
62 }
63 
64 // ------------ method called to produce the data ------------
66  LogInfo(category_) << "Processing event number: " << iEvent.id();
67 
68  theService->update(iSetup);
69 
70  unsigned int counter =
71  0;
73  edm::EDGetTokenT<reco::TrackCollection> > >::const_iterator iLink = theTrackLinks.begin();
74  iLink != theTrackLinks.end();
75  iLink++) {
76 #ifdef EDM_ML_DEBUG
77  edm::EDConsumerBase::Labels labels_first;
78  edm::EDConsumerBase::Labels labels_second;
79  labelsForToken(iLink->first, labels_first);
80  labelsForToken(iLink->second, labels_second);
81  LogDebug(category_) << "making map between " << labels_first.module << " and " << labels_second.module;
82 #endif
83  std::string mapname = theTrackLinkNames[counter].first + "To" + theTrackLinkNames[counter].second;
85 
87  Handle<reco::TrackCollection> parentTracks;
88 
89  iEvent.getByToken((*iLink).first, subTracks);
90  iEvent.getByToken((*iLink).second, parentTracks);
91 
92  ttmap = mapTracks(subTracks, parentTracks);
93  LogTrace(category_) << "Mapped: " << theTrackLinkNames[counter].first << " " << subTracks->size() << " and "
94  << theTrackLinkNames[counter].second << " " << parentTracks->size()
95  << ", results: " << ttmap.size() << endl;
96 
97  iEvent.put(std::make_unique<reco::TrackToTrackMap>(ttmap), mapname);
98 
99  counter++;
100  }
101 }
102 
104  const Handle<reco::TrackCollection>& parentTracks) const {
105  reco::TrackToTrackMap map(subTracks, parentTracks);
106  for (unsigned int position1 = 0; position1 != subTracks->size(); ++position1) {
107  TrackRef track1(subTracks, position1);
108  for (unsigned int position2 = 0; position2 != parentTracks->size(); ++position2) {
109  TrackRef track2(parentTracks, position2);
110  int shared = sharedHits(*track1, *track2);
111  LogTrace(category_) << "sharedHits " << shared << " track1 " << track1->found() << " track2 " << track2->found()
112  << endl;
113 
114  if (shared > (track1->found()) / 2)
115  map.insert(track1, track2);
116  }
117  }
118 
119  return map;
120 }
121 
122 int CosmicMuonLinksProducer::sharedHits(const reco::Track& track1, const reco::Track& track2) const {
123  int match = 0;
124 
125  for (trackingRecHit_iterator hit1 = track1.recHitsBegin(); hit1 != track1.recHitsEnd(); ++hit1) {
126  if (!(*hit1)->isValid())
127  continue;
128  DetId id1 = (*hit1)->geographicalId();
129  if (id1.det() != DetId::Muon)
130  continue; //ONLY MUON
131  LogTrace(category_) << "first ID " << id1.rawId() << " " << (*hit1)->localPosition() << endl;
132  GlobalPoint pos1 = theService->trackingGeometry()->idToDet(id1)->surface().toGlobal((*hit1)->localPosition());
133 
134  for (trackingRecHit_iterator hit2 = track2.recHitsBegin(); hit2 != track2.recHitsEnd(); ++hit2) {
135  if (!(*hit2)->isValid())
136  continue;
137 
138  DetId id2 = (*hit2)->geographicalId();
139  if (id2.det() != DetId::Muon)
140  continue; //ONLY MUON
141 
142  // LogTrace(category_)<<"second ID "<<id2.rawId()<< (*hit2)->localPosition()<<endl;
143 
144  if (id2.rawId() != id1.rawId())
145  continue;
146 
147  GlobalPoint pos2 = theService->trackingGeometry()->idToDet(id2)->surface().toGlobal((*hit2)->localPosition());
148  if ((pos1 - pos2).mag() < 10e-5)
149  match++;
150  }
151  }
152 
153  return match;
154 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void produce(edm::Event &, const edm::EventSetup &) override
std::string const & label() const
Definition: InputTag.h:36
#define LogTrace(id)
size_type size() const
map size
int iEvent
Definition: GenABIO.cc:224
int sharedHits(const reco::Track &track1, const reco::Track &track2) const
reco::TrackToTrackMap mapTracks(const edm::Handle< reco::TrackCollection > &, const edm::Handle< reco::TrackCollection > &) const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
char const * module
Definition: ProductLabels.h:5
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
Log< level::Info, false > LogInfo
Definition: DetId.h:17
fixed size matrix
HLT enums.
static std::atomic< unsigned int > counter
CosmicMuonLinksProducer(const edm::ParameterSet &)
#define LogDebug(id)
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)