CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
RegressionHelper Class Reference

#include <RegressionHelper.h>

Classes

struct  Configuration
 
struct  ESGetTokens
 

Public Member Functions

void applyCombinationRegression (reco::GsfElectron &ele) const
 
void applyEcalRegression (reco::GsfElectron &electron, const reco::VertexCollection &vertices, const EcalRecHitCollection &rechitsEB, const EcalRecHitCollection &rechitsEE) const
 
void checkSetup (const edm::EventSetup &)
 
 RegressionHelper (Configuration const &, bool useEcalReg, bool useCombinationReg, edm::ConsumesCollector &cc)
 

Private Member Functions

void getEcalRegression (const reco::SuperCluster &sc, const reco::VertexCollection &vertices, const EcalRecHitCollection &rechitsEB, const EcalRecHitCollection &rechitsEE, double &energyFactor, double &errorFactor) const
 

Private Attributes

const CaloGeometrycaloGeometry_
 
const CaloTopologycaloTopology_
 
const Configuration cfg_
 
const GBRForestcombinationReg_
 
bool combinationRegressionInitialized_ = false
 
const GBRForestecalRegBarrel_
 
const GBRForestecalRegEndcap_
 
const GBRForestecalRegErrorBarrel_
 
const GBRForestecalRegErrorEndcap_
 
bool ecalRegressionInitialized_ = false
 
const ESGetTokens esGetTokens_
 

Detailed Description

Definition at line 25 of file RegressionHelper.h.

Constructor & Destructor Documentation

◆ RegressionHelper()

RegressionHelper::RegressionHelper ( Configuration const &  config,
bool  useEcalReg,
bool  useCombinationReg,
edm::ConsumesCollector cc 
)

Definition at line 27 of file RegressionHelper.cc.

31  : cfg_(config), esGetTokens_{cfg_, useEcalReg, useCombinationReg, cc} {}

References cfg_.

Member Function Documentation

◆ applyCombinationRegression()

void RegressionHelper::applyCombinationRegression ( reco::GsfElectron ele) const

Definition at line 114 of file RegressionHelper.cc.

114  {
115  float energy = ele.correctedEcalEnergy();
116  float energyError = ele.correctedEcalEnergyError();
117  float momentum = ele.trackMomentumAtVtx().R();
118  float momentumError = ele.trackMomentumError();
119  int elClass = -1;
120 
121  switch (ele.classification()) {
123  elClass = 0;
124  break;
126  elClass = 1;
127  break;
129  elClass = 2;
130  break;
132  elClass = 3;
133  break;
135  elClass = 4;
136  break;
137  default:
138  elClass = -1;
139  }
140 
141  bool isEcalDriven = ele.ecalDriven();
142  bool isTrackerDriven = ele.trackerDrivenSeed();
143  bool isEB = ele.isEB();
144 
145  // compute relative errors and ratio of errors
146  float energyRelError = energyError / energy;
147  float momentumRelError = momentumError / momentum;
148  float errorRatio = energyRelError / momentumRelError;
149 
150  // calculate E/p and corresponding error
151  float eOverP = energy / momentum;
152  float eOverPerror = eOverP * std::hypot(energyRelError, momentumRelError);
153 
154  // fill input variables
155  std::vector<float> regressionInputs;
156  regressionInputs.resize(11, 0.);
157 
158  regressionInputs[0] = energy;
159  regressionInputs[1] = energyRelError;
160  regressionInputs[2] = momentum;
161  regressionInputs[3] = momentumRelError;
162  regressionInputs[4] = errorRatio;
163  regressionInputs[5] = eOverP;
164  regressionInputs[6] = eOverPerror;
165  regressionInputs[7] = static_cast<float>(isEcalDriven);
166  regressionInputs[8] = static_cast<float>(isTrackerDriven);
167  regressionInputs[9] = static_cast<float>(elClass);
168  regressionInputs[10] = static_cast<float>(isEB);
169 
170  // retrieve combination weight
171  float weight = 0.;
172  if (eOverP > 0.025 &&
173  fabs(momentum - energy) < 15. * sqrt(momentumError * momentumError +
174  energyError * energyError)) // protection against crazy track measurement
175  {
176  weight = combinationReg_->GetResponse(regressionInputs.data());
177  if (weight > 1.)
178  weight = 1.;
179  else if (weight < 0.)
180  weight = 0.;
181  }
182 
183  float combinedMomentum = weight * momentum + (1. - weight) * energy;
184  float combinedMomentumError =
185  sqrt(weight * weight * momentumError * momentumError + (1. - weight) * (1. - weight) * energyError * energyError);
186 
187  // FIXME : pure tracker electrons have track momentum error of 999.
188  // If the combination try to combine such electrons then the original combined momentum is kept
189  if (momentumError != 999. || weight == 0.) {
190  math::XYZTLorentzVector oldMomentum = ele.p4();
191  math::XYZTLorentzVector newMomentum(oldMomentum.x() * combinedMomentum / oldMomentum.t(),
192  oldMomentum.y() * combinedMomentum / oldMomentum.t(),
193  oldMomentum.z() * combinedMomentum / oldMomentum.t(),
194  combinedMomentum);
195 
196  ele.setP4(reco::GsfElectron::P4_COMBINATION, newMomentum, combinedMomentumError, true);
197  }
198 }

