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");
18  trackAssociatorParameters_.loadParameters(cfgTrackAssociator, iC);
20 
21  // maps of detId to number of hits attributed to muon
22  produces<detIdToIntMap>("hitsMuPlus");
23  produces<detIdToIntMap>("hitsMuMinus");
24 
25  verbosity_ = ( cfg.exists("verbosity") ) ?
26  cfg.getParameter<int>("verbosity") : 0;
27 }
28 
30 {
31 // nothing to be done yet...
32 }
33 
35 {
36  std::auto_ptr<detIdToIntMap> hitsMuPlus(new detIdToIntMap());
37  std::auto_ptr<detIdToIntMap> hitsMuMinus(new detIdToIntMap());
38 
39  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
40  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
41  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
42 
43  if ( muPlus.isNonnull() ) fillHitMap(evt, es, &(*muPlus), *hitsMuPlus);
44  if ( muMinus.isNonnull() ) fillHitMap(evt, es, &(*muMinus), *hitsMuMinus);
45 
46  evt.put(hitsMuPlus, "hitsMuPlus");
47  evt.put(hitsMuMinus, "hitsMuMinus");
48 }
49 
50 namespace
51 {
52  void fillHitMapRH(const TrackingRecHit& rh, std::map<uint32_t, int>& hitMap, int& numHits)
53  {
54  std::vector<const TrackingRecHit*> rh_components = rh.recHits();
55  if ( rh_components.size() == 0 ) {
56  ++hitMap[rh.rawId()];
57  ++numHits;
58  } else {
59  for ( std::vector<const TrackingRecHit*>::const_iterator rh_component = rh_components.begin();
60  rh_component != rh_components.end(); ++rh_component ) {
61  fillHitMapRH(**rh_component, hitMap, numHits);
62  }
63  }
64  }
65 
66  void printHitMapRH(const edm::EventSetup& es, const std::map<uint32_t, int>& hitMap)
67  {
68  std::cout << "detIds:";
69  for ( std::map<uint32_t, int>::const_iterator rh = hitMap.begin();
70  rh != hitMap.end(); ++rh ) {
71  printMuonDetId(es, rh->first);
72  }
73  }
74 }
75 
77 {
78  int numHits = 0;
79 
80  const reco::Muon* recoMuon = dynamic_cast<const reco::Muon*>(muon);
81  if ( recoMuon && recoMuon->outerTrack().isNonnull() ) {
82  const reco::TrackRef muonOuterTrack = recoMuon->outerTrack();
84  for ( std::vector<TAMuonChamberMatch>::const_iterator rh = trackDetMatchInfo.chambers.begin();
85  rh != trackDetMatchInfo.chambers.end(); ++rh ) {
86  ++hitMap[rh->id.rawId()];
87  ++numHits;
88  }
89  for ( trackingRecHit_iterator rh = muonOuterTrack->recHitsBegin();
90  rh != muonOuterTrack->recHitsEnd(); ++rh ) {
91  fillHitMapRH(**rh, hitMap, numHits);
92  }
93  } else {
94  GlobalVector muonP3(muon->px(), muon->py(), muon->pz());
95  GlobalPoint muonVtx(muon->vertex().x(), muon->vertex().y(), muon->vertex().z());
96  TrackDetMatchInfo trackDetMatchInfo = trackAssociator_.associate(evt, es, muonP3, muonVtx, muon->charge(), trackAssociatorParameters_);
97  for ( std::vector<TAMuonChamberMatch>::const_iterator rh = trackDetMatchInfo.chambers.begin();
98  rh != trackDetMatchInfo.chambers.end(); ++rh ) {
99  ++hitMap[rh->id.rawId()];
100  ++numHits;
101  }
102  }
103 
104  if ( verbosity_ ) {
105  std::string muonCharge_string = "";
106  if ( muon->charge() > +0.5 ) muonCharge_string = "+";
107  else if ( muon->charge() < -0.5 ) muonCharge_string = "-";
108  std::cout << "Mu" << muonCharge_string << ": Pt = " << muon->pt() << ", eta = " << muon->eta() << ", phi = " << muon->phi()
109  << " --> #Hits = " << numHits << std::endl;
110  if ( verbosity_ >= 2 ) printHitMapRH(es, hitMap);
111  }
112 }
113 
115 
T getParameter(std::string const &) const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
tuple cfg
Definition: looper.py:293
void fillHitMap(edm::Event &, const edm::EventSetup &, const reco::Candidate *, detIdToIntMap &)
virtual double pt() const =0
transverse momentum
TrackAssociatorParameters trackAssociatorParameters_
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
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
std::map< uint32_t, int > detIdToIntMap
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:337
MuonDetCleaner(const edm::ParameterSet &)
TrackDetectorAssociator trackAssociator_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
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:145
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
id_type rawId() const
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity