CMS 3D CMS Logo

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

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

Inheritance diagram for FFTJetCorrectionProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 FFTJetCorrectionProducer (const edm::ParameterSet &)
 
 ~FFTJetCorrectionProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

template<typename Jet >
void applyCorrections (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
virtual void beginJob () override
 
virtual void endJob () override
 
template<typename Jet >
void makeProduces (const std::string &alias, const std::string &tag)
 
template<typename Jet >
void performPileupSubtraction (Jet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

unsigned long eventCount
 
const edm::InputTag inputLabel
 
const JetType jetType
 
const std::string outputLabel
 
const std::vector< std::string > records
 
std::vector< int > sequenceMasks
 
const bool subtractPileup
 
const bool subtractPileupAs4Vec
 
const bool verbose
 
const bool writeUncertainties
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: producer for correcting jets created by FFTJetProducer

Implementation: [Notes on implementation]

Definition at line 92 of file FFTJetCorrectionProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 360 of file FFTJetCorrectionProducer.cc.

References edm::ParameterSet::getUntrackedParameter(), jet_type_switch, makeProduces(), outputLabel, AlCaHLTBitMon_QueryRunRegistry::string, and writeUncertainties.

361  : inputLabel(ps.getParameter<edm::InputTag>("src")),
362  outputLabel(ps.getParameter<std::string>("outputLabel")),
363  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
364  records(ps.getParameter<std::vector<std::string> >("records")),
365  writeUncertainties(ps.getParameter<bool>("writeUncertainties")),
366  subtractPileup(ps.getParameter<bool>("subtractPileup")),
367  subtractPileupAs4Vec(ps.getParameter<bool>("subtractPileupAs4Vec")),
368  verbose(ps.getUntrackedParameter<bool>("verbose", false)),
369  eventCount(0UL)
370 {
372  "alias", outputLabel));
374 
375  if (writeUncertainties)
376  produces<std::vector<float> >(outputLabel).setBranchAlias(alias);
377 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define jet_type_switch(method, arg1, arg2)
void makeProduces(const std::string &alias, const std::string &tag)
JetType parseJetType(const std::string &name)
Definition: JetType.cc:5
const std::vector< std::string > records
FFTJetCorrectionProducer::~FFTJetCorrectionProducer ( )

Definition at line 380 of file FFTJetCorrectionProducer.cc.

381 {
382 }

Member Function Documentation

template<typename Jet >
void FFTJetCorrectionProducer::applyCorrections ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Definition at line 170 of file FFTJetCorrectionProducer.cc.

References alignCSCRings::corr, gather_cfg::cout, edm::hlt::Exception, f, reco::FFTJet< Real >::f_recoScale(), reco::FFTJet< Real >::f_status(), reco::FFTJet< Real >::f_vec(), edm::Event::getByLabel(), i, dtTPAnalyzer_cfg::inputLabel, instance, makeTFileFromDB::isMC, edm::EventBase::isRealData(), j, fwrapper::jets, testEve_cfg::level, PILEUP_CALCULATION_MASK, PILEUP_SUBTRACTION_MASK_ANY, RecoTauCleanerPlugins::pt, edm::Event::put(), alignCSCRings::s, python.multivaluedict::sort(), and mathSSE::sqrt().

Referenced by produce().

172 {
173  using reco::FFTJet;
174 
175  // Various useful typedefs
176  typedef reco::FFTAnyJet<Jet> MyJet;
177  typedef std::vector<MyJet> MyCollection;
178  typedef typename FFTJetCorrectorSequenceTypemap<MyJet>::loader Loader;
179  typedef typename Loader::data_type CorrectorSequence;
180  typedef typename CorrectorSequence::result_type CorrectorResult;
181 
182  // Load the jet corrector sequences
183  const unsigned nRecords = records.size();
184  std::vector<edm::ESHandle<CorrectorSequence> > handles(nRecords);
185  for (unsigned irec=0; irec<nRecords; ++irec)
186  Loader::instance().load(iSetup, records[irec], handles[irec]);
187 
188  // Figure out which correction levels we are applying
189  // and create masks which will indicate this
190  sequenceMasks.clear();
191  sequenceMasks.reserve(nRecords);
192 
193  int totalMask = 0;
194  for (unsigned irec=0; irec<nRecords; ++irec)
195  {
196  int levelMask = 0;
197  const unsigned nLevels = handles[irec]->nLevels();
198  for (unsigned i=0; i<nLevels; ++i)
199  {
200  const unsigned lev = (*handles[irec])[i].level();
201 
202  // Not tracking "level 0" corrections in the status word.
203  // Level 0 is basically reserved for uncertainty calculations.
204  if (lev)
205  {
206  const int mask = (1 << lev);
207  if (totalMask & mask)
208  throw cms::Exception("FFTJetBadConfig")
209  << "Error in FFTJetCorrectionProducer::applyCorrections:"
210  << " jet correction at level " << lev
211  << " is applied more than once\n";
212  totalMask |= mask;
213  levelMask |= mask;
214  }
215  }
216  sequenceMasks.push_back(levelMask << 12);
217  }
218  totalMask = (totalMask << 12);
219 
220  // Is this data or MC?
221  const bool isMC = !iEvent.isRealData();
222 
223  // Load the jet collection
225  iEvent.getByLabel(inputLabel, jets);
226 
227  // Create the output collection
228  const unsigned nJets = jets->size();
229  std::auto_ptr<MyCollection> coll(new MyCollection());
230  coll->reserve(nJets);
231 
232  // Cycle over jets and apply the corrector sequences
233  bool sorted = true;
234  double previousPt = DBL_MAX;
235  for (unsigned ijet=0; ijet<nJets; ++ijet)
236  {
237  const MyJet& j((*jets)[ijet]);
238 
239  // Check that this jet has not been corrected yet
240  const int initialStatus = j.getFFTSpecific().f_status();
241  if (initialStatus & totalMask)
242  throw cms::Exception("FFTJetBadConfig")
243  << "Error in FFTJetCorrectionProducer::applyCorrections: "
244  << "this jet collection is already corrected for some or all "
245  << "of the specified levels\n";
246 
247  MyJet corJ(j);
248 
249  if (verbose)
250  {
251  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
252  std::cout << "++++ Evt " << eventCount << " jet " << ijet
253  << ": pt = " << corJ.pt()
254  << ", eta = " << fj.f_vec().eta()
255  << ", R = " << fj.f_recoScale()
256  << ", s = 0x" << std::hex << fj.f_status() << std::dec
257  << std::endl;
258  }
259 
260  // Check if we need to subtract pileup first.
261  // Pileup subtraction is not part of the corrector sequence
262  // itself because 4-vector subtraction does not map well
263  // into multiplication of 4-vectors by a scale factor.
264  if (subtractPileup)
265  {
266  if (initialStatus & PILEUP_SUBTRACTION_MASK_ANY)
267  throw cms::Exception("FFTJetBadConfig")
268  << "Error in FFTJetCorrectionProducer::applyCorrections: "
269  << "this jet collection is already pileup-subtracted\n";
270  if (!(initialStatus & PILEUP_CALCULATION_MASK))
271  throw cms::Exception("FFTJetBadConfig")
272  << "Error in FFTJetCorrectionProducer::applyCorrections: "
273  << "pileup was not calculated for this jet collection\n";
275 
276  if (verbose)
277  {
278  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
279  std::cout << " Pileup subtract"
280  << ": pt = " << corJ.pt()
281  << ", eta = " << fj.f_vec().eta()
282  << ", R = " << fj.f_recoScale()
283  << ", s = 0x" << std::hex << fj.f_status() << std::dec
284  << std::endl;
285  }
286  }
287 
288  // Apply all jet correction sequences
289  double sigmaSquared = 0.0;
290  for (unsigned irec=0; irec<nRecords; ++irec)
291  {
292  const CorrectorResult& corr = handles[irec]->correct(corJ, isMC);
293 
294  // Update the 4-vector
295  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(corJ.getFFTSpecific()));
296  corJ.setP4(corr.vec());
297  fftJet.setFourVec(corr.vec());
298 
299  // Update the jet correction status
300  fftJet.setStatus(fftJet.f_status() | sequenceMasks[irec]);
301 
302  // Update the (systematic) uncertainty
303  const double s = corr.sigma();
304  sigmaSquared += s*s;
305  }
306 
307  // There is no place for uncertainty in the jet structure.
308  // However, there is the unused pileup field (FFTJet maintains
309  // the pileup separately as a 4-vector). Use this unused field
310  // to store the uncertainty. This hack is needed because
311  // subsequent sequence sorting by Pt can change the jet ordering.
312  if (writeUncertainties)
313  corJ.setPileup(sqrt(sigmaSquared));
314 
315  coll->push_back(corJ);
316 
317  // Check whether the sequence remains sorted by pt
318  const double pt = corJ.pt();
319  if (pt > previousPt)
320  sorted = false;
321  previousPt = pt;
322 
323  if (verbose)
324  {
325  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
326  std::cout << " Fully corrected"
327  << ": pt = " << corJ.pt()
328  << ", eta = " << fj.f_vec().eta()
329  << ", R = " << fj.f_recoScale()
330  << ", s = 0x" << std::hex << fj.f_status() << std::dec
331  << std::endl;
332  }
333  }
334 
335  if (!sorted)
336  std::sort(coll->begin(), coll->end(), LocalSortByPt());
337 
338  // Create the uncertainty sequence
339  if (writeUncertainties)
340  {
341  std::auto_ptr<std::vector<float> > unc(new std::vector<float>());
342  unc->reserve(nJets);
343  for (unsigned ijet=0; ijet<nJets; ++ijet)
344  {
345  MyJet& j((*coll)[ijet]);
346  unc->push_back(j.pileup());
347  j.setPileup(0.f);
348  }
349  iEvent.put(unc, outputLabel);
350  }
351 
352  iEvent.put(coll, outputLabel);
353  ++eventCount;
354 }
int i
Definition: DBlmapReader.cc:9
static PFTauRenderPlugin instance
int f_status() const
Definition: FFTJet.h:77
bool isRealData() const
Definition: EventBase.h:60
Real f_recoScale() const
Definition: FFTJet.h:73
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
Implements inheritance relationships for FFTJet jets.
Definition: FFTAnyJet.h:16
int j
Definition: DBlmapReader.cc:9
const math::XYZTLorentzVector & f_vec() const
Definition: FFTJet.h:62
double f[11][100]
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
#define PILEUP_SUBTRACTION_MASK_ANY
Storage class for jets reconstructed by FFTJet package.
Definition: FFTJet.h:19
tuple cout
Definition: gather_cfg.py:121
tuple level
Definition: testEve_cfg.py:34
#define PILEUP_CALCULATION_MASK
const std::vector< std::string > records
void FFTJetCorrectionProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 393 of file FFTJetCorrectionProducer.cc.

