10 #include "TMatrixDSym.h" 11 #include "TMatrixDSymEigen.h" 26 for (
int i0 = 0; i0 <
NWPs; i0++) {
32 for (
int i1 = 0;
i1 < 1;
i1++) {
33 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" + lCutType).c_str());
34 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_" + lCutType).c_str());
35 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_" + lCutType).c_str());
36 std::vector<double> pt3050 = jetConfig.
getParameter<std::vector<double> >((
"Pt3050_" + lCutType).c_str());
53 Float_t impactParTkThreshod,
111 void Assign(
const std::vector<float> &vec,
float &
a,
float &
b,
float &
c,
float &
d) {
112 size_t sz = vec.size();
113 a = (sz > 0 ? vec[0] : 0.);
114 b = (sz > 1 ? vec[1] : 0.);
115 c = (sz > 2 ? vec[2] : 0.);
116 d = (sz > 3 ? vec[3] : 0.);
126 reader_ =
new TMVA::Reader(
"!Color:Silent");
172 return std::pair<int, int>(ptId, etaId);
202 typedef std::vector<reco::PFCandidatePtr> constituents_type;
203 typedef std::vector<reco::PFCandidatePtr>::iterator constituents_iterator;
216 std::vector<float>
frac, fracCh, fracEm, fracNeut;
218 std::array<float, ncones> cones{{0.1, 0.2, 0.3, 0.4}};
219 std::array<float *, ncones> coneFracs{
221 TMatrixDSym covMatrix(2);
226 float sumPt = 0., sumPt2 = 0., sumPtCh = 0, sumPtNe = 0;
230 float sum_detadphi = 0;
236 for (constituents_iterator
it = constituents.begin();
it != constituents.end(); ++
it) {
238 float candPt = icand->pt();
239 float candPtFrac = candPt /
jetPt;
241 float candDeta = fabs((*it)->eta() -
jet->eta());
243 float candPtDr = candPt * candDr;
244 size_t icone =
std::lower_bound(&cones[0], &cones[ncones], candDr) - &cones[0];
245 float weight2 = candPt * candPt;
247 if (lLead.
isNull() || candPt > lLead->pt()) {
250 }
else if ((lSecond.
isNull() || candPt > lSecond->pt()) && (candPt < lLead->
pt())) {
259 sumPt2 += candPt * candPt;
260 sum_deta += candDeta * weight2;
261 sum_dphi += candDphi * weight2;
262 sum_deta2 += candDeta * candDeta * weight2;
263 sum_detadphi += candDeta * candDphi * weight2;
264 sum_dphi2 += candDphi * candDphi * weight2;
268 frac.push_back(candPtFrac);
269 if (icone < ncones) {
270 *coneFracs[icone] += candPt;
274 if (lLeadNeut.
isNull() || candPt > lLeadNeut->pt()) {
278 fracNeut.push_back(candPtFrac);
283 if (lLeadEm.
isNull() || candPt > lLeadEm->pt()) {
287 fracEm.push_back(candPtFrac);
292 if (lLeadCh.
isNull() || candPt > lLeadCh->pt()) {
296 fracCh.push_back(candPtFrac);
301 float tkpt = icand->trackRef()->pt();
304 bool inAnyOther =
false;
306 double dZ0 = fabs(icand->trackRef()->dz(
vtx->position()));
308 for (reco::VertexCollection::const_iterator vi = allvtx.begin(); vi != allvtx.end(); ++vi) {
310 if (
iv.isFake() ||
iv.ndof() < 4) {
314 bool isVtx0 = (
iv.position() -
vtx->position()).
r() < 0.02;
316 if (!isVtx0 && !inAnyOther) {
323 if (inVtx0 && !inAnyOther) {
325 }
else if (!inVtx0 && inAnyOther) {
331 }
else if (
dZ < 0.2) {
336 if (lTrail.
isNull() || candPt < lTrail->pt()) {
354 impactTrack = lLeadCh->trackRef();
374 std::sort(fracCh.begin(), fracCh.end(), std::greater<float>());
375 std::sort(fracEm.begin(), fracEm.end(), std::greater<float>());
376 std::sort(fracNeut.begin(), fracNeut.end(), std::greater<float>());
400 for (
size_t ic = 0; ic < ncones; ++ic) {
401 *coneFracs[ic] /=
jetPt;
406 for (
unsigned int i0 = 0; i0 <
frac.size(); i0++) {
407 ptRMS += (
frac[i0] - ptMean) * (
frac[i0] - ptMean);
427 float ave_deta = sum_deta / sumPt2;
428 float ave_dphi = sum_dphi / sumPt2;
429 float ave_deta2 = sum_deta2 / sumPt2;
430 float ave_dphi2 = sum_dphi2 / sumPt2;
431 float a = ave_deta2 - ave_deta * ave_deta;
432 float b = ave_dphi2 - ave_dphi * ave_dphi;
433 float c = -(sum_detadphi / sumPt2 - ave_deta * ave_dphi);
436 if ((((
a -
b) * (
a -
b) + 4 *
c *
c)) > 0) {
452 float ddetaR_sum(0.0), ddphiR_sum(0.0);
456 float deta =
part->eta() -
jet->eta();
458 float ddeta, ddphi, ddR;
459 ddeta = deta - ave_deta;
461 ddR =
sqrt(ddeta * ddeta + ddphi * ddphi);
462 ddetaR_sum += ddR * ddeta *
weight;
463 ddphiR_sum += ddR * ddphi *
weight;
466 float ddetaR_ave = ddetaR_sum / sumPt2;
467 float ddphiR_ave = ddphiR_sum / sumPt2;
468 internalId_.dRMean_ =
sqrt(ddetaR_ave * ddetaR_ave + ddphiR_ave * ddphiR_ave);
480 std::stringstream
out;
482 out << std::setw(15) <<
it->first << std::setw(3) <<
"=" << std::setw(5) << *
it->second.first <<
" (" 483 << std::setw(5) <<
it->second.second <<
")" << std::endl;
491 *
it->second.first =
it->second.second;
495 #define INIT_VARIABLE(NAME, TMVANAME, VAL) \ 496 internalId_.NAME##_ = VAL; \ 497 variables_[#NAME] = std::make_pair(&internalId_.NAME##_, VAL);
constexpr double deltaPhi(double phi1, double phi2)
T getParameter(std::string const &) const
std::vector< std::string > tmvaVariables_
float neutralHadronEnergy() const
neutralHadronEnergy
int chargedMultiplicity() const
chargedMultiplicity
float chargedEmEnergy() const
chargedEmEnergy
std::string fullPath() const
float neutralEmEnergy() const
neutralEmEnergy
Float_t mvacut_[NWPs][NEtas][NPts]
#define INIT_VARIABLE(NAME, TMVANAME, VAL)
Base class for all types of Jets.
std::vector< std::string > tmvaSpectators_
bool isNonnull() const
Checks for non-null.
std::vector< Vertex > VertexCollection
collection of Vertex objects
variables_list_t variables_
int neutralMultiplicity() const
neutralMultiplicity
static constexpr int NPts
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Jets made from PFObjects.
void swap(Association< C > &lhs, Association< C > &rhs)
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
bool isNull() const
Checks for null.
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
bool isNonnull() const
Checks for non-null.
virtual reco::PFCandidatePtr getPFConstituent(unsigned fIndex) const
get specific constituent
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho, bool calculateMva=false)
void SetPtEtaPhi(const reco::Candidate &p, float &pt, float &eta, float &phi)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static constexpr float d0
PileupJetIdentifier internalId_
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
void set(const PileupJetIdentifier &)
std::string dumpVariables() const
std::map< std::string, std::string > tmvaNames_
std::pair< int, int > getJetIdKey(float jetPt, float jetEta)
PileupJetIdentifier computeMva()
float chargedHadronEnergy() const
chargedHadronEnergy
Float_t impactParTkThreshod_
MVAJetPuId(int version=CATEv0, const std::string &tmvaWeight="", const std::string &tmvaMethod="", Float_t impactParTkThreshod_=1., const std::vector< std::string > &tmvaVariables=std::vector< std::string >())
int computeIDflag(float mva, float jetPt, float jetEta)
void Assign(const std::vector< float > &vec, float &a, float &b, float &c, float &d)
static constexpr int NWPs