References reco::GsfElectron::BADTRACK, reco::GsfElectron::BIGBREM, reco::GsfElectron::classification(), combinationReg_, reco::GsfElectron::correctedEcalEnergy(), reco::GsfElectron::correctedEcalEnergyError(), reco::GsfElectron::ecalDriven(), HCALHighEnergyHPDFilter_cfi::energy, EgHLTOffHistBins_cfi::eOverP, reco::GsfElectron::GAP, GBRForest::GetResponse(), reco::GsfElectron::GOLDEN, reco::GsfElectron::isEB(), reco::GsfElectron::p4(), reco::GsfElectron::P4_COMBINATION, reco::GsfElectron::setP4(), reco::GsfElectron::SHOWERING, mathSSE::sqrt(), reco::GsfElectron::trackerDrivenSeed(), reco::GsfElectron::trackMomentumAtVtx(), reco::GsfElectron::trackMomentumError(), and mps_merge::weight.

Referenced by GsfElectronAlgo::createElectron().

◆ applyEcalRegression()

void RegressionHelper::applyEcalRegression ( reco::GsfElectron electron,
const reco::VertexCollection vertices,
const EcalRecHitCollection rechitsEB,
const EcalRecHitCollection rechitsEE 
) const

Definition at line 33 of file RegressionHelper.cc.

36  {
37  double cor, err;
38  getEcalRegression(*ele.superCluster(), vertices, rechitsEB, rechitsEE, cor, err);
39  ele.setCorrectedEcalEnergy(cor * ele.superCluster()->correctedEnergy());
40  ele.setCorrectedEcalEnergyError(err * ele.superCluster()->correctedEnergy());
41 }

References submitPVResolutionJobs::err, getEcalRegression(), reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), reco::GsfElectron::superCluster(), and pwdgSkimBPark_cfi::vertices.

Referenced by GsfElectronAlgo::createElectron().

◆ checkSetup()

void RegressionHelper::checkSetup ( const edm::EventSetup es)

Definition at line 43 of file RegressionHelper.cc.

43  {
46 
47  // Ecal regression
48 
49  // if at least one of the set of weights come from the DB
50  if (cfg_.ecalWeightsFromDB) {
51  ecalRegBarrel_ = &es.getData(esGetTokens_.ecalRegBarrel); // ECAL barrel
52  ecalRegEndcap_ = &es.getData(esGetTokens_.ecalRegEndcap); // ECAL endcaps
53  ecalRegErrorBarrel_ = &es.getData(esGetTokens_.ecalRegErrorBarrel); // ECAL barrel error
54  ecalRegErrorEndcap_ = &es.getData(esGetTokens_.ecalRegErrorEndcap); // ECAL endcap error
56  }
58  // Combination
61  }
62 
63  // read weights from file - for debugging. Even if it is one single files, 4 files should b set in the vector
65  TFile file0(edm::FileInPath(cfg_.ecalRegressionWeightFiles[0].c_str()).fullPath().c_str());
66  ecalRegBarrel_ = (const GBRForest*)file0.Get(cfg_.ecalRegressionWeightLabels[0].c_str());
67  file0.Close();
68  TFile file1(edm::FileInPath(cfg_.ecalRegressionWeightFiles[1].c_str()).fullPath().c_str());
70  file1.Close();
71  TFile file2(edm::FileInPath(cfg_.ecalRegressionWeightFiles[2].c_str()).fullPath().c_str());
73  file2.Close();
74  TFile file3(edm::FileInPath(cfg_.ecalRegressionWeightFiles[3].c_str()).fullPath().c_str());
75  ecalRegErrorEndcap_ = (const GBRForest*)file3.Get(cfg_.ecalRegressionWeightLabels[3].c_str());
77  file3.Close();
78  }
79 
82  TFile file0(edm::FileInPath(cfg_.combinationRegressionWeightFiles[0].c_str()).fullPath().c_str());
83  combinationReg_ = (const GBRForest*)file0.Get(cfg_.combinationRegressionWeightLabels[0].c_str());
85  file0.Close();
86  }
87 }

