CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/SimMuon/MCTruth/interface/MuonAssociatorByHits.h

Go to the documentation of this file.
00001 #ifndef MuonAssociatorByHits_h
00002 #define MuonAssociatorByHits_h
00003 
00004 #include "FWCore/Framework/interface/Frameworkfwd.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "DataFormats/Common/interface/Handle.h"
00010 #include "DataFormats/Common/interface/EDProduct.h"
00011 #include "DataFormats/Common/interface/Ref.h"
00012 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00013 #include "DataFormats/TrackReco/interface/Track.h"
00014 #include "DataFormats/MuonReco/interface/Muon.h"
00015 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00016 #include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
00017 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00018 #include "SimMuon/MCTruth/interface/DTHitAssociator.h"
00019 #include "SimMuon/MCTruth/interface/MuonTruth.h"
00020 #include "SimMuon/MCTruth/interface/RPCHitAssociator.h"
00021 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
00022 #include "SimTracker/TrackAssociation/interface/TrackAssociatorBase.h"
00023 
00024 class MuonAssociatorByHits : public TrackAssociatorBase {
00025   
00026  public:
00027   typedef std::pair <uint32_t, EncodedEventId> SimHitIdpr;
00028   typedef std::map<unsigned int, std::vector<SimHitIdpr> > MapOfMatchedIds;
00029 
00030   MuonAssociatorByHits( const edm::ParameterSet& );  
00031   ~MuonAssociatorByHits();
00032   
00033   // Get base methods from base class
00034   using TrackAssociatorBase::associateRecoToSim;
00035   using TrackAssociatorBase::associateSimToReco;
00036  
00037   /* Associate SimTracks to RecoTracks By Hits */
00039   reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector<reco::Track>&,
00040                                                const edm::RefVector<TrackingParticleCollection>&,
00041                                                const edm::Event * event = 0, const edm::EventSetup * setup = 0) const;
00042   
00044   reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector<reco::Track>&,
00045                                                const edm::RefVector<TrackingParticleCollection>&,
00046                                                const edm::Event * event = 0, const edm::EventSetup * setup = 0) const ;
00047 
00048  
00049   void getMatchedIds
00050     (MapOfMatchedIds & tracker_matchedIds_valid, MapOfMatchedIds & muon_matchedIds_valid,
00051      MapOfMatchedIds & tracker_matchedIds_INVALID, MapOfMatchedIds & muon_matchedIds_INVALID,
00052      int& n_tracker_valid, int& n_dt_valid, int& n_csc_valid, int& n_rpc_valid,
00053      int& n_tracker_matched_valid, int& n_dt_matched_valid, int& n_csc_matched_valid, int& n_rpc_matched_valid,
00054      int& n_tracker_INVALID, int& n_dt_INVALID, int& n_csc_INVALID, int& n_rpc_INVALID,
00055      int& n_tracker_matched_INVALID, int& n_dt_matched_INVALID, int& n_csc_matched_INVALID, int& n_rpc_matched_INVALID,
00056      trackingRecHit_iterator begin, trackingRecHit_iterator end,
00057      TrackerHitAssociator* trackertruth, DTHitAssociator& dttruth, MuonTruth& csctruth, RPCHitAssociator& rpctruth, 
00058      bool printRts) const;
00059   
00060   int getShared(MapOfMatchedIds & matchedIds, TrackingParticleCollection::const_iterator trpart) const;
00061 
00062 
00063   enum MuonTrackType { InnerTk, OuterTk, GlobalTk, Segments };
00064   struct RefToBaseSort { 
00065     template<typename T> bool operator()(const edm::RefToBase<T> &r1, const edm::RefToBase<T> &r2) const { 
00066         return (r1.id() == r2.id() ? r1.key() < r2.key() : r1.id() < r2.id()); 
00067     }
00068   };
00069   typedef std::map<edm::RefToBase<reco::Muon>, std::vector<std::pair<TrackingParticleRef, double> >, RefToBaseSort> MuonToSimCollection;
00070   typedef std::map<TrackingParticleRef, std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > >               SimToMuonCollection;
00071 
00072 
00073   void associateMuons(MuonToSimCollection & recoToSim, SimToMuonCollection & simToReco,
00074                       const edm::RefToBaseVector<reco::Muon> &, MuonTrackType ,
00075                       const edm::RefVector<TrackingParticleCollection>&,
00076                       const edm::Event * event = 0, const edm::EventSetup * setup = 0) const ; 
00077 
00078   void associateMuons(MuonToSimCollection & recoToSim, SimToMuonCollection & simToReco,
00079                       const edm::Handle<edm::View<reco::Muon> > &, MuonTrackType , 
00080                       const edm::Handle<TrackingParticleCollection>&,
00081                       const edm::Event * event = 0, const edm::EventSetup * setup = 0) const ;
00082 
00083  private:
00084   const bool includeZeroHitMuons;    
00085   const bool acceptOneStubMatchings;
00086   bool UseTracker;
00087   bool UseMuon;
00088   const bool AbsoluteNumberOfHits_track;
00089   unsigned int NHitCut_track;    
00090   double EfficiencyCut_track;
00091   double PurityCut_track;
00092   const bool AbsoluteNumberOfHits_muon;
00093   unsigned int NHitCut_muon;    
00094   double EfficiencyCut_muon;
00095   double PurityCut_muon;
00096   const bool UsePixels;
00097   const bool UseGrouped;
00098   const bool UseSplitting;
00099   const bool ThreeHitTracksAreSpecial;
00100   const bool dumpDT;
00101   const bool dumpInputCollections;
00102   const bool crossingframe;
00103   edm::InputTag simtracksTag;
00104   edm::InputTag simtracksXFTag;
00105   const edm::ParameterSet& conf_;
00106 
00107   int LayerFromDetid(const DetId&) const;
00108   const TrackingRecHit* getHitPtr(edm::OwnVector<TrackingRecHit>::const_iterator iter) const {return &*iter;}
00109   const TrackingRecHit* getHitPtr(trackingRecHit_iterator iter) const {return &**iter;}
00110 
00111   std::string write_matched_simtracks(const std::vector<SimHitIdpr>&) const;
00112 
00113   /* ==== ALL BELOW THIS IS FOR EXPERTS OR INTERNAL USE ONLY ==== */
00114   typedef std::vector<std::pair<trackingRecHit_iterator, trackingRecHit_iterator> > TrackHitsCollection;
00115   struct IndexMatch {
00116       IndexMatch(size_t index, double global_quality) : idx(index), quality(global_quality) {}
00117       size_t idx; double quality; 
00118       bool operator<(const IndexMatch &other) const { return other.quality < quality; } 
00119   };
00120   typedef std::map<size_t, std::vector<IndexMatch> > IndexAssociation;
00121  
00122   IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, 
00123                                              const edm::RefVector<TrackingParticleCollection>&,
00124                                              const edm::Event * event = 0, const edm::EventSetup * setup = 0) const ; 
00125   IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, 
00126                                              const edm::RefVector<TrackingParticleCollection>&,
00127                                              const edm::Event * event = 0, const edm::EventSetup * setup = 0) const ;
00128   
00129 
00130 
00131 };
00132 
00133 #endif