CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
FFTJetPileupProcessor Class Reference

#include <RecoJets/FFTJetProducers/plugins/FFTJetPileupProcessor.cc>

Inheritance diagram for FFTJetPileupProcessor:
edm::EDProducer fftjetcms::FFTJetInterface edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 FFTJetPileupProcessor (const edm::ParameterSet &)
 
 ~FFTJetPileupProcessor ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from fftjetcms::FFTJetInterface
virtual ~FFTJetInterface ()
 

Protected Member Functions

void beginJob ()
 
void endJob ()
 
void produce (edm::Event &, const edm::EventSetup &)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 
- Protected Member Functions inherited from fftjetcms::FFTJetInterface
template<class Ptr >
void checkConfig (const Ptr &ptr, const char *message)
 
void discretizeEnergyFlow ()
 
 FFTJetInterface (const edm::ParameterSet &)
 
double getEventScale () const
 
void loadInputCollection (const edm::Event &)
 
bool storeInSinglePrecision () const
 
const reco::Particle::PointvertexUsed () const
 

Private Member Functions

void buildKernelConvolver (const edm::ParameterSet &)
 
 FFTJetPileupProcessor ()
 
 FFTJetPileupProcessor (const FFTJetPileupProcessor &)
 
void mixExtraGrid ()
 
FFTJetPileupProcessoroperator= (const FFTJetPileupProcessor &)
 

Private Attributes

std::auto_ptr< fftjet::Grid2d
< fftjetcms::Real > > 
convolvedFlow
 
std::auto_ptr
< fftjet::AbsConvolverBase
< Real > > 
convolver
 
unsigned convolverMaxBin
 
unsigned convolverMinBin
 
unsigned currentFileNum
 
std::auto_ptr< MyFFTEngineengine
 
std::vector< double > etaFlatteningFactors
 
std::vector< std::string > externalGridFiles
 
std::auto_ptr
< fftjet::EquidistantInLogSpace > 
filterScales
 
std::ifstream gridStream
 
std::auto_ptr
< fftjet::AbsFrequencyKernel > 
kernel2d
 
unsigned nPercentiles
 
double pileupEtaPhiArea
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from fftjetcms::FFTJetInterface
enum  JetType {
  BASICJET = 0, GENJET, CALOJET, PFJET,
  TRACKJET, JPTJET
}
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from fftjetcms::FFTJetInterface
static JetType parse_jet_type (const std::string &name)
 
- Protected Attributes inherited from fftjetcms::FFTJetInterface
const AnomalousTower anomalous
 
std::vector< unsigned > candidateIndex
 
const bool doPVCorrection
 
std::auto_ptr< fftjet::Grid2d
< fftjetcms::Real > > 
energyFlow
 
const std::vector< double > etaDependentMagnutideFactors
 
std::vector
< fftjetcms::VectorLike
eventData
 
edm::Handle< reco::CandidateViewinputCollection
 
const edm::InputTag inputLabel
 
const JetType jetType
 
const std::string outputLabel
 
const edm::InputTag srcPVs
 

Detailed Description

Description: Runs FFTJet multiscale pileup filtering code and saves the results

Implementation: [Notes on implementation]

Definition at line 52 of file FFTJetPileupProcessor.cc.

Constructor & Destructor Documentation

FFTJetPileupProcessor::FFTJetPileupProcessor ( const edm::ParameterSet ps)
explicit

Definition at line 110 of file FFTJetPileupProcessor.cc.

References buildKernelConvolver(), fftjetcms::FFTJetInterface::checkConfig(), convolvedFlow, fftjetcms::FFTJetInterface::energyFlow, etaFlatteningFactors, edm::hlt::Exception, fftjetcms::fftjet_Grid2d_parser(), filterScales, edm::ParameterSet::getParameter(), and fftjetcms::FFTJetInterface::outputLabel.

