CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
EpCombinationTool Class Reference

#include <EpCombinationTool.h>

Public Member Functions

std::pair< float, float > combine (const reco::GsfElectron &electron) const
 
std::pair< float, float > combine (const reco::GsfElectron &electron, float corrEcalEnergyErr) const
 
void combine (SimpleElectron &mySimpleElectron) const
 
 EpCombinationTool ()
 
 EpCombinationTool (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&cc)
 
 EpCombinationTool (const EpCombinationTool &other)=delete
 
bool init (const GBRForest *forest)
 
bool init (const std::string &regressionFile, const std::string &bdtName)
 
EpCombinationTooloperator= (const EpCombinationTool &other)=delete
 
void setEventContent (const edm::EventSetup &iSetup)
 
 ~EpCombinationTool ()
 
 ~EpCombinationTool ()
 

Static Public Member Functions

static edm::ParameterSetDescription makePSetDescription ()
 

Private Attributes

EgammaRegressionContainer ecalTrkEnergyRegress_
 
EgammaRegressionContainer ecalTrkEnergyRegressUncert_
 
const GBRForestm_forest
 
bool m_ownForest
 
float maxEcalEnergyForComb_
 
float maxEPDiffInSigmaForComb_
 
float maxRelTrkMomErrForComb_
 
float minEOverPForComb_
 

Detailed Description

Definition at line 10 of file EpCombinationTool.h.

Constructor & Destructor Documentation

◆ EpCombinationTool() [1/3]

EpCombinationTool::EpCombinationTool ( )

Definition at line 12 of file EpCombinationTool.cc.

13  : m_forest(nullptr),
14  m_ownForest(false)
15 /*****************************************************************/
16 {}

◆ ~EpCombinationTool() [1/2]

EpCombinationTool::~EpCombinationTool ( )

Definition at line 19 of file EpCombinationTool.cc.

21 {
22  if (m_ownForest)
23  delete m_forest;
24 }

References m_forest, and m_ownForest.

◆ EpCombinationTool() [2/3]

EpCombinationTool::EpCombinationTool ( const EpCombinationTool other)
delete

◆ EpCombinationTool() [3/3]

EpCombinationTool::EpCombinationTool ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  cc 
)

Definition at line 15 of file EpCombinationTool.cc.

16  : ecalTrkEnergyRegress_(iConfig.getParameter<edm::ParameterSet>("ecalTrkRegressionConfig"), cc),
17  ecalTrkEnergyRegressUncert_(iConfig.getParameter<edm::ParameterSet>("ecalTrkRegressionUncertConfig"), cc),
18  maxEcalEnergyForComb_(iConfig.getParameter<double>("maxEcalEnergyForComb")),
19  minEOverPForComb_(iConfig.getParameter<double>("minEOverPForComb")),
20  maxEPDiffInSigmaForComb_(iConfig.getParameter<double>("maxEPDiffInSigmaForComb")),
21  maxRelTrkMomErrForComb_(iConfig.getParameter<double>("maxRelTrkMomErrForComb")) {}

◆ ~EpCombinationTool() [2/2]

EpCombinationTool::~EpCombinationTool ( )
inline

Definition at line 23 of file EpCombinationTool.h.

23 {}

Member Function Documentation

◆ combine() [1/3]

std::pair< float, float > EpCombinationTool::combine ( const reco::GsfElectron electron) const

Definition at line 40 of file EpCombinationTool.cc.

40  {
41  return combine(ele, ele.correctedEcalEnergyError());
42 }

References combine(), and reco::GsfElectron::correctedEcalEnergyError().

◆ combine() [2/3]

std::pair< float, float > EpCombinationTool::combine ( const reco::GsfElectron electron,
float  corrEcalEnergyErr 
) const

Definition at line 47 of file EpCombinationTool.cc.

