CMS 3D CMS Logo

TrackFromParentImporter.h
Go to the documentation of this file.
1 #ifndef __TrackFromParentImporter_H__
2 #define __TrackFromParentImporter_H__
3 
8 
9 namespace pflow {
10  namespace noop {
11  // this adaptor class gets redefined later to match the
12  // needs of the collection and importing cuts we are using
13  template <class Collection>
15  public:
16  static bool check_importable(const typename Collection::value_type&) { return true; }
17  static const std::vector<reco::PFRecTrackRef>& get_track_refs(const typename Collection::value_type&) {
18  return _empty;
19  }
21  static const std::vector<reco::PFRecTrackRef> _empty;
22  };
23  } // namespace noop
24  namespace importers {
25  template <class Collection, class Adaptor = noop::ParentCollectionAdaptor<Collection> >
27  public:
29  : BlockElementImporterBase(conf, sumes),
30  _src(sumes.consumes<Collection>(conf.getParameter<edm::InputTag>("source"))) {}
31 
32  void importToBlock(const edm::Event&, ElementList&) const override;
33 
34  private:
36  };
37 
38  template <class Collection, class Adaptor>
40  const edm::Event& e, BlockElementImporterBase::ElementList& elems) const {
42  auto pfparents = e.getHandle(_src);
43  elems.reserve(elems.size() + 2 * pfparents->size());
44  // setup our elements so that all the SCs are grouped together
45  auto TKs_end = std::partition(
46  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
47  // insert tracks into the element list, updating tracks that exist already
48  auto bpar = pfparents->cbegin();
49  auto epar = pfparents->cend();
50  edm::Ref<Collection> parentRef;
51  reco::PFBlockElement* trkElem = nullptr;
52  for (auto pfparent = bpar; pfparent != epar; ++pfparent) {
53  if (Adaptor::check_importable(*pfparent)) {
54  parentRef = edm::Ref<Collection>(pfparents, std::distance(bpar, pfparent));
55  const auto& pftracks = Adaptor::get_track_refs(*pfparent);
56  for (const auto& pftrack : pftracks) {
57  auto tk_elem = std::find_if(
58  elems.begin(), TKs_end, [&](const ElementType& a) { return (a->trackRef() == pftrack->trackRef()); });
59  if (tk_elem != TKs_end) { // if found flag the track, otherwise import
60  Adaptor::set_element_info(tk_elem->get(), parentRef);
61  } else {
62  trkElem = new reco::PFBlockElementTrack(pftrack);
63  Adaptor::set_element_info(trkElem, parentRef);
64  TKs_end = elems.insert(TKs_end, ElementType(trkElem));
65  ++TKs_end;
66  }
67  }
68  }
69  } // loop on tracking coming from common parent
70  elems.shrink_to_fit();
71  }
72  } // namespace importers
73 } // namespace pflow
74 #endif
static bool check_importable(const typename Collection::value_type &)
Abstract base class for a PFBlock element (track, cluster...)
static void set_element_info(reco::PFBlockElement *, const typename edm::Ref< Collection > &)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:547
static const std::vector< reco::PFRecTrackRef > & get_track_refs(const typename Collection::value_type &)
static const std::vector< reco::PFRecTrackRef > _empty
HLT enums.
TrackFromParentImporter(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
double a
Definition: hdecay.h:119
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList