CMS 3D CMS Logo

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::stream::EDProducer<>

Public Member Functions

 FFTJetCorrectionProducer (const edm::ParameterSet &)
 
 ~FFTJetCorrectionProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

template<typename Jet >
void applyCorrections (edm::Event &iEvent, const edm::EventSetup &iSetup, std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &ptr)
 
template<typename Jet >
void makeProduces (const std::string &alias, const std::string &tag, std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &ptr)
 
template<typename Jet >
void performPileupSubtraction (Jet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::unique_ptr< FFTBasicJetCorrectorSequenceLoaderesLoaderBasic
 
std::unique_ptr< FFTCaloJetCorrectorSequenceLoaderesLoaderCalo
 
std::unique_ptr< FFTGenJetCorrectorSequenceLoaderesLoaderGen
 
std::unique_ptr< FFTJPTJetCorrectorSequenceLoaderesLoaderJPT
 
std::unique_ptr< FFTPFJetCorrectorSequenceLoaderesLoaderPF
 
std::unique_ptr< FFTTrackJetCorrectorSequenceLoaderesLoaderTrack
 
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::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

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::FFTJetCorrectionProducer ( const edm::ParameterSet ps)
explicit

Definition at line 345 of file FFTJetCorrectionProducer.cc.

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

346  : inputLabel(ps.getParameter<edm::InputTag>("src")),
347  outputLabel(ps.getParameter<std::string>("outputLabel")),
348  jetType(parseJetType(ps.getParameter<std::string>("jetType"))),
349  records(ps.getParameter<std::vector<std::string>>("records")),
350  writeUncertainties(ps.getParameter<bool>("writeUncertainties")),
351  subtractPileup(ps.getParameter<bool>("subtractPileup")),
352  subtractPileupAs4Vec(ps.getParameter<bool>("subtractPileupAs4Vec")),
353  verbose(ps.getUntrackedParameter<bool>("verbose", false)),
354  eventCount(0UL) {
357 
358  if (writeUncertainties)
359  produces<std::vector<float>>(outputLabel).setBranchAlias(alias);
360 
361  input_jets_token_ = consumes<std::vector<reco::FFTAnyJet<reco::Jet>>>(inputLabel);
362 }
edm::EDGetTokenT< std::vector< reco::FFTAnyJet< reco::Jet > > > input_jets_token_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
#define jet_type_switch(method, arg1, arg2)
T getUntrackedParameter(std::string const &, T const &) const
JetType parseJetType(const std::string &name)
Definition: JetType.cc:5
void makeProduces(const std::string &alias, const std::string &tag, std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &ptr)
const std::vector< std::string > records

◆ ~FFTJetCorrectionProducer()

FFTJetCorrectionProducer::~FFTJetCorrectionProducer ( )
override

Definition at line 364 of file FFTJetCorrectionProducer.cc.

364 {}

Member Function Documentation

◆ applyCorrections()

template<typename Jet >
void FFTJetCorrectionProducer::applyCorrections ( edm::Event iEvent,
const edm::EventSetup iSetup,
std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &  ptr 
)
private

Definition at line 181 of file FFTJetCorrectionProducer.cc.

References alignCSCRings::corr, gather_cfg::cout, TauDecayModes::dec, Exception, f, reco::FFTJet< Real >::f_recoScale(), reco::FFTJet< Real >::f_status(), reco::FFTJet< Real >::f_vec(), mps_fire::i, iEvent, DiMuonV_cfg::isMC, dqmiolumiharvest::j, PDWG_EXODelayedJetMET_cff::jets, gammaJetAnalysis_CHSJECs_cff::level, web.browse_db::loader, GCPpyPlots::Loader, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, eostools::move(), nJets, recoTrackAccumulator_cfi::outputLabel, PILEUP_CALCULATION_MASK, PILEUP_SUBTRACTION_MASK_ANY, DiDispStaMuonMonitor_cfi::pt, alignCSCRings::s, jetUpdater_cfi::sort, mathSSE::sqrt(), fftjetproducer_cfi::subtractPileup, and verbose.

Referenced by produce().

184  {
185  using reco::FFTJet;
186  typedef reco::FFTAnyJet<Jet> MyJet;
187  typedef std::vector<MyJet> MyCollection;
189  typedef typename Loader::data_type CorrectorSequence;
190  typedef typename CorrectorSequence::result_type CorrectorResult;
191 
192  // Load the jet corrector sequences
193  const unsigned nRecords = records.size();
194  std::vector<edm::ESHandle<CorrectorSequence>> handles(nRecords);
195  for (unsigned irec = 0; irec < nRecords; ++irec)
196  handles[irec] = loader->load(records[irec], iSetup);
197 
198  // Figure out which correction levels we are applying
199  // and create masks which will indicate this
200  sequenceMasks.clear();
201  sequenceMasks.reserve(nRecords);
202 
203  int totalMask = 0;
204  for (unsigned irec = 0; irec < nRecords; ++irec) {
205  int levelMask = 0;
206  const unsigned nLevels = handles[irec]->nLevels();
207  for (unsigned i = 0; i < nLevels; ++i) {
208  const unsigned lev = (*handles[irec])[i].level();
209 
210  // Not tracking "level 0" corrections in the status word.
211  // Level 0 is basically reserved for uncertainty calculations.
212  if (lev) {
213  const int mask = (1 << lev);
214  if (totalMask & mask)
215  throw cms::Exception("FFTJetBadConfig")
216  << "Error in FFTJetCorrectionProducer::applyCorrections:"
217  << " jet correction at level " << lev << " is applied more than once\n";
218  totalMask |= mask;
219  levelMask |= mask;
220  }
221  }
222  sequenceMasks.push_back(levelMask << 12);
223  }
224  totalMask = (totalMask << 12);
225 
226  // Is this data or MC?
227  const bool isMC = !iEvent.isRealData();
228 
229  // Load the jet collection
231  iEvent.getByToken(input_jets_token_, jets);
232 
233  // Create the output collection
234  const unsigned nJets = jets->size();
235  auto coll = std::make_unique<MyCollection>();
236  coll->reserve(nJets);
237 
238  // Cycle over jets and apply the corrector sequences
239  bool sorted = true;
240  double previousPt = DBL_MAX;
241  for (unsigned ijet = 0; ijet < nJets; ++ijet) {
242  const MyJet& j((*jets)[ijet]);
243 
244  // Check that this jet has not been corrected yet
245  const int initialStatus = j.getFFTSpecific().f_status();
246  if (initialStatus & totalMask)
247  throw cms::Exception("FFTJetBadConfig") << "Error in FFTJetCorrectionProducer::applyCorrections: "
248  << "this jet collection is already corrected for some or all "
249  << "of the specified levels\n";
250 
251  MyJet corJ(j);
252 
253  if (verbose) {
254  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
255  std::cout << "++++ Evt " << eventCount << " jet " << ijet << ": pt = " << corJ.pt()
256  << ", eta = " << fj.f_vec().eta() << ", R = " << fj.f_recoScale() << ", s = 0x" << std::hex
257  << fj.f_status() << std::dec << 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  if (initialStatus & PILEUP_SUBTRACTION_MASK_ANY)
266  throw cms::Exception("FFTJetBadConfig") << "Error in FFTJetCorrectionProducer::applyCorrections: "
267  << "this jet collection is already pileup-subtracted\n";
268  if (!(initialStatus & PILEUP_CALCULATION_MASK))
269  throw cms::Exception("FFTJetBadConfig") << "Error in FFTJetCorrectionProducer::applyCorrections: "
270  << "pileup was not calculated for this jet collection\n";
272 
273  if (verbose) {
274  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
275  std::cout << " Pileup subtract"
276  << ": pt = " << corJ.pt() << ", eta = " << fj.f_vec().eta() << ", R = " << fj.f_recoScale()
277  << ", s = 0x" << std::hex << fj.f_status() << std::dec << std::endl;
278  }
279  }
280 
281  // Apply all jet correction sequences
282  double sigmaSquared = 0.0;
283  for (unsigned irec = 0; irec < nRecords; ++irec) {
284  const CorrectorResult& corr = handles[irec]->correct(corJ, isMC);
285 
286  // Update the 4-vector
287  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(corJ.getFFTSpecific()));
288  corJ.setP4(corr.vec());
289  fftJet.setFourVec(corr.vec());
290 
291  // Update the jet correction status
292  fftJet.setStatus(fftJet.f_status() | sequenceMasks[irec]);
293 
294  // Update the (systematic) uncertainty
295  const double s = corr.sigma();
296  sigmaSquared += s * s;
297  }
298 
299  // There is no place for uncertainty in the jet structure.
300  // However, there is the unused pileup field (FFTJet maintains
301  // the pileup separately as a 4-vector). Use this unused field
302  // to store the uncertainty. This hack is needed because
303  // subsequent sequence sorting by Pt can change the jet ordering.
304  if (writeUncertainties)
305  corJ.setPileup(sqrt(sigmaSquared));
306 
307  coll->push_back(corJ);
308 
309  // Check whether the sequence remains sorted by pt
310  const double pt = corJ.pt();
311  if (pt > previousPt)
312  sorted = false;
313  previousPt = pt;
314 
315  if (verbose) {
316  const reco::FFTJet<float>& fj = corJ.getFFTSpecific();
317  std::cout << " Fully corrected"
318  << ": pt = " << corJ.pt() << ", eta = " << fj.f_vec().eta() << ", R = " << fj.f_recoScale()
319  << ", s = 0x" << std::hex << fj.f_status() << std::dec << std::endl;
320  }
321  }
322 
323  if (!sorted)
324  std::sort(coll->begin(), coll->end(), LocalSortByPt());
325 
326  // Create the uncertainty sequence
327  if (writeUncertainties) {
328  auto unc = std::make_unique<std::vector<float>>();
329  unc->reserve(nJets);
330  for (unsigned ijet = 0; ijet < nJets; ++ijet) {
331  MyJet& j((*coll)[ijet]);
332  unc->push_back(j.pileup());
333  j.setPileup(0.f);
334  }
335  iEvent.put(std::move(unc), outputLabel);
336  }
337 
338  iEvent.put(std::move(coll), outputLabel);
339  ++eventCount;
340 }
edm::EDGetTokenT< std::vector< reco::FFTAnyJet< reco::Jet > > > input_jets_token_
::ecal::reco::ComputationScalarType data_type
static constexpr int nJets
int iEvent
Definition: GenABIO.cc:224
dictionary corr
std::vector< BaseVolumeHandle * > handles
T sqrt(T t)
Definition: SSEVec.h:23
Implements inheritance relationships for FFTJet jets.
Definition: FFTAnyJet.h:16
double f[11][100]
#define PILEUP_SUBTRACTION_MASK_ANY
Storage class for jets reconstructed by FFTJet package.
Definition: FFTJet.h:19
dictionary isMC
Definition: DiMuonV_cfg.py:36
int f_status() const
Definition: FFTJet.h:89
#define PILEUP_CALCULATION_MASK
const std::vector< std::string > records
const math::XYZTLorentzVector & f_vec() const
Definition: FFTJet.h:74
def move(src, dest)
Definition: eostools.py:511
Real f_recoScale() const
Definition: FFTJet.h:85