47  {
48  const float scRawEnergy = ele.superCluster()->rawEnergy();
49  const float esEnergy = ele.superCluster()->preshowerEnergy();
50 
51  const float corrEcalEnergy = ele.correctedEcalEnergy();
52  const float ecalMean = ele.correctedEcalEnergy() / (scRawEnergy + esEnergy);
53  const float ecalSigma = corrEcalEnergyErr / corrEcalEnergy;
54 
55  auto gsfTrk = ele.gsfTrack();
56 
57  const float trkP = gsfTrk->pMode();
58  const float trkEta = gsfTrk->etaMode();
59  const float trkPhi = gsfTrk->phiMode();
60  const float trkPErr = std::abs(gsfTrk->qoverpModeError()) * trkP * trkP;
61  const float eOverP = corrEcalEnergy / trkP;
62  const float fbrem = ele.fbrem();
63 
64  if (corrEcalEnergy < maxEcalEnergyForComb_ && eOverP > minEOverPForComb_ &&
65  std::abs(corrEcalEnergy - trkP) <
66  maxEPDiffInSigmaForComb_ * std::sqrt(trkPErr * trkPErr + corrEcalEnergyErr * corrEcalEnergyErr) &&
67  trkPErr < maxRelTrkMomErrForComb_ * trkP) {
68  std::array<float, 9> eval;
69  eval[0] = corrEcalEnergy;
70  eval[1] = ecalSigma / ecalMean;
71  eval[2] = trkPErr / trkP;
72  eval[3] = eOverP;
73  eval[4] = ele.ecalDrivenSeed();
74  eval[5] = ele.full5x5_showerShape().r9;
75  eval[6] = fbrem;
76  eval[7] = trkEta;
77  eval[8] = trkPhi;
78 
79  const float preCombinationEt = corrEcalEnergy / std::cosh(trkEta);
80  float mean = ecalTrkEnergyRegress_(preCombinationEt, ele.isEB(), ele.nSaturatedXtals() != 0, eval.data());
81  float sigma = ecalTrkEnergyRegressUncert_(preCombinationEt, ele.isEB(), ele.nSaturatedXtals() != 0, eval.data());
82  // Final correction
83  // A negative energy means that the correction went
84  // outside the boundaries of the training. In this case uses raw.
85  // The resolution estimation, on the other hand should be ok.
86  if (mean < 0.)
87  mean = 1.0;
88 
89  //why this differs from the defination of corrEcalEnergyErr (it misses the mean) is not clear to me
90  //still this is a direct port from EGExtraInfoModifierFromDB, potential bugs and all
91  const float ecalSigmaTimesRawEnergy = ecalSigma * (scRawEnergy + esEnergy);
92  const float rawCombEnergy =
93  (corrEcalEnergy * trkPErr * trkPErr + trkP * ecalSigmaTimesRawEnergy * ecalSigmaTimesRawEnergy) /
94  (trkPErr * trkPErr + ecalSigmaTimesRawEnergy * ecalSigmaTimesRawEnergy);
95 
96  return std::make_pair(mean * rawCombEnergy, sigma * rawCombEnergy);
97  } else {
98  return std::make_pair(corrEcalEnergy, corrEcalEnergyErr);
99  }
100 }

References funct::abs(), reco::GsfElectron::correctedEcalEnergy(), reco::GsfElectron::ecalDrivenSeed(), ecalTrkEnergyRegress_, ecalTrkEnergyRegressUncert_, EgHLTOffHistBins_cfi::eOverP, reco::GsfElectron::fbrem(), reco::GsfElectron::full5x5_showerShape(), reco::GsfElectron::gsfTrack(), reco::GsfElectron::isEB(), maxEPDiffInSigmaForComb_, maxRelTrkMomErrForComb_, SiStripPI::mean, minEOverPForComb_, reco::GsfElectron::nSaturatedXtals(), reco::GsfElectron::ShowerShape::r9, mathSSE::sqrt(), and reco::GsfElectron::superCluster().

◆ combine() [3/3]

void EpCombinationTool::combine ( SimpleElectron mySimpleElectron) const

Definition at line 58 of file EpCombinationTool.cc.

