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 
22 
25 
26 #include <string>
27 #include <vector>
28 
29 template <typename T>
31 {
32  typedef std::vector<T> ParticleCollection;
33 
34  public:
35 
37  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
38  {
39  srcToken_ = consumes<ParticleCollection>(cfg.getParameter<edm::InputTag>("src"));
40 
41  shiftBy_ = cfg.getParameter<double>("shiftBy");
42 
43  if ( cfg.exists("binning") ) {
44  typedef std::vector<edm::ParameterSet> vParameterSet;
45  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
46  for ( vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin();
47  cfgBinningEntry != cfgBinning.end(); ++cfgBinningEntry ) {
48  binning_.push_back(new binningEntryType(*cfgBinningEntry));
49  }
50  } else {
51  double uncertainty = cfg.getParameter<double>("uncertainty");
52  binning_.push_back(new binningEntryType(uncertainty));
53  }
54 
55  produces<ParticleCollection>();
56  }
58  {
59  for ( typename std::vector<binningEntryType*>::const_iterator it = binning_.begin();
60  it != binning_.end(); ++it ) {
61  delete (*it);
62  }
63  }
64 
65  private:
66 
67  void produce(edm::Event& evt, const edm::EventSetup& es)
68  {
69  edm::Handle<ParticleCollection> originalParticles;
70  evt.getByToken(srcToken_, originalParticles);
71 
72  std::auto_ptr<ParticleCollection> shiftedParticles(new ParticleCollection);
73 
74  for ( typename ParticleCollection::const_iterator originalParticle = originalParticles->begin();
75  originalParticle != originalParticles->end(); ++originalParticle ) {
76 
77  double uncertainty = 0.;
78  for ( typename std::vector<binningEntryType*>::iterator binningEntry = binning_.begin();
79  binningEntry != binning_.end(); ++binningEntry ) {
80  if ( (!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(*originalParticle) ) {
81  uncertainty = (*binningEntry)->binUncertainty_;
82  break;
83  }
84  }
85 
86  double shift = shiftBy_*uncertainty;
87 
88  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle->p4();
89  shiftedParticleP4 *= (1. + shift);
90 
91  T shiftedParticle(*originalParticle);
92  shiftedParticle.setP4(shiftedParticleP4);
93 
94  shiftedParticles->push_back(shiftedParticle);
95  }
96 
97  evt.put(shiftedParticles);
98  }
99 
101 
103 
105  {
106  binningEntryType(double uncertainty)
107  : binSelection_(0),
108  binUncertainty_(uncertainty)
109  {}
111  : binSelection_(new StringCutObjectSelector<T>(cfg.getParameter<std::string>("binSelection"))),
112  binUncertainty_(cfg.getParameter<double>("binUncertainty"))
113  {}
115  {
116  delete binSelection_;
117  }
120  };
121  std::vector<binningEntryType*> binning_;
122 
123  double shiftBy_; // set to +1.0/-1.0 for up/down variation of energy scale
124 };
125 
126 #endif
127 
128 
129 
130 
T getParameter(std::string const &) const
edm::EDGetTokenT< ParticleCollection > srcToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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:116
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
static unsigned int const shift
long double T