00001 00002 #ifndef TrackClassifierByProxy_h 00003 #define TrackClassifierByProxy_h 00004 00005 #include "DataFormats/Common/interface/AssociationMap.h" 00006 00007 #include "SimTracker/TrackHistory/interface/TrackClassifier.h" 00008 00010 template <typename Collection> 00011 class TrackClassifierByProxy : public TrackClassifier 00012 { 00013 00014 public: 00015 00017 typedef edm::AssociationMap<edm::OneToMany<Collection, reco::TrackCollection> > Association; 00018 00020 TrackClassifierByProxy(edm::ParameterSet const & config) : TrackClassifier(config), 00021 proxy_( config.getUntrackedParameter<edm::InputTag>("trackProducer") ) {} 00022 00024 virtual void newEvent(edm::Event const & event, edm::EventSetup const & config) 00025 { 00026 // Get the association part of the proxy to the collection 00027 event.getByLabel(proxy_, proxyHandler_); 00028 // Call the previous new event 00029 TrackClassifier::newEvent(event, config); 00030 } 00031 00033 TrackClassifierByProxy<Collection> const & evaluate (TrackingParticleRef const & track) 00034 { 00035 TrackClassifier::evaluate(track); 00036 return *this; 00037 } 00038 00040 TrackClassifierByProxy<Collection> const & evaluate (edm::Ref<Collection> const & track, std::size_t index) 00041 { 00042 const reco::TrackRefVector * tracks = 0; 00043 00044 try 00045 { 00046 // Get a reference to the vector of associated tracks 00047 tracks = proxyHandler_->find(track)->val; 00048 } 00049 catch (edm::Exception& e) 00050 { 00051 // If association fails define the track as unknown 00052 reset(); 00053 unknownTrack(); 00054 return *this; 00055 } 00056 00057 // Evaluate the history for a given index 00058 TrackClassifier::evaluate( tracks->at(index) ); 00059 00060 return *this; 00061 } 00062 00064 TrackClassifierByProxy<Collection> const & evaluate (edm::Ref<Collection> const & track) 00065 { 00066 const reco::TrackRefVector * tracks = 0; 00067 00068 try 00069 { 00070 // Get a reference to the vector of associated tracks 00071 tracks = proxyHandler_->find(track)->val; 00072 } 00073 catch (edm::Exception& e) 00074 { 00075 // If association fails define the track as unknown 00076 reset(); 00077 unknownTrack(); 00078 return *this; 00079 } 00080 00081 // Loop over all the associated tracks 00082 for (std::size_t index = 0; index < tracks->size(); ++index) 00083 { 00084 // Copy the last status for all the flags 00085 Flags flags(flags_); 00086 00087 // Evaluate the history for a given index 00088 TrackClassifier::evaluate( tracks->at(index) ); 00089 00090 // Combine OR the flag information 00091 for (std::size_t i = 0; i < flags_.size(); ++i) 00092 flags_[i] = flags_[i] | flags[i]; 00093 } 00094 00095 return *this; 00096 } 00097 00098 private: 00099 00100 const edm::InputTag proxy_; 00101 00102 edm::Handle<Association> proxyHandler_; 00103 00104 }; 00105 00106 #endif