◆ makeProduces()

template<typename Jet >
void FFTJetCorrectionProducer::makeProduces ( const std::string &  alias,
const std::string &  tag,
std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &  ptr 
)
private

Definition at line 149 of file FFTJetCorrectionProducer.cc.

References isoTrack_cff::alias, GCPpyPlots::Loader, and makeGlobalPositionRcd_cfg::tag.

Referenced by FFTJetCorrectionProducer().

152  {
153  typedef reco::FFTAnyJet<Jet> MyJet;
155 
156  produces<std::vector<MyJet>>(tag).setBranchAlias(alias);
157 
158  ptr = std::make_unique<Loader>();
159  const unsigned nRecords = records.size();
160  for (unsigned irec = 0; irec < nRecords; ++irec)
161  ptr->acquireToken(records[irec], consumesCollector());
162 }
Implements inheritance relationships for FFTJet jets.
Definition: FFTAnyJet.h:16
const std::vector< std::string > records

◆ performPileupSubtraction()

template<typename Jet >
void FFTJetCorrectionProducer::performPileupSubtraction ( Jet &  jet)
private

Definition at line 165 of file FFTJetCorrectionProducer.cc.

References fftjetcms::adjustForPileup(), metsig::jet, PILEUP_SUBTRACTION_MASK_4VEC, PILEUP_SUBTRACTION_MASK_PT, mps_update::status, and fftjetproducer_cfi::subtractPileupAs4Vec.

