CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CosmicMuonLinksProducer Class Reference

#include <CosmicMuonLinksProducer.h>

Inheritance diagram for CosmicMuonLinksProducer:
edm::stream::EDProducer<>

Public Member Functions

 CosmicMuonLinksProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~CosmicMuonLinksProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

reco::TrackToTrackMap mapTracks (const edm::Handle< reco::TrackCollection > &, const edm::Handle< reco::TrackCollection > &) const
 
int sharedHits (const reco::Track &track1, const reco::Track &track2) const
 

Private Attributes

std::string category_
 
MuonServiceProxytheService
 
std::vector< std::pair< std::string, std::string > > theTrackLinkNames
 
std::vector< std::pair< edm::EDGetTokenT< reco::TrackCollection >, edm::EDGetTokenT< reco::TrackCollection > > > theTrackLinks
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Original Author: Chang Liu - Purdue University chang.nosp@m..liu.nosp@m.@cern.nosp@m..ch

Definition at line 16 of file CosmicMuonLinksProducer.h.

Constructor & Destructor Documentation

◆ CosmicMuonLinksProducer()

CosmicMuonLinksProducer::CosmicMuonLinksProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 36 of file CosmicMuonLinksProducer.cc.

References edm::ParameterSet::getParameter(), edm::InputTag::label(), LogDebug, MuonServiceProxy_cff::MuonServiceProxy, and AlCaHLTBitMon_QueryRunRegistry::string.

36  {
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 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::pair< std::string, std::string > > theTrackLinkNames
std::string const & label() const
Definition: InputTag.h:36
std::vector< std::pair< edm::EDGetTokenT< reco::TrackCollection >, edm::EDGetTokenT< reco::TrackCollection > > > theTrackLinks
#define LogDebug(id)

◆ ~CosmicMuonLinksProducer()

CosmicMuonLinksProducer::~CosmicMuonLinksProducer ( )
override

Definition at line 59 of file CosmicMuonLinksProducer.cc.

59  {
60  if (theService)
61  delete theService;
62 }

Member Function Documentation

◆ mapTracks()

reco::TrackToTrackMap CosmicMuonLinksProducer::mapTracks ( const edm::Handle< reco::TrackCollection > &  subTracks,
const edm::Handle< reco::TrackCollection > &  parentTracks 
) const
private

Definition at line 103 of file CosmicMuonLinksProducer.cc.

References LogTrace, genParticles_cff::map, and muonCosmicCompatibility_cfi::sharedHits.

104  {
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 }
#define LogTrace(id)
int sharedHits(const reco::Track &track1, const reco::Track &track2) const

◆ produce()

void CosmicMuonLinksProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

DAMN I cannot read the label of the TOKEN so I need to do this stupid thing to create the labels of the products!

Definition at line 65 of file CosmicMuonLinksProducer.cc.

References counter, iEvent, LogDebug, LogTrace, edm::ProductLabels::module, edm::AssociationMap< Tag >::size(), AlCaHLTBitMon_QueryRunRegistry::string, and trackerHitRTTI::vector.

65  {
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 }
std::vector< std::pair< std::string, std::string > > theTrackLinkNames
#define LogTrace(id)
size_type size() const
map size
std::vector< std::pair< edm::EDGetTokenT< reco::TrackCollection >, edm::EDGetTokenT< reco::TrackCollection > > > theTrackLinks
int iEvent
Definition: GenABIO.cc:224
reco::TrackToTrackMap mapTracks(const edm::Handle< reco::TrackCollection > &, const edm::Handle< reco::TrackCollection > &) const
char const * module
Definition: ProductLabels.h:5
Log< level::Info, false > LogInfo
static std::atomic< unsigned int > counter
#define LogDebug(id)

◆ sharedHits()

int CosmicMuonLinksProducer::sharedHits ( const reco::Track track1,
const reco::Track track2 
) const
private

Definition at line 122 of file CosmicMuonLinksProducer.cc.

References MillePedeFileConverter_cfg::e, globals_cff::id1, globals_cff::id2, LogTrace, edm::match(), DetId::Muon, reco::Track::recHitsBegin(), and reco::Track::recHitsEnd().

122  {
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 }
#define LogTrace(id)
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
Definition: DetId.h:17
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10

Member Data Documentation

◆ category_

std::string CosmicMuonLinksProducer::category_
private

Definition at line 36 of file CosmicMuonLinksProducer.h.

◆ theService

MuonServiceProxy* CosmicMuonLinksProducer::theService
private

Definition at line 30 of file CosmicMuonLinksProducer.h.

◆ theTrackLinkNames

std::vector<std::pair<std::string, std::string> > CosmicMuonLinksProducer::theTrackLinkNames
private

Definition at line 34 of file CosmicMuonLinksProducer.h.

◆ theTrackLinks

std::vector<std::pair<edm::EDGetTokenT<reco::TrackCollection>, edm::EDGetTokenT<reco::TrackCollection> > > CosmicMuonLinksProducer::theTrackLinks
private

Definition at line 33 of file CosmicMuonLinksProducer.h.