Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:43

0001 #ifndef JetReco_JetTrackMatch_h
0002 #define JetReco_JetTrackMatch_h
0003 
0004 /** \class reco::JetTrackMatch
0005  *
0006  * \short Association between Jets from jet collection and tracks from track collection
0007  *
0008  * Every jet may have several tracks associated with it
0009  *
0010  * class definition:
0011  * 
0012  *  template <typename JetC>
0013  *   class JetTrackMatch {
0014  *   public:
0015  *   typedef edm::Ref<JetC> JetRef;
0016  *   typedef edm::Ref<reco::TrackCollection> TrackRef;
0017  *   JetTrackMatch ();
0018  *   ~JetTrackMatch ();
0019  *   // insert orphan jet
0020  *   void insert (const JetRef& fJet);
0021  *   // assign track to jet. 
0022  *   void insert (const JetRef& fJet, const TrackRef& fTrack);
0023  *   // get list of all tracks in the map
0024  *   std::vector <JetRef> allJets () const;
0025  *   // get all tracks associated with jet
0026  *   std::vector <TrackRef> getTracks (const JetRef& mJet) const;
0027  * };
0028  *
0029  * \author Fedor Ratnikov, UMd
0030  *
0031  ************************************************************/
0032 
0033 #include "DataFormats/Common/interface/AssociationMap.h"
0034 #include "DataFormats/TrackReco/interface/Track.h"
0035 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0036 
0037 namespace reco {
0038   template <typename JetC>
0039   class JetTrackMatch {
0040   public:
0041     typedef edm::Ref<JetC> JetRef;
0042     typedef edm::Ref<reco::TrackCollection> TrackRef;
0043     typedef edm::AssociationMap<edm::OneToMany<JetC, reco::TrackCollection> > Map;
0044 
0045   private:
0046     Map mMap;
0047 
0048   public:
0049     JetTrackMatch() {}
0050     ~JetTrackMatch() {}
0051 
0052     /// insert orphan jet
0053     void insert(const JetRef& fJet) { mMap.insert(fJet, TrackRef()); }
0054 
0055     /// assign track to jet.
0056     void insert(const JetRef& fJet, const TrackRef& fTrack) { mMap.insert(fJet, fTrack); }
0057 
0058     /// get list of all jats in the map
0059     std::vector<JetRef> allJets() const {
0060       std::vector<JetRef> result;
0061       typename Map::const_iterator it = mMap.begin();
0062       for (; it != mMap.end(); ++it) {
0063         result.push_back(it->key);
0064       }
0065       return result;
0066     }
0067     /// get all tracks associated with jet
0068     std::vector<TrackRef> getTracks(const JetRef& mJet) const {
0069       std::vector<TrackRef> result;
0070       reco::TrackRefVector tracks = mMap[mJet];
0071       int i = tracks.size();
0072       while (--i >= 0) {
0073         if (!tracks[i].isNull())
0074           result.push_back(tracks[i]);
0075       }
0076       return result;
0077     }
0078   };
0079 }  // namespace reco
0080 
0081 #endif