111  : FFTJetInterface(ps),
113  ps.getParameter<std::vector<double> >("etaFlatteningFactors")),
114  nPercentiles(ps.getParameter<unsigned>("nPercentiles")),
115  convolverMinBin(ps.getParameter<unsigned>("convolverMinBin")),
116  convolverMaxBin(ps.getParameter<unsigned>("convolverMaxBin")),
117  pileupEtaPhiArea(ps.getParameter<double>("pileupEtaPhiArea")),
118  externalGridFiles(ps.getParameter<std::vector<std::string> >("externalGridFiles")),
119  currentFileNum(externalGridFiles.size() + 1U)
120 {
121  // Build the discretization grid
123  ps.getParameter<edm::ParameterSet>("GridConfiguration"));
124  checkConfig(energyFlow, "invalid discretization grid");
125 
126  // Copy of the grid which will be used for convolutions
127  convolvedFlow = std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> >(
128  new fftjet::Grid2d<fftjetcms::Real>(*energyFlow));
129 
130  // Make sure the size of flattening factors is appropriate
131  if (!etaFlatteningFactors.empty())
132  {
133  if (etaFlatteningFactors.size() != convolvedFlow->nEta())
134  throw cms::Exception("FFTJetBadConfig")
135  << "ERROR in FFTJetPileupProcessor constructor:"
136  " number of elements in the \"etaFlatteningFactors\""
137  " vector is inconsistent with the iscretization grid binning"
138  << std::endl;
139  }
140 
141  // Build the FFT engine(s), pattern recognition kernel(s),
142  // and the kernel convolver
144 
145  // Build the set of pattern recognition scales
146  const unsigned nScales = ps.getParameter<unsigned>("nScales");
147  const double minScale = ps.getParameter<double>("minScale");
148  const double maxScale = ps.getParameter<double>("maxScale");
149  if (minScale <= 0.0 || maxScale < minScale || nScales == 0U)
150  throw cms::Exception("FFTJetBadConfig")
151  << "invalid filter scales" << std::endl;
152 
153  filterScales = std::auto_ptr<fftjet::EquidistantInLogSpace>(
154  new fftjet::EquidistantInLogSpace(minScale, maxScale, nScales));
155 
156  produces<TH2D>(outputLabel);
157  produces<std::pair<double,double> >(outputLabel);
158 }
T getParameter(std::string const &) const
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
std::vector< std::string > externalGridFiles
std::auto_ptr< fftjet::EquidistantInLogSpace > filterScales
std::auto_ptr< fftjet::Grid2d< Real > > fftjet_Grid2d_parser(const edm::ParameterSet &ps)
void checkConfig(const Ptr &ptr, const char *message)
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > convolvedFlow
void buildKernelConvolver(const edm::ParameterSet &)
std::vector< double > etaFlatteningFactors
const std::string outputLabel
FFTJetPileupProcessor::~FFTJetPileupProcessor ( )

Definition at line 198 of file FFTJetPileupProcessor.cc.

199 {
200 }
FFTJetPileupProcessor::FFTJetPileupProcessor ( )
private
FFTJetPileupProcessor::FFTJetPileupProcessor ( const FFTJetPileupProcessor )
private

Member Function Documentation

void FFTJetPileupProcessor::beginJob ( void  )
protectedvirtual

Reimplemented from edm::EDProducer.

Definition at line 332 of file FFTJetPileupProcessor.cc.

333 {
334 }
void FFTJetPileupProcessor::buildKernelConvolver ( const edm::ParameterSet ps)
private

Definition at line 161 of file FFTJetPileupProcessor.cc.

References convolver, convolverMaxBin, convolverMinBin, fftjetcms::FFTJetInterface::energyFlow, engine, edm::hlt::Exception, edm::ParameterSet::getParameter(), kernel2d, and M_PI.

Referenced by FFTJetPileupProcessor().

