test
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 
23 
26 
27 #include <string>
28 #include <vector>
29 
30 template <typename T>
32 {
33  typedef std::vector<T> ParticleCollection;
34 
35  public:
36 
38  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
39  {
40  srcToken_ = consumes<ParticleCollection>(cfg.getParameter<edm::InputTag>("src"));
41 
42  shiftBy_ = cfg.getParameter<double>("shiftBy");
43 
44  if ( cfg.exists("binning") ) {
45  typedef std::vector<edm::ParameterSet> vParameterSet;
46  vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
47  for ( vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin();
48  cfgBinningEntry != cfgBinning.end(); ++cfgBinningEntry ) {
49  binning_.push_back(new binningEntryType(*cfgBinningEntry));
50  }
51  } else {
52  double uncertainty = cfg.getParameter<double>("uncertainty");
53  binning_.push_back(new binningEntryType(uncertainty));
54  }
55 
56  produces<ParticleCollection>();
57  }
59  {
60  for ( typename std::vector<binningEntryType*>::const_iterator it = binning_.begin();
61  it != binning_.end(); ++it ) {
62  delete (*it);
63  }
64  }
65 
66  private:
67 
68  void produce(edm::Event& evt, const edm::EventSetup& es)
69  {
70  edm::Handle<ParticleCollection> originalParticles;
71  evt.getByToken(srcToken_, originalParticles);
72 
73  std::auto_ptr<ParticleCollection> shiftedParticles(new ParticleCollection);
74 
75  for ( typename ParticleCollection::const_iterator originalParticle = originalParticles->begin();
76  originalParticle != originalParticles->end(); ++originalParticle ) {
77 
78  double uncertainty = 0.;
79  for ( typename std::vector<binningEntryType*>::iterator binningEntry = binning_.begin();
80  binningEntry != binning_.end(); ++binningEntry ) {
81  if ( (!(*binningEntry)->binSelection_) || (*(*binningEntry)->binSelection_)(*originalParticle) ) {
82  uncertainty = (*binningEntry)->binUncertainty_;
83  break;
84  }
85  }
86 
87  double shift = shiftBy_*uncertainty;
88 
89  reco::Candidate::LorentzVector shiftedParticleP4 = originalParticle->p4();
90  //leave 0*nan = 0
91  if (! (edm::isNotFinite(shift) && shiftedParticleP4.mag2()==0)) 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 
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
tuple cfg
Definition: looper.py:293
edm::EDGetTokenT< ParticleCollection > srcToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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)
bool isNotFinite(T x)
Definition: isFinite.h:10
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
static unsigned int const shift
long double T