CMS 3D CMS Logo

GeneralTracksImporter.cc
Go to the documentation of this file.
11 
13 public:
15  : BlockElementImporterBase(conf, sumes),
16  src_(sumes.consumes<reco::PFRecTrackCollection>(conf.getParameter<edm::InputTag>("source"))),
17  vetoEndcap_(conf.getParameter<bool>("vetoEndcap")),
18  muons_(sumes.consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
19  trackQuality_(reco::TrackBase::qualityByName(conf.getParameter<std::string>("trackQuality"))),
20  DPtovPtCut_(conf.getParameter<std::vector<double>>("DPtOverPtCuts_byTrackAlgo")),
21  NHitCut_(conf.getParameter<std::vector<unsigned>>("NHitCuts_byTrackAlgo")),
22  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
23  cleanBadConvBrems_(conf.getParameter<bool>("cleanBadConvertedBrems")),
24  muonMaxDPtOPt_(conf.getParameter<double>("muonMaxDPtOPt")) {
25  if (vetoEndcap_) {
26  vetoMode_ = conf.getParameter<unsigned>("vetoMode");
27  switch (vetoMode_) {
30  break;
31  case ticlSeedingRegion:
33  sumes.consumes<std::vector<TICLSeedingRegion>>(conf.getParameter<edm::InputTag>("vetoSrc"));
35  break;
39  break;
40  } // switch
41  }
42  }
43 
44  void importToBlock(const edm::Event&, ElementList&) const override;
45 
46 private:
48  const bool vetoEndcap_;
51  const std::vector<double> DPtovPtCut_;
52  const std::vector<unsigned> NHitCut_;
54  const double muonMaxDPtOPt_;
55  unsigned int vetoMode_;
60 };
61 
63 
66  auto tracks = e.getHandle(src_);
67 
68  typedef std::pair<edm::ProductID, unsigned> TrackProdIDKey;
69  std::vector<TrackProdIDKey> vetoed;
70  if (vetoEndcap_) {
71  switch (vetoMode_) {
72  case pfRecTrackCollection: {
73  const auto& vetoes = e.get(vetoPFTracksSrc_);
74  for (const auto& veto : vetoes)
75  vetoed.emplace_back(veto.trackRef().id(), veto.trackRef().key());
76  break;
77  }
78  case ticlSeedingRegion: {
79  const auto& vetoes = e.get(vetoTICLSeedingSrc_);
80  auto tracksH = e.getHandle(tracksSrc_);
81  for (const auto& veto : vetoes) {
82  assert(veto.collectionID == tracksH.id());
83  reco::TrackRef trkref = reco::TrackRef(tracksH, veto.index);
84  vetoed.emplace_back(tracksH.id(), veto.index); // track prod id and key
85  }
86  break;
87  }
88  case pfCandidateCollection: {
89  const auto& vetoes = e.get(vetoPFCandidatesSrc_);
90  for (const auto& veto : vetoes) {
91  if (veto.trackRef().isNull())
92  continue;
93  vetoed.emplace_back(veto.trackRef().id(), veto.trackRef().key());
94  }
95  break;
96  }
97  } // switch
98  std::sort(vetoed.begin(), vetoed.end());
99  }
100  const auto muonH = e.getHandle(muons_);
101  const auto muons = *muonH;
102  elems.reserve(elems.size() + tracks->size());
103  std::vector<bool> mask(tracks->size(), true);
104  reco::MuonRef muonref;
105 
106  // remove converted brems with bad pT resolution if requested
107  // this reproduces the old behavior of PFBlockAlgo
108  if (cleanBadConvBrems_) {
109  auto itr = elems.begin();
110  while (itr != elems.end()) {
111  if ((*itr)->type() == reco::PFBlockElement::TRACK) {
112  const reco::PFBlockElementTrack* trkel = static_cast<reco::PFBlockElementTrack*>(itr->get());
113  const reco::ConversionRefVector& cRef = trkel->convRefs();
115  const reco::VertexCompositeCandidateRef& v0Ref = trkel->V0Ref();
116  // if there is no displaced vertex reference and it is marked
117  // as a conversion it's gotta be a converted brem
118  if (trkel->trackType(reco::PFBlockElement::T_FROM_GAMMACONV) && cRef.empty() && dvRef.isNull() &&
119  v0Ref.isNull()) {
120  // if the Pt resolution is bad we kill this element
123  itr = elems.erase(itr);
124  continue;
125  }
126  }
127  }
128  ++itr;
129  } // loop on existing elements
130  }
131  // preprocess existing tracks in the element list and create a mask
132  // so that we do not import tracks twice, tag muons we find
133  // in this collection
134  auto TKs_end = std::partition(
135  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
136  auto btk_elems = elems.begin();
137  auto btrack = tracks->cbegin();
138  auto etrack = tracks->cend();
139  for (auto track = btrack; track != etrack; ++track) {
140  auto tk_elem =
141  std::find_if(btk_elems, TKs_end, [&](const ElementType& a) { return (a->trackRef() == track->trackRef()); });
142  if (tk_elem != TKs_end) {
143  mask[std::distance(tracks->cbegin(), track)] = false;
144  // check and update if this track is a muon
145  const int muId = PFMuonAlgo::muAssocToTrack((*tk_elem)->trackRef(), muons);
146  if (muId != -1) {
147  muonref = reco::MuonRef(muonH, muId);
148  if (PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref)) {
149  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
150  }
151  }
152  }
153  }
154  // now we actually insert tracks, again tagging muons along the way
155  reco::PFRecTrackRef pftrackref;
156  reco::PFBlockElementTrack* trkElem = nullptr;
157  for (auto track = btrack; track != etrack; ++track) {
158  const unsigned idx = std::distance(btrack, track);
159  // since we already set muon refs in the previously imported tracks,
160  // here we can skip everything that is already imported
161  if (!mask[idx])
162  continue;
163  muonref = reco::MuonRef();
164  pftrackref = reco::PFRecTrackRef(tracks, idx);
165  // Get the eventual muon associated to this track
166  const int muId = PFMuonAlgo::muAssocToTrack(pftrackref->trackRef(), muons);
167  bool thisIsAPotentialMuon = false;
168  if (muId != -1) {
169  muonref = reco::MuonRef(muonH, muId);
170  thisIsAPotentialMuon =
171  ((PFMuonAlgo::hasValidTrack(muonref, true, muonMaxDPtOPt_) && PFMuonAlgo::isLooseMuon(muonref)) ||
172  (PFMuonAlgo::hasValidTrack(muonref, false, muonMaxDPtOPt_) && PFMuonAlgo::isMuon(muonref)));
173  }
174  if (thisIsAPotentialMuon || PFTrackAlgoTools::goodPtResolution(
175  pftrackref->trackRef(), DPtovPtCut_, NHitCut_, useIterTracking_, trackQuality_)) {
176  trkElem = new reco::PFBlockElementTrack(pftrackref);
177  if (thisIsAPotentialMuon) {
178  LogDebug("GeneralTracksImporter")
179  << "Potential Muon P " << pftrackref->trackRef()->p() << " pt " << pftrackref->trackRef()->p() << std::endl;
180  }
181  if (muId != -1)
182  trkElem->setMuonRef(muonref);
183  //
184  // if _vetoEndcap is false, add this trk automatically.
185  // if _vetoEndcap is true, veto against the hgcal region tracks or charged PF candidates.
186  // when simPF is used, we don't veto tracks with muonref even if they are in the hgcal region.
187  //
188  if (!vetoEndcap_)
189  elems.emplace_back(trkElem);
190  else {
191  TrackProdIDKey trk = std::make_pair(pftrackref->trackRef().id(), pftrackref->trackRef().key());
192  auto lower = std::lower_bound(vetoed.begin(), vetoed.end(), trk);
193  bool inVetoList = (lower != vetoed.end() && *lower == trk);
194  if (!inVetoList || (vetoMode_ == pfRecTrackCollection && muonref.isNonnull())) {
195  elems.emplace_back(trkElem);
196  } else
197  delete trkElem;
198  }
199  }
200  }
201  elems.shrink_to_fit();
202 }
reco::PFBlockElementTrack::trackType
bool trackType(TrackType trType) const override
Definition: PFBlockElementTrack.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
electrons_cff.bool
bool
Definition: electrons_cff.py:366
GeneralTracksImporter::NHitCut_
const std::vector< unsigned > NHitCut_
Definition: GeneralTracksImporter.cc:52
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
Muon.h
MessageLogger.h
PFMuonAlgo.h
reco::PFBlockElementTrack::V0Ref
const VertexCompositeCandidateRef & V0Ref() const override
Definition: PFBlockElementTrack.h:104
edm::EDGetTokenT< reco::PFRecTrackCollection >
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
GeneralTracksImporter::muons_
const edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: GeneralTracksImporter.cc:49
GeneralTracksImporter::tracksSrc_
edm::EDGetTokenT< reco::TrackCollection > tracksSrc_
Definition: GeneralTracksImporter.cc:58
reco::PFBlockElementTrack::trackRef
const reco::TrackRef & trackRef() const override
Definition: PFBlockElementTrack.h:49
cms::cuda::assert
assert(be >=bs)
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
GeneralTracksImporter::vetoTICLSeedingSrc_
edm::EDGetTokenT< std::vector< TICLSeedingRegion > > vetoTICLSeedingSrc_
Definition: GeneralTracksImporter.cc:57
GeneralTracksImporter::cleanBadConvBrems_
const bool cleanBadConvBrems_
Definition: GeneralTracksImporter.cc:53
GeneralTracksImporter::useIterTracking_
const bool useIterTracking_
Definition: GeneralTracksImporter.cc:53
BlockElementImporterBase::ticlSeedingRegion
Definition: BlockElementImporterBase.h:29
edm::RefVector< ConversionCollection >
GeneralTracksImporter::vetoMode_
unsigned int vetoMode_
Definition: GeneralTracksImporter.cc:55
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
GeneralTracksImporter::vetoEndcap_
const bool vetoEndcap_
Definition: GeneralTracksImporter.cc:48
GeneralTracksImporter::src_
const edm::EDGetTokenT< reco::PFRecTrackCollection > src_
Definition: GeneralTracksImporter.cc:47
edm::Ref< TrackCollection >
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
reco::PFBlockElementTrack::displacedVertexRef
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const override
Definition: PFBlockElementTrack.h:65
Track.h
BlockElementImporterBase.h
reco::PFBlockElementTrack::setMuonRef
void setMuonRef(const MuonRef &muref) override
\set reference to the Muon
Definition: PFBlockElementTrack.h:89
reco::PFBlockElement::TRACK
Definition: PFBlockElement.h:32
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
reco::MuonRef
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
GeneralTracksImporter::vetoPFCandidatesSrc_
edm::EDGetTokenT< reco::PFCandidateCollection > vetoPFCandidatesSrc_
Definition: GeneralTracksImporter.cc:59
BlockElementImporterBase::pfRecTrackCollection
Definition: BlockElementImporterBase.h:29
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
reco::PFRecTrackRef
edm::Ref< PFRecTrackCollection > PFRecTrackRef
persistent reference to PFRecTrack objects
Definition: PFRecTrackFwd.h:15
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BlockElementImporterBase::ElementList
std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
Definition: BlockElementImporterBase.h:16
reco::PFBlockElement::T_FROM_DISP
Definition: PFBlockElement.h:47
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
PFTrackAlgoTools.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
GeneralTracksImporter::GeneralTracksImporter
GeneralTracksImporter(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
Definition: GeneralTracksImporter.cc:14
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
edmplugin::PluginFactory
Definition: PluginFactory.h:34
PFMuonAlgo::hasValidTrack
static bool hasValidTrack(const reco::MuonRef &muonRef, bool loose, double maxDPtOPt)
Definition: PFMuonAlgo.cc:348
GeneralTracksImporter::vetoPFTracksSrc_
edm::EDGetTokenT< reco::PFRecTrackCollection > vetoPFTracksSrc_
Definition: GeneralTracksImporter.cc:56
reco::PFBlockElement::T_FROM_GAMMACONV
Definition: PFBlockElement.h:47
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
GeneralTracksImporter::DPtovPtCut_
const std::vector< double > DPtovPtCut_
Definition: GeneralTracksImporter.cc:51
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
GeneralTracksImporter::muonMaxDPtOPt_
const double muonMaxDPtOPt_
Definition: GeneralTracksImporter.cc:54
PFTrackAlgoTools::goodPtResolution
bool goodPtResolution(const reco::TrackRef &, const std::vector< double > &DPtovPtCut, const std::vector< unsigned > &NHitCut, bool useIterTracking, const reco::TrackBase::TrackQuality trackQuality)
Definition: PFTrackAlgoTools.cc:236
PFRecTrack.h
ValueMap.h
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
TICLSeedingRegion.h
std
Definition: JetResolutionObject.h:76
GeneralTracksImporter::trackQuality_
const reco::TrackBase::TrackQuality trackQuality_
Definition: GeneralTracksImporter.cc:50
PFMuonAlgo::isMuon
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:48
PFMuonAlgo::muAssocToTrack
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
Definition: PFMuonAlgo.cc:479
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::PFRecTrackCollection
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
GeneralTracksImporter::importToBlock
void importToBlock(const edm::Event &, ElementList &) const override
Definition: GeneralTracksImporter.cc:64
GeneralTracksImporter
Definition: GeneralTracksImporter.cc:12
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
PFMuonAlgo::isLooseMuon
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:57
reco::PFBlockElementTrack::convRefs
const ConversionRefVector & convRefs() const override
Definition: PFBlockElementTrack.h:95
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
BlockElementImporterBase
Definition: BlockElementImporterBase.h:14