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