CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
ShiftedParticleProducer Class Reference
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
 
 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 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<>
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

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 30 of file ShiftedParticleProducer.cc.

Member Typedef Documentation

◆ CandidateView

Definition at line 31 of file ShiftedParticleProducer.cc.

Constructor & Destructor Documentation

◆ ShiftedParticleProducer()

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

Definition at line 75 of file ShiftedParticleProducer.cc.

75  {
76  moduleLabel_ = cfg.getParameter<std::string>("@module_label");
77  srcToken_ = consumes<CandidateView>(cfg.getParameter<edm::InputTag>("src"));
78  shiftBy_ = cfg.getParameter<double>("shiftBy");
79  edm::InputTag srcWeights = cfg.getParameter<edm::InputTag>("srcWeights");
80  if (!srcWeights.label().empty())
82 
83  if (cfg.exists("binning")) {
84  typedef std::vector<edm::ParameterSet> vParameterSet;
85  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
86  for (vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin(); cfgBinningEntry != cfgBinning.end();
87  ++cfgBinningEntry) {
88  binning_.push_back(new binningEntryType(*cfgBinningEntry, moduleLabel_));
89  }
90  } else {
91  std::string uncertainty = cfg.getParameter<std::string>("uncertainty");
92  binning_.push_back(new binningEntryType(uncertainty, moduleLabel_));
93  }
94 
95  produces<reco::CandidateCollection>();
96 }

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

◆ ~ShiftedParticleProducer()

ShiftedParticleProducer::~ShiftedParticleProducer ( )
override

Definition at line 98 of file ShiftedParticleProducer.cc.

98  {
99  for (std::vector<binningEntryType*>::const_iterator it = binning_.begin(); it != binning_.end(); ++it) {
100  delete (*it);
101  }
102 }

References binning_.

Member Function Documentation

◆ getUncShift()

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

Definition at line 142 of file ShiftedParticleProducer.cc.

142  {
143  double valx = 0;
144  double valy = 0;
145  for (std::vector<binningEntryType*>::iterator binningEntry = binning_.begin(); binningEntry != binning_.end();
146  ++binningEntry) {
147  if ((!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(originalParticle)) {
148  if ((*binningEntry)->energyDep_)
149  valx = originalParticle.energy();
150  else
151  valx = originalParticle.pt();
152 
153  valy = originalParticle.eta();
154  return (*binningEntry)->binUncFormula_->Eval(valx, valy);
155  }
156  }
157  return 0;
158 }

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 104 of file ShiftedParticleProducer.cc.

104  {
105  edm::Handle<CandidateView> originalParticles;
106  evt.getByToken(srcToken_, originalParticles);
107 
111 
112  auto shiftedParticles = std::make_unique<reco::CandidateCollection>();
113 
114  for (unsigned i = 0; i < originalParticles->size(); ++i) {
115  float weight = 1.0;
117  edm::Ptr<reco::Candidate> particlePtr = originalParticles->ptrAt(i);
118  while (!weights->contains(particlePtr.id()) && (particlePtr->numberOfSourceCandidatePtrs() > 0))
119  particlePtr = particlePtr->sourceCandidatePtr(0);
120  weight = (*weights)[particlePtr];
121  }
122  const reco::Candidate& originalParticle = originalParticles->at(i);
123  reco::LeafCandidate weightedParticle(originalParticle);
124  weightedParticle.setP4(originalParticle.p4() * weight);
125  double uncertainty = getUncShift(weightedParticle);
126  double shift = shiftBy_ * uncertainty;
127 
128  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle.p4();
129  //leave 0*nan = 0
130  if ((weight > 0) && (!(edm::isNotFinite(shift) && shiftedParticleP4.mag2() == 0)))
131  shiftedParticleP4 *= (1. + shift);
132 
133  std::unique_ptr<reco::Candidate> shiftedParticle = std::make_unique<reco::LeafCandidate>(originalParticle);
134  shiftedParticle->setP4(shiftedParticleP4);
135 
136  shiftedParticles->push_back(shiftedParticle.release());
137  }
138 
139  evt.put(std::move(shiftedParticles));
140 }

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 72 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().

◆ srcToken_

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

Definition at line 44 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().

◆ weightsToken_

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

Definition at line 45 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().

reco::Candidate::energy
virtual double energy() const =0
energy
ShiftedParticleProducer::binning_
std::vector< binningEntryType * > binning_
Definition: ShiftedParticleProducer.cc:70
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.cc:44
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99207
ShiftedParticleProducer::getUncShift
double getUncShift(const reco::Candidate &originalParticle)
Definition: ShiftedParticleProducer.cc:142
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
ShiftedParticleProducer::moduleLabel_
std::string moduleLabel_
Definition: ShiftedParticleProducer.cc:42
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.cc:45
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.srcWeights
srcWeights
Definition: HLT_FULL_cff.py:8709
edm::Ptr< reco::Candidate >
looper.cfg
cfg
Definition: looper.py:296
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.cc:72
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