References RegressionHelper::ESGetTokens::caloGeometry, caloGeometry_, RegressionHelper::ESGetTokens::caloTopology, caloTopology_, cfg_, RegressionHelper::ESGetTokens::combinationReg, combinationReg_, combinationRegressionInitialized_, RegressionHelper::Configuration::combinationRegressionWeightFiles, RegressionHelper::Configuration::combinationRegressionWeightLabels, RegressionHelper::Configuration::combinationWeightsFromDB, RegressionHelper::ESGetTokens::ecalRegBarrel, ecalRegBarrel_, RegressionHelper::ESGetTokens::ecalRegEndcap, ecalRegEndcap_, RegressionHelper::ESGetTokens::ecalRegErrorBarrel, ecalRegErrorBarrel_, RegressionHelper::ESGetTokens::ecalRegErrorEndcap, ecalRegErrorEndcap_, ecalRegressionInitialized_, RegressionHelper::Configuration::ecalRegressionWeightFiles, RegressionHelper::Configuration::ecalRegressionWeightLabels, RegressionHelper::Configuration::ecalWeightsFromDB, esGetTokens_, timingPdfMaker::file1, edmOneToOneComparison::file2, contentValuesFiles::fullPath, and edm::EventSetup::getData().

Referenced by GsfElectronAlgo::checkSetup().

◆ getEcalRegression()

void RegressionHelper::getEcalRegression ( const reco::SuperCluster sc,
const reco::VertexCollection vertices,
const EcalRecHitCollection rechitsEB,
const EcalRecHitCollection rechitsEE,
double &  energyFactor,
double &  errorFactor 
) const
private

Definition at line 89 of file RegressionHelper.cc.

94  {
95  energyFactor = -999.;
96  errorFactor = -999.;
97 
98  std::vector<float> rInputs;
99  EcalRegressionData regData;
100  regData.fill(sc, &rechitsEB, &rechitsEE, caloGeometry_, caloTopology_, &vertices);
101  regData.fillVec(rInputs);
102  if (sc.seed()->hitsAndFractions()[0].first.subdetId() == EcalBarrel) {
103  energyFactor = ecalRegBarrel_->GetResponse(&rInputs[0]);
104  errorFactor = ecalRegErrorBarrel_->GetResponse(&rInputs[0]);
105  } else if (sc.seed()->hitsAndFractions()[0].first.subdetId() == EcalEndcap) {
106  energyFactor = ecalRegEndcap_->GetResponse(&rInputs[0]);
107  errorFactor = ecalRegErrorEndcap_->GetResponse(&rInputs[0]);
108  } else {
109  throw cms::Exception("RegressionHelper::calculateRegressedEnergy")
110  << "Supercluster seed is either EB nor EE!" << std::endl;
111  }
112 }

References caloGeometry_, caloTopology_, EcalBarrel, EcalEndcap, ecalRegBarrel_, ecalRegEndcap_, ecalRegErrorBarrel_, ecalRegErrorEndcap_, Exception, EcalRegressionData::fill(), EcalRegressionData::fillVec(), GBRForest::GetResponse(), reco::SuperCluster::seed(), and pwdgSkimBPark_cfi::vertices.

Referenced by applyEcalRegression().

Member Data Documentation

◆ caloGeometry_

