11 template <
typename T1,
typename T2>
12 float floatDR(
const T1 &
t1,
const T2 &
t2) {
13 return deltaR(
t1.floatEta(),
t1.floatPhi(),
t2.floatEta(),
t2.floatPhi());
25 if (muMatchMode ==
"boxBestByPtRatio")
27 else if (muMatchMode ==
"drBestByPtRatio")
29 else if (muMatchMode ==
"drBestByPtDiff")
32 throw cms::Exception(
"Configuration",
"bad value for trackMuMatch configurable");
35 if (tkCaloLinkMetric ==
"bestByDR")
37 else if (tkCaloLinkMetric ==
"bestByDRPt")
39 else if (tkCaloLinkMetric ==
"bestByDR2Pt2")
42 throw cms::Exception(
"Configuration",
"bad value for tkCaloLinkMetric configurable");
69 "PFAlgo2HGC\nPFAlgo2HGC region eta [ %+5.2f , %+5.2f ], phi [ %+5.2f , %+5.2f ], fiducial eta [ %+5.2f , "
70 "%+5.2f ], phi [ %+5.2f , %+5.2f ]\n",
71 r.etaMin -
r.etaExtra,
72 r.etaMax +
r.etaExtra,
73 r.phiCenter -
r.phiHalfWidth -
r.phiExtra,
74 r.phiCenter +
r.phiHalfWidth +
r.phiExtra,
77 r.phiCenter -
r.phiHalfWidth,
78 r.phiCenter +
r.phiHalfWidth);
80 "PFAlgo2HGC \t N(track) %3lu N(calo) %3lu N(mu) %3lu\n",
r.track.size(),
r.calo.size(),
r.muon.size());
81 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
82 const auto &tk =
r.track[itk];
84 "PFAlgo2HGC \t track %3d: pt %7.2f +- %5.2f vtx eta %+5.2f vtx phi %+5.2f calo eta %+5.2f calo phi "
85 "%+5.2f fid %1d calo ptErr %7.2f stubs %2d chi2 %7.1f\n",
93 int(
r.fiducialLocal(tk.floatEta(), tk.floatPhi())),
98 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
99 auto &
calo =
r.calo[ic];
101 "PFAlgo2HGC \t calo %3d: pt %7.2f +- %5.2f vtx eta %+5.2f vtx phi %+5.2f calo eta %+5.2f calo phi "
102 "%+5.2f fid %1d calo ptErr %7.2f em pt %7.2f isEM %1d \n",
115 for (
int im = 0, nm =
r.muon.size(); im < nm; ++im) {
116 auto &
mu =
r.muon[im];
118 "PFAlgo2HGC \t muon %3d: pt %7.2f vtx eta %+5.2f vtx phi %+5.2f calo eta %+5.2f calo phi "
126 int(
r.fiducialLocal(
mu.floatEta(),
mu.floatPhi())));
130 std::vector<int> tk2mu(
r.track.size(), -1), mu2tk(
r.muon.size(), -1);
134 std::vector<int> tk2calo(
r.track.size(), -1);
139 std::vector<int> calo2ntk(
r.calo.size(), 0);
140 std::vector<float> calo2sumtkpt(
r.calo.size(), 0);
141 std::vector<float> calo2sumtkpterr(
r.calo.size(), 0);
142 sum_tk2calo(
r, tk2calo, calo2ntk, calo2sumtkpt, calo2sumtkpterr);
151 calo_relink(
r, calo2ntk, calo2sumtkpt, calo2sumtkpterr);
155 std::vector<float> calo2alpha(
r.calo.size(), 1);
170 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
173 for (
int imu = 0, nmu =
r.muon.size(); imu < nmu; ++imu) {
174 const auto &
mu =
r.muon[imu];
176 dbgPrintf(
"PFAlgo2HGC \t muon %3d (pt %7.2f, eta %+5.2f, phi %+5.2f) \n",
181 float minDistance = 9e9;
190 minDistance = 0.5 *
mu.floatPt();
194 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
195 const auto &tk =
r.track[itk];
197 int dphi =
std::abs((
mu.hwPhi - tk.hwPhi) % CaloCluster::PHI_WRAP);
198 float dr = floatDR(
mu, tk);
199 float dpt =
std::abs(
mu.floatPt() - tk.floatPt());
200 float dptr = (
mu.hwPt > tk.hwPt ?
mu.floatPt() / tk.floatPt() : tk.floatPt() /
mu.floatPt());
205 ok = (deta < intDrMuonMatchBox) && (dphi < intDrMuonMatchBox);
219 "PFAlgo2HGC \t\t possible match with track %3d (pt %7.2f, caloeta %+5.2f, calophi %+5.2f, dr %.2f, eta "
220 "%+5.2f, phi %+5.2f, dr %.2f): angular %1d, distance %.3f (vs %.3f)\n",
228 deltaR(
mu.floatEta(),
mu.floatPhi(), tk.floatVtxEta(), tk.floatVtxPhi()),
241 if (
debug_ && imatch > -1)
242 dbgPrintf(
"PFAlgo2HGC \t muon %3d (pt %7.2f) linked to track %3d (pt %7.2f)\n",
246 r.track[imatch].floatPt());
247 if (
debug_ && imatch == -1)
248 dbgPrintf(
"PFAlgo2HGC \t muon %3d (pt %7.2f) not linked to any track\n", imu,
mu.floatPt());
252 r.track[imatch].muonLink =
true;
259 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
260 const auto &tk =
r.track[itk];
261 if (tk.muonLink || tk.used)
263 float drbest =
drMatch_, dptscale = 0;
270 dptscale =
drMatch_ / tk.floatCaloPtErr();
274 dptscale =
drMatch_ / tk.floatCaloPtErr();
277 float minCaloPt = tk.floatPt() -
ptMatchLow_ * tk.floatCaloPtErr();
280 "PFAlgo2HGC \t track %3d (pt %7.2f) to be matched to calo, min pT %7.2f\n", itk, tk.floatPt(), minCaloPt);
281 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
282 auto &
calo =
r.calo[ic];
283 if (
calo.used ||
calo.floatPt() <= minCaloPt)
285 float dr = floatDR(tk,
calo), dq;
294 dq =
dr + std::max<float>(tk.floatPt() -
calo.floatPt(), 0.) * dptscale;
296 dbgPrintf(
"PFAlgo2HGC \t\t\t track %3d (pt %7.2f) vs calo %3d (pt %7.2f): dr %.3f, dq %.3f\n",
309 dq = hypot(
dr, std::max<float>(tk.floatPt() -
calo.floatPt(), 0.) * dptscale);
311 dbgPrintf(
"PFAlgo2HGC \t\t\t track %3d (pt %7.2f) vs calo %3d (pt %7.2f): dr %.3f, dq %.3f\n",
325 if (
debug_ && tk2calo[itk] != -1)
326 dbgPrintf(
"PFAlgo2HGC \t track %3d (pt %7.2f) matches to calo %3d (pt %7.2f) with dist %.3f (dr %.3f)\n",
330 r.calo[tk2calo[itk]].floatPt(),
332 floatDR(tk,
r.calo[tk2calo[itk]]));
334 if (
debug_ && tk2calo[itk] == -1) {
337 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
338 auto &
calo =
r.calo[ic];
341 float dr = floatDR(tk,
calo);
349 "PFAlgo2HGC \t track %3d (pt %7.2f) would match to calo %3d (pt %7.2f) with dr %.3f if the pt min and dr "
350 "requirement had been relaxed\n",
354 r.calo[ibest].floatPt(),
361 const std::vector<int> &tk2calo,
362 std::vector<int> &calo2ntk,
363 std::vector<float> &calo2sumtkpt,
364 std::vector<float> &calo2sumtkpterr)
const {
366 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
367 const auto &
calo =
r.calo[ic];
368 if (
r.globalAbsEta(
calo.floatEta()) > 2.5)
370 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
371 if (tk2calo[itk] == ic) {
372 const auto &tk =
r.track[itk];
373 if (tk.muonLink || tk.used)
376 calo2sumtkpt[ic] += tk.floatPt();
381 calo2sumtkpterr[ic] =
std::sqrt(calo2sumtkpterr[ic]);
387 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
388 auto &tk =
r.track[itk];
389 if (tk2calo[itk] != -1 || tk.muonLink || tk.used)
394 if (tk.floatPt() <
maxPt) {
397 "PFAlgo2HGC \t track %3d (pt %7.2f) not matched to calo, kept as charged hadron\n", itk, tk.floatPt());
403 dbgPrintf(
"PFAlgo2HGC \t track %3d (pt %7.2f) not matched to calo, dropped\n", itk, tk.floatPt());
409 const std::vector<int> &calo2ntk,
410 const std::vector<float> &calo2sumtkpt,
411 const std::vector<float> &calo2sumtkpterr)
const {
416 std::vector<float> addtopt(
r.calo.size(), 0);
417 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
418 auto &
calo =
r.calo[ic];
419 if (calo2ntk[ic] != 0 ||
calo.used ||
r.globalAbsEta(
calo.floatEta()) > 2.5)
423 for (
int ic2 = 0; ic2 < nc; ++ic2) {
424 const auto &calo2 =
r.calo[ic2];
425 if (calo2ntk[ic2] == 0 || calo2.used ||
r.globalAbsEta(calo2.floatEta()) > 2.5)
427 float dr = floatDR(
calo, calo2);
432 calo2sumtkpt[ic2] - calo2.floatPt() + (
useTrackCaloSigma_ ? calo2sumtkpterr[ic2] : calo2.floatPtErr());
440 const auto &calo2 =
r.calo[i2best];
443 "PFAlgo2HGC \t calo %3d (pt %7.2f) with no tracks matched within dr %.3f with calo %3d with pt %7.2f (sum "
444 "tk pt %7.2f), track excess %7.2f +- %7.2f\n",
450 calo2sumtkpt[i2best],
451 calo2sumtkpt[i2best] - calo2.floatPt(),
454 addtopt[i2best] +=
calo.floatPt();
458 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
460 auto &
calo =
r.calo[ic];
462 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f, sum tk pt %7.2f) is increased to pt %7.2f after merging\n",
466 calo.floatPt() + addtopt[ic]);
467 calo.setFloatPt(
calo.floatPt() + addtopt[ic]);
473 const std::vector<int> &calo2ntk,
474 const std::vector<float> &calo2sumtkpt,
475 const std::vector<float> &calo2sumtkpterr,
476 std::vector<float> &calo2alpha)
const {
479 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
480 auto &
calo =
r.calo[ic];
481 if (calo2ntk[ic] == 0 ||
calo.used)
483 float ptdiff =
calo.floatPt() - calo2sumtkpt[ic];
487 "PFAlgo2HGC \t calo %3d (pt %7.2f +- %7.2f, empt %7.2f) has %2d tracks (sumpt %7.2f, sumpterr %7.2f), ptdif "
500 if (
calo.floatEmPt() > 1) {
504 "PFAlgo2HGC \t calo %3d (pt %7.2f, empt %7.2f) ---> make photon with pt %7.2f, reduce ptdiff to "
513 p.setFloatPt(emptdiff);
519 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f, empt %7.2f) ---> make also neutral hadron with pt %7.2f\n",
525 p.setFloatPt(ptdiff);
530 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f) ---> promoted to neutral with pt %7.2f\n",
535 p.setFloatPt(ptdiff);
543 "PFAlgo2HGC \t calo %3d (pt %7.2f) ---> to be deleted, will use tracks instead\n", ic,
calo.floatPt());
549 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f) ---> tracks overshoot and will be scaled down by %.4f\n",
554 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f) ---> tracks overshoot by %.4f\n",
557 calo2sumtkpt[ic] /
calo.floatPt());
564 const std::vector<int> &tk2calo,
565 const std::vector<int> &calo2ntk,
566 const std::vector<float> &calo2alpha)
const {
568 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
569 auto &tk =
r.track[itk];
570 if (tk2calo[itk] == -1 || tk.muonLink || tk.used)
574 const auto &
calo =
r.calo[tk2calo[itk]];
577 p.cluster.src =
calo.src;
578 if (
calo.hwFlags == 1) {
582 float ptavg = tk.floatPt();
583 if (tk.floatPtErr() > 0) {
584 float wcalo = 1.0 /
std::pow(tk.floatCaloPtErr(), 2);
585 float wtk = 1.0 /
std::pow(tk.floatPtErr(), 2);
586 ptavg = (
calo.floatPt() * wcalo + tk.floatPt() * wtk) / (wcalo + wtk);
592 "PFAlgo2HGC \t track %3d (pt %7.2f +- %7.2f) combined with calo %3d (pt %7.2f +- %7.2f (from tk) "
593 "yielding candidate of pt %7.2f\n",
604 dbgPrintf(
"PFAlgo2HGC \t track %3d (pt %7.2f) linked to calo %3d promoted to %s\n",
610 }
else if (
calo.hwFlags == 2) {
612 p.setFloatPt(tk.floatPt() * calo2alpha[tk2calo[itk]]);
616 "PFAlgo2HGC \t track %3d (pt %7.2f, stubs %2d chi2 %7.1f) linked to calo %3d promoted to %s with pt %7.2f "
617 "after maybe rescaling\n",
631 for (
int ic = 0, nc =
r.calo.size(); ic < nc; ++ic) {
632 if (!
r.calo[ic].used) {
635 dbgPrintf(
"PFAlgo2HGC \t calo %3d (pt %7.2f) not linked, promoted to neutral\n", ic,
r.calo[ic].floatPt());
642 for (
int itk = 0, ntk =
r.track.size(); itk < ntk; ++itk) {
643 if (
r.track[itk].muonLink) {
645 p.muonsrc =
r.muon[tk2mu[itk]].src;
647 dbgPrintf(
"PFAlgo2HGC \t track %3d (pt %7.2f) promoted to muon.\n", itk,
r.track[itk].floatPt());