CMS 3D CMS Logo

MuScleFitMuonSelector.h
Go to the documentation of this file.
1 #ifndef MUSCLEFITMUONSELECTOR
2 #define MUSCLEFITMUONSELECTOR
3 
15 
16 #include "HepMC/GenParticle.h"
17 #include "HepMC/GenEvent.h"
18 
19 #include "MuScleFitPlotter.h"
20 
21 #include <vector>
22 
28 
30 public:
32  const int muonType,
33  const bool PATmuons,
34  const std::vector<int>& resfind,
35  const bool speedup,
36  const std::string& genParticlesName,
37  const bool compareToSimTracks,
38  const edm::InputTag& simTracksCollectionName,
39  const bool sherpa,
40  const bool debug)
42  muonType_(muonType),
45  speedup_(speedup),
46  genParticlesName_(genParticlesName),
47  compareToSimTracks_(compareToSimTracks),
48  simTracksCollectionName_(simTracksCollectionName),
49  sherpa_(sherpa),
50  debug_(debug) {}
52 
53  //Method to get the muon after FSR (status 1 muon in PYTHIA6) starting from status 3 muon which is daughter of the Z
54  const reco::Candidate* getStatus1Muon(const reco::Candidate* status3Muon);
55 
56  //Method to get the muon before FSR (status 3 muon in PYTHIA6) starting from status 3 muon which is daughter of the Z
57  const reco::Candidate* getStatus3Muon(const reco::Candidate* status3Muon);
58 
60  void selectMuons(const edm::Event& event,
61  std::vector<MuScleFitMuon>& muons,
62  std::vector<GenMuonPair>& genPair,
63  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
65 
66 protected:
68  bool selGlobalMuon(const pat::Muon* aMuon);
70  bool selTrackerMuon(const pat::Muon* aMuon);
71 
72  // Generator and simulation level information
75  std::pair<lorentzVector, lorentzVector> findSimMuFromRes(const edm::Handle<edm::HepMCProduct>& evtMC,
78  const std::vector<const pat::Muon*>& collMuSel,
79  std::vector<GenMuonPair>& genPair,
82  std::vector<GenMuonPair>& genPair,
83  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
85  // void selectGeneratedMuons(const edm::Event & event, std::vector<std::pair<lorentzVector,lorentzVector> > & genPair);
87  const bool ifHepMC,
89  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
91 
93  template <typename T>
94  std::vector<MuScleFitMuon> fillMuonCollection(const std::vector<T>& tracks) {
95  std::vector<MuScleFitMuon> muons;
96  typename std::vector<T>::const_iterator track;
97  for (track = tracks.begin(); track != tracks.end(); ++track) {
99  mu = reco::Particle::LorentzVector(track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + mMu2));
100 
101  Double_t hitsTk(0), hitsMuon(0), ptError(0);
102  if (const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track))) {
103  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
104  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
105  ptError = myMu->innerTrack()->ptError();
106  } else if (const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track))) {
107  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
108  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
109  ptError = myMu->innerTrack()->ptError();
110  } else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))) {
111  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
112  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
113  ptError = myMu->ptError();
114  }
115 
116  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon);
117 
118  if (debug_ > 0) {
119  std::cout << "[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization" << std::endl;
120  std::cout << " muon = " << muon << std::endl;
121  }
122 
123  muons.push_back(muon);
124  }
125  return muons;
126  }
127 
129  template <typename T>
130  void takeSelectedMuonType(const T& muon, std::vector<reco::Track>& tracks) {
131  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
132  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
133  // to avoid double counting of the same muon
134  if (muon->isGlobalMuon() && muonType_ == 1)
135  tracks.push_back(*(muon->globalTrack()));
136  else if (muon->isStandAloneMuon() && muonType_ == 2)
137  tracks.push_back(*(muon->outerTrack()));
138  else if (muon->isTrackerMuon() && muonType_ == 3)
139  tracks.push_back(*(muon->innerTrack()));
140 
141  else if (muonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
142  tracks.push_back(*(muon->innerTrack()));
143  else if (muonType_ == 11 && muon->isGlobalMuon())
144  tracks.push_back(*(muon->innerTrack()));
145  else if (muonType_ == 13 && muon->isTrackerMuon())
146  tracks.push_back(*(muon->innerTrack()));
147  }
148 
150  const int muonType_;
151  const bool PATmuons_;
152  const std::vector<int> resfind_;
153  const bool speedup_;
157  const bool sherpa_;
158  const bool debug_;
159  static const double mMu2;
160  static const unsigned int motherPdgIdArray[6];
161 };
162 
163 #endif
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
CompositeCandidate.h
genParticles2HepMC_cfi.genParticles
genParticles
Definition: genParticles2HepMC_cfi.py:4
MuScleFitMuonSelector::compareToSimTracks_
const bool compareToSimTracks_
Definition: MuScleFitMuonSelector.h:155
muon
Definition: MuonCocktails.h:17
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
MuScleFitMuonSelector::motherPdgIdArray
static const unsigned int motherPdgIdArray[6]
Definition: MuScleFitMuonSelector.h:160
GenMuonPair
Definition: GenMuonPair.h:19
Muon.h
MuScleFitMuonSelector::findSimMuFromRes
std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
Definition: MuScleFitMuonSelector.cc:456
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MuScleFitMuonSelector::sherpa_
const bool sherpa_
Definition: MuScleFitMuonSelector.h:157
MuScleFitMuonSelector::getStatus3Muon
const reco::Candidate * getStatus3Muon(const reco::Candidate *status3Muon)
Definition: MuScleFitMuonSelector.cc:32
reco::GenParticleCollection
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
Definition: GenParticleFwd.h:13
commonCuts_cff.muonLabel
muonLabel
Definition: commonCuts_cff.py:13
MuScleFit_cfi.PATmuons
PATmuons
Definition: MuScleFit_cfi.py:43
MuScleFitMuonSelector::muonType_
const int muonType_
Definition: MuScleFitMuonSelector.h:150
MuScleFitMuonSelector::findGenMuFromRes
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
Definition: MuScleFitMuonSelector.cc:397
TrackCandidateProducer_cfi.simTracks
simTracks
Definition: TrackCandidateProducer_cfi.py:15
MuScleFitMuon
Definition: Muon.h:14
MuScleFitMuonSelector::selTrackerMuon
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
Definition: MuScleFitMuonSelector.cc:70
MuScleFitMuonSelector::debug_
const bool debug_
Definition: MuScleFitMuonSelector.h:158
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
MuScleFitMuonSelector::muonLabel_
const edm::InputTag muonLabel_
Definition: MuScleFitMuonSelector.h:149
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
edm::Handle< edm::HepMCProduct >
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
MuScleFitMuonSelector::selGlobalMuon
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
Definition: MuScleFitMuonSelector.cc:54
MuScleFitMuonSelector::~MuScleFitMuonSelector
~MuScleFitMuonSelector()
Definition: MuScleFitMuonSelector.h:51
reco::Muon
Definition: Muon.h:27
MuScleFitMuonSelector::PATmuons_
const bool PATmuons_
Definition: MuScleFitMuonSelector.h:151
debug
#define debug
Definition: HDRShower.cc:19
MuScleFitMuonSelector::resfind_
const std::vector< int > resfind_
Definition: MuScleFitMuonSelector.h:152
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MuScleFitGenFilter_cfi.resfind
resfind
Definition: MuScleFitGenFilter_cfi.py:11
MuScleFitPlotter.h
reco::Track
Definition: Track.h:27
LeafCandidate.h
MuScleFitMuonSelector::genParticlesName_
const std::string genParticlesName_
Definition: MuScleFitMuonSelector.h:154
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MuScleFitMuonSelector::selectSimulatedMuons
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
Definition: MuScleFitMuonSelector.cc:332
MuScleFitMuonSelector::selectGenSimMuons
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
Definition: MuScleFitMuonSelector.cc:293
Event.h
trackingPlots.plotter
plotter
Definition: trackingPlots.py:1313
MuScleFitMuonSelector::simTracksCollectionName_
const edm::InputTag simTracksCollectionName_
Definition: MuScleFitMuonSelector.h:156
MuScleFitMuonSelector
Definition: MuScleFitMuonSelector.h:29
InputTag.h
reco::Candidate
Definition: Candidate.h:27
MuScleFitMuonSelector::getStatus1Muon
const reco::Candidate * getStatus1Muon(const reco::Candidate *status3Muon)
Definition: MuScleFitMuonSelector.cc:9
MuScleFitMuonSelector::takeSelectedMuonType
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
Definition: MuScleFitMuonSelector.h:130
MuScleFitMuonSelector::selectGeneratedMuons
void selectGeneratedMuons(const edm::Handle< pat::CompositeCandidateCollection > &collAll, const std::vector< const pat::Muon * > &collMuSel, std::vector< GenMuonPair > &genPair, MuScleFitPlotter *plotter)
For PATmuons the generator information is read directly from the PAT object.
Definition: MuScleFitMuonSelector.cc:237
MuScleFitMuonSelector::mMu2
static const double mMu2
Definition: MuScleFitMuonSelector.h:159
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
MuScleFitMuonSelector::fillMuonCollection
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
Definition: MuScleFitMuonSelector.h:94
GenMuonPair.h
lorentzVector
reco::Particle::LorentzVector lorentzVector
Definition: MuScleFitMuonSelector.h:27
MuScleFitPlotter
Definition: MuScleFitPlotter.h:27
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
edm::HepMCProduct
Definition: HepMCProduct.h:18
HepMCProduct.h
MuScleFitMuonSelector::speedup_
const bool speedup_
Definition: MuScleFitMuonSelector.h:153
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
MuScleFitMuonSelector::MuScleFitMuonSelector
MuScleFitMuonSelector(const edm::InputTag &muonLabel, const int muonType, const bool PATmuons, const std::vector< int > &resfind, const bool speedup, const std::string &genParticlesName, const bool compareToSimTracks, const edm::InputTag &simTracksCollectionName, const bool sherpa, const bool debug)
Definition: MuScleFitMuonSelector.h:31
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
MuScleFitMuonSelector::selectMuons
void selectMuons(const edm::Event &event, std::vector< MuScleFitMuon > &muons, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
Main method used to select muons of type specified by muonType_ from the collection specified by muon...
Definition: MuScleFitMuonSelector.cc:85
Muon.h