const CaloGeometry* RegressionHelper::caloGeometry_
private

Definition at line 71 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ caloTopology_

const CaloTopology* RegressionHelper::caloTopology_
private

Definition at line 70 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ cfg_

const Configuration RegressionHelper::cfg_
private

Definition at line 67 of file RegressionHelper.h.

Referenced by checkSetup(), and RegressionHelper().

◆ combinationReg_

const GBRForest* RegressionHelper::combinationReg_
private

Definition at line 79 of file RegressionHelper.h.

Referenced by applyCombinationRegression(), and checkSetup().

◆ combinationRegressionInitialized_

bool RegressionHelper::combinationRegressionInitialized_ = false
private

Definition at line 73 of file RegressionHelper.h.

Referenced by checkSetup().

◆ ecalRegBarrel_

const GBRForest* RegressionHelper::ecalRegBarrel_
private

Definition at line 75 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegEndcap_

const GBRForest* RegressionHelper::ecalRegEndcap_
private

Definition at line 76 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegErrorBarrel_

const GBRForest* RegressionHelper::ecalRegErrorBarrel_
private

Definition at line 77 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegErrorEndcap_

const GBRForest* RegressionHelper::ecalRegErrorEndcap_
private

Definition at line 78 of file RegressionHelper.h.

Referenced by checkSetup(), and getEcalRegression().

◆ ecalRegressionInitialized_

bool RegressionHelper::ecalRegressionInitialized_ = false
private

Definition at line 72 of file RegressionHelper.h.

Referenced by checkSetup().

◆ esGetTokens_

const ESGetTokens RegressionHelper::esGetTokens_
private

Definition at line 68 of file RegressionHelper.h.

Referenced by checkSetup().

