CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
ShiftedParticleProducer Class Reference

#include <ShiftedParticleProducer.h>

Inheritance diagram for ShiftedParticleProducer:
edm::stream::EDProducer<>

Classes

struct  binningEntryType
 

Public Member Functions

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

Private Types

typedef edm::View< reco::CandidateCandidateView
 

Private Member Functions

double getUncShift (const reco::Candidate &originalParticle)
 
void produce (edm::Event &evt, const edm::EventSetup &es) override
 

Private Attributes

std::vector< binningEntryType * > binning_
 
std::string moduleLabel_
 
double shiftBy_
 
edm::EDGetTokenT< CandidateViewsrcToken_
 
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Vary energy of electrons/muons/tau-jets by +/- 1 standard deviation, in order to estimate resulting uncertainty on MET

NOTE: energy scale uncertainties need to be specified in python config

Author
Matthieu marionneau ETH

Definition at line 33 of file ShiftedParticleProducer.h.

Member Typedef Documentation

◆ CandidateView

Definition at line 34 of file ShiftedParticleProducer.h.

Constructor & Destructor Documentation

◆ ShiftedParticleProducer()

ShiftedParticleProducer::ShiftedParticleProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 4 of file ShiftedParticleProducer.cc.

4  {
5  moduleLabel_ = cfg.getParameter<std::string>("@module_label");
6  srcToken_ = consumes<CandidateView>(cfg.getParameter<edm::InputTag>("src"));
7  shiftBy_ = cfg.getParameter<double>("shiftBy");
8  edm::InputTag srcWeights = cfg.getParameter<edm::InputTag>("srcWeights");
9  if (!srcWeights.label().empty())
11 
12  if (cfg.exists("binning")) {
13  typedef std::vector<edm::ParameterSet> vParameterSet;
14  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
15  for (vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin(); cfgBinningEntry != cfgBinning.end();
16  ++cfgBinningEntry) {
17  binning_.push_back(new binningEntryType(*cfgBinningEntry, moduleLabel_));
18  }
19  } else {
20  std::string uncertainty = cfg.getParameter<std::string>("uncertainty");
21  binning_.push_back(new binningEntryType(uncertainty, moduleLabel_));
22  }
23 
24  produces<reco::CandidateCollection>();
25 }

References binning_, looper::cfg, moduleLabel_, shiftBy_, srcToken_, HLT_FULL_cff::srcWeights, AlCaHLTBitMon_QueryRunRegistry::string, and weightsToken_.

◆ ~ShiftedParticleProducer()

ShiftedParticleProducer::~ShiftedParticleProducer ( )
override

Definition at line 27 of file ShiftedParticleProducer.cc.

27  {
28  for (std::vector<binningEntryType*>::const_iterator it = binning_.begin(); it != binning_.end(); ++it) {
29  delete (*it);
30  }
31 }

References binning_.

Member Function Documentation

◆ getUncShift()

double ShiftedParticleProducer::getUncShift ( const reco::Candidate originalParticle)
private

Definition at line 71 of file ShiftedParticleProducer.cc.

71  {
72  double valx = 0;
73  double valy = 0;
74  for (std::vector<binningEntryType*>::iterator binningEntry = binning_.begin(); binningEntry != binning_.end();
75  ++binningEntry) {
76  if ((!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(originalParticle)) {
77  if ((*binningEntry)->energyDep_)
78  valx = originalParticle.energy();
79  else
80  valx = originalParticle.pt();
81 
82  valy = originalParticle.eta();
83  return (*binningEntry)->binUncFormula_->Eval(valx, valy);
84  }
85  }
86  return 0;
87 }

References binning_, reco::Candidate::energy(), reco::Candidate::eta(), and reco::Candidate::pt().

Referenced by produce().

◆ produce()

void ShiftedParticleProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
overrideprivate

Definition at line 33 of file ShiftedParticleProducer.cc.

33  {
34  edm::Handle<CandidateView> originalParticles;
35  evt.getByToken(srcToken_, originalParticles);
36 
40 
41  auto shiftedParticles = std::make_unique<reco::CandidateCollection>();
42 
43  for (unsigned i = 0; i < originalParticles->size(); ++i) {
44  float weight = 1.0;
46  edm::Ptr<reco::Candidate> particlePtr = originalParticles->ptrAt(i);
47  while (!weights->contains(particlePtr.id()) && (particlePtr->numberOfSourceCandidatePtrs() > 0))
48  particlePtr = particlePtr->sourceCandidatePtr(0);
49  weight = (*weights)[particlePtr];
50  }
51  const reco::Candidate& originalParticle = originalParticles->at(i);
52  reco::LeafCandidate weightedParticle(originalParticle);
53  weightedParticle.setP4(originalParticle.p4() * weight);
54  double uncertainty = getUncShift(weightedParticle);
55  double shift = shiftBy_ * uncertainty;
56 
57  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle.p4();
58  //leave 0*nan = 0
59  if ((weight > 0) && (!(edm::isNotFinite(shift) && shiftedParticleP4.mag2() == 0)))
60  shiftedParticleP4 *= (1. + shift);
61 
62  std::unique_ptr<reco::Candidate> shiftedParticle = std::make_unique<reco::LeafCandidate>(originalParticle);
63  shiftedParticle->setP4(shiftedParticleP4);
64 
65  shiftedParticles->push_back(shiftedParticle.release());
66  }
67 
68  evt.put(std::move(shiftedParticles));
69 }

