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 
9  if (cfg.exists("binning")) {
10  typedef std::vector<edm::ParameterSet> vParameterSet;
11  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
12  for (vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin(); cfgBinningEntry != cfgBinning.end();
13  ++cfgBinningEntry) {
14  binning_.push_back(new binningEntryType(*cfgBinningEntry, moduleLabel_));
15  }
16  } else {
17  std::string uncertainty = cfg.getParameter<std::string>("uncertainty");
18  binning_.push_back(new binningEntryType(uncertainty, moduleLabel_));
19  }
20 
21  produces<reco::CandidateCollection>();
22 }
23 
25  for (std::vector<binningEntryType*>::const_iterator it = binning_.begin(); it != binning_.end(); ++it) {
26  delete (*it);
27  }
28 }
29 
31  edm::Handle<CandidateView> originalParticles;
32  evt.getByToken(srcToken_, originalParticles);
33 
34  auto shiftedParticles = std::make_unique<reco::CandidateCollection>();
35 
36  for (CandidateView::const_iterator originalParticle = originalParticles->begin();
37  originalParticle != originalParticles->end();
38  ++originalParticle) {
39  double uncertainty = getUncShift(originalParticle);
40  double shift = shiftBy_ * uncertainty;
41 
42  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle->p4();
43  //leave 0*nan = 0
44  if (!(edm::isNotFinite(shift) && shiftedParticleP4.mag2() == 0))
45  shiftedParticleP4 *= (1. + shift);
46 
47  std::unique_ptr<reco::Candidate> shiftedParticle = std::make_unique<reco::LeafCandidate>(*originalParticle);
48  shiftedParticle->setP4(shiftedParticleP4);
49 
50  shiftedParticles->push_back(shiftedParticle.release());
51  }
52 
53  evt.put(std::move(shiftedParticles));
54 }
55 
57  double valx = 0;
58  double valy = 0;
59  for (std::vector<binningEntryType*>::iterator binningEntry = binning_.begin(); binningEntry != binning_.end();
60  ++binningEntry) {
61  if ((!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(*originalParticle)) {
62  if ((*binningEntry)->energyDep_)
63  valx = originalParticle->energy();
64  else
65  valx = originalParticle->pt();
66 
67  valy = originalParticle->eta();
68  return (*binningEntry)->binUncFormula_->Eval(valx, valy);
69  }
70  }
71  return 0;
72 }
73 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
edm::EDGetTokenT< CandidateView > srcToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
void produce(edm::Event &evt, const edm::EventSetup &es) override
ShiftedParticleProducer(const edm::ParameterSet &cfg)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
double getUncShift(const CandidateView::const_iterator &originalParticle)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
static unsigned int const shift
const_iterator end() const
def move(src, dest)
Definition: eostools.py:511
std::vector< binningEntryType * > binning_