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