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 }
TrackExtra.h
counter
Definition: counter.py:1
CosmicMuonLinksProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CosmicMuonLinksProducer.cc:65
MessageLogger.h
ESHandle.h
reco::Track::recHitsBegin
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
CosmicMuonLinksProducer::CosmicMuonLinksProducer
CosmicMuonLinksProducer(const edm::ParameterSet &)
Definition: CosmicMuonLinksProducer.cc:36
edm::EDGetTokenT< reco::TrackCollection >
CosmicMuonLinksProducer.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ProductLabels::module
char const * module
Definition: ProductLabels.h:5
globals_cff.id1
id1
Definition: globals_cff.py:33
CosmicMuonLinksProducer::sharedHits
int sharedHits(const reco::Track &track1, const reco::Track &track2) const
Definition: CosmicMuonLinksProducer.cc:122
CosmicMuonLinksProducer::~CosmicMuonLinksProducer
~CosmicMuonLinksProducer() override
Definition: CosmicMuonLinksProducer.cc:59
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
muonCosmicCompatibility_cfi.sharedHits
sharedHits
Definition: muonCosmicCompatibility_cfi.py:31
edm::Handle< reco::TrackCollection >
MuonServiceProxy_cff.MuonServiceProxy
MuonServiceProxy
Definition: MuonServiceProxy_cff.py:14
edm::Ref< TrackCollection >
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
DetId
Definition: DetId.h:17
MakerMacros.h
Track.h
reco::Track::recHitsEnd
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
reco::Track
Definition: Track.h:27
Point3DBase< float, GlobalTag >
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
CosmicMuonLinksProducer::mapTracks
reco::TrackToTrackMap mapTracks(const edm::Handle< reco::TrackCollection > &, const edm::Handle< reco::TrackCollection > &) const
Definition: CosmicMuonLinksProducer.cc:103
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
edm::AssociationMap::size
size_type size() const
map size
Definition: AssociationMap.h:162
Event.h
edm::AssociationMap
Definition: AssociationMap.h:48
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
edm::EventSetup
Definition: EventSetup.h:58
std
Definition: JetResolutionObject.h:76
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition: BranchDescription.cc:351
Frameworkfwd.h
MuonServiceProxy.h
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ConsumesCollector.h
DetId::Muon
Definition: DetId.h:26
genParticles_cff.map
map
Definition: genParticles_cff.py:11
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
globals_cff.id2
id2
Definition: globals_cff.py:34
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ProductLabels
Definition: ProductLabels.h:4
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37