162 {
163  // Get the eta and phi scales for the kernel(s)
164  double kernelEtaScale = ps.getParameter<double>("kernelEtaScale");
165  const double kernelPhiScale = ps.getParameter<double>("kernelPhiScale");
166  if (kernelEtaScale <= 0.0 || kernelPhiScale <= 0.0)
167  throw cms::Exception("FFTJetBadConfig")
168  << "invalid kernel scales" << std::endl;
169 
172  convolverMaxBin > energyFlow->nEta())
173  throw cms::Exception("FFTJetBadConfig")
174  << "invalid convolver bin range" << std::endl;
175 
176  // FFT assumes that the grid extent in eta is 2*Pi. Adjust the
177  // kernel scale in eta to compensate.
178  kernelEtaScale *= (2.0*M_PI/(energyFlow->etaMax() - energyFlow->etaMin()));
179 
180  // Build the FFT engine
181  engine = std::auto_ptr<MyFFTEngine>(
182  new MyFFTEngine(energyFlow->nEta(), energyFlow->nPhi()));
183 
184  // 2d kernel
185  kernel2d = std::auto_ptr<fftjet::AbsFrequencyKernel>(
186  new fftjet::DiscreteGauss2d(
187  kernelEtaScale, kernelPhiScale,
188  energyFlow->nEta(), energyFlow->nPhi()));
189 
190  // 2d convolver
191  convolver = std::auto_ptr<fftjet::AbsConvolverBase<Real> >(
192  new fftjet::FrequencyKernelConvolver<Real,Complex>(
193  engine.get(), kernel2d.get(),
195 }
T getParameter(std::string const &) const
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
std::auto_ptr< fftjet::AbsConvolverBase< Real > > convolver
std::auto_ptr< fftjet::AbsFrequencyKernel > kernel2d
#define M_PI
Definition: BFit3D.cc:3
std::auto_ptr< MyFFTEngine > engine
fftjet::FFTWDoubleEngine MyFFTEngine
void FFTJetPileupProcessor::endJob ( void  )
protectedvirtual

Reimplemented from edm::EDProducer.

Definition at line 338 of file FFTJetPileupProcessor.cc.

339 {
340 }
void FFTJetPileupProcessor::mixExtraGrid ( )
private

Definition at line 283 of file FFTJetPileupProcessor.cc.

References fftjetcms::add_Grid2d_data(), currentFileNum, fftjetcms::FFTJetInterface::energyFlow, edm::hlt::Exception, externalGridFiles, g, gridStream, recoMuon::in, and SiPixelLorentzAngle_cfi::read.

Referenced by produce().

284 {
285  const unsigned nFiles = externalGridFiles.size();
286  if (currentFileNum > nFiles)
287  {
288  // This is the first time this function is called
289  currentFileNum = 0;
291  std::ios_base::in | std::ios_base::binary);
292  if (!gridStream.is_open())
293  throw cms::Exception("FFTJetBadConfig")
294  << "ERROR in FFTJetPileupProcessor::mixExtraGrid():"
295  " failed to open external grid file "
296  << externalGridFiles[currentFileNum] << std::endl;
297  }
298 
299  const fftjet::Grid2d<float>* g = fftjet::Grid2d<float>::read(gridStream);
300 
301  // If we can't read the grid, we need to switch to another file
302  for (unsigned ntries=0; ntries<nFiles && g == 0; ++ntries)
303  {
304  gridStream.close();
305  currentFileNum = (currentFileNum + 1U) % nFiles;
307  std::ios_base::in | std::ios_base::binary);
308  if (!gridStream.is_open())
309  throw cms::Exception("FFTJetBadConfig")
310  << "ERROR in FFTJetPileupProcessor::mixExtraGrid():"
311  " failed to open external grid file "
312  << externalGridFiles[currentFileNum] << std::endl;
314  }
315 
316  if (g)
317  {
318  add_Grid2d_data(energyFlow.get(), *g);
319  delete g;
320  }
321  else
322  {
323  // Too bad, no useful file found
324  throw cms::Exception("FFTJetBadConfig")
325  << "ERROR in FFTJetPileupProcessor::mixExtraGrid():"
326  " no valid grid records found" << std::endl;
327  }
328 }
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
std::vector< std::string > externalGridFiles
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void add_Grid2d_data(fftjet::Grid2d< F2 > *to, const fftjet::Grid2d< F1 > &from)
FFTJetPileupProcessor& FFTJetPileupProcessor::operator= ( const FFTJetPileupProcessor )
private
void FFTJetPileupProcessor::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
protectedvirtual

Implements edm::EDProducer.

Definition at line 204 of file FFTJetPileupProcessor.cc.

References convolvedFlow, convolver, convolverMaxBin, convolverMinBin, fftjetcms::FFTJetInterface::discretizeEnergyFlow(), fftjetcms::FFTJetInterface::energyFlow, etaFlatteningFactors, externalGridFiles, filterScales, g, fftjetcms::FFTJetInterface::loadInputCollection(), mixExtraGrid(), nPercentiles, fftjetcms::FFTJetInterface::outputLabel, pileupEtaPhiArea, edm::Event::put(), lumiQueryAPI::q, and python.multivaluedict::sort().

