11 #include "TMatrixDSym.h" 12 #include "TMatrixDSymEigen.h" 22 : cutBased_(ps.getParameter<
bool>(
"cutBased")),
23 etaBinnedWeights_(
false),
26 label_(ps.getParameter<
std::
string>(
"label")),
30 std::vector<edm::FileInPath> tmvaEtaWeights;
37 const std::vector<edm::ParameterSet>&
trainings = ps.getParameter<std::vector<edm::ParameterSet> >(
"trainings");
38 nEtaBins_ = ps.getParameter<
int>(
"nEtaBins");
40 tmvaEtaWeights.push_back(trainings.at(
v).getParameter<
edm::FileInPath>(
"tmvaWeights"));
41 jEtaMin_.push_back(trainings.at(
v).getParameter<
double>(
"jEtaMin"));
42 jEtaMax_.push_back(trainings.at(
v).getParameter<
double>(
"jEtaMax"));
45 tmvaEtaVariables_.push_back(trainings.at(
v).getParameter<std::vector<std::string> >(
"tmvaVariables"));
48 tmvaVariables_ = ps.getParameter<std::vector<std::string> >(
"tmvaVariables");
51 tmvaSpectators = ps.getParameter<std::vector<std::string> >(
"tmvaSpectators");
52 version = ps.getParameter<
int>(
"version");
58 for (
int i0 = 0; i0 < 3; i0++) {
67 for (
int i1 = 0; i1 < nCut; i1++) {
70 lFullCutType =
"BetaStar" + lCutType;
72 lFullCutType =
"RMS" + lCutType;
73 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" + lFullCutType).c_str());
74 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_" + lFullCutType).c_str());
75 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_" + lFullCutType).c_str());
76 std::vector<double> pt3040 = jetConfig.
getParameter<std::vector<double> >((
"Pt3040_" + lFullCutType).c_str());
77 std::vector<double> pt4050 = jetConfig.
getParameter<std::vector<double> >((
"Pt4050_" + lFullCutType).c_str());
79 for (
int i2 = 0; i2 < 4; i2++)
81 for (
int i2 = 0; i2 < 4; i2++)
82 mvacut_[i0][1][i2] = pt1020[i2];
83 for (
int i2 = 0; i2 < 4; i2++)
84 mvacut_[i0][2][i2] = pt2030[i2];
85 for (
int i2 = 0; i2 < 4; i2++)
86 mvacut_[i0][3][i2] = pt3040[i2];
87 for (
int i2 = 0; i2 < 4; i2++)
88 mvacut_[i0][4][i2] = pt4050[i2];
91 for (
int i2 = 0; i2 < 4; i2++)
93 for (
int i2 = 0; i2 < 4; i2++)
95 for (
int i2 = 0; i2 < 4; i2++)
97 for (
int i2 = 0; i2 < 4; i2++)
99 for (
int i2 = 0; i2 < 4; i2++)
103 for (
int i2 = 0; i2 < 4; i2++)
104 rmsCut_[i0][0][i2] = pt010[i2];
105 for (
int i2 = 0; i2 < 4; i2++)
106 rmsCut_[i0][1][i2] = pt1020[i2];
107 for (
int i2 = 0; i2 < 4; i2++)
108 rmsCut_[i0][2][i2] = pt2030[i2];
109 for (
int i2 = 0; i2 < 4; i2++)
110 rmsCut_[i0][3][i2] = pt3040[i2];
111 for (
int i2 = 0; i2 < 4; i2++)
112 rmsCut_[i0][4][i2] = pt4050[i2];
138 void assign(
const std::vector<float>& vec,
float&
a,
float&
b,
float&
c,
float&
d) {
139 size_t sz = vec.size();
140 a = (sz > 0 ? vec[0] : 0.);
141 b = (sz > 1 ? vec[1] : 0.);
142 c = (sz > 2 ? vec[2] : 0.);
143 d = (sz > 3 ? vec[3] : 0.);
158 const std::unique_ptr<const GBRForest>&
reader) {
159 std::vector<float>
vars;
160 for (std::vector<std::string>::const_iterator it = varList.begin(); it != varList.end(); ++it) {
162 vars.push_back(*var.first);
164 return reader->GetClassifier(vars.data());
198 if (jetPt >= 10 && jetPt < 20)
200 if (jetPt >= 20 && jetPt < 30)
202 if (jetPt >= 30 && jetPt < 40)
215 return std::pair<int, int>(ptId, etaId);
219 std::pair<int, int> jetIdKey =
getJetIdKey(jetPt, jetEta);
220 float betaStarModified = betaStarClassic /
log(nvtx - 0.64);
237 std::pair<int, int> jetIdKey =
getJetIdKey(jetPt, jetEta);
272 assert(patjet !=
nullptr || pfjet !=
nullptr);
273 if (patjet !=
nullptr && jec == 0.) {
280 const reco::Candidate *lLead =
nullptr, *lSecond =
nullptr, *lLeadNeut =
nullptr, *lLeadEm =
nullptr,
281 *lLeadCh =
nullptr, *lTrail =
nullptr;
282 std::vector<float>
frac, fracCh, fracEm, fracNeut;
283 float cones[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7};
284 size_t ncones =
sizeof(cones) /
sizeof(
float);
313 TMatrixDSym covMatrix(2);
316 float sumPt = 0., sumPt2 = 0., sumTkPt = 0., sumPtCh = 0, sumPtNe = 0;
317 float multNeut = 0.0;
332 bool isPacked =
true;
333 if (lPack ==
nullptr) {
336 float candPuppiWeight = 1.0;
337 if (usePuppi && isPacked)
339 float candPt = (icand->
pt()) * candPuppiWeight;
340 float candPtFrac = candPt /
jetPt;
342 float candDeta = icand->
eta() - jet->
eta();
344 float candPtDr = candPt * candDr;
345 size_t icone =
std::lower_bound(&cones[0], &cones[ncones], candDr) - &cones[0];
351 if (lLead ==
nullptr || candPt > lLead->
pt()) {
354 }
else if ((lSecond ==
nullptr || candPt > lSecond->pt()) && (candPt < lLead->
pt())) {
361 covMatrix(0, 0) += candPt * candPt * candDeta * candDeta;
362 covMatrix(0, 1) += candPt * candPt * candDeta * candDphi;
363 covMatrix(1, 1) += candPt * candPt * candDphi * candDphi;
366 sumPt2 += candPt * candPt;
369 frac.push_back(candPtFrac);
371 if (icone < ncones) {
372 *coneFracs[icone] += candPt;
377 if (lLeadNeut ==
nullptr || candPt > lLeadNeut->pt()) {
381 fracNeut.push_back(candPtFrac);
382 if (icone < ncones) {
383 *coneNeutFracs[icone] += candPt;
387 multNeut += candPuppiWeight;
390 if (icand->
pdgId() == 22) {
391 if (lLeadEm ==
nullptr || candPt > lLeadEm->pt()) {
395 fracEm.push_back(candPtFrac);
396 if (icone < ncones) {
397 *coneEmFracs[icone] += candPt;
401 multNeut += candPuppiWeight;
404 multNeut += candPuppiWeight;
407 if (icand->
charge() != 0) {
408 if (lLeadCh ==
nullptr || candPt > lLeadCh->pt()) {
412 if (lPF &&
std::abs(icand->
pdgId()) == 13 && pfTrk ==
nullptr) {
418 <<
"Found a PFCandidate muon without a trackRef: falling back to Muon::bestTrack ";
421 if (pfTrk ==
nullptr) {
426 }
else if (lPF !=
nullptr) {
438 fracCh.push_back(candPtFrac);
439 if (icone < ncones) {
440 *coneChFracs[icone] += candPt;
445 if (icand->
charge() != 0) {
453 bool inAnyOther =
false;
457 for (reco::VertexCollection::const_iterator vi = allvtx.begin(); vi != allvtx.end(); ++vi) {
466 if (!isVtx0 && !inAnyOther) {
473 if (inVtx0 && !inAnyOther) {
475 }
else if (!inVtx0 && inAnyOther) {
481 }
else if (dZ < 0.2) {
489 bool inVtxOther =
false;
491 double dZ_tmp = 9999.;
492 for (
unsigned vtx_i = 0; vtx_i < allvtx.size(); vtx_i++) {
493 auto iv = allvtx[vtx_i];
499 bool isVtx0 = (iv.position() - vtx->
position()).
r() < 0.02;
504 if (lPack->
fromPV(vtx_i) == 0)
506 dZ0 = lPack->
dz(iv.position());
509 if (fabs(lPack->
dz(iv.position())) < fabs(dZ_tmp)) {
510 dZ_tmp = lPack->
dz(iv.position());
515 }
else if (inVtxOther) {
518 if (fabs(dZ0) < 0.2) {
520 }
else if (fabs(dZ_tmp) < 0.2) {
527 if (lTrail ==
nullptr || candPt < lTrail->
pt()) {
533 assert(!(lLead ==
nullptr));
535 if (lSecond ==
nullptr) {
538 if (lLeadNeut ==
nullptr) {
541 if (lLeadEm ==
nullptr) {
544 if (lLeadCh ==
nullptr) {
548 if (patjet !=
nullptr) {
569 float sum_deta(0.0), sum_dphi(0.0);
570 float ave_deta(0.0), ave_dphi(0.0);
573 if (!(
part.isAvailable() &&
part.isNonnull())) {
577 float partPuppiWeight = 1.0;
580 if (partpack !=
nullptr)
584 float weight = (
part->pt()) * partPuppiWeight;
585 float weight2 = weight *
weight;
587 float deta =
part->eta() - jet->
eta();
589 sum_deta += deta * weight2;
590 sum_dphi += dphi * weight2;
592 ave_deta = sum_deta / sumW2;
593 ave_dphi = sum_dphi / sumW2;
597 float ddetaR_sum(0.0), ddphiR_sum(0.0), pull_tmp(0.0);
600 if (!(
part.isAvailable() &&
part.isNonnull())) {
604 float partPuppiWeight = 1.0;
607 if (partpack !=
nullptr)
611 float weight = partPuppiWeight * (
part->pt()) * partPuppiWeight * (
part->pt());
612 float deta =
part->eta() - jet->
eta();
614 float ddeta, ddphi, ddR;
615 ddeta = deta - ave_deta;
616 ddphi = dphi - ave_dphi;
617 ddR =
sqrt(ddeta * ddeta + ddphi * ddphi);
618 ddetaR_sum += ddR * ddeta *
weight;
619 ddphiR_sum += ddR * ddphi *
weight;
622 float ddetaR_ave = ddetaR_sum / sumW2;
623 float ddphiR_ave = ddphiR_sum / sumW2;
624 pull_tmp =
sqrt(ddetaR_ave * ddetaR_ave + ddphiR_ave * ddphiR_ave);
635 std::sort(frac.begin(), frac.end(), std::greater<float>());
636 std::sort(fracCh.begin(), fracCh.end(), std::greater<float>());
637 std::sort(fracEm.begin(), fracEm.end(), std::greater<float>());
638 std::sort(fracNeut.begin(), fracNeut.end(), std::greater<float>());
650 covMatrix(0, 0) /= sumPt2;
651 covMatrix(0, 1) /= sumPt2;
652 covMatrix(1, 1) /= sumPt2;
653 covMatrix(1, 0) = covMatrix(0, 1);
658 eigVals = TMatrixDSymEigen(covMatrix).GetEigenValues();
666 if (lSecond ==
nullptr) {
675 for (
size_t ic = 0; ic < ncones; ++ic) {
676 *coneFracs[ic] /=
jetPt;
677 *coneEmFracs[ic] /=
jetPt;
678 *coneNeutFracs[ic] /=
jetPt;
679 *coneChFracs[ic] /=
jetPt;
684 for (
unsigned int i0 = 0; i0 < frac.size(); i0++) {
685 ptRMS += (frac[i0] - ptMean) * (frac[i0] - ptMean);
723 std::stringstream
out;
725 out << std::setw(15) << it->first << std::setw(3) <<
"=" << std::setw(5) << *it->second.first <<
" (" 726 << std::setw(5) << it->second.second <<
")" << std::endl;
735 *it->second.first = it->second.second;
740 #define INIT_VARIABLE(NAME, TMVANAME, VAL) \ 741 internalId_.NAME##_ = VAL; \ 742 variables_[#NAME] = std::make_pair(&internalId_.NAME##_, VAL); float puppiWeight() const
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
constexpr double deltaPhi(double phi1, double phi2)
T getParameter(std::string const &) const
void set(const PileupJetIdentifier &)
bool isNonnull() const
Checks for non-null.
AlgoGBRForestsAndConstants const * cache_
double eta() const final
momentum pseudorapidity
#define INIT_VARIABLE(NAME, TMVANAME, VAL)
AlgoGBRForestsAndConstants(edm::ParameterSet const &, bool runMvas)
float chargedHadronEnergy() const
chargedHadronEnergy
float chargedEmEnergy() const
chargedEmEnergy
std::vector< double > const & jEtaMin() const
float neutralEmEnergy() const
neutralEmEnergy
std::vector< std::unique_ptr< const GBRForest > > etaReader_
virtual const Track * bestTrack() const
T const * get() const
Returns C++ pointer to the item.
Base class for all types of Jets.
float neutralHadronEnergy() const
neutralHadronEnergy
std::pair< int, int > getJetIdKey(float jetPt, float jetEta)
size_type numberOfSourceCandidatePtrs() const override
std::vector< double > jEtaMin_
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
int neutralMultiplicity() const
neutralMultiplicity
int computeCutIDflag(float betaStarClassic, float dR2Mean, float nvtx, float jetPt, float jetEta)
std::vector< double > const & jEtaMax() const
int chargedMultiplicity() const
chargedMultiplicity
const Track * bestTrack() const override
const Point & position() const
position
Jets made from PFObjects.
float neutralEmEnergy() const
neutralEmEnergy
float chargedEmEnergy() const
chargedEmEnergy
size_t numberOfDaughters() const override
number of daughters
reco::TrackRef trackRef() const
std::vector< std::string > tmvaVariables_
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho, bool usePuppi)
PileupJetIdentifier internalId_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual int pdgId() const =0
PDG identifier.
const PVAssoc fromPV(size_t ipv=0) const
std::string dumpVariables() const
float betaStarCut_[3][5][4]
double energy() const final
energy
Abs< T >::type abs(const T &t)
void assign(const std::vector< float > &vec, float &a, float &b, float &c, float &d)
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
T const * get() const
Returns C++ pointer to the item.
std::unique_ptr< const GBRForest > const & reader() const
std::vector< std::vector< std::string > > tmvaEtaVariables_
int computeIDflag(float mva, float jetPt, float jetEta)
int neutralMultiplicity() const
neutralMultiplicity
array_t const & mvacut() const
reco::MuonRef muonRef() const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
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...
void setPtEtaPhi(const reco::Candidate &p, float &pt, float &eta, float &phi)
virtual double eta() const =0
momentum pseudorapidity
virtual double pt() const =0
transverse momentum
virtual CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
PileupJetIdentifier computeMva()
Analysis-level calorimeter jet class.
std::vector< std::unique_ptr< const GBRForest > > const & etaReader() const
virtual int charge() const =0
electric charge
Particle reconstructed by the particle flow algorithm.
virtual int nConstituents() const
of constituents
reco::GsfTrackRef gsfTrackRef() const
CandidatePtr sourceCandidatePtr(size_type i) const override
std::vector< std::vector< std::string > > const & tmvaEtaVariables() const
variables_list_t variables_
float neutralHadronEnergy() const
neutralHadronEnergy
bool etaBinnedWeights() const
virtual float dxy() const
dxy with respect to the PV ref
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Jet correctedJet(const std::string &level, const std::string &flavor="none", const std::string &set="") const
std::vector< std::string > const & tmvaVariables() const
float getMVAval(const std::vector< std::string > &, const std::unique_ptr< const GBRForest > &)
virtual double phi() const =0
momentum azimuthal angle
int chargedMultiplicity() const
chargedMultiplicity
float chargedHadronEnergy() const
chargedHadronEnergy
std::unique_ptr< const GBRForest > reader_
PileupJetIdAlgo(AlgoGBRForestsAndConstants const *cache)
double mass() const final
mass
std::vector< double > jEtaMax_