16 bool passesQuality(
const reco::Track& trk,
const std::vector<reco::TrackBase::TrackQuality>& allowedQuals) {
17 for (
const auto& qual : allowedQuals) {
76 iConfig.getParameter<
edm::
InputTag>(
"packedPFCandidates"))),
83 minPt_(iConfig.getParameter<double>(
"minPt")),
84 minHits_(iConfig.getParameter<uint32_t>(
"minHits")),
85 minPixelHits_(iConfig.getParameter<uint32_t>(
"minPixelHits")),
86 minPtToStoreProps_(iConfig.getParameter<double>(
"minPtToStoreProps")),
87 covarianceVersion_(iConfig.getParameter<
int>(
"covarianceVersion")),
88 covariancePackingSchemas_(iConfig.getParameter<
std::
vector<
int>>(
"covariancePackingSchemas")),
90 passThroughCut_(iConfig.getParameter<
std::
string>(
"passThroughCut")),
91 maxDzForPrimaryAssignment_(
92 iConfig.getParameter<
edm::
ParameterSet>(
"pvAssignment").getParameter<double>(
"maxDzForPrimaryAssignment")),
93 maxDzSigForPrimaryAssignment_(
94 iConfig.getParameter<
edm::
ParameterSet>(
"pvAssignment").getParameter<double>(
"maxDzSigForPrimaryAssignment")),
95 maxDzErrorForPrimaryAssignment_(iConfig.getParameter<
edm::
ParameterSet>(
"pvAssignment")
96 .getParameter<double>(
"maxDzErrorForPrimaryAssignment")),
97 maxDxyForNotReconstructedPrimary_(iConfig.getParameter<
edm::
ParameterSet>(
"pvAssignment")
98 .getParameter<double>(
"maxDxyForNotReconstructedPrimary")),
99 maxDxySigForNotReconstructedPrimary_(iConfig.getParameter<
edm::
ParameterSet>(
"pvAssignment")
100 .getParameter<double>(
"maxDxySigForNotReconstructedPrimary")),
101 useLegacySetup_(iConfig.getParameter<
bool>(
"useLegacySetup")) {
102 std::vector<std::string> trkQuals(iConfig.
getParameter<std::vector<std::string>>(
"qualsToAutoAccept"));
108 std::ostringstream
msg;
109 msg <<
" PATLostTracks has a quality requirement which resolves to undefQuality. This usually means a typo and is "
110 "therefore treated a config error\nquality requirements:\n ";
111 for (
const auto& trkQual : trkQuals)
112 msg << trkQual <<
" ";
116 produces<std::vector<reco::Track>>();
117 produces<std::vector<pat::PackedCandidate>>();
118 produces<std::vector<pat::PackedCandidate>>(
"eleTracks");
119 produces<edm::Association<pat::PackedCandidateCollection>>();
129 iEvent.getByToken(map_, pf2pc);
150 iEvent.getByToken(pvOrigs_, pvOrigs);
152 auto outPtrTrks = std::make_unique<std::vector<reco::Track>>();
153 auto outPtrTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
154 auto outPtrEleTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
156 std::vector<TrkStatus> trkStatus(
tracks->size(), TrkStatus::NOTUSED);
161 for (
unsigned int ic = 0, nc =
cands->size(); ic < nc; ++ic) {
164 if (
cand.charge() &&
cand.trackRef().isNonnull() &&
cand.trackRef().id() ==
tracks.id()) {
165 if (
cand.pdgId() == 11)
166 trkStatus[
cand.trackRef().key()] = TrkStatus::PFELECTRON;
167 else if (
cand.pdgId() == -11)
168 trkStatus[
cand.trackRef().key()] = TrkStatus::PFPOSITRON;
169 else if ((*pf2pc)[
r]->numberOfHits() > 0)
170 trkStatus[
cand.trackRef().key()] = TrkStatus::PFCAND;
172 trkStatus[
cand.trackRef().key()] = TrkStatus::PFCANDNOTRKPROPS;
177 for (
const auto& secVert : *
vertices) {
178 for (
auto trkIt = secVert.tracks_begin(); trkIt != secVert.tracks_end(); trkIt++) {
179 if (trkStatus[trkIt->key()] == TrkStatus::NOTUSED)
180 trkStatus[trkIt->key()] = TrkStatus::VTX;
184 for (
size_t dIdx = 0; dIdx <
v0.numberOfDaughters(); dIdx++) {
185 size_t key = (dynamic_cast<const reco::RecoChargedCandidate*>(
v0.daughter(dIdx)))->track().key();
186 if (trkStatus[
key] == TrkStatus::NOTUSED)
187 trkStatus[
key] = TrkStatus::VTX;
191 for (
size_t dIdx = 0; dIdx <
v0.numberOfDaughters(); dIdx++) {
192 size_t key = (dynamic_cast<const reco::RecoChargedCandidate*>(
v0.daughter(dIdx)))->track().key();
193 if (trkStatus[
key] == TrkStatus::NOTUSED)
194 trkStatus[
key] = TrkStatus::VTX;
199 for (
unsigned int trkIndx = 0; trkIndx <
tracks->size(); trkIndx++) {
201 if (trkStatus[trkIndx] == TrkStatus::VTX || (trkStatus[trkIndx] == TrkStatus::NOTUSED && passTrkCuts(*trk))) {
202 outPtrTrks->emplace_back(*trk);
204 std::pair<int, pat::PackedCandidate::PVAssociationQuality> pvAsso = associateTrkToVtx(*pvOrigs, trk);
208 }
else if (!
pvs->empty()) {
211 addPackedCandidate(*outPtrTrksAsCands, trk,
pv, pvRefProd, trkStatus[trkIndx], pvAsso.second,
muons);
215 mapping[trkIndx] = lostTrkIndx;
217 }
else if ((trkStatus[trkIndx] == TrkStatus::PFELECTRON || trkStatus[trkIndx] == TrkStatus::PFPOSITRON) &&
220 std::pair<int, pat::PackedCandidate::PVAssociationQuality> pvAsso = associateTrkToVtx(*pvOrigs, trk);
224 }
else if (!
pvs->empty()) {
227 addPackedCandidate(*outPtrEleTrksAsCands, trk,
pv, pvRefProd, trkStatus[trkIndx], pvAsso.second,
muons);
234 auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
244 const bool passTrkQual = passesQuality(tr, qualsToAutoAccept_);
246 return passTrkHits || passTrkQual || passThroughCut_(tr);
256 const float mass = 0.13957018;
258 int id = 211 * trk->charge();
259 if (trkStatus == TrkStatus::PFELECTRON)
261 else if (trkStatus == TrkStatus::PFPOSITRON)
267 id = -13 * trk->charge();
289 if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) {
290 if (useLegacySetup_ ||
std::abs(
id) == 11 || trkStatus == TrkStatus::VTX) {
291 cands.back().setTrackProperties(*trk, covariancePackingSchemas_[4], covarianceVersion_);
293 if (trk->hitPattern().numberOfValidPixelHits() > 0) {
294 cands.back().setTrackProperties(
295 *trk, covariancePackingSchemas_[0], covarianceVersion_);
297 cands.back().setTrackProperties(
298 *trk, covariancePackingSchemas_[1], covarianceVersion_);
301 }
else if (!useLegacySetup_ && trk->pt() > 0.5) {
302 if (trk->hitPattern().numberOfValidPixelHits() > 0) {
303 cands.back().setTrackProperties(
304 *trk, covariancePackingSchemas_[2], covarianceVersion_);
306 cands.back().setTrackProperties(
307 *trk, covariancePackingSchemas_[3], covarianceVersion_);
310 cands.back().setAssociationQuality(pvAssocQuality);
318 if (useLegacySetup_) {
323 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(0,
326 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(-1,
334 int iVtxMaxWeight = -1;
335 int iVtxMinDzDist = -1;
341 float w =
vtx.trackWeight(trk);
343 double dzSig =
dz / trk->dzError();
348 if (dzSig < minDzSig) {
356 if (iVtxMaxWeight >= 0) {
357 if (maxWeight > 0.5) {
358 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
361 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
366 if (
minDz < maxDzForPrimaryAssignment_) {
367 const double add_cov =
vertices[iVtxMinDzDist].covariance(2, 2);
368 const double dzErr =
sqrt(trk->dzError() * trk->dzError() + add_cov);
369 if (
minDz / dzErr < maxDzSigForPrimaryAssignment_ && trk->dzError() < maxDzErrorForPrimaryAssignment_) {
370 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,
377 std::abs(trk->dxy(
vertices[0].position()) / trk->dxyError()) < maxDxySigForNotReconstructedPrimary_)
378 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,