00001 00014 #include <iostream> 00015 #include <string> 00016 #include <list> 00017 #include <cmath> 00018 #include <cstdio> 00019 #include <vector> 00020 #include <memory> 00021 00022 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00023 #include "DataFormats/Common/interface/Handle.h" 00024 00025 #include "SUSYBSMAnalysis/CSA07Skims/interface/HadSUSYdiMuonSkim.h" 00026 #include "DataFormats/MuonReco/interface/Muon.h" 00027 #include "DataFormats/MuonReco/interface/MuonFwd.h" 00028 00029 using namespace edm; 00030 using namespace std; 00031 using namespace reco; 00032 00033 class PtSorter { 00034 public: 00035 template <class T> bool operator() ( const T& a, const T& b ) { 00036 return ( a.pt() > b.pt() ); 00037 } 00038 }; 00039 00040 HadSUSYdiMuonSkim::HadSUSYdiMuonSkim( const edm::ParameterSet& iConfig ) : 00041 nEvents_(0), nAccepted_(0) 00042 { 00043 Muonsrc_ = iConfig.getParameter<InputTag>( "Muonsrc" ); 00044 NminMuon_ = iConfig.getParameter<int>( "NminMuon"); 00045 MuonPtmin_ = iConfig.getParameter<double>( "MuonPtmin"); 00046 PtmindiMuon_ = iConfig.getParameter<double>( "PtmindiMuon"); 00047 } 00048 00049 /*------------------------------------------------------------------------*/ 00050 00051 HadSUSYdiMuonSkim::~HadSUSYdiMuonSkim() 00052 {} 00053 00054 /*------------------------------------------------------------------------*/ 00055 00056 bool HadSUSYdiMuonSkim::filter( edm::Event& iEvent, 00057 const edm::EventSetup& iSetup ) 00058 { 00059 nEvents_++; 00060 00061 Handle<MuonCollection> MuonHandle; 00062 // try { 00063 iEvent.getByLabel( Muonsrc_, MuonHandle ); 00064 // } 00065 // catch ( cms::Exception& ex ) { 00066 // edm::LogError( "HadSUSYdiMuonSkim" ) 00067 // << "Unable to get Muon collection " 00068 // << Muonsrc_.label(); 00069 // return false; 00070 // } 00071 if ( MuonHandle->empty() ) return false; 00072 MuonCollection TheMuons = *MuonHandle; 00073 std::stable_sort( TheMuons.begin(), TheMuons.end(), PtSorter() ); 00074 00075 int nMuon = 0; 00076 double Pxdimuon = 0., Pydimuon = 0.; 00077 for ( MuonCollection::const_iterator it = TheMuons.begin(); 00078 it != TheMuons.end(); it++ ) { 00079 if ( (it->pt() > MuonPtmin_) 00080 && (fabs(it->eta()) < 3.0) ) { 00081 if ( nMuon < 2 ) { 00082 Pxdimuon += it->p()*sin(it->theta())*cos(it->phi()); 00083 Pydimuon += it->p()*sin(it->theta())*sin(it->phi()); 00084 } 00085 nMuon++; 00086 } 00087 } 00088 00089 if ( nMuon < NminMuon_ ) return false; 00090 00091 double PtdiMuon = sqrt( Pxdimuon*Pxdimuon + Pydimuon*Pydimuon ); 00092 if ( PtdiMuon < PtmindiMuon_ ) return false; 00093 00094 nAccepted_++; 00095 00096 return true; 00097 } 00098 00099 /*------------------------------------------------------------------------*/ 00100 00101 void HadSUSYdiMuonSkim::endJob() 00102 { 00103 edm::LogVerbatim( "HadSUSYdiMuonSkim" ) 00104 << "Events read " << nEvents_ 00105 << " Events accepted " << nAccepted_ 00106 << "\nEfficiency " << (double)(nAccepted_)/(double)(nEvents_) 00107 << endl; 00108 }