CMS 3D CMS Logo

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

Public Member Functions

 GeneralTracksImporterWithVeto (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 Member Functions

int muAssocToTrack (const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
 

Private Attributes

const bool cleanBadConvBrems_
 
const std::vector< double > DPtovPtCut_
 
edm::EDGetTokenT< reco::MuonCollectionmuons_
 
const std::vector< unsigned > NHitCut_
 
std::unique_ptr< PFMuonAlgopfmu_
 
edm::EDGetTokenT< reco::PFRecTrackCollectionsrc_
 
const reco::TrackBase::TrackQuality trackQuality_
 
const bool useIterTracking_
 
edm::EDGetTokenT< reco::PFRecTrackCollectionveto_
 

Additional Inherited Members

- Public Types inherited from BlockElementImporterBase
typedef std::vector< std::unique_ptr< reco::PFBlockElement > > ElementList
 

Detailed Description

Definition at line 11 of file GeneralTracksImporterWithVeto.cc.

Constructor & Destructor Documentation

◆ GeneralTracksImporterWithVeto()

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

Definition at line 13 of file GeneralTracksImporterWithVeto.cc.

14  : BlockElementImporterBase(conf, sumes),
18  trackQuality_((conf.existsAs<std::string>("trackQuality"))
21  DPtovPtCut_(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
22  NHitCut_(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
23  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
25  conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false) {
26  bool postMuonCleaning =
27  conf.existsAs<bool>("postMuonCleaning") ? conf.getParameter<bool>("postMuonCleaning") : false;
28  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo(conf, postMuonCleaning));
29  }

References edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), pfmu_, and HLT_2018_cff::postMuonCleaning.

Member Function Documentation

◆ importToBlock()

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

Implements BlockElementImporterBase.

Definition at line 48 of file GeneralTracksImporterWithVeto.cc.

49  {
51  auto tracks = e.getHandle(src_);
52  auto vetosH = e.getHandle(veto_);
53  const auto& vetos = *vetosH;
54  std::unordered_set<unsigned> vetoed;
55  for (unsigned i = 0; i < vetos.size(); ++i) {
56  vetoed.insert(vetos[i].trackRef().key());
57  }
58  auto muons = e.getHandle(muons_);
59  elems.reserve(elems.size() + tracks->size());
60  std::vector<bool> mask(tracks->size(), true);
61  reco::MuonRef muonref;
62 
63  // remove converted brems with bad pT resolution if requested
64  // this reproduces the old behavior of PFBlockAlgo
65  if (cleanBadConvBrems_) {
66  auto itr = elems.begin();
67  while (itr != elems.end()) {
68  if ((*itr)->type() == reco::PFBlockElement::TRACK) {
69  const reco::PFBlockElementTrack* trkel = static_cast<reco::PFBlockElementTrack*>(itr->get());
70  const reco::ConversionRefVector& cRef = trkel->convRefs();
72  const reco::VertexCompositeCandidateRef& v0Ref = trkel->V0Ref();
73  // if there is no displaced vertex reference and it is marked
74  // as a conversion it's gotta be a converted brem
75  if (trkel->trackType(reco::PFBlockElement::T_FROM_GAMMACONV) && cRef.empty() && dvRef.isNull() &&
76  v0Ref.isNull()) {
77  // if the Pt resolution is bad we kill this element
80  itr = elems.erase(itr);
81  continue;
82  }
83  }
84  }
85  ++itr;
86  } // loop on existing elements
87  }
88  // preprocess existing tracks in the element list and create a mask
89  // so that we do not import tracks twice, tag muons we find
90  // in this collection
91  auto TKs_end = std::partition(
92  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
93  auto btk_elems = elems.begin();
94  auto btrack = tracks->cbegin();
95  auto etrack = tracks->cend();
96  for (auto track = btrack; track != etrack; ++track) {
97  auto tk_elem =
98  std::find_if(btk_elems, TKs_end, [&](const ElementType& a) { return (a->trackRef() == track->trackRef()); });
99  if (tk_elem != TKs_end) {
100  mask[std::distance(tracks->cbegin(), track)] = false;
101  // check and update if this track is a muon
102  const int muId = muAssocToTrack((*tk_elem)->trackRef(), muons);
103  if (muId != -1) {
104  muonref = reco::MuonRef(muons, muId);
105  if (PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref)) {
106  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
107  }
108  }
109  }
110  }
111  // now we actually insert tracks, again tagging muons along the way
112  reco::PFRecTrackRef pftrackref;
113  reco::PFBlockElementTrack* trkElem = nullptr;
114  for (auto track = btrack; track != etrack; ++track) {
115  const unsigned idx = std::distance(btrack, track);
116  // since we already set muon refs in the previously imported tracks,
117  // here we can skip everything that is already imported
118  if (!mask[idx])
119  continue;
120  muonref = reco::MuonRef();
121  pftrackref = reco::PFRecTrackRef(tracks, idx);
122  // Get the eventual muon associated to this track
123  const int muId = muAssocToTrack(pftrackref->trackRef(), muons);
124  bool thisIsAPotentialMuon = false;
125  if (muId != -1) {
126  muonref = reco::MuonRef(muons, muId);
127  thisIsAPotentialMuon = ((pfmu_->hasValidTrack(muonref, true) && PFMuonAlgo::isLooseMuon(muonref)) ||
128  (pfmu_->hasValidTrack(muonref, false) && PFMuonAlgo::isMuon(muonref)));
129  }
130  if (thisIsAPotentialMuon || PFTrackAlgoTools::goodPtResolution(
131  pftrackref->trackRef(), DPtovPtCut_, NHitCut_, useIterTracking_, trackQuality_)) {
132  trkElem = new reco::PFBlockElementTrack(pftrackref);
133  if (thisIsAPotentialMuon) {
134  LogDebug("GeneralTracksImporterWithVeto")
135  << "Potential Muon P " << pftrackref->trackRef()->p() << " pt " << pftrackref->trackRef()->p() << std::endl;
136  }
137  if (muId != -1)
138  trkElem->setMuonRef(muonref);
139  if (vetoed.count(pftrackref->trackRef().key()) == 0 || muonref.isNonnull()) {
140  elems.emplace_back(trkElem);
141  } else
142  delete trkElem;
143  }
144  }
145  elems.shrink_to_fit();
146 }

References a, cleanBadConvBrems_, reco::PFBlockElementTrack::convRefs(), reco::PFBlockElementTrack::displacedVertexRef(), HLT_2018_cff::distance, DPtovPtCut_, MillePedeFileConverter_cfg::e, PFTrackAlgoTools::goodPtResolution(), mps_fire::i, charmTagsComputerCvsB_cfi::idx, PFMuonAlgo::isLooseMuon(), PFMuonAlgo::isMuon(), edm::Ref< C, T, F >::isNull(), crabWrapper::key, edm::Ref< C, T, F >::key(), LogDebug, muAssocToTrack(), PDWG_BPHSkim_cff::muons, muons_, NHitCut_, pfmu_, reco::PFBlockElementTrack::setMuonRef(), src_, reco::PFBlockElement::T_FROM_DISP, reco::PFBlockElement::T_FROM_GAMMACONV, reco::PFBlockElement::TRACK, HLT_2018_cff::track, trackQuality_, reco::PFBlockElementTrack::trackRef(), PDWG_EXOHSCP_cff::tracks, reco::PFBlockElementTrack::trackType(), useIterTracking_, reco::PFBlockElementTrack::V0Ref(), veto_, and boostedElectronIsolation_cff::vetos.

◆ muAssocToTrack()

int GeneralTracksImporterWithVeto::muAssocToTrack ( const reco::TrackRef trackref,
const edm::Handle< reco::MuonCollection > &  muonh 
) const
private

Definition at line 148 of file GeneralTracksImporterWithVeto.cc.

149  {
150  auto muon = std::find_if(muonh->cbegin(), muonh->cend(), [&](const reco::Muon& m) {
151  return (m.track().isNonnull() && m.track() == trackref);
152  });
153  return (muon != muonh->cend() ? std::distance(muonh->cbegin(), muon) : -1);
154 }

References HLT_2018_cff::distance, visualization-live-secondInstance_cfg::m, and HLT_2018_cff::muon.

Referenced by importToBlock().

Member Data Documentation

◆ cleanBadConvBrems_

const bool GeneralTracksImporterWithVeto::cleanBadConvBrems_
private

Definition at line 41 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ DPtovPtCut_

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

Definition at line 39 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ muons_

edm::EDGetTokenT<reco::MuonCollection> GeneralTracksImporterWithVeto::muons_
private

Definition at line 37 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ NHitCut_

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

Definition at line 40 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ pfmu_

std::unique_ptr<PFMuonAlgo> GeneralTracksImporterWithVeto::pfmu_
private

◆ src_

edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporterWithVeto::src_
private

Definition at line 36 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ trackQuality_

const reco::TrackBase::TrackQuality GeneralTracksImporterWithVeto::trackQuality_
private

Definition at line 38 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ useIterTracking_

const bool GeneralTracksImporterWithVeto::useIterTracking_
private

Definition at line 41 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

◆ veto_

edm::EDGetTokenT<reco::PFRecTrackCollection> GeneralTracksImporterWithVeto::veto_
private

Definition at line 36 of file GeneralTracksImporterWithVeto.cc.

Referenced by importToBlock().

GeneralTracksImporterWithVeto::trackQuality_
const reco::TrackBase::TrackQuality trackQuality_
Definition: GeneralTracksImporterWithVeto.cc:38
reco::PFBlockElementTrack::trackType
bool trackType(TrackType trType) const override
Definition: PFBlockElementTrack.h:28
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
mps_fire.i
i
Definition: mps_fire.py:355
GeneralTracksImporterWithVeto::DPtovPtCut_
const std::vector< double > DPtovPtCut_
Definition: GeneralTracksImporterWithVeto.cc:39
muon
Definition: MuonCocktails.h:17
reco::PFBlockElementTrack::V0Ref
const VertexCompositeCandidateRef & V0Ref() const override
Definition: PFBlockElementTrack.h:100
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
reco::PFBlockElementTrack::trackRef
const reco::TrackRef & trackRef() const override
Definition: PFBlockElementTrack.h:49
GeneralTracksImporterWithVeto::veto_
edm::EDGetTokenT< reco::PFRecTrackCollection > veto_
Definition: GeneralTracksImporterWithVeto.cc:36
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
GeneralTracksImporterWithVeto::cleanBadConvBrems_
const bool cleanBadConvBrems_
Definition: GeneralTracksImporterWithVeto.cc:41
charmTagsComputerCvsB_cfi.idx
idx
Definition: charmTagsComputerCvsB_cfi.py:108
edm::RefVector< ConversionCollection >
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
HLT_2018_cff.postMuonCleaning
postMuonCleaning
Definition: HLT_2018_cff.py:12310
reco::Muon
Definition: Muon.h:27
BlockElementImporterBase::BlockElementImporterBase
BlockElementImporterBase(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
Definition: BlockElementImporterBase.h:17
edm::Ref< MuonCollection >
GeneralTracksImporterWithVeto::muons_
edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: GeneralTracksImporterWithVeto.cc:37
reco::PFBlockElementTrack::displacedVertexRef
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const override
Definition: PFBlockElementTrack.h:61
reco::PFBlockElementTrack::setMuonRef
void setMuonRef(const MuonRef &muref) override
\set reference to the Muon
Definition: PFBlockElementTrack.h:85
reco::PFBlockElement::TRACK
Definition: PFBlockElement.h:32
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
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
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:49
reco::PFRecTrackRef
edm::Ref< PFRecTrackCollection > PFRecTrackRef
persistent reference to PFRecTrack objects
Definition: PFRecTrackFwd.h:15
GeneralTracksImporterWithVeto::useIterTracking_
const bool useIterTracking_
Definition: GeneralTracksImporterWithVeto.cc:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::PFBlockElement::T_FROM_DISP
Definition: PFBlockElement.h:47
PFMuonAlgo
Definition: PFMuonAlgo.h:13
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
GeneralTracksImporterWithVeto::src_
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
Definition: GeneralTracksImporterWithVeto.cc:36
a
double a
Definition: hdecay.h:119
reco::PFBlockElement::T_FROM_GAMMACONV
Definition: PFBlockElement.h:47
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:28
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::ParameterSet::getParameter
T getParameter(std::string const &) const
GeneralTracksImporterWithVeto::muAssocToTrack
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
Definition: GeneralTracksImporterWithVeto.cc:148
PFMuonAlgo::isMuon
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:56
GeneralTracksImporterWithVeto::NHitCut_
const std::vector< unsigned > NHitCut_
Definition: GeneralTracksImporterWithVeto.cc:40
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
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_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
crabWrapper.key
key
Definition: crabWrapper.py:19
boostedElectronIsolation_cff.vetos
vetos
Definition: boostedElectronIsolation_cff.py:79
edm::InputTag
Definition: InputTag.h:15
PFMuonAlgo::isLooseMuon
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:65
reco::PFBlockElementTrack::convRefs
const ConversionRefVector & convRefs() const override
Definition: PFBlockElementTrack.h:91
GeneralTracksImporterWithVeto::pfmu_
std::unique_ptr< PFMuonAlgo > pfmu_
Definition: GeneralTracksImporterWithVeto.cc:43
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
reco::TrackBase::highPurity
Definition: TrackBase.h:154