Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:45

0001 #ifndef CategoryCriteria_h
0002 #define CategoryCriteria_h
0003 
0004 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 
0010 #include "DataFormats/Common/interface/Ref.h"
0011 
0012 //! Implement a selector given a track or vertex collection and track or vertex
0013 //! classifier.
0014 template <typename Collection, typename Classifier>
0015 class CategoryCriteria {
0016 public:
0017   // Input collection type
0018   typedef Collection collection;
0019 
0020   // Type of the collection elements
0021   typedef typename Collection::value_type type;
0022 
0023   // Oumemberut collection type
0024   typedef std::vector<const type *> container;
0025 
0026   // Iterator over result collection type.
0027   typedef typename container::const_iterator const_iterator;
0028 
0029   // Constructor from parameter set configurability
0030   CategoryCriteria(const edm::ParameterSet &config, edm::ConsumesCollector &&iC)
0031       : classifier_(config, std::move(iC)), evaluate_(config.getParameter<std::string>("cut")) {}
0032 
0033   // Select object from a collection and possibly event content
0034   void select(const edm::Handle<collection> &collectionHandler, const edm::Event &event, const edm::EventSetup &setup) {
0035     selected_.clear();
0036 
0037     // const collection & collectionPointer = *(collectionHandler.product());
0038 
0039     classifier_.newEvent(event, setup);
0040 
0041     for (typename collection::size_type i = 0; i < collectionHandler->size(); ++i) {
0042       edm::Ref<Collection> member(collectionHandler, i);
0043 
0044       classifier_.evaluate(member);
0045 
0046       // Classifier is evaluated using StringCutObjectSelector
0047       if (evaluate_(classifier_))
0048         selected_.push_back(&(*member));
0049     }
0050   }
0051 
0052   // Iterators over selected objects: collection begin
0053   const_iterator begin() const { return selected_.begin(); }
0054 
0055   // Iterators over selected objects: collection end
0056   const_iterator end() const { return selected_.end(); }
0057 
0058   // True if no object has been selected
0059   std::size_t size() const { return selected_.size(); }
0060 
0061 private:
0062   container selected_;
0063 
0064   Classifier classifier_;
0065 
0066   StringCutObjectSelector<typename Classifier::Categories> evaluate_;
0067 };
0068 
0069 #endif