Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-05 23:51:51

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