11 #include "TMatrixDSym.h"
12 #include "TMatrixDSymEigen.h"
34 for(
int i0 = 0; i0 < 3; i0++) {
40 for(
int i1 = 0; i1 < nCut; i1++) {
42 if(
cutBased_ && i1 == 0) lFullCutType =
"BetaStar"+ lCutType;
43 if(
cutBased_ && i1 == 1) lFullCutType =
"RMS" + lCutType;
44 std::vector<double> pt010 = jetConfig.
getParameter<std::vector<double> >((
"Pt010_" +lFullCutType).c_str());
45 std::vector<double> pt1020 = jetConfig.
getParameter<std::vector<double> >((
"Pt1020_"+lFullCutType).c_str());
46 std::vector<double> pt2030 = jetConfig.
getParameter<std::vector<double> >((
"Pt2030_"+lFullCutType).c_str());
47 std::vector<double> pt3050 = jetConfig.
getParameter<std::vector<double> >((
"Pt3050_"+lFullCutType).c_str());
49 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][0][i2] = pt010 [i2];
50 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][1][i2] = pt1020[i2];
51 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][2][i2] = pt2030[i2];
52 for(
int i2 = 0; i2 < 4; i2++)
mvacut_[i0][3][i2] = pt3050[i2];
55 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][0][i2] = pt010 [i2];
56 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][1][i2] = pt1020[i2];
57 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][2][i2] = pt2030[i2];
58 for(
int i2 = 0; i2 < 4; i2++)
betaStarCut_[i0][3][i2] = pt3050[i2];
61 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][0][i2] = pt010 [i2];
62 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][1][i2] = pt1020[i2];
63 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][2][i2] = pt2030[i2];
64 for(
int i2 = 0; i2 < 4; i2++)
rmsCut_[i0][3][i2] = pt3050[i2];
76 Float_t impactParTkThreshod,
77 const std::vector<std::string> & tmvaVariables
174 void assign(
const std::vector<float> & vec,
float &
a,
float &
b,
float &
c,
float & d )
176 size_t sz = vec.size();
177 a = ( sz > 0 ? vec[0] : 0. );
178 b = ( sz > 1 ? vec[1] : 0. );
179 c = ( sz > 2 ? vec[2] : 0. );
180 d = ( sz > 3 ? vec[3] : 0. );
193 reader_ =
new TMVA::Reader(
"!Color:!Silent");
233 if(jetPt > 10 && jetPt < 20) ptId = 1;
234 if(jetPt > 20 && jetPt < 30) ptId = 2;
235 if(jetPt > 30 ) ptId = 3;
238 if(fabs(jetEta) > 2.5 && fabs(jetEta) < 2.75) etaId = 1;
239 if(fabs(jetEta) > 2.75 && fabs(jetEta) < 3.0 ) etaId = 2;
240 if(fabs(jetEta) > 3.0 && fabs(jetEta) < 5.0 ) etaId = 3;
242 return std::pair<int,int>(ptId,etaId);
247 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
248 float betaStarModified = betaStarClassic/
log(nvtx-0.64);
266 std::pair<int,int> jetIdKey =
getJetIdKey(jetPt,jetEta);
293 static std::atomic<int> printWarning{10};
294 typedef std::vector <reco::PFCandidatePtr> constituents_type;
295 typedef std::vector <reco::PFCandidatePtr>::iterator constituents_iterator;
314 std::vector<float>
frac, fracCh, fracEm, fracNeut;
315 float cones[] = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7 };
316 size_t ncones =
sizeof(cones)/
sizeof(
float);
325 TMatrixDSym covMatrix(2); covMatrix = 0.;
329 float sumPt = 0., sumPt2 = 0., sumTkPt = 0.,sumPtCh=0,sumPtNe = 0;
334 for(constituents_iterator it=constituents.begin(); it!=constituents.end(); ++it) {
336 float candPt = icand->pt();
337 float candPtFrac = candPt/
jetPt;
339 float candDeta = fabs( (*it)->eta() - jet->
eta() );
341 float candPtDr = candPt * candDr;
342 size_t icone = std::lower_bound(&cones[0],&cones[ncones],candDr) - &cones[0];
345 if( lLead.
isNull() || candPt > lLead->pt() ) {
348 }
else if( (lSecond.
isNull() || candPt > lSecond->pt()) && (candPt < lLead->
pt()) ) {
355 covMatrix(0,0) += candPt*candPt*candDeta*candDeta;
356 covMatrix(0,1) += candPt*candPt*candDeta*candDphi;
357 covMatrix(1,1) += candPt*candPt*candDphi*candDphi;
360 sumPt2 += candPt*candPt;
363 frac.push_back(candPtFrac);
364 if( icone < ncones ) { *coneFracs[icone] += candPt; }
368 if (lLeadNeut.
isNull() || candPt > lLeadNeut->pt()) { lLeadNeut = icand; }
370 fracNeut.push_back(candPtFrac);
371 if( icone < ncones ) { *coneNeutFracs[icone] += candPt; }
377 if(lLeadEm.
isNull() || candPt > lLeadEm->pt()) { lLeadEm = icand; }
379 fracEm.push_back(candPtFrac);
380 if( icone < ncones ) { *coneEmFracs[icone] += candPt; }
386 if (lLeadCh.
isNull() || candPt > lLeadCh->pt()) { lLeadCh = icand; }
389 fracCh.push_back(candPtFrac);
390 if( icone < ncones ) { *coneChFracs[icone] += candPt; }
396 float tkpt = icand->trackRef()->pt();
400 bool inAnyOther =
false;
402 double dZ0 = fabs(icand->trackRef()->dz(vtx->
position()));
404 for(reco::VertexCollection::const_iterator vi=allvtx.begin(); vi!=allvtx.end(); ++vi ) {
406 if( iv.
isFake() || iv.
ndof() < 4 ) {
continue; }
410 if( ! isVtx0 && ! inAnyOther ) {
417 if( inVtx0 && ! inAnyOther ) {
419 }
else if( ! inVtx0 && inAnyOther ) {
425 }
else if( dZ < 0.2 ) {
429 if(printWarning-- > 0) {
std::cerr << e << std::endl; }
433 if( lTrail.
isNull() || candPt < lTrail->pt() ) {
441 if ( lSecond.
isNull() ) { lSecond = lTrail; }
442 if ( lLeadNeut.
isNull() ) { lLeadNeut = lTrail; }
443 if ( lLeadEm.
isNull() ) { lLeadEm = lTrail; }
444 if ( lLeadCh.
isNull() ) { lLeadCh = lTrail; }
445 impactTrack = lLeadCh->trackRef();
458 if(printWarning-- > 0) {
std::cerr <<
"WARNING : did not find any valid track reference attached to the jet " << std::endl; }
468 std::sort(frac.begin(),frac.end(),std::greater<float>());
469 std::sort(fracCh.begin(),fracCh.end(),std::greater<float>());
470 std::sort(fracEm.begin(),fracEm.end(),std::greater<float>());
471 std::sort(fracNeut.begin(),fracNeut.end(),std::greater<float>());
477 covMatrix(0,0) /= sumPt2;
478 covMatrix(0,1) /= sumPt2;
479 covMatrix(1,1) /= sumPt2;
480 covMatrix(1,0) = covMatrix(0,1);
484 TVectorD eigVals(2); eigVals = TMatrixDSymEigen(covMatrix).GetEigenValues();
497 for(
size_t ic=0; ic<ncones; ++ic){
498 *coneFracs[ic] /=
jetPt;
499 *coneEmFracs[ic] /=
jetPt;
500 *coneNeutFracs[ic] /=
jetPt;
501 *coneChFracs[ic] /=
jetPt;
506 for(
unsigned int i0 = 0; i0 < frac.size(); i0++) {ptRMS+=(frac[i0]-ptMean)*(frac[i0]-ptMean);}
520 if( sumTkPt != 0. ) {
541 std::stringstream
out;
542 for(variables_list_t::const_iterator it=
variables_.begin();
544 out << std::setw(15) << it->first << std::setw(3) <<
"="
545 << std::setw(5) << *it->second.first
546 <<
" (" << std::setw(5) << it->second.second <<
")" << std::endl;
555 for(variables_list_t::iterator it=
variables_.begin();
557 *it->second.first = it->second.second;
562 #define INIT_VARIABLE(NAME,TMVANAME,VAL) \
563 internalId_.NAME ## _ = VAL; \
564 variables_[ # NAME ] = std::make_pair(& internalId_.NAME ## _, VAL);
virtual double energy() const GCC11_FINAL
energy
T getParameter(std::string const &) const
void set(const PileupJetIdentifier &)
Float_t impactParTkThreshod_
std::vector< std::string > tmvaVariables_
#define INIT_VARIABLE(NAME, TMVANAME, VAL)
float chargedEmEnergy() const
chargedEmEnergy
trackRef_iterator tracks_end() const
last iterator over tracks
virtual float eta() const =0
momentum pseudorapidity
Base class for all types of Jets.
std::pair< int, int > getJetIdKey(float jetPt, float jetEta)
std::map< std::string, std::string > tmvaNames_
virtual float phi() const =0
momentum azimuthal angle
std::vector< Vertex > VertexCollection
collection of Vertex objects
int computeCutIDflag(float betaStarClassic, float dR2Mean, float nvtx, float jetPt, float jetEta)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Float_t betaStarCut_[3][4][4]
int chargedMultiplicity() const
chargedMultiplicity
const Point & position() const
position
Jets made from PFObjects.
float neutralEmEnergy() const
neutralEmEnergy
bool isNonnull() const
Checks for non-null.
bool isNonnull() const
Checks for non-null.
virtual float pt() const =0
transverse momentum
const T & max(const T &a, const T &b)
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
PileupJetIdentifier internalId_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::string dumpVariables() const
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)
PileupJetIdentifier computeIdVariables(const reco::Jet *jet, float jec, const reco::Vertex *, const reco::VertexCollection &, bool calculateMva=false)
int computeIDflag(float mva, float jetPt, float jetEta)
int neutralMultiplicity() const
neutralMultiplicity
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
void setPtEtaPhi(const reco::Candidate &p, float &pt, float &eta, float &phi)
double deltaPhi(double phi1, double phi2)
virtual float mass() const GCC11_FINAL
mass
unsigned int nCharged(const GenJet &jet)
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 >())
PileupJetIdentifier computeMva()
std::vector< std::string > tmvaSpectators_
bool isNull() const
Checks for null.
variables_list_t variables_
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
float neutralHadronEnergy() const
neutralHadronEnergy
std::string fullPath() const
trackRef_iterator tracks_begin() const
first iterator over tracks
virtual float pt() const GCC11_FINAL
transverse momentum
float chargedHadronEnergy() const
chargedHadronEnergy
void loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)