CMS 3D CMS Logo

ShiftedParticleProducer.cc
Go to the documentation of this file.
3 
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 }
26 
28  for (std::vector<binningEntryType*>::const_iterator it = binning_.begin(); it != binning_.end(); ++it) {
29  delete (*it);
30  }
31 }
32 
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 }
70 
71 double ShiftedParticleProducer::getUncShift(const reco::Candidate& originalParticle) {
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 }
88 
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
ShiftedParticleProducer.h
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
ShiftedParticleProducer::~ShiftedParticleProducer
~ShiftedParticleProducer() override
Definition: ShiftedParticleProducer.cc:27
ShiftedParticleProducer::ShiftedParticleProducer
ShiftedParticleProducer(const edm::ParameterSet &cfg)
Definition: ShiftedParticleProducer.cc:4
edm::Handle
Definition: AssociativeIterator.h:50
ShiftedParticleProducer::binningEntryType
Definition: ShiftedParticleProducer.h:50
ShiftedParticleProducer::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition: ShiftedParticleProducer.h:47
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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::ParameterSet
Definition: ParameterSet.h:47
edm::Ptr::id
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
ShiftedParticleProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: ShiftedParticleProducer.cc:33
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
edm::EventSetup
Definition: EventSetup.h:58
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
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
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
isFinite.h
ShiftedParticleProducer::shiftBy_
double shiftBy_
Definition: ShiftedParticleProducer.h:75
edm::ValueMap< float >
ShiftedParticleProducer
Definition: ShiftedParticleProducer.h:33
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::Event
Definition: Event.h:73
edm::View::ptrAt
Ptr< value_type > ptrAt(size_type i) const
edm::InputTag
Definition: InputTag.h:15
weight
Definition: weight.py:1