CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
31  public:
32  MuScleFitMuonSelector(const edm::InputTag & muonLabel, const int muonType, const bool PATmuons,
33  const std::vector<int> & resfind,
34  const bool speedup, const std::string & genParticlesName,
35  const bool compareToSimTracks, const edm::InputTag & simTracksCollectionName,
36  const bool sherpa, const bool debug) :
37  muonLabel_(muonLabel),
38  muonType_(muonType),
39  PATmuons_(PATmuons),
40  resfind_(resfind),
41  speedup_(speedup),
42  genParticlesName_(genParticlesName),
43  compareToSimTracks_(compareToSimTracks),
44  simTracksCollectionName_(simTracksCollectionName),
45  sherpa_(sherpa),
46  debug_(debug)
47  {}
49 
50  //Method to get the muon after FSR (status 1 muon) starting from status 3 muon which is daughter of the Z
51  const reco::Candidate* getStatus1Muon(const reco::Candidate* status3Muon);
52 
54  void selectMuons(const edm::Event & event, std::vector<MuScleFitMuon> & muons,
55  std::vector<GenMuonPair> & genPair,
56  std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
58 
59 
60  protected:
62  bool selGlobalMuon(const pat::Muon* aMuon);
64  bool selTrackerMuon(const pat::Muon* aMuon);
65 
66  // Generator and simulation level information
69  std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
70  const edm::Handle<edm::SimTrackContainer> & simTracks );
72  const std::vector<const pat::Muon*> & collMuSel,
73  std::vector<GenMuonPair> & genPair,
75  void selectGenSimMuons(const edm::Event & event,
76  std::vector<GenMuonPair> & genPair,
77  std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
79  // void selectGeneratedMuons(const edm::Event & event, std::vector<std::pair<lorentzVector,lorentzVector> > & genPair);
81  const bool ifHepMC, edm::Handle<edm::HepMCProduct> evtMC,
82  std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
84 
86  template<typename T>
87  std::vector<MuScleFitMuon> fillMuonCollection( const std::vector<T>& tracks )
88  {
89  std::vector<MuScleFitMuon> muons;
90  typename std::vector<T>::const_iterator track;
91  for( track = tracks.begin(); track != tracks.end(); ++track ) {
93  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
94  sqrt(track->p()*track->p() + mMu2));
95 
96  Double_t hitsTk(0), hitsMuon(0), ptError(0);
97  if ( const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track)) ){
98  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
99  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
100  ptError = myMu->innerTrack()->ptError();
101  }
102  else if ( const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track)) ) {
103  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
104  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
105  ptError = myMu->innerTrack()->ptError();
106  }
107  else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))){
108  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
109  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
110  ptError = myMu->ptError();
111  }
112 
113  MuScleFitMuon muon(mu,track->charge(),ptError,hitsTk,hitsMuon);
114 
115  if (debug_>0) {
116  std::cout<<"[MuScleFitMuonSelector::fillMuonCollection] after MuScleFitMuon initialization"<<std::endl;
117  std::cout<<" muon = "<<muon<<std::endl;
118  }
119 
120  muons.push_back(muon);
121  }
122  return muons;
123  }
124 
126  template<typename T>
127  void takeSelectedMuonType(const T & muon, std::vector<reco::Track> & tracks)
128  {
129  // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
130  //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
131  // to avoid double counting of the same muon
132  if(muon->isGlobalMuon() && muonType_==1)
133  tracks.push_back(*(muon->globalTrack()));
134  else if(muon->isStandAloneMuon() && muonType_==2)
135  tracks.push_back(*(muon->outerTrack()));
136  else if(muon->isTrackerMuon() && muonType_==3)
137  tracks.push_back(*(muon->innerTrack()));
138 
139  else if( muonType_ == 10 && !(muon->isStandAloneMuon()) ) //particular case!!
140  tracks.push_back(*(muon->innerTrack()));
141  else if( muonType_ == 11 && muon->isGlobalMuon() )
142  tracks.push_back(*(muon->innerTrack()));
143  else if( muonType_ == 13 && muon->isTrackerMuon() )
144  tracks.push_back(*(muon->innerTrack()));
145  }
146 
148  const int muonType_;
149  const bool PATmuons_;
150  const std::vector<int> resfind_;
151  const bool speedup_;
155  const bool sherpa_;
156  const bool debug_;
157  static const double mMu2;
158  static const unsigned int motherPdgIdArray[6];
159 };
160 
161 #endif
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
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.
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< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
Template function used to convert the muon collection to a vector of reco::LeafCandidate.
bool selTrackerMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select trackerMuons.
void selectSimulatedMuons(const edm::Event &event, const bool ifHepMC, edm::Handle< edm::HepMCProduct > evtMC, std::vector< std::pair< lorentzVector, lorentzVector > > &simPair, MuScleFitPlotter *plotter)
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)
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:9
static const unsigned int motherPdgIdArray[6]
const edm::InputTag muonLabel_
static const double mMu2
T sqrt(T t)
Definition: SSEVec.h:48
const int mu
Definition: Constants.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
#define debug
Definition: HDRShower.cc:19
tuple tracks
Definition: testEve_cfg.py:39
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_
tuple muons
Definition: patZpeak.py:38
bool selGlobalMuon(const pat::Muon *aMuon)
Apply the Onia cuts to select globalMuons.
tuple cout
Definition: gather_cfg.py:121
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template function used to extract the selected muon type from the muon collection.
long double T
const std::vector< int > resfind_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Analysis-level muon class.
Definition: Muon.h:49
const reco::Candidate * getStatus1Muon(const reco::Candidate *status3Muon)