CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector
< edm::ProductResolverIndex >
const & 
indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector
< edm::ProductResolverIndex >
const & 
putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector
< ProductResolverIndexAndSkipBit >
const & 
itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

template<typename Jet >
void applyCorrections (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
void beginJob () override
 
void endJob () override
 
template<typename Jet >
void makeProduces (const std::string &alias, const std::string &tag)
 
template<typename Jet >
void performPileupSubtraction (Jet &)
 
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
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
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)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Description: producer for correcting jets created by FFTJetProducer

Implementation: [Notes on implementation]

Definition at line 87 of file FFTJetCorrectionProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 321 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.

322  : inputLabel(ps.getParameter<edm::InputTag>("src")),
323  outputLabel(ps.getParameter<std::string>("outputLabel")),
324  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
325  records(ps.getParameter<std::vector<std::string>>("records")),
326  writeUncertainties(ps.getParameter<bool>("writeUncertainties")),
327  subtractPileup(ps.getParameter<bool>("subtractPileup")),
328  subtractPileupAs4Vec(ps.getParameter<bool>("subtractPileupAs4Vec")),
329  verbose(ps.getUntrackedParameter<bool>("verbose", false)),
330  eventCount(0UL) {
333 
334  if (writeUncertainties)
335  produces<std::vector<float>>(outputLabel).setBranchAlias(alias);
336 
337  input_jets_token_ = consumes<std::vector<reco::FFTAnyJet<reco::Jet>>>(inputLabel);
338 }
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::vector< std::string > records
FFTJetCorrectionProducer::~FFTJetCorrectionProducer ( )
override

Definition at line 340 of file FFTJetCorrectionProducer.cc.

340 {}

Member Function Documentation

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

Definition at line 160 of file FFTJetCorrectionProducer.cc.

References alignCSCRings::corr, gather_cfg::cout, TauDecayModes::dec, Exception, validate-o2o-wbm::f, reco::FFTJet< Real >::f_recoScale(), reco::FFTJet< Real >::f_status(), reco::FFTJet< Real >::f_vec(), edm::Event::getByToken(), mps_fire::i, instance, submitPVValidationJobs::isMC, edm::EventBase::isRealData(), dqmiolumiharvest::j, fwrapper::jets, testEve_cfg::level, eostools::move(), PILEUP_CALCULATION_MASK, PILEUP_SUBTRACTION_MASK_ANY, DiDispStaMuonMonitor_cfi::pt, edm::Event::put(), alignCSCRings::s, mathSSE::sqrt(), and verbose.

Referenced by produce().

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

Reimplemented from edm::EDProducer.

Definition at line 348 of file FFTJetCorrectionProducer.cc.

348 {}
void FFTJetCorrectionProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 351 of file FFTJetCorrectionProducer.cc.

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

Definition at line 139 of file FFTJetCorrectionProducer.cc.

References GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by FFTJetCorrectionProducer().

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

Definition at line 144 of file FFTJetCorrectionProducer.cc.

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

144  {
145  using reco::FFTJet;
146 
147  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(jet.getFFTSpecific()));
148  const math::XYZTLorentzVector& new4vec = adjustForPileup(fftJet.f_vec(), fftJet.f_pileup(), subtractPileupAs4Vec);
149  fftJet.setFourVec(new4vec);
150  int status = fftJet.f_status();
153  else
154  status |= PILEUP_SUBTRACTION_MASK_PT;
155  fftJet.setStatus(status);
156  jet.setP4(new4vec);
157 }
list status
Definition: mps_update.py:107
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
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 343 of file FFTJetCorrectionProducer.cc.

References applyCorrections(), and jet_type_switch.

343  {
344  jet_type_switch(applyCorrections, iEvent, iSetup);
345 }
#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 132 of file FFTJetCorrectionProducer.cc.

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

Definition at line 135 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

const edm::InputTag FFTJetCorrectionProducer::inputLabel
private

Definition at line 107 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

const JetType FFTJetCorrectionProducer::jetType
private

Definition at line 113 of file FFTJetCorrectionProducer.cc.

const std::string FFTJetCorrectionProducer::outputLabel
private

Definition at line 110 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

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

Definition at line 116 of file FFTJetCorrectionProducer.cc.

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

Definition at line 129 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileup
private

Definition at line 122 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::subtractPileupAs4Vec
private

Definition at line 123 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::verbose
private

Definition at line 126 of file FFTJetCorrectionProducer.cc.

const bool FFTJetCorrectionProducer::writeUncertainties
private

Definition at line 119 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().