12 #include "TMatrixDSym.h" 13 #include "TMatrixDSymEigen.h" 23 : cutBased_(ps.getParameter<
bool>(
"cutBased")),
24 etaBinnedWeights_(
false),
27 label_(ps.getParameter<
std::
string>(
"label")),
31 std::vector<edm::FileInPath> tmvaEtaWeights;
36 etaBinnedWeights_ = ps.getParameter<
bool>(
"etaBinnedWeights");
37 if (etaBinnedWeights_) {
38 const std::vector<edm::ParameterSet>&
trainings = ps.getParameter<std::vector<edm::ParameterSet> >(
"trainings");
39 nEtaBins_ = ps.getParameter<
int>(
"nEtaBins");
40 for (
int v = 0;
v < nEtaBins_;
v++) {
42 jEtaMin_.push_back(
trainings.at(
v).getParameter<
double>(
"jEtaMin"));
43 jEtaMax_.push_back(
trainings.at(
v).getParameter<
double>(
"jEtaMax"));
45 for (
int v = 0;
v < nEtaBins_;
v++) {
46 tmvaEtaVariables_.push_back(
trainings.at(
v).getParameter<std::vector<std::string> >(
"tmvaVariables"));
49 tmvaVariables_ = ps.getParameter<std::vector<std::string> >(
"tmvaVariables");
51 tmvaMethod_ = ps.getParameter<
std::string>(
"tmvaMethod");
52 tmvaSpectators = ps.getParameter<std::vector<std::string> >(
"tmvaSpectators");
53 version = ps.getParameter<
int>(
"version");
59 for (
int i0 = 0; i0 < 3; i0++) {
68 for (
int i1 = 0;
i1 < nCut;
i1++) {
70 if (cutBased_ &&
i1 == 0)
71 lFullCutType =
"BetaStar" + lCutType;
72 if (cutBased_ &&
i1 == 1)
73 lFullCutType =
"RMS" + lCutType;
74 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" + lFullCutType).c_str());
75 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_" + lFullCutType).c_str());
76 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_" + lFullCutType).c_str());
77 std::vector<double> pt3040 = jetConfig.
getParameter<std::vector<double> >((
"Pt3040_" + lFullCutType).c_str());
78 std::vector<double> pt4050 = jetConfig.
getParameter<std::vector<double> >((
"Pt4050_" + lFullCutType).c_str());
80 for (
int i2 = 0;
i2 < 4;
i2++)
81 mvacut_[i0][0][
i2] = pt010[
i2];
82 for (
int i2 = 0;
i2 < 4;
i2++)
83 mvacut_[i0][1][
i2] = pt1020[
i2];
84 for (
int i2 = 0;
i2 < 4;
i2++)
85 mvacut_[i0][2][
i2] = pt2030[
i2];
86 for (
int i2 = 0;
i2 < 4;
i2++)
87 mvacut_[i0][3][
i2] = pt3040[
i2];
88 for (
int i2 = 0;
i2 < 4;
i2++)
89 mvacut_[i0][4][
i2] = pt4050[
i2];
91 if (cutBased_ &&
i1 == 0) {
92 for (
int i2 = 0;
i2 < 4;
i2++)
93 betaStarCut_[i0][0][
i2] = pt010[
i2];
94 for (
int i2 = 0;
i2 < 4;
i2++)
95 betaStarCut_[i0][1][
i2] = pt1020[
i2];
96 for (
int i2 = 0;
i2 < 4;
i2++)
97 betaStarCut_[i0][2][
i2] = pt2030[
i2];
98 for (
int i2 = 0;
i2 < 4;
i2++)
99 betaStarCut_[i0][3][
i2] = pt3040[
i2];
100 for (
int i2 = 0;
i2 < 4;
i2++)
101 betaStarCut_[i0][4][
i2] = pt4050[
i2];
103 if (cutBased_ &&
i1 == 1) {
104 for (
int i2 = 0;
i2 < 4;
i2++)
105 rmsCut_[i0][0][
i2] = pt010[
i2];
106 for (
int i2 = 0;
i2 < 4;
i2++)
107 rmsCut_[i0][1][
i2] = pt1020[
i2];
108 for (
int i2 = 0;
i2 < 4;
i2++)
109 rmsCut_[i0][2][
i2] = pt2030[
i2];
110 for (
int i2 = 0;
i2 < 4;
i2++)
111 rmsCut_[i0][3][
i2] = pt3040[
i2];
112 for (
int i2 = 0;
i2 < 4;
i2++)
113 rmsCut_[i0][4][
i2] = pt4050[
i2];
119 assert(tmvaMethod_.empty() || ((!tmvaVariables_.empty() || (!tmvaEtaVariables_.empty())) &&
version ==
USER));
122 if ((!cutBased_) && (runMvas_)) {
123 if (etaBinnedWeights_) {
124 for (
int v = 0;
v < nEtaBins_;
v++) {
139 void assign(
const std::vector<float>& vec,
float&
a,
float&
b,
float&
c,
float&
d) {
140 size_t sz = vec.size();
141 a = (sz > 0 ? vec[0] : 0.);
142 b = (sz > 1 ? vec[1] : 0.);
143 c = (sz > 2 ? vec[2] : 0.);
144 d = (sz > 3 ? vec[3] : 0.);
159 const std::unique_ptr<const GBRForest>&
reader) {
160 std::vector<float>
vars;
161 for (std::vector<std::string>::const_iterator
it = varList.begin();
it != varList.end(); ++
it) {
216 return std::pair<int, int>(ptId, etaId);
221 float betaStarModified = betaStarClassic /
log(nvtx - 0.64);
267 bool applyConstituentWeight) {
274 assert(patjet !=
nullptr || pfjet !=
nullptr);
275 if (patjet !=
nullptr &&
jec == 0.) {
282 const reco::Candidate *lLead =
nullptr, *lSecond =
nullptr, *lLeadNeut =
nullptr, *lLeadEm =
nullptr,
283 *lLeadCh =
nullptr, *lTrail =
nullptr;
285 std::vector<float>
frac, fracCh, fracEm, fracNeut;
286 float cones[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7};
287 size_t ncones =
sizeof(cones) /
sizeof(
float);
316 TMatrixDSym covMatrix(2);
319 float sumPt = 0., sumPt2 = 0., sumTkPt = 0., sumPtCh = 0, sumPtNe = 0;
320 float multNeut = 0.0;
322 float sum_deta(0.0), sum_dphi(0.0);
323 float ave_deta(0.0), ave_dphi(0.0);
331 float LeadcandWeight = 1.0;
332 float SecondcandWeight = 1.0;
333 float LeadNeutcandWeight = 1.0;
334 float LeadEmcandWeight = 1.0;
335 float LeadChcandWeight = 1.0;
336 float TrailcandWeight = 1.0;
338 for (
unsigned i = 0;
i <
jet->numberOfSourceCandidatePtrs(); ++
i) {
343 bool isPacked =
true;
344 if (lPack ==
nullptr) {
348 float candWeight = 1.0;
349 if (applyConstituentWeight) {
350 candWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
352 float candPt = (icand->
pt()) * candWeight;
353 float candPtFrac = candPt /
jetPt;
355 float candDeta = icand->
eta() -
jet->eta();
357 float candPtDr = candPt * candDr;
358 size_t icone =
std::lower_bound(&cones[0], &cones[ncones], candDr) - &cones[0];
364 if (lLead ==
nullptr || candPt > (lLead->
pt()) * LeadcandWeight) {
366 SecondcandWeight = LeadcandWeight;
368 if (applyConstituentWeight) {
369 LeadcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
371 }
else if ((lSecond ==
nullptr || candPt > (lSecond->pt()) * SecondcandWeight) &&
372 (candPt < (lLead->
pt()) * LeadcandWeight)) {
374 if (applyConstituentWeight) {
375 SecondcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
382 covMatrix(0, 0) += candPt * candPt * candDeta * candDeta;
383 covMatrix(0, 1) += candPt * candPt * candDeta * candDphi;
384 covMatrix(1, 1) += candPt * candPt * candDphi * candDphi;
387 sumPt2 += candPt * candPt;
390 frac.push_back(candPtFrac);
392 if (icone < ncones) {
393 *coneFracs[icone] += candPt;
398 if (lLeadNeut ==
nullptr || candPt > (lLeadNeut->pt()) * LeadNeutcandWeight) {
400 if (applyConstituentWeight) {
401 LeadNeutcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
406 fracNeut.push_back(candPtFrac);
407 if (icone < ncones) {
408 *coneNeutFracs[icone] += candPt;
412 multNeut += candWeight;
416 if (icand->
pdgId() == 22) {
417 if (lLeadEm ==
nullptr || candPt > (lLeadEm->pt()) * LeadEmcandWeight) {
419 if (applyConstituentWeight) {
420 LeadEmcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
424 fracEm.push_back(candPtFrac);
425 if (icone < ncones) {
426 *coneEmFracs[icone] += candPt;
430 multNeut += candWeight;
434 multNeut += candWeight;
437 if (icand->
charge() != 0) {
438 if (lLeadCh ==
nullptr || candPt > (lLeadCh->pt()) * LeadChcandWeight) {
440 if (applyConstituentWeight) {
441 LeadChcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
444 if (lPF &&
std::abs(icand->
pdgId()) == 13 && pfTrk ==
nullptr) {
450 <<
"Found a PFCandidate muon without a trackRef: falling back to Muon::bestTrack ";
453 if (pfTrk ==
nullptr) {
458 }
else if (lPF !=
nullptr) {
470 fracCh.push_back(candPtFrac);
471 if (icone < ncones) {
472 *coneChFracs[icone] += candPt;
477 if (icand->
charge() != 0) {
483 bool inVtx0 =
vtx->trackWeight(lPF->
trackRef()) > 0;
485 bool inAnyOther =
false;
489 for (reco::VertexCollection::const_iterator vi = allvtx.begin(); vi != allvtx.end(); ++vi) {
491 if (
iv.isFake() ||
iv.ndof() < 4) {
495 bool isVtx0 = (
iv.position() -
vtx->position()).
r() < 0.02;
498 if (!isVtx0 && !inAnyOther) {
499 inAnyOther =
vtx->trackWeight(lPF->
trackRef()) <= 0;
505 if (inVtx0 && !inAnyOther) {
507 }
else if (!inVtx0 && inAnyOther) {
513 }
else if (
dZ < 0.2) {
521 bool inVtxOther =
false;
523 double dZ_tmp = 9999.;
524 for (
unsigned vtx_i = 0; vtx_i < allvtx.size(); vtx_i++) {
525 const auto&
iv = allvtx[vtx_i];
531 bool isVtx0 = (
iv.position() -
vtx->position()).
r() < 0.02;
536 if (lPack->
fromPV(vtx_i) == 0)
538 dZ0 = lPack->
dz(
iv.position());
541 if (fabs(lPack->
dz(
iv.position())) < fabs(dZ_tmp)) {
542 dZ_tmp = lPack->
dz(
iv.position());
547 }
else if (inVtxOther) {
550 if (fabs(dZ0) < 0.2) {
552 }
else if (fabs(dZ_tmp) < 0.2) {
559 if (lTrail ==
nullptr || candPt < (lTrail->pt()) * TrailcandWeight) {
561 if (applyConstituentWeight) {
562 TrailcandWeight = constituentWeights[
jet->sourceCandidatePtr(
i)];
568 float weight2 = candPt * candPt;
570 float deta = icand->
eta() -
jet->eta();
572 sum_deta += deta * weight2;
573 sum_dphi += dphi * weight2;
576 ave_deta = sum_deta / sumW2;
577 ave_dphi = sum_dphi / sumW2;
583 assert(!(lLead ==
nullptr));
588 if (lSecond !=
nullptr) {
598 if (lLeadNeut !=
nullptr) {
608 if (lLeadEm !=
nullptr) {
618 if (lLeadCh !=
nullptr) {
628 if (patjet !=
nullptr) {
635 if (applyConstituentWeight)
644 if (applyConstituentWeight)
650 float ddetaR_sum(0.0), ddphiR_sum(0.0), pull_tmp(0.0);
651 for (
unsigned k = 0;
k <
jet->numberOfSourceCandidatePtrs();
k++) {
656 float candWeight = 1.0;
658 if (applyConstituentWeight)
659 candWeight = constituentWeights[
jet->sourceCandidatePtr(
k)];
661 float weight = candWeight * (
part->pt()) * candWeight * (
part->pt());
662 float deta =
part->eta() -
jet->eta();
664 float ddeta, ddphi, ddR;
665 ddeta = deta - ave_deta;
666 ddphi = dphi - ave_dphi;
667 ddR =
sqrt(ddeta * ddeta + ddphi * ddphi);
668 ddetaR_sum += ddR * ddeta *
weight;
669 ddphiR_sum += ddR * ddphi *
weight;
672 float ddetaR_ave = ddetaR_sum / sumW2;
673 float ddphiR_ave = ddphiR_sum / sumW2;
674 pull_tmp =
sqrt(ddetaR_ave * ddetaR_ave + ddphiR_ave * ddphiR_ave);
680 std::sort(fracCh.begin(), fracCh.end(), std::greater<float>());
681 std::sort(fracEm.begin(), fracEm.end(), std::greater<float>());
682 std::sort(fracNeut.begin(), fracNeut.end(), std::greater<float>());
694 covMatrix(0, 0) /= sumPt2;
695 covMatrix(0, 1) /= sumPt2;
696 covMatrix(1, 1) /= sumPt2;
697 covMatrix(1, 0) = covMatrix(0, 1);
702 eigVals = TMatrixDSymEigen(covMatrix).GetEigenValues();
710 if (lSecond !=
nullptr) {
719 for (
size_t ic = 0; ic < ncones; ++ic) {
720 *coneFracs[ic] /=
jetPt;
721 *coneEmFracs[ic] /=
jetPt;
722 *coneNeutFracs[ic] /=
jetPt;
723 *coneChFracs[ic] /=
jetPt;
728 for (
unsigned int i0 = 0; i0 <
frac.size(); i0++) {
729 ptRMS += (
frac[i0] - ptMean) * (
frac[i0] - ptMean);
745 if (lLeadCh !=
nullptr) {
772 std::stringstream
out;
774 out << std::setw(15) <<
it->first << std::setw(3) <<
"=" << std::setw(5) << *
it->second.first <<
" (" 775 << std::setw(5) <<
it->second.second <<
")" << std::endl;
784 *
it->second.first =
it->second.second;
789 #define INIT_VARIABLE(NAME, TMVANAME, VAL) \ 790 internalId_.NAME##_ = VAL; \ 791 variables_[#NAME] = std::make_pair(&internalId_.NAME##_, VAL);
constexpr double deltaPhi(double phi1, double phi2)
void set(const PileupJetIdentifier &)
reco::GsfTrackRef gsfTrackRef() const
T getParameter(std::string const &) const
std::vector< double > const & jEtaMin() const
AlgoGBRForestsAndConstants const * cache_
#define INIT_VARIABLE(NAME, TMVANAME, VAL)
AlgoGBRForestsAndConstants(edm::ParameterSet const &, bool runMvas)
float neutralHadronEnergy() const
neutralHadronEnergy
double pt() const final
transverse momentum
int chargedMultiplicity() const
chargedMultiplicity
int chargedMultiplicity() const
chargedMultiplicity
float chargedEmEnergy() const
chargedEmEnergy
float neutralEmEnergy() const
neutralEmEnergy
virtual double pt() const =0
transverse momentum
Base class for all types of Jets.
std::string dumpVariables() const
std::pair< int, int > getJetIdKey(float jetPt, float jetEta)
bool isNonnull() const
Checks for non-null.
std::vector< Vertex > VertexCollection
collection of Vertex objects
const PVAssoc fromPV(size_t ipv=0) const
int neutralMultiplicity() const
neutralMultiplicity
bool etaBinnedWeights() const
int computeCutIDflag(float betaStarClassic, float dR2Mean, float nvtx, float jetPt, float jetEta)
const Track * bestTrack() const override
int neutralMultiplicity() const
neutralMultiplicity
Jets made from PFObjects.
void swap(Association< C > &lhs, Association< C > &rhs)
std::vector< std::vector< std::string > > const & tmvaEtaVariables() const
float chargedHadronEnergy() const
chargedHadronEnergy
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
PileupJetIdentifier internalId_
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho, edm::ValueMap< float > &constituentWeights, bool applyConstituentWeight)
array_t const & mvacut() const
Abs< T >::type abs(const T &t)
std::vector< std::string > const & tmvaVariables() const
void assign(const std::vector< float > &vec, float &a, float &b, float &c, float &d)
virtual int charge() const =0
electric charge
Jet correctedJet(const std::string &level, const std::string &flavor="none", const std::string &set="") const
float chargedEmEnergy() const
chargedEmEnergy
reco::MuonRef muonRef() const
int computeIDflag(float mva, float jetPt, float jetEta)
T const * get() const
Returns C++ pointer to the item.
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
virtual int pdgId() const =0
PDG identifier.
float neutralHadronEnergy() const
neutralHadronEnergy
void setPtEtaPhi(const reco::Candidate &p, float &pt, float &eta, float &phi)
static constexpr float d0
std::vector< std::unique_ptr< const GBRForest > > const & etaReader() const
PileupJetIdentifier computeMva()
Analysis-level calorimeter jet class.
std::unique_ptr< const GBRForest > const & reader() const
float neutralEmEnergy() const
neutralEmEnergy
Particle reconstructed by the particle flow algorithm.
float chargedHadronEnergy() const
chargedHadronEnergy
virtual const Track * bestTrack() const
T const * get() const
Returns C++ pointer to the item.
variables_list_t variables_
reco::TrackRef trackRef() const
virtual float dxy() const
dxy with respect to the PV ref
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
Log< level::Warning, false > LogWarning
std::vector< double > const & jEtaMax() const
float getMVAval(const std::vector< std::string > &, const std::unique_ptr< const GBRForest > &)
PileupJetIdAlgo(AlgoGBRForestsAndConstants const *cache)
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...