CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

CosmicMuonLinksProducer Class Reference

#include <CosmicMuonLinksProducer.h>

Inheritance diagram for CosmicMuonLinksProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 CosmicMuonLinksProducer (const edm::ParameterSet &)
virtual void produce (edm::Event &, const edm::EventSetup &)
 ~CosmicMuonLinksProducer ()

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
< edm::InputTag, edm::InputTag > > 
theTrackLinks

Detailed Description

Date:
2009/01/05 21:58:19
Revision:
1.2

Original Author: Chang Liu - Purdue University <chang.liu@cern.ch>

Definition at line 18 of file CosmicMuonLinksProducer.h.


Constructor & Destructor Documentation

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

Definition at line 37 of file CosmicMuonLinksProducer.cc.

References edm::ParameterSet::getParameter(), LogDebug, and MuonServiceProxy_cff::MuonServiceProxy.

{

  category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonLinksProducer";

  ParameterSet serviceParameters = iConfig.getParameter<ParameterSet>("ServiceParameters");

  theService = new MuonServiceProxy(serviceParameters);

  std::vector<edm::ParameterSet> theMapPSets = iConfig.getParameter<std::vector<edm::ParameterSet> >("Maps");
  for (std::vector<edm::ParameterSet>::const_iterator iMPS = theMapPSets.begin();
       iMPS != theMapPSets.end(); iMPS++) {
     edm::InputTag subTrackTag = (*iMPS).getParameter<edm::InputTag>("subTrack");
     edm::InputTag parentTrackTag = (*iMPS).getParameter<edm::InputTag>("parentTrack");
     theTrackLinks.push_back( make_pair(subTrackTag, parentTrackTag) );
  }

  for(std::vector<std::pair<edm::InputTag, edm::InputTag> >::const_iterator iLink = theTrackLinks.begin();
     iLink != theTrackLinks.end(); iLink++) {
    LogDebug(category_) << "preparing map between " << (*iLink).first<<" & "<< (*iLink).second;
    std::string mapname = (*iLink).first.label() + "To" + (*iLink).second.label();
    produces<reco::TrackToTrackMap>(mapname);
  }

}
CosmicMuonLinksProducer::~CosmicMuonLinksProducer ( )

Definition at line 63 of file CosmicMuonLinksProducer.cc.

{
  if (theService) delete theService;
}

Member Function Documentation

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

Definition at line 100 of file CosmicMuonLinksProducer.cc.

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

                                                                                                                                                          {
  reco::TrackToTrackMap map;
  for ( unsigned int position1 = 0; position1 != subTracks->size(); ++position1) {
    TrackRef track1(subTracks, position1);
    for ( unsigned int position2 = 0; position2 != parentTracks->size(); ++position2) {
      TrackRef track2(parentTracks, position2);
      int shared = sharedHits(*track1, *track2); 
      LogTrace(category_)<<"sharedHits "<<shared<<" track1 "<<track1->found()<<" track2 "<<track2->found()<<endl;
 
      if (shared > (track1->found())/2 ) map.insert(track1, track2);
    }
  }

  return map; 
}
void CosmicMuonLinksProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 71 of file CosmicMuonLinksProducer.cc.

References edm::Event::getByLabel(), edm::EventBase::id(), LogDebug, LogTrace, edm::Event::put(), and edm::AssociationMap< Tag >::size().

{
  LogInfo(category_) << "Processing event number: " << iEvent.id();

  theService->update(iSetup);

  for(std::vector<std::pair<edm::InputTag, edm::InputTag> >::const_iterator iLink = theTrackLinks.begin();
     iLink != theTrackLinks.end(); iLink++){
    LogDebug(category_) << "making map between " << (*iLink).first<<" and "<< (*iLink).second;
    std::string mapname = (*iLink).first.label() + "To" + (*iLink).second.label();
    reco::TrackToTrackMap ttmap;

    Handle<reco::TrackCollection> subTracks;
    Handle<reco::TrackCollection> parentTracks;

    if ( iEvent.getByLabel( (*iLink).first, subTracks) && iEvent.getByLabel( (*iLink).second, parentTracks) ) {

         ttmap = mapTracks(subTracks, parentTracks); 
         LogTrace(category_) << "Mapped: "<<
(*iLink).first.label()<<" "<<subTracks->size()<< " and "<<(*iLink).second.label()<<" "<<parentTracks->size()<<", results: "<< ttmap.size() <<endl;

    }

    auto_ptr<reco::TrackToTrackMap> trackToTrackmap(new reco::TrackToTrackMap(ttmap));
    iEvent.put(trackToTrackmap, mapname);
  }

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

Definition at line 116 of file CosmicMuonLinksProducer.cc.

References DetId::det(), alignCSCRings::e, LogTrace, edm::match(), DetId::Muon, DetId::rawId(), reco::Track::recHitsBegin(), and reco::Track::recHitsEnd().

                                                                                              {

  int match = 0;

  for (trackingRecHit_iterator hit1 = track1.recHitsBegin(); hit1 != track1.recHitsEnd(); ++hit1) {
    if ( !(*hit1)->isValid() ) continue;
    DetId id1 = (*hit1)->geographicalId();
    if ( id1.det() != DetId::Muon ) continue; //ONLY MUON
    LogTrace(category_)<<"first ID "<<id1.rawId()<<" "<<(*hit1)->localPosition()<<endl;
    GlobalPoint pos1 = theService->trackingGeometry()->idToDet(id1)->surface().toGlobal((*hit1)->localPosition());

    for (trackingRecHit_iterator hit2 = track2.recHitsBegin(); hit2 != track2.recHitsEnd(); ++hit2) {

          if ( !(*hit2)->isValid() ) continue;

          DetId id2 = (*hit2)->geographicalId();
          if ( id2.det() != DetId::Muon ) continue; //ONLY MUON

//          LogTrace(category_)<<"second ID "<<id2.rawId()<< (*hit2)->localPosition()<<endl;

          if (id2.rawId() != id1.rawId() ) continue;

          GlobalPoint pos2 = theService->trackingGeometry()->idToDet(id2)->surface().toGlobal((*hit2)->localPosition());
          if ( ( pos1 - pos2 ).mag()< 10e-5 ) match++;

        }

    }

   return match;

}

Member Data Documentation

std::string CosmicMuonLinksProducer::category_ [private]

Definition at line 36 of file CosmicMuonLinksProducer.h.

Definition at line 32 of file CosmicMuonLinksProducer.h.

Definition at line 34 of file CosmicMuonLinksProducer.h.