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, edm::ConsumesCollector &)
 
void modifyObject (pat::Electron &ele) const final
 
void modifyObject (pat::Photon &pho) const 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,
edm::ConsumesCollector  
)

Definition at line 87 of file EGEtScaleSysModifier.cc.

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

87  :
89  epCombTool_(conf.getParameter<edm::ParameterSet>("epCombConfig"))
90 {
91  const edm::ParameterSet funcPSet = conf.getParameter<edm::ParameterSet>("uncertFunc");
92  const std::string& funcName = funcPSet.getParameter<std::string>("name");
93  if(funcName == "UncertFuncV1"){
94  uncertFunc_ = std::make_unique<UncertFuncV1>(funcPSet);
95  }else{
96  throw cms::Exception("ConfigError") <<"Error constructing EGEtScaleSysModifier, function name "<<funcName<<" not valid";
97  }
98 
99 }
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 176 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().

179 {
180  const float oldEcalEnergy = ele.ecalEnergy();
181  const float oldEcalEnergyErr = ele.ecalEnergyError();
182  const auto oldP4 = ele.p4();
183  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
184  const float oldTrkMomErr = ele.trackMomentumError();
185 
186  setEcalEnergy(ele,scale,smear);
187  const auto& combinedMomentum = epCombTool_.combine(ele);
188  ele.setCorrectedEcalEnergy(oldEcalEnergy);
189  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
190  ele.correctMomentum(oldP4,oldTrkMomErr,oldP4Err);
191 
192 
193  return combinedMomentum;
194 }
float trackMomentumError() const
Definition: GsfElectron.h:847
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:225
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:869
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:860
void setEcalEnergy(reco::GsfElectron &ele, const float scale, const float smear) const
float ecalEnergy() const
Definition: GsfElectron.h:859
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::modifyObject ( pat::Electron ele) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 112 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().

113 {
114  auto getVal = [](const pat::Electron& ele,EGEnergySysIndex::Index valIndex){
115  return ele.userFloat(EGEnergySysIndex::name(valIndex));
116  };
117  //so ele.energy() may be either pre or post corrections, we have no idea
118  //so we explicity access the pre and post correction ecal energies
119  //we need the pre corrected to properly do the e/p combination
120  //we need the post corrected to get et uncertainty
121  const float ecalEnergyPostCorr = getVal(ele,EGEnergySysIndex::kEcalPostCorr);
122  const float ecalEnergyPreCorr = getVal(ele,EGEnergySysIndex::kEcalPreCorr);
123  const float ecalEnergyErrPreCorr = getVal(ele,EGEnergySysIndex::kEcalErrPreCorr);
124 
125  //the et cut is in terms of ecal et using the track angle and post corr ecal energy
126  const float etUncert = uncertFunc_->val(ele.et()/ele.energy()*ecalEnergyPostCorr);
127  const float smear = getVal(ele,EGEnergySysIndex::kSmearValue);
128  const float corr = getVal(ele,EGEnergySysIndex::kScaleValue);
129 
130  //get the values we have to reset back to
131  const float oldEcalEnergy = ele.ecalEnergy();
132  const float oldEcalEnergyErr = ele.ecalEnergyError();
133  const auto oldP4 = ele.p4();
134  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
135  const float oldTrkMomErr = ele.trackMomentumError();
136 
137  ele.setCorrectedEcalEnergy(ecalEnergyPreCorr);
138  ele.setCorrectedEcalEnergyError(ecalEnergyErrPreCorr);
139 
140  const float energyEtUncertUp = calCombinedMom(ele,corr+etUncert,smear).first;
141  const float energyEtUncertDn = calCombinedMom(ele,corr-etUncert,smear).first;
142 
143  //reset it back to how it was
144  ele.setCorrectedEcalEnergy(oldEcalEnergy);
145  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
146  ele.correctMomentum(oldP4,oldTrkMomErr,oldP4Err);
147 
148  ele.addUserFloat("energyScaleEtUp",energyEtUncertUp);
149  ele.addUserFloat("energyScaleEtDown",energyEtUncertDn);
150 
151 }
float trackMomentumError() const
Definition: GsfElectron.h:847
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:869
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:860
JetCorrectorParameters corr
Definition: classes.h:5
Analysis-level electron class.
Definition: Electron.h:52
float ecalEnergy() const
Definition: GsfElectron.h:859
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::modifyObject ( pat::Photon pho) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 153 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().

154 {
155  auto getVal = [](const pat::Photon& pho,EGEnergySysIndex::Index valIndex){
156  return pho.userFloat(EGEnergySysIndex::name(valIndex));
157  };
158  //so pho.energy() may be either pre or post corrections, we have no idea
159  //so we explicity access the pre and post correction ecal energies
160  //post corr for the et value for the systematic, pre corr to apply them
161  const float ecalEnergyPostCorr = getVal(pho,EGEnergySysIndex::kEcalPostCorr);
162  const float ecalEnergyPreCorr = getVal(pho,EGEnergySysIndex::kEcalPreCorr);
163 
164  //the et cut is in terms of post corr ecal energy
165  const float etUncert = uncertFunc_->val(pho.et()/pho.energy()*ecalEnergyPostCorr);
166  const float corr = getVal(pho,EGEnergySysIndex::kScaleValue);
167 
168  const float energyEtUncertUp = ecalEnergyPreCorr*(corr+etUncert);
169  const float energyEtUncertDn = ecalEnergyPreCorr*(corr-etUncert);
170 
171  pho.addUserFloat("energyScaleEtUp",energyEtUncertUp);
172  pho.addUserFloat("energyScaleEtDown",energyEtUncertDn);
173 
174 }
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::setEcalEnergy ( reco::GsfElectron ele,
const float  scale,
const float  smear 
) const
private

Definition at line 196 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().

199 {
200  const float oldEcalEnergy = ele.ecalEnergy();
201  const float oldEcalEnergyErr = ele.ecalEnergyError();
202  ele.setCorrectedEcalEnergy( oldEcalEnergy*scale );
203  ele.setCorrectedEcalEnergyError(std::hypot( oldEcalEnergyErr*scale, oldEcalEnergy*smear*scale ) );
204 }
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:179
float ecalEnergyError() const
Definition: GsfElectron.h:860
float ecalEnergy() const
Definition: GsfElectron.h:859
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:182
void EGEtScaleSysModifier::setEvent ( const edm::Event iEvent)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 101 of file EGEtScaleSysModifier.cc.

Referenced by ~EGEtScaleSysModifier().

102 {
103 
104 }
void EGEtScaleSysModifier::setEventContent ( const edm::EventSetup iSetup)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 106 of file EGEtScaleSysModifier.cc.

References epCombTool_, and EpCombinationTool::setEventContent().

Referenced by ~EGEtScaleSysModifier().

107 {
109 }
EpCombinationTool epCombTool_
void setEventContent(const edm::EventSetup &iSetup)

Member Data Documentation

EpCombinationTool EGEtScaleSysModifier::epCombTool_
private

Definition at line 83 of file EGEtScaleSysModifier.cc.

Referenced by calCombinedMom(), and setEventContent().

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

Definition at line 84 of file EGEtScaleSysModifier.cc.

Referenced by EGEtScaleSysModifier(), and modifyObject().