CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ShiftedParticleProducerT.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatUtils_ShiftedParticleProducerT_h
2 #define PhysicsTools_PatUtils_ShiftedParticleProducerT_h
3 
24 
27 
28 #include <string>
29 #include <vector>
30 
31 template <typename T>
33 {
34  typedef std::vector<T> ParticleCollection;
35 
36  public:
37 
39  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
40  {
41  src_ = cfg.getParameter<edm::InputTag>("src");
42 
43  shiftBy_ = cfg.getParameter<double>("shiftBy");
44 
45  if ( cfg.exists("binning") ) {
46  typedef std::vector<edm::ParameterSet> vParameterSet;
47  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
48  for ( vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin();
49  cfgBinningEntry != cfgBinning.end(); ++cfgBinningEntry ) {
50  binning_.push_back(new binningEntryType(*cfgBinningEntry));
51  }
52  } else {
53  double uncertainty = cfg.getParameter<double>("uncertainty");
54  binning_.push_back(new binningEntryType(uncertainty));
55  }
56 
57  produces<ParticleCollection>();
58  }
60  {
61  for ( typename std::vector<binningEntryType*>::const_iterator it = binning_.begin();
62  it != binning_.end(); ++it ) {
63  delete (*it);
64  }
65  }
66 
67  private:
68 
69  void produce(edm::Event& evt, const edm::EventSetup& es)
70  {
71  edm::Handle<ParticleCollection> originalParticles;
72  evt.getByLabel(src_, originalParticles);
73 
74  std::auto_ptr<ParticleCollection> shiftedParticles(new ParticleCollection);
75 
76  for ( typename ParticleCollection::const_iterator originalParticle = originalParticles->begin();
77  originalParticle != originalParticles->end(); ++originalParticle ) {
78 
79  double uncertainty = 0.;
80  for ( typename std::vector<binningEntryType*>::iterator binningEntry = binning_.begin();
81  binningEntry != binning_.end(); ++binningEntry ) {
82  if ( (!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(*originalParticle) ) {
83  uncertainty = (*binningEntry)->binUncertainty_;
84  break;
85  }
86  }
87 
88  double shift = shiftBy_*uncertainty;
89 
90  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle->p4();
91  shiftedParticleP4 *= (1. + shift);
92 
93  T shiftedParticle(*originalParticle);
94  shiftedParticle.setP4(shiftedParticleP4);
95 
96  shiftedParticles->push_back(shiftedParticle);
97  }
98 
99  evt.put(shiftedParticles);
100  }
101 
102  std::string moduleLabel_;
103 
105 
107  {
108  binningEntryType(double uncertainty)
109  : binSelection_(0),
110  binUncertainty_(uncertainty)
111  {}
113  : binSelection_(new StringCutObjectSelector<T>(cfg.getParameter<std::string>("binSelection"))),
114  binUncertainty_(cfg.getParameter<double>("binUncertainty"))
115  {}
117  {
118  delete binSelection_;
119  }
122  };
123  std::vector<binningEntryType*> binning_;
124 
125  double shiftBy_; // set to +1.0/-1.0 for up/down variation of energy scale
126 };
127 
128 #endif
129 
130 
131 
132 
T getParameter(std::string const &) const
void produce(edm::Event &evt, const edm::EventSetup &es)
std::vector< binningEntryType * > binning_
bool exists(std::string const &parameterName) const
checks if a parameter exists
ShiftedParticleProducerT(const edm::ParameterSet &cfg)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
static unsigned int const shift
long double T