60 {
61  if (!m_forest) {
62  cout << "ERROR: The combination tool is not initialized\n";
63  return;
64  }
65 
66  float energy = mySimpleElectron.getNewEnergy();
67  float energyError = mySimpleElectron.getNewEnergyError();
68  float momentum = mySimpleElectron.getTrackerMomentum();
69  float momentumError = mySimpleElectron.getTrackerMomentumError();
70  int electronClass = mySimpleElectron.getElClass();
71  bool isEcalDriven = mySimpleElectron.isEcalDriven();
72  bool isTrackerDriven = mySimpleElectron.isTrackerDriven();
73  bool isEB = mySimpleElectron.isEB();
74 
75  // compute relative errors and ratio of errors
76  float energyRelError = energyError / energy;
77  float momentumRelError = momentumError / momentum;
78  float errorRatio = energyRelError / momentumRelError;
79 
80  // calculate E/p and corresponding error
81  float eOverP = energy / momentum;
82  float eOverPerror =
83  sqrt((energyError / momentum) * (energyError / momentum) +
84  (energy * momentumError / momentum / momentum) * (energy * momentumError / momentum / momentum));
85 
86  // fill input variables
87  float regressionInputs[11];
88  regressionInputs[0] = energy;
89  regressionInputs[1] = energyRelError;
90  regressionInputs[2] = momentum;
91  regressionInputs[3] = momentumRelError;
92  regressionInputs[4] = errorRatio;
93  regressionInputs[5] = eOverP;
94  regressionInputs[6] = eOverPerror;
95  regressionInputs[7] = static_cast<float>(isEcalDriven);
96  regressionInputs[8] = static_cast<float>(isTrackerDriven);
97  regressionInputs[9] = static_cast<float>(electronClass);
98  regressionInputs[10] = static_cast<float>(isEB);
99 
100  // retrieve combination weight
101  float weight = 0.;
102  if (eOverP > 0.025 &&
103  fabs(momentum - energy) < 15. * sqrt(momentumError * momentumError + energyError * energyError) &&
104  ((momentumError < 10. * momentum) || (energy < 200.))) // protection against crazy track measurement
105  {
106  weight = m_forest->GetResponse(regressionInputs);
107  if (weight > 1.)
108  weight = 1.;
109  else if (weight < 0.)
110  weight = 0.;
111  }
112 
113  float combinedMomentum = weight * momentum + (1. - weight) * energy;
114  float combinedMomentumError =
115  sqrt(weight * weight * momentumError * momentumError + (1. - weight) * (1. - weight) * energyError * energyError);
116 
117  // FIXME : pure tracker electrons have track momentum error of 999.
118  // If the combination try to combine such electrons then the original combined momentum is kept
119  if (momentumError != 999. || weight == 0.) {
120  mySimpleElectron.setCombinedMomentum(combinedMomentum);
121  mySimpleElectron.setCombinedMomentumError(combinedMomentumError);
122  }
123 }

References gather_cfg::cout, HCALHighEnergyHPDFilter_cfi::energy, EgHLTOffHistBins_cfi::eOverP, mathSSE::sqrt(), and mps_merge::weight.

Referenced by EGEtScaleSysModifier::calCombinedMom(), ElectronEnergyCalibrator::calCombinedMom(), ElectronEnergyCalibratorRun2::calibrate(), and combine().

◆ init() [1/2]

bool EpCombinationTool::init ( const GBRForest forest)

Definition at line 49 of file EpCombinationTool.cc.

49  {
50  if (m_ownForest)
51  delete m_forest;
52  m_forest = forest;
53  m_ownForest = false;
54  return true;
55 }

References m_forest, and m_ownForest.

◆ init() [2/2]

bool EpCombinationTool::init ( const std::string &  regressionFile,
const std::string &  bdtName 
)

Definition at line 27 of file EpCombinationTool.cc.

29 {
30  TFile* regressionFile = TFile::Open(regressionFileName.c_str());
31  if (!regressionFile) {
32  cout << "ERROR: Cannot open regression file " << regressionFileName << "\n";
33  return false;
34  }
35  if (m_ownForest)
36  delete m_forest;
37  m_forest = (GBRForest*)regressionFile->Get(bdtName.c_str());
38  m_ownForest = true;
39  //regressionFile->GetObject(bdtName.c_str(), m_forest);
40  if (!m_forest) {
41  cout << "ERROR: Cannot find forest " << bdtName << " in " << regressionFileName << "\n";
42  regressionFile->Close();
43  return false;
44  }
45  regressionFile->Close();
46  return true;
47 }

References gather_cfg::cout, m_forest, and m_ownForest.

◆ makePSetDescription()

edm::ParameterSetDescription EpCombinationTool::makePSetDescription ( )
static

Definition at line 23 of file EpCombinationTool.cc.

