CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::Candidate
CandidateView
 

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

Definition at line 31 of file ShiftedParticleProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 75 of file ShiftedParticleProducer.cc.

References binning_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), moduleLabel_, shiftBy_, srcToken_, HLT_FULL_cff::srcWeights, AlCaHLTBitMon_QueryRunRegistry::string, and weightsToken_.

75  {
76  moduleLabel_ = cfg.getParameter<std::string>("@module_label");
77  srcToken_ = consumes<CandidateView>(cfg.getParameter<edm::InputTag>("src"));
78  shiftBy_ = cfg.getParameter<double>("shiftBy");
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 }
edm::EDGetTokenT< CandidateView > srcToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< binningEntryType * > binning_
ShiftedParticleProducer::~ShiftedParticleProducer ( )
override

Definition at line 98 of file ShiftedParticleProducer.cc.

References binning_.

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

Member Function Documentation

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

Definition at line 142 of file ShiftedParticleProducer.cc.

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

Referenced by produce().

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 }
virtual double energy() const =0
energy
virtual double pt() const =0
transverse momentum
std::vector< binningEntryType * > binning_
virtual double eta() const =0
momentum pseudorapidity
void ShiftedParticleProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
overrideprivate

Definition at line 104 of file ShiftedParticleProducer.cc.

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

104  {
105  edm::Handle<CandidateView> originalParticles;
106  evt.getByToken(srcToken_, originalParticles);
107 
110  evt.getByToken(weightsToken_, weights);
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 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
edm::EDGetTokenT< CandidateView > srcToken_
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
double getUncShift(const reco::Candidate &originalParticle)
def move
Definition: eostools.py:511
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
static unsigned int const shift
int weight
Definition: histoStyle.py:51
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector

Member Data Documentation

std::vector<binningEntryType*> ShiftedParticleProducer::binning_
private
std::string ShiftedParticleProducer::moduleLabel_
private
double ShiftedParticleProducer::shiftBy_
private

Definition at line 72 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().

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

Definition at line 44 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().

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

Definition at line 45 of file ShiftedParticleProducer.cc.

Referenced by produce(), and ShiftedParticleProducer().