CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoParticleFlow/PFProducer/interface/PFMuonAlgo.h

Go to the documentation of this file.
00001 #ifndef RecoParticleFlow_PFProducer_PFMuonAlgo_h
00002 #define RecoParticleFlow_PFProducer_PFMuonAlgo_h 
00003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00004 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00005 #include "DataFormats/VertexReco/interface/Vertex.h"
00006 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "DataFormats/MuonReco/interface/Muon.h"
00010 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00011 
00012 class PFMuonAlgo {
00013 
00014   typedef reco::Muon::MuonTrackTypePair MuonTrackTypePair;
00015   typedef reco::Muon::MuonTrackType  MuonTrackType;
00016 
00017  public:
00018 
00020   PFMuonAlgo();
00021 
00022   void setParameters(const edm::ParameterSet&);
00023   
00024 
00025 
00027   virtual ~PFMuonAlgo() {;}
00028   
00030 
00031   static bool isMuon( const reco::PFBlockElement& elt );
00032 
00033   static bool isLooseMuon( const reco::PFBlockElement& elt );
00034 
00035   static bool isGlobalTightMuon( const reco::PFBlockElement& elt );
00036 
00037   static bool isGlobalLooseMuon( const reco::PFBlockElement& elt );
00038 
00039   static bool isTrackerTightMuon( const reco::PFBlockElement& elt );
00040 
00041   static bool isTrackerLooseMuon( const reco::PFBlockElement& elt );
00042 
00043   static bool isIsolatedMuon( const reco::PFBlockElement& elt );
00044 
00045   static bool hasValidTracks(const reco::MuonRef& );
00046 
00047   static bool isMuon( const reco::MuonRef& muonRef );  
00048 
00049   static bool isLooseMuon( const reco::MuonRef& muonRef );
00050 
00051   static bool isGlobalTightMuon( const reco::MuonRef& muonRef );
00052 
00053   static bool isGlobalLooseMuon( const reco::MuonRef& muonRef );
00054 
00055   static bool isTrackerTightMuon( const reco::MuonRef& muonRef );
00056   
00057   static bool isTrackerLooseMuon( const reco::MuonRef& muonRef );
00058   
00059   static bool isIsolatedMuon( const reco::MuonRef& muonRef );
00060 
00061   static bool isTightMuonPOG(const reco::MuonRef& muonRef);
00062 
00063   static void printMuonProperties( const reco::MuonRef& muonRef );
00064 
00065 
00066 
00067 
00069 
00070   //Make a PF Muon : Basic method
00071   bool reconstructMuon(reco::PFCandidate&, const reco::MuonRef&,bool allowLoose = false);
00072 
00073 
00074   //Assign a different track to the muon
00075   void changeTrack(reco::PFCandidate&,const MuonTrackTypePair&);
00076   //PF Post cleaning algorithm
00077   void setInputsForCleaning(const reco::VertexCollection*); 
00078   void postClean(reco::PFCandidateCollection *);
00079   void addMissingMuons(edm::Handle<reco::MuonCollection>, reco::PFCandidateCollection* cands);
00080 
00081   std::auto_ptr<reco::PFCandidateCollection>& transferCleanedCosmicCandidates() {
00082     return pfCosmicsMuonCleanedCandidates_;
00083   }
00084 
00085   std::auto_ptr<reco::PFCandidateCollection>& transferCleanedTrackerAndGlobalCandidates() {
00086     return pfCleanedTrackerAndGlobalMuonCandidates_;
00087   }
00088 
00089   std::auto_ptr<reco::PFCandidateCollection>& transferCleanedFakeCandidates() {
00090     return pfFakeMuonCleanedCandidates_;
00091   }
00092 
00093   std::auto_ptr<reco::PFCandidateCollection>& transferPunchThroughCleanedMuonCandidates() {
00094     return pfPunchThroughMuonCleanedCandidates_;
00095   }
00096 
00097   std::auto_ptr<reco::PFCandidateCollection>& transferPunchThroughCleanedHadronCandidates() {
00098     return pfPunchThroughHadronCleanedCandidates_;
00099   }
00100 
00101   std::auto_ptr<reco::PFCandidateCollection>& transferAddedMuonCandidates() {
00102     return pfAddedMuonCandidates_;
00103   }
00104 
00105  private:
00106   //Gives the track with the smallest Dpt/Pt
00107   MuonTrackTypePair getTrackWithSmallestError(const std::vector<MuonTrackTypePair>&);
00108 
00109   std::vector<reco::Muon::MuonTrackTypePair> muonTracks(const reco::MuonRef& muon,bool includeSA = false,double dpt = 1e+9);
00110 
00111   //Gets the good tracks
00112   std::vector<reco::Muon::MuonTrackTypePair> goodMuonTracks(const reco::MuonRef& muon,bool includeSA = false);
00113 
00114 
00115   //Estimate MET and SUmET for post cleaning
00116   void estimateEventQuantities(const reco::PFCandidateCollection*  );
00117 
00118   //Post cleaning Sub-methods
00119   bool cleanMismeasured(reco::PFCandidate&,unsigned int);
00120   bool cleanPunchThroughAndFakes(reco::PFCandidate&,reco::PFCandidateCollection* ,unsigned int );
00121 
00122   void  removeDeadCandidates(reco::PFCandidateCollection*, const std::vector<unsigned int>&);
00123 
00124 
00125 
00126   //helpers  
00127   std::pair<double,double> getMinMaxMET2(const reco::PFCandidate&);
00128   std::vector<MuonTrackTypePair> tracksWithBetterMET(const std::vector<MuonTrackTypePair>& ,const reco::PFCandidate&);
00129   std::vector<MuonTrackTypePair> tracksPointingAtMET(const std::vector<MuonTrackTypePair>&);
00130 
00131   //Output collections for post cleaning
00133   std::auto_ptr< reco::PFCandidateCollection >    pfCosmicsMuonCleanedCandidates_;
00135   std::auto_ptr< reco::PFCandidateCollection >    pfCleanedTrackerAndGlobalMuonCandidates_;
00137   std::auto_ptr< reco::PFCandidateCollection >    pfFakeMuonCleanedCandidates_;
00139   std::auto_ptr< reco::PFCandidateCollection >    pfPunchThroughMuonCleanedCandidates_;
00141   std::auto_ptr< reco::PFCandidateCollection >    pfPunchThroughHadronCleanedCandidates_;
00143   std::auto_ptr< reco::PFCandidateCollection >    pfAddedMuonCandidates_;
00144   
00145   std::vector<unsigned int > maskedIndices_;
00146 
00147   
00149   const reco::VertexCollection *  vertices_;
00150 
00151 
00152 
00153   //Configurables
00154   double maxDPtOPt_;
00155   int minTrackerHits_;
00156   int minPixelHits_;
00157   reco::TrackBase::TrackQuality trackQuality_;
00158   
00159   double errorCompScale_;
00160   double eventFractionCleaning_;
00161   double sumetPU_;
00162   double dzPV_;
00163   bool postCleaning_;
00164   double minPostCleaningPt_;
00165   double eventFactorCosmics_;
00166   double metSigForCleaning_;
00167   double metSigForRejection_;
00168   double metFactorCleaning_;
00169   double eventFractionRejection_;
00170   double metFactorRejection_;
00171   double metFactorHighEta_;
00172   double ptFactorHighEta_;
00173   double metFactorFake_;
00174   double minPunchThroughMomentum_;
00175   double minPunchThroughEnergy_;
00176   double punchThroughFactor_;
00177   double punchThroughMETFactor_;
00178   double cosmicRejDistance_;
00179 
00180   double sumet_;
00181   double METX_;
00182   double METY_;
00183 
00184 
00186 
00187   class TrackMETComparator {
00188   public:
00189     TrackMETComparator(double METX,double METY) {metx_ = METX; mety_=METY;}
00190     ~TrackMETComparator() {}
00191     
00192     bool operator()(MuonTrackTypePair mu1,MuonTrackTypePair mu2) {
00193       return pow(metx_+mu1.first->px(),2)+pow(mety_+mu1.first->py(),2) < pow(metx_+mu2.first->px(),2)+pow(mety_+mu2.first->py(),2);
00194     }
00195   private:
00196     double metx_;
00197     double mety_;
00198 
00199 
00200   };
00201 
00202 
00203   class IndexPtComparator {
00204   public:
00205 
00206     IndexPtComparator(const reco::PFCandidateCollection* coll):coll_(coll) {
00207     }
00208     ~IndexPtComparator() {}
00209     
00210     bool operator()(int mu1,int mu2) {
00211       return coll_->at(mu1).pt() > coll_->at(mu2).pt();
00212     }
00213 
00214   private:
00215     const reco::PFCandidateCollection * coll_;
00216 
00217   };
00218 
00219 
00220 
00221 
00222   class TrackPtErrorSorter {
00223   public:
00224     TrackPtErrorSorter() {}
00225     ~TrackPtErrorSorter() {}
00226 
00227     bool operator()(MuonTrackTypePair mu1,MuonTrackTypePair mu2) {
00228       return mu1.first->ptError()/mu1.first->pt() < mu2.first->ptError()/mu2.first->pt();
00229     }
00230   };
00231 
00232 
00233 
00234 };
00235 
00236 #endif