Skip to content

Commit

Permalink
Merge pull request #31164 from missirol/devel_112X_puppi_speedup2
Browse files Browse the repository at this point in the history
improving performance of PuppiProducer
  • Loading branch information
cmsbuild committed Aug 25, 2020
2 parents f596dec + e0f02d3 commit 25a40ac
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 143 deletions.
1 change: 0 additions & 1 deletion CommonTools/PileupAlgos/BuildFile.xml
@@ -1,7 +1,6 @@
<use name="FWCore/ParameterSet"/>
<use name="root"/>
<use name="rootcore"/>
<use name="fastjet"/>
<export>
<lib name="1"/>
</export>
2 changes: 2 additions & 0 deletions CommonTools/PileupAlgos/interface/PuppiAlgo.h
Expand Up @@ -35,6 +35,8 @@ class PuppiAlgo {
inline double rms() const { return cur_RMS; }
inline double median() const { return cur_Med; }

inline double etaMaxExtrap() const { return fEtaMaxExtrap; }

private:
unsigned int fNAlgos;
std::vector<double> fEtaMax;
Expand Down
36 changes: 10 additions & 26 deletions CommonTools/PileupAlgos/interface/PuppiCandidate.h
@@ -1,29 +1,13 @@
#ifndef CommonTools_PileupAlgos_PuppiCandidate
#define CommonTools_PileupAlgos_PuppiCandidate

#include "fastjet/PseudoJet.hh"

// Extension of fastjet::PseudoJet that caches eta and some other info
// Puppi uses register to decide between NHs, PV CHs, and PU CHs.
class PuppiCandidate : public fastjet::PseudoJet {
public:
using fastjet::PseudoJet::PseudoJet;
double pseudorapidity() const {
_ensure_valid_eta();
return _eta;
}
double eta() const { return pseudorapidity(); }
void _ensure_valid_eta() const {
if (_eta == fastjet::pseudojet_invalid_rap)
_eta = fastjet::PseudoJet::pseudorapidity();
}
void set_info(int puppi_register) { _puppi_register = puppi_register; }
inline int puppi_register() const { return _puppi_register; }

private:
// variable names in fastjet style
mutable double _eta = fastjet::pseudojet_invalid_rap;
int _puppi_register;
#ifndef CommonTools_PileupAlgos_PuppiCandidate_h
#define CommonTools_PileupAlgos_PuppiCandidate_h

struct PuppiCandidate {
double pt{0};
double eta{0};
double phi{0};
double m{0};
double rapidity{0};
int id{0};
};

#endif
7 changes: 3 additions & 4 deletions CommonTools/PileupAlgos/interface/PuppiContainer.h
Expand Up @@ -2,8 +2,8 @@
#define COMMONTOOLS_PUPPI_PUPPICONTAINER_H_

#include "CommonTools/PileupAlgos/interface/PuppiAlgo.h"
#include "CommonTools/PileupAlgos/interface/RecoObj.h"
#include "CommonTools/PileupAlgos/interface/PuppiCandidate.h"
#include "CommonTools/PileupAlgos/interface/RecoObj.h"

class PuppiContainer {
public:
Expand All @@ -13,7 +13,6 @@ class PuppiContainer {
void setNPV(int iNPV) { fNPV = iNPV; }

std::vector<PuppiCandidate> const &pfParticles() const { return fPFParticles; }
std::vector<PuppiCandidate> const &pvParticles() const { return fChargedPV; }
std::vector<double> const &puppiWeights();
const std::vector<double> &puppiRawAlphas() { return fRawAlphas; }
const std::vector<double> &puppiAlphas() { return fVals; }
Expand Down Expand Up @@ -43,7 +42,8 @@ class PuppiContainer {
bool fPuppiDiagnostics;
const std::vector<RecoObj> *fRecoParticles;
std::vector<PuppiCandidate> fPFParticles;
std::vector<PuppiCandidate> fChargedPV;
std::vector<PuppiCandidate> fPFParticlesForVar;
std::vector<PuppiCandidate> fPFParticlesForVarChargedPV;
std::vector<double> fWeights;
std::vector<double> fVals;
std::vector<double> fRawAlphas;
Expand All @@ -62,7 +62,6 @@ class PuppiContainer {
double fPtMaxNeutralsStartSlope;
int fNAlgos;
int fNPV;
double fPVFrac;
std::vector<PuppiAlgo> fPuppiAlgo;
};
#endif
1 change: 0 additions & 1 deletion CommonTools/PileupAlgos/plugins/PuppiProducer.cc
Expand Up @@ -18,7 +18,6 @@
#include "DataFormats/Common/interface/Association.h"
//Main File
#include "CommonTools/PileupAlgos/plugins/PuppiProducer.h"
#include "CommonTools/PileupAlgos/interface/PuppiCandidate.h"

// ------------------------------------------------------------------------------------------
PuppiProducer::PuppiProducer(const edm::ParameterSet& iConfig) {
Expand Down
9 changes: 4 additions & 5 deletions CommonTools/PileupAlgos/src/PuppiAlgo.cc
Expand Up @@ -85,24 +85,24 @@ void PuppiAlgo::fixAlgoEtaBin(int i_eta) {
}

void PuppiAlgo::add(const PuppiCandidate &iParticle, const double &iVal, const unsigned int iAlgo) {
if (iParticle.pt() < fRMSPtMin[iAlgo])
if (iParticle.pt < fRMSPtMin[iAlgo])
return;
// Change from SRR : Previously used fastjet::PseudoJet::user_index to decide the particle type.
// In CMSSW we use the user_index to specify the index in the input collection, so I invented
// a new mechanism using the fastjet UserInfo functionality. Of course, it's still just an integer
// but that interface could be changed (or augmented) if desired / needed.
int puppi_id = iParticle.puppi_register();
int puppi_id = iParticle.id;
if (puppi_id == std::numeric_limits<int>::lowest()) {
throw cms::Exception("PuppiRegisterNotSet") << "The puppi register is not set. This must be set before use.\n";
}

// added by Nhan -- for all eta regions, compute mean/RMS from the central charged PU
if ((std::abs(iParticle.eta()) < fEtaMaxExtrap) && (puppi_id == 2)) {
if ((std::abs(iParticle.eta) < fEtaMaxExtrap) && (puppi_id == 2)) {
fPups.push_back(iVal);
fNCount[iAlgo]++;
}
// for the low PU case, correction. for checking that the PU-only median will be below the PV particles
if (std::abs(iParticle.eta()) < fEtaMaxExtrap && (puppi_id == 1))
if (std::abs(iParticle.eta) < fEtaMaxExtrap && (puppi_id == 1))
fPupsPV.push_back(iVal);
}

Expand Down Expand Up @@ -158,7 +158,6 @@ void PuppiAlgo::computeMedRMS(const unsigned int &iAlgo) {

if (fAdjust[iAlgo]) {
//Adjust the p-value to correspond to the median
std::sort(fPupsPV.begin(), fPupsPV.end());
int lNPV = 0;
for (unsigned int i0 = 0; i0 < fPupsPV.size(); i0++)
if (fPupsPV[i0] <= lMed)
Expand Down
1 change: 0 additions & 1 deletion CommonTools/PileupAlgos/src/PuppiCandidate.cc

This file was deleted.

0 comments on commit 25a40ac

Please sign in to comment.