11 #include "TMatrixDSym.h" 12 #include "TMatrixDSymEigen.h" 13 #include "TMVA/MethodBDT.h" 32 const std::vector<edm::ParameterSet>&
trainings = ps.
getParameter<std::vector <edm::ParameterSet> >(
"trainings");
36 jEtaMin_.push_back( trainings.at(
v).getParameter<
double>(
"jEtaMin") );
37 jEtaMax_.push_back( trainings.at(
v).getParameter<
double>(
"jEtaMax") );
40 tmvaEtaVariables_.push_back( trainings.at(
v).getParameter<std::vector<std::string> >(
"tmvaVariables") );
53 for(
int i0 = 0; i0 < 3; i0++) {
59 for(
int i1 = 0; i1 < nCut; i1++) {
61 if(
cutBased_ && i1 == 0) lFullCutType =
"BetaStar"+ lCutType;
62 if(
cutBased_ && i1 == 1) lFullCutType =
"RMS" + lCutType;
63 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" +lFullCutType).c_str());
64 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_"+lFullCutType).c_str());
65 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_"+lFullCutType).c_str());
66 std::vector<double> pt3050 = jetConfig.
getParameter<std::vector<double> >((
"Pt3050_"+lFullCutType).c_str());
68 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][0][i2] = pt010 [i2];
69 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][1][i2] = pt1020[i2];
70 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][2][i2] = pt2030[i2];
71 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][3][i2] = pt3050[i2];
74 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][0][i2] = pt010 [i2];
75 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][1][i2] = pt1020[i2];
76 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][2][i2] = pt2030[i2];
77 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][3][i2] = pt3050[i2];
80 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][0][i2] = pt010 [i2];
81 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][1][i2] = pt1020[i2];
82 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][2][i2] = pt2030[i2];
83 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][3][i2] = pt3050[i2];
94 Float_t impactParTkThreshod,
127 void assign(
const std::vector<float> & vec,
float &
a,
float &
b,
float &
c,
float &
d )
129 size_t sz = vec.size();
130 a = ( sz > 0 ? vec[0] : 0. );
131 b = ( sz > 1 ? vec[1] : 0. );
132 c = ( sz > 2 ? vec[2] : 0. );
133 d = ( sz > 3 ? vec[3] : 0. );
145 TMVA::Reader tmpTMVAReader(
"!Color:Silent:!Error" );
146 for(std::vector<std::string>::const_iterator it=varList.begin(); it!=varList.end(); ++it) {
155 return( std::make_unique<const GBRForest> ( dynamic_cast<TMVA::MethodBDT*>( tmpTMVAReader.FindMVA(
tmvaMethod_.c_str()) ) ) );
178 std::vector<float> vars;
179 for(std::vector<std::string>::const_iterator it=varList.begin(); it!=varList.end(); ++it) {
181 vars.push_back( *var.first );
183 mvaval = reader->GetClassifier(vars.data());
218 if(jetPt >= 10 && jetPt < 20) ptId = 1;
219 if(jetPt >= 20 && jetPt < 30) ptId = 2;
220 if(jetPt >= 30 ) ptId = 3;
227 return std::pair<int,int>(ptId,etaId);
232 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
233 float betaStarModified = betaStarClassic/
log(nvtx-0.64);
251 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
278 static std::atomic<int> printWarning{10};
286 assert( patjet !=
nullptr || pfjet !=
nullptr );
287 if( patjet !=
nullptr && jec == 0. ) {
294 const reco::Candidate* lLead =
nullptr, *lSecond =
nullptr, *lLeadNeut =
nullptr, *lLeadEm =
nullptr, *lLeadCh =
nullptr, *lTrail =
nullptr;
295 std::vector<float>
frac, fracCh, fracEm, fracNeut;
296 float cones[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 };
297 size_t ncones =
sizeof(cones)/
sizeof(
float);
306 TMatrixDSym covMatrix(2); covMatrix = 0.;
308 float sumPt = 0., sumPt2 = 0., sumTkPt = 0.,sumPtCh=0,sumPtNe = 0;
322 bool isPacked =
true;
323 if (lPack ==
nullptr){
327 float candPt = icand->
pt();
328 float candPtFrac = candPt/
jetPt;
330 float candDeta = icand->
eta() - jet->
eta();
332 float candPtDr = candPt * candDr;
333 size_t icone = std::lower_bound(&cones[0],&cones[ncones],candDr) - &cones[0];
335 if(candDr < dRmin) dRmin = candDr;
338 if( lLead ==
nullptr || candPt > lLead->
pt() ) {
341 }
else if( (lSecond ==
nullptr || candPt > lSecond->pt()) && (candPt < lLead->
pt()) ) {
348 covMatrix(0,0) += candPt*candPt*candDeta*candDeta;
349 covMatrix(0,1) += candPt*candPt*candDeta*candDphi;
350 covMatrix(1,1) += candPt*candPt*candDphi*candDphi;
353 sumPt2 += candPt*candPt;
356 frac.push_back(candPtFrac);
358 if( icone < ncones ) { *coneFracs[icone] += candPt; }
362 if (lLeadNeut ==
nullptr || candPt > lLeadNeut->pt()) { lLeadNeut = icand; }
364 fracNeut.push_back(candPtFrac);
365 if( icone < ncones ) { *coneNeutFracs[icone] += candPt; }
370 if( icand->
pdgId() == 22 ) {
371 if(lLeadEm ==
nullptr || candPt > lLeadEm->pt()) { lLeadEm = icand; }
373 fracEm.push_back(candPtFrac);
374 if( icone < ncones ) { *coneEmFracs[icone] += candPt; }
379 if( icand->
charge() != 0 ) {
380 if (lLeadCh ==
nullptr || candPt > lLeadCh->pt()) {
384 if (lPF &&
std::abs(icand->
pdgId()) == 13 && pfTrk ==
nullptr){
389 edm::LogWarning(
"BadMuon")<<
"Found a PFCandidate muon without a trackRef: falling back to Muon::bestTrack ";
404 else if(lPF!=
nullptr) {
417 fracCh.push_back(candPtFrac);
418 if( icone < ncones ) { *coneChFracs[icone] += candPt; }
422 if( icand->
charge() != 0 ) {
430 bool inAnyOther =
false;
434 for(reco::VertexCollection::const_iterator vi=allvtx.begin(); vi!=allvtx.end(); ++vi ) {
436 if( iv.
isFake() || iv.
ndof() < 4 ) {
continue; }
441 if( ! isVtx0 && ! inAnyOther ) {
448 if( inVtx0 && ! inAnyOther ) {
450 }
else if( ! inVtx0 && inAnyOther ) {
456 }
else if( dZ < 0.2 ) {
465 bool inVtxOther =
false;
467 double dZ_tmp = 9999.;
468 for (
unsigned vtx_i = 0 ; vtx_i < allvtx.size() ; vtx_i++ ) {
469 auto iv = allvtx[vtx_i];
475 bool isVtx0 = (iv.position() - vtx->
position()).
r() < 0.02;
479 if (lPack->
fromPV(vtx_i) == 0) inVtxOther =
true;
480 dZ0 = lPack->
dz(iv.position());
483 if (fabs(lPack->
dz(iv.position())) < fabs(dZ_tmp)) {
484 dZ_tmp = lPack->
dz(iv.position());
489 }
else if (inVtxOther){
492 if (fabs(dZ0) < 0.2){
494 }
else if (fabs(dZ_tmp) < 0.2){
500 if( lTrail ==
nullptr || candPt < lTrail->
pt() ) {
507 assert( !(lLead ==
nullptr) );
509 if ( lSecond ==
nullptr ) { lSecond = lTrail; }
510 if ( lLeadNeut ==
nullptr ) { lLeadNeut = lTrail; }
511 if ( lLeadEm ==
nullptr ) { lLeadEm = lTrail; }
512 if ( lLeadCh ==
nullptr ) { lLeadCh = lTrail; }
514 if( patjet !=
nullptr ) {
533 float sum_deta(0.0),sum_dphi(0.0);
534 float ave_deta(0.0), ave_dphi(0.0);
537 if (!(
part.isAvailable() &&
part.isNonnull()) ){
542 float weight2 = weight *
weight;
544 float deta =
part->eta() - jet->
eta();
546 sum_deta += deta*weight2;
547 sum_dphi += dphi*weight2;
549 ave_deta = sum_deta/sumW2;
550 ave_dphi = sum_dphi/sumW2;
554 float ddetaR_sum(0.0), ddphiR_sum(0.0), pull_tmp(0.0);
557 if (!(
part.isAvailable() &&
part.isNonnull()) ){
561 float deta =
part->eta() - jet->
eta();
563 float ddeta, ddphi, ddR;
564 ddeta = deta - ave_deta ;
565 ddphi = dphi-ave_dphi;
566 ddR =
sqrt(ddeta*ddeta + ddphi*ddphi);
567 ddetaR_sum += ddR*ddeta*
weight;
568 ddphiR_sum += ddR*ddphi*
weight;
571 float ddetaR_ave = ddetaR_sum/sumW2;
572 float ddphiR_ave = ddphiR_sum/sumW2;
573 pull_tmp =
sqrt(ddetaR_ave*ddetaR_ave+ddphiR_ave*ddphiR_ave);
585 std::sort(frac.begin(),frac.end(),std::greater<float>());
586 std::sort(fracCh.begin(),fracCh.end(),std::greater<float>());
587 std::sort(fracEm.begin(),fracEm.end(),std::greater<float>());
588 std::sort(fracNeut.begin(),fracNeut.end(),std::greater<float>());
594 covMatrix(0,0) /= sumPt2;
595 covMatrix(0,1) /= sumPt2;
596 covMatrix(1,1) /= sumPt2;
597 covMatrix(1,0) = covMatrix(0,1);
601 TVectorD eigVals(2); eigVals = TMatrixDSymEigen(covMatrix).GetEigenValues();
614 for(
size_t ic=0; ic<ncones; ++ic){
615 *coneFracs[ic] /=
jetPt;
616 *coneEmFracs[ic] /=
jetPt;
617 *coneNeutFracs[ic] /=
jetPt;
618 *coneChFracs[ic] /=
jetPt;
623 for(
unsigned int i0 = 0; i0 < frac.size(); i0++) {ptRMS+=(frac[i0]-ptMean)*(frac[i0]-ptMean);}
641 if( sumTkPt != 0. ) {
662 std::stringstream
out;
663 for(variables_list_t::const_iterator it=
variables_.begin();
665 out << std::setw(15) << it->first << std::setw(3) <<
"=" 666 << std::setw(5) << *it->second.first
667 <<
" (" << std::setw(5) << it->second.second <<
")" << std::endl;
676 for(variables_list_t::iterator it=
variables_.begin();
678 *it->second.first = it->second.second;
683 #define INIT_VARIABLE(NAME,TMVANAME,VAL) \ 684 internalId_.NAME ## _ = VAL; \ 685 variables_[ # NAME ] = std::make_pair(& internalId_.NAME ## _, VAL);
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
void set(const PileupJetIdentifier &)
std::vector< std::string > tmvaEtaWeights_
std::vector< std::string > tmvaVariables_
bool isNonnull() const
Checks for non-null.
#define INIT_VARIABLE(NAME, TMVANAME, VAL)
float chargedHadronEnergy() const
chargedHadronEnergy
virtual double mass() const final
mass
float chargedEmEnergy() const
chargedEmEnergy
float neutralEmEnergy() const
neutralEmEnergy
virtual double eta() const final
momentum pseudorapidity
CandidatePtr daughterPtr(size_type i) const
reference to daughter at given position
virtual const Track * bestTrack() const
T const * get() const
Returns C++ pointer to the item.
Base class for all types of Jets.
std::unique_ptr< const GBRForest > getMVA(const std::vector< std::string > &, const std::string &)
float neutralHadronEnergy() const
neutralHadronEnergy
std::pair< int, int > getJetIdKey(float jetPt, float jetEta)
std::map< std::string, std::string > tmvaNames_
std::vector< double > jEtaMin_
std::vector< Vertex > VertexCollection
collection of Vertex objects
int neutralMultiplicity() const
neutralMultiplicity
float impactParTkThreshod_
int computeCutIDflag(float betaStarClassic, float dR2Mean, float nvtx, float jetPt, float jetEta)
int chargedMultiplicity() const
chargedMultiplicity
const Point & position() const
position
Jets made from PFObjects.
float neutralEmEnergy() const
neutralEmEnergy
std::vector< std::unique_ptr< const GBRForest > > etaReader_
float chargedEmEnergy() const
chargedEmEnergy
reco::TrackRef trackRef() const
virtual const Track * bestTrack() const
best track pointer
virtual size_t numberOfDaughters() const
number of daughters
virtual CandidatePtr sourceCandidatePtr(size_type i) const
float betaStarCut_[3][4][4]
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
std::vector< std::vector< std::string > > tmvaEtaVariables_
virtual double energy() const final
energy
Abs< T >::type abs(const T &t)
virtual const reco::Track & pseudoTrack() const
Return reference to a pseudo track made with candidate kinematics, parameterized error for eta...
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
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.
virtual size_type numberOfSourceCandidatePtrs() const
T const * get() const
Returns C++ pointer to the item.
PileupJetIdAlgo(int version=PHILv0, const std::string &tmvaWeight="", const std::string &tmvaMethod="", Float_t impactParTkThreshod_=1., const std::vector< std::string > &tmvaVariables=std::vector< std::string >(), bool runMvas=true)
std::unique_ptr< const GBRForest > reader_
int computeIDflag(float mva, float jetPt, float jetEta)
int neutralMultiplicity() const
neutralMultiplicity
reco::MuonRef muonRef() const
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
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)
double deltaPhi(double phi1, double phi2)
virtual double eta() const =0
momentum pseudorapidity
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, double rho)
virtual double pt() const =0
transverse momentum
PileupJetIdentifier computeMva()
Analysis-level calorimeter jet class.
std::vector< std::string > tmvaSpectators_
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
virtual int charge() const =0
electric charge
Particle reconstructed by the particle flow algorithm.
virtual int nConstituents() const
of constituents
std::vector< double > jEtaMax_
reco::GsfTrackRef gsfTrackRef() const
variables_list_t variables_
std::string fullPath() const
float neutralHadronEnergy() const
neutralHadronEnergy
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
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