CMS 3D CMS Logo

GeneralTracksImporter.cc
Go to the documentation of this file.
10 
12 public:
14  : BlockElementImporterBase(conf, sumes),
15  src_(sumes.consumes<reco::PFRecTrackCollection>(conf.getParameter<edm::InputTag>("source"))),
16  muons_(sumes.consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
17  trackQuality_((conf.existsAs<std::string>("trackQuality"))
18  ? reco::TrackBase::qualityByName(conf.getParameter<std::string>("trackQuality"))
19  : reco::TrackBase::highPurity),
20  DPtovPtCut_(conf.getParameter<std::vector<double> >("DPtOverPtCuts_byTrackAlgo")),
21  NHitCut_(conf.getParameter<std::vector<unsigned> >("NHitCuts_byTrackAlgo")),
22  useIterTracking_(conf.getParameter<bool>("useIterativeTracking")),
24  conf.existsAs<bool>("cleanBadConvertedBrems") ? conf.getParameter<bool>("cleanBadConvertedBrems") : false) {
25  bool postMuonCleaning =
26  conf.existsAs<bool>("postMuonCleaning") ? conf.getParameter<bool>("postMuonCleaning") : false;
27  pfmu_ = std::unique_ptr<PFMuonAlgo>(new PFMuonAlgo(conf, postMuonCleaning));
28  }
29 
30  void importToBlock(const edm::Event&, ElementList&) const override;
31 
32 private:
33  int muAssocToTrack(const reco::TrackRef& trackref, const edm::Handle<reco::MuonCollection>& muonh) const;
34 
38  const std::vector<double> DPtovPtCut_;
39  const std::vector<unsigned> NHitCut_;
41  std::unique_ptr<PFMuonAlgo> pfmu_;
42 };
43 
45 
48  auto tracks = e.getHandle(src_);
49  auto muons = e.getHandle(muons_);
50  elems.reserve(elems.size() + tracks->size());
51  std::vector<bool> mask(tracks->size(), true);
52  reco::MuonRef muonref;
53 
54  // remove converted brems with bad pT resolution if requested
55  // this reproduces the old behavior of PFBlockAlgo
56  if (cleanBadConvBrems_) {
57  auto itr = elems.begin();
58  while (itr != elems.end()) {
59  if ((*itr)->type() == reco::PFBlockElement::TRACK) {
60  const reco::PFBlockElementTrack* trkel = static_cast<reco::PFBlockElementTrack*>(itr->get());
61  const reco::ConversionRefVector& cRef = trkel->convRefs();
63  const reco::VertexCompositeCandidateRef& v0Ref = trkel->V0Ref();
64  // if there is no displaced vertex reference and it is marked
65  // as a conversion it's gotta be a converted brem
66  if (trkel->trackType(reco::PFBlockElement::T_FROM_GAMMACONV) && cRef.empty() && dvRef.isNull() &&
67  v0Ref.isNull()) {
68  // if the Pt resolution is bad we kill this element
71  itr = elems.erase(itr);
72  continue;
73  }
74  }
75  }
76  ++itr;
77  } // loop on existing elements
78  }
79  // preprocess existing tracks in the element list and create a mask
80  // so that we do not import tracks twice, tag muons we find
81  // in this collection
82  auto TKs_end = std::partition(
83  elems.begin(), elems.end(), [](const ElementType& a) { return a->type() == reco::PFBlockElement::TRACK; });
84  auto btk_elems = elems.begin();
85  auto btrack = tracks->cbegin();
86  auto etrack = tracks->cend();
87  for (auto track = btrack; track != etrack; ++track) {
88  auto tk_elem =
89  std::find_if(btk_elems, TKs_end, [&](const ElementType& a) { return (a->trackRef() == track->trackRef()); });
90  if (tk_elem != TKs_end) {
91  mask[std::distance(tracks->cbegin(), track)] = false;
92  // check and update if this track is a muon
93  const int muId = muAssocToTrack((*tk_elem)->trackRef(), muons);
94  if (muId != -1) {
95  muonref = reco::MuonRef(muons, muId);
96  if (PFMuonAlgo::isLooseMuon(muonref) || PFMuonAlgo::isMuon(muonref)) {
97  static_cast<reco::PFBlockElementTrack*>(tk_elem->get())->setMuonRef(muonref);
98  }
99  }
100  }
101  }
102  // now we actually insert tracks, again tagging muons along the way
103  reco::PFRecTrackRef pftrackref;
104  reco::PFBlockElementTrack* trkElem = nullptr;
105  for (auto track = btrack; track != etrack; ++track) {
106  const unsigned idx = std::distance(btrack, track);
107  // since we already set muon refs in the previously imported tracks,
108  // here we can skip everything that is already imported
109  if (!mask[idx])
110  continue;
111  muonref = reco::MuonRef();
112  pftrackref = reco::PFRecTrackRef(tracks, idx);
113  // Get the eventual muon associated to this track
114  const int muId = muAssocToTrack(pftrackref->trackRef(), muons);
115  bool thisIsAPotentialMuon = false;
116  if (muId != -1) {
117  muonref = reco::MuonRef(muons, muId);
118  thisIsAPotentialMuon = ((pfmu_->hasValidTrack(muonref, true) && PFMuonAlgo::isLooseMuon(muonref)) ||
119  (pfmu_->hasValidTrack(muonref, false) && PFMuonAlgo::isMuon(muonref)));
120  }
121  if (thisIsAPotentialMuon || PFTrackAlgoTools::goodPtResolution(
122  pftrackref->trackRef(), DPtovPtCut_, NHitCut_, useIterTracking_, trackQuality_)) {
123  trkElem = new reco::PFBlockElementTrack(pftrackref);
124  if (thisIsAPotentialMuon) {
125  LogDebug("GeneralTracksImporter")
126  << "Potential Muon P " << pftrackref->trackRef()->p() << " pt " << pftrackref->trackRef()->p() << std::endl;
127  }
128  if (muId != -1)
129  trkElem->setMuonRef(muonref);
130  elems.emplace_back(trkElem);
131  }
132  }
133  elems.shrink_to_fit();
134 }
135 
137  const edm::Handle<reco::MuonCollection>& muonh) const {
138  auto muon = std::find_if(muonh->cbegin(), muonh->cend(), [&](const reco::Muon& m) {
139  return (m.track().isNonnull() && m.track() == trackref);
140  });
141  return (muon != muonh->cend() ? std::distance(muonh->cbegin(), muon) : -1);
142 }
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::muons_
edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: GeneralTracksImporter.cc:36
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
electrons_cff.bool
bool
Definition: electrons_cff.py:372
GeneralTracksImporter::NHitCut_
const std::vector< unsigned > NHitCut_
Definition: GeneralTracksImporter.cc:39
Muon.h
GeneralTracksImporter::src_
edm::EDGetTokenT< reco::PFRecTrackCollection > src_
Definition: GeneralTracksImporter.cc:35
MessageLogger.h
PFMuonAlgo.h
funct::false
false
Definition: Factorize.h:34
muon
Definition: MuonCocktails.h:17
reco::PFBlockElementTrack::V0Ref
const VertexCompositeCandidateRef & V0Ref() const override
Definition: PFBlockElementTrack.h:100
edm::EDGetTokenT< reco::PFRecTrackCollection >
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::PFBlockElementTrack::trackRef
const reco::TrackRef & trackRef() const override
Definition: PFBlockElementTrack.h:49
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
GeneralTracksImporter::cleanBadConvBrems_
const bool cleanBadConvBrems_
Definition: GeneralTracksImporter.cc:40
GeneralTracksImporter::useIterTracking_
const bool useIterTracking_
Definition: GeneralTracksImporter.cc:40
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
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
HLT_2018_cff.postMuonCleaning
postMuonCleaning
Definition: HLT_2018_cff.py:12310
GeneralTracksImporter::muAssocToTrack
int muAssocToTrack(const reco::TrackRef &trackref, const edm::Handle< reco::MuonCollection > &muonh) const
Definition: GeneralTracksImporter.cc:136
edm::Handle< reco::MuonCollection >
training_settings.idx
idx
Definition: training_settings.py:16
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
reco::PFBlockElementTrack::displacedVertexRef
const PFDisplacedTrackerVertexRef & displacedVertexRef(TrackType trType) const override
Definition: PFBlockElementTrack.h:61
Track.h
BlockElementImporterBase.h
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
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
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
PFMuonAlgo
Definition: PFMuonAlgo.h:13
PFTrackAlgoTools.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
a
double a
Definition: hdecay.h:119
GeneralTracksImporter::GeneralTracksImporter
GeneralTracksImporter(const edm::ParameterSet &conf, edm::ConsumesCollector &sumes)
Definition: GeneralTracksImporter.cc:13
edmplugin::PluginFactory
Definition: PluginFactory.h:34
reco::PFBlockElement::T_FROM_GAMMACONV
Definition: PFBlockElement.h:47
GeneralTracksImporter::DPtovPtCut_
const std::vector< double > DPtovPtCut_
Definition: GeneralTracksImporter.cc:38
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
PFRecTrack.h
ValueMap.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GeneralTracksImporter::pfmu_
std::unique_ptr< PFMuonAlgo > pfmu_
Definition: GeneralTracksImporter.cc:41
std
Definition: JetResolutionObject.h:76
GeneralTracksImporter::trackQuality_
const reco::TrackBase::TrackQuality trackQuality_
Definition: GeneralTracksImporter.cc:37
PFMuonAlgo::isMuon
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:56
muons_cff.highPurity
highPurity
Definition: muons_cff.py:140
reco::PFBlockElementTrack
Track Element.
Definition: PFBlockElementTrack.h:17
reco::PFRecTrackCollection
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
Definition: PFRecTrackFwd.h:9
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
GeneralTracksImporter::importToBlock
void importToBlock(const edm::Event &, ElementList &) const override
Definition: GeneralTracksImporter.cc:46
GeneralTracksImporter
Definition: GeneralTracksImporter.cc:11
edm::Event
Definition: Event.h:73
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
PFBlockElementTrack.h
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
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
BlockElementImporterBase
Definition: BlockElementImporterBase.h:14