394 {
395 }
void FFTJetCorrectionProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 398 of file FFTJetCorrectionProducer.cc.

399 {
400 }
template<typename T >
void FFTJetCorrectionProducer::makeProduces ( const std::string &  alias,
const std::string &  tag 
)
private

Definition at line 143 of file FFTJetCorrectionProducer.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by FFTJetCorrectionProducer().

145 {
146  produces<std::vector<reco::FFTAnyJet<T> > >(tag).setBranchAlias(alias);
147 }
template<typename Jet >
void FFTJetCorrectionProducer::performPileupSubtraction ( Jet &  jet)
private

Definition at line 151 of file FFTJetCorrectionProducer.cc.

References fftjetcms::adjustForPileup(), PILEUP_SUBTRACTION_MASK_4VEC, PILEUP_SUBTRACTION_MASK_PT, and ntuplemaker::status.

152 {
153  using reco::FFTJet;
154 
155  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(jet.getFFTSpecific()));
156  const math::XYZTLorentzVector& new4vec = adjustForPileup(
157  fftJet.f_vec(), fftJet.f_pileup(), subtractPileupAs4Vec);
158  fftJet.setFourVec(new4vec);
159  int status = fftJet.f_status();
162  else
163  status |= PILEUP_SUBTRACTION_MASK_PT;
164  fftJet.setStatus(status);
165  jet.setP4(new4vec);
166 }
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
#define PILEUP_SUBTRACTION_MASK_PT
#define PILEUP_SUBTRACTION_MASK_4VEC
Storage class for jets reconstructed by FFTJet package.
Definition: FFTJet.h:19
tuple status
Definition: ntuplemaker.py:245
math::XYZTLorentzVector adjustForPileup(const math::XYZTLorentzVector &jet, const math::XYZTLorentzVector &pileup, bool subtractPileupAs4Vec)
void FFTJetCorrectionProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 386 of file FFTJetCorrectionProducer.cc.

References applyCorrections(), and jet_type_switch.

388 {
389  jet_type_switch(applyCorrections, iEvent, iSetup);
390 }
#define jet_type_switch(method, arg1, arg2)
void applyCorrections(edm::Event &iEvent, const edm::EventSetup &iSetup)

Member Data Documentation

unsigned long FFTJetCorrectionProducer::eventCount
private

Definition at line 138 of file FFTJetCorrectionProducer.cc.

const edm::InputTag FFTJetCorrectionProducer::inputLabel
private

Definition at line 113 of file FFTJetCorrectionProducer.cc.

const JetType FFTJetCorrectionProducer::jetType
private

Definition at line 119 of file FFTJetCorrectionProducer.cc.

const std::string FFTJetCorrectionProducer::outputLabel
private

Definition at line 116 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

const std::vector<std::string> FFTJetCorrectionProducer::records
private

Definition at line 122 of file FFTJetCorrectionProducer.cc.

std::vector<int> FFTJetCorrectionProducer::sequenceMasks
private

Definition at line 135 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileup
private

Definition at line 128 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileupAs4Vec
private

Definition at line 129 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::verbose
private

Definition at line 132 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::writeUncertainties
private

Definition at line 125 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().