CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/MuonAnalysis/MomentumScaleCalibration/interface/MuScleFitMuonSelector.h

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 "MuonAnalysis/MomentumScaleCalibration/interface/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   
00050   void selectMuons(const edm::Event & event, std::vector<reco::LeafCandidate> & muons,
00051                    std::vector<GenMuonPair> & genPair,
00052                    std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00053                    MuScleFitPlotter * plotter);
00054 
00055  protected:
00057   bool selGlobalMuon(const pat::Muon* aMuon);
00059   bool selTrackerMuon(const pat::Muon* aMuon);
00060 
00061   // Generator and simulation level information
00062   GenMuonPair findGenMuFromRes( const reco::GenParticleCollection* genParticles);
00063   GenMuonPair findGenMuFromRes( const edm::HepMCProduct* evtMC );
00064   std::pair<lorentzVector, lorentzVector> findSimMuFromRes( const edm::Handle<edm::HepMCProduct> & evtMC,
00065                                                             const edm::Handle<edm::SimTrackContainer> & simTracks );
00066   void selectGeneratedMuons(const edm::Handle<pat::CompositeCandidateCollection> & collAll,
00067                             const std::vector<const pat::Muon*> & collMuSel,
00068                             std::vector<GenMuonPair> & genPair,
00069                             MuScleFitPlotter * plotter);
00070   void selectGenSimMuons(const edm::Event & event,
00071                          std::vector<GenMuonPair> & genPair,
00072                          std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00073                          MuScleFitPlotter * plotter);
00074   // void selectGeneratedMuons(const edm::Event & event, std::vector<std::pair<lorentzVector,lorentzVector> > & genPair);
00075   void selectSimulatedMuons(const edm::Event & event,
00076                             const bool ifHepMC, edm::Handle<edm::HepMCProduct> evtMC,
00077                             std::vector<std::pair<lorentzVector,lorentzVector> > & simPair,
00078                             MuScleFitPlotter * plotter);
00079 
00081   template<typename T>
00082   std::vector<reco::LeafCandidate> fillMuonCollection( const std::vector<T>& tracks )
00083   {
00084     std::vector<reco::LeafCandidate> muons;
00085     typename std::vector<T>::const_iterator track;
00086     for( track = tracks.begin(); track != tracks.end(); ++track ) {
00087       reco::Particle::LorentzVector mu;
00088       mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
00089                                          sqrt(track->p()*track->p() + mMu2));
00090       reco::LeafCandidate muon(track->charge(),mu);
00091       muons.push_back(muon);
00092     }
00093     return muons;
00094   }
00095 
00097   template<typename T>
00098   void takeSelectedMuonType(const T & muon, std::vector<reco::Track> & tracks)
00099   {
00100     // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
00101     //NNBB: one muon can be of many kinds at once but with the muonType_ we are sure
00102     // to avoid double counting of the same muon
00103     if(muon->isGlobalMuon() && muonType_==1)
00104       tracks.push_back(*(muon->globalTrack()));
00105     else if(muon->isStandAloneMuon() && muonType_==2)
00106       tracks.push_back(*(muon->outerTrack()));
00107     else if(muon->isTrackerMuon() && muonType_==3)
00108       tracks.push_back(*(muon->innerTrack()));
00109 
00110     else if( muonType_ == 10 && !(muon->isStandAloneMuon()) ) //particular case!!
00111       tracks.push_back(*(muon->innerTrack()));
00112     else if( muonType_ == 11 && muon->isGlobalMuon() )
00113       tracks.push_back(*(muon->innerTrack()));
00114     else if( muonType_ == 13 && muon->isTrackerMuon() )
00115       tracks.push_back(*(muon->innerTrack()));
00116   }
00117 
00118   const edm::InputTag muonLabel_;
00119   const int muonType_;
00120   const bool PATmuons_;
00121   const std::vector<int> resfind_;
00122   const bool speedup_;
00123   const std::string genParticlesName_;
00124   const bool compareToSimTracks_;
00125   const edm::InputTag simTracksCollectionName_;
00126   const bool sherpa_;
00127   const bool debug_;
00128   static const double mMu2;
00129   static const unsigned int motherPdgIdArray[6];
00130 };
00131 
00132 #endif