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 ()
 
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 ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) 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 ()
 
virtual void endJob ()
 
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 &)
 

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
 
typedef WorkerT< EDProducerWorkerType
 
- 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::EDProducer
CurrentProcessingContext const * currentContext () const
 
- 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 93 of file FFTJetCorrectionProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 361 of file FFTJetCorrectionProducer.cc.

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

362  : inputLabel(ps.getParameter<edm::InputTag>("src")),
363  outputLabel(ps.getParameter<std::string>("outputLabel")),
364  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
365  records(ps.getParameter<std::vector<std::string> >("records")),
366  writeUncertainties(ps.getParameter<bool>("writeUncertainties")),
367  subtractPileup(ps.getParameter<bool>("subtractPileup")),
368  subtractPileupAs4Vec(ps.getParameter<bool>("subtractPileupAs4Vec")),
369  verbose(ps.getUntrackedParameter<bool>("verbose", false)),
370  eventCount(0UL)
371 {
373  "alias", outputLabel));
375 
376  if (writeUncertainties)
377  produces<std::vector<float> >(outputLabel).setBranchAlias(alias);
378 }
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 381 of file FFTJetCorrectionProducer.cc.

382 {
383 }

Member Function Documentation

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

Definition at line 171 of file FFTJetCorrectionProducer.cc.

References coll, 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, edm::Event::put(), alignCSCRings::s, python.multivaluedict::sort(), and mathSSE::sqrt().

Referenced by produce().

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

Reimplemented from edm::EDProducer.

Definition at line 394 of file FFTJetCorrectionProducer.cc.

395 {
396 }
void FFTJetCorrectionProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 399 of file FFTJetCorrectionProducer.cc.

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

Definition at line 144 of file FFTJetCorrectionProducer.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by FFTJetCorrectionProducer().

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

Definition at line 152 of file FFTJetCorrectionProducer.cc.

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

153 {
154  using reco::FFTJet;
155 
156  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(jet.getFFTSpecific()));
157  const math::XYZTLorentzVector& new4vec = adjustForPileup(
158  fftJet.f_vec(), fftJet.f_pileup(), subtractPileupAs4Vec);
159  fftJet.setFourVec(new4vec);
160  int status = fftJet.f_status();
163  else
164  status |= PILEUP_SUBTRACTION_MASK_PT;
165  fftJet.setStatus(status);
166  jet.setP4(new4vec);
167 }
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
#define PILEUP_SUBTRACTION_MASK_PT
#define PILEUP_SUBTRACTION_MASK_4VEC
Storage class for jets reconstructed by FFTJet package.
Definition: FFTJet.h:20
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 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 387 of file FFTJetCorrectionProducer.cc.

References applyCorrections(), and jet_type_switch.

389 {
390  jet_type_switch(applyCorrections, iEvent, iSetup);
391 }
#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 139 of file FFTJetCorrectionProducer.cc.

const edm::InputTag FFTJetCorrectionProducer::inputLabel
private

Definition at line 114 of file FFTJetCorrectionProducer.cc.

const JetType FFTJetCorrectionProducer::jetType
private

Definition at line 120 of file FFTJetCorrectionProducer.cc.

const std::string FFTJetCorrectionProducer::outputLabel
private

Definition at line 117 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

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

Definition at line 123 of file FFTJetCorrectionProducer.cc.

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

Definition at line 136 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileup
private

Definition at line 129 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileupAs4Vec
private

Definition at line 130 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::verbose
private

Definition at line 133 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::writeUncertainties
private

Definition at line 126 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().