CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
pat::ObjectEnergyScale< T > Class Template Reference

Energy scale shifting and smearing module. More...

#include "PhysicsTools/PatAlgos/interface/ObjectEnergyScale.h"

Inheritance diagram for pat::ObjectEnergyScale< T >:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 ObjectEnergyScale (const edm::ParameterSet &iConfig)
 
 ~ObjectEnergyScale ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

float getSmearing (T &object)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
void setScale (T &object)
 

Private Attributes

float factor_
 
CLHEP::RandGaussQ * gaussian_
 
float iniRes_
 
edm::InputTag objects_
 
float shiftFactor_
 
bool useDefaultIniRes_
 
bool useFixedMass_
 
bool useIniResByFraction_
 
bool useWorsenResByFactor_
 
float worsenRes_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

template<class T>
class pat::ObjectEnergyScale< T >

Energy scale shifting and smearing module.

This class provides energy scale shifting & smearing to objects with resolutions for systematic error studies. A detailed documentation is found in PhysicsTools/PatAlgos/data/ObjectEnergyScale.cfi

Author
Volker Adler
Version
Id:
ObjectEnergyScale.h,v 1.2 2010/02/20 21:00:18 wmtan Exp

Definition at line 37 of file ObjectEnergyScale.h.

Constructor & Destructor Documentation

template<class T >
pat::ObjectEnergyScale< T >::ObjectEnergyScale ( const edm::ParameterSet iConfig)
explicit

Definition at line 70 of file ObjectEnergyScale.h.

References edm::RandomNumberGenerator::getEngine(), and edm::ParameterSet::getParameter().

71 {
72  objects_ = iConfig.getParameter<edm::InputTag>("scaledObject");
73  useFixedMass_ = iConfig.getParameter<bool> ("fixMass");
74  shiftFactor_ = iConfig.getParameter<double> ("shiftFactor");
75  useDefaultIniRes_ = iConfig.getParameter<bool> ("useDefaultInitialResolution");
76  iniRes_ = iConfig.getParameter<double> ("initialResolution");
77  useIniResByFraction_ = iConfig.getParameter<bool> ("initialResolutionByFraction");
78  worsenRes_ = iConfig.getParameter<double> ("worsenResolution");
79  useWorsenResByFactor_ = iConfig.getParameter<bool> ("worsenResolutionByFactor");
80 
82  CLHEP::HepRandomEngine& engine = rng->getEngine();
83  gaussian_ = new CLHEP::RandGaussQ(engine);
84 
85  produces<std::vector<T> >();
86 }
T getParameter(std::string const &) const
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
CLHEP::RandGaussQ * gaussian_
template<class T >
pat::ObjectEnergyScale< T >::~ObjectEnergyScale ( )

Definition at line 90 of file ObjectEnergyScale.h.

91 {
92  delete gaussian_;
93 }
CLHEP::RandGaussQ * gaussian_

Member Function Documentation

template<class T >
float pat::ObjectEnergyScale< T >::getSmearing ( T object)
private

Returns a smearing factor which is multiplied to the initial value then to get it smeared, sets initial resolution to resolution provided by input object if required and converts the 'worsenResolution' parameter to protect from meaningless final resolution values.

Definition at line 120 of file ObjectEnergyScale.h.

References funct::cos(), relval_parameters_module::energy, max(), funct::pow(), funct::sin(), mathSSE::sqrt(), and theta().

