CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
GeneralTracksImporter Class Reference
Inheritance diagram for GeneralTracksImporter:
BlockElementImporterBase

Public Member Functions

 GeneralTracksImporter (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
void importToBlock (const edm::Event &, ElementList &) const override
 
- Public Member Functions inherited from BlockElementImporterBase
 BlockElementImporterBase (const BlockElementImporterBase &)=delete
 
 BlockElementImporterBase (const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
 
const std::string & name () const
 
BlockElementImporterBaseoperator= (const BlockElementImporterBase &)=delete
 
virtual void updateEventSetup (const edm::EventSetup &)
 
virtual ~BlockElementImporterBase ()=default
 

Private Attributes

const bool cleanBadConvBrems_
 
const std::vector< double > DPtovPtCut_
 
const double muonMaxDPtOPt_
 
const edm::EDGetTokenT< reco::MuonCollectionmuons_
 
const std::vector< unsigned > NHitCut_
 
const edm::EDGetTokenT< reco::PFRecTrackCollectionsrc_
 
const reco::TrackBase::TrackQuality trackQuality_
 
edm::EDGetTokenT< reco::TrackCollectiontracksSrc_
 
const bool useIterTracking_
 
const bool vetoEndcap_
 
unsigned int vetoMode_
 
edm::EDGetTokenT< reco::PFCandidateCollectionvetoPFCandidatesSrc_
 
edm::EDGetTokenT< reco::PFRecTrackCollectionvetoPFTracksSrc_
 
edm::EDGetTokenT< std::vector< TICLSeedingRegion > > vetoTICLSeedingSrc_
 

Additional Inherited Members

- Public Types inherited from BlockElementImporterBase
typedef std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
 
enum  VetoMode { pfRecTrackCollection = 0, ticlSeedingRegion = 1, pfCandidateCollection = 2 }
 

Detailed Description

Definition at line 12 of file GeneralTracksImporter.cc.

Constructor & Destructor Documentation

◆ GeneralTracksImporter()

GeneralTracksImporter::GeneralTracksImporter ( const edm::ParameterSet conf,
edm::ConsumesCollector sumes 
)
inline

Definition at line 14 of file GeneralTracksImporter.cc.

15  : BlockElementImporterBase(conf, sumes),
17  vetoEndcap_(conf.getParameter<bool>("vetoEndcap")),
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  }

References edm::ConsumesCollector::consumes(), edm::ParameterSet::getParameter(), BlockElementImporterBase::pfCandidateCollection, BlockElementImporterBase::pfRecTrackCollection, BlockElementImporterBase::ticlSeedingRegion, tracksSrc_, vetoEndcap_, vetoMode_, vetoPFCandidatesSrc_, vetoPFTracksSrc_, and vetoTICLSeedingSrc_.

Member Function Documentation

◆ importToBlock()

void GeneralTracksImporter::importToBlock ( const edm::Event e,
BlockElementImporterBase::ElementList elems 
) const
overridevirtual

Implements BlockElementImporterBase.

Definition at line 64 of file GeneralTracksImporter.cc.

64  {
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 }

References a, cms::cuda::assert(), cleanBadConvBrems_, reco::PFBlockElementTrack::convRefs(), reco::PFBlockElementTrack::displacedVertexRef(), HLT_FULL_cff::distance, DPtovPtCut_, MillePedeFileConverter_cfg::e, PFTrackAlgoTools::goodPtResolution(), PFMuonAlgo::hasValidTrack(), edm::Ref< C, T, F >::id(), heavyIonCSV_trainingSettings::idx, PFMuonAlgo::isLooseMuon(), PFMuonAlgo::isMuon(), edm::Ref< C, T, F >::isNull(), edm::Ref< C, T, F >::key(), LogDebug, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, PFMuonAlgo::muAssocToTrack(), muonMaxDPtOPt_, PDWG_BPHSkim_cff::muons, muons_, NHitCut_, BlockElementImporterBase::pfCandidateCollection, BlockElementImporterBase::pfRecTrackCollection, reco::PFBlockElementTrack::setMuonRef(), jetUpdater_cfi::sort, src_, reco::PFBlockElement::T_FROM_DISP, reco::PFBlockElement::T_FROM_GAMMACONV, BlockElementImporterBase::ticlSeedingRegion, reco::PFBlockElement::TRACK, HLT_FULL_cff::track, trackQuality_, reco::PFBlockElementTrack::trackRef(), tracks, tracksSrc_, reco::PFBlockElementTrack::trackType(), useIterTracking_, reco::PFBlockElementTrack::V0Ref(), PbPb_ZMuSkimMuonDPG_cff::veto, vetoEndcap_, vetoMode_, vetoPFCandidatesSrc_, vetoPFTracksSrc_, and vetoTICLSeedingSrc_.

Member Data Documentation

◆ cleanBadConvBrems_

const bool GeneralTracksImporter::cleanBadConvBrems_
private

Definition at line 53 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ DPtovPtCut_

const std::vector<double> GeneralTracksImporter::DPtovPtCut_
private

Definition at line 51 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ muonMaxDPtOPt_

const double GeneralTracksImporter::muonMaxDPtOPt_
private

Definition at line 54 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ muons_

const edm::EDGetTokenT<reco::MuonCollection> GeneralTracksImporter::muons_
private

Definition at line 49 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ NHitCut_

const std::vector<unsigned> GeneralTracksImporter::NHitCut_
private

Definition at line 52 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ src_

const edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporter::src_
private

Definition at line 47 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ trackQuality_

const reco::TrackBase::TrackQuality GeneralTracksImporter::trackQuality_
private

Definition at line 50 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ tracksSrc_

edm::EDGetTokenT<reco::TrackCollection> GeneralTracksImporter::tracksSrc_
private

Definition at line 58 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

◆ useIterTracking_

const bool GeneralTracksImporter::useIterTracking_
private

Definition at line 53 of file GeneralTracksImporter.cc.

Referenced by importToBlock().

◆ vetoEndcap_

const bool GeneralTracksImporter::vetoEndcap_
private

Definition at line 48 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

◆ vetoMode_

unsigned int GeneralTracksImporter::vetoMode_
private

Definition at line 55 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

◆ vetoPFCandidatesSrc_

edm::EDGetTokenT<reco::PFCandidateCollection> GeneralTracksImporter::vetoPFCandidatesSrc_
private

Definition at line 59 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

◆ vetoPFTracksSrc_

edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporter::vetoPFTracksSrc_
private

Definition at line 56 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

◆ vetoTICLSeedingSrc_

edm::EDGetTokenT<std::vector<TICLSeedingRegion> > GeneralTracksImporter::vetoTICLSeedingSrc_
private

Definition at line 57 of file GeneralTracksImporter.cc.

Referenced by GeneralTracksImporter(), and importToBlock().

reco::PFBlockElementTrack::trackType
bool trackType(TrackType trType) const override
Definition: PFBlockElementTrack.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
GeneralTracksImporter::NHitCut_
const std::vector< unsigned > NHitCut_
Definition: GeneralTracksImporter.cc:52
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
reco::PFBlockElementTrack::V0Ref
const VertexCompositeCandidateRef & V0Ref() const override
Definition: PFBlockElementTrack.h:104
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
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)
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
GeneralTracksImporter::vetoEndcap_
const bool vetoEndcap_
Definition: GeneralTracksImporter.cc:48
GeneralTracksImporter::src_
const edm::EDGetTokenT< reco::PFRecTrackCollection > src_
Definition: GeneralTracksImporter.cc:47
BlockElementImporterBase::BlockElementImporterBase
BlockElementImporterBase(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
Definition: BlockElementImporterBase.h:17
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
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
reco::TrackRef
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::PFBlockElement::T_FROM_DISP
Definition: PFBlockElement.h:47
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
a
double a
Definition: hdecay.h:119
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:159
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
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
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
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
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
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
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