CMS 3D CMS Logo

TrackFromParentImporter.h
Go to the documentation of this file.
1 #ifndef __TrackFromParentImporter_H__
2 #define __TrackFromParentImporter_H__
3 
9 
10 namespace pflow {
11  namespace noop {
12  // this adaptor class gets redefined later to match the
13  // needs of the collection and importing cuts we are using
14  template <class Collection>
16  public:
17  static bool check_importable(const typename Collection::value_type&) { return true; }
18  static const std::vector<reco::PFRecTrackRef>& get_track_refs(const typename Collection::value_type&) {
19  return empty_;
20  }
22  static const std::vector<reco::PFRecTrackRef> empty_;
23  };
24  } // namespace noop
25  namespace importers {
26  template <class Collection, class Adaptor = noop::ParentCollectionAdaptor<Collection>>
28  public:
30  : BlockElementImporterBase(conf, sumes),
31  src_(sumes.consumes<Collection>(conf.getParameter<edm::InputTag>("source"))),
32  vetoEndcap_(conf.getParameter<bool>("vetoEndcap")) {
33  if (vetoEndcap_) {
34  vetoMode_ = conf.getParameter<unsigned>("vetoMode");
35  switch (vetoMode_) {
39  break;
40  case ticlSeedingRegion:
42  sumes.consumes<std::vector<TICLSeedingRegion>>(conf.getParameter<edm::InputTag>("vetoSrc"));
44  break;
48  break;
49  } // switch
50  } // vetoEndcap_
51  }
52 
53  void importToBlock(const edm::Event&, ElementList&) const override;
54 
55  private:
58  const bool vetoEndcap_;
59  unsigned int vetoMode_;
64  };
65 
66  template <class Collection, class Adaptor>
68  const edm::Event& e, BlockElementImporterBase::ElementList& elems) const {
70  auto pfparents = e.getHandle(src_);
71  //
72  // Store tracks to be vetoed
73  typedef std::pair<edm::ProductID, unsigned> TrackProdIDKey;
74  std::vector<TrackProdIDKey> vetoed;
75  edm::ProductID prodIdForVeto;
76  if (vetoEndcap_) {
77  switch (vetoMode_) {
78  case pfRecTrackCollection: {
79  const auto& vetoes = e.get(vetoPFTracksSrc_);
80  for (const auto& veto : vetoes) {
81  vetoed.emplace_back(veto.trackRef().id(), veto.trackRef().key());
82  }
83  break;
84  }
85  case ticlSeedingRegion: {
86  const auto& vetoes = e.get(vetoTICLSeedingSrc_);
87  auto tracksH = e.getHandle(tracksSrc_);
88  for (const auto& veto : vetoes) {
89  assert(veto.collectionID == tracksH.id());
90  vetoed.emplace_back(tracksH.id(), veto.index); // track prod id and key
91  }
92  break;
93  }
94  case pfCandidateCollection: {
95  const auto& vetoes = e.get(vetoPFCandidatesSrc_);
96  for (const auto& veto : vetoes) {
97  if (veto.trackRef().isNull())
98  continue;
99  vetoed.emplace_back(veto.trackRef().id(), veto.trackRef().key());
100  }
101  break;
102  }
103  } // switch
104  std::sort(vetoed.begin(), vetoed.end());
105  }
106  //
107  elems.reserve(elems.size() + 2 * pfparents->size());
108  //
109  auto TKs_end = std::partition(
110  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
111  // insert tracks into the element list, updating tracks that exist already
112  auto bpar = pfparents->cbegin();
113  auto epar = pfparents->cend();
114  edm::Ref<Collection> parentRef;
115  reco::PFBlockElement* trkElem = nullptr;
116  for (auto pfparent = bpar; pfparent != epar; ++pfparent) {
117  if (Adaptor::check_importable(*pfparent)) {
118  parentRef = edm::Ref<Collection>(pfparents, std::distance(bpar, pfparent));
119  const auto& pftracks = Adaptor::get_track_refs(*pfparent);
120  for (const auto& pftrack : pftracks) {
121  if (vetoEndcap_) { // vetoEndcap flag
122  TrackProdIDKey trk = std::make_pair(pftrack->trackRef().id(), pftrack->trackRef().key());
123  auto lower = std::lower_bound(vetoed.begin(), vetoed.end(), trk);
124  bool inVetoList = (lower != vetoed.end() && *lower == trk);
125  if (inVetoList)
126  continue; // found a track in a veto list
127  }
128  //
129  // Now try to update an entry in pfblock or import
130  auto tk_elem = std::find_if(
131  elems.begin(), TKs_end, [&](const ElementType& a) { return (a->trackRef() == pftrack->trackRef()); });
132  if (tk_elem != TKs_end) { // if found flag the track, otherwise import
133  Adaptor::set_element_info(tk_elem->get(), parentRef);
134  } else {
135  trkElem = new reco::PFBlockElementTrack(pftrack);
136  Adaptor::set_element_info(trkElem, parentRef);
137  TKs_end = elems.insert(TKs_end, ElementType(trkElem));
138  ++TKs_end;
139  }
140  } // daughter track loop ends
141  } // end of importable check
142  } // loop on tracking coming from common parent
143  elems.shrink_to_fit();
144  } // end of importToBlock
145  } // namespace importers
146 } // namespace pflow
147 #endif
HLT_FULL_cff.pfCandidateCollection
pfCandidateCollection
Definition: HLT_FULL_cff.py:125438
pflow::importers::TrackFromParentImporter
Definition: TrackFromParentImporter.h:27
electrons_cff.bool
bool
Definition: electrons_cff.py:366
pflow::noop::ParentCollectionAdaptor::empty_
static const std::vector< reco::PFRecTrackRef > empty_
Definition: TrackFromParentImporter.h:22
PFCandidate.h
edm::EDGetTokenT< Collection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
cms::cuda::assert
assert(be >=bs)
pflow::importers::TrackFromParentImporter::srcTag_
edm::InputTag srcTag_
Definition: TrackFromParentImporter.h:57
BlockElementImporterBase::ticlSeedingRegion
Definition: BlockElementImporterBase.h:29
pflow::noop::ParentCollectionAdaptor::set_element_info
static void set_element_info(reco::PFBlockElement *, const typename edm::Ref< Collection > &)
Definition: TrackFromParentImporter.h:21
pflow::importers::TrackFromParentImporter::vetoEndcap_
const bool vetoEndcap_
Definition: TrackFromParentImporter.h:58
edm::Ref
Definition: AssociativeIterator.h:58
pflow::noop::ParentCollectionAdaptor
Definition: TrackFromParentImporter.h:15
pflow::importers::TrackFromParentImporter::src_
edm::EDGetTokenT< Collection > src_
Definition: TrackFromParentImporter.h:56
BlockElementImporterBase.h
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:18
BlockElementImporterBase::pfRecTrackCollection
Definition: BlockElementImporterBase.h:29
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
BlockElementImporterBase::ElementList
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
Definition: BlockElementImporterBase.h:16
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
pflow::importers::TrackFromParentImporter::vetoMode_
unsigned int vetoMode_
Definition: TrackFromParentImporter.h:59
pflow
Definition: TrackFromParentImporter.h:10
pflow::importers::TrackFromParentImporter::vetoPFCandidatesSrc_
edm::EDGetTokenT< reco::PFCandidateCollection > vetoPFCandidatesSrc_
Definition: TrackFromParentImporter.h:63
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:29
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:67
TICLSeedingRegion.h
pflow::importers::TrackFromParentImporter::tracksSrc_
edm::EDGetTokenT< reco::TrackCollection > tracksSrc_
Definition: TrackFromParentImporter.h:62
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
pflow::importers::TrackFromParentImporter::vetoTICLSeedingSrc_
edm::EDGetTokenT< std::vector< TICLSeedingRegion > > vetoTICLSeedingSrc_
Definition: TrackFromParentImporter.h:61
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
pflow::importers::TrackFromParentImporter::vetoPFTracksSrc_
edm::EDGetTokenT< reco::PFRecTrackCollection > vetoPFTracksSrc_
Definition: TrackFromParentImporter.h:60
pflow::noop::ParentCollectionAdaptor::check_importable
static bool check_importable(const typename Collection::value_type &)
Definition: TrackFromParentImporter.h:17
reco::PFRecTrackCollection
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
PbPb_ZMuSkimMuonDPG_cff.veto
veto
Definition: PbPb_ZMuSkimMuonDPG_cff.py:61
edm::InputTag
Definition: InputTag.h:15
BlockElementImporterBase::pfCandidateCollection
Definition: BlockElementImporterBase.h:29
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PFBlockElementTrack.h
edm::ProductID
Definition: ProductID.h:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
BlockElementImporterBase
Definition: BlockElementImporterBase.h:14