CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
EGEtScaleSysModifier Class Reference
Inheritance diagram for EGEtScaleSysModifier:
ModifyObjectValueBase

Classes

class  UncertFuncBase
 
class  UncertFuncV1
 

Public Member Functions

 EGEtScaleSysModifier (const edm::ParameterSet &conf)
 
void modifyObject (pat::Electron &ele) const final
 
void modifyObject (pat::Photon &pho) const final
 
void setConsumes (edm::ConsumesCollector &) final
 
void setEvent (const edm::Event &) final
 
void setEventContent (const edm::EventSetup &) final
 
 ~EGEtScaleSysModifier () override
 
- Public Member Functions inherited from ModifyObjectValueBase
virtual void modifyObject (reco::GsfElectron &) const
 
virtual void modifyObject (reco::Photon &) const
 
virtual void modifyObject (reco::Muon &) const
 
virtual void modifyObject (reco::BaseTau &) const
 
virtual void modifyObject (reco::Jet &) const
 
virtual void modifyObject (pat::Muon &) const
 
virtual void modifyObject (pat::Tau &) const
 
virtual void modifyObject (pat::Jet &) const
 
 ModifyObjectValueBase (const edm::ParameterSet &conf)
 
const std::string & name () const
 
virtual ~ModifyObjectValueBase ()
 

Private Member Functions

std::pair< float, float > calCombinedMom (reco::GsfElectron &ele, const float scale, const float smear) const
 
void setEcalEnergy (reco::GsfElectron &ele, const float scale, const float smear) const
 

Private Attributes

EpCombinationTool epCombTool_
 
std::unique_ptr< UncertFuncBaseuncertFunc_
 

Detailed Description

Definition at line 29 of file EGEtScaleSysModifier.cc.

Constructor & Destructor Documentation

EGEtScaleSysModifier::EGEtScaleSysModifier ( const edm::ParameterSet conf)

Definition at line 88 of file EGEtScaleSysModifier.cc.

References Exception, edm::ParameterSet::getParameter(), AlCaHLTBitMon_QueryRunRegistry::string, and uncertFunc_.

88  :
90  epCombTool_(conf.getParameter<edm::ParameterSet>("epCombConfig"))
91 {
92  const edm::ParameterSet funcPSet = conf.getParameter<edm::ParameterSet>("uncertFunc");
93  const std::string& funcName = funcPSet.getParameter<std::string>("name");
94  if(funcName == "UncertFuncV1"){
95  uncertFunc_ = std::make_unique<UncertFuncV1>(funcPSet);
96  }else{
97  throw cms::Exception("ConfigError") <<"Error constructing EGEtScaleSysModifier, function name "<<funcName<<" not valid";
98  }
99 
100 }
T getParameter(std::string const &) const
std::unique_ptr< UncertFuncBase > uncertFunc_
EpCombinationTool epCombTool_
ModifyObjectValueBase(const edm::ParameterSet &conf)
EGEtScaleSysModifier::~EGEtScaleSysModifier ( )
inlineoverride

Member Function Documentation

std::pair< float, float > EGEtScaleSysModifier::calCombinedMom ( reco::GsfElectron ele,
const float  scale,
const float  smear 
) const
private

Definition at line 182 of file EGEtScaleSysModifier.cc.

References EpCombinationTool::combine(), reco::GsfElectron::correctMomentum(), reco::GsfElectron::ecalEnergy(), reco::GsfElectron::ecalEnergyError(), epCombTool_, reco::GsfElectron::p4(), reco::GsfElectron::P4_COMBINATION, reco::GsfElectron::p4Error(), reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), setEcalEnergy(), and reco::GsfElectron::trackMomentumError().

Referenced by modifyObject(), and ~EGEtScaleSysModifier().

185 {
186  const float oldEcalEnergy = ele.ecalEnergy();
187  const float oldEcalEnergyErr = ele.ecalEnergyError();
188  const auto oldP4 = ele.p4();
189  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
190  const float oldTrkMomErr = ele.trackMomentumError();
191 
192  setEcalEnergy(ele,scale,smear);
193  const auto& combinedMomentum = epCombTool_.combine(ele);
194  ele.setCorrectedEcalEnergy(oldEcalEnergy);
195  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
196  ele.correctMomentum(oldP4,oldTrkMomErr,oldP4Err);
197 
198 
199  return combinedMomentum;
200 }
float trackMomentumError() const
Definition: GsfElectron.h:836
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:858
EpCombinationTool epCombTool_
void combine(SimpleElectron &mySimpleElectron) const
float p4Error(P4Kind kind) const
Definition: GsfElectron.cc:237
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
float ecalEnergyError() const
Definition: GsfElectron.h:849
void setEcalEnergy(reco::GsfElectron &ele, const float scale, const float smear) const
float ecalEnergy() const
Definition: GsfElectron.h:848
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::modifyObject ( pat::Electron ele) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 118 of file EGEtScaleSysModifier.cc.

