68 int& pc_ref_idx)
const;
122 iConfig.getParameter<
edm::
InputTag>(
"packedPFCandidates"))),
124 iConfig.getParameter<
edm::
InputTag>(
"lostTracks"))),
126 iConfig.getParameter<
edm::
InputTag>(
"packedPFCandidates"))),
128 gt2dedxStrip_(consumes<
edm::ValueMap<
reco::DeDxData>>(iConfig.getParameter<
edm::
InputTag>(
"dEdxDataStrip"))),
129 gt2dedxPixel_(consumes<
edm::ValueMap<
reco::DeDxData>>(iConfig.getParameter<
edm::
InputTag>(
"dEdxDataPixel"))),
131 addPrescaledDeDxTracks_(iConfig.getParameter<
bool>(
"addPrescaledDeDxTracks")),
132 gt2dedxHitInfoPrescale_(addPrescaledDeDxTracks_ ? consumes<
edm::ValueMap<
int>>(
133 iConfig.getParameter<
edm::
InputTag>(
"dEdxHitInfoPrescale"))
134 :
edm::EDGetTokenT<
edm::ValueMap<
int>>()),
135 usePrecomputedDeDxStrip_(iConfig.getParameter<
bool>(
"usePrecomputedDeDxStrip")),
136 usePrecomputedDeDxPixel_(iConfig.getParameter<
bool>(
"usePrecomputedDeDxPixel")),
137 pT_cut_(iConfig.getParameter<double>(
"pT_cut")),
138 pT_cut_noIso_(iConfig.getParameter<double>(
"pT_cut_noIso")),
139 pfIsolation_DR_(iConfig.getParameter<double>(
"pfIsolation_DR")),
140 pfIsolation_DZ_(iConfig.getParameter<double>(
"pfIsolation_DZ")),
141 absIso_cut_(iConfig.getParameter<double>(
"absIso_cut")),
142 relIso_cut_(iConfig.getParameter<double>(
"relIso_cut")),
143 miniRelIso_cut_(iConfig.getParameter<double>(
"miniRelIso_cut")),
144 caloJet_DR_(iConfig.getParameter<double>(
"caloJet_DR")),
145 pflepoverlap_DR_(iConfig.getParameter<double>(
"pflepoverlap_DR")),
146 pflepoverlap_pTmin_(iConfig.getParameter<double>(
"pflepoverlap_pTmin")),
147 pcRefNearest_DR_(iConfig.getParameter<double>(
"pcRefNearest_DR")),
148 pcRefNearest_pTmin_(iConfig.getParameter<double>(
"pcRefNearest_pTmin")),
149 pfneutralsum_DR_(iConfig.getParameter<double>(
"pfneutralsum_DR")),
150 useHighPurity_(iConfig.getParameter<
bool>(
"useHighPurity")),
151 saveDeDxHitInfo_(iConfig.getParameter<
bool>(
"saveDeDxHitInfo")),
152 saveDeDxHitInfoCut_(iConfig.getParameter<
std::
string>(
"saveDeDxHitInfoCut")) {
162 throw cms::Exception(
"ParameterError") <<
"miniIsoParams must have exactly 3 elements.\n";
164 produces<pat::IsolatedTrackCollection>();
167 produces<reco::DeDxHitInfoCollection>();
168 produces<reco::DeDxHitInfoAss>();
177 iEvent.getByToken(pc_, pc_h);
187 iEvent.getByToken(gt_, gt_h);
197 iEvent.getByToken(gt2pc_, gt2pc);
201 iEvent.getByToken(gt2lt_, gt2lt);
205 iEvent.getByToken(pc2pf_, pc2pf);
212 iEvent.getByToken(gt2dedxStrip_, gt2dedxStrip);
216 iEvent.getByToken(gt2dedxPixel_, gt2dedxPixel);
220 iEvent.getByToken(gt2dedxHitInfo_, gt2dedxHitInfo);
222 if (addPrescaledDeDxTracks_) {
223 iEvent.getByToken(gt2dedxHitInfoPrescale_, gt2dedxHitInfoPrescale);
234 auto outDeDxC = std::make_unique<reco::DeDxHitInfoCollection>();
235 std::vector<int> dEdXass;
237 auto outPtrP = std::make_unique<std::vector<pat::IsolatedTrack>>();
240 for (
unsigned int igt = 0; igt <
generalTracks->size(); igt++) {
254 bool isInPackedCands = (pcref.
isNonnull() && pcref.
id() == pc_h.
id() && pfCand->
charge() != 0);
255 bool isInLostTracks = (ltref.
isNonnull() && ltref.
id() == lt_h.
id());
261 float dz,
dxy, dzError, dxyError;
266 if (isInPackedCands) {
268 polarP4 = pfCand->
p4();
270 pfCandInd = pcref.
key();
272 }
else if (isInLostTracks) {
273 p4 = lostTrack->
p4();
274 polarP4 = lostTrack->
p4();
277 ltCandInd = ltref.
key();
279 double m = 0.13957018;
280 double E =
sqrt(
m *
m + gentk.
p() * gentk.
p());
281 p4.SetPxPyPzE(gentk.
px(), gentk.
py(), gentk.
pz(), E);
282 polarP4.SetCoordinates(gentk.
pt(), gentk.
eta(), gentk.
phi(),
m);
289 if (addPrescaledDeDxTracks_) {
290 const auto& dedxRef = (*gt2dedxHitInfo)[tkref];
291 if (dedxRef.isNonnull()) {
292 prescaled = (*gt2dedxHitInfoPrescale)[dedxRef];
296 if (polarP4.pt() < pT_cut_ && prescaled <= 1)
304 getIsolation(polarP4, pc, pfCandInd, isolationDR03, miniIso);
307 if (polarP4.pt() < pT_cut_noIso_ && prescaled <= 1 &&
314 if (isInPackedCands) {
322 }
else if (isInLostTracks) {
324 dz = lostTrack->
dz();
332 dz = gentk.
dz(
pv.position());
340 float caloJetEm, caloJetHad;
341 getCaloJetEnergy(polarP4,
caloJets.product(), caloJetEm, caloJetHad);
343 bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc);
344 float pfNeutralSum = getPFNeutralSum(polarP4, pc, pfCandInd);
347 int refToNearestPF_idx = -1;
348 getNearestPCRef(polarP4, pc, pfCandInd, refToNearestPF_idx);
349 if (refToNearestPF_idx != -1)
353 int refToNearestLostTrack_idx = -1;
354 getNearestPCRef(polarP4, lt, ltCandInd, refToNearestLostTrack_idx);
355 if (refToNearestLostTrack_idx != -1)
359 float dEdxPixel = -1, dEdxStrip = -1;
360 if (usePrecomputedDeDxStrip_ && gt2dedxStrip.
isValid() && gt2dedxStrip->contains(tkref.
id())) {
361 dEdxStrip = (*gt2dedxStrip)[tkref].dEdx();
364 dEdxStrip = getDeDx(hitInfo,
false,
true);
366 if (usePrecomputedDeDxPixel_ && gt2dedxPixel.
isValid() && gt2dedxPixel->contains(tkref.
id())) {
367 dEdxPixel = (*gt2dedxPixel)[tkref].dEdx();
370 dEdxPixel = getDeDx(hitInfo,
true,
false);
379 std::vector<uint32_t> crossedHcalStatus;
383 std::vector<uint16_t> crossedEcalStatus;
385 crossedEcalStatus.push_back(ecalS->
find(did.rawId())->getStatusCode());
423 refToNearestLostTrack));
424 outPtrP->back().setStatus(prescaled);
426 if (saveDeDxHitInfo_) {
427 const auto& dedxRef = (*gt2dedxHitInfo)[tkref];
428 if (saveDeDxHitInfoCut_(outPtrP->back()) && dedxRef.isNonnull()) {
429 outDeDxC->push_back(*dedxRef);
430 dEdXass.push_back(outDeDxC->size() - 1);
432 dEdXass.push_back(-1);
440 for (
unsigned int ipc = 0; ipc < pc->size(); ipc++) {
446 if (pfref.
get()->trackRef().isNonnull() && pfref.
get()->trackRef().id() == gt_h.
id())
452 float dz,
dxy, dzError, dxyError;
457 if (polarP4.pt() < pT_cut_)
465 getIsolation(polarP4, pc, ipc, isolationDR03, miniIso);
468 if (polarP4.pt() < pT_cut_noIso_ && !(isolationDR03.
chargedHadronIso() < absIso_cut_ ||
486 float caloJetEm, caloJetHad;
487 getCaloJetEnergy(polarP4,
caloJets.product(), caloJetEm, caloJetHad);
489 bool pfLepOverlap = getPFLeptonOverlap(polarP4, pc);
490 float pfNeutralSum = getPFNeutralSum(polarP4, pc, ipc);
493 int refToNearestPF_idx = -1;
494 getNearestPCRef(polarP4, pc, ipc, refToNearestPF_idx);
495 if (refToNearestPF_idx != -1)
499 int refToNearestLostTrack_idx = -1;
500 getNearestPCRef(polarP4, lt, -1, refToNearestLostTrack_idx);
501 if (refToNearestLostTrack_idx != -1)
506 float dEdxPixel = -1, dEdxStrip = -1;
508 std::vector<uint16_t> ecalStatus;
509 std::vector<uint32_t> hcalStatus;
537 refToNearestLostTrack));
539 dEdXass.push_back(-1);
543 if (saveDeDxHitInfo_) {
545 auto dedxMatch = std::make_unique<reco::DeDxHitInfoAss>(dedxOH);
547 filler.insert(orphHandle, dEdXass.begin(), dEdXass.end());
558 float chiso = 0, nhiso = 0, phiso = 0, puiso = 0;
559 float chmiso = 0, nhmiso = 0, phmiso = 0, pumiso = 0;
560 float miniDR =
std::max(miniIsoParams_[0],
std::min(miniIsoParams_[1], miniIsoParams_[2] /
p4.pt()));
561 for (pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++) {
562 if (
int(pf_it - pc->begin()) == pc_idx)
565 bool fromPV = (pf_it->fromPV() > 1 || fabs(pf_it->dz()) < pfIsolation_DZ_);
566 float pt = pf_it->p4().pt();
569 if (
dr < pfIsolation_DR_) {
603 bool isOverlap =
false;
604 float dr_min = pflepoverlap_DR_;
606 for (
const auto&
pf : *pc) {
615 if (
pt < pflepoverlap_pTmin_)
619 if (
dr > pflepoverlap_DR_)
628 if (dr_min < pflepoverlap_DR_ && (id_drmin == 11 || id_drmin == 13))
638 int& pc_ref_idx)
const {
639 float dr_min = pcRefNearest_DR_;
640 float dr_min_pu = pcRefNearest_DR_;
641 int pc_ref_idx_pu = -1;
642 for (pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++) {
643 if (
int(pf_it - pc->begin()) == pc_idx)
646 bool fromPV = (pf_it->fromPV() > 1 || fabs(pf_it->dz()) < pfIsolation_DZ_);
647 float pt = pf_it->p4().pt();
651 if (
pt < pcRefNearest_pTmin_)
653 if (
dr > dr_min &&
dr > dr_min_pu)
659 pc_ref_idx =
int(pf_it - pc->begin());
662 if (
dr < dr_min_pu) {
664 pc_ref_idx_pu =
int(pf_it - pc->begin());
669 if (pc_ref_idx == -1 &&
671 pc_ref_idx = pc_ref_idx_pu;
679 float nhsum = 0, phsum = 0;
680 for (pat::PackedCandidateCollection::const_iterator pf_it = pc->begin(); pf_it != pc->end(); pf_it++) {
681 if (
int(pf_it - pc->begin()) == pc_idx)
684 float pt = pf_it->p4().pt();
687 if (
dr < pfneutralsum_DR_) {
697 nsum = nhsum + phsum;
704 if (hitInfo ==
nullptr) {
708 std::vector<float> charge_vec;
709 for (
unsigned int ih = 0; ih < hitInfo->
size(); ih++) {
730 Norm = 3.61e-06 * 265;
736 int size = charge_vec.size();
741 for (
int i = 0;
i <
size;
i++) {
758 return trackAssociator_.associate(
iEvent, iSetup, trackAssocParameters_, &initialState);
764 float& caloJetHad)
const {
765 float nearestDR = 999;
767 for (
unsigned int i = 0;
i < cJets->size();
i++) {
769 if (
dR < caloJet_DR_ &&
dR < nearestDR) {