11 #include "TMatrixDSym.h" 12 #include "TMatrixDSymEigen.h" 22 cutBased_(ps.getParameter<
bool>(
"cutBased")),
23 etaBinnedWeights_(
false),
26 label_(ps.getParameter<
std::
string>(
"label")),
32 std::vector<edm::FileInPath> tmvaEtaWeights;
39 const std::vector<edm::ParameterSet>&
trainings = ps.getParameter<std::vector <edm::ParameterSet> >(
"trainings");
40 nEtaBins_ = ps.getParameter<
int>(
"nEtaBins");
42 tmvaEtaWeights.push_back(trainings.at(
v).getParameter<
edm::FileInPath>(
"tmvaWeights"));
43 jEtaMin_.push_back( trainings.at(
v).getParameter<
double>(
"jEtaMin") );
44 jEtaMax_.push_back( trainings.at(
v).getParameter<
double>(
"jEtaMax") );
47 tmvaEtaVariables_.push_back( trainings.at(
v).getParameter<std::vector<std::string> >(
"tmvaVariables") );
50 tmvaVariables_ = ps.getParameter<std::vector<std::string> >(
"tmvaVariables");
53 tmvaSpectators = ps.getParameter<std::vector<std::string> >(
"tmvaSpectators");
54 version = ps.getParameter<
int>(
"version");
60 for (
int i0 = 0; i0 < 3; i0++) {
66 for (
int i1 = 0; i1 < nCut; i1++) {
68 if (
cutBased_ && i1 == 0) lFullCutType =
"BetaStar"+ lCutType;
69 if (
cutBased_ && i1 == 1) lFullCutType =
"RMS" + lCutType;
70 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" +lFullCutType).c_str());
71 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_"+lFullCutType).c_str());
72 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_"+lFullCutType).c_str());
73 std::vector<double> pt3050 = jetConfig.
getParameter<std::vector<double> >((
"Pt3050_"+lFullCutType).c_str());
75 for (
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][0][i2] = pt010 [i2];
76 for (
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][1][i2] = pt1020[i2];
77 for (
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][2][i2] = pt2030[i2];
78 for (
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][3][i2] = pt3050[i2];
81 for (
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][0][i2] = pt010 [i2];
82 for (
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][1][i2] = pt1020[i2];
83 for (
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][2][i2] = pt2030[i2];
84 for (
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][3][i2] = pt3050[i2];
87 for (
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][0][i2] = pt010 [i2];
88 for (
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][1][i2] = pt1020[i2];
89 for (
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][2][i2] = pt2030[i2];
90 for (
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][3][i2] = pt3050[i2];
122 void assign(
const std::vector<float> & vec,
float &
a,
float &
b,
float &
c,
float &
d )
124 size_t sz = vec.size();
125 a = ( sz > 0 ? vec[0] : 0. );
126 b = ( sz > 1 ? vec[1] : 0. );
127 c = ( sz > 2 ? vec[2] : 0. );
128 d = ( sz > 3 ? vec[3] : 0. );
148 std::vector<float> vars;
149 for(std::vector<std::string>::const_iterator it=varList.begin(); it!=varList.end(); ++it) {
151 vars.push_back( *var.first );
153 return reader->GetClassifier(vars.data());
187 if(jetPt >= 10 && jetPt < 20) ptId = 1;
188 if(jetPt >= 20 && jetPt < 30) ptId = 2;
189 if(jetPt >= 30 ) ptId = 3;
196 return std::pair<int,int>(ptId,etaId);
201 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
202 float betaStarModified = betaStarClassic/
log(nvtx-0.64);
220 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
253 assert( patjet !=
nullptr || pfjet !=
nullptr );
254 if( patjet !=
nullptr && jec == 0. ) {
261 const reco::Candidate* lLead =
nullptr, *lSecond =
nullptr, *lLeadNeut =
nullptr, *lLeadEm =
nullptr, *lLeadCh =
nullptr, *lTrail =
nullptr;
262 std::vector<float>
frac, fracCh, fracEm, fracNeut;
263 float cones[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 };
264 size_t ncones =
sizeof(cones)/
sizeof(
float);
273 TMatrixDSym covMatrix(2); covMatrix = 0.;
275 float sumPt = 0., sumPt2 = 0., sumTkPt = 0.,sumPtCh=0,sumPtNe = 0;
276 float multNeut = 0.0;
290 bool isPacked =
true;
291 if (lPack ==
nullptr){
294 float candPuppiWeight = 1.0;
295 if (usePuppi && isPacked) candPuppiWeight = lPack->
puppiWeight();
296 float candPt = (icand->
pt())*candPuppiWeight;
297 float candPtFrac = candPt/
jetPt;
299 float candDeta = icand->
eta() - jet->
eta();
301 float candPtDr = candPt * candDr;
302 size_t icone = std::lower_bound(&cones[0],&cones[ncones],candDr) - &cones[0];
304 if(candDr < dRmin) dRmin = candDr;
307 if( lLead ==
nullptr || candPt > lLead->
pt() ) {
310 }
else if( (lSecond ==
nullptr || candPt > lSecond->pt()) && (candPt < lLead->
pt()) ) {
317 covMatrix(0,0) += candPt*candPt*candDeta*candDeta;
318 covMatrix(0,1) += candPt*candPt*candDeta*candDphi;
319 covMatrix(1,1) += candPt*candPt*candDphi*candDphi;
322 sumPt2 += candPt*candPt;
325 frac.push_back(candPtFrac);
327 if( icone < ncones ) { *coneFracs[icone] += candPt; }
331 if (lLeadNeut ==
nullptr || candPt > lLeadNeut->pt()) { lLeadNeut = icand; }
333 fracNeut.push_back(candPtFrac);
334 if( icone < ncones ) { *coneNeutFracs[icone] += candPt; }
337 multNeut += candPuppiWeight;
340 if( icand->
pdgId() == 22 ) {
341 if(lLeadEm ==
nullptr || candPt > lLeadEm->pt()) { lLeadEm = icand; }
343 fracEm.push_back(candPtFrac);
344 if( icone < ncones ) { *coneEmFracs[icone] += candPt; }
347 multNeut += candPuppiWeight;
349 if((
abs(icand->
pdgId()) == 1) || (
abs(icand->
pdgId()) == 2)) multNeut += candPuppiWeight;
352 if( icand->
charge() != 0 ) {
353 if (lLeadCh ==
nullptr || candPt > lLeadCh->pt()) {
357 if (lPF &&
std::abs(icand->
pdgId()) == 13 && pfTrk ==
nullptr){
362 edm::LogWarning(
"BadMuon")<<
"Found a PFCandidate muon without a trackRef: falling back to Muon::bestTrack ";
371 else if(lPF!=
nullptr) {
384 fracCh.push_back(candPtFrac);
385 if( icone < ncones ) { *coneChFracs[icone] += candPt; }
389 if( icand->
charge() != 0 ) {
397 bool inAnyOther =
false;
401 for(reco::VertexCollection::const_iterator vi=allvtx.begin(); vi!=allvtx.end(); ++vi ) {
403 if( iv.
isFake() || iv.
ndof() < 4 ) {
continue; }
408 if( ! isVtx0 && ! inAnyOther ) {
415 if( inVtx0 && ! inAnyOther ) {
417 }
else if( ! inVtx0 && inAnyOther ) {
423 }
else if( dZ < 0.2 ) {
432 bool inVtxOther =
false;
434 double dZ_tmp = 9999.;
435 for (
unsigned vtx_i = 0 ; vtx_i < allvtx.size() ; vtx_i++ ) {
436 auto iv = allvtx[vtx_i];
442 bool isVtx0 = (iv.position() - vtx->
position()).
r() < 0.02;
446 if (lPack->
fromPV(vtx_i) == 0) inVtxOther =
true;
447 dZ0 = lPack->
dz(iv.position());
450 if (fabs(lPack->
dz(iv.position())) < fabs(dZ_tmp)) {
451 dZ_tmp = lPack->
dz(iv.position());
456 }
else if (inVtxOther){
459 if (fabs(dZ0) < 0.2){
461 }
else if (fabs(dZ_tmp) < 0.2){
468 if( lTrail ==
nullptr || candPt < lTrail->
pt() ) {
475 assert( !(lLead ==
nullptr) );
477 if ( lSecond ==
nullptr ) { lSecond = lTrail; }
478 if ( lLeadNeut ==
nullptr ) { lLeadNeut = lTrail; }
479 if ( lLeadEm ==
nullptr ) { lLeadEm = lTrail; }
480 if ( lLeadCh ==
nullptr ) { lLeadCh = lTrail; }
482 if( patjet !=
nullptr ) {
502 float sum_deta(0.0),sum_dphi(0.0);
503 float ave_deta(0.0), ave_dphi(0.0);
506 if (!(
part.isAvailable() &&
part.isNonnull()) ){
510 float partPuppiWeight=1.0;
513 if (partpack!=
nullptr) partPuppiWeight = partpack->
puppiWeight();
517 float weight2 = weight *
weight;
519 float deta =
part->eta() - jet->
eta();
521 sum_deta += deta*weight2;
522 sum_dphi += dphi*weight2;
524 ave_deta = sum_deta/sumW2;
525 ave_dphi = sum_dphi/sumW2;
529 float ddetaR_sum(0.0), ddphiR_sum(0.0), pull_tmp(0.0);
532 if (!(
part.isAvailable() &&
part.isNonnull()) ){
536 float partPuppiWeight=1.0;
539 if (partpack!=
nullptr) partPuppiWeight = partpack->
puppiWeight();
542 float weight = partPuppiWeight*(
part->pt())*partPuppiWeight*(
part->pt());
543 float deta =
part->eta() - jet->
eta();
545 float ddeta, ddphi, ddR;
546 ddeta = deta - ave_deta ;
547 ddphi = dphi-ave_dphi;
548 ddR =
sqrt(ddeta*ddeta + ddphi*ddphi);
549 ddetaR_sum += ddR*ddeta*
weight;
550 ddphiR_sum += ddR*ddphi*
weight;
553 float ddetaR_ave = ddetaR_sum/sumW2;
554 float ddphiR_ave = ddphiR_sum/sumW2;
555 pull_tmp =
sqrt(ddetaR_ave*ddetaR_ave+ddphiR_ave*ddphiR_ave);
567 std::sort(frac.begin(),frac.end(),std::greater<float>());
568 std::sort(fracCh.begin(),fracCh.end(),std::greater<float>());
569 std::sort(fracEm.begin(),fracEm.end(),std::greater<float>());
570 std::sort(fracNeut.begin(),fracNeut.end(),std::greater<float>());
576 covMatrix(0,0) /= sumPt2;
577 covMatrix(0,1) /= sumPt2;
578 covMatrix(1,1) /= sumPt2;
579 covMatrix(1,0) = covMatrix(0,1);
583 TVectorD eigVals(2); eigVals = TMatrixDSymEigen(covMatrix).GetEigenValues();
596 for(
size_t ic=0; ic<ncones; ++ic){
597 *coneFracs[ic] /=
jetPt;
598 *coneEmFracs[ic] /=
jetPt;
599 *coneNeutFracs[ic] /=
jetPt;
600 *coneChFracs[ic] /=
jetPt;
605 for(
unsigned int i0 = 0; i0 < frac.size(); i0++) {ptRMS+=(frac[i0]-ptMean)*(frac[i0]-ptMean);}
623 if( sumTkPt != 0. ) {
644 std::stringstream
out;
645 for(variables_list_t::const_iterator it=
variables_.begin();
647 out << std::setw(15) << it->first << std::setw(3) <<
"=" 648 << std::setw(5) << *it->second.first
649 <<
" (" << std::setw(5) << it->second.second <<
")" << std::endl;
658 for(variables_list_t::iterator it=
variables_.begin();
660 *it->second.first = it->second.second;
665 #define INIT_VARIABLE(NAME,TMVANAME,VAL) \ 666 internalId_.NAME ## _ = VAL; \ 667 variables_[ # NAME ] = std::make_pair(& internalId_.NAME ## _, VAL); float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
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
float betaStarCut_[3][4][4]
std::string dumpVariables() const
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_