206 {
207  loadInputCollection(iEvent);
209 
210  // Determine the average Et density for this event.
211  // Needs to be done here, before mixing in another grid.
212  const fftjet::Grid2d<Real>& g(*energyFlow);
213  const double densityBeforeMixing = g.sum()/pileupEtaPhiArea;
214 
215  // Mix an extra grid (if requested)
216  double densityAfterMixing = -1.0;
217  if (!externalGridFiles.empty())
218  {
219  mixExtraGrid();
220  densityAfterMixing = g.sum()/pileupEtaPhiArea;
221  }
222 
223  // Various useful variables
224  const unsigned nScales = filterScales->size();
225  const double* scales = &(*filterScales)[0];
226  Real* convData = const_cast<Real*>(convolvedFlow->data());
227  Real* sortData = convData + convolverMinBin*convolvedFlow->nPhi();
228  const unsigned dataLen = convolverMaxBin ?
230  convolvedFlow->nEta()*convolvedFlow->nPhi();
231 
232  // We will fill the following histo
233  std::auto_ptr<TH2D> pTable(new TH2D("FFTJetPileupProcessor",
234  "FFTJetPileupProcessor",
235  nScales, -0.5, nScales-0.5,
236  nPercentiles, 0.0, 1.0));
237  pTable->SetDirectory(0);
238  pTable->GetXaxis()->SetTitle("Filter Number");
239  pTable->GetYaxis()->SetTitle("Et CDF");
240  pTable->GetZaxis()->SetTitle("Et Density");
241 
242  // Go over all scales and perform the convolutions
243  convolver->setEventData(g.data(), g.nEta(), g.nPhi());
244  for (unsigned iscale=0; iscale<nScales; ++iscale)
245  {
246  // Perform the convolution
247  convolver->convolveWithKernel(
248  scales[iscale], convData,
249  convolvedFlow->nEta(), convolvedFlow->nPhi());
250 
251  // Apply the flattening factors
252  if (!etaFlatteningFactors.empty())
253  convolvedFlow->scaleData(&etaFlatteningFactors[0],
254  etaFlatteningFactors.size());
255 
256  // Sort the convolved data
257  std::sort(sortData, sortData+dataLen);
258 
259  // Determine the percentile points
260  for (unsigned iper=0; iper<nPercentiles; ++iper)
261  {
262  // Map percentile 0 into point number 0,
263  // 1 into point number dataLen-1
264  const double q = (iper + 0.5)/nPercentiles;
265  const double dindex = q*(dataLen-1U);
266  const unsigned ilow = static_cast<unsigned>(std::floor(dindex));
267  const double percentile = fftjet::lin_interpolate_1d(
268  ilow, ilow+1U, sortData[ilow], sortData[ilow+1U], dindex);
269 
270  // Store the calculated percentile
271  pTable->SetBinContent(iscale+1U, iper+1U, percentile);
272  }
273  }
274 
275  iEvent.put(pTable, outputLabel);
276 
277  std::auto_ptr<std::pair<double,double> > etSum(
278  new std::pair<double,double>(densityBeforeMixing, densityAfterMixing));
279  iEvent.put(etSum, outputLabel);
280 }
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > energyFlow
std::vector< std::string > externalGridFiles
std::auto_ptr< fftjet::EquidistantInLogSpace > filterScales
std::auto_ptr< fftjet::AbsConvolverBase< Real > > convolver
void loadInputCollection(const edm::Event &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::auto_ptr< fftjet::Grid2d< fftjetcms::Real > > convolvedFlow
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
std::vector< double > etaFlatteningFactors
double Real
const std::string outputLabel

Member Data Documentation

std::auto_ptr<fftjet::Grid2d<fftjetcms::Real> > FFTJetPileupProcessor::convolvedFlow
private

Definition at line 82 of file FFTJetPileupProcessor.cc.

Referenced by FFTJetPileupProcessor(), and produce().

std::auto_ptr<fftjet::AbsConvolverBase<Real> > FFTJetPileupProcessor::convolver
private

Definition at line 79 of file FFTJetPileupProcessor.cc.

Referenced by buildKernelConvolver(), and produce().

unsigned FFTJetPileupProcessor::convolverMaxBin
private

Definition at line 96 of file FFTJetPileupProcessor.cc.

Referenced by buildKernelConvolver(), and produce().

unsigned FFTJetPileupProcessor::convolverMinBin
private

Definition at line 95 of file FFTJetPileupProcessor.cc.

Referenced by buildKernelConvolver(), and produce().

unsigned FFTJetPileupProcessor::currentFileNum
private

Definition at line 104 of file FFTJetPileupProcessor.cc.

Referenced by mixExtraGrid().

std::auto_ptr<MyFFTEngine> FFTJetPileupProcessor::engine
private

Definition at line 73 of file FFTJetPileupProcessor.cc.

Referenced by buildKernelConvolver().

std::vector<double> FFTJetPileupProcessor::etaFlatteningFactors
private

Definition at line 89 of file FFTJetPileupProcessor.cc.

Referenced by FFTJetPileupProcessor(), and produce().

std::vector<std::string> FFTJetPileupProcessor::externalGridFiles
private

Definition at line 102 of file FFTJetPileupProcessor.cc.

Referenced by mixExtraGrid(), and produce().

std::auto_ptr<fftjet::EquidistantInLogSpace> FFTJetPileupProcessor::filterScales
private

Definition at line 85 of file FFTJetPileupProcessor.cc.

Referenced by FFTJetPileupProcessor(), and produce().

std::ifstream FFTJetPileupProcessor::gridStream
private

Definition at line 103 of file FFTJetPileupProcessor.cc.

Referenced by mixExtraGrid().

std::auto_ptr<fftjet::AbsFrequencyKernel> FFTJetPileupProcessor::kernel2d
private

Definition at line 76 of file FFTJetPileupProcessor.cc.

Referenced by buildKernelConvolver().

unsigned FFTJetPileupProcessor::nPercentiles
private

Definition at line 92 of file FFTJetPileupProcessor.cc.

Referenced by produce().

double FFTJetPileupProcessor::pileupEtaPhiArea
private

Definition at line 99 of file FFTJetPileupProcessor.cc.

Referenced by produce().