ObjectPairCollectionSelector

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#ifndef RecoAlgos_ObjectPairCollectionSelector_h
#define RecoAlgos_ObjectPairCollectionSelector_h
/** \class ObjectPairCollectionSelector
 *
 * selects object pairs wose combination satiefies a specific selection
 * for instance, could be based on invariant mass, deltaR , deltaPhi, etc.
 *
 * \author Luca Lista, INFN
 *
 * \version $Revision: 1.1 $
 *
 * $Id: ObjectPairCollectionSelector.h,v 1.1 2009/03/03 13:07:27 llista Exp $
 *
 */

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
#include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
#include <vector>

namespace edm {
  class Event;
}

template <typename InputCollection,
          typename Selector,
          typename StoreContainer = std::vector<const typename InputCollection::value_type *>,
          typename RefAdder = typename helper::SelectionAdderTrait<InputCollection, StoreContainer>::type>
class ObjectPairCollectionSelector {
public:
  typedef InputCollection collection;

private:
  typedef const typename InputCollection::value_type *reference;
  typedef StoreContainer container;
  typedef typename container::const_iterator const_iterator;

public:
  ObjectPairCollectionSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
      : select_(reco::modules::make<Selector>(cfg)) {}
  const_iterator begin() const { return selected_.begin(); }
  const_iterator end() const { return selected_.end(); }
  void select(const edm::Handle<InputCollection> &c, const edm::Event &, const edm::EventSetup &) {
    unsigned int s = c->size();
    std::vector<bool> v(s, false);
    for (unsigned int i = 0; i < s; ++i)
      for (unsigned int j = i + 1; j < s; ++j) {
        if (select_((*c)[i], (*c)[j]))
          v[i] = v[j] = true;
      }
    selected_.clear();
    for (unsigned int i = 0; i < s; ++i)
      if (v[i])
        addRef_(selected_, c, i);
  }

  static void fillPSetDescription(edm::ParameterSetDescription &desc) {
    // Use ParameterAdapter to fill the descriptions
    reco::modules::ParameterAdapter<Selector>::fillPSetDescription(desc);
  }

private:
  Selector select_;
  StoreContainer selected_;
  RefAdder addRef_;
};

#endif