CMS 3D CMS Logo

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