Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:16

0001 #ifndef RecoAlgos_ObjectPairCollectionSelector_h
0002 #define RecoAlgos_ObjectPairCollectionSelector_h
0003 /** \class ObjectPairCollectionSelector
0004  *
0005  * selects object pairs wose combination satiefies a specific selection
0006  * for instance, could be based on invariant mass, deltaR , deltaPhi, etc.
0007  *
0008  * \author Luca Lista, INFN
0009  *
0010  * \version $Revision: 1.1 $
0011  *
0012  * $Id: ObjectPairCollectionSelector.h,v 1.1 2009/03/03 13:07:27 llista Exp $
0013  *
0014  */
0015 
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/ConsumesCollector.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
0020 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
0021 #include <vector>
0022 
0023 namespace edm {
0024   class Event;
0025 }
0026 
0027 template <typename InputCollection,
0028           typename Selector,
0029           typename StoreContainer = std::vector<const typename InputCollection::value_type *>,
0030           typename RefAdder = typename helper::SelectionAdderTrait<InputCollection, StoreContainer>::type>
0031 class ObjectPairCollectionSelector {
0032 public:
0033   typedef InputCollection collection;
0034 
0035 private:
0036   typedef const typename InputCollection::value_type *reference;
0037   typedef StoreContainer container;
0038   typedef typename container::const_iterator const_iterator;
0039 
0040 public:
0041   ObjectPairCollectionSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
0042       : select_(reco::modules::make<Selector>(cfg)) {}
0043   const_iterator begin() const { return selected_.begin(); }
0044   const_iterator end() const { return selected_.end(); }
0045   void select(const edm::Handle<InputCollection> &c, const edm::Event &, const edm::EventSetup &) {
0046     unsigned int s = c->size();
0047     std::vector<bool> v(s, false);
0048     for (unsigned int i = 0; i < s; ++i)
0049       for (unsigned int j = i + 1; j < s; ++j) {
0050         if (select_((*c)[i], (*c)[j]))
0051           v[i] = v[j] = true;
0052       }
0053     selected_.clear();
0054     for (unsigned int i = 0; i < s; ++i)
0055       if (v[i])
0056         addRef_(selected_, c, i);
0057   }
0058 
0059 private:
0060   Selector select_;
0061   StoreContainer selected_;
0062   RefAdder addRef_;
0063 };
0064 
0065 #endif