Go to the documentation of this file.00001 #ifndef MUSCLEFITMUONSELECTOR
00002 #define MUSCLEFITMUONSELECTOR
00003
00004 #include "FWCore/Framework/interface/Frameworkfwd.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00007 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00008 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00009 #include "DataFormats/PatCandidates/interface/Muon.h"
00010 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00011 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00012 #include "FWCore/Utilities/interface/InputTag.h"
00013 #include "MuonAnalysis/MomentumScaleCalibration/interface/GenMuonPair.h"
00014
00015 #include "HepMC/GenParticle.h"
00016 #include "HepMC/GenEvent.h"
00017
00018 #include "MuScleFitPlotter.h"
00019
00020 #include <vector>
00021
00026 typedef reco::Particle::LorentzVector lorentzVector;
00027
00028 class MuScleFitMuonSelector
00029 {
00030 public:
00031 MuScleFitMuonSelector(const edm::InputTag & muonLabel, const int muonType, const bool PATmuons,
00032 const std::vector<int> & resfind,
00033 const bool speedup, const std::string & genParticlesName,
00034 const bool compareToSimTracks, const edm::InputTag & simTracksCollectionName,
00035 const bool sherpa, const bool debug) :
00036 muonLabel_(muonLabel),
00037 muonType_(muonType),
00038 PATmuons_(PATmuons),
00039 resfind_(resfind),
00040 speedup_(speedup),
00041 genParticlesName_(genParticlesName),
00042 compareToSimTracks_(compareToSimTracks),
00043 simTracksCollectionName_(simTracksCollectionName),
00044 sherpa_(sherpa),
00045 debug_(debug)
00046 {}
00047 ~MuScleFitMuonSelector() {}
00048
00049
00050 const reco::Candidate* getStatus1Muon(const reco::Candidate* status3Muon);
00051
00053 void selectMuons(const edm::Event & event, std::vector<reco::LeafCandidate> & muons,
00054 std::vector<GenMuonPair> & genPair,
00055 std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00056 MuScleFitPlotter * plotter);
00057
00058 protected:
00060 bool selGlobalMuon(const pat::Muon* aMuon);
00062 bool selTrackerMuon(const pat::Muon* aMuon);
00063
00064
00065 GenMuonPair findGenMuFromRes( const reco::GenParticleCollection* genParticles);
00066 GenMuonPair findGenMuFromRes( const edm::HepMCProduct* evtMC );
00067 std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
00068 const edm::Handle<edm::SimTrackContainer> & simTracks );
00069 void selectGeneratedMuons(const edm::Handle<pat::CompositeCandidateCollection> & collAll,
00070 const std::vector<const pat::Muon*> & collMuSel,
00071 std::vector<GenMuonPair> & genPair,
00072 MuScleFitPlotter * plotter);
00073 void selectGenSimMuons(const edm::Event & event,
00074 std::vector<GenMuonPair> & genPair,
00075 std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00076 MuScleFitPlotter * plotter);
00077
00078 void selectSimulatedMuons(const edm::Event & event,
00079 const bool ifHepMC, edm::Handle<edm::HepMCProduct> evtMC,
00080 std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00081 MuScleFitPlotter * plotter);
00082
00084 template<typename T>
00085 std::vector<reco::LeafCandidate> fillMuonCollection( const std::vector<T>& tracks )
00086 {
00087 std::vector<reco::LeafCandidate> muons;
00088 typename std::vector<T>::const_iterator track;
00089 for( track = tracks.begin(); track != tracks.end(); ++track ) {
00090 reco::Particle::LorentzVector mu;
00091 mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
00092 sqrt(track->p()*track->p() + mMu2));
00093 reco::LeafCandidate muon(track->charge(),mu);
00094 muons.push_back(muon);
00095 }
00096 return muons;
00097 }
00098
00100 template<typename T>
00101 void takeSelectedMuonType(const T & muon, std::vector<reco::Track> & tracks)
00102 {
00103
00104
00105
00106 if(muon->isGlobalMuon() && muonType_==1)
00107 tracks.push_back(*(muon->globalTrack()));
00108 else if(muon->isStandAloneMuon() && muonType_==2)
00109 tracks.push_back(*(muon->outerTrack()));
00110 else if(muon->isTrackerMuon() && muonType_==3)
00111 tracks.push_back(*(muon->innerTrack()));
00112
00113 else if( muonType_ == 10 && !(muon->isStandAloneMuon()) )
00114 tracks.push_back(*(muon->innerTrack()));
00115 else if( muonType_ == 11 && muon->isGlobalMuon() )
00116 tracks.push_back(*(muon->innerTrack()));
00117 else if( muonType_ == 13 && muon->isTrackerMuon() )
00118 tracks.push_back(*(muon->innerTrack()));
00119 }
00120
00121 const edm::InputTag muonLabel_;
00122 const int muonType_;
00123 const bool PATmuons_;
00124 const std::vector<int> resfind_;
00125 const bool speedup_;
00126 const std::string genParticlesName_;
00127 const bool compareToSimTracks_;
00128 const edm::InputTag simTracksCollectionName_;
00129 const bool sherpa_;
00130 const bool debug_;
00131 static const double mMu2;
00132 static const unsigned int motherPdgIdArray[6];
00133 };
00134
00135 #endif