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 (pat::Jet &) const
 
virtual void modifyObject (pat::Muon &) const
 
virtual void modifyObject (pat::Tau &) const
 
virtual void modifyObject (reco::BaseTau &) const
 
virtual void modifyObject (reco::GsfElectron &) const
 
virtual void modifyObject (reco::Jet &) const
 
virtual void modifyObject (reco::Muon &) const
 
virtual void modifyObject (reco::Photon &) 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 28 of file EGEtScaleSysModifier.cc.

Constructor & Destructor Documentation

◆ EGEtScaleSysModifier()

EGEtScaleSysModifier::EGEtScaleSysModifier ( const edm::ParameterSet conf,
edm::ConsumesCollector cc 
)

Definition at line 89 of file EGEtScaleSysModifier.cc.

90  : ModifyObjectValueBase(conf), epCombTool_{conf.getParameterSet("epCombConfig"), std::move(cc)} {
91  const edm::ParameterSet& funcPSet = conf.getParameterSet("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
97  << " not valid";
98  }
99 }

References edm::ParameterSet::getParameterSet(), and eostools::move().

◆ ~EGEtScaleSysModifier()

EGEtScaleSysModifier::~EGEtScaleSysModifier ( )
inlineoverride

Definition at line 31 of file EGEtScaleSysModifier.cc.

31 {}

Member Function Documentation

◆ calCombinedMom()

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

Definition at line 165 of file EGEtScaleSysModifier.cc.

167  {
168  const float oldEcalEnergy = ele.ecalEnergy();
169  const float oldEcalEnergyErr = ele.ecalEnergyError();
170  const auto oldP4 = ele.p4();
171  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
172  const float oldTrkMomErr = ele.trackMomentumError();
173 
174  setEcalEnergy(ele, scale, smear);
175  const auto& combinedMomentum = epCombTool_.combine(ele);
176  ele.setCorrectedEcalEnergy(oldEcalEnergy);
177  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
178  ele.correctMomentum(oldP4, oldTrkMomErr, oldP4Err);
179 
180  return combinedMomentum;
181 }

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

Referenced by modifyObject().

◆ modifyObject() [1/2]

void EGEtScaleSysModifier::modifyObject ( pat::Electron ele) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 105 of file EGEtScaleSysModifier.cc.

105  {
106  auto getVal = [](const pat::Electron& ele, EGEnergySysIndex::Index valIndex) {
107  return ele.userFloat(EGEnergySysIndex::name(valIndex));
108  };
109  //so ele.energy() may be either pre or post corrections, we have no idea
110  //so we explicity access the pre and post correction ecal energies
111  //we need the pre corrected to properly do the e/p combination
112  //we need the post corrected to get et uncertainty
113  const float ecalEnergyPostCorr = getVal(ele, EGEnergySysIndex::kEcalPostCorr);
114  const float ecalEnergyPreCorr = getVal(ele, EGEnergySysIndex::kEcalPreCorr);
115  const float ecalEnergyErrPreCorr = getVal(ele, EGEnergySysIndex::kEcalErrPreCorr);
116 
117  //the et cut is in terms of ecal et using the track angle and post corr ecal energy
118  const float etUncert = uncertFunc_->val(ele.et() / ele.energy() * ecalEnergyPostCorr);
119  const float smear = getVal(ele, EGEnergySysIndex::kSmearValue);
120  const float corr = getVal(ele, EGEnergySysIndex::kScaleValue);
121 
122  //get the values we have to reset back to
123  const float oldEcalEnergy = ele.ecalEnergy();
124  const float oldEcalEnergyErr = ele.ecalEnergyError();
125  const auto oldP4 = ele.p4();
126  const float oldP4Err = ele.p4Error(reco::GsfElectron::P4_COMBINATION);
127  const float oldTrkMomErr = ele.trackMomentumError();
128 
129  ele.setCorrectedEcalEnergy(ecalEnergyPreCorr);
130  ele.setCorrectedEcalEnergyError(ecalEnergyErrPreCorr);
131 
132  const float energyEtUncertUp = calCombinedMom(ele, corr + etUncert, smear).first;
133  const float energyEtUncertDn = calCombinedMom(ele, corr - etUncert, smear).first;
134 
135  //reset it back to how it was
136  ele.setCorrectedEcalEnergy(oldEcalEnergy);
137  ele.setCorrectedEcalEnergyError(oldEcalEnergyErr);
138  ele.correctMomentum(oldP4, oldTrkMomErr, oldP4Err);
139 
140  ele.addUserFloat("energyScaleEtUp", energyEtUncertUp);
141  ele.addUserFloat("energyScaleEtDown", energyEtUncertDn);
142 }

References pat::PATObject< ObjectType >::addUserFloat(), calCombinedMom(), alignCSCRings::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().

◆ modifyObject() [2/2]

void EGEtScaleSysModifier::modifyObject ( pat::Photon pho) const
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 144 of file EGEtScaleSysModifier.cc.

