16 bool passesQuality(
const reco::Track& trk,
const std::vector<reco::TrackBase::TrackQuality>& allowedQuals) {
17 for (
const auto& qual : allowedQuals) {
79 iConfig.getParameter<edm::
InputTag>(
"packedPFCandidates"))),
86 minPt_(iConfig.getParameter<double>(
"minPt")),
87 minHits_(iConfig.getParameter<uint32_t>(
"minHits")),
88 minPixelHits_(iConfig.getParameter<uint32_t>(
"minPixelHits")),
89 minPtToStoreProps_(iConfig.getParameter<double>(
"minPtToStoreProps")),
90 minPtToStoreLowQualityProps_(iConfig.getParameter<double>(
"minPtToStoreLowQualityProps")),
91 covarianceVersion_(iConfig.getParameter<int>(
"covarianceVersion")),
92 covariancePackingSchemas_(iConfig.getParameter<std::
vector<int>>(
"covariancePackingSchemas")),
94 passThroughCut_(iConfig.getParameter<std::
string>(
"passThroughCut")),
95 maxDzForPrimaryAssignment_(
96 iConfig.getParameter<edm::
ParameterSet>(
"pvAssignment").getParameter<double>(
"maxDzForPrimaryAssignment")),
97 maxDzSigForPrimaryAssignment_(
98 iConfig.getParameter<edm::
ParameterSet>(
"pvAssignment").getParameter<double>(
"maxDzSigForPrimaryAssignment")),
99 maxDzErrorForPrimaryAssignment_(iConfig.getParameter<edm::
ParameterSet>(
"pvAssignment")
100 .getParameter<double>(
"maxDzErrorForPrimaryAssignment")),
101 maxDxyForNotReconstructedPrimary_(iConfig.getParameter<edm::
ParameterSet>(
"pvAssignment")
102 .getParameter<double>(
"maxDxyForNotReconstructedPrimary")),
103 maxDxySigForNotReconstructedPrimary_(iConfig.getParameter<edm::
ParameterSet>(
"pvAssignment")
104 .getParameter<double>(
"maxDxySigForNotReconstructedPrimary")),
105 useLegacySetup_(iConfig.getParameter<bool>(
"useLegacySetup")),
106 xiSelection_(iConfig.getParameter<bool>(
"xiSelection")),
107 xiMassCut_(iConfig.getParameter<double>(
"xiMassCut")) {
108 std::vector<std::string> trkQuals(iConfig.
getParameter<std::vector<std::string>>(
"qualsToAutoAccept"));
114 std::ostringstream
msg;
115 msg <<
" PATLostTracks has a quality requirement which resolves to undefQuality. This usually means a typo and is "
116 "therefore treated a config error\nquality requirements:\n ";
117 for (
const auto& trkQual : trkQuals)
118 msg << trkQual <<
" ";
122 produces<std::vector<reco::Track>>();
123 produces<std::vector<pat::PackedCandidate>>();
124 produces<std::vector<pat::PackedCandidate>>(
"eleTracks");
125 produces<edm::Association<pat::PackedCandidateCollection>>();
158 auto outPtrTrks = std::make_unique<std::vector<reco::Track>>();
159 auto outPtrTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
160 auto outPtrEleTrksAsCands = std::make_unique<std::vector<pat::PackedCandidate>>();
162 std::vector<TrkStatus> trkStatus(tracks->size(), TrkStatus::NOTUSED);
167 for (
unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
171 if (cand.
pdgId() == 11)
172 trkStatus[cand.
trackRef().
key()] = TrkStatus::PFELECTRON;
173 else if (cand.
pdgId() == -11)
174 trkStatus[cand.
trackRef().
key()] = TrkStatus::PFPOSITRON;
175 else if ((*pf2pc)[r]->numberOfHits() > 0)
176 trkStatus[cand.
trackRef().
key()] = TrkStatus::PFCAND;
178 trkStatus[cand.
trackRef().
key()] = TrkStatus::PFCANDNOTRKPROPS;
183 for (
const auto& secVert : *vertices) {
184 for (
auto trkIt = secVert.tracks_begin(); trkIt != secVert.tracks_end(); trkIt++) {
185 if (trkStatus[trkIt->key()] == TrkStatus::NOTUSED)
186 trkStatus[trkIt->key()] = TrkStatus::VTX;
189 for (
const auto& v0 : *kshorts) {
190 for (
size_t dIdx = 0; dIdx < v0.numberOfDaughters(); dIdx++) {
192 if (trkStatus[key] == TrkStatus::NOTUSED)
193 trkStatus[
key] = TrkStatus::VTX;
196 for (
const auto& v0 : *lambdas) {
197 double protonCharge = 0;
198 for (
size_t dIdx = 0; dIdx < v0.numberOfDaughters(); dIdx++) {
200 if (trkStatus[key] == TrkStatus::NOTUSED)
201 trkStatus[
key] = TrkStatus::VTX;
202 protonCharge += v0.daughter(dIdx)->charge() * v0.daughter(dIdx)->momentum().mag2();
208 for (
unsigned int trkIndx = 0; trkIndx < tracks->size(); trkIndx++) {
210 if ((*trk).charge() * protonCharge < 0 || trkStatus[trkIndx] != TrkStatus::NOTUSED)
214 trk->px(), trk->py(), trk->pz(),
sqrt(trk->momentum().mag2() + 0.01947995518));
215 if ((p4Lambda + p4pi).M() < xiMassCut_)
216 trkStatus[trkIndx] = TrkStatus::VTX;
220 std::vector<int> mapping(tracks->size(), -1);
222 for (
unsigned int trkIndx = 0; trkIndx < tracks->size(); trkIndx++) {
224 if (trkStatus[trkIndx] == TrkStatus::VTX || (trkStatus[trkIndx] == TrkStatus::NOTUSED && passTrkCuts(*trk))) {
225 outPtrTrks->emplace_back(*trk);
227 std::pair<int, pat::PackedCandidate::PVAssociationQuality> pvAsso = associateTrkToVtx(*pvOrigs, trk);
231 }
else if (!pvs->empty()) {
234 addPackedCandidate(*outPtrTrksAsCands, trk,
pv, pvRefProd, trkStatus[trkIndx], pvAsso.second, muons);
238 mapping[trkIndx] = lostTrkIndx;
240 }
else if ((trkStatus[trkIndx] == TrkStatus::PFELECTRON || trkStatus[trkIndx] == TrkStatus::PFPOSITRON) &&
243 std::pair<int, pat::PackedCandidate::PVAssociationQuality> pvAsso = associateTrkToVtx(*pvOrigs, trk);
247 }
else if (!pvs->empty()) {
250 addPackedCandidate(*outPtrEleTrksAsCands, trk,
pv, pvRefProd, trkStatus[trkIndx], pvAsso.second, muons);
255 iEvent.
put(
std::move(outPtrEleTrksAsCands),
"eleTracks");
257 auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
259 tk2pcFiller.insert(tracks, mapping.begin(), mapping.end());
267 const bool passTrkQual = passesQuality(tr, qualsToAutoAccept_);
269 return passTrkHits || passTrkQual || passThroughCut_(tr);
279 const float mass = 0.13957018;
281 int id = 211 * trk->charge();
282 if (trkStatus == TrkStatus::PFELECTRON)
284 else if (trkStatus == TrkStatus::PFPOSITRON)
288 for (
auto&
mu : *muons) {
290 id = -13 * trk->charge();
310 cands.back().setCovarianceVersion(covarianceVersion_);
311 cands.back().setLostInnerHits(lostHits);
312 if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) {
313 if (useLegacySetup_ ||
std::abs(
id) == 11 || trkStatus == TrkStatus::VTX) {
314 cands.back().setTrackProperties(*trk, covariancePackingSchemas_[4], covarianceVersion_);
316 if (trk->hitPattern().numberOfValidPixelHits() > 0) {
317 cands.back().setTrackProperties(
318 *trk, covariancePackingSchemas_[0], covarianceVersion_);
320 cands.back().setTrackProperties(
321 *trk, covariancePackingSchemas_[1], covarianceVersion_);
324 }
else if (!useLegacySetup_ && trk->pt() > minPtToStoreLowQualityProps_) {
325 if (trk->hitPattern().numberOfValidPixelHits() > 0) {
326 cands.back().setTrackProperties(
327 *trk, covariancePackingSchemas_[2], covarianceVersion_);
329 cands.back().setTrackProperties(
330 *trk, covariancePackingSchemas_[3], covarianceVersion_);
333 cands.back().setAssociationQuality(pvAssocQuality);
341 if (useLegacySetup_) {
342 float w = vertices[0].trackWeight(trk);
346 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(0,
349 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(-1,
357 int iVtxMaxWeight = -1;
358 int iVtxMinDzDist = -1;
363 for (
auto const& vtx : vertices) {
364 float w = vtx.trackWeight(trk);
365 double dz =
std::abs(trk->dz(vtx.position()));
366 double dzSig = dz / trk->dzError();
371 if (dzSig < minDzSig) {
379 if (iVtxMaxWeight >= 0) {
380 if (maxWeight > 0.5) {
381 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
384 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
389 if (minDz < maxDzForPrimaryAssignment_) {
390 const double add_cov = vertices[iVtxMinDzDist].covariance(2, 2);
391 const double dzErr =
sqrt(trk->dzError() * trk->dzError() + add_cov);
392 if (minDz / dzErr < maxDzSigForPrimaryAssignment_ && trk->dzError() < maxDzErrorForPrimaryAssignment_) {
393 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,
399 if (!vertices.empty() &&
std::abs(trk->dxy(vertices[0].position())) < maxDxyForNotReconstructedPrimary_ &&
400 std::abs(trk->dxy(vertices[0].position()) / trk->dxyError()) < maxDxySigForNotReconstructedPrimary_)
401 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
bool isNonnull() const
Checks for non-null.
const double minPtToStoreProps_
uint16_t *__restrict__ id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
~PATLostTracks() override
#define DEFINE_FWK_MODULE(type)
std::vector< l1t::PFCandidate > PFCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
const double maxDzSigForPrimaryAssignment_
std::vector< Track > TrackCollection
collection of Tracks
std::vector< Vertex > VertexCollection
collection of Vertex objects
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
auto const & tracks
cannot be loose
const double minPtToStoreLowQualityProps_
key_type key() const
Accessor for product key.
PATLostTracks(const edm::ParameterSet &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const double maxDxyForNotReconstructedPrimary_
std::vector< Vertex > VertexCollection
const int covarianceVersion_
ProductID id() const
Accessor for product ID.
reco::TrackRef trackRef() const
int pdgId() const final
PDG identifier.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const edm::EDGetTokenT< reco::PFCandidateCollection > cands_
const double maxDzErrorForPrimaryAssignment_
const edm::EDGetTokenT< reco::MuonCollection > muons_
const bool useLegacySetup_
double pt() const
track transverse momentum
tuple key
prepare the HTCondor submission files and eventually submit them
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > lambdas_
Abs< T >::type abs(const T &t)
unsigned short numberOfValidHits() const
number of valid hits found
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
std::pair< int, pat::PackedCandidate::PVAssociationQuality > associateTrkToVtx(const reco::VertexCollection &vertices, const reco::TrackRef &trk) const
const double maxDzForPrimaryAssignment_
const double maxDxySigForNotReconstructedPrimary_
LostInnerHits
Enumerator specifying the.
static TrackQuality qualityByName(const std::string &name)
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
void addPackedCandidate(std::vector< pat::PackedCandidate > &cands, const reco::TrackRef &trk, const reco::VertexRef &pvSlimmed, const reco::VertexRefProd &pvSlimmedColl, const TrkStatus &trkStatus, const pat::PackedCandidate::PVAssociationQuality &pvAssocQuality, edm::Handle< reco::MuonCollection > muons) const
bool passTrkCuts(const reco::Track &tr) const
const edm::EDGetTokenT< reco::TrackCollection > tracks_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
const edm::EDGetTokenT< reco::VertexCollection > vertices_
T getParameter(std::string const &) const
const std::vector< int > covariancePackingSchemas_
bool quality(const TrackQuality) const
Track quality.
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > kshorts_
std::vector< Muon > MuonCollection
std::vector< reco::TrackBase::TrackQuality > qualsToAutoAccept_
StringCutObjectSelector< reco::Track, false > passThroughCut_
Particle reconstructed by the particle flow algorithm.
int numberOfValidPixelHits() const
const double minPixelHits_
const edm::EDGetTokenT< reco::VertexCollection > pv_
int charge() const final
electric charge
const edm::EDGetTokenT< reco::VertexCollection > pvOrigs_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.