References pat::PATObject< ObjectType >::addUserFloat(), calCombinedMom(), corr, reco::GsfElectron::correctMomentum(), reco::GsfElectron::ecalEnergy(), reco::GsfElectron::ecalEnergyError(), reco::LeafCandidate::energy(), reco::LeafCandidate::et(), EGEnergySysIndex::kEcalErrPreCorr, EGEnergySysIndex::kEcalPostCorr, EGEnergySysIndex::kEcalPreCorr, EGEnergySysIndex::kScaleValue, EGEnergySysIndex::kSmearValue, EGEnergySysIndex::name(), reco::GsfElectron::p4(), reco::GsfElectron::P4_COMBINATION, reco::GsfElectron::p4Error(), reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), reco::GsfElectron::trackMomentumError(), uncertFunc_, and pat::PATObject< ObjectType >::userFloat().

Referenced by ~EGEtScaleSysModifier().

119 {
120  auto getVal = [](const pat::Electron& ele,EGEnergySysIndex::Index valIndex){
121  return ele.userFloat(EGEnergySysIndex::name(valIndex));
122  };
123  //so ele.energy() may be either pre or post corrections, we have no idea
124  //so we explicity access the pre and post correction ecal energies
125  //we need the pre corrected to properly do the e/p combination
126  //we need the post corrected to get et uncertainty
127  const float ecalEnergyPostCorr = getVal(ele,EGEnergySysIndex::kEcalPostCorr);
128  const float ecalEnergyPreCorr = getVal(ele,EGEnergySysIndex::kEcalPreCorr);
129  const float ecalEnergyErrPreCorr = getVal(ele,EGEnergySysIndex::kEcalErrPreCorr);
130 
131  //the et cut is in terms of ecal et using the track angle and post corr ecal energy
132  const float etUncert = uncertFunc_->val(ele.et()/ele.energy()*ecalEnergyPostCorr);
133  const float smear = getVal(ele,EGEnergySysIndex::kSmearValue);
134  const float corr = getVal(ele,EGEnergySysIndex::kScaleValue);
135 
136  //get the values we have to reset back to
137  const float oldEcalEnergy = ele.ecalEnergy();
138  const float oldEcalEnergyErr = ele.ecalEnergyError();
139  const auto oldP4 = ele.p4();
140  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
141  const float oldTrkMomErr = ele.trackMomentumError();
142 
143  ele.setCorrectedEcalEnergy(ecalEnergyPreCorr);
144  ele.setCorrectedEcalEnergyError(ecalEnergyErrPreCorr);
145 
146  const float energyEtUncertUp = calCombinedMom(ele,corr+etUncert,smear).first;
147  const float energyEtUncertDn = calCombinedMom(ele,corr-etUncert,smear).first;
148 
149  //reset it back to how it was
150  ele.setCorrectedEcalEnergy(oldEcalEnergy);
151  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
152  ele.correctMomentum(oldP4,oldTrkMomErr,oldP4Err);
153 
154  ele.addUserFloat("energyScaleEtUp",energyEtUncertUp);
155  ele.addUserFloat("energyScaleEtDown",energyEtUncertDn);
156 
157 }
float trackMomentumError() const
Definition: GsfElectron.h:836
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
std::unique_ptr< UncertFuncBase > uncertFunc_
static const std::string & name(size_t index)
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:858
float p4Error(P4Kind kind) const
Definition: GsfElectron.cc:237
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:813
float userFloat(const std::string &key) const
Definition: PATObject.h:791
std::pair< float, float > calCombinedMom(reco::GsfElectron &ele, const float scale, const float smear) const
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
double et() const final
transverse energy
double energy() const final
energy
float ecalEnergyError() const
Definition: GsfElectron.h:849
JetCorrectorParameters corr
Definition: classes.h:5
Analysis-level electron class.
Definition: Electron.h:52
float ecalEnergy() const
Definition: GsfElectron.h:848
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::modifyObject ( pat::Photon pho) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 159 of file EGEtScaleSysModifier.cc.

