Skip to content

Commit

Permalink
Merge pull request #37999 from igv4321/fftjet-update
Browse files Browse the repository at this point in the history
Changing FFTJet modules to stream modules
  • Loading branch information
cmsbuild committed May 20, 2022
2 parents 983c83f + c4c86e3 commit a25b2d7
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 116 deletions.
4 changes: 2 additions & 2 deletions RecoJets/FFTJetProducers/interface/FFTJetInterface.h
Expand Up @@ -28,7 +28,7 @@
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "DataFormats/Candidate/interface/Particle.h"

Expand All @@ -49,7 +49,7 @@
// class declaration
//
namespace fftjetcms {
class FFTJetInterface : public edm::EDProducer {
class FFTJetInterface : public edm::stream::EDProducer<> {
public:
// Explicitly disable other ways to construct this object
FFTJetInterface() = delete;
Expand Down
12 changes: 2 additions & 10 deletions RecoJets/FFTJetProducers/plugins/FFTJetCorrectionProducer.cc
Expand Up @@ -24,7 +24,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down Expand Up @@ -84,15 +84,13 @@ namespace {
//
// class declaration
//
class FFTJetCorrectionProducer : public edm::EDProducer {
class FFTJetCorrectionProducer : public edm::stream::EDProducer<> {
public:
explicit FFTJetCorrectionProducer(const edm::ParameterSet&);
~FFTJetCorrectionProducer() override;

private:
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

template <typename Jet>
void makeProduces(const std::string& alias, const std::string& tag);
Expand Down Expand Up @@ -344,11 +342,5 @@ void FFTJetCorrectionProducer::produce(edm::Event& iEvent, const edm::EventSetup
jet_type_switch(applyCorrections, iEvent, iSetup);
}

// ------------ method called once each job just before starting event loop ------------
void FFTJetCorrectionProducer::beginJob() {}

// ------------ method called once each job just after ending the event loop ------------
void FFTJetCorrectionProducer::endJob() {}

//define this as a plug-in
DEFINE_FWK_MODULE(FFTJetCorrectionProducer);
20 changes: 5 additions & 15 deletions RecoJets/FFTJetProducers/plugins/FFTJetDijetFilter.cc
Expand Up @@ -27,7 +27,7 @@

// framework include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand All @@ -48,7 +48,7 @@ using namespace fftjetcms;
//
// class declaration
//
class FFTJetDijetFilter : public edm::EDFilter {
class FFTJetDijetFilter : public edm::stream::EDFilter<> {
public:
typedef fftjet::ProximityClusteringTree<fftjet::Peak, long> ClusteringTree;
typedef fftjet::SparseClusteringTree<fftjet::Peak, long> SparseTree;
Expand All @@ -62,9 +62,7 @@ class FFTJetDijetFilter : public edm::EDFilter {
private:
typedef reco::PattRecoTree<float, reco::PattRecoPeak<float> > StoredTree;

void beginJob() override;
bool filter(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
void endJob() override;

template <class Ptr>
inline void checkConfig(const Ptr& ptr, const char* message) const {
Expand Down Expand Up @@ -129,7 +127,9 @@ FFTJetDijetFilter::FFTJetDijetFilter(const edm::ParameterSet& ps)
init_param(double, maxPeakEta),
init_param(bool, insertCompleteEvent),
clusteringTree(nullptr),
sparseTree(nullptr) {
sparseTree(nullptr),
nPassed(0),
nRejected(0) {
// Parse the set of scales
iniScales = fftjet_ScaleSet_parser(ps.getParameter<edm::ParameterSet>("InitialScales"));
checkConfig(iniScales, "invalid set of scales");
Expand All @@ -152,16 +152,6 @@ FFTJetDijetFilter::~FFTJetDijetFilter() {
delete clusteringTree;
}

void FFTJetDijetFilter::beginJob() {
nPassed = 0;
nRejected = 0;
}

void FFTJetDijetFilter::endJob() {
// std::cout << "In FTJetDijetFilter::endJob: nPassed = " << nPassed
// << ", nRejected = " << nRejected << std::endl;
}

// ------------ method called to produce the data ------------
bool FFTJetDijetFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<StoredTree> input;
Expand Down
8 changes: 0 additions & 8 deletions RecoJets/FFTJetProducers/plugins/FFTJetEFlowSmoother.cc
Expand Up @@ -58,9 +58,7 @@ class FFTJetEFlowSmoother : public FFTJetInterface {

protected:
// methods
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

private:
void buildKernelConvolver(const edm::ParameterSet&);
Expand Down Expand Up @@ -242,11 +240,5 @@ void FFTJetEFlowSmoother::produce(edm::Event& iEvent, const edm::EventSetup& iSe
iEvent.put(std::move(pTable), outputLabel);
}

// ------------ method called once each job just before starting event loop
void FFTJetEFlowSmoother::beginJob() {}

// ------------ method called once each job just after ending the event loop
void FFTJetEFlowSmoother::endJob() {}

//define this as a plug-in
DEFINE_FWK_MODULE(FFTJetEFlowSmoother);
12 changes: 2 additions & 10 deletions RecoJets/FFTJetProducers/plugins/FFTJetPFPileupCleaner.cc
Expand Up @@ -22,7 +22,7 @@

// framework include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand All @@ -42,7 +42,7 @@
//
// class declaration
//
class FFTJetPFPileupCleaner : public edm::EDProducer {
class FFTJetPFPileupCleaner : public edm::stream::EDProducer<> {
public:
explicit FFTJetPFPileupCleaner(const edm::ParameterSet&);
FFTJetPFPileupCleaner() = delete;
Expand All @@ -52,9 +52,7 @@ class FFTJetPFPileupCleaner : public edm::EDProducer {

protected:
// methods
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

private:
bool isRemovable(reco::PFCandidate::ParticleType ptype) const;
Expand Down Expand Up @@ -445,11 +443,5 @@ void FFTJetPFPileupCleaner::buildRemovalMask() {
setRemovalBit(reco::PFCandidate::egamma_HF, remove_egamma_HF);
}

// ------------ method called once each job just before starting event loop
void FFTJetPFPileupCleaner::beginJob() {}

// ------------ method called once each job just after ending the event loop
void FFTJetPFPileupCleaner::endJob() {}

//define this as a plug-in
DEFINE_FWK_MODULE(FFTJetPFPileupCleaner);
13 changes: 2 additions & 11 deletions RecoJets/FFTJetProducers/plugins/FFTJetPatRecoProducer.cc
Expand Up @@ -77,9 +77,7 @@ class FFTJetPatRecoProducer : public FFTJetInterface {
typedef fftjet::ClusteringTreeSparsifier<fftjet::Peak, long> Sparsifier;

// methods
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

void buildKernelConvolver(const edm::ParameterSet&);
fftjet::PeakFinder buildPeakFinder(const edm::ParameterSet&);
Expand Down Expand Up @@ -319,6 +317,8 @@ fftjet::PeakFinder FFTJetPatRecoProducer::buildPeakFinder(const edm::ParameterSe
FFTJetPatRecoProducer::~FFTJetPatRecoProducer() {
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
if (storeGridsExternally)
externalGridStream.close();
delete clusteringTree;
delete extGrid;
}
Expand Down Expand Up @@ -424,14 +424,5 @@ void FFTJetPatRecoProducer::produce(edm::Event& iEvent, const edm::EventSetup& i
}
}

// ------------ method called once each job just before starting event loop
void FFTJetPatRecoProducer::beginJob() {}

// ------------ method called once each job just after ending the event loop
void FFTJetPatRecoProducer::endJob() {
if (storeGridsExternally)
externalGridStream.close();
}

//define this as a plug-in
DEFINE_FWK_MODULE(FFTJetPatRecoProducer);
10 changes: 2 additions & 8 deletions RecoJets/FFTJetProducers/plugins/FFTJetPileupEstimator.cc
Expand Up @@ -19,7 +19,7 @@
#include <cmath>

// Framework include files
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -43,7 +43,7 @@ using namespace fftjetcms;
//
// class declaration
//
class FFTJetPileupEstimator : public edm::EDProducer {
class FFTJetPileupEstimator : public edm::stream::EDProducer<> {
public:
explicit FFTJetPileupEstimator(const edm::ParameterSet&);
FFTJetPileupEstimator() = delete;
Expand All @@ -53,9 +53,7 @@ class FFTJetPileupEstimator : public edm::EDProducer {

protected:
// methods
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

private:
std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromConfig(double uncalibrated) const;
Expand Down Expand Up @@ -161,10 +159,6 @@ void FFTJetPileupEstimator::produce(edm::Event& iEvent, const edm::EventSetup& i
iEvent.put(std::move(summary), outputLabel);
}

void FFTJetPileupEstimator::beginJob() {}

void FFTJetPileupEstimator::endJob() {}

std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromConfig(const double curve) const {
const double pileupRho = ptToDensityFactor * (*calibrationCurve)(curve);
const double rhoUncert = ptToDensityFactor * (*uncertaintyCurve)(curve);
Expand Down
8 changes: 0 additions & 8 deletions RecoJets/FFTJetProducers/plugins/FFTJetPileupProcessor.cc
Expand Up @@ -60,9 +60,7 @@ class FFTJetPileupProcessor : public FFTJetInterface {

protected:
// methods
void beginJob() override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

private:
void buildKernelConvolver(const edm::ParameterSet&);
Expand Down Expand Up @@ -317,12 +315,6 @@ void FFTJetPileupProcessor::mixExtraGrid() {
}
}

// ------------ method called once each job just before starting event loop
void FFTJetPileupProcessor::beginJob() {}

// ------------ method called once each job just after ending the event loop
void FFTJetPileupProcessor::endJob() {}

void FFTJetPileupProcessor::loadFlatteningFactors(const edm::EventSetup& iSetup) {
edm::ESHandle<FFTJetLookupTableSequence> h;
StaticFFTJetLookupTableSequenceLoader::instance().load(iSetup, flatteningTableRecord, h);
Expand Down
22 changes: 11 additions & 11 deletions RecoJets/FFTJetProducers/plugins/FFTJetProducer.cc
Expand Up @@ -173,14 +173,16 @@ FFTJetProducer::FFTJetProducer(const edm::ParameterSet& ps)
checkConfig(iniScales, "invalid set of scales");
std::sort(iniScales->begin(), iniScales->end(), std::greater<double>());

input_recotree_token_ =
consumes<reco::PattRecoTree<fftjetcms::Real, reco::PattRecoPeak<fftjetcms::Real> > >(treeLabel);
if (storeInSinglePrecision())
input_recotree_token_f_ = consumes<reco::PattRecoTree<float, reco::PattRecoPeak<float> > >(treeLabel);
else
input_recotree_token_d_ = consumes<reco::PattRecoTree<double, reco::PattRecoPeak<double> > >(treeLabel);
input_genjet_token_ = consumes<std::vector<reco::FFTAnyJet<reco::GenJet> > >(genJetsLabel);
input_energyflow_token_ = consumes<reco::DiscretizedEnergyFlow>(treeLabel);
input_pusummary_token_ = consumes<reco::FFTJetPileupSummary>(pileupLabel);

// Most of the configuration has to be performed inside
// the "beginJob" method. This is because chaining of the
// the "beginStream" method. This is because chaining of the
// parsers between this base class and the derived classes
// can not work from the constructor of the base class.
}
Expand All @@ -191,12 +193,13 @@ FFTJetProducer::~FFTJetProducer() {}
// member functions
//
template <class Real>
void FFTJetProducer::loadSparseTreeData(const edm::Event& iEvent) {
void FFTJetProducer::loadSparseTreeData(
const edm::Event& iEvent, const edm::EDGetTokenT<reco::PattRecoTree<Real, reco::PattRecoPeak<Real> > >& tok) {
typedef reco::PattRecoTree<Real, reco::PattRecoPeak<Real> > StoredTree;

// Get the input
edm::Handle<StoredTree> input;
iEvent.getByToken(input_recotree_token_, input);
iEvent.getByToken(tok, input);

if (!input->isSparse())
throw cms::Exception("FFTJetBadConfig") << "The stored clustering tree is not sparse" << std::endl;
Expand Down Expand Up @@ -651,9 +654,9 @@ void FFTJetProducer::saveResults(edm::Event& ev, const edm::EventSetup& iSetup,
void FFTJetProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
// Load the clustering tree made by FFTJetPatRecoProducer
if (storeInSinglePrecision())
loadSparseTreeData<float>(iEvent);
loadSparseTreeData<float>(iEvent, input_recotree_token_f_);
else
loadSparseTreeData<double>(iEvent);
loadSparseTreeData<double>(iEvent, input_recotree_token_d_);

// Do we need to load the candidate collection?
if (assignConstituents || !(useGriddedAlgorithm && reuseExistingGrid))
Expand Down Expand Up @@ -810,7 +813,7 @@ FFTJetProducer::parse_jetDistanceCalc(const edm::ParameterSet& ps) {
void FFTJetProducer::assignMembershipFunctions(std::vector<fftjet::Peak>*) {}

// ------------ method called once each job just before starting event loop
void FFTJetProducer::beginJob() {
void FFTJetProducer::beginStream(edm::StreamID) {
const edm::ParameterSet& ps(myConfiguration);

// Parse the peak selector definition
Expand Down Expand Up @@ -1108,8 +1111,5 @@ void FFTJetProducer::determinePileup() {
}
}

// ------------ method called once each job just after ending the event loop
void FFTJetProducer::endJob() {}

//define this as a plug-in
DEFINE_FWK_MODULE(FFTJetProducer);
9 changes: 5 additions & 4 deletions RecoJets/FFTJetProducers/plugins/FFTJetProducer.h
Expand Up @@ -110,9 +110,8 @@ class FFTJetProducer : public fftjetcms::FFTJetInterface {

protected:
// Functions which should be overriden from the base
void beginJob() override;
void beginStream(edm::StreamID) override;
void produce(edm::Event&, const edm::EventSetup&) override;
void endJob() override;

// The following functions can be overriden by derived classes
// in order to adjust jet reconstruction algorithm behavior.
Expand Down Expand Up @@ -183,7 +182,8 @@ class FFTJetProducer : public fftjetcms::FFTJetInterface {

// Useful local utilities
template <class Real>
void loadSparseTreeData(const edm::Event&);
void loadSparseTreeData(const edm::Event&,
const edm::EDGetTokenT<reco::PattRecoTree<Real, reco::PattRecoPeak<Real> > >& tok);

void removeFakePreclusters();

Expand Down Expand Up @@ -399,7 +399,8 @@ class FFTJetProducer : public fftjetcms::FFTJetInterface {
std::vector<unsigned> cellCountsVec;

// Tokens for data access
edm::EDGetTokenT<reco::PattRecoTree<fftjetcms::Real, reco::PattRecoPeak<fftjetcms::Real> > > input_recotree_token_;
edm::EDGetTokenT<reco::PattRecoTree<double, reco::PattRecoPeak<double> > > input_recotree_token_d_;
edm::EDGetTokenT<reco::PattRecoTree<float, reco::PattRecoPeak<float> > > input_recotree_token_f_;
edm::EDGetTokenT<std::vector<reco::FFTAnyJet<reco::GenJet> > > input_genjet_token_;
edm::EDGetTokenT<reco::DiscretizedEnergyFlow> input_energyflow_token_;
edm::EDGetTokenT<reco::FFTJetPileupSummary> input_pusummary_token_;
Expand Down

0 comments on commit a25b2d7

Please sign in to comment.