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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 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
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) 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
 
edm::EDGetTokenT< std::vector
< reco::FFTAnyJet< reco::Jet > > > 
input_jets_token_
 
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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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 362 of file FFTJetCorrectionProducer.cc.

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

363  : inputLabel(ps.getParameter<edm::InputTag>("src")),
364  outputLabel(ps.getParameter<std::string>("outputLabel")),
365  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
366  records(ps.getParameter<std::vector<std::string> >("records")),
367  writeUncertainties(ps.getParameter<bool>("writeUncertainties")),
368  subtractPileup(ps.getParameter<bool>("subtractPileup")),
369  subtractPileupAs4Vec(ps.getParameter<bool>("subtractPileupAs4Vec")),
370  verbose(ps.getUntrackedParameter<bool>("verbose", false)),
371  eventCount(0UL)
372 {
374  "alias", outputLabel));
376 
377  if (writeUncertainties)
378  produces<std::vector<float> >(outputLabel).setBranchAlias(alias);
379 
380  input_jets_token_ = consumes<std::vector<reco::FFTAnyJet<reco::Jet> > >(inputLabel);
381 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< std::vector< reco::FFTAnyJet< reco::Jet > > > input_jets_token_
#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 384 of file FFTJetCorrectionProducer.cc.

385 {
386 }

Member Function Documentation

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

Definition at line 174 of file FFTJetCorrectionProducer.cc.

References coll, corr, gather_cfg::cout, TauDecayModes::dec, Exception, f, reco::FFTJet< Real >::f_recoScale(), reco::FFTJet< Real >::f_status(), reco::FFTJet< Real >::f_vec(), edm::Event::getByToken(), i, instance, edm::EventBase::isRealData(), j, fwrapper::jets, testEve_cfg::level, PILEUP_CALCULATION_MASK, PILEUP_SUBTRACTION_MASK_ANY, EnergyCorrector::pt, edm::Event::put(), alignCSCRings::s, and mathSSE::sqrt().

Referenced by produce().

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

398 {
399 }
void FFTJetCorrectionProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 402 of file FFTJetCorrectionProducer.cc.

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

Definition at line 147 of file FFTJetCorrectionProducer.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by FFTJetCorrectionProducer().

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

Definition at line 155 of file FFTJetCorrectionProducer.cc.

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

156 {
157  using reco::FFTJet;
158 
159  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(jet.getFFTSpecific()));
160  const math::XYZTLorentzVector& new4vec = adjustForPileup(
161  fftJet.f_vec(), fftJet.f_pileup(), subtractPileupAs4Vec);
162  fftJet.setFourVec(new4vec);
163  int status = fftJet.f_status();
166  else
167  status |= PILEUP_SUBTRACTION_MASK_PT;
168  fftJet.setStatus(status);
169  jet.setP4(new4vec);
170 }
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 390 of file FFTJetCorrectionProducer.cc.

References applyCorrections(), and jet_type_switch.

392 {
393  jet_type_switch(applyCorrections, iEvent, iSetup);
394 }
#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.

edm::EDGetTokenT<std::vector<reco::FFTAnyJet<reco::Jet> > > FFTJetCorrectionProducer::input_jets_token_
private

Definition at line 142 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

const edm::InputTag FFTJetCorrectionProducer::inputLabel
private

Definition at line 114 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

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().