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::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CosmicMuonLinksProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~CosmicMuonLinksProducer () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

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::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

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 ( const edm::ParameterSet iConfig)
explicit

Definition at line 35 of file CosmicMuonLinksProducer.cc.

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

35  {
36  category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonLinksProducer";
37 
38  ParameterSet serviceParameters = iConfig.getParameter<ParameterSet>("ServiceParameters");
39 
40  theService = new MuonServiceProxy(serviceParameters);
41 
42  std::vector<edm::ParameterSet> theMapPSets = iConfig.getParameter<std::vector<edm::ParameterSet> >("Maps");
43  for (std::vector<edm::ParameterSet>::const_iterator iMPS = theMapPSets.begin(); iMPS != theMapPSets.end(); iMPS++) {
44  edm::InputTag sTag = (*iMPS).getParameter<edm::InputTag>("subTrack");
45  edm::InputTag pTag = (*iMPS).getParameter<edm::InputTag>("parentTrack");
46 
47  edm::EDGetTokenT<reco::TrackCollection> subTrackTag = consumes<reco::TrackCollection>(sTag);
48  edm::EDGetTokenT<reco::TrackCollection> parentTrackTag = consumes<reco::TrackCollection>(pTag);
49  theTrackLinks.push_back(make_pair(subTrackTag, parentTrackTag));
50  theTrackLinkNames.push_back(make_pair(sTag.label(), pTag.label()));
51 
52  LogDebug(category_) << "preparing map between " << sTag << " & " << pTag;
53  std::string mapname = sTag.label() + "To" + pTag.label();
54  produces<reco::TrackToTrackMap>(mapname);
55  }
56 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::vector< std::pair< std::string, std::string > > theTrackLinkNames
std::vector< std::pair< edm::EDGetTokenT< reco::TrackCollection >, edm::EDGetTokenT< reco::TrackCollection > > > theTrackLinks
std::string const & label() const
Definition: InputTag.h:36
CosmicMuonLinksProducer::~CosmicMuonLinksProducer ( )
override

Definition at line 58 of file CosmicMuonLinksProducer.cc.

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

Member Function Documentation

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

Definition at line 102 of file CosmicMuonLinksProducer.cc.

References edm::AssociationMap< Tag >::insert(), LogTrace, genParticles_cff::map, and muonCosmicCompatibility_cfi::sharedHits.

103  {
104  reco::TrackToTrackMap map(subTracks, parentTracks);
105  for (unsigned int position1 = 0; position1 != subTracks->size(); ++position1) {
106  TrackRef track1(subTracks, position1);
107  for (unsigned int position2 = 0; position2 != parentTracks->size(); ++position2) {
108  TrackRef track2(parentTracks, position2);
109  int shared = sharedHits(*track1, *track2);
110  LogTrace(category_) << "sharedHits " << shared << " track1 " << track1->found() << " track2 " << track2->found()
111  << endl;
112 
113  if (shared > (track1->found()) / 2)
114  map.insert(track1, track2);
115  }
116  }
117 
118  return map;
119 }
int sharedHits(const reco::Track &track1, const reco::Track &track2) const
#define LogTrace(id)
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 64 of file CosmicMuonLinksProducer.cc.

References counter, edm::Event::getByToken(), edm::EventBase::id(), LogDebug, LogTrace, edm::ProductLabels::module, edm::Event::put(), edm::AssociationMap< Tag >::size(), and AlCaHLTBitMon_QueryRunRegistry::string.

64  {
65  LogInfo(category_) << "Processing event number: " << iEvent.id();
66 
67  theService->update(iSetup);
68 
69  unsigned int counter =
70  0;
71  for (std::vector<std::pair<edm::EDGetTokenT<reco::TrackCollection>,
72  edm::EDGetTokenT<reco::TrackCollection> > >::const_iterator iLink = theTrackLinks.begin();
73  iLink != theTrackLinks.end();
74  iLink++) {
75 #ifdef EDM_ML_DEBUG
76  edm::EDConsumerBase::Labels labels_first;
77  edm::EDConsumerBase::Labels labels_second;
78  labelsForToken(iLink->first, labels_first);
79  labelsForToken(iLink->second, labels_second);
80  LogDebug(category_) << "making map between " << labels_first.module << " and " << labels_second.module;
81 #endif
82  std::string mapname = theTrackLinkNames[counter].first + "To" + theTrackLinkNames[counter].second;
84 
86  Handle<reco::TrackCollection> parentTracks;
87 
88  iEvent.getByToken((*iLink).first, subTracks);
89  iEvent.getByToken((*iLink).second, parentTracks);
90 
91  ttmap = mapTracks(subTracks, parentTracks);
92  LogTrace(category_) << "Mapped: " << theTrackLinkNames[counter].first << " " << subTracks->size() << " and "
93  << theTrackLinkNames[counter].second << " " << parentTracks->size()
94  << ", results: " << ttmap.size() << endl;
95 
96  iEvent.put(std::make_unique<reco::TrackToTrackMap>(ttmap), mapname);
97 
98  counter++;
99  }
100 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< std::pair< std::string, std::string > > theTrackLinkNames
std::vector< std::pair< edm::EDGetTokenT< reco::TrackCollection >, edm::EDGetTokenT< reco::TrackCollection > > > theTrackLinks
char const * module
Definition: ProductLabels.h:5
#define LogTrace(id)
size_type size() const
map size
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
edm::EventID id() const
Definition: EventBase.h:59
static std::atomic< unsigned int > counter
reco::TrackToTrackMap mapTracks(const edm::Handle< reco::TrackCollection > &, const edm::Handle< reco::TrackCollection > &) const
int CosmicMuonLinksProducer::sharedHits ( const reco::Track track1,
const reco::Track track2 
) const
private

Definition at line 121 of file CosmicMuonLinksProducer.cc.

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

121  {
122  int match = 0;
123 
124  for (trackingRecHit_iterator hit1 = track1.recHitsBegin(); hit1 != track1.recHitsEnd(); ++hit1) {
125  if (!(*hit1)->isValid())
126  continue;
127  DetId id1 = (*hit1)->geographicalId();
128  if (id1.det() != DetId::Muon)
129  continue; //ONLY MUON
130  LogTrace(category_) << "first ID " << id1.rawId() << " " << (*hit1)->localPosition() << endl;
131  GlobalPoint pos1 = theService->trackingGeometry()->idToDet(id1)->surface().toGlobal((*hit1)->localPosition());
132 
133  for (trackingRecHit_iterator hit2 = track2.recHitsBegin(); hit2 != track2.recHitsEnd(); ++hit2) {
134  if (!(*hit2)->isValid())
135  continue;
136 
137  DetId id2 = (*hit2)->geographicalId();
138  if (id2.det() != DetId::Muon)
139  continue; //ONLY MUON
140 
141  // LogTrace(category_)<<"second ID "<<id2.rawId()<< (*hit2)->localPosition()<<endl;
142 
143  if (id2.rawId() != id1.rawId())
144  continue;
145 
146  GlobalPoint pos2 = theService->trackingGeometry()->idToDet(id2)->surface().toGlobal((*hit2)->localPosition());
147  if ((pos1 - pos2).mag() < 10e-5)
148  match++;
149  }
150  }
151 
152  return match;
153 }
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:88
#define LogTrace(id)
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
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:91

Member Data Documentation

std::string CosmicMuonLinksProducer::category_
private

Definition at line 36 of file CosmicMuonLinksProducer.h.

MuonServiceProxy* CosmicMuonLinksProducer::theService
private

Definition at line 30 of file CosmicMuonLinksProducer.h.

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

Definition at line 34 of file CosmicMuonLinksProducer.h.

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

Definition at line 33 of file CosmicMuonLinksProducer.h.