Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:05

0001 
0002 #ifndef VertexClassifierByProxy_h
0003 #define VertexClassifierByProxy_h
0004 
0005 #include "DataFormats/Common/interface/AssociationMap.h"
0006 
0007 #include "SimTracker/TrackHistory/interface/VertexClassifier.h"
0008 
0009 //! Get track history and classification by proxy
0010 template <typename Collection>
0011 class VertexClassifierByProxy : public VertexClassifier {
0012 public:
0013   //! Association type.
0014   typedef edm::AssociationMap<edm::OneToMany<Collection, reco::VertexCollection>> Association;
0015 
0016   //! Constructor by ParameterSet.
0017   VertexClassifierByProxy(edm::ParameterSet const &config, edm::ConsumesCollector &&collector)
0018       : VertexClassifier(config, std::move(collector)),
0019         proxy_(config.getUntrackedParameter<edm::InputTag>("vertexProducer")) {
0020     collector.consumes<Association>(proxy_);
0021   }
0022 
0023   //! Pre-process event information (for accessing reconstraction information).
0024   void newEvent(edm::Event const &event, edm::EventSetup const &config) override {
0025     // Get the association part of the proxy to the collection
0026     event.getByLabel(proxy_, proxyHandler_);
0027     // Call the previous new event
0028     VertexClassifier::newEvent(event, config);
0029   }
0030 
0031   //! Classify the TrackingVertex in categories.
0032   VertexClassifierByProxy<Collection> const &evaluate(TrackingVertexRef const &vertex) {
0033     VertexClassifier::evaluate(vertex);
0034     return *this;
0035   }
0036 
0037   //! Classify any vertexes in categories.
0038   VertexClassifierByProxy<Collection> const &evaluate(edm::Ref<Collection> const &vertex, std::size_t index) {
0039     const reco::VertexRefVector *vertexes = nullptr;
0040 
0041     try {
0042       // Get a reference to the vector of associated vertexes
0043       vertexes = &(proxyHandler_->find(vertex)->val);
0044     } catch (edm::Exception &e) {
0045       // If association fails define the vertex as unknown
0046       reset();
0047       unknownVertex();
0048       return *this;
0049     }
0050 
0051     // Evaluate the history for a given index
0052     VertexClassifier::evaluate(vertexes->at(index));
0053 
0054     return *this;
0055   }
0056 
0057   //! Classify any vertexes in categories.
0058   VertexClassifierByProxy<Collection> const &evaluate(edm::Ref<Collection> const &vertex) {
0059     const reco::VertexRefVector *vertexes = nullptr;
0060 
0061     try {
0062       // Get a reference to the vector of associated vertexes
0063       vertexes = &(proxyHandler_->find(vertex)->val);
0064     } catch (edm::Exception &e) {
0065       // If association fails define the vertex as unknown
0066       reset();
0067       unknownVertex();
0068       return *this;
0069     }
0070 
0071     // Loop over all the associated vertexes
0072     for (std::size_t index = 0; index < vertexes->size(); ++index) {
0073       // Copy the last status for all the flags
0074       Flags flags(flags_);
0075 
0076       // Evaluate the history for a given index
0077       VertexClassifier::evaluate(vertexes->at(index));
0078 
0079       // Combine OR the flag information
0080       for (std::size_t i = 0; i < flags_.size(); ++i)
0081         flags_[i] = flags_[i] || flags[i];
0082     }
0083 
0084     return *this;
0085   }
0086 
0087 private:
0088   const edm::InputTag proxy_;
0089 
0090   edm::Handle<Association> proxyHandler_;
0091 };
0092 
0093 #endif