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
0010 template <typename Collection>
0011 class VertexClassifierByProxy : public VertexClassifier {
0012 public:
0013
0014 typedef edm::AssociationMap<edm::OneToMany<Collection, reco::VertexCollection>> Association;
0015
0016
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
0024 void newEvent(edm::Event const &event, edm::EventSetup const &config) override {
0025
0026 event.getByLabel(proxy_, proxyHandler_);
0027
0028 VertexClassifier::newEvent(event, config);
0029 }
0030
0031
0032 VertexClassifierByProxy<Collection> const &evaluate(TrackingVertexRef const &vertex) {
0033 VertexClassifier::evaluate(vertex);
0034 return *this;
0035 }
0036
0037
0038 VertexClassifierByProxy<Collection> const &evaluate(edm::Ref<Collection> const &vertex, std::size_t index) {
0039 const reco::VertexRefVector *vertexes = nullptr;
0040
0041 try {
0042
0043 vertexes = &(proxyHandler_->find(vertex)->val);
0044 } catch (edm::Exception &e) {
0045
0046 reset();
0047 unknownVertex();
0048 return *this;
0049 }
0050
0051
0052 VertexClassifier::evaluate(vertexes->at(index));
0053
0054 return *this;
0055 }
0056
0057
0058 VertexClassifierByProxy<Collection> const &evaluate(edm::Ref<Collection> const &vertex) {
0059 const reco::VertexRefVector *vertexes = nullptr;
0060
0061 try {
0062
0063 vertexes = &(proxyHandler_->find(vertex)->val);
0064 } catch (edm::Exception &e) {
0065
0066 reset();
0067 unknownVertex();
0068 return *this;
0069 }
0070
0071
0072 for (std::size_t index = 0; index < vertexes->size(); ++index) {
0073
0074 Flags flags(flags_);
0075
0076
0077 VertexClassifier::evaluate(vertexes->at(index));
0078
0079
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