165  {
166  using reco::FFTJet;
167 
168  FFTJet<float>& fftJet(const_cast<FFTJet<float>&>(jet.getFFTSpecific()));
169  const math::XYZTLorentzVector& new4vec = adjustForPileup(fftJet.f_vec(), fftJet.f_pileup(), subtractPileupAs4Vec);
170  fftJet.setFourVec(new4vec);
171  int status = fftJet.f_status();
174  else
176  fftJet.setStatus(status);
177  jet.setP4(new4vec);
178 }
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)

◆ produce()

void FFTJetCorrectionProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 367 of file FFTJetCorrectionProducer.cc.

References applyCorrections(), iEvent, and jet_type_switch.

367  {
369 }
void applyCorrections(edm::Event &iEvent, const edm::EventSetup &iSetup, std::unique_ptr< typename FFTJetCorrectorSequenceTypemap< reco::FFTAnyJet< Jet >>::loader > &ptr)
#define jet_type_switch(method, arg1, arg2)
int iEvent
Definition: GenABIO.cc:224

Member Data Documentation

◆ esLoaderBasic

std::unique_ptr<FFTBasicJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderBasic
private

Definition at line 140 of file FFTJetCorrectionProducer.cc.

◆ esLoaderCalo

std::unique_ptr<FFTCaloJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderCalo
private

