CMS 3D CMS Logo

MuScleFitMuonSelector.h
Go to the documentation of this file.
1 #ifndef MUSCLEFITMUONSELECTOR
2 #define MUSCLEFITMUONSELECTOR
3 
16 
17 #include "HepMC/GenParticle.h"
18 #include "HepMC/GenEvent.h"
19 
20 #include "MuScleFitPlotter.h"
21 
22 #include <vector>
23 
29 
31 public:
33  const edm::InputTag& muonLabel,
34  const int muonType,
35  const bool PATmuons,
36  const std::vector<int>& resfind,
37  const bool speedup,
38  const std::string& genParticlesName,
39  const bool compareToSimTracks,
40  const edm::InputTag& simTracksCollectionName,
41  const bool sherpa,
42  const bool debug)
44  muonType_(muonType),
48  genParticlesName_(genParticlesName),
49  compareToSimTracks_(compareToSimTracks),
50  simTracksCollectionName_(simTracksCollectionName),
51  sherpa_(sherpa),
52  debug_(debug),
53  onia2MuMuToken_(iC.consumes<pat::CompositeCandidateCollection>(edm::InputTag("onia2MuMuPatTrkTrk"))),
61  ~MuScleFitMuonSelector() = default;
62 
63  //Method to get the muon after FSR (status 1 muon in PYTHIA6) starting from status 3 muon which is daughter of the Z
64  const reco::Candidate* getStatus1Muon(const reco::Candidate* status3Muon);
65 
66  //Method to get the muon before FSR (status 3 muon in PYTHIA6) starting from status 3 muon which is daughter of the Z
67  const reco::Candidate* getStatus3Muon(const reco::Candidate* status3Muon);
68 
70  void selectMuons(const edm::Event& event,
71  std::vector<MuScleFitMuon>& muons,
72  std::vector<GenMuonPair>& genPair,
73  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
75 
76 protected:
78  bool selGlobalMuon(const pat::Muon* aMuon);
80  bool selTrackerMuon(const pat::Muon* aMuon);
81 
82  // Generator and simulation level information
85  std::pair<lorentzVector, lorentzVector> findSimMuFromRes(const edm::Handle<edm::HepMCProduct>& evtMC,
88  const std::vector<const pat::Muon*>& collMuSel,
89  std::vector<GenMuonPair>& genPair,
92  std::vector<GenMuonPair>& genPair,
93  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
95  // void selectGeneratedMuons(const edm::Event & event, std::vector<std::pair<lorentzVector,lorentzVector> > & genPair);
97  const bool ifHepMC,
99  std::vector<std::pair<lorentzVector, lorentzVector> >& simPair,
101 
103  template <typename T>
104  std::vector<MuScleFitMuon> fillMuonCollection(const std::vector<T>& tracks) {
105  std::vector<MuScleFitMuon> muons;
106  typename std::vector<T>::const_iterator track;
107  for (track = tracks.begin(); track != tracks.end(); ++track) {
109  mu = reco::Particle::LorentzVector(track->px(), track->py(), track->pz(), sqrt(track->p() * track->p() + mMu2));
110 
111  Double_t hitsTk(0), hitsMuon(0), ptError(0);
112  if (const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track))) {
113  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
114  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
115  ptError = myMu->innerTrack()->ptError();
116  } else if (const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track))) {
117  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
118  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
119  ptError = myMu->innerTrack()->ptError();
120  } else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))) {
121  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
122  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
123  ptError = myMu->ptError();
124  }
125 
126  MuScleFitMuon muon(mu, track->charge(), ptError, hitsTk, hitsMuon);
127 
128  if (debug_ > 0) {
129  std::cout << "[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization" << std::endl;
130  std::cout << " muon = " << muon << std::endl;
131  }
132 
133  muons.push_back(muon);
134  }
135  return muons;
136  }
137 
139  template <typename T>
140  void takeSelectedMuonType(const T& muon, std::vector<reco::Track>& tracks) {
141  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
142  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
143  // to avoid double counting of the same muon
144  if (muon->isGlobalMuon() && muonType_ == 1)
145  tracks.push_back(*(muon->globalTrack()));
146  else if (muon->isStandAloneMuon() && muonType_ == 2)
147  tracks.push_back(*(muon->outerTrack()));
148  else if (muon->isTrackerMuon() && muonType_ == 3)
149  tracks.push_back(*(muon->innerTrack()));
150 
151  else if (muonType_ == 10 && !(muon->isStandAloneMuon())) //particular case!!
152  tracks.push_back(*(muon->innerTrack()));
153  else if (muonType_ == 11 && muon->isGlobalMuon())
154  tracks.push_back(*(muon->innerTrack()));
155  else if (muonType_ == 13 && muon->isTrackerMuon())
156  tracks.push_back(*(muon->innerTrack()));
157  }
158 
160  const int muonType_;
161  const bool PATmuons_;
162  const std::vector<int> resfind_;
163  const bool speedup_;
167  const bool sherpa_;
168  const bool debug_;
169 
178 
179  static const double mMu2;
180  static const unsigned int motherPdgIdArray[6];
181 };
182 
183 #endif
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
MuScleFitMuonSelector(edm::ConsumesCollector &iC, 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)
std::pair< lorentzVector, lorentzVector > findSimMuFromRes(const edm::Handle< edm::HepMCProduct > &evtMC, const edm::Handle< edm::SimTrackContainer > &simTracks)
const std::string genParticlesName_
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...
std::vector< CompositeCandidate > CompositeCandidateCollection
collection of Candidate objects
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
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.
const edm::EDGetTokenT< edm::HepMCProduct > evtMCToken_
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
const edm::EDGetTokenT< reco::CaloMuonCollection > caloMuonToken_
~MuScleFitMuonSelector()=default
const edm::EDGetTokenT< reco::GenParticleCollection > genParticleToken_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const edm::EDGetTokenT< pat::MuonCollection > patMuonToken_
Definition: HeavyIon.h:7
static const unsigned int motherPdgIdArray[6]
const edm::InputTag muonLabel_
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:19
reco::Particle::LorentzVector lorentzVector
const edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken_
#define debug
Definition: HDRShower.cc:19
auto const & tracks
cannot be loose
GenMuonPair findGenMuFromRes(const reco::GenParticleCollection *genParticles)
void selectGenSimMuons(const edm::Event &event, std::vector< GenMuonPair > &genPair, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
const edm::InputTag simTracksCollectionName_
fixed size matrix
HLT enums.
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
const edm::EDGetTokenT< reco::MuonCollection > recoMuonToken_
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
const reco::Candidate * getStatus3Muon(const reco::Candidate *status3Muon)
const edm::EDGetTokenT< pat::CompositeCandidateCollection > onia2MuMuToken_
long double T
const std::vector< int > resfind_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
std::vector< SimTrack > SimTrackContainer
Analysis-level muon class.
Definition: Muon.h:51
const edm::EDGetTokenT< reco::TrackCollection > trackCollectionToken_
Definition: event.py:1
const reco::Candidate * getStatus1Muon(const reco::Candidate *status3Muon)