References pat::PATObject< ObjectType >::addUserFloat(), corr, reco::LeafCandidate::energy(), reco::LeafCandidate::et(), EGEnergySysIndex::kEcalPostCorr, EGEnergySysIndex::kEcalPreCorr, EGEnergySysIndex::kScaleValue, EGEnergySysIndex::name(), uncertFunc_, and pat::PATObject< ObjectType >::userFloat().

160 {
161  auto getVal = [](const pat::Photon& pho,EGEnergySysIndex::Index valIndex){
162  return pho.userFloat(EGEnergySysIndex::name(valIndex));
163  };
164  //so pho.energy() may be either pre or post corrections, we have no idea
165  //so we explicity access the pre and post correction ecal energies
166  //post corr for the et value for the systematic, pre corr to apply them
167  const float ecalEnergyPostCorr = getVal(pho,EGEnergySysIndex::kEcalPostCorr);
168  const float ecalEnergyPreCorr = getVal(pho,EGEnergySysIndex::kEcalPreCorr);
169 
170  //the et cut is in terms of post corr ecal energy
171  const float etUncert = uncertFunc_->val(pho.et()/pho.energy()*ecalEnergyPostCorr);
172  const float corr = getVal(pho,EGEnergySysIndex::kScaleValue);
173 
174  const float energyEtUncertUp = ecalEnergyPreCorr*(corr+etUncert);
175  const float energyEtUncertDn = ecalEnergyPreCorr*(corr-etUncert);
176 
177  pho.addUserFloat("energyScaleEtUp",energyEtUncertUp);
178  pho.addUserFloat("energyScaleEtDown",energyEtUncertDn);
179 
180 }
Analysis-level Photon class.
Definition: Photon.h:47
std::unique_ptr< UncertFuncBase > uncertFunc_
static const std::string & name(size_t index)
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:813
float userFloat(const std::string &key) const
Definition: PATObject.h:791
double et() const final
transverse energy
double energy() const final
energy
JetCorrectorParameters corr
Definition: classes.h:5
void EGEtScaleSysModifier::setConsumes ( edm::ConsumesCollector cc)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 102 of file EGEtScaleSysModifier.cc.

Referenced by ~EGEtScaleSysModifier().

103 {
104 
105 }
void EGEtScaleSysModifier::setEcalEnergy ( reco::GsfElectron ele,
const float  scale,
const float  smear 
) const
private

Definition at line 202 of file EGEtScaleSysModifier.cc.

References DEFINE_EDM_PLUGIN, reco::GsfElectron::ecalEnergy(), reco::GsfElectron::ecalEnergyError(), reco::GsfElectron::setCorrectedEcalEnergy(), and reco::GsfElectron::setCorrectedEcalEnergyError().

Referenced by calCombinedMom(), and ~EGEtScaleSysModifier().

205 {
206  const float oldEcalEnergy = ele.ecalEnergy();
207  const float oldEcalEnergyErr = ele.ecalEnergyError();
208  ele.setCorrectedEcalEnergy( oldEcalEnergy*scale );
209  ele.setCorrectedEcalEnergyError(std::hypot( oldEcalEnergyErr*scale, oldEcalEnergy*smear*scale ) );
210 }
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
float ecalEnergyError() const
Definition: GsfElectron.h:849
float ecalEnergy() const
Definition: GsfElectron.h:848
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::setEvent ( const edm::Event iEvent)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 107 of file EGEtScaleSysModifier.cc.

Referenced by ~EGEtScaleSysModifier().

108 {
109 
110 }
void EGEtScaleSysModifier::setEventContent ( const edm::EventSetup iSetup)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 112 of file EGEtScaleSysModifier.cc.

References epCombTool_, and EpCombinationTool::setEventContent().

Referenced by ~EGEtScaleSysModifier().

113 {
115 }
EpCombinationTool epCombTool_
void setEventContent(const edm::EventSetup &iSetup)

Member Data Documentation

EpCombinationTool EGEtScaleSysModifier::epCombTool_
private

Definition at line 84 of file EGEtScaleSysModifier.cc.

Referenced by calCombinedMom(), and setEventContent().

std::unique_ptr<UncertFuncBase> EGEtScaleSysModifier::uncertFunc_
private

Definition at line 85 of file EGEtScaleSysModifier.cc.

Referenced by EGEtScaleSysModifier(), and modifyObject().