EgHLTOffHistBins_cfi.eOverP
eOverP
Definition: EgHLTOffHistBins_cfi.py:37
reco::GsfElectron::isEB
bool isEB() const
Definition: GsfElectron.h:336
RegressionHelper::Configuration::ecalRegressionWeightLabels
std::vector< std::string > ecalRegressionWeightLabels
Definition: RegressionHelper.h:29
RegressionHelper::ecalRegEndcap_
const GBRForest * ecalRegEndcap_
Definition: RegressionHelper.h:76
RegressionHelper::ESGetTokens::caloGeometry
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometry
Definition: RegressionHelper.h:41
RegressionHelper::Configuration::combinationRegressionWeightLabels
std::vector< std::string > combinationRegressionWeightLabels
Definition: RegressionHelper.h:32
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
mps_merge.weight
weight
Definition: mps_merge.py:88
GBRForest
Definition: GBRForest.h:25
RegressionHelper::combinationReg_
const GBRForest * combinationReg_
Definition: RegressionHelper.h:79
RegressionHelper::ESGetTokens::ecalRegErrorBarrel
edm::ESGetToken< GBRForest, GBRWrapperRcd > ecalRegErrorBarrel
Definition: RegressionHelper.h:44
reco::GsfElectron::P4_COMBINATION
Definition: GsfElectron.h:769
EcalRegressionData
Definition: EcalRegressionData.h:17
RegressionHelper::ecalRegErrorBarrel_
const GBRForest * ecalRegErrorBarrel_
Definition: RegressionHelper.h:77
RegressionHelper::ESGetTokens::ecalRegEndcap
edm::ESGetToken< GBRForest, GBRWrapperRcd > ecalRegEndcap
Definition: RegressionHelper.h:43
RegressionHelper::ecalRegBarrel_
const GBRForest * ecalRegBarrel_
Definition: RegressionHelper.h:75
edmOneToOneComparison.file2
file2
Definition: edmOneToOneComparison.py:107
EcalBarrel
Definition: EcalSubdetector.h:10
RegressionHelper::Configuration::combinationWeightsFromDB
bool combinationWeightsFromDB
Definition: RegressionHelper.h:33
GBRForest::GetResponse
double GetResponse(const float *vector) const
Definition: GBRForest.h:49
reco::GsfElectron::SHOWERING
Definition: GsfElectron.h:724
config
Definition: config.py:1
edm::FileInPath
Definition: FileInPath.h:64
reco::GsfElectron::setP4
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:188
EcalRegressionData::fill
void fill(const reco::SuperCluster &superClus, const EcalRecHitCollection *ebRecHits, const EcalRecHitCollection *eeRecHits, const CaloGeometry *geom, const CaloTopology *topology, const reco::VertexCollection *vertices)
Definition: EcalRegressionData.h:82
RegressionHelper::cfg_
const Configuration cfg_
Definition: RegressionHelper.h:67
RegressionHelper::caloTopology_
const CaloTopology * caloTopology_
Definition: RegressionHelper.h:70
RegressionHelper::Configuration::combinationRegressionWeightFiles
std::vector< std::string > combinationRegressionWeightFiles
Definition: RegressionHelper.h:34
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::GsfElectron::trackMomentumAtVtx
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:276
reco::GsfElectron::GOLDEN
Definition: GsfElectron.h:724
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
reco::GsfElectron::correctedEcalEnergyError
float correctedEcalEnergyError() const
Definition: GsfElectron.h:807
RegressionHelper::combinationRegressionInitialized_
bool combinationRegressionInitialized_
Definition: RegressionHelper.h:73
RegressionHelper::ecalRegErrorEndcap_
const GBRForest * ecalRegErrorEndcap_
Definition: RegressionHelper.h:78
RegressionHelper::ESGetTokens::caloTopology
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopology
Definition: RegressionHelper.h:40
EcalEndcap
Definition: EcalSubdetector.h:10
RegressionHelper::ESGetTokens::ecalRegErrorEndcap
edm::ESGetToken< GBRForest, GBRWrapperRcd > ecalRegErrorEndcap
Definition: RegressionHelper.h:45
RegressionHelper::caloGeometry_
const CaloGeometry * caloGeometry_
Definition: RegressionHelper.h:71
reco::SuperCluster::seed
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:77
RegressionHelper::ESGetTokens::combinationReg
edm::ESGetToken< GBRForest, GBRWrapperRcd > combinationReg
Definition: RegressionHelper.h:46
EcalRegressionData::fillVec
void fillVec(std::vector< float > &inputVec) const
Definition: EcalRegressionData.cc:158
reco::GsfElectron::ecalDriven
bool ecalDriven() const
Definition: GsfElectron.cc:168
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
cc
reco::GsfElectron::p4
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:211
RegressionHelper::ESGetTokens::ecalRegBarrel
edm::ESGetToken< GBRForest, GBRWrapperRcd > ecalRegBarrel
Definition: RegressionHelper.h:42
RegressionHelper::esGetTokens_
const ESGetTokens esGetTokens_
Definition: RegressionHelper.h:68
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
reco::GsfElectron::BIGBREM
Definition: GsfElectron.h:724
reco::GsfElectron::correctedEcalEnergy
float correctedEcalEnergy() const
Definition: GsfElectron.h:806
timingPdfMaker.file1
file1
Definition: timingPdfMaker.py:79
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Exception
Definition: hltDiff.cc:246
RegressionHelper::Configuration::ecalWeightsFromDB
bool ecalWeightsFromDB
Definition: RegressionHelper.h:30
reco::GsfElectron::classification
Classification classification() const
Definition: GsfElectron.h:730
RegressionHelper::ecalRegressionInitialized_
bool ecalRegressionInitialized_
Definition: RegressionHelper.h:72
reco::GsfElectron::GAP
Definition: GsfElectron.h:724
reco::GsfElectron::trackerDrivenSeed
bool trackerDrivenSeed() const
Definition: GsfElectron.h:167
reco::GsfElectron::trackMomentumError
float trackMomentumError() const
Definition: GsfElectron.h:808
reco::GsfElectron::BADTRACK
Definition: GsfElectron.h:724
RegressionHelper::Configuration::ecalRegressionWeightFiles
std::vector< std::string > ecalRegressionWeightFiles
Definition: RegressionHelper.h:31
weight
Definition: weight.py:1
RegressionHelper::getEcalRegression
void getEcalRegression(const reco::SuperCluster &sc, const reco::VertexCollection &vertices, const EcalRecHitCollection &rechitsEB, const EcalRecHitCollection &rechitsEE, double &energyFactor, double &errorFactor) const
Definition: RegressionHelper.cc:89
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7