CMS 3D CMS Logo

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