16 bool passesQuality(
const reco::Track&
trk,
const std::vector<reco::TrackBase::TrackQuality>& allowedQuals) {
17 for (
const auto& qual : allowedQuals) {
18 if (
trk.quality(qual))
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>>();
135 iEvent.getByToken(map_, pf2pc);
156 iEvent.getByToken(pvOrigs_, pvOrigs);
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) {
170 if (
cand.charge() &&
cand.trackRef().isNonnull() &&
cand.trackRef().id() ==
tracks.id()) {
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;
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);
257 auto tk2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
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)
291 id = -13 *
trk->charge();
312 cands.back().setCovarianceVersion(covarianceVersion_);
314 if (
trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) {
315 cands.back().setTrkAlgo(static_cast<uint8_t>(
trk->algo()), static_cast<uint8_t>(
trk->originalAlgo()));
317 if (useLegacySetup_ ||
std::abs(
id) == 11 || trkStatus == TrkStatus::VTX) {
318 cands.back().setTrackProperties(*
trk, covariancePackingSchemas_[4], covarianceVersion_);
320 if (
trk->hitPattern().numberOfValidPixelHits() > 0) {
321 cands.back().setTrackProperties(
322 *
trk, covariancePackingSchemas_[0], covarianceVersion_);
324 cands.back().setTrackProperties(
325 *
trk, covariancePackingSchemas_[1], covarianceVersion_);
328 }
else if (!useLegacySetup_ &&
trk->pt() > minPtToStoreLowQualityProps_) {
329 if (
trk->hitPattern().numberOfValidPixelHits() > 0) {
330 cands.back().setTrackProperties(
331 *
trk, covariancePackingSchemas_[2], covarianceVersion_);
333 cands.back().setTrackProperties(
334 *
trk, covariancePackingSchemas_[3], covarianceVersion_);
337 cands.back().setAssociationQuality(pvAssocQuality);
340 cands.back().setMuonID(
muon->isStandAloneMuon(),
muon->isGlobalMuon());
348 if (useLegacySetup_) {
353 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(0,
356 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(-1,
364 int iVtxMaxWeight = -1;
365 int iVtxMinDzDist = -1;
371 float w =
vtx.trackWeight(
trk);
373 double dzSig =
dz /
trk->dzError();
378 if (dzSig < minDzSig) {
386 if (iVtxMaxWeight >= 0) {
387 if (maxWeight > 0.5) {
388 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
391 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMaxWeight,
396 if (
minDz < maxDzForPrimaryAssignment_) {
397 const double add_cov =
vertices[iVtxMinDzDist].covariance(2, 2);
399 if (
minDz / dzErr < maxDzSigForPrimaryAssignment_ && trk->
dzError() < maxDzErrorForPrimaryAssignment_) {
400 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,
408 return std::pair<int, pat::PackedCandidate::PVAssociationQuality>(iVtxMinDzDist,
int numberOfValidPixelHits() const
T getParameter(std::string const &) const
std::pair< int, pat::PackedCandidate::PVAssociationQuality > associateTrkToVtx(const reco::VertexCollection &vertices, const reco::TrackRef &trk) const
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
const double minPtToStoreProps_
unsigned short numberOfValidHits() const
number of valid hits found
~PATLostTracks() override
std::vector< l1t::PFCandidate > PFCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
const double maxDzSigForPrimaryAssignment_
std::vector< Track > TrackCollection
collection of Tracks
bool isNonnull() const
Checks for non-null.
std::vector< Vertex > VertexCollection
collection of Vertex objects
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const double minPtToStoreLowQualityProps_
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
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
const int covarianceVersion_
key_type key() const
Accessor for product key.
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
double pt() const
track transverse momentum
const edm::EDGetTokenT< reco::PFCandidateCollection > cands_
const double maxDzErrorForPrimaryAssignment_
const edm::EDGetTokenT< reco::MuonCollection > muons_
const bool useLegacySetup_
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > lambdas_
Abs< T >::type abs(const T &t)
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
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_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
const edm::EDGetTokenT< reco::TrackCollection > tracks_
const edm::EDGetTokenT< reco::VertexCollection > vertices_
const std::vector< int > covariancePackingSchemas_
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
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.
bool passTrkCuts(const reco::Track &tr) const
const double minPixelHits_
const edm::EDGetTokenT< reco::VertexCollection > pv_
const edm::EDGetTokenT< reco::VertexCollection > pvOrigs_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.