CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/PhysicsTools/SelectorUtils/interface/PFMuonSelector.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PatUtils_interface_PFMuonSelector_h
00002 #define PhysicsTools_PatUtils_interface_PFMuonSelector_h
00003 
00004 #include "DataFormats/PatCandidates/interface/Muon.h"
00005 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include "PhysicsTools/SelectorUtils/interface/Selector.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 
00011 #include <iostream>
00012 
00013 class PFMuonSelector : public Selector<pat::Muon> {
00014 
00015  public: // interface
00016 
00017   bool verbose_;
00018   
00019   enum Version_t { SPRING11, N_VERSIONS };
00020 
00021   PFMuonSelector() {}
00022 
00023   PFMuonSelector( edm::ParameterSet const & parameters ) {
00024 
00025     verbose_ = false;
00026     
00027     std::string versionStr = parameters.getParameter<std::string>("version");
00028 
00029     Version_t version = N_VERSIONS;
00030 
00031     if ( versionStr == "SPRING11" ) {
00032       version = SPRING11;
00033     }
00034     else {
00035       throw cms::Exception("InvalidInput") << "Expect version to be one of SPRING11" << std::endl;
00036     }
00037 
00038     initialize( version, 
00039                 parameters.getParameter<double>("Chi2"),
00040                 parameters.getParameter<double>("D0")  ,
00041                 parameters.getParameter<int>   ("NHits")   ,
00042                 parameters.getParameter<int>   ("NValMuHits"),
00043                 parameters.getParameter<double>("PFIso"),
00044                 parameters.getParameter<int>   ("nPixelHits"),
00045                 parameters.getParameter<int>   ("nMatchedStations")
00046                 );
00047     if ( parameters.exists("cutsToIgnore") )
00048       setIgnoredCuts( parameters.getParameter<std::vector<std::string> >("cutsToIgnore") );
00049         
00050     retInternal_ = getBitTemplate();
00051 
00052   }
00053 
00054   void initialize( Version_t version,
00055                    double chi2 = 10.0,
00056                    double d0 = 0.02,
00057                    int nhits = 11,
00058                    int nValidMuonHits = 0,
00059                    double pfiso = 0.15,
00060                    int minPixelHits = 1,
00061                    int minNMatches = 1 )
00062   {
00063     version_ = version; 
00064 
00065     push_back("Chi2",      chi2   );
00066     push_back("D0",        d0     );
00067     push_back("NHits",     nhits  );
00068     push_back("NValMuHits",nValidMuonHits  );
00069     push_back("PFIso",     pfiso );
00070     push_back("nPixelHits",minPixelHits);
00071     push_back("nMatchedStations", minNMatches);
00072 
00073     set("Chi2");
00074     set("D0");
00075     set("NHits");
00076     set("NValMuHits");
00077     set("PFIso");   
00078     set("nPixelHits");
00079     set("nMatchedStations");  
00080 
00081     indexChi2_          = index_type(&bits_, "Chi2"         );
00082     indexD0_            = index_type(&bits_, "D0"           );
00083     indexNHits_         = index_type(&bits_, "NHits"        );
00084     indexNValMuHits_    = index_type(&bits_, "NValMuHits"   );
00085     indexPFIso_         = index_type(&bits_, "PFIso"       );
00086     indexPixHits_       = index_type(&bits_, "nPixelHits");
00087     indexStations_      = index_type(&bits_, "nMatchedStations");
00088 
00089   }
00090 
00091   // Allow for multiple definitions of the cuts. 
00092   bool operator()( const pat::Muon & muon, pat::strbitset & ret ) 
00093   { 
00094     if (version_ == SPRING11 ) return spring11Cuts(muon, ret);
00095     else {
00096       return false;
00097     }
00098   }
00099 
00100   using Selector<pat::Muon>::operator();
00101 
00102   // cuts based on top group L+J synchronization exercise
00103   bool spring11Cuts( const pat::Muon & muon, pat::strbitset & ret)
00104   {
00105     ret.set(false);
00106 
00107     double norm_chi2 = 9999999.0;
00108     if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )
00109       norm_chi2 = muon.normChi2();
00110     double corr_d0 = 999999.0;
00111     if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )    
00112       corr_d0 = muon.dB();
00113 
00114     int nhits = static_cast<int>( muon.numberOfValidHits() );
00115     int nValidMuonHits = 0;
00116     if ( muon.globalTrack().isNonnull() && muon.globalTrack().isAvailable() )
00117       nValidMuonHits = static_cast<int> (muon.globalTrack()->hitPattern().numberOfValidMuonHits());
00118 
00119     double chIso = muon.userIsolation(pat::PfChargedHadronIso);
00120     double nhIso = muon.userIsolation(pat::PfNeutralHadronIso);
00121     double gIso  = muon.userIsolation(pat::PfGammaIso);
00122     double pt    = muon.pt() ;
00123 
00124     double pfIso = (chIso + nhIso + gIso) / pt;
00125 
00126     int nPixelHits = 0;
00127     if ( muon.innerTrack().isNonnull() && muon.innerTrack().isAvailable() )
00128       nPixelHits = muon.innerTrack()->hitPattern().pixelLayersWithMeasurement();
00129 
00130     int nMatchedStations = muon.numberOfMatches();
00131 
00132     if ( norm_chi2     <  cut(indexChi2_,   double()) || ignoreCut(indexChi2_)    ) passCut(ret, indexChi2_   );
00133     if ( fabs(corr_d0) <  cut(indexD0_,     double()) || ignoreCut(indexD0_)      ) passCut(ret, indexD0_     );
00134     if ( nhits         >= cut(indexNHits_,  int()   ) || ignoreCut(indexNHits_)   ) passCut(ret, indexNHits_  );
00135     if ( nValidMuonHits>  cut(indexNValMuHits_,int()) || ignoreCut(indexNValMuHits_)) passCut(ret, indexNValMuHits_  );
00136     if ( pfIso         <  cut(indexPFIso_, double())  || ignoreCut(indexPFIso_)  ) passCut(ret, indexPFIso_ );
00137     if ( nPixelHits    >  cut(indexPixHits_,int())    || ignoreCut(indexPixHits_))  passCut(ret, indexPixHits_);
00138     if ( nMatchedStations> cut(indexStations_,int())  || ignoreCut(indexStations_))  passCut(ret, indexStations_);
00139 
00140     setIgnored(ret);
00141     
00142     return (bool)ret;
00143   }
00144 
00145   
00146   
00147  private: // member variables
00148   
00149   Version_t version_;
00150 
00151   index_type indexChi2_;
00152   index_type indexD0_;
00153   index_type indexNHits_;
00154   index_type indexNValMuHits_;
00155   index_type indexPFIso_;
00156   index_type indexPixHits_;
00157   index_type indexStations_;
00158 
00159 
00160 };
00161 
00162 #endif