Definition at line 141 of file FFTJetCorrectionProducer.cc.

◆ esLoaderGen

std::unique_ptr<FFTGenJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderGen
private

Definition at line 142 of file FFTJetCorrectionProducer.cc.

◆ esLoaderJPT

std::unique_ptr<FFTJPTJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderJPT
private

Definition at line 145 of file FFTJetCorrectionProducer.cc.

◆ esLoaderPF

std::unique_ptr<FFTPFJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderPF
private

Definition at line 143 of file FFTJetCorrectionProducer.cc.

◆ esLoaderTrack

std::unique_ptr<FFTTrackJetCorrectorSequenceLoader> FFTJetCorrectionProducer::esLoaderTrack
private

Definition at line 144 of file FFTJetCorrectionProducer.cc.

◆ eventCount

unsigned long FFTJetCorrectionProducer::eventCount
private

Definition at line 134 of file FFTJetCorrectionProducer.cc.

◆ input_jets_token_

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

Definition at line 137 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

◆ inputLabel

const edm::InputTag FFTJetCorrectionProducer::inputLabel
private

Definition at line 109 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

◆ jetType

const JetType FFTJetCorrectionProducer::jetType
private

Definition at line 115 of file FFTJetCorrectionProducer.cc.

◆ outputLabel

const std::string FFTJetCorrectionProducer::outputLabel
private

Definition at line 112 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().

◆ records

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

Definition at line 118 of file FFTJetCorrectionProducer.cc.

◆ sequenceMasks

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

Definition at line 131 of file FFTJetCorrectionProducer.cc.

◆ subtractPileup

const bool FFTJetCorrectionProducer::subtractPileup
private

Definition at line 124 of file FFTJetCorrectionProducer.cc.

◆ subtractPileupAs4Vec

const bool FFTJetCorrectionProducer::subtractPileupAs4Vec
private

Definition at line 125 of file FFTJetCorrectionProducer.cc.

◆ verbose

const bool FFTJetCorrectionProducer::verbose
private

Definition at line 128 of file FFTJetCorrectionProducer.cc.

◆ writeUncertainties

const bool FFTJetCorrectionProducer::writeUncertainties
private

Definition at line 121 of file FFTJetCorrectionProducer.cc.

Referenced by FFTJetCorrectionProducer().