121 {
122  // overwrite config file parameter 'initialResolution' if required
123  if ( useDefaultIniRes_ ) {
124  // get initial resolution from input object (and calculate relative initial resolution from absolute value)
125  iniRes_ = (1. / sin(object.theta()) * object.resolutionEt() - object.et() * cos(object.theta()) / std::pow(sin(object.theta()),2) * object.resolutionTheta()) / object.energy(); // conversion of resEt and resTheta into energy resolution
126  } else if ( ! useIniResByFraction_ ) {
127  // calculate relative initial resolution from absolute value
128  iniRes_ = iniRes_ / object.energy();
129  }
130  // Is 'worsenResolution' a factor or a summand?
131  float finalRes = useWorsenResByFactor_ ?
132  (1.+fabs(1.-fabs(worsenRes_))) * fabs(iniRes_) :
133  fabs(worsenRes_)/object.energy() + fabs(iniRes_); // conversion as protection from "finalRes_<iniRes_"
134  // return smearing factor
135  return std::max( gaussian_->fire(1., sqrt(std::pow(finalRes,2)-std::pow(iniRes_,2))), 0. ); // protection from negative smearing factors
136 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:28
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
list object
Definition: dbtoconf.py:77
CLHEP::RandGaussQ * gaussian_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
template<class T >
void pat::ObjectEnergyScale< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 97 of file ObjectEnergyScale.h.

References edm::Event::getByLabel(), i, and edm::Event::put().

98 {
99  edm::Handle<std::vector<T> > objectsHandle;
100  iEvent.getByLabel(objects_, objectsHandle);
101  std::vector<T> objects = *objectsHandle;
102  std::auto_ptr<std::vector<T> > objectsVector(new std::vector<T>);
103  objectsVector->reserve(objectsHandle->size());
104 
105  for ( unsigned int i = 0; i < objects.size(); i++ ) {
106  factor_ = shiftFactor_ * ( objects[i].energy() > 0. ?
107  getSmearing(objects[i]) :
108  0.);
109  setScale(objects[i]);
110  objectsVector->push_back(objects[i]);
111  }
112  iEvent.put(objectsVector);
113 }
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
float getSmearing(T &object)
template<class T >
void pat::ObjectEnergyScale< T >::setScale ( T object)
private

Mutliplies the final factor (consisting of shifting and smearing factors) to the object's 4-vector and takes care of preserved masses.

Definition at line 142 of file ObjectEnergyScale.h.

References relval_parameters_module::energy, funct::pow(), and mathSSE::sqrt().

143 {
144  if ( factor_ < 0. ) {
145  factor_ = 0.;
146  }
147  // calculate the momentum factor for fixed or not fixed mass
148  float factorMomentum = useFixedMass_ && object.p() > 0. ?
149  sqrt(std::pow(factor_*object.energy(),2)-object.massSqr()) / object.p() :
150  factor_;
151  // set shifted & smeared new 4-vector
152  object.setP4(reco::Particle::LorentzVector(factorMomentum*object.px(),
153  factorMomentum*object.py(),
154  factorMomentum*object.pz(),
155  factor_ *object.energy()));
156 }
T sqrt(T t)
Definition: SSEVec.h:28
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40

Member Data Documentation

template<class T >
float pat::ObjectEnergyScale< T >::factor_
private

Definition at line 52 of file ObjectEnergyScale.h.

template<class T >
CLHEP::RandGaussQ* pat::ObjectEnergyScale< T >::gaussian_
private

Definition at line 61 of file ObjectEnergyScale.h.

template<class T >
float pat::ObjectEnergyScale< T >::iniRes_
private

Definition at line 52 of file ObjectEnergyScale.h.

template<class T >
edm::InputTag pat::ObjectEnergyScale< T >::objects_
private

Definition at line 51 of file ObjectEnergyScale.h.

template<class T >
float pat::ObjectEnergyScale< T >::shiftFactor_
private

Definition at line 52 of file ObjectEnergyScale.h.

template<class T >
bool pat::ObjectEnergyScale< T >::useDefaultIniRes_
private

Definition at line 56 of file ObjectEnergyScale.h.

template<class T >
bool pat::ObjectEnergyScale< T >::useFixedMass_
private

Definition at line 56 of file ObjectEnergyScale.h.

template<class T >
bool pat::ObjectEnergyScale< T >::useIniResByFraction_
private

Definition at line 56 of file ObjectEnergyScale.h.

template<class T >
bool pat::ObjectEnergyScale< T >::useWorsenResByFactor_
private

Definition at line 56 of file ObjectEnergyScale.h.

template<class T >
float pat::ObjectEnergyScale< T >::worsenRes_
private

Definition at line 52 of file ObjectEnergyScale.h.