CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonDetCleaner.cc
Go to the documentation of this file.
2 
4 
7 
9 
10 #include <string>
11 #include <vector>
12 
14  : srcSelectedMuons_(cfg.getParameter<edm::InputTag>("selectedMuons"))
15 {
16  edm::ParameterSet cfgTrackAssociator = cfg.getParameter<edm::ParameterSet>("trackAssociator");
17  trackAssociatorParameters_.loadParameters(cfgTrackAssociator);
19 
20  // maps of detId to number of hits attributed to muon
21  produces<detIdToIntMap>("hitsMuPlus");
22  produces<detIdToIntMap>("hitsMuMinus");
23 
24  verbosity_ = ( cfg.exists("verbosity") ) ?
25  cfg.getParameter<int>("verbosity") : 0;
26 }
27 
29 {
30 // nothing to be done yet...
31 }
32 
34 {
35  std::auto_ptr<detIdToIntMap> hitsMuPlus(new detIdToIntMap());
36  std::auto_ptr<detIdToIntMap> hitsMuMinus(new detIdToIntMap());
37 
38  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
39  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
40  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
41 
42  if ( muPlus.isNonnull() ) fillHitMap(evt, es, &(*muPlus), *hitsMuPlus);
43  if ( muMinus.isNonnull() ) fillHitMap(evt, es, &(*muMinus), *hitsMuMinus);
44 
45  evt.put(hitsMuPlus, "hitsMuPlus");
46  evt.put(hitsMuMinus, "hitsMuMinus");
47 }
48 
49 namespace
50 {
51  void fillHitMapRH(const TrackingRecHit& rh, std::map<uint32_t, int>& hitMap, int& numHits)
52  {
53  std::vector<const TrackingRecHit*> rh_components = rh.recHits();
54  if ( rh_components.size() == 0 ) {
55  ++hitMap[rh.rawId()];
56  ++numHits;
57  } else {
58  for ( std::vector<const TrackingRecHit*>::const_iterator rh_component = rh_components.begin();
59  rh_component != rh_components.end(); ++rh_component ) {
60  fillHitMapRH(**rh_component, hitMap, numHits);
61  }
62  }
63  }
64 
65  void printHitMapRH(const edm::EventSetup& es, const std::map<uint32_t, int>& hitMap)
66  {
67  std::cout << "detIds:";
68  for ( std::map<uint32_t, int>::const_iterator rh = hitMap.begin();
69  rh != hitMap.end(); ++rh ) {
70  printMuonDetId(es, rh->first);
71  }
72  }
73 }
74 
76 {
77  int numHits = 0;
78 
79  const reco::Muon* recoMuon = dynamic_cast<const reco::Muon*>(muon);
80  if ( recoMuon && recoMuon->outerTrack().isNonnull() ) {
81  const reco::TrackRef muonOuterTrack = recoMuon->outerTrack();
83  for ( std::vector<TAMuonChamberMatch>::const_iterator rh = trackDetMatchInfo.chambers.begin();
84  rh != trackDetMatchInfo.chambers.end(); ++rh ) {
85  ++hitMap[rh->id.rawId()];
86  ++numHits;
87  }
88  for ( trackingRecHit_iterator rh = muonOuterTrack->recHitsBegin();
89  rh != muonOuterTrack->recHitsEnd(); ++rh ) {
90  fillHitMapRH(**rh, hitMap, numHits);
91  }
92  } else {
93  GlobalVector muonP3(muon->px(), muon->py(), muon->pz());
94  GlobalPoint muonVtx(muon->vertex().x(), muon->vertex().y(), muon->vertex().z());
95  TrackDetMatchInfo trackDetMatchInfo = trackAssociator_.associate(evt, es, muonP3, muonVtx, muon->charge(), trackAssociatorParameters_);
96  for ( std::vector<TAMuonChamberMatch>::const_iterator rh = trackDetMatchInfo.chambers.begin();
97  rh != trackDetMatchInfo.chambers.end(); ++rh ) {
98  ++hitMap[rh->id.rawId()];
99  ++numHits;
100  }
101  }
102 
103  if ( verbosity_ ) {
104  std::string muonCharge_string = "";
105  if ( muon->charge() > +0.5 ) muonCharge_string = "+";
106  else if ( muon->charge() < -0.5 ) muonCharge_string = "-";
107  std::cout << "Mu" << muonCharge_string << ": Pt = " << muon->pt() << ", eta = " << muon->eta() << ", phi = " << muon->phi()
108  << " --> #Hits = " << numHits << std::endl;
109  if ( verbosity_ >= 2 ) printHitMapRH(es, hitMap);
110  }
111 }
112 
114 
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
void fillHitMap(edm::Event &, const edm::EventSetup &, const reco::Candidate *, detIdToIntMap &)
TrackAssociatorParameters trackAssociatorParameters_
virtual float eta() const =0
momentum pseudorapidity
edm::InputTag srcSelectedMuons_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual double pz() const =0
z coordinate of momentum vector
void useDefaultPropagator()
use the default propagator
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::map< uint32_t, int > detIdToIntMap
virtual float phi() const =0
momentum azimuthal angle
MuonDetCleaner(const edm::ParameterSet &)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual float pt() const =0
transverse momentum
TrackDetectorAssociator trackAssociator_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
std::vector< TAMuonChamberMatch > chambers
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
virtual const Point & vertex() const =0
vertex position
virtual int charge() const =0
electric charge
virtual double py() const =0
y coordinate of momentum vector
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
virtual double px() const =0
x coordinate of momentum vector
void printMuonDetId(const edm::EventSetup &, uint32_t)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
tuple cout
Definition: gather_cfg.py:121
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
id_type rawId() const
void loadParameters(const edm::ParameterSet &)