References edm::View< T >::at(), edm::Event::getByToken(), getUncShift(), mps_fire::i, edm::Ptr< T >::id(), edm::isNotFinite(), edm::EDGetTokenT< T >::isUninitialized(), eostools::move(), reco::Candidate::numberOfSourceCandidatePtrs(), reco::Candidate::p4(), edm::View< T >::ptrAt(), edm::Event::put(), reco::LeafCandidate::setP4(), edm::shift, shiftBy_, edm::View< T >::size(), reco::Candidate::sourceCandidatePtr(), srcToken_, mps_merge::weight, HLT_FULL_cff::weights, and weightsToken_.

Member Data Documentation

◆ binning_

std::vector<binningEntryType*> ShiftedParticleProducer::binning_
private

◆ moduleLabel_

std::string ShiftedParticleProducer::moduleLabel_
private

◆ shiftBy_

double ShiftedParticleProducer::shiftBy_
private

Definition at line 75 of file ShiftedParticleProducer.h.

Referenced by produce(), and ShiftedParticleProducer().

◆ srcToken_

edm::EDGetTokenT<CandidateView> ShiftedParticleProducer::srcToken_
private

Definition at line 47 of file ShiftedParticleProducer.h.

Referenced by produce(), and ShiftedParticleProducer().

◆ weightsToken_

edm::EDGetTokenT<edm::ValueMap<float> > ShiftedParticleProducer::weightsToken_
private

Definition at line 48 of file ShiftedParticleProducer.h.

Referenced by produce(), and ShiftedParticleProducer().

reco::Candidate::energy
virtual double energy() const =0
energy
ShiftedParticleProducer::binning_
std::vector< binningEntryType * > binning_
Definition: ShiftedParticleProducer.h:73
mps_fire.i
i
Definition: mps_fire.py:428
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
mps_merge.weight
weight
Definition: mps_merge.py:88
reco::Candidate::pt
virtual double pt() const =0
transverse momentum
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
edm::Handle
Definition: AssociativeIterator.h:50
ShiftedParticleProducer::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition: ShiftedParticleProducer.h:47
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99170
ShiftedParticleProducer::getUncShift
double getUncShift(const reco::Candidate &originalParticle)
Definition: ShiftedParticleProducer.cc:71
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
ShiftedParticleProducer::moduleLabel_
std::string moduleLabel_
Definition: ShiftedParticleProducer.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
edm::View::at
const_reference at(size_type pos) const
edm::Ptr::id
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
ShiftedParticleProducer::weightsToken_
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
Definition: ShiftedParticleProducer.h:48
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
HLT_FULL_cff.srcWeights
srcWeights
Definition: HLT_FULL_cff.py:8647
edm::Ptr< reco::Candidate >
looper.cfg
cfg
Definition: looper.py:297
reco::Candidate
Definition: Candidate.h:27
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::Candidate::sourceCandidatePtr
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: Candidate.h:169
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
ShiftedParticleProducer::shiftBy_
double shiftBy_
Definition: ShiftedParticleProducer.h:75
edm::ValueMap< float >
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
reco::Candidate::numberOfSourceCandidatePtrs
virtual size_t numberOfSourceCandidatePtrs() const =0
reco::LeafCandidate
Definition: LeafCandidate.h:16
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
edm::View::ptrAt
Ptr< value_type > ptrAt(size_type i) const
edm::InputTag
Definition: InputTag.h:15
weight
Definition: weight.py:1