144  {
145  auto getVal = [](const pat::Photon& pho, EGEnergySysIndex::Index valIndex) {
146  return pho.userFloat(EGEnergySysIndex::name(valIndex));
147  };
148  //so pho.energy() may be either pre or post corrections, we have no idea
149  //so we explicity access the pre and post correction ecal energies
150  //post corr for the et value for the systematic, pre corr to apply them
151  const float ecalEnergyPostCorr = getVal(pho, EGEnergySysIndex::kEcalPostCorr);
152  const float ecalEnergyPreCorr = getVal(pho, EGEnergySysIndex::kEcalPreCorr);
153 
154  //the et cut is in terms of post corr ecal energy
155  const float etUncert = uncertFunc_->val(pho.et() / pho.energy() * ecalEnergyPostCorr);
156  const float corr = getVal(pho, EGEnergySysIndex::kScaleValue);
157 
158  const float energyEtUncertUp = ecalEnergyPreCorr * (corr + etUncert);
159  const float energyEtUncertDn = ecalEnergyPreCorr * (corr - etUncert);
160 
161  pho.addUserFloat("energyScaleEtUp", energyEtUncertUp);
162  pho.addUserFloat("energyScaleEtDown", energyEtUncertDn);
163 }

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

◆ setEcalEnergy()

void EGEtScaleSysModifier::setEcalEnergy ( reco::GsfElectron ele,
const float  scale,
const float  smear 
) const
private

Definition at line 183 of file EGEtScaleSysModifier.cc.

183  {
184  const float oldEcalEnergy = ele.ecalEnergy();
185  const float oldEcalEnergyErr = ele.ecalEnergyError();
186  ele.setCorrectedEcalEnergy(oldEcalEnergy * scale);
187  ele.setCorrectedEcalEnergyError(std::hypot(oldEcalEnergyErr * scale, oldEcalEnergy * smear * scale));
188 }

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

Referenced by calCombinedMom().

◆ setEvent()

void EGEtScaleSysModifier::setEvent ( const edm::Event iEvent)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 101 of file EGEtScaleSysModifier.cc.

101 {}

◆ setEventContent()

void EGEtScaleSysModifier::setEventContent ( const edm::EventSetup iSetup)
finalvirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 103 of file EGEtScaleSysModifier.cc.

103 { epCombTool_.setEventContent(iSetup); }

References epCombTool_, and EpCombinationTool::setEventContent().

Member Data Documentation

◆ epCombTool_

EpCombinationTool EGEtScaleSysModifier::epCombTool_
private

Definition at line 85 of file EGEtScaleSysModifier.cc.

Referenced by calCombinedMom(), and setEventContent().

◆ uncertFunc_

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

Definition at line 86 of file EGEtScaleSysModifier.cc.

Referenced by modifyObject().

L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
reco::GsfElectron::correctMomentum
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
Definition: GsfElectron.h:829
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
reco::GsfElectron::P4_COMBINATION
Definition: GsfElectron.h:769
reco::GsfElectron::p4Error
float p4Error(P4Kind kind) const
Definition: GsfElectron.cc:224
EGEnergySysIndex::Index
Index
Definition: EGEnergySysIndex.h:15
EpCombinationTool::combine
void combine(SimpleElectron &mySimpleElectron) const
Definition: EpCombinationTool.cc:58
EGEtScaleSysModifier::calCombinedMom
std::pair< float, float > calCombinedMom(reco::GsfElectron &ele, const float scale, const float smear) const
Definition: EGEtScaleSysModifier.cc:165
pat::PATObject::userFloat
float userFloat(const std::string &key) const
Definition: PATObject.h:873
ModifyObjectValueBase::ModifyObjectValueBase
ModifyObjectValueBase(const edm::ParameterSet &conf)
Definition: ModifyObjectValueBase.h:20
EGEnergySysIndex::kScaleValue
Definition: EGEnergySysIndex.h:30
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
EGEnergySysIndex::kEcalErrPreCorr
Definition: EGEnergySysIndex.h:34
EGEnergySysIndex::name
static const std::string & name(size_t index)
Definition: EGEnergySysIndex.h:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::GsfElectron::setCorrectedEcalEnergyError
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:170
edm::ParameterSet
Definition: ParameterSet.h:47
pat::PATObject::addUserFloat
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:894
cc
EGEnergySysIndex::kEcalPostCorr
Definition: EGEnergySysIndex.h:35
reco::GsfElectron::p4
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:211
EGEtScaleSysModifier::setEcalEnergy
void setEcalEnergy(reco::GsfElectron &ele, const float scale, const float smear) const
Definition: EGEtScaleSysModifier.cc:183
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
EpCombinationTool::setEventContent
void setEventContent(const edm::EventSetup &iSetup)
Definition: EpCombinationTool.cc:35
eostools.move
def move(src, dest)
Definition: eostools.py:511
EGEnergySysIndex::kEcalPreCorr
Definition: EGEnergySysIndex.h:33
EGEnergySysIndex::kSmearValue
Definition: EGEnergySysIndex.h:31
Exception
Definition: hltDiff.cc:246
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
reco::GsfElectron::ecalEnergyError
float ecalEnergyError() const
Definition: GsfElectron.h:821
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
reco::GsfElectron::trackMomentumError
float trackMomentumError() const
Definition: GsfElectron.h:808
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
reco::GsfElectron::setCorrectedEcalEnergy
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:174
EGEtScaleSysModifier::epCombTool_
EpCombinationTool epCombTool_
Definition: EGEtScaleSysModifier.cc:85
EGEtScaleSysModifier::uncertFunc_
std::unique_ptr< UncertFuncBase > uncertFunc_
Definition: EGEtScaleSysModifier.cc:86
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2128
reco::GsfElectron::ecalEnergy
float ecalEnergy() const
Definition: GsfElectron.h:820