23  {
26  desc.add<edm::ParameterSetDescription>("ecalTrkRegressionUncertConfig",
28  desc.add<double>("maxEcalEnergyForComb", 200.);
29  desc.add<double>("minEOverPForComb", 0.025);
30  desc.add<double>("maxEPDiffInSigmaForComb", 15.);
31  desc.add<double>("maxRelTrkMomErrForComb", 10.);
32  return desc;
33 }

References submitPVResolutionJobs::desc, and EgammaRegressionContainer::makePSetDescription().

Referenced by CalibratedElectronProducerT< T >::fillDescriptions().

◆ operator=()

EpCombinationTool& EpCombinationTool::operator= ( const EpCombinationTool other)
delete

◆ setEventContent()

void EpCombinationTool::setEventContent ( const edm::EventSetup iSetup)

Member Data Documentation

◆ ecalTrkEnergyRegress_

EgammaRegressionContainer EpCombinationTool::ecalTrkEnergyRegress_
private

Definition at line 32 of file EpCombinationTool.h.

Referenced by combine(), and setEventContent().

◆ ecalTrkEnergyRegressUncert_

EgammaRegressionContainer EpCombinationTool::ecalTrkEnergyRegressUncert_
private

Definition at line 33 of file EpCombinationTool.h.

Referenced by combine(), and setEventContent().

◆ m_forest

const GBRForest* EpCombinationTool::m_forest
private

Definition at line 23 of file EpCombinationTool.h.

Referenced by init(), and ~EpCombinationTool().

◆ m_ownForest

bool EpCombinationTool::m_ownForest
private

Definition at line 24 of file EpCombinationTool.h.

Referenced by init(), and ~EpCombinationTool().

◆ maxEcalEnergyForComb_

float EpCombinationTool::maxEcalEnergyForComb_
private

Definition at line 34 of file EpCombinationTool.h.

◆ maxEPDiffInSigmaForComb_

float EpCombinationTool::maxEPDiffInSigmaForComb_
private

Definition at line 36 of file EpCombinationTool.h.

Referenced by combine().

◆ maxRelTrkMomErrForComb_

float EpCombinationTool::maxRelTrkMomErrForComb_
private

Definition at line 37 of file EpCombinationTool.h.

Referenced by combine().

◆ minEOverPForComb_

float EpCombinationTool::minEOverPForComb_
private

Definition at line 35 of file EpCombinationTool.h.

Referenced by combine().

EgHLTOffHistBins_cfi.eOverP
eOverP
Definition: EgHLTOffHistBins_cfi.py:37
SimpleElectron::getTrackerMomentumError
double getTrackerMomentumError() const
Definition: SimpleElectron.h:66
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
SimpleElectron::getTrackerMomentum
double getTrackerMomentum() const
Definition: SimpleElectron.h:65
EpCombinationTool::m_ownForest
bool m_ownForest
Definition: EpCombinationTool.h:24
mps_merge.weight
weight
Definition: mps_merge.py:88
GBRForest
Definition: GBRForest.h:24
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EpCombinationTool::m_forest
const GBRForest * m_forest
Definition: EpCombinationTool.h:23
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EgammaRegressionContainer::setEventContent
void setEventContent(const edm::EventSetup &iSetup)
Definition: EgammaRegressionContainer.cc:36
EpCombinationTool::combine
void combine(SimpleElectron &mySimpleElectron) const
Definition: EpCombinationTool.cc:58
EpCombinationTool::ecalTrkEnergyRegress_
EgammaRegressionContainer ecalTrkEnergyRegress_
Definition: EpCombinationTool.h:32
SimpleElectron::setCombinedMomentumError
void setCombinedMomentumError(double combinedMomentumError)
Definition: SimpleElectron.h:78
EpCombinationTool::maxEPDiffInSigmaForComb_
float maxEPDiffInSigmaForComb_
Definition: EpCombinationTool.h:36
GBRForest::GetResponse
double GetResponse(const float *vector) const
Definition: GBRForest.h:48
SimpleElectron::isEB
bool isEB() const
Definition: SimpleElectron.h:71
EgammaRegressionContainer::makePSetDescription
static edm::ParameterSetDescription makePSetDescription()
Definition: EgammaRegressionContainer.cc:21
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::ParameterSet
Definition: ParameterSet.h:47
EpCombinationTool::ecalTrkEnergyRegressUncert_
EgammaRegressionContainer ecalTrkEnergyRegressUncert_
Definition: EpCombinationTool.h:33
SimpleElectron::setCombinedMomentum
void setCombinedMomentum(double combinedMomentum)
Definition: SimpleElectron.h:77
EpCombinationTool::minEOverPForComb_
float minEOverPForComb_
Definition: EpCombinationTool.h:35
SimpleElectron::getNewEnergyError
double getNewEnergyError() const
Definition: SimpleElectron.h:56
SimpleElectron::isTrackerDriven
bool isTrackerDriven() const
Definition: SimpleElectron.h:74
cc
EpCombinationTool::maxRelTrkMomErrForComb_
float maxRelTrkMomErrForComb_
Definition: EpCombinationTool.h:37
EpCombinationTool::maxEcalEnergyForComb_
float maxEcalEnergyForComb_
Definition: EpCombinationTool.h:34
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
SimpleElectron::getNewEnergy
double getNewEnergy() const
Definition: SimpleElectron.h:55
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SimpleElectron::isEcalDriven
bool isEcalDriven() const
Definition: SimpleElectron.h:73
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
SimpleElectron::getElClass
int getElClass() const
Definition: SimpleElectron